mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 18:56:44 -04:00
Merge branch 'wmhack'
This commit is contained in:
commit
c06e2b4578
12
assets/www/js/jsfile.js
Normal file
12
assets/www/js/jsfile.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
function() {
|
||||||
|
window.onload = onLoad();
|
||||||
|
|
||||||
|
function onLoad() {
|
||||||
|
window.HTMLUtils.start();
|
||||||
|
for (i=0; i<document.querySelectorAll('h1, h2, h3, h4, h5, h6').length; i++) {
|
||||||
|
headerObject = document.querySelectorAll('h1, h2, h3, h4, h5, h6')[i];
|
||||||
|
window.HTMLUtils.parse(headerObject.textContent, headerObject.tagName, headerObject.id);
|
||||||
|
}
|
||||||
|
window.HTMLUtils.stop();
|
||||||
|
}
|
||||||
|
}
|
@ -55,7 +55,8 @@
|
|||||||
android:paddingLeft="4dp"
|
android:paddingLeft="4dp"
|
||||||
android:paddingRight="4dp"
|
android:paddingRight="4dp"
|
||||||
android:paddingTop="4dp"
|
android:paddingTop="4dp"
|
||||||
android:src="?attr/arrowBackDrawable"/>
|
android:src="?attr/arrowBackDrawable"
|
||||||
|
android:id="@+id/action_back_button" />
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
@ -94,7 +95,8 @@
|
|||||||
android:paddingLeft="4dp"
|
android:paddingLeft="4dp"
|
||||||
android:paddingRight="4dp"
|
android:paddingRight="4dp"
|
||||||
android:paddingTop="4dp"
|
android:paddingTop="4dp"
|
||||||
android:src="?attr/arrowForwardDrawable"/>
|
android:src="?attr/arrowForwardDrawable"
|
||||||
|
android:id="@+id/action_forward_button" />
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
42
res/layout/drawer_right.xml
Normal file
42
res/layout/drawer_right.xml
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/right_drawer"
|
||||||
|
android:layout_width="@dimen/navigation_width"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_gravity="end"
|
||||||
|
android:background="?attr/drawerBackground"
|
||||||
|
android:clickable="true"
|
||||||
|
android:fitsSystemWindows="true"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
|
||||||
|
<ListView
|
||||||
|
android:id="@+id/right_drawer_list"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:choiceMode="singleChoice"
|
||||||
|
android:divider="@null"
|
||||||
|
android:dividerHeight="0dp"
|
||||||
|
android:listSelector="?attr/listBackground"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/empty"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_marginLeft="16dp"
|
||||||
|
android:layout_marginRight="16dp"
|
||||||
|
android:layout_toLeftOf="@+id/deleteButton"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:fontFamily="sans-serif-light"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:text="@string/no_section_info"
|
||||||
|
android:minHeight="?android:attr/listPreferredItemHeightSmall"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceListItemSmall"
|
||||||
|
/>
|
||||||
|
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -65,7 +65,8 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<include layout="@layout/drawer"/>
|
<include layout="@layout/drawer_left"/>
|
||||||
|
<include layout="@layout/drawer_right"/>
|
||||||
|
|
||||||
</android.support.v4.widget.DrawerLayout>
|
</android.support.v4.widget.DrawerLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
27
res/layout/section_list.xml
Normal file
27
res/layout/section_list.xml
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="56dp"
|
||||||
|
android:background="?attr/selectedBackground"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:clickable="false"
|
||||||
|
android:focusable="false">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textTab"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_marginLeft="16dp"
|
||||||
|
android:layout_marginRight="16dp"
|
||||||
|
android:layout_toLeftOf="@+id/deleteButton"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:fontFamily="sans-serif-light"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:minHeight="?android:attr/listPreferredItemHeightSmall"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceListItemSmall"/>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
@ -53,4 +53,5 @@
|
|||||||
<string name="no_reader_application_installed">Could not find an installed application for this type of file</string>
|
<string name="no_reader_application_installed">Could not find an installed application for this type of file</string>
|
||||||
<string name="customapp_missing_content">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.</string>
|
<string name="customapp_missing_content">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.</string>
|
||||||
<string name="go_to_play_store">Go to Play Store</string>
|
<string name="go_to_play_store">Go to Play Store</string>
|
||||||
|
<string name="no_section_info">No Content Headers Found</string>
|
||||||
</resources>
|
</resources>
|
@ -27,6 +27,10 @@ import android.content.DialogInterface;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Configuration;
|
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.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -42,6 +46,7 @@ import android.support.v7.app.AppCompatActivity;
|
|||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.ActionMode;
|
import android.view.ActionMode;
|
||||||
|
import android.view.Gravity;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
@ -85,8 +90,10 @@ import java.util.prefs.Preferences;
|
|||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.kiwix.kiwixmobile.settings.Constants;
|
import org.kiwix.kiwixmobile.settings.Constants;
|
||||||
import org.kiwix.kiwixmobile.settings.KiwixSettingsActivity;
|
import org.kiwix.kiwixmobile.settings.KiwixSettingsActivity;
|
||||||
|
import org.kiwix.kiwixmobile.utils.HTMLUtils;
|
||||||
import org.kiwix.kiwixmobile.utils.KiwixTextToSpeech;
|
import org.kiwix.kiwixmobile.utils.KiwixTextToSpeech;
|
||||||
import org.kiwix.kiwixmobile.utils.LanguageUtils;
|
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.FileUtils;
|
||||||
import org.kiwix.kiwixmobile.utils.files.RateAppCounter;
|
import org.kiwix.kiwixmobile.utils.files.RateAppCounter;
|
||||||
import org.kiwix.kiwixmobile.views.AnimatedProgressBar;
|
import org.kiwix.kiwixmobile.views.AnimatedProgressBar;
|
||||||
@ -126,6 +133,8 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
|
|
||||||
private static final int REQUEST_PREFERENCES = 1235;
|
private static final int REQUEST_PREFERENCES = 1235;
|
||||||
|
|
||||||
|
private static String jsContent;
|
||||||
|
|
||||||
public static ArrayList<State> mPrefState;
|
public static ArrayList<State> mPrefState;
|
||||||
|
|
||||||
public static boolean mIsFullscreenOpened;
|
public static boolean mIsFullscreenOpened;
|
||||||
@ -138,6 +147,10 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
|
|
||||||
public ImageButton exitFullscreenButton;
|
public ImageButton exitFullscreenButton;
|
||||||
|
|
||||||
|
public List<SectionProperties> sectionProperties;
|
||||||
|
|
||||||
|
private HTMLUtils htmlUtils;
|
||||||
|
|
||||||
protected boolean requestClearHistoryAfterLoad;
|
protected boolean requestClearHistoryAfterLoad;
|
||||||
|
|
||||||
protected boolean requestInitAllMenuItems;
|
protected boolean requestInitAllMenuItems;
|
||||||
@ -150,19 +163,27 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
|
|
||||||
private Button mBackToTopButton;
|
private Button mBackToTopButton;
|
||||||
|
|
||||||
private ListView mDrawerList;
|
private ListView mLeftDrawerList;
|
||||||
|
|
||||||
private DrawerLayout mDrawerLayout;
|
private ListView mRightDrawerList;
|
||||||
|
|
||||||
|
private DrawerLayout mLeftDrawerLayout;
|
||||||
|
|
||||||
|
public DrawerLayout mRightDrawerLayout;
|
||||||
|
|
||||||
private ArrayList<String> bookmarks;
|
private ArrayList<String> bookmarks;
|
||||||
|
|
||||||
private List<KiwixWebView> mWebViews = new ArrayList<>();
|
private List<KiwixWebView> mWebViews = new ArrayList<>();
|
||||||
|
|
||||||
|
private List<TextView> mSections = new ArrayList<>();
|
||||||
|
|
||||||
private KiwixTextToSpeech tts;
|
private KiwixTextToSpeech tts;
|
||||||
|
|
||||||
private CompatFindActionModeCallback mCompatCallback;
|
private CompatFindActionModeCallback mCompatCallback;
|
||||||
|
|
||||||
private ArrayAdapter<KiwixWebView> mDrawerAdapter;
|
private ArrayAdapter<KiwixWebView> mLeftArrayAdapter;
|
||||||
|
|
||||||
|
private ArrayAdapter<TextView> mRightArrayAdapter;
|
||||||
|
|
||||||
private FrameLayout mContentFrame;
|
private FrameLayout mContentFrame;
|
||||||
|
|
||||||
@ -172,6 +193,8 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
|
|
||||||
private AnimatedProgressBar mProgressBar;
|
private AnimatedProgressBar mProgressBar;
|
||||||
|
|
||||||
|
public Handler mHandler = new Handler();
|
||||||
|
|
||||||
// Initialized when onActionModeStarted is triggered.
|
// Initialized when onActionModeStarted is triggered.
|
||||||
private ActionMode mActionMode = null;
|
private ActionMode mActionMode = null;
|
||||||
private KiwixWebView tempForUndo;
|
private KiwixWebView tempForUndo;
|
||||||
@ -248,10 +271,15 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
mToolbarContainer = (RelativeLayout) findViewById(R.id.toolbar_layout);
|
mToolbarContainer = (RelativeLayout) findViewById(R.id.toolbar_layout);
|
||||||
mProgressBar = (AnimatedProgressBar) findViewById(R.id.progress_view);
|
mProgressBar = (AnimatedProgressBar) findViewById(R.id.progress_view);
|
||||||
exitFullscreenButton = (ImageButton) findViewById(R.id.FullscreenControlButton);
|
exitFullscreenButton = (ImageButton) findViewById(R.id.FullscreenControlButton);
|
||||||
|
|
||||||
tempForUndo =
|
tempForUndo =
|
||||||
new KiwixWebView(getApplicationContext()); /** initializing temporary tab value **/
|
new KiwixWebView(getApplicationContext()); /** initializing temporary tab value **/
|
||||||
snackbarLayout =
|
snackbarLayout =
|
||||||
(LinearLayout) findViewById(R.id.linearlayout_main); /** Linear layout definition**/
|
(LinearLayout) findViewById(R.id.linearlayout_main); /** Linear layout definition**/
|
||||||
|
|
||||||
|
FileReader fileReader = new FileReader();
|
||||||
|
jsContent = fileReader.readFile("www/js/jsfile.js", this);
|
||||||
|
|
||||||
RelativeLayout newTabButton = (RelativeLayout) findViewById(R.id.new_tab_button);
|
RelativeLayout newTabButton = (RelativeLayout) findViewById(R.id.new_tab_button);
|
||||||
newTabButton.setOnClickListener(new View.OnClickListener() {
|
newTabButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
|
||||||
@ -281,23 +309,71 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
mDrawerAdapter = new KiwixWebViewAdapter(this, R.layout.tabs_list, mWebViews);
|
mLeftArrayAdapter = new KiwixWebViewAdapter(this, R.layout.tabs_list, mWebViews);
|
||||||
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
mLeftDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||||
mDrawerList = (ListView) findViewById(R.id.left_drawer_list);
|
mLeftDrawerList = (ListView) findViewById(R.id.left_drawer_list);
|
||||||
mDrawerList.setDivider(null);
|
mLeftDrawerList.setDivider(null);
|
||||||
mDrawerList.setDividerHeight(0);
|
mLeftDrawerList.setDividerHeight(0);
|
||||||
mDrawerList.setAdapter(mDrawerAdapter);
|
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);
|
||||||
|
TextView tView = (TextView) findViewById(R.id.empty);
|
||||||
|
mRightDrawerList.setEmptyView(tView);
|
||||||
|
sectionProperties = new ArrayList<SectionProperties>();
|
||||||
|
mRightArrayAdapter.notifyDataSetChanged();
|
||||||
|
|
||||||
|
mLeftDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
selectTab(position);
|
selectTab(position);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar,
|
mRightDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||||
0, 0);
|
@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){
|
||||||
|
|
||||||
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().setDisplayHomeAsUpEnabled(true);
|
||||||
getSupportActionBar().setHomeButtonEnabled(true);
|
getSupportActionBar().setHomeButtonEnabled(true);
|
||||||
drawerToggle.syncState();
|
drawerToggle.syncState();
|
||||||
@ -305,6 +381,7 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
mCompatCallback = new CompatFindActionModeCallback(this);
|
mCompatCallback = new CompatFindActionModeCallback(this);
|
||||||
mContentFrame = (FrameLayout) findViewById(R.id.content_frame);
|
mContentFrame = (FrameLayout) findViewById(R.id.content_frame);
|
||||||
setUpTTS();
|
setUpTTS();
|
||||||
|
htmlUtils= new HTMLUtils(sectionProperties, mSections, mRightDrawerList, this, mHandler);
|
||||||
newTab();
|
newTab();
|
||||||
|
|
||||||
manageExternalLaunchAndRestoringViewState(savedInstanceState);
|
manageExternalLaunchAndRestoringViewState(savedInstanceState);
|
||||||
@ -435,6 +512,11 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
tts.shutdown();
|
tts.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateTableOfContents(){
|
||||||
|
mRightDrawerList.clearChoices();
|
||||||
|
getCurrentWebView().loadUrl("javascript:(" + jsContent + ")()");
|
||||||
|
}
|
||||||
|
|
||||||
private KiwixWebView newTab() {
|
private KiwixWebView newTab() {
|
||||||
String mainPage = Uri.parse(ZimContentProvider.CONTENT_URI
|
String mainPage = Uri.parse(ZimContentProvider.CONTENT_URI
|
||||||
+ ZimContentProvider.getMainPage()).toString();
|
+ ZimContentProvider.getMainPage()).toString();
|
||||||
@ -443,27 +525,28 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
|
|
||||||
private KiwixWebView newTab(String url) {
|
private KiwixWebView newTab(String url) {
|
||||||
KiwixWebView webView = new KiwixWebView(KiwixMobileActivity.this);
|
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.setWebChromeClient(new KiwixWebChromeClient());
|
||||||
webView.loadUrl(url);
|
webView.loadUrl(url);
|
||||||
webView.loadPrefs();
|
webView.loadPrefs();
|
||||||
|
|
||||||
mWebViews.add(webView);
|
mWebViews.add(webView);
|
||||||
mDrawerAdapter.notifyDataSetChanged();
|
mLeftArrayAdapter.notifyDataSetChanged();
|
||||||
selectTab(mWebViews.size() - 1);
|
selectTab(mWebViews.size() - 1);
|
||||||
setUpWebView();
|
setUpWebView();
|
||||||
|
htmlUtils.initInterface(webView);
|
||||||
return webView;
|
return webView;
|
||||||
}
|
}
|
||||||
|
|
||||||
private KiwixWebView restoreTabAtIndex(String url, int index) {
|
private KiwixWebView restoreTabAtIndex(String url, int index) {
|
||||||
KiwixWebView webView = new KiwixWebView(KiwixMobileActivity.this);
|
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.setWebChromeClient(new KiwixWebChromeClient());
|
||||||
webView.loadUrl(url);
|
webView.loadUrl(url);
|
||||||
webView.loadPrefs();
|
webView.loadPrefs();
|
||||||
|
|
||||||
mWebViews.add(index,webView);
|
mWebViews.add(index,webView);
|
||||||
mDrawerAdapter.notifyDataSetChanged();
|
mLeftArrayAdapter.notifyDataSetChanged();
|
||||||
selectTab(mWebViews.size() - 1);
|
selectTab(mWebViews.size() - 1);
|
||||||
setUpWebView();
|
setUpWebView();
|
||||||
return webView;
|
return webView;
|
||||||
@ -494,14 +577,14 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
if (index < mCurrentWebViewIndex) {
|
if (index < mCurrentWebViewIndex) {
|
||||||
mCurrentWebViewIndex--;
|
mCurrentWebViewIndex--;
|
||||||
}
|
}
|
||||||
mDrawerList.setItemChecked(mCurrentWebViewIndex, true);
|
mLeftDrawerList.setItemChecked(mCurrentWebViewIndex, true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mWebViews.remove(0);
|
mWebViews.remove(0);
|
||||||
mCurrentWebViewIndex = 0;
|
mCurrentWebViewIndex = 0;
|
||||||
newTab();
|
newTab();
|
||||||
}
|
}
|
||||||
mDrawerAdapter.notifyDataSetChanged();
|
mLeftArrayAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void undoSnackbar(final int index) {
|
private void undoSnackbar(final int index) {
|
||||||
@ -520,17 +603,17 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
|
|
||||||
private void selectTab(int position) {
|
private void selectTab(int position) {
|
||||||
mCurrentWebViewIndex = position;
|
mCurrentWebViewIndex = position;
|
||||||
mDrawerList.setItemChecked(position, true);
|
mLeftDrawerList.setItemChecked(position, true);
|
||||||
mContentFrame.removeAllViews();
|
mContentFrame.removeAllViews();
|
||||||
mContentFrame.addView(mWebViews.get(position));
|
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();
|
final Handler handler = new Handler();
|
||||||
handler.postDelayed(new Runnable() {
|
handler.postDelayed(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
mDrawerLayout.closeDrawers();
|
mLeftDrawerLayout.closeDrawers();
|
||||||
}
|
}
|
||||||
}, 150);
|
}, 150);
|
||||||
}
|
}
|
||||||
@ -538,10 +621,11 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
if (menu != null) {
|
if (menu != null) {
|
||||||
refreshBookmarkSymbol(menu);
|
refreshBookmarkSymbol(menu);
|
||||||
}
|
}
|
||||||
|
updateTableOfContents();
|
||||||
}
|
}
|
||||||
|
|
||||||
private KiwixWebView getCurrentWebView() {
|
public KiwixWebView getCurrentWebView() {
|
||||||
return mDrawerAdapter.getItem(mCurrentWebViewIndex);
|
return mLeftArrayAdapter.getItem(mCurrentWebViewIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -754,7 +838,7 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
} else {
|
} else {
|
||||||
Log.e(TAG_KIWIX, "ZIM file doesn't exist at " + file.getAbsolutePath());
|
Log.e(TAG_KIWIX, "ZIM file doesn't exist at " + file.getAbsolutePath());
|
||||||
Toast.makeText(this, getResources().getString(R.string.error_filenotfound),
|
Toast.makeText(this, getResources().getString(R.string.error_filenotfound),
|
||||||
Toast.LENGTH_LONG).show();
|
Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -792,6 +876,18 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
overridePendingTransition(0, 0);
|
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()) {
|
if (tts.isInitialized()) {
|
||||||
menu.findItem(R.id.menu_read_aloud).setVisible(true);
|
menu.findItem(R.id.menu_read_aloud).setVisible(true);
|
||||||
@ -824,6 +920,7 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void toggleBookmark() {
|
public void toggleBookmark() {
|
||||||
@ -1105,6 +1202,7 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||||
super.onPrepareOptionsMenu(menu);
|
super.onPrepareOptionsMenu(menu);
|
||||||
refreshBookmarkSymbol(menu);
|
refreshBookmarkSymbol(menu);
|
||||||
|
refreshNavigationButtons();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1122,6 +1220,26 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void refreshNavigationButtons() {
|
||||||
|
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());
|
||||||
|
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) {
|
||||||
|
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() {
|
public void loadPrefs() {
|
||||||
|
|
||||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
@ -1198,7 +1316,9 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
String zimFile = settings.getString(TAG_CURRENT_FILE, null);
|
String zimFile = settings.getString(TAG_CURRENT_FILE, null);
|
||||||
String zimArticles = settings.getString(TAG_CURRENT_ARTICLES, null);
|
String zimArticles = settings.getString(TAG_CURRENT_ARTICLES, null);
|
||||||
String zimPositions = settings.getString(TAG_CURRENT_POSITIONS, 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);
|
openZimFile(new File(zimFile), false);
|
||||||
try {
|
try {
|
||||||
JSONArray urls = new JSONArray(zimArticles);
|
JSONArray urls = new JSONArray(zimArticles);
|
||||||
@ -1425,6 +1545,7 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
view.reload();
|
view.reload();
|
||||||
}
|
}
|
||||||
mAdapter.notifyDataSetChanged();
|
mAdapter.notifyDataSetChanged();
|
||||||
|
updateTableOfContents();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1505,4 +1626,62 @@ public class KiwixMobileActivity extends AppCompatActivity
|
|||||||
ImageView exit;
|
ImageView exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private class KiwixToCAdapter extends ArrayAdapter<TextView> {
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
|
||||||
|
private int mLayoutResource;
|
||||||
|
|
||||||
|
private KiwixMobileActivity parentKiwix;
|
||||||
|
|
||||||
|
private List<TextView> mTextViews;
|
||||||
|
|
||||||
|
public KiwixToCAdapter(Context context, int resource, List<TextView> 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.kiwix.kiwixmobile;
|
package org.kiwix.kiwixmobile;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.view.MenuItemCompat;
|
import android.support.v4.view.MenuItemCompat;
|
||||||
@ -10,14 +11,26 @@ import android.view.Menu;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import org.kiwix.kiwixmobile.utils.DatabaseHelper;
|
||||||
import org.kiwix.kiwixmobile.views.AutoCompleteAdapter;
|
import org.kiwix.kiwixmobile.views.AutoCompleteAdapter;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class SearchActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
|
public class SearchActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
|
||||||
|
|
||||||
private ListView mListView;
|
private ListView mListView;
|
||||||
|
|
||||||
private AutoCompleteAdapter mAdapter;
|
private AutoCompleteAdapter mAutoAdapter;
|
||||||
|
|
||||||
|
private ArrayAdapter<String> mDefaultAdapter;
|
||||||
|
|
||||||
|
private SearchActivity context;
|
||||||
|
|
||||||
|
private DatabaseHelper mDatabaseHelper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -28,10 +41,17 @@ public class SearchActivity extends AppCompatActivity implements AdapterView.OnI
|
|||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
getSupportActionBar().setHomeButtonEnabled(true);
|
getSupportActionBar().setHomeButtonEnabled(true);
|
||||||
|
|
||||||
|
|
||||||
mListView = (ListView) findViewById(R.id.search_list);
|
mListView = (ListView) findViewById(R.id.search_list);
|
||||||
mAdapter = new AutoCompleteAdapter(this);
|
mDatabaseHelper = new DatabaseHelper(this);
|
||||||
mListView.setAdapter(mAdapter);
|
ArrayList<String> a = mDatabaseHelper.getRecentSearches();
|
||||||
mListView.setOnItemClickListener(this);
|
mDefaultAdapter = new ArrayAdapter<String>(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
|
@Override
|
||||||
@ -57,22 +77,28 @@ public class SearchActivity extends AppCompatActivity implements AdapterView.OnI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onQueryTextChange(String s) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
MenuItemCompat.setOnActionExpandListener(searchMenuItem,
|
MenuItemCompat.setOnActionExpandListener(searchMenuItem,
|
||||||
new MenuItemCompat.OnActionExpandListener() {
|
new MenuItemCompat.OnActionExpandListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemActionExpand(MenuItem item) {
|
public boolean onMenuItemActionExpand(MenuItem item) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemActionCollapse(MenuItem item) {
|
public boolean onMenuItemActionCollapse(MenuItem item) {
|
||||||
finish();
|
finish();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
@ -80,7 +106,8 @@ public class SearchActivity extends AppCompatActivity implements AdapterView.OnI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
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);
|
sendMessage(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
83
src/org/kiwix/kiwixmobile/utils/DatabaseHelper.java
Normal file
83
src/org/kiwix/kiwixmobile/utils/DatabaseHelper.java
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
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<String> getRecentSearches() {
|
||||||
|
ArrayList<String> array_list = new ArrayList<String>();
|
||||||
|
|
||||||
|
//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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
128
src/org/kiwix/kiwixmobile/utils/HTMLUtils.java
Normal file
128
src/org/kiwix/kiwixmobile/utils/HTMLUtils.java
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
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<KiwixMobileActivity.SectionProperties> sectionProperties;
|
||||||
|
private List<TextView> textViews;
|
||||||
|
private ArrayAdapter arrayAdapter;
|
||||||
|
private KiwixMobileActivity context;
|
||||||
|
private Handler mHandler;
|
||||||
|
private ListView mRightListView;
|
||||||
|
private TextView headerView;
|
||||||
|
|
||||||
|
public HTMLUtils(List<KiwixMobileActivity.SectionProperties> sectionProperties, List<TextView> 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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
31
src/org/kiwix/kiwixmobile/utils/files/FileReader.java
Normal file
31
src/org/kiwix/kiwixmobile/utils/files/FileReader.java
Normal file
@ -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 "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user