From 3bbcf57ca2810e6475ecc55bbedb12c24d75f698 Mon Sep 17 00:00:00 2001 From: Isaac Date: Fri, 1 Apr 2016 15:55:12 +0300 Subject: [PATCH 01/12] Android back and forward buttons gray out if unusable --- res/layout/drawer.xml | 6 ++-- .../kiwixmobile/KiwixMobileActivity.java | 28 +++++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/res/layout/drawer.xml b/res/layout/drawer.xml index 9bc33403d..067aa09c1 100644 --- a/res/layout/drawer.xml +++ b/res/layout/drawer.xml @@ -55,7 +55,8 @@ android:paddingLeft="4dp" android:paddingRight="4dp" android:paddingTop="4dp" - android:src="?attr/arrowBackDrawable"/> + android:src="?attr/arrowBackDrawable" + android:id="@+id/action_back_button" /> + android:src="?attr/arrowForwardDrawable" + android:id="@+id/action_forward_button" /> diff --git a/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java b/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java index 18024a55d..f2e5fa8e5 100644 --- a/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java +++ b/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java @@ -26,6 +26,9 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Configuration; +import android.graphics.Color; +import android.graphics.PorterDuff; +import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -628,7 +631,7 @@ public class KiwixMobileActivity extends AppCompatActivity } else { Log.e(TAG_KIWIX, "ZIM file doesn't exist at " + file.getAbsolutePath()); Toast.makeText(this, getResources().getString(R.string.error_filenotfound), - Toast.LENGTH_LONG).show(); + Toast.LENGTH_LONG).show(); } return false; } @@ -976,10 +979,11 @@ public class KiwixMobileActivity extends AppCompatActivity public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); refreshBookmarkSymbol(menu); + refreshNavigationButtons(); return true; } - public void refreshBookmarkSymbol(Menu menu){ + public void refreshBookmarkSymbol(Menu menu) { if (menu.findItem(R.id.menu_bookmarks) != null && getCurrentWebView().getUrl() != null && !getCurrentWebView().getUrl().equals("file:///android_res/raw/help.html") && @@ -993,6 +997,26 @@ public class KiwixMobileActivity extends AppCompatActivity } } + public void refreshNavigationButtons() { + ImageView back = (ImageView) mDrawerLayout.findViewById(R.id.action_back_button); + ImageView forward = (ImageView) mDrawerLayout.findViewById(R.id.action_forward_button); + toggleImageViewGrayFilter(back, getCurrentWebView().canGoBack()); + toggleImageViewGrayFilter(forward, getCurrentWebView().canGoForward()); + mDrawerLayout.findViewById(R.id.action_back).setEnabled(getCurrentWebView().canGoBack()); + mDrawerLayout.findViewById(R.id.action_forward).setEnabled(getCurrentWebView().canGoForward()); + } + + public void toggleImageViewGrayFilter(ImageView image, boolean state) { + Drawable originalIcon = image.getDrawable(); + Drawable res = originalIcon.mutate(); + if (state) { + res.clearColorFilter(); + } else { + res.setColorFilter(Color.GRAY, PorterDuff.Mode.SRC_IN); + } + image.setImageDrawable(res); + } + public void loadPrefs() { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); From a3635a25414fb50289b1257fded852354a5e2e14 Mon Sep 17 00:00:00 2001 From: Isaac Date: Sat, 2 Apr 2016 19:17:38 +0300 Subject: [PATCH 02/12] Added android table of contents accessed by swiping left --- res/layout/drawer.xml | 103 --------- res/layout/main.xml | 3 +- res/layout/section_list.xml | 25 +++ .../kiwixmobile/KiwixMobileActivity.java | 205 +++++++++++++++--- .../kiwix/kiwixmobile/utils/HTMLUtils.java | 126 +++++++++++ .../kiwixmobile/utils/files/FileReader.java | 31 +++ 6 files changed, 362 insertions(+), 131 deletions(-) delete mode 100644 res/layout/drawer.xml create mode 100644 res/layout/section_list.xml create mode 100644 src/org/kiwix/kiwixmobile/utils/HTMLUtils.java create mode 100644 src/org/kiwix/kiwixmobile/utils/files/FileReader.java diff --git a/res/layout/drawer.xml b/res/layout/drawer.xml deleted file mode 100644 index 067aa09c1..000000000 --- a/res/layout/drawer.xml +++ /dev/null @@ -1,103 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/res/layout/main.xml b/res/layout/main.xml index 6a1600d2d..38857886b 100644 --- a/res/layout/main.xml +++ b/res/layout/main.xml @@ -64,7 +64,8 @@ - + + \ No newline at end of file diff --git a/res/layout/section_list.xml b/res/layout/section_list.xml new file mode 100644 index 000000000..d1e4bbaa6 --- /dev/null +++ b/res/layout/section_list.xml @@ -0,0 +1,25 @@ + + + + + + \ No newline at end of file diff --git a/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java b/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java index f2e5fa8e5..9aa97b7c4 100644 --- a/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java +++ b/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java @@ -28,6 +28,7 @@ import android.content.SharedPreferences; import android.content.res.Configuration; import android.graphics.Color; import android.graphics.PorterDuff; +import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Build; @@ -43,6 +44,7 @@ import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.util.Log; import android.view.ActionMode; +import android.view.Gravity; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.Menu; @@ -84,8 +86,10 @@ import java.util.Locale; import org.json.JSONArray; import org.kiwix.kiwixmobile.settings.Constants; import org.kiwix.kiwixmobile.settings.KiwixSettingsActivity; +import org.kiwix.kiwixmobile.utils.HTMLUtils; import org.kiwix.kiwixmobile.utils.KiwixTextToSpeech; import org.kiwix.kiwixmobile.utils.LanguageUtils; +import org.kiwix.kiwixmobile.utils.files.FileReader; import org.kiwix.kiwixmobile.utils.files.FileUtils; import org.kiwix.kiwixmobile.views.AnimatedProgressBar; import org.kiwix.kiwixmobile.views.CompatFindActionModeCallback; @@ -124,6 +128,8 @@ public class KiwixMobileActivity extends AppCompatActivity private static final int REQUEST_PREFERENCES = 1235; + private static String jsContent; + public static ArrayList mPrefState; public static boolean mIsFullscreenOpened; @@ -136,6 +142,10 @@ public class KiwixMobileActivity extends AppCompatActivity public ImageButton exitFullscreenButton; + public List sectionProperties; + + private HTMLUtils htmlUtils; + protected boolean requestClearHistoryAfterLoad; protected boolean requestInitAllMenuItems; @@ -148,19 +158,27 @@ public class KiwixMobileActivity extends AppCompatActivity private Button mBackToTopButton; - private ListView mDrawerList; + private ListView mLeftDrawerList; - private DrawerLayout mDrawerLayout; + private ListView mRightDrawerList; + + private DrawerLayout mLeftDrawerLayout; + + public DrawerLayout mRightDrawerLayout; private ArrayList bookmarks; private List mWebViews = new ArrayList<>(); + private List mSections = new ArrayList<>(); + private KiwixTextToSpeech tts; private CompatFindActionModeCallback mCompatCallback; - private ArrayAdapter mDrawerAdapter; + private ArrayAdapter mLeftArrayAdapter; + + private ArrayAdapter mRightArrayAdapter; private FrameLayout mContentFrame; @@ -170,6 +188,8 @@ public class KiwixMobileActivity extends AppCompatActivity private AnimatedProgressBar mProgressBar; + public Handler mHandler = new Handler(); + // Initialized when onActionModeStarted is triggered. private ActionMode mActionMode = null; @@ -233,6 +253,9 @@ public class KiwixMobileActivity extends AppCompatActivity mProgressBar = (AnimatedProgressBar) findViewById(R.id.progress_view); exitFullscreenButton = (ImageButton) findViewById(R.id.FullscreenControlButton); + FileReader fileReader = new FileReader(); + jsContent = fileReader.readFile("www/js/jsfile.js", this); + RelativeLayout newTabButton = (RelativeLayout) findViewById(R.id.new_tab_button); newTabButton.setOnClickListener(new View.OnClickListener() { @@ -262,23 +285,64 @@ public class KiwixMobileActivity extends AppCompatActivity } }); - mDrawerAdapter = new KiwixWebViewAdapter(this, R.layout.tabs_list, mWebViews); - mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); - mDrawerList = (ListView) findViewById(R.id.left_drawer_list); - mDrawerList.setDivider(null); - mDrawerList.setDividerHeight(0); - mDrawerList.setAdapter(mDrawerAdapter); + mLeftArrayAdapter = new KiwixWebViewAdapter(this, R.layout.tabs_list, mWebViews); + mLeftDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); + mLeftDrawerList = (ListView) findViewById(R.id.left_drawer_list); + mLeftDrawerList.setDivider(null); + mLeftDrawerList.setDividerHeight(0); + mLeftDrawerList.setAdapter(mLeftArrayAdapter); - mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() { + mRightArrayAdapter = new KiwixToCAdapter(this, R.layout.section_list, mSections, this); + mRightDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); + mRightDrawerList = (ListView) findViewById(R.id.right_drawer_list); + mRightDrawerList.setDivider(null); + mRightDrawerList.setDividerHeight(0); + mRightDrawerList.setAdapter(mRightArrayAdapter); + sectionProperties = new ArrayList(); + // + // +mRightDrawerList.addHeaderView(tDiddy); + mRightArrayAdapter.notifyDataSetChanged(); + + mLeftDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { selectTab(position); } }); - ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, - 0, 0); + final ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(this, mLeftDrawerLayout, toolbar, + 0, 0){ - mDrawerLayout.setDrawerListener(drawerToggle); + @Override + public void onDrawerSlide(View drawerView, float slideOffset) { + // Make sure it was the navigation drawer + if (drawerView.getId() == R.id.left_drawer){ + super.onDrawerSlide(drawerView, slideOffset); + } + } + @Override + public void onDrawerOpened(View drawerView) { + // Make sure it was the navigation drawer + if (drawerView.getId() == R.id.left_drawer){ + super.onDrawerOpened(drawerView); + mRightDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.RIGHT); + } else { + mLeftDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.LEFT); + } + } + + @Override + public void onDrawerClosed(View drawerView) { + // Make sure it was the navigation drawer + if (drawerView.getId() == R.id.left_drawer){ + super.onDrawerClosed(drawerView); + mRightDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, Gravity.RIGHT); + } else { + mLeftDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, Gravity.LEFT); + } + } + }; + + mLeftDrawerLayout.setDrawerListener(drawerToggle); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); drawerToggle.syncState(); @@ -286,6 +350,7 @@ public class KiwixMobileActivity extends AppCompatActivity mCompatCallback = new CompatFindActionModeCallback(this); mContentFrame = (FrameLayout) findViewById(R.id.content_frame); setUpTTS(); + htmlUtils= new HTMLUtils(sectionProperties, mSections, mRightDrawerList, this, mHandler); newTab(); manageExternalLaunchAndRestoringViewState(savedInstanceState); @@ -349,6 +414,10 @@ public class KiwixMobileActivity extends AppCompatActivity tts.shutdown(); } + private void updateTableOfContents(){ + getCurrentWebView().loadUrl("javascript:(" + jsContent + ")()"); + } + private KiwixWebView newTab() { String mainPage = Uri.parse(ZimContentProvider.CONTENT_URI + ZimContentProvider.getMainPage()).toString(); @@ -357,15 +426,16 @@ public class KiwixMobileActivity extends AppCompatActivity private KiwixWebView newTab(String url) { KiwixWebView webView = new KiwixWebView(KiwixMobileActivity.this); - webView.setWebViewClient(new KiwixWebViewClient(KiwixMobileActivity.this, mDrawerAdapter)); + webView.setWebViewClient(new KiwixWebViewClient(KiwixMobileActivity.this, mLeftArrayAdapter)); webView.setWebChromeClient(new KiwixWebChromeClient()); webView.loadUrl(url); webView.loadPrefs(); mWebViews.add(webView); - mDrawerAdapter.notifyDataSetChanged(); + mLeftArrayAdapter.notifyDataSetChanged(); selectTab(mWebViews.size() - 1); setUpWebView(); + htmlUtils.initInterface(webView); return webView; } @@ -385,29 +455,29 @@ public class KiwixMobileActivity extends AppCompatActivity if (index < mCurrentWebViewIndex) { mCurrentWebViewIndex--; } - mDrawerList.setItemChecked(mCurrentWebViewIndex, true); + mLeftDrawerList.setItemChecked(mCurrentWebViewIndex, true); } } else { mWebViews.remove(0); mCurrentWebViewIndex = 0; newTab(); } - mDrawerAdapter.notifyDataSetChanged(); + mLeftArrayAdapter.notifyDataSetChanged(); } private void selectTab(int position) { mCurrentWebViewIndex = position; - mDrawerList.setItemChecked(position, true); + mLeftDrawerList.setItemChecked(position, true); mContentFrame.removeAllViews(); mContentFrame.addView(mWebViews.get(position)); - mDrawerList.setItemChecked(mCurrentWebViewIndex, true); + mLeftDrawerList.setItemChecked(mCurrentWebViewIndex, true); - if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) { + if (mLeftDrawerLayout.isDrawerOpen(GravityCompat.START)) { final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { - mDrawerLayout.closeDrawers(); + mLeftDrawerLayout.closeDrawers(); } }, 150); } @@ -415,10 +485,11 @@ public class KiwixMobileActivity extends AppCompatActivity if (menu != null) { refreshBookmarkSymbol(menu); } + updateTableOfContents(); } - private KiwixWebView getCurrentWebView() { - return mDrawerAdapter.getItem(mCurrentWebViewIndex); + public KiwixWebView getCurrentWebView() { + return mLeftArrayAdapter.getItem(mCurrentWebViewIndex); } @Override @@ -669,6 +740,18 @@ public class KiwixMobileActivity extends AppCompatActivity overridePendingTransition(0, 0); } }); + toolbar.setNavigationOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (mRightDrawerLayout.isDrawerOpen(Gravity.RIGHT)) { + mRightDrawerLayout.closeDrawer(Gravity.RIGHT); + } else if (mLeftDrawerLayout.isDrawerOpen(Gravity.LEFT)){ + mLeftDrawerLayout.closeDrawer(Gravity.LEFT); + } else { + mLeftDrawerLayout.openDrawer(Gravity.LEFT); + } + } + }); if (tts.isInitialized()) { menu.findItem(R.id.menu_read_aloud).setVisible(true); @@ -701,6 +784,7 @@ public class KiwixMobileActivity extends AppCompatActivity } } return false; + } public void toggleBookmark() { @@ -998,12 +1082,12 @@ public class KiwixMobileActivity extends AppCompatActivity } public void refreshNavigationButtons() { - ImageView back = (ImageView) mDrawerLayout.findViewById(R.id.action_back_button); - ImageView forward = (ImageView) mDrawerLayout.findViewById(R.id.action_forward_button); + ImageView back = (ImageView) mLeftDrawerLayout.findViewById(R.id.action_back_button); + ImageView forward = (ImageView) mLeftDrawerLayout.findViewById(R.id.action_forward_button); toggleImageViewGrayFilter(back, getCurrentWebView().canGoBack()); toggleImageViewGrayFilter(forward, getCurrentWebView().canGoForward()); - mDrawerLayout.findViewById(R.id.action_back).setEnabled(getCurrentWebView().canGoBack()); - mDrawerLayout.findViewById(R.id.action_forward).setEnabled(getCurrentWebView().canGoForward()); + mLeftDrawerLayout.findViewById(R.id.action_back).setEnabled(getCurrentWebView().canGoBack()); + mLeftDrawerLayout.findViewById(R.id.action_forward).setEnabled(getCurrentWebView().canGoForward()); } public void toggleImageViewGrayFilter(ImageView image, boolean state) { @@ -1324,6 +1408,7 @@ public class KiwixMobileActivity extends AppCompatActivity view.reload(); } mAdapter.notifyDataSetChanged(); + updateTableOfContents(); } } @@ -1404,4 +1489,70 @@ public class KiwixMobileActivity extends AppCompatActivity ImageView exit; } } + private class KiwixToCAdapter extends ArrayAdapter { + + private Context mContext; + + private int mLayoutResource; + + private KiwixMobileActivity parentKiwix; + + private List mTextViews; + + public KiwixToCAdapter(Context context, int resource, List textViews, KiwixMobileActivity parent) { + super(context, resource, textViews); + mContext = context; + mLayoutResource = resource; + mSections = textViews; + parentKiwix = parent; + } + + @Override + public View getView(final int position, View convertView, final ViewGroup parent) { + View row = convertView; + ViewHolder holder; + + if (row == null) { + LayoutInflater inflater = ((Activity) mContext).getLayoutInflater(); + row = inflater.inflate(mLayoutResource, parent, false); + + holder = new ViewHolder(); + holder.txtTitle = (TextView) row.findViewById(R.id.textTab); + row.setTag(holder); + } else { + holder = (ViewHolder) row.getTag(); + } + + holder.txtTitle.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View view) { + getCurrentWebView().loadUrl("javascript:document.getElementById('" + sectionProperties.get(position).sectionId + "').scrollIntoView();"); + mRightDrawerLayout.closeDrawers(); + } + }); + if (sectionProperties.isEmpty()) + return row; + SectionProperties section = sectionProperties.get(position); + holder.txtTitle.setText(section.sectionTitle); + holder.txtTitle.setPadding(section.leftPadding, 0, 0, 0); + holder.txtTitle.setTypeface(section.typeface); + holder.txtTitle.setTextColor(section.color); + return row; + } + + class ViewHolder { + + TextView txtTitle; + + } + } + + public static class SectionProperties { + public Typeface typeface; + public int leftPadding; + public String sectionTitle; + public String sectionId; + public int color; + } } diff --git a/src/org/kiwix/kiwixmobile/utils/HTMLUtils.java b/src/org/kiwix/kiwixmobile/utils/HTMLUtils.java new file mode 100644 index 000000000..1041845c0 --- /dev/null +++ b/src/org/kiwix/kiwixmobile/utils/HTMLUtils.java @@ -0,0 +1,126 @@ +package org.kiwix.kiwixmobile.utils; + +import android.content.Context; +import android.graphics.Color; +import android.graphics.Typeface; +import android.os.Handler; +import android.view.Gravity; +import android.view.LayoutInflater; +import android.view.View; +import android.webkit.JavascriptInterface; +import android.webkit.WebView; +import android.widget.ArrayAdapter; +import android.widget.ListView; +import android.widget.TextView; + +import org.kiwix.kiwixmobile.KiwixMobileActivity; +import org.kiwix.kiwixmobile.R; + +import java.util.List; + +public class HTMLUtils { + + private List sectionProperties; + private List textViews; + private ArrayAdapter arrayAdapter; + private KiwixMobileActivity context; + private Handler mHandler; + private ListView mRightListView; + private TextView headerView; + + public HTMLUtils(List sectionProperties, List textViews, ListView listView, KiwixMobileActivity context, Handler handler) { + this.sectionProperties = sectionProperties; + this.textViews = textViews; + this.mRightListView = listView; + this.arrayAdapter = (ArrayAdapter) listView.getAdapter(); + this.context = context; + this.mHandler = handler; + } + + public void initInterface(WebView webView){ + webView.addJavascriptInterface(new HTMLinterface(), "HTMLUtils"); + } + + + class HTMLinterface + { + int i = 0; + @JavascriptInterface + @SuppressWarnings("unused") + public void parse(final String sectionTitle, final String element,final String id) { + mHandler.post(new Runnable() { + @Override + public void run() { + if (element.equals("H1")) { + mRightListView.removeHeaderView(headerView); + LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE ); + View view = inflater.inflate( R.layout.section_list, null ); + headerView = (TextView) view.findViewById( R.id.textTab ); + headerView.setText(sectionTitle); + headerView.setPadding((int) (26 * context.getResources().getDisplayMetrics().density), 0, 0, 0); + headerView.setBackgroundColor(Color.LTGRAY); + headerView.setTypeface(Typeface.DEFAULT_BOLD); + headerView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + context.getCurrentWebView().setScrollY(0); + context.mRightDrawerLayout.closeDrawer(Gravity.RIGHT); + } + }); + mRightListView.addHeaderView(headerView); + } else { + textViews.add(i, new TextView(context)); + sectionProperties.add(i, new KiwixMobileActivity.SectionProperties()); + KiwixMobileActivity.SectionProperties section = sectionProperties.get(i); + section.sectionTitle = sectionTitle; + section.sectionId = id; + switch (element) { + case "H2": + section.leftPadding = (int) (30 * context.getResources().getDisplayMetrics().density); + section.typeface = Typeface.DEFAULT; + section.color = Color.BLACK; + break; + case "H3": + section.leftPadding = (int) (50 * context.getResources().getDisplayMetrics().density); + section.typeface = Typeface.DEFAULT; + section.color = Color.GRAY; + break; + default: + section.leftPadding = (int) (30 * context.getResources().getDisplayMetrics().density); + section.typeface = Typeface.DEFAULT; + section.color = Color.BLACK; + break; + } + i++; + } + } + }); + } + @JavascriptInterface + @SuppressWarnings("unused") + public void start() { + mHandler.post(new Runnable() { + @Override + public void run() { + i=0; + textViews.clear(); + sectionProperties.clear(); + arrayAdapter.clear(); + arrayAdapter.notifyDataSetChanged(); + } + }); + } + @JavascriptInterface + @SuppressWarnings("unused") + public void stop() { + mHandler.post(new Runnable() { + @Override + public void run() { + arrayAdapter.notifyDataSetChanged(); + } + }); + } + } +} + + diff --git a/src/org/kiwix/kiwixmobile/utils/files/FileReader.java b/src/org/kiwix/kiwixmobile/utils/files/FileReader.java new file mode 100644 index 000000000..29d96865e --- /dev/null +++ b/src/org/kiwix/kiwixmobile/utils/files/FileReader.java @@ -0,0 +1,31 @@ +package org.kiwix.kiwixmobile.utils.files; + +import android.content.Context; + +import org.kiwix.kiwixmobile.KiwixMobileActivity; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; + +public class FileReader { + + public String readFile(String filePath , Context context){ + try { + StringBuilder buf = new StringBuilder(); + InputStream json = context.getAssets().open(filePath); + BufferedReader in = + new BufferedReader(new InputStreamReader(json, "UTF-8")); + String str; + + while ((str = in.readLine()) != null) { + buf.append(str); + } + + in.close(); + return buf.toString(); + } catch (Exception e){ + return ""; + } + } +} From 2bc9ad320d8666d68e108ef5132ec08a2d105194 Mon Sep 17 00:00:00 2001 From: Isaac Date: Sat, 2 Apr 2016 20:39:20 +0300 Subject: [PATCH 03/12] Improved table of contents UI on android --- res/layout/section_list.xml | 4 +++- res/values/strings.xml | 1 + .../kiwixmobile/KiwixMobileActivity.java | 21 +++++++++---------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/res/layout/section_list.xml b/res/layout/section_list.xml index d1e4bbaa6..2a2977edd 100644 --- a/res/layout/section_list.xml +++ b/res/layout/section_list.xml @@ -4,7 +4,9 @@ android:layout_height="56dp" android:background="?attr/selectedBackground" android:gravity="center_vertical" - android:orientation="horizontal"> + android:orientation="horizontal" + android:clickable="false" + android:focusable="false"> Could not find an installed application for this type of file Your application is corrupted.\nThis might happen when you remove files on the SD Card.\nYou need to uninstall then reinstall the App from the Play Store. Go to Play Store + No Content Headers Found \ No newline at end of file diff --git a/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java b/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java index 9aa97b7c4..eb2f30399 100644 --- a/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java +++ b/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java @@ -298,9 +298,9 @@ public class KiwixMobileActivity extends AppCompatActivity mRightDrawerList.setDivider(null); mRightDrawerList.setDividerHeight(0); mRightDrawerList.setAdapter(mRightArrayAdapter); + TextView tView = (TextView) findViewById(R.id.empty); + mRightDrawerList.setEmptyView(tView); sectionProperties = new ArrayList(); - // - // +mRightDrawerList.addHeaderView(tDiddy); mRightArrayAdapter.notifyDataSetChanged(); mLeftDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @@ -309,6 +309,13 @@ public class KiwixMobileActivity extends AppCompatActivity selectTab(position); } }); + mRightDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + getCurrentWebView().loadUrl("javascript:document.getElementById('" + sectionProperties.get(position - mRightDrawerList.getHeaderViewsCount()).sectionId+ "').scrollIntoView();"); + mRightDrawerLayout.closeDrawers(); + } + }); final ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(this, mLeftDrawerLayout, toolbar, 0, 0){ @@ -1178,7 +1185,7 @@ public class KiwixMobileActivity extends AppCompatActivity String zimArticles = settings.getString(TAG_CURRENT_ARTICLES, null); String zimPositions = settings.getString(TAG_CURRENT_POSITIONS, null); int currentTab = settings.getInt(TAG_CURRENT_TAB, 0 ); - openZimFile( new File(zimFile), false); + openZimFile(new File(zimFile), false); try { JSONArray urls = new JSONArray(zimArticles); JSONArray positions = new JSONArray(zimPositions); @@ -1523,14 +1530,6 @@ public class KiwixMobileActivity extends AppCompatActivity holder = (ViewHolder) row.getTag(); } - holder.txtTitle.setOnClickListener(new View.OnClickListener() { - - @Override - public void onClick(View view) { - getCurrentWebView().loadUrl("javascript:document.getElementById('" + sectionProperties.get(position).sectionId + "').scrollIntoView();"); - mRightDrawerLayout.closeDrawers(); - } - }); if (sectionProperties.isEmpty()) return row; SectionProperties section = sectionProperties.get(position); From 63aa024900bbd7a4d05c8afde2ba63af367f48c1 Mon Sep 17 00:00:00 2001 From: Isaac Date: Sun, 3 Apr 2016 10:43:15 +0300 Subject: [PATCH 04/12] Android fix for heighlighted section persisting after article change --- src/org/kiwix/kiwixmobile/KiwixMobileActivity.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java b/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java index eb2f30399..4e7ca973e 100644 --- a/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java +++ b/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java @@ -422,6 +422,7 @@ public class KiwixMobileActivity extends AppCompatActivity } private void updateTableOfContents(){ + mRightDrawerList.clearChoices(); getCurrentWebView().loadUrl("javascript:(" + jsContent + ")()"); } From fdf3ff1f400cad49b5a168c8ba32bb3f17b8655b Mon Sep 17 00:00:00 2001 From: Isaac Date: Sun, 3 Apr 2016 11:47:42 +0300 Subject: [PATCH 05/12] Added slider views to android app --- res/layout/drawer_left.xml | 103 ++++++++++++++++++++++++++++++++++++ res/layout/drawer_right.xml | 42 +++++++++++++++ 2 files changed, 145 insertions(+) create mode 100644 res/layout/drawer_left.xml create mode 100644 res/layout/drawer_right.xml diff --git a/res/layout/drawer_left.xml b/res/layout/drawer_left.xml new file mode 100644 index 000000000..067aa09c1 --- /dev/null +++ b/res/layout/drawer_left.xml @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/layout/drawer_right.xml b/res/layout/drawer_right.xml new file mode 100644 index 000000000..fd8e5bc24 --- /dev/null +++ b/res/layout/drawer_right.xml @@ -0,0 +1,42 @@ + + + + + + + + + + \ No newline at end of file From c83655d29c20263d875b3e6357e1355db4f07b7c Mon Sep 17 00:00:00 2001 From: Isaac Date: Sun, 3 Apr 2016 13:00:03 +0300 Subject: [PATCH 06/12] Android text search now displays recent searches from inital database implementation --- src/org/kiwix/kiwixmobile/SearchActivity.java | 57 ++++++++---- .../kiwixmobile/utils/DatabaseHelper.java | 87 +++++++++++++++++++ 2 files changed, 129 insertions(+), 15 deletions(-) create mode 100644 src/org/kiwix/kiwixmobile/utils/DatabaseHelper.java diff --git a/src/org/kiwix/kiwixmobile/SearchActivity.java b/src/org/kiwix/kiwixmobile/SearchActivity.java index 74144273d..4a1213f6d 100644 --- a/src/org/kiwix/kiwixmobile/SearchActivity.java +++ b/src/org/kiwix/kiwixmobile/SearchActivity.java @@ -1,5 +1,6 @@ package org.kiwix.kiwixmobile; +import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.support.v4.view.MenuItemCompat; @@ -10,14 +11,26 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; +import android.widget.ArrayAdapter; import android.widget.ListView; +import android.widget.TextView; + +import org.kiwix.kiwixmobile.utils.DatabaseHelper; import org.kiwix.kiwixmobile.views.AutoCompleteAdapter; +import java.util.ArrayList; + public class SearchActivity extends AppCompatActivity implements AdapterView.OnItemClickListener { private ListView mListView; - private AutoCompleteAdapter mAdapter; + private AutoCompleteAdapter mAutoAdapter; + + private ArrayAdapter mDefaultAdapter; + + private SearchActivity context; + + private DatabaseHelper mDatabaseHelper; @Override protected void onCreate(Bundle savedInstanceState) { @@ -28,10 +41,17 @@ public class SearchActivity extends AppCompatActivity implements AdapterView.OnI getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); + mListView = (ListView) findViewById(R.id.search_list); - mAdapter = new AutoCompleteAdapter(this); - mListView.setAdapter(mAdapter); - mListView.setOnItemClickListener(this); + mDatabaseHelper = new DatabaseHelper(this); + ArrayList a = mDatabaseHelper.getRecentSearches(); + mDefaultAdapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1); + mListView.setAdapter(mDefaultAdapter); + mDefaultAdapter.addAll(a); + mDefaultAdapter.notifyDataSetChanged(); + context = this; + mAutoAdapter = new AutoCompleteAdapter(context); + mListView.setOnItemClickListener(context); } @Override @@ -57,22 +77,28 @@ public class SearchActivity extends AppCompatActivity implements AdapterView.OnI @Override public boolean onQueryTextChange(String s) { - mAdapter.getFilter().filter(s); + if (s.equals("")) { + mListView.setAdapter(mDefaultAdapter); + } else { + mListView.setAdapter(mAutoAdapter); + mAutoAdapter.getFilter().filter(s); + } + return true; } }); MenuItemCompat.setOnActionExpandListener(searchMenuItem, - new MenuItemCompat.OnActionExpandListener() { - @Override - public boolean onMenuItemActionExpand(MenuItem item) { - return false; - } + new MenuItemCompat.OnActionExpandListener() { + @Override + public boolean onMenuItemActionExpand(MenuItem item) { + return false; + } - @Override - public boolean onMenuItemActionCollapse(MenuItem item) { - finish(); - return true; + @Override + public boolean onMenuItemActionCollapse(MenuItem item) { + finish(); + return true; } }); return true; @@ -80,7 +106,8 @@ public class SearchActivity extends AppCompatActivity implements AdapterView.OnI @Override public void onItemClick(AdapterView parent, View view, int position, long id) { - String title = mAdapter.getItemRaw(position); + String title = ((TextView) view).getText().toString(); + mDatabaseHelper.insertSearch(title); sendMessage(title); } diff --git a/src/org/kiwix/kiwixmobile/utils/DatabaseHelper.java b/src/org/kiwix/kiwixmobile/utils/DatabaseHelper.java new file mode 100644 index 000000000..25f9127e9 --- /dev/null +++ b/src/org/kiwix/kiwixmobile/utils/DatabaseHelper.java @@ -0,0 +1,87 @@ +package org.kiwix.kiwixmobile.utils; + +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; +import android.database.DatabaseUtils; + +import java.util.ArrayList; +import java.util.HashMap; + + + public class DatabaseHelper extends SQLiteOpenHelper { + + public static final String DATABASE_NAME = "Kiwix.db"; + public static final String CONTACTS_TABLE_NAME = "recentsearches"; + public static final String CONTACTS_COLUMN_ID = "id"; + public static final String CONTACTS_COLUMN_SEARCH = "search"; + + public DatabaseHelper(Context context) + { + super(context, DATABASE_NAME , null, 1); + } + + @Override + public void onCreate(SQLiteDatabase db) { + // TODO Auto-generated method stub + db.execSQL( + "create table " + CONTACTS_TABLE_NAME + + " (id integer primary key, search text)" + ); + } + + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + // TODO Auto-generated method stub + db.execSQL("DROP TABLE IF EXISTS " + CONTACTS_TABLE_NAME); + onCreate(db); + } + + public boolean insertSearch (String search) + { + SQLiteDatabase db = this.getWritableDatabase(); + ContentValues contentValues = new ContentValues(); + contentValues.put(CONTACTS_COLUMN_SEARCH, search); + db.insert(CONTACTS_TABLE_NAME, null, contentValues); + return true; + } + + public Cursor getData(int id){ + SQLiteDatabase db = this.getReadableDatabase(); + Cursor res = db.rawQuery( "select * from " + CONTACTS_TABLE_NAME + " where id="+id+"", null ); + return res; + } + + public int numberOfRows(){ + SQLiteDatabase db = this.getReadableDatabase(); + int numRows = (int) DatabaseUtils.queryNumEntries(db, CONTACTS_TABLE_NAME); + return numRows; + } + + public Integer deleteSearches (Integer id) + { + SQLiteDatabase db = this.getWritableDatabase(); + return db.delete(CONTACTS_TABLE_NAME, + "id = ? ", + new String[] { Integer.toString(id) }); + } + + public ArrayList getRecentSearches() + { + ArrayList array_list = new ArrayList(); + + //hp = new HashMap(); + SQLiteDatabase db = this.getReadableDatabase(); + Cursor res = db.rawQuery( "select * from " + CONTACTS_TABLE_NAME, null ); + res.moveToLast(); + + while(res.isBeforeFirst() == false){ + array_list.add(res.getString(res.getColumnIndex(CONTACTS_COLUMN_SEARCH))); + res.moveToPrevious(); + } + return array_list; + } + } + From 1fd4c9d0ea0fb7cdff654e32ade1c76d036fbe3b Mon Sep 17 00:00:00 2001 From: Isaac Date: Sun, 3 Apr 2016 13:08:33 +0300 Subject: [PATCH 07/12] Two space indentation --- .../kiwixmobile/utils/DatabaseHelper.java | 118 ++++++----- .../kiwix/kiwixmobile/utils/HTMLUtils.java | 190 +++++++++--------- 2 files changed, 153 insertions(+), 155 deletions(-) diff --git a/src/org/kiwix/kiwixmobile/utils/DatabaseHelper.java b/src/org/kiwix/kiwixmobile/utils/DatabaseHelper.java index 25f9127e9..fa3f2e398 100644 --- a/src/org/kiwix/kiwixmobile/utils/DatabaseHelper.java +++ b/src/org/kiwix/kiwixmobile/utils/DatabaseHelper.java @@ -11,77 +11,73 @@ import java.util.ArrayList; import java.util.HashMap; - public class DatabaseHelper extends SQLiteOpenHelper { +public class DatabaseHelper extends SQLiteOpenHelper { - public static final String DATABASE_NAME = "Kiwix.db"; - public static final String CONTACTS_TABLE_NAME = "recentsearches"; - public static final String CONTACTS_COLUMN_ID = "id"; - public static final String CONTACTS_COLUMN_SEARCH = "search"; + public static final String DATABASE_NAME = "Kiwix.db"; + public static final String CONTACTS_TABLE_NAME = "recentsearches"; + public static final String CONTACTS_COLUMN_ID = "id"; + public static final String CONTACTS_COLUMN_SEARCH = "search"; - public DatabaseHelper(Context context) - { - super(context, DATABASE_NAME , null, 1); - } + public DatabaseHelper(Context context) { + super(context, DATABASE_NAME, null, 1); + } - @Override - public void onCreate(SQLiteDatabase db) { - // TODO Auto-generated method stub - db.execSQL( - "create table " + CONTACTS_TABLE_NAME + - " (id integer primary key, search text)" - ); - } + @Override + public void onCreate(SQLiteDatabase db) { + // TODO Auto-generated method stub + db.execSQL( + "create table " + CONTACTS_TABLE_NAME + + " (id integer primary key, search text)" + ); + } - @Override - public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { - // TODO Auto-generated method stub - db.execSQL("DROP TABLE IF EXISTS " + CONTACTS_TABLE_NAME); - onCreate(db); - } + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + // TODO Auto-generated method stub + db.execSQL("DROP TABLE IF EXISTS " + CONTACTS_TABLE_NAME); + onCreate(db); + } - public boolean insertSearch (String search) - { - SQLiteDatabase db = this.getWritableDatabase(); - ContentValues contentValues = new ContentValues(); - contentValues.put(CONTACTS_COLUMN_SEARCH, search); - db.insert(CONTACTS_TABLE_NAME, null, contentValues); - return true; - } + public boolean insertSearch(String search) { + SQLiteDatabase db = this.getWritableDatabase(); + ContentValues contentValues = new ContentValues(); + contentValues.put(CONTACTS_COLUMN_SEARCH, search); + db.insert(CONTACTS_TABLE_NAME, null, contentValues); + return true; + } - public Cursor getData(int id){ - SQLiteDatabase db = this.getReadableDatabase(); - Cursor res = db.rawQuery( "select * from " + CONTACTS_TABLE_NAME + " where id="+id+"", null ); - return res; - } + public Cursor getData(int id) { + SQLiteDatabase db = this.getReadableDatabase(); + Cursor res = db.rawQuery("select * from " + CONTACTS_TABLE_NAME + " where id=" + id + "", null); + return res; + } - public int numberOfRows(){ - SQLiteDatabase db = this.getReadableDatabase(); - int numRows = (int) DatabaseUtils.queryNumEntries(db, CONTACTS_TABLE_NAME); - return numRows; - } + public int numberOfRows() { + SQLiteDatabase db = this.getReadableDatabase(); + int numRows = (int) DatabaseUtils.queryNumEntries(db, CONTACTS_TABLE_NAME); + return numRows; + } - public Integer deleteSearches (Integer id) - { - SQLiteDatabase db = this.getWritableDatabase(); - return db.delete(CONTACTS_TABLE_NAME, - "id = ? ", - new String[] { Integer.toString(id) }); - } + public Integer deleteSearches(Integer id) { + SQLiteDatabase db = this.getWritableDatabase(); + return db.delete(CONTACTS_TABLE_NAME, + "id = ? ", + new String[]{Integer.toString(id)}); + } - public ArrayList getRecentSearches() - { - ArrayList array_list = new ArrayList(); + public ArrayList getRecentSearches() { + ArrayList array_list = new ArrayList(); - //hp = new HashMap(); - SQLiteDatabase db = this.getReadableDatabase(); - Cursor res = db.rawQuery( "select * from " + CONTACTS_TABLE_NAME, null ); - res.moveToLast(); + //hp = new HashMap(); + SQLiteDatabase db = this.getReadableDatabase(); + Cursor res = db.rawQuery("select * from " + CONTACTS_TABLE_NAME, null); + res.moveToLast(); - while(res.isBeforeFirst() == false){ - array_list.add(res.getString(res.getColumnIndex(CONTACTS_COLUMN_SEARCH))); - res.moveToPrevious(); - } - return array_list; - } + while (res.isBeforeFirst() == false) { + array_list.add(res.getString(res.getColumnIndex(CONTACTS_COLUMN_SEARCH))); + res.moveToPrevious(); } + return array_list; + } +} diff --git a/src/org/kiwix/kiwixmobile/utils/HTMLUtils.java b/src/org/kiwix/kiwixmobile/utils/HTMLUtils.java index 1041845c0..5a4cad369 100644 --- a/src/org/kiwix/kiwixmobile/utils/HTMLUtils.java +++ b/src/org/kiwix/kiwixmobile/utils/HTMLUtils.java @@ -20,107 +20,109 @@ import java.util.List; public class HTMLUtils { - private List sectionProperties; - private List textViews; - private ArrayAdapter arrayAdapter; - private KiwixMobileActivity context; - private Handler mHandler; - private ListView mRightListView; - private TextView headerView; + private List sectionProperties; + private List textViews; + private ArrayAdapter arrayAdapter; + private KiwixMobileActivity context; + private Handler mHandler; + private ListView mRightListView; + private TextView headerView; - public HTMLUtils(List sectionProperties, List textViews, ListView listView, KiwixMobileActivity context, Handler handler) { - this.sectionProperties = sectionProperties; - this.textViews = textViews; - this.mRightListView = listView; - this.arrayAdapter = (ArrayAdapter) listView.getAdapter(); - this.context = context; - this.mHandler = handler; + public HTMLUtils(List sectionProperties, List textViews, ListView listView, KiwixMobileActivity context, Handler handler) { + this.sectionProperties = sectionProperties; + this.textViews = textViews; + this.mRightListView = listView; + this.arrayAdapter = (ArrayAdapter) listView.getAdapter(); + this.context = context; + this.mHandler = handler; + } + + public void initInterface(WebView webView) { + webView.addJavascriptInterface(new HTMLinterface(), "HTMLUtils"); + } + + + class HTMLinterface { + int i = 0; + + @JavascriptInterface + @SuppressWarnings("unused") + public void parse(final String sectionTitle, final String element, final String id) { + mHandler.post(new Runnable() { + @Override + public void run() { + if (element.equals("H1")) { + mRightListView.removeHeaderView(headerView); + LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + View view = inflater.inflate(R.layout.section_list, null); + headerView = (TextView) view.findViewById(R.id.textTab); + headerView.setText(sectionTitle); + headerView.setPadding((int) (26 * context.getResources().getDisplayMetrics().density), 0, 0, 0); + headerView.setBackgroundColor(Color.LTGRAY); + headerView.setTypeface(Typeface.DEFAULT_BOLD); + headerView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + context.getCurrentWebView().setScrollY(0); + context.mRightDrawerLayout.closeDrawer(Gravity.RIGHT); + } + }); + mRightListView.addHeaderView(headerView); + } else { + textViews.add(i, new TextView(context)); + sectionProperties.add(i, new KiwixMobileActivity.SectionProperties()); + KiwixMobileActivity.SectionProperties section = sectionProperties.get(i); + section.sectionTitle = sectionTitle; + section.sectionId = id; + switch (element) { + case "H2": + section.leftPadding = (int) (30 * context.getResources().getDisplayMetrics().density); + section.typeface = Typeface.DEFAULT; + section.color = Color.BLACK; + break; + case "H3": + section.leftPadding = (int) (50 * context.getResources().getDisplayMetrics().density); + section.typeface = Typeface.DEFAULT; + section.color = Color.GRAY; + break; + default: + section.leftPadding = (int) (30 * context.getResources().getDisplayMetrics().density); + section.typeface = Typeface.DEFAULT; + section.color = Color.BLACK; + break; + } + i++; + } + } + }); } - public void initInterface(WebView webView){ - webView.addJavascriptInterface(new HTMLinterface(), "HTMLUtils"); + @JavascriptInterface + @SuppressWarnings("unused") + public void start() { + mHandler.post(new Runnable() { + @Override + public void run() { + i = 0; + textViews.clear(); + sectionProperties.clear(); + arrayAdapter.clear(); + arrayAdapter.notifyDataSetChanged(); + } + }); } - - class HTMLinterface - { - int i = 0; - @JavascriptInterface - @SuppressWarnings("unused") - public void parse(final String sectionTitle, final String element,final String id) { - mHandler.post(new Runnable() { - @Override - public void run() { - if (element.equals("H1")) { - mRightListView.removeHeaderView(headerView); - LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE ); - View view = inflater.inflate( R.layout.section_list, null ); - headerView = (TextView) view.findViewById( R.id.textTab ); - headerView.setText(sectionTitle); - headerView.setPadding((int) (26 * context.getResources().getDisplayMetrics().density), 0, 0, 0); - headerView.setBackgroundColor(Color.LTGRAY); - headerView.setTypeface(Typeface.DEFAULT_BOLD); - headerView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - context.getCurrentWebView().setScrollY(0); - context.mRightDrawerLayout.closeDrawer(Gravity.RIGHT); - } - }); - mRightListView.addHeaderView(headerView); - } else { - textViews.add(i, new TextView(context)); - sectionProperties.add(i, new KiwixMobileActivity.SectionProperties()); - KiwixMobileActivity.SectionProperties section = sectionProperties.get(i); - section.sectionTitle = sectionTitle; - section.sectionId = id; - switch (element) { - case "H2": - section.leftPadding = (int) (30 * context.getResources().getDisplayMetrics().density); - section.typeface = Typeface.DEFAULT; - section.color = Color.BLACK; - break; - case "H3": - section.leftPadding = (int) (50 * context.getResources().getDisplayMetrics().density); - section.typeface = Typeface.DEFAULT; - section.color = Color.GRAY; - break; - default: - section.leftPadding = (int) (30 * context.getResources().getDisplayMetrics().density); - section.typeface = Typeface.DEFAULT; - section.color = Color.BLACK; - break; - } - i++; - } - } - }); - } - @JavascriptInterface - @SuppressWarnings("unused") - public void start() { - mHandler.post(new Runnable() { - @Override - public void run() { - i=0; - textViews.clear(); - sectionProperties.clear(); - arrayAdapter.clear(); - arrayAdapter.notifyDataSetChanged(); - } - }); - } - @JavascriptInterface - @SuppressWarnings("unused") - public void stop() { - mHandler.post(new Runnable() { - @Override - public void run() { - arrayAdapter.notifyDataSetChanged(); - } - }); + @JavascriptInterface + @SuppressWarnings("unused") + public void stop() { + mHandler.post(new Runnable() { + @Override + public void run() { + arrayAdapter.notifyDataSetChanged(); } + }); } + } } From 4f049b3c86281d4238d8634c0873d6477108c623 Mon Sep 17 00:00:00 2001 From: Isaac Date: Sun, 3 Apr 2016 13:15:58 +0300 Subject: [PATCH 08/12] Merged new features from wmhack to master --- .../kiwixmobile/KiwixMobileActivity.java | 189 +++++++++++++++--- 1 file changed, 159 insertions(+), 30 deletions(-) diff --git a/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java b/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java index 4e7ca973e..fd864dcf2 100644 --- a/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java +++ b/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java @@ -20,6 +20,7 @@ package org.kiwix.kiwixmobile; import android.app.Activity; +import android.app.Dialog; import android.content.ActivityNotFoundException; import android.content.Context; import android.content.DialogInterface; @@ -36,6 +37,7 @@ import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.preference.PreferenceManager; +import android.support.design.widget.Snackbar; import android.support.v4.view.GravityCompat; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarDrawerToggle; @@ -68,6 +70,7 @@ import android.widget.Button; import android.widget.FrameLayout; import android.widget.ImageButton; import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.ListView; import android.widget.RelativeLayout; import android.widget.TextView; @@ -83,6 +86,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Locale; +import java.util.prefs.Preferences; import org.json.JSONArray; import org.kiwix.kiwixmobile.settings.Constants; import org.kiwix.kiwixmobile.settings.KiwixSettingsActivity; @@ -91,6 +95,7 @@ import org.kiwix.kiwixmobile.utils.KiwixTextToSpeech; import org.kiwix.kiwixmobile.utils.LanguageUtils; import org.kiwix.kiwixmobile.utils.files.FileReader; import org.kiwix.kiwixmobile.utils.files.FileUtils; +import org.kiwix.kiwixmobile.utils.files.RateAppCounter; import org.kiwix.kiwixmobile.views.AnimatedProgressBar; import org.kiwix.kiwixmobile.views.CompatFindActionModeCallback; import org.kiwix.kiwixmobile.views.KiwixWebView; @@ -192,7 +197,10 @@ public class KiwixMobileActivity extends AppCompatActivity // Initialized when onActionModeStarted is triggered. private ActionMode mActionMode = null; - + private KiwixWebView tempForUndo; + private LinearLayout snackbarLayout; + private RateAppCounter visitCounterPref; + private int tempVisitCount; @Override public void onActionModeStarted(ActionMode mode) { if (mActionMode == null) { @@ -240,6 +248,17 @@ public class KiwixMobileActivity extends AppCompatActivity toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); + + visitCounterPref = new RateAppCounter(this); + tempVisitCount = visitCounterPref.getCount(); + ++tempVisitCount; + visitCounterPref.setCount(tempVisitCount); + + if(tempVisitCount >= 5 && !visitCounterPref.getNoThanksState()){ + showRateDialog(this,visitCounterPref.getEditor()); + } + + bookmarks = new ArrayList<>(); requestClearHistoryAfterLoad = false; requestWebReloadOnFinished = 0; @@ -256,6 +275,11 @@ public class KiwixMobileActivity extends AppCompatActivity FileReader fileReader = new FileReader(); jsContent = fileReader.readFile("www/js/jsfile.js", this); + tempForUndo = + new KiwixWebView(getApplicationContext()); /** initializing temporary tab value **/ + snackbarLayout = + (LinearLayout) findViewById(R.id.linearlayout_main); /** Linear layout definition**/ + RelativeLayout newTabButton = (RelativeLayout) findViewById(R.id.new_tab_button); newTabButton.setOnClickListener(new View.OnClickListener() { @@ -366,6 +390,73 @@ public class KiwixMobileActivity extends AppCompatActivity updateTitle(ZimContentProvider.getZimFileTitle()); } + public void showRateDialog(final Context mContext, final SharedPreferences.Editor editor) { + AlertDialog alertDialog = new AlertDialog.Builder(mContext).create(); + + alertDialog.setTitle("Please Rate"); + + alertDialog.setMessage("If you enjoy using " + + getString(R.string.app_name) + + ", please take a moment to rate it. Thanks for your support!"); + + alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Rate!", + new DialogInterface.OnClickListener() { + + public void onClick(DialogInterface dialog, int id) { + visitCounterPref.setNoThanksState(true); + goToRateApp(); + + } + }); + + alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "No, thanks", + new DialogInterface.OnClickListener() { + + public void onClick(DialogInterface dialog, int id) { + + visitCounterPref.setNoThanksState(true); + + } + }); + + alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "Remind me later", + new DialogInterface.OnClickListener() { + + public void onClick(DialogInterface dialog, int id) { + + tempVisitCount = 0; + visitCounterPref.setCount(tempVisitCount); + + } + }); + + + + alertDialog.show(); + + + + + } + + private void goToRateApp() { + + Uri uri = Uri.parse("market://details?id=" + getPackageName()); + Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri); + + goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | + Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET | + Intent.FLAG_ACTIVITY_MULTIPLE_TASK); + + try { + startActivity(goToMarket); + } catch (ActivityNotFoundException e) { + startActivity(new Intent(Intent.ACTION_VIEW, + Uri.parse("http://play.google.com/store/apps/details?id=" + getPackageName()))); + } + + } + private void updateTitle(String zimFileTitle) { if (zimFileTitle == null || zimFileTitle.trim().isEmpty()) { getSupportActionBar().setTitle(getString(R.string.app_name)); @@ -447,19 +538,42 @@ public class KiwixMobileActivity extends AppCompatActivity return webView; } + private KiwixWebView restoreTabAtIndex(String url, int index) { + KiwixWebView webView = new KiwixWebView(KiwixMobileActivity.this); + webView.setWebViewClient(new KiwixWebViewClient(KiwixMobileActivity.this, mLeftArrayAdapter)); + webView.setWebChromeClient(new KiwixWebChromeClient()); + webView.loadUrl(url); + webView.loadPrefs(); + + mWebViews.add(index,webView); + mLeftArrayAdapter.notifyDataSetChanged(); + selectTab(mWebViews.size() - 1); + setUpWebView(); + return webView; + } + private void closeTab(int index) { if (mWebViews.size() > 1) { if (mCurrentWebViewIndex == index) { if (mCurrentWebViewIndex >= 1) { selectTab(mCurrentWebViewIndex - 1); + + tempForUndo = mWebViews.get(index); + mWebViews.remove(index); + undoSnackbar(index); + } else { selectTab(mCurrentWebViewIndex + 1); mWebViews.remove(index); + } } else { + tempForUndo = mWebViews.get(index); mWebViews.remove(index); + selectTab(mCurrentWebViewIndex - 1); + undoSnackbar(index); if (index < mCurrentWebViewIndex) { mCurrentWebViewIndex--; } @@ -473,6 +587,20 @@ public class KiwixMobileActivity extends AppCompatActivity mLeftArrayAdapter.notifyDataSetChanged(); } + private void undoSnackbar(final int index) { + Snackbar undoSnackbar = + Snackbar.make(snackbarLayout, "Tab closed", Snackbar.LENGTH_LONG) + .setAction("Undo", new View.OnClickListener() { + @Override + public void onClick(View v) { + restoreTabAtIndex(tempForUndo.getUrl(), index); + selectTab(index); + } + }); + undoSnackbar.setActionTextColor(getResources().getColor(R.color.white_undo)); + undoSnackbar.show(); + } + private void selectTab(int position) { mCurrentWebViewIndex = position; mLeftDrawerList.setItemChecked(position, true); @@ -1022,16 +1150,19 @@ public class KiwixMobileActivity extends AppCompatActivity break; case REQUEST_FILE_SEARCH: if (resultCode == RESULT_OK) { - String title = data.getStringExtra(TAG_FILE_SEARCHED).replace("", "").replace("", ""); - String articleUrl = ""; + String title = + data.getStringExtra(TAG_FILE_SEARCHED).replace("", "").replace("", ""); + String articleUrl = ""; - if(title.startsWith("A/")) { - articleUrl = title; - } else articleUrl = ZimContentProvider.getPageUrlFromTitle(title); + if (title.startsWith("A/")) { + articleUrl = title; + } else { + articleUrl = ZimContentProvider.getPageUrlFromTitle(title); + } - //System.out.println("Opening "+articleUrl + " (" + title + ")"); + //System.out.println("Opening "+articleUrl + " (" + title + ")"); - openArticle(articleUrl); + openArticle(articleUrl); } break; case REQUEST_PREFERENCES: @@ -1160,13 +1291,13 @@ public class KiwixMobileActivity extends AppCompatActivity startActivityForResult(i, REQUEST_PREFERENCES); } - public void saveTabStates(){ + public void saveTabStates() { SharedPreferences settings = getSharedPreferences(PREF_KIWIX_MOBILE, 0); SharedPreferences.Editor editor = settings.edit(); JSONArray urls = new JSONArray(); JSONArray positions = new JSONArray(); - for (KiwixWebView view : mWebViews){ + for (KiwixWebView view : mWebViews) { urls.put(view.getUrl()); positions.put(view.getScrollY()); } @@ -1180,26 +1311,28 @@ public class KiwixMobileActivity extends AppCompatActivity editor.apply(); } - public void restoreTabStates(){ + public void restoreTabStates() { SharedPreferences settings = getSharedPreferences(PREF_KIWIX_MOBILE, 0); String zimFile = settings.getString(TAG_CURRENT_FILE, null); String zimArticles = settings.getString(TAG_CURRENT_ARTICLES, null); String zimPositions = settings.getString(TAG_CURRENT_POSITIONS, null); - int currentTab = settings.getInt(TAG_CURRENT_TAB, 0 ); + + int currentTab = settings.getInt(TAG_CURRENT_TAB, 0); + openZimFile(new File(zimFile), false); try { JSONArray urls = new JSONArray(zimArticles); JSONArray positions = new JSONArray(zimPositions); - int i=0; + int i = 0; getCurrentWebView().loadUrl(urls.getString(i)); getCurrentWebView().setScrollY(positions.getInt(i)); i++; - for (;i Open last used zimFile " - + zimFile); + " Kiwix normal start, zimFile loaded last time -> Open last used zimFile " + + zimFile); restoreTabStates(); // Alternative would be to restore webView state. But more effort to implement, and actually // fits better normal android behavior if after closing app ("back" button) state is not maintained. @@ -1270,15 +1403,14 @@ public class KiwixMobileActivity extends AppCompatActivity zimFileMissingBuilder .setPositiveButton(getString(R.string.go_to_play_store), new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - String market_uri = "market://details?id=" - + Constants.CUSTOM_APP_ID; - Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse(market_uri)); - startActivity(intent); - activity.finish(); - System.exit(0); - } + public void onClick(DialogInterface dialog, int which) { + String market_uri = "market://details?id=" + Constants.CUSTOM_APP_ID; + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setData(Uri.parse(market_uri)); + startActivity(intent); + activity.finish(); + System.exit(0); + } }); zimFileMissingBuilder.setCancelable(false); AlertDialog zimFileMissingDialog = zimFileMissingBuilder.create(); @@ -1295,8 +1427,6 @@ public class KiwixMobileActivity extends AppCompatActivity } } - - @Override public void onPause() { super.onPause(); @@ -1395,8 +1525,7 @@ public class KiwixMobileActivity extends AppCompatActivity String failingUrl) { String errorString = String - .format(getResources().getString(R.string.error_articleurlnotfound), - failingUrl); + .format(getResources().getString(R.string.error_articleurlnotfound), failingUrl); // TODO apparently screws up back/forward getCurrentWebView().loadDataWithBaseURL("file://error", "" + errorString + "", "text/html", "utf-8", From 5225c719ace881f64c93d037e2d752598706aeea Mon Sep 17 00:00:00 2001 From: Isaac Date: Sun, 3 Apr 2016 13:19:59 +0300 Subject: [PATCH 09/12] More mergeing --- .../utils/files/RateAppCounter.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/org/kiwix/kiwixmobile/utils/files/RateAppCounter.java diff --git a/src/org/kiwix/kiwixmobile/utils/files/RateAppCounter.java b/src/org/kiwix/kiwixmobile/utils/files/RateAppCounter.java new file mode 100644 index 000000000..5225fb986 --- /dev/null +++ b/src/org/kiwix/kiwixmobile/utils/files/RateAppCounter.java @@ -0,0 +1,39 @@ +package org.kiwix.kiwixmobile.utils.files; + +import android.content.Context; +import android.content.SharedPreferences; + + +public class RateAppCounter { + + String MASTER_NAME = "visitCounter"; + String NOTHANKS_CLICKED = "clickedNoThanks"; + SharedPreferences visitCounter; + + public RateAppCounter(Context context) { + visitCounter = context.getSharedPreferences(MASTER_NAME, 0); + visitCounter = context.getSharedPreferences(NOTHANKS_CLICKED,0); + } + + public boolean getNoThanksState(){ + return visitCounter.getBoolean(NOTHANKS_CLICKED, false); + } + public void setNoThanksState(boolean val){ + SharedPreferences.Editor CounterEditor = visitCounter.edit(); + CounterEditor.putBoolean(NOTHANKS_CLICKED, val); + CounterEditor.commit(); + } + public void setCount(int count) { + SharedPreferences.Editor CounterEditor = visitCounter.edit(); + CounterEditor.putInt("count", count); + CounterEditor.commit(); + + } + public SharedPreferences.Editor getEditor(){ + return visitCounter.edit(); + } + + public int getCount() { + return visitCounter.getInt("count", 0); + } +} From abaa3da9ab46b7fc2bbd8c04d2031e754da3db3a Mon Sep 17 00:00:00 2001 From: Isaac Date: Sun, 3 Apr 2016 13:22:52 +0300 Subject: [PATCH 10/12] Revert "Merged new features from wmhack to master" This reverts commit 7b4fcd90c38641b8dc9d29661587149ed71b0f0d. --- .../kiwixmobile/KiwixMobileActivity.java | 189 +++--------------- 1 file changed, 30 insertions(+), 159 deletions(-) diff --git a/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java b/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java index fd864dcf2..4e7ca973e 100644 --- a/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java +++ b/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java @@ -20,7 +20,6 @@ package org.kiwix.kiwixmobile; import android.app.Activity; -import android.app.Dialog; import android.content.ActivityNotFoundException; import android.content.Context; import android.content.DialogInterface; @@ -37,7 +36,6 @@ import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.preference.PreferenceManager; -import android.support.design.widget.Snackbar; import android.support.v4.view.GravityCompat; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarDrawerToggle; @@ -70,7 +68,6 @@ import android.widget.Button; import android.widget.FrameLayout; import android.widget.ImageButton; import android.widget.ImageView; -import android.widget.LinearLayout; import android.widget.ListView; import android.widget.RelativeLayout; import android.widget.TextView; @@ -86,7 +83,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Locale; -import java.util.prefs.Preferences; import org.json.JSONArray; import org.kiwix.kiwixmobile.settings.Constants; import org.kiwix.kiwixmobile.settings.KiwixSettingsActivity; @@ -95,7 +91,6 @@ import org.kiwix.kiwixmobile.utils.KiwixTextToSpeech; import org.kiwix.kiwixmobile.utils.LanguageUtils; import org.kiwix.kiwixmobile.utils.files.FileReader; import org.kiwix.kiwixmobile.utils.files.FileUtils; -import org.kiwix.kiwixmobile.utils.files.RateAppCounter; import org.kiwix.kiwixmobile.views.AnimatedProgressBar; import org.kiwix.kiwixmobile.views.CompatFindActionModeCallback; import org.kiwix.kiwixmobile.views.KiwixWebView; @@ -197,10 +192,7 @@ public class KiwixMobileActivity extends AppCompatActivity // Initialized when onActionModeStarted is triggered. private ActionMode mActionMode = null; - private KiwixWebView tempForUndo; - private LinearLayout snackbarLayout; - private RateAppCounter visitCounterPref; - private int tempVisitCount; + @Override public void onActionModeStarted(ActionMode mode) { if (mActionMode == null) { @@ -248,17 +240,6 @@ public class KiwixMobileActivity extends AppCompatActivity toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); - - visitCounterPref = new RateAppCounter(this); - tempVisitCount = visitCounterPref.getCount(); - ++tempVisitCount; - visitCounterPref.setCount(tempVisitCount); - - if(tempVisitCount >= 5 && !visitCounterPref.getNoThanksState()){ - showRateDialog(this,visitCounterPref.getEditor()); - } - - bookmarks = new ArrayList<>(); requestClearHistoryAfterLoad = false; requestWebReloadOnFinished = 0; @@ -275,11 +256,6 @@ public class KiwixMobileActivity extends AppCompatActivity FileReader fileReader = new FileReader(); jsContent = fileReader.readFile("www/js/jsfile.js", this); - tempForUndo = - new KiwixWebView(getApplicationContext()); /** initializing temporary tab value **/ - snackbarLayout = - (LinearLayout) findViewById(R.id.linearlayout_main); /** Linear layout definition**/ - RelativeLayout newTabButton = (RelativeLayout) findViewById(R.id.new_tab_button); newTabButton.setOnClickListener(new View.OnClickListener() { @@ -390,73 +366,6 @@ public class KiwixMobileActivity extends AppCompatActivity updateTitle(ZimContentProvider.getZimFileTitle()); } - public void showRateDialog(final Context mContext, final SharedPreferences.Editor editor) { - AlertDialog alertDialog = new AlertDialog.Builder(mContext).create(); - - alertDialog.setTitle("Please Rate"); - - alertDialog.setMessage("If you enjoy using " - + getString(R.string.app_name) - + ", please take a moment to rate it. Thanks for your support!"); - - alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Rate!", - new DialogInterface.OnClickListener() { - - public void onClick(DialogInterface dialog, int id) { - visitCounterPref.setNoThanksState(true); - goToRateApp(); - - } - }); - - alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "No, thanks", - new DialogInterface.OnClickListener() { - - public void onClick(DialogInterface dialog, int id) { - - visitCounterPref.setNoThanksState(true); - - } - }); - - alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "Remind me later", - new DialogInterface.OnClickListener() { - - public void onClick(DialogInterface dialog, int id) { - - tempVisitCount = 0; - visitCounterPref.setCount(tempVisitCount); - - } - }); - - - - alertDialog.show(); - - - - - } - - private void goToRateApp() { - - Uri uri = Uri.parse("market://details?id=" + getPackageName()); - Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri); - - goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | - Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET | - Intent.FLAG_ACTIVITY_MULTIPLE_TASK); - - try { - startActivity(goToMarket); - } catch (ActivityNotFoundException e) { - startActivity(new Intent(Intent.ACTION_VIEW, - Uri.parse("http://play.google.com/store/apps/details?id=" + getPackageName()))); - } - - } - private void updateTitle(String zimFileTitle) { if (zimFileTitle == null || zimFileTitle.trim().isEmpty()) { getSupportActionBar().setTitle(getString(R.string.app_name)); @@ -538,42 +447,19 @@ public class KiwixMobileActivity extends AppCompatActivity return webView; } - private KiwixWebView restoreTabAtIndex(String url, int index) { - KiwixWebView webView = new KiwixWebView(KiwixMobileActivity.this); - webView.setWebViewClient(new KiwixWebViewClient(KiwixMobileActivity.this, mLeftArrayAdapter)); - webView.setWebChromeClient(new KiwixWebChromeClient()); - webView.loadUrl(url); - webView.loadPrefs(); - - mWebViews.add(index,webView); - mLeftArrayAdapter.notifyDataSetChanged(); - selectTab(mWebViews.size() - 1); - setUpWebView(); - return webView; - } - private void closeTab(int index) { if (mWebViews.size() > 1) { if (mCurrentWebViewIndex == index) { if (mCurrentWebViewIndex >= 1) { selectTab(mCurrentWebViewIndex - 1); - - tempForUndo = mWebViews.get(index); - mWebViews.remove(index); - undoSnackbar(index); - } else { selectTab(mCurrentWebViewIndex + 1); mWebViews.remove(index); - } } else { - tempForUndo = mWebViews.get(index); mWebViews.remove(index); - selectTab(mCurrentWebViewIndex - 1); - undoSnackbar(index); if (index < mCurrentWebViewIndex) { mCurrentWebViewIndex--; } @@ -587,20 +473,6 @@ public class KiwixMobileActivity extends AppCompatActivity mLeftArrayAdapter.notifyDataSetChanged(); } - private void undoSnackbar(final int index) { - Snackbar undoSnackbar = - Snackbar.make(snackbarLayout, "Tab closed", Snackbar.LENGTH_LONG) - .setAction("Undo", new View.OnClickListener() { - @Override - public void onClick(View v) { - restoreTabAtIndex(tempForUndo.getUrl(), index); - selectTab(index); - } - }); - undoSnackbar.setActionTextColor(getResources().getColor(R.color.white_undo)); - undoSnackbar.show(); - } - private void selectTab(int position) { mCurrentWebViewIndex = position; mLeftDrawerList.setItemChecked(position, true); @@ -1150,19 +1022,16 @@ public class KiwixMobileActivity extends AppCompatActivity break; case REQUEST_FILE_SEARCH: if (resultCode == RESULT_OK) { - String title = - data.getStringExtra(TAG_FILE_SEARCHED).replace("", "").replace("", ""); - String articleUrl = ""; + String title = data.getStringExtra(TAG_FILE_SEARCHED).replace("", "").replace("", ""); + String articleUrl = ""; - if (title.startsWith("A/")) { - articleUrl = title; - } else { - articleUrl = ZimContentProvider.getPageUrlFromTitle(title); - } + if(title.startsWith("A/")) { + articleUrl = title; + } else articleUrl = ZimContentProvider.getPageUrlFromTitle(title); - //System.out.println("Opening "+articleUrl + " (" + title + ")"); + //System.out.println("Opening "+articleUrl + " (" + title + ")"); - openArticle(articleUrl); + openArticle(articleUrl); } break; case REQUEST_PREFERENCES: @@ -1291,13 +1160,13 @@ public class KiwixMobileActivity extends AppCompatActivity startActivityForResult(i, REQUEST_PREFERENCES); } - public void saveTabStates() { + public void saveTabStates(){ SharedPreferences settings = getSharedPreferences(PREF_KIWIX_MOBILE, 0); SharedPreferences.Editor editor = settings.edit(); JSONArray urls = new JSONArray(); JSONArray positions = new JSONArray(); - for (KiwixWebView view : mWebViews) { + for (KiwixWebView view : mWebViews){ urls.put(view.getUrl()); positions.put(view.getScrollY()); } @@ -1311,28 +1180,26 @@ public class KiwixMobileActivity extends AppCompatActivity editor.apply(); } - public void restoreTabStates() { + public void restoreTabStates(){ SharedPreferences settings = getSharedPreferences(PREF_KIWIX_MOBILE, 0); String zimFile = settings.getString(TAG_CURRENT_FILE, null); String zimArticles = settings.getString(TAG_CURRENT_ARTICLES, null); String zimPositions = settings.getString(TAG_CURRENT_POSITIONS, null); - - int currentTab = settings.getInt(TAG_CURRENT_TAB, 0); - + int currentTab = settings.getInt(TAG_CURRENT_TAB, 0 ); openZimFile(new File(zimFile), false); try { JSONArray urls = new JSONArray(zimArticles); JSONArray positions = new JSONArray(zimPositions); - int i = 0; + int i=0; getCurrentWebView().loadUrl(urls.getString(i)); getCurrentWebView().setScrollY(positions.getInt(i)); i++; - for (; i < urls.length(); i++) { + for (;i Open last used zimFile " - + zimFile); + " Kiwix normal start, zimFile loaded last time -> Open last used zimFile " + + zimFile); restoreTabStates(); // Alternative would be to restore webView state. But more effort to implement, and actually // fits better normal android behavior if after closing app ("back" button) state is not maintained. @@ -1403,14 +1270,15 @@ public class KiwixMobileActivity extends AppCompatActivity zimFileMissingBuilder .setPositiveButton(getString(R.string.go_to_play_store), new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - String market_uri = "market://details?id=" + Constants.CUSTOM_APP_ID; - Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse(market_uri)); - startActivity(intent); - activity.finish(); - System.exit(0); - } + public void onClick(DialogInterface dialog, int which) { + String market_uri = "market://details?id=" + + Constants.CUSTOM_APP_ID; + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setData(Uri.parse(market_uri)); + startActivity(intent); + activity.finish(); + System.exit(0); + } }); zimFileMissingBuilder.setCancelable(false); AlertDialog zimFileMissingDialog = zimFileMissingBuilder.create(); @@ -1427,6 +1295,8 @@ public class KiwixMobileActivity extends AppCompatActivity } } + + @Override public void onPause() { super.onPause(); @@ -1525,7 +1395,8 @@ public class KiwixMobileActivity extends AppCompatActivity String failingUrl) { String errorString = String - .format(getResources().getString(R.string.error_articleurlnotfound), failingUrl); + .format(getResources().getString(R.string.error_articleurlnotfound), + failingUrl); // TODO apparently screws up back/forward getCurrentWebView().loadDataWithBaseURL("file://error", "" + errorString + "", "text/html", "utf-8", From aca353b989df762f46d213a31620c3baf8f68329 Mon Sep 17 00:00:00 2001 From: Isaac Date: Sun, 3 Apr 2016 13:23:37 +0300 Subject: [PATCH 11/12] Revert "More mergeing" This reverts commit c8b3fb3ec0b286873482e7b41b8954283c9b6b90. --- .../utils/files/RateAppCounter.java | 39 ------------------- 1 file changed, 39 deletions(-) delete mode 100644 src/org/kiwix/kiwixmobile/utils/files/RateAppCounter.java diff --git a/src/org/kiwix/kiwixmobile/utils/files/RateAppCounter.java b/src/org/kiwix/kiwixmobile/utils/files/RateAppCounter.java deleted file mode 100644 index 5225fb986..000000000 --- a/src/org/kiwix/kiwixmobile/utils/files/RateAppCounter.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.kiwix.kiwixmobile.utils.files; - -import android.content.Context; -import android.content.SharedPreferences; - - -public class RateAppCounter { - - String MASTER_NAME = "visitCounter"; - String NOTHANKS_CLICKED = "clickedNoThanks"; - SharedPreferences visitCounter; - - public RateAppCounter(Context context) { - visitCounter = context.getSharedPreferences(MASTER_NAME, 0); - visitCounter = context.getSharedPreferences(NOTHANKS_CLICKED,0); - } - - public boolean getNoThanksState(){ - return visitCounter.getBoolean(NOTHANKS_CLICKED, false); - } - public void setNoThanksState(boolean val){ - SharedPreferences.Editor CounterEditor = visitCounter.edit(); - CounterEditor.putBoolean(NOTHANKS_CLICKED, val); - CounterEditor.commit(); - } - public void setCount(int count) { - SharedPreferences.Editor CounterEditor = visitCounter.edit(); - CounterEditor.putInt("count", count); - CounterEditor.commit(); - - } - public SharedPreferences.Editor getEditor(){ - return visitCounter.edit(); - } - - public int getCount() { - return visitCounter.getInt("count", 0); - } -} From 7ae42510f8aec37e927c6c1b203bdf9d5a666760 Mon Sep 17 00:00:00 2001 From: Isaac Date: Sun, 3 Apr 2016 13:28:57 +0300 Subject: [PATCH 12/12] Added additional javascript file that is loaded into android app --- assets/www/js/jsfile.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 assets/www/js/jsfile.js diff --git a/assets/www/js/jsfile.js b/assets/www/js/jsfile.js new file mode 100644 index 000000000..1ced46cbf --- /dev/null +++ b/assets/www/js/jsfile.js @@ -0,0 +1,12 @@ +function() { + window.onload = onLoad(); + + function onLoad() { + window.HTMLUtils.start(); + for (i=0; i