mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 18:56:44 -04:00
Format code
This commit is contained in:
parent
2782c57e6d
commit
6f0516f61a
3
.idea/misc.xml
generated
3
.idea/misc.xml
generated
@ -1,5 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
|
<component name="EntryPointsManager">
|
||||||
|
<entry_points version="2.0" />
|
||||||
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/classes" />
|
<output url="file://$PROJECT_DIR$/classes" />
|
||||||
</component>
|
</component>
|
||||||
|
@ -4,59 +4,66 @@ import android.annotation.SuppressLint;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.support.v4.app.DialogFragment;
|
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.DialogFragment;
|
||||||
|
|
||||||
@SuppressLint("ValidFragment")
|
@SuppressLint("ValidFragment")
|
||||||
public class BookmarkDialog extends DialogFragment {
|
public class BookmarkDialog extends DialogFragment {
|
||||||
private BookmarkDialogListener listen;
|
|
||||||
private String[] contents;
|
|
||||||
private boolean isBookmarked;
|
|
||||||
public BookmarkDialog(String[] contents, boolean isBookmarked){
|
|
||||||
this.contents = contents;
|
|
||||||
this.isBookmarked = isBookmarked;
|
|
||||||
}
|
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState){
|
|
||||||
AlertDialog.Builder build = new AlertDialog.Builder(getActivity());
|
|
||||||
//build.setTitle(R.string.menu_bookmarks);
|
|
||||||
String buttonText;
|
|
||||||
if (isBookmarked) {
|
|
||||||
buttonText = getResources().getString(R.string.remove_bookmark);
|
|
||||||
} else {
|
|
||||||
buttonText = getResources().getString(R.string.add_bookmark);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (contents.length != 0) {
|
private BookmarkDialogListener listen;
|
||||||
build.setItems(contents, new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int choice) {
|
|
||||||
listen.onListItemSelect(contents[choice]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
build.setNeutralButton(buttonText, new DialogInterface.OnClickListener() {
|
private String[] contents;
|
||||||
public void onClick(DialogInterface dialog, int choice) {
|
|
||||||
listen.onBookmarkButtonPressed();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return build.create();
|
private boolean isBookmarked;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public BookmarkDialog(String[] contents, boolean isBookmarked) {
|
||||||
public void onAttach(Activity a) {
|
this.contents = contents;
|
||||||
super.onAttach(a);
|
this.isBookmarked = isBookmarked;
|
||||||
try {
|
}
|
||||||
listen=(BookmarkDialogListener)a;
|
|
||||||
} catch (ClassCastException e){
|
|
||||||
throw new ClassCastException(a.toString()
|
|
||||||
+ " must implement BookmarkDialogListener");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface BookmarkDialogListener{
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
public void onListItemSelect(String choice);
|
AlertDialog.Builder build = new AlertDialog.Builder(getActivity());
|
||||||
public void onBookmarkButtonPressed();
|
//build.setTitle(R.string.menu_bookmarks);
|
||||||
}
|
String buttonText;
|
||||||
|
if (isBookmarked) {
|
||||||
|
buttonText = getResources().getString(R.string.remove_bookmark);
|
||||||
|
} else {
|
||||||
|
buttonText = getResources().getString(R.string.add_bookmark);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (contents.length != 0) {
|
||||||
|
build.setItems(contents, new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int choice) {
|
||||||
|
listen.onListItemSelect(contents[choice]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
build.setNeutralButton(buttonText, new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int choice) {
|
||||||
|
listen.onBookmarkButtonPressed();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return build.create();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttach(Activity a) {
|
||||||
|
super.onAttach(a);
|
||||||
|
try {
|
||||||
|
listen = (BookmarkDialogListener) a;
|
||||||
|
} catch (ClassCastException e) {
|
||||||
|
throw new ClassCastException(a.toString()
|
||||||
|
+ " must implement BookmarkDialogListener");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface BookmarkDialogListener {
|
||||||
|
|
||||||
|
public void onListItemSelect(String choice);
|
||||||
|
|
||||||
|
public void onBookmarkButtonPressed();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,14 +24,11 @@ import com.actionbarsherlock.view.Menu;
|
|||||||
import com.actionbarsherlock.view.MenuItem;
|
import com.actionbarsherlock.view.MenuItem;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.Selection;
|
import android.text.Selection;
|
||||||
import android.text.Spannable;
|
import android.text.Spannable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
|
||||||
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
@ -39,7 +36,8 @@ import android.widget.EditText;
|
|||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
public class CompatFindActionModeCallback implements ActionMode.Callback, TextWatcher, View.OnClickListener {
|
public class CompatFindActionModeCallback
|
||||||
|
implements ActionMode.Callback, TextWatcher, View.OnClickListener {
|
||||||
|
|
||||||
public boolean mIsActive;
|
public boolean mIsActive;
|
||||||
|
|
||||||
@ -94,7 +92,8 @@ public class CompatFindActionModeCallback implements ActionMode.Callback, TextWa
|
|||||||
// Set the WebView to search. Must be non null, and set before calling startActionMode.
|
// Set the WebView to search. Must be non null, and set before calling startActionMode.
|
||||||
public void setWebView(WebView webView) {
|
public void setWebView(WebView webView) {
|
||||||
if (null == webView) {
|
if (null == webView) {
|
||||||
throw new AssertionError("WebView supplied to CompatFindActionModeCallback cannot be null");
|
throw new AssertionError(
|
||||||
|
"WebView supplied to CompatFindActionModeCallback cannot be null");
|
||||||
}
|
}
|
||||||
mWebView = webView;
|
mWebView = webView;
|
||||||
}
|
}
|
||||||
@ -178,7 +177,8 @@ public class CompatFindActionModeCallback implements ActionMode.Callback, TextWa
|
|||||||
@Override
|
@Override
|
||||||
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
||||||
if (mWebView == null) {
|
if (mWebView == null) {
|
||||||
throw new AssertionError("No WebView for CompatFindActionModeCallback::onActionItemClicked");
|
throw new AssertionError(
|
||||||
|
"No WebView for CompatFindActionModeCallback::onActionItemClicked");
|
||||||
}
|
}
|
||||||
|
|
||||||
mInput.hideSoftInputFromWindow(mWebView.getWindowToken(), 0);
|
mInput.hideSoftInputFromWindow(mWebView.getWindowToken(), 0);
|
||||||
|
@ -48,7 +48,7 @@ public class FileSearch {
|
|||||||
// paths proves insufficient, the alternatives used by some projects
|
// paths proves insufficient, the alternatives used by some projects
|
||||||
// is to read and parse contents of /proc/mounts.
|
// is to read and parse contents of /proc/mounts.
|
||||||
final String[] additionalRoots = {
|
final String[] additionalRoots = {
|
||||||
"/mnt"
|
"/mnt"
|
||||||
};
|
};
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@ -63,7 +63,7 @@ public class FileSearch {
|
|||||||
|
|
||||||
String dirNamePrimary = new File(
|
String dirNamePrimary = new File(
|
||||||
Environment.getExternalStorageDirectory().getAbsolutePath()).toString();
|
Environment.getExternalStorageDirectory().getAbsolutePath()).toString();
|
||||||
// addFilesToFileList(dirNamePrimary, filter, fileList);
|
// addFilesToFileList(dirNamePrimary, filter, fileList);
|
||||||
|
|
||||||
for (final String dirName : additionalRoots) {
|
for (final String dirName : additionalRoots) {
|
||||||
if (dirNamePrimary.equals(dirName)) {
|
if (dirNamePrimary.equals(dirName)) {
|
||||||
@ -140,7 +140,8 @@ public class FileSearch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fill fileList with files found in the specific directory
|
// Fill fileList with files found in the specific directory
|
||||||
private void addFilesToFileList(String directory, FilenameFilter[] filter, List<String> fileList) {
|
private void addFilesToFileList(String directory, FilenameFilter[] filter,
|
||||||
|
List<String> fileList) {
|
||||||
Log.d(TAG_KIWIX, "Searching directory " + directory);
|
Log.d(TAG_KIWIX, "Searching directory " + directory);
|
||||||
File[] foundFiles = listFilesAsArray(new File(directory), filter, -1);
|
File[] foundFiles = listFilesAsArray(new File(directory), filter, -1);
|
||||||
for (File f : foundFiles) {
|
for (File f : foundFiles) {
|
||||||
|
@ -20,25 +20,45 @@
|
|||||||
package org.kiwix.kiwixmobile;
|
package org.kiwix.kiwixmobile;
|
||||||
|
|
||||||
public class JNIKiwix {
|
public class JNIKiwix {
|
||||||
|
|
||||||
public native String getMainPage();
|
public native String getMainPage();
|
||||||
|
|
||||||
public native String getId();
|
public native String getId();
|
||||||
|
|
||||||
public native String getLanguage();
|
public native String getLanguage();
|
||||||
|
|
||||||
public native String getMimeType(String url);
|
public native String getMimeType(String url);
|
||||||
|
|
||||||
public native boolean loadZIM(String path);
|
public native boolean loadZIM(String path);
|
||||||
|
|
||||||
public native byte[] getContent(String url, JNIKiwixString mimeType, JNIKiwixInt size);
|
public native byte[] getContent(String url, JNIKiwixString mimeType, JNIKiwixInt size);
|
||||||
|
|
||||||
public native boolean searchSuggestions(String prefix, int count);
|
public native boolean searchSuggestions(String prefix, int count);
|
||||||
|
|
||||||
public native boolean getNextSuggestion(JNIKiwixString title);
|
public native boolean getNextSuggestion(JNIKiwixString title);
|
||||||
|
|
||||||
public native boolean getPageUrlFromTitle(String title, JNIKiwixString url);
|
public native boolean getPageUrlFromTitle(String title, JNIKiwixString url);
|
||||||
|
|
||||||
public native boolean getTitle(JNIKiwixString title);
|
public native boolean getTitle(JNIKiwixString title);
|
||||||
|
|
||||||
public native boolean getDescription(JNIKiwixString title);
|
public native boolean getDescription(JNIKiwixString title);
|
||||||
|
|
||||||
public native boolean getDate(JNIKiwixString language);
|
public native boolean getDate(JNIKiwixString language);
|
||||||
|
|
||||||
public native boolean getFavicon(JNIKiwixString content, JNIKiwixString mimeType);
|
public native boolean getFavicon(JNIKiwixString content, JNIKiwixString mimeType);
|
||||||
|
|
||||||
public native boolean getCreator(JNIKiwixString creator);
|
public native boolean getCreator(JNIKiwixString creator);
|
||||||
|
|
||||||
public native boolean getPublisher(JNIKiwixString publisher);
|
public native boolean getPublisher(JNIKiwixString publisher);
|
||||||
|
|
||||||
public native boolean getFileSize(JNIKiwixInt size);
|
public native boolean getFileSize(JNIKiwixInt size);
|
||||||
|
|
||||||
public native boolean getArticleCount(JNIKiwixInt count);
|
public native boolean getArticleCount(JNIKiwixInt count);
|
||||||
|
|
||||||
public native boolean getMediaCount(JNIKiwixInt count);
|
public native boolean getMediaCount(JNIKiwixInt count);
|
||||||
|
|
||||||
public native boolean getRandomPage(JNIKiwixString url);
|
public native boolean getRandomPage(JNIKiwixString url);
|
||||||
|
|
||||||
public native void setDataDirectory(String icuDataDir);
|
public native void setDataDirectory(String icuDataDir);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@ -47,13 +67,16 @@ public class JNIKiwix {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class JNIKiwixString {
|
class JNIKiwixString {
|
||||||
|
|
||||||
String value;
|
String value;
|
||||||
}
|
}
|
||||||
|
|
||||||
class JNIKiwixInt {
|
class JNIKiwixInt {
|
||||||
|
|
||||||
int value;
|
int value;
|
||||||
}
|
}
|
||||||
|
|
||||||
class JNIKiwixBool {
|
class JNIKiwixBool {
|
||||||
|
|
||||||
boolean value;
|
boolean value;
|
||||||
}
|
}
|
||||||
|
@ -21,8 +21,6 @@ package org.kiwix.kiwixmobile;
|
|||||||
|
|
||||||
|
|
||||||
import com.actionbarsherlock.app.ActionBar;
|
import com.actionbarsherlock.app.ActionBar;
|
||||||
import com.actionbarsherlock.app.SherlockActivity;
|
|
||||||
import com.actionbarsherlock.app.SherlockFragment;
|
|
||||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||||
import com.actionbarsherlock.view.MenuItem;
|
import com.actionbarsherlock.view.MenuItem;
|
||||||
|
|
||||||
@ -41,13 +39,11 @@ import android.support.v4.app.FragmentManager;
|
|||||||
import android.support.v4.app.FragmentStatePagerAdapter;
|
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||||
import android.support.v4.app.FragmentTransaction;
|
import android.support.v4.app.FragmentTransaction;
|
||||||
import android.support.v4.view.ViewPager;
|
import android.support.v4.view.ViewPager;
|
||||||
|
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
import android.view.DragEvent;
|
import android.view.DragEvent;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.ViewParent;
|
import android.view.ViewParent;
|
||||||
@ -58,13 +54,13 @@ import android.widget.LinearLayout;
|
|||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import static org.kiwix.kiwixmobile.BackwardsCompatibilityTools.equalsOrNewThanApi;
|
import static org.kiwix.kiwixmobile.BackwardsCompatibilityTools.equalsOrNewThanApi;
|
||||||
import static org.kiwix.kiwixmobile.BackwardsCompatibilityTools.newApi;
|
import static org.kiwix.kiwixmobile.BackwardsCompatibilityTools.newApi;
|
||||||
|
|
||||||
public class KiwixMobileActivity extends SherlockFragmentActivity implements ActionBar.TabListener,
|
public class KiwixMobileActivity extends SherlockFragmentActivity implements ActionBar.TabListener,
|
||||||
View.OnLongClickListener, KiwixMobileFragment.FragmentCommunicator, BookmarkDialog.BookmarkDialogListener {
|
View.OnLongClickListener, KiwixMobileFragment.FragmentCommunicator,
|
||||||
|
BookmarkDialog.BookmarkDialogListener {
|
||||||
|
|
||||||
public static final String TAG_KIWIX = "kiwix";
|
public static final String TAG_KIWIX = "kiwix";
|
||||||
|
|
||||||
@ -101,7 +97,7 @@ public class KiwixMobileActivity extends SherlockFragmentActivity implements Act
|
|||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
// startActivity(new Intent(this, LibraryActivity.class));
|
// startActivity(new Intent(this, LibraryActivity.class));
|
||||||
|
|
||||||
requestWindowFeature(Window.FEATURE_PROGRESS);
|
requestWindowFeature(Window.FEATURE_PROGRESS);
|
||||||
|
|
||||||
@ -157,7 +153,8 @@ public class KiwixMobileActivity extends SherlockFragmentActivity implements Act
|
|||||||
mViewPager.setPageMargin(3);
|
mViewPager.setPageMargin(3);
|
||||||
mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
|
mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
public void onPageScrolled(int position, float positionOffset,
|
||||||
|
int positionOffsetPixels) {
|
||||||
reattachOnLongClickListener();
|
reattachOnLongClickListener();
|
||||||
super.onPageScrolled(position, positionOffset, positionOffsetPixels);
|
super.onPageScrolled(position, positionOffset, positionOffsetPixels);
|
||||||
}
|
}
|
||||||
@ -312,24 +309,24 @@ public class KiwixMobileActivity extends SherlockFragmentActivity implements Act
|
|||||||
case R.id.menu_forward:
|
case R.id.menu_forward:
|
||||||
if (mCurrentFragment.webView.canGoForward()) {
|
if (mCurrentFragment.webView.canGoForward()) {
|
||||||
mCurrentFragment.webView.goForward();
|
mCurrentFragment.webView.goForward();
|
||||||
if (newApi()) {
|
if (newApi()) {
|
||||||
invalidateOptionsMenu();
|
invalidateOptionsMenu();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R.id.menu_back:
|
case R.id.menu_back:
|
||||||
if (mCurrentFragment.webView.canGoBack()) {
|
if (mCurrentFragment.webView.canGoBack()) {
|
||||||
mCurrentFragment.webView.goBack();
|
mCurrentFragment.webView.goBack();
|
||||||
if (newApi()) {
|
if (newApi()) {
|
||||||
invalidateOptionsMenu();
|
invalidateOptionsMenu();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R.id.menu_bookmarks:
|
case R.id.menu_bookmarks:
|
||||||
mCurrentFragment.viewBookmarks();
|
mCurrentFragment.viewBookmarks();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R.id.menu_randomarticle:
|
case R.id.menu_randomarticle:
|
||||||
mCurrentFragment.openRandomArticle();
|
mCurrentFragment.openRandomArticle();
|
||||||
@ -426,7 +423,7 @@ public class KiwixMobileActivity extends SherlockFragmentActivity implements Act
|
|||||||
// handle the back button for the WebView in the current Fragment
|
// handle the back button for the WebView in the current Fragment
|
||||||
mCurrentFragment = getCurrentVisibleFragment();
|
mCurrentFragment = getCurrentVisibleFragment();
|
||||||
if (mCurrentFragment != null) {
|
if (mCurrentFragment != null) {
|
||||||
return mCurrentFragment.onKeyDown(keyCode, event);
|
return mCurrentFragment.onKeyDown(keyCode, event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -448,7 +445,8 @@ public class KiwixMobileActivity extends SherlockFragmentActivity implements Act
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
String title = getResources().getString(R.string.app_name);
|
String title = getResources().getString(R.string.app_name);
|
||||||
if (mCurrentFragment.webView.getTitle() != null && !mCurrentFragment.webView.getTitle()
|
if (mCurrentFragment.webView.getTitle() != null && !mCurrentFragment.webView
|
||||||
|
.getTitle()
|
||||||
.isEmpty()) {
|
.isEmpty()) {
|
||||||
title = mCurrentFragment.webView.getTitle();
|
title = mCurrentFragment.webView.getTitle();
|
||||||
}
|
}
|
||||||
@ -642,7 +640,8 @@ public class KiwixMobileActivity extends SherlockFragmentActivity implements Act
|
|||||||
// This method gets a reference to the fragment, that is currently visible in the ViewPager
|
// This method gets a reference to the fragment, that is currently visible in the ViewPager
|
||||||
private KiwixMobileFragment getCurrentVisibleFragment() {
|
private KiwixMobileFragment getCurrentVisibleFragment() {
|
||||||
|
|
||||||
return ((KiwixMobileFragment) mViewPagerAdapter.getFragmentAtPosition(mViewPager.getCurrentItem()));
|
return ((KiwixMobileFragment) mViewPagerAdapter
|
||||||
|
.getFragmentAtPosition(mViewPager.getCurrentItem()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -689,6 +688,17 @@ public class KiwixMobileActivity extends SherlockFragmentActivity implements Act
|
|||||||
dialog.show();
|
dialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//These two methods are used with the BookmarkDialog.
|
||||||
|
@Override
|
||||||
|
public void onListItemSelect(String choice) {
|
||||||
|
mCurrentFragment.openArticleFromBookmark(choice);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBookmarkButtonPressed() {
|
||||||
|
mCurrentFragment.toggleBookmark();
|
||||||
|
}
|
||||||
|
|
||||||
public class State {
|
public class State {
|
||||||
|
|
||||||
private boolean hasToBeRefreshed;
|
private boolean hasToBeRefreshed;
|
||||||
@ -706,17 +716,6 @@ public class KiwixMobileActivity extends SherlockFragmentActivity implements Act
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//These two methods are used with the BookmarkDialog.
|
|
||||||
@Override
|
|
||||||
public void onListItemSelect(String choice) {
|
|
||||||
mCurrentFragment.openArticleFromBookmark(choice);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBookmarkButtonPressed() {
|
|
||||||
mCurrentFragment.toggleBookmark();
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ViewPagerAdapter extends FragmentStatePagerAdapter {
|
public class ViewPagerAdapter extends FragmentStatePagerAdapter {
|
||||||
|
|
||||||
// Keep track of the active Fragments
|
// Keep track of the active Fragments
|
||||||
@ -733,9 +732,9 @@ public class KiwixMobileActivity extends SherlockFragmentActivity implements Act
|
|||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void putItem(Fragment attachedFragment) {
|
protected void putItem(Fragment attachedFragment) {
|
||||||
tabs.put(tabs.size(), attachedFragment);
|
tabs.put(tabs.size(), attachedFragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroyItem(ViewGroup container, int position, Object object) {
|
public void destroyItem(ViewGroup container, int position, Object object) {
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -14,12 +14,17 @@ import java.util.HashMap;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
public class KiwixTextToSpeech {
|
public class KiwixTextToSpeech {
|
||||||
|
|
||||||
public static final String TAG_KIWIX = "kiwix";
|
public static final String TAG_KIWIX = "kiwix";
|
||||||
|
|
||||||
private Context context;
|
private Context context;
|
||||||
|
|
||||||
private OnSpeakingListener onSpeakingListener;
|
private OnSpeakingListener onSpeakingListener;
|
||||||
|
|
||||||
private WebView webView;
|
private WebView webView;
|
||||||
|
|
||||||
private TextToSpeech tts;
|
private TextToSpeech tts;
|
||||||
|
|
||||||
private boolean initialized = false;
|
private boolean initialized = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -33,8 +38,8 @@ public class KiwixTextToSpeech {
|
|||||||
* ended
|
* ended
|
||||||
*/
|
*/
|
||||||
public KiwixTextToSpeech(Context context, WebView webView,
|
public KiwixTextToSpeech(Context context, WebView webView,
|
||||||
final OnInitSucceedListener onInitSucceedListener,
|
final OnInitSucceedListener onInitSucceedListener,
|
||||||
final OnSpeakingListener onSpeakingListener) {
|
final OnSpeakingListener onSpeakingListener) {
|
||||||
Log.d(TAG_KIWIX, "Initializing TextToSpeech");
|
Log.d(TAG_KIWIX, "Initializing TextToSpeech");
|
||||||
|
|
||||||
this.context = context;
|
this.context = context;
|
||||||
@ -59,7 +64,8 @@ public class KiwixTextToSpeech {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (BackwardsCompatibilityTools.equalsOrNewThanApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)) {
|
if (BackwardsCompatibilityTools
|
||||||
|
.equalsOrNewThanApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)) {
|
||||||
tts.setOnUtteranceProgressListener(new UtteranceProgressListener() {
|
tts.setOnUtteranceProgressListener(new UtteranceProgressListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onStart(String utteranceId) {
|
public void onStart(String utteranceId) {
|
||||||
@ -96,32 +102,32 @@ public class KiwixTextToSpeech {
|
|||||||
onSpeakingListener.onSpeakingEnded();
|
onSpeakingListener.onSpeakingEnded();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Locale locale = LanguageUtils.ISO3ToLocale(ZimContentProvider.getLanguage());
|
Locale locale = LanguageUtils.ISO3ToLocale(ZimContentProvider.getLanguage());
|
||||||
int result;
|
int result;
|
||||||
if (locale == null
|
if (locale == null
|
||||||
|| (result = tts.isLanguageAvailable(locale)) == TextToSpeech.LANG_MISSING_DATA
|
|| (result = tts.isLanguageAvailable(locale)) == TextToSpeech.LANG_MISSING_DATA
|
||||||
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
|
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
|
||||||
Log.d(TAG_KIWIX, "TextToSpeech: language not supported: " +
|
Log.d(TAG_KIWIX, "TextToSpeech: language not supported: " +
|
||||||
ZimContentProvider.getLanguage() + " (" + locale.getLanguage() + ")");
|
ZimContentProvider.getLanguage() + " (" + locale.getLanguage() + ")");
|
||||||
Toast.makeText(context,
|
Toast.makeText(context,
|
||||||
context.getResources().getString(R.string.tts_lang_not_supported),
|
context.getResources().getString(R.string.tts_lang_not_supported),
|
||||||
Toast.LENGTH_LONG).show();
|
Toast.LENGTH_LONG).show();
|
||||||
} else {
|
} else {
|
||||||
tts.setLanguage(locale);
|
tts.setLanguage(locale);
|
||||||
|
|
||||||
// We use JavaScript to get the content of the page conveniently, earlier making some
|
// We use JavaScript to get the content of the page conveniently, earlier making some
|
||||||
// changes in the page
|
// changes in the page
|
||||||
webView.loadUrl("javascript:" +
|
webView.loadUrl("javascript:" +
|
||||||
"body = document.getElementsByTagName('body')[0].cloneNode(true);" +
|
"body = document.getElementsByTagName('body')[0].cloneNode(true);" +
|
||||||
// Remove some elements that are shouldn't be read (table of contents,
|
// Remove some elements that are shouldn't be read (table of contents,
|
||||||
// references numbers, thumbnail captions, duplicated title, etc.)
|
// references numbers, thumbnail captions, duplicated title, etc.)
|
||||||
"toRemove = body.querySelectorAll('sup.reference, #toc, .thumbcaption, " +
|
"toRemove = body.querySelectorAll('sup.reference, #toc, .thumbcaption, " +
|
||||||
" title, .navbox');" +
|
" title, .navbox');" +
|
||||||
"Array.prototype.forEach.call(toRemove, function(elem) {" +
|
"Array.prototype.forEach.call(toRemove, function(elem) {" +
|
||||||
" elem.parentElement.removeChild(elem);" +
|
" elem.parentElement.removeChild(elem);" +
|
||||||
"});" +
|
"});" +
|
||||||
"tts.speakAloud(body.innerText);");
|
"tts.speakAloud(body.innerText);");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,7 +149,30 @@ public class KiwixTextToSpeech {
|
|||||||
tts.shutdown();
|
tts.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The listener which is notified when initialization of the TextToSpeech engine is successfully
|
||||||
|
* done.
|
||||||
|
*/
|
||||||
|
public interface OnInitSucceedListener {
|
||||||
|
|
||||||
|
public void onInitSucceed();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The listener that is notified when speaking starts or stops (regardless of whether it was a
|
||||||
|
* result of error, user, or because whole text was read).
|
||||||
|
*
|
||||||
|
* Note that the methods of this interface may not be called from the UI thread.
|
||||||
|
*/
|
||||||
|
public interface OnSpeakingListener {
|
||||||
|
|
||||||
|
public void onSpeakingStarted();
|
||||||
|
|
||||||
|
public void onSpeakingEnded();
|
||||||
|
}
|
||||||
|
|
||||||
private class TTSJavaScriptInterface {
|
private class TTSJavaScriptInterface {
|
||||||
|
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public void speakAloud(String content) {
|
public void speakAloud(String content) {
|
||||||
@ -164,24 +193,4 @@ public class KiwixTextToSpeech {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The listener which is notified when initialization of the TextToSpeech engine is successfully
|
|
||||||
* done.
|
|
||||||
*/
|
|
||||||
public interface OnInitSucceedListener {
|
|
||||||
public void onInitSucceed();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The listener that is notified when speaking starts or stops (regardless of whether it was
|
|
||||||
* a result of error, user, or because whole text was read).
|
|
||||||
*
|
|
||||||
* Note that the methods of this interface may not be called from the UI thread.
|
|
||||||
*/
|
|
||||||
public interface OnSpeakingListener {
|
|
||||||
public void onSpeakingStarted();
|
|
||||||
|
|
||||||
public void onSpeakingEnded();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,14 +20,15 @@
|
|||||||
package org.kiwix.kiwixmobile;
|
package org.kiwix.kiwixmobile;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.os.Build;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.webkit.WebView;
|
|
||||||
import android.webkit.WebChromeClient;
|
import android.webkit.WebChromeClient;
|
||||||
|
import android.webkit.WebSettings.LayoutAlgorithm;
|
||||||
|
import android.webkit.WebView;
|
||||||
import android.webkit.WebViewClient;
|
import android.webkit.WebViewClient;
|
||||||
import android.widget.ZoomButtonsController;
|
import android.widget.ZoomButtonsController;
|
||||||
import android.webkit.WebSettings.LayoutAlgorithm;
|
|
||||||
import android.os.Build;
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import static org.kiwix.kiwixmobile.BackwardsCompatibilityTools.newApi;
|
import static org.kiwix.kiwixmobile.BackwardsCompatibilityTools.newApi;
|
||||||
@ -44,34 +45,34 @@ public class KiwixWebView extends WebView {
|
|||||||
|
|
||||||
public KiwixWebView(Context context) {
|
public KiwixWebView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
public KiwixWebView(Context context, AttributeSet attrs) {
|
public KiwixWebView(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
public KiwixWebView(Context context, AttributeSet attrs, int defStyle) {
|
public KiwixWebView(Context context, AttributeSet attrs, int defStyle) {
|
||||||
super(context, attrs, defStyle);
|
super(context, attrs, defStyle);
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
setWebChromeClient(new WebChromeClient());
|
setWebChromeClient(new WebChromeClient());
|
||||||
setWebViewClient(new WebViewClient());
|
setWebViewClient(new WebViewClient());
|
||||||
getSettings().setJavaScriptEnabled(true);
|
getSettings().setJavaScriptEnabled(true);
|
||||||
getSettings().setSupportMultipleWindows(true);
|
getSettings().setSupportMultipleWindows(true);
|
||||||
getSettings().setSupportZoom(true);
|
getSettings().setSupportZoom(true);
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||||
|
|
||||||
// Avoid crash with WebViewClassic
|
// Avoid crash with WebViewClassic
|
||||||
try {
|
try {
|
||||||
getSettings().setLayoutAlgorithm(LayoutAlgorithm.TEXT_AUTOSIZING);
|
getSettings().setLayoutAlgorithm(LayoutAlgorithm.TEXT_AUTOSIZING);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -90,14 +91,14 @@ public class KiwixWebView extends WebView {
|
|||||||
super.onScrollChanged(l, t, oldl, oldt);
|
super.onScrollChanged(l, t, oldl, oldt);
|
||||||
int windowHeight = getMeasuredHeight();
|
int windowHeight = getMeasuredHeight();
|
||||||
|
|
||||||
// It seems that in a few cases, getMeasuredHeight() returns 0
|
// It seems that in a few cases, getMeasuredHeight() returns 0
|
||||||
if (windowHeight > 0) {
|
if (windowHeight > 0) {
|
||||||
int pages = getContentHeight() / windowHeight;
|
int pages = getContentHeight() / windowHeight;
|
||||||
int page = t / windowHeight;
|
int page = t / windowHeight;
|
||||||
if (mChangeListener != null) {
|
if (mChangeListener != null) {
|
||||||
mChangeListener.onPageChanged(page, pages);
|
mChangeListener.onPageChanged(page, pages);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disableZoomControlls(boolean disable) {
|
public void disableZoomControlls(boolean disable) {
|
||||||
@ -142,6 +143,7 @@ public class KiwixWebView extends WebView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public interface OnPageChangeListener {
|
public interface OnPageChangeListener {
|
||||||
|
|
||||||
public void onPageChanged(int page, int maxPages);
|
public void onPageChanged(int page, int maxPages);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +87,8 @@ public class LanguageUtils {
|
|||||||
Locale.setDefault(locale);
|
Locale.setDefault(locale);
|
||||||
Configuration config = new Configuration();
|
Configuration config = new Configuration();
|
||||||
config.locale = locale;
|
config.locale = locale;
|
||||||
context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
|
context.getResources()
|
||||||
|
.updateConfiguration(config, context.getResources().getDisplayMetrics());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -254,17 +255,20 @@ public class LanguageUtils {
|
|||||||
Log.d(TAG_KIWIX, "Applying custom font");
|
Log.d(TAG_KIWIX, "Applying custom font");
|
||||||
|
|
||||||
// Reduce the text size
|
// Reduce the text size
|
||||||
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textView.getTextSize() - 2f);
|
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX,
|
||||||
|
textView.getTextSize() - 2f);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
|
|
||||||
} catch (InflateException e) {
|
} catch (InflateException e) {
|
||||||
Log.e(TAG_KIWIX, "Could not apply the custom font to " + name + " " + e.getMessage());
|
Log.e(TAG_KIWIX,
|
||||||
|
"Could not apply the custom font to " + name + " " + e.getMessage());
|
||||||
|
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
Log.e(TAG_KIWIX, "Could not apply the custom font to " + name + " " + e.getMessage());
|
Log.e(TAG_KIWIX,
|
||||||
|
"Could not apply the custom font to " + name + " " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,18 +23,17 @@ import android.content.ContentProvider;
|
|||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.webkit.MimeTypeMap;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.ParcelFileDescriptor;
|
import android.os.ParcelFileDescriptor;
|
||||||
import android.os.ParcelFileDescriptor.AutoCloseOutputStream;
|
import android.os.ParcelFileDescriptor.AutoCloseOutputStream;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.webkit.MimeTypeMap;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.File;
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
public class ZimContentProvider extends ContentProvider {
|
public class ZimContentProvider extends ContentProvider {
|
||||||
@ -147,22 +146,49 @@ public class ZimContentProvider extends ContentProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String loadICUData(Context context, File workingDir) {
|
||||||
|
String icuFileName = "icudt49l.dat";
|
||||||
|
try {
|
||||||
|
File icuDir = new File(workingDir, "icu");
|
||||||
|
if (!icuDir.exists()) {
|
||||||
|
icuDir.mkdirs();
|
||||||
|
}
|
||||||
|
File icuDataFile = new File(icuDir, icuFileName);
|
||||||
|
if (!icuDataFile.exists()) {
|
||||||
|
InputStream in = context.getAssets().open(icuFileName);
|
||||||
|
OutputStream out = new FileOutputStream(icuDataFile);
|
||||||
|
byte[] buf = new byte[1024];
|
||||||
|
int len;
|
||||||
|
while ((len = in.read(buf)) > 0) {
|
||||||
|
out.write(buf, 0, len);
|
||||||
|
}
|
||||||
|
in.close();
|
||||||
|
out.flush();
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
return icuDir.getAbsolutePath();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG_KIWIX, "Error copying icu data file", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreate() {
|
public boolean onCreate() {
|
||||||
jniKiwix = new JNIKiwix();
|
jniKiwix = new JNIKiwix();
|
||||||
setIcuDataDirectory();
|
setIcuDataDirectory();
|
||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType(Uri uri) {
|
public String getType(Uri uri) {
|
||||||
String mimeType;
|
String mimeType;
|
||||||
|
|
||||||
// This is the code which makes a guess based on the file extenstion
|
// This is the code which makes a guess based on the file extenstion
|
||||||
String extension = MimeTypeMap.getFileExtensionFromUrl(uri.toString().toLowerCase());
|
String extension = MimeTypeMap.getFileExtensionFromUrl(uri.toString().toLowerCase());
|
||||||
mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
|
mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
|
||||||
|
|
||||||
// This is the code which retrieve the mimeType from the libzim
|
// This is the code which retrieve the mimeType from the libzim
|
||||||
// "slow" and still bugyy
|
// "slow" and still bugyy
|
||||||
if (mimeType.isEmpty() && jniKiwix != null && uri == null) {
|
if (mimeType.isEmpty() && jniKiwix != null && uri == null) {
|
||||||
String t = uri.toString();
|
String t = uri.toString();
|
||||||
@ -177,21 +203,21 @@ public class ZimContentProvider extends ContentProvider {
|
|||||||
t = t.substring(0, pos);
|
t = t.substring(0, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
mimeType = jniKiwix.getMimeType(t);
|
mimeType = jniKiwix.getMimeType(t);
|
||||||
|
|
||||||
// Truncate mime-type (everything after the first space
|
// Truncate mime-type (everything after the first space
|
||||||
mimeType = mimeType.replaceAll("^([^ ]+).*$", "$1");
|
mimeType = mimeType.replaceAll("^([^ ]+).*$", "$1");
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.d(TAG_KIWIX, "Getting mime-type for " + uri.toString() + " = " + mimeType);
|
Log.d(TAG_KIWIX, "Getting mime-type for " + uri.toString() + " = " + mimeType);
|
||||||
return mimeType;
|
return mimeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ParcelFileDescriptor openFile(Uri uri, String mode)
|
public ParcelFileDescriptor openFile(Uri uri, String mode)
|
||||||
throws FileNotFoundException {
|
throws FileNotFoundException {
|
||||||
ParcelFileDescriptor[] pipe = null;
|
ParcelFileDescriptor[] pipe = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
pipe = ParcelFileDescriptor.createPipe();
|
pipe = ParcelFileDescriptor.createPipe();
|
||||||
new TransferThread(jniKiwix, uri, new AutoCloseOutputStream(pipe[1])).start();
|
new TransferThread(jniKiwix, uri, new AutoCloseOutputStream(pipe[1])).start();
|
||||||
@ -200,7 +226,7 @@ public class ZimContentProvider extends ContentProvider {
|
|||||||
throw new FileNotFoundException("Could not open pipe for: "
|
throw new FileNotFoundException("Could not open pipe for: "
|
||||||
+ uri.toString());
|
+ uri.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
return (pipe[0]);
|
return (pipe[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,6 +252,16 @@ public class ZimContentProvider extends ContentProvider {
|
|||||||
throw new RuntimeException("Operation not supported");
|
throw new RuntimeException("Operation not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setIcuDataDirectory() {
|
||||||
|
File workingDir = this.getContext().getFilesDir();
|
||||||
|
String icuDirPath = loadICUData(this.getContext(), workingDir);
|
||||||
|
|
||||||
|
if (icuDirPath != null) {
|
||||||
|
Log.d(TAG_KIWIX, "Setting the ICU directory path to " + icuDirPath);
|
||||||
|
jniKiwix.setDataDirectory(icuDirPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static class TransferThread extends Thread {
|
static class TransferThread extends Thread {
|
||||||
|
|
||||||
Uri articleUri;
|
Uri articleUri;
|
||||||
@ -266,60 +302,28 @@ public class ZimContentProvider extends ContentProvider {
|
|||||||
JNIKiwixString mime = new JNIKiwixString();
|
JNIKiwixString mime = new JNIKiwixString();
|
||||||
JNIKiwixInt size = new JNIKiwixInt();
|
JNIKiwixInt size = new JNIKiwixInt();
|
||||||
byte[] data = jniKiwix.getContent(articleZimUrl, mime, size);
|
byte[] data = jniKiwix.getContent(articleZimUrl, mime, size);
|
||||||
out.write(data, 0, data.length);
|
out.write(data, 0, data.length);
|
||||||
out.flush();
|
out.flush();
|
||||||
|
|
||||||
Log.d(TAG_KIWIX, "reading " + articleZimUrl
|
Log.d(TAG_KIWIX, "reading " + articleZimUrl
|
||||||
+ "(mime: " + mime.value + ", size: " + size.value + ") finished.");
|
+ "(mime: " + mime.value + ", size: " + size.value + ") finished.");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e(TAG_KIWIX, "Exception reading article " + articleZimUrl + " from zim file", e);
|
Log.e(TAG_KIWIX, "Exception reading article " + articleZimUrl + " from zim file",
|
||||||
|
e);
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
Log.e(TAG_KIWIX, "Exception reading article " + articleZimUrl + " from zim file", e);
|
Log.e(TAG_KIWIX, "Exception reading article " + articleZimUrl + " from zim file",
|
||||||
|
e);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
out.close();
|
out.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e(TAG_KIWIX, "Custom exception by closing out stream for article " + articleZimUrl, e);
|
Log.e(TAG_KIWIX,
|
||||||
|
"Custom exception by closing out stream for article " + articleZimUrl,
|
||||||
|
e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setIcuDataDirectory() {
|
|
||||||
File workingDir = this.getContext().getFilesDir();
|
|
||||||
String icuDirPath = loadICUData(this.getContext(), workingDir);
|
|
||||||
|
|
||||||
if(icuDirPath != null) {
|
|
||||||
Log.d(TAG_KIWIX, "Setting the ICU directory path to " + icuDirPath);
|
|
||||||
jniKiwix.setDataDirectory(icuDirPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String loadICUData(Context context, File workingDir) {
|
|
||||||
String icuFileName = "icudt49l.dat";
|
|
||||||
try {
|
|
||||||
File icuDir = new File(workingDir, "icu");
|
|
||||||
if(!icuDir.exists()) icuDir.mkdirs();
|
|
||||||
File icuDataFile = new File(icuDir, icuFileName);
|
|
||||||
if(!icuDataFile.exists()) {
|
|
||||||
InputStream in = context.getAssets().open(icuFileName);
|
|
||||||
OutputStream out = new FileOutputStream(icuDataFile);
|
|
||||||
byte[] buf = new byte[1024];
|
|
||||||
int len;
|
|
||||||
while ((len = in.read(buf)) > 0) {
|
|
||||||
out.write(buf, 0, len);
|
|
||||||
}
|
|
||||||
in.close();
|
|
||||||
out.flush();
|
|
||||||
out.close();
|
|
||||||
}
|
|
||||||
return icuDir.getAbsolutePath();
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
Log.e(TAG_KIWIX, "Error copying icu data file", e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
package org.kiwix.kiwixmobile;
|
package org.kiwix.kiwixmobile;
|
||||||
|
|
||||||
import com.actionbarsherlock.app.SherlockActivity;
|
|
||||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||||
import com.actionbarsherlock.view.Menu;
|
import com.actionbarsherlock.view.Menu;
|
||||||
import com.actionbarsherlock.view.MenuInflater;
|
import com.actionbarsherlock.view.MenuInflater;
|
||||||
@ -38,10 +37,7 @@ import android.support.v4.app.LoaderManager;
|
|||||||
import android.support.v4.content.CursorLoader;
|
import android.support.v4.content.CursorLoader;
|
||||||
import android.support.v4.content.Loader;
|
import android.support.v4.content.Loader;
|
||||||
import android.support.v4.widget.SimpleCursorAdapter;
|
import android.support.v4.widget.SimpleCursorAdapter;
|
||||||
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.animation.AlphaAnimation;
|
import android.view.animation.AlphaAnimation;
|
||||||
@ -52,7 +48,6 @@ import android.widget.ArrayAdapter;
|
|||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -235,7 +230,8 @@ public class ZimFileSelectActivity extends SherlockFragmentActivity
|
|||||||
protected void startQuery() {
|
protected void startQuery() {
|
||||||
|
|
||||||
// Defines a list of columns to retrieve from the Cursor and load into an output row
|
// Defines a list of columns to retrieve from the Cursor and load into an output row
|
||||||
String[] mZimListColumns = {MediaStore.Files.FileColumns.TITLE, MediaStore.Files.FileColumns.DATA};
|
String[] mZimListColumns = {MediaStore.Files.FileColumns.TITLE,
|
||||||
|
MediaStore.Files.FileColumns.DATA};
|
||||||
|
|
||||||
// Defines a list of View IDs that will receive the Cursor columns for each row
|
// Defines a list of View IDs that will receive the Cursor columns for each row
|
||||||
int[] mZimListItems = {android.R.id.text1, android.R.id.text2};
|
int[] mZimListItems = {android.R.id.text1, android.R.id.text2};
|
||||||
|
@ -32,7 +32,8 @@ public class KiwixSettingsActivityHC extends Activity {
|
|||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
getFragmentManager().beginTransaction().replace(android.R.id.content, new PrefsFragment()).commit();
|
getFragmentManager().beginTransaction().replace(android.R.id.content, new PrefsFragment())
|
||||||
|
.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PrefsFragment extends PreferenceFragment {
|
public class PrefsFragment extends PreferenceFragment {
|
||||||
|
@ -114,7 +114,8 @@ public class SettingsHelper {
|
|||||||
String version;
|
String version;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
version = getContext().getPackageManager().getPackageInfo("org.kiwix.kiwixmobile", 0).versionName;
|
version = getContext().getPackageManager()
|
||||||
|
.getPackageInfo("org.kiwix.kiwixmobile", 0).versionName;
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user