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"?>
|
||||
<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">
|
||||
<output url="file://$PROJECT_DIR$/classes" />
|
||||
</component>
|
||||
|
@ -4,59 +4,66 @@ import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
|
||||
@SuppressLint("ValidFragment")
|
||||
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) {
|
||||
build.setItems(contents, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int choice) {
|
||||
listen.onListItemSelect(contents[choice]);
|
||||
}
|
||||
});
|
||||
}
|
||||
private BookmarkDialogListener listen;
|
||||
|
||||
build.setNeutralButton(buttonText, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int choice) {
|
||||
listen.onBookmarkButtonPressed();
|
||||
}
|
||||
});
|
||||
private String[] contents;
|
||||
|
||||
return build.create();
|
||||
}
|
||||
private boolean isBookmarked;
|
||||
|
||||
@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 BookmarkDialog(String[] contents, boolean isBookmarked) {
|
||||
this.contents = contents;
|
||||
this.isBookmarked = isBookmarked;
|
||||
}
|
||||
|
||||
public interface BookmarkDialogListener{
|
||||
public void onListItemSelect(String choice);
|
||||
public void onBookmarkButtonPressed();
|
||||
}
|
||||
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) {
|
||||
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 android.content.Context;
|
||||
|
||||
import android.text.Editable;
|
||||
import android.text.Selection;
|
||||
import android.text.Spannable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.LayoutInflater;
|
||||
|
||||
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.webkit.WebView;
|
||||
@ -39,7 +36,8 @@ import android.widget.EditText;
|
||||
|
||||
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;
|
||||
|
||||
@ -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.
|
||||
public void setWebView(WebView 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;
|
||||
}
|
||||
@ -178,7 +177,8 @@ public class CompatFindActionModeCallback implements ActionMode.Callback, TextWa
|
||||
@Override
|
||||
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
||||
if (mWebView == null) {
|
||||
throw new AssertionError("No WebView for CompatFindActionModeCallback::onActionItemClicked");
|
||||
throw new AssertionError(
|
||||
"No WebView for CompatFindActionModeCallback::onActionItemClicked");
|
||||
}
|
||||
|
||||
mInput.hideSoftInputFromWindow(mWebView.getWindowToken(), 0);
|
||||
|
@ -48,7 +48,7 @@ public class FileSearch {
|
||||
// paths proves insufficient, the alternatives used by some projects
|
||||
// is to read and parse contents of /proc/mounts.
|
||||
final String[] additionalRoots = {
|
||||
"/mnt"
|
||||
"/mnt"
|
||||
};
|
||||
|
||||
int i = 0;
|
||||
@ -63,7 +63,7 @@ public class FileSearch {
|
||||
|
||||
String dirNamePrimary = new File(
|
||||
Environment.getExternalStorageDirectory().getAbsolutePath()).toString();
|
||||
// addFilesToFileList(dirNamePrimary, filter, fileList);
|
||||
// addFilesToFileList(dirNamePrimary, filter, fileList);
|
||||
|
||||
for (final String dirName : additionalRoots) {
|
||||
if (dirNamePrimary.equals(dirName)) {
|
||||
@ -140,7 +140,8 @@ public class FileSearch {
|
||||
}
|
||||
|
||||
// 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);
|
||||
File[] foundFiles = listFilesAsArray(new File(directory), filter, -1);
|
||||
for (File f : foundFiles) {
|
||||
|
@ -20,25 +20,45 @@
|
||||
package org.kiwix.kiwixmobile;
|
||||
|
||||
public class JNIKiwix {
|
||||
|
||||
public native String getMainPage();
|
||||
|
||||
public native String getId();
|
||||
|
||||
public native String getLanguage();
|
||||
|
||||
public native String getMimeType(String url);
|
||||
|
||||
public native boolean loadZIM(String path);
|
||||
|
||||
public native byte[] getContent(String url, JNIKiwixString mimeType, JNIKiwixInt size);
|
||||
|
||||
public native boolean searchSuggestions(String prefix, int count);
|
||||
|
||||
public native boolean getNextSuggestion(JNIKiwixString title);
|
||||
|
||||
public native boolean getPageUrlFromTitle(String title, JNIKiwixString url);
|
||||
|
||||
public native boolean getTitle(JNIKiwixString title);
|
||||
|
||||
public native boolean getDescription(JNIKiwixString title);
|
||||
|
||||
public native boolean getDate(JNIKiwixString language);
|
||||
|
||||
public native boolean getFavicon(JNIKiwixString content, JNIKiwixString mimeType);
|
||||
|
||||
public native boolean getCreator(JNIKiwixString creator);
|
||||
|
||||
public native boolean getPublisher(JNIKiwixString publisher);
|
||||
|
||||
public native boolean getFileSize(JNIKiwixInt size);
|
||||
|
||||
public native boolean getArticleCount(JNIKiwixInt count);
|
||||
|
||||
public native boolean getMediaCount(JNIKiwixInt count);
|
||||
|
||||
public native boolean getRandomPage(JNIKiwixString url);
|
||||
|
||||
public native void setDataDirectory(String icuDataDir);
|
||||
|
||||
static {
|
||||
@ -47,13 +67,16 @@ public class JNIKiwix {
|
||||
}
|
||||
|
||||
class JNIKiwixString {
|
||||
|
||||
String value;
|
||||
}
|
||||
|
||||
class JNIKiwixInt {
|
||||
|
||||
int value;
|
||||
}
|
||||
|
||||
class JNIKiwixBool {
|
||||
|
||||
boolean value;
|
||||
}
|
||||
|
@ -21,8 +21,6 @@ package org.kiwix.kiwixmobile;
|
||||
|
||||
|
||||
import com.actionbarsherlock.app.ActionBar;
|
||||
import com.actionbarsherlock.app.SherlockActivity;
|
||||
import com.actionbarsherlock.app.SherlockFragment;
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
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.FragmentTransaction;
|
||||
import android.support.v4.view.ViewPager;
|
||||
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.view.DragEvent;
|
||||
import android.view.KeyEvent;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewParent;
|
||||
@ -58,13 +54,13 @@ import android.widget.LinearLayout;
|
||||
import android.widget.Spinner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.kiwix.kiwixmobile.BackwardsCompatibilityTools.equalsOrNewThanApi;
|
||||
import static org.kiwix.kiwixmobile.BackwardsCompatibilityTools.newApi;
|
||||
|
||||
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";
|
||||
|
||||
@ -101,7 +97,7 @@ public class KiwixMobileActivity extends SherlockFragmentActivity implements Act
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// startActivity(new Intent(this, LibraryActivity.class));
|
||||
// startActivity(new Intent(this, LibraryActivity.class));
|
||||
|
||||
requestWindowFeature(Window.FEATURE_PROGRESS);
|
||||
|
||||
@ -157,7 +153,8 @@ public class KiwixMobileActivity extends SherlockFragmentActivity implements Act
|
||||
mViewPager.setPageMargin(3);
|
||||
mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||
public void onPageScrolled(int position, float positionOffset,
|
||||
int positionOffsetPixels) {
|
||||
reattachOnLongClickListener();
|
||||
super.onPageScrolled(position, positionOffset, positionOffsetPixels);
|
||||
}
|
||||
@ -312,24 +309,24 @@ public class KiwixMobileActivity extends SherlockFragmentActivity implements Act
|
||||
case R.id.menu_forward:
|
||||
if (mCurrentFragment.webView.canGoForward()) {
|
||||
mCurrentFragment.webView.goForward();
|
||||
if (newApi()) {
|
||||
invalidateOptionsMenu();
|
||||
}
|
||||
}
|
||||
if (newApi()) {
|
||||
invalidateOptionsMenu();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case R.id.menu_back:
|
||||
if (mCurrentFragment.webView.canGoBack()) {
|
||||
mCurrentFragment.webView.goBack();
|
||||
if (newApi()) {
|
||||
invalidateOptionsMenu();
|
||||
}
|
||||
mCurrentFragment.webView.goBack();
|
||||
if (newApi()) {
|
||||
invalidateOptionsMenu();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case R.id.menu_bookmarks:
|
||||
mCurrentFragment.viewBookmarks();
|
||||
break;
|
||||
case R.id.menu_bookmarks:
|
||||
mCurrentFragment.viewBookmarks();
|
||||
break;
|
||||
|
||||
case R.id.menu_randomarticle:
|
||||
mCurrentFragment.openRandomArticle();
|
||||
@ -426,7 +423,7 @@ public class KiwixMobileActivity extends SherlockFragmentActivity implements Act
|
||||
// handle the back button for the WebView in the current Fragment
|
||||
mCurrentFragment = getCurrentVisibleFragment();
|
||||
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
|
||||
public void run() {
|
||||
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()) {
|
||||
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
|
||||
private KiwixMobileFragment getCurrentVisibleFragment() {
|
||||
|
||||
return ((KiwixMobileFragment) mViewPagerAdapter.getFragmentAtPosition(mViewPager.getCurrentItem()));
|
||||
return ((KiwixMobileFragment) mViewPagerAdapter
|
||||
.getFragmentAtPosition(mViewPager.getCurrentItem()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -689,6 +688,17 @@ public class KiwixMobileActivity extends SherlockFragmentActivity implements Act
|
||||
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 {
|
||||
|
||||
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 {
|
||||
|
||||
// Keep track of the active Fragments
|
||||
@ -733,9 +732,9 @@ public class KiwixMobileActivity extends SherlockFragmentActivity implements Act
|
||||
return fragment;
|
||||
}
|
||||
|
||||
protected void putItem(Fragment attachedFragment) {
|
||||
tabs.put(tabs.size(), attachedFragment);
|
||||
}
|
||||
protected void putItem(Fragment attachedFragment) {
|
||||
tabs.put(tabs.size(), attachedFragment);
|
||||
}
|
||||
|
||||
@Override
|
||||
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;
|
||||
|
||||
public class KiwixTextToSpeech {
|
||||
|
||||
public static final String TAG_KIWIX = "kiwix";
|
||||
|
||||
private Context context;
|
||||
|
||||
private OnSpeakingListener onSpeakingListener;
|
||||
|
||||
private WebView webView;
|
||||
|
||||
private TextToSpeech tts;
|
||||
|
||||
private boolean initialized = false;
|
||||
|
||||
/**
|
||||
@ -33,8 +38,8 @@ public class KiwixTextToSpeech {
|
||||
* ended
|
||||
*/
|
||||
public KiwixTextToSpeech(Context context, WebView webView,
|
||||
final OnInitSucceedListener onInitSucceedListener,
|
||||
final OnSpeakingListener onSpeakingListener) {
|
||||
final OnInitSucceedListener onInitSucceedListener,
|
||||
final OnSpeakingListener onSpeakingListener) {
|
||||
Log.d(TAG_KIWIX, "Initializing TextToSpeech");
|
||||
|
||||
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() {
|
||||
@Override
|
||||
public void onStart(String utteranceId) {
|
||||
@ -96,32 +102,32 @@ public class KiwixTextToSpeech {
|
||||
onSpeakingListener.onSpeakingEnded();
|
||||
}
|
||||
} else {
|
||||
Locale locale = LanguageUtils.ISO3ToLocale(ZimContentProvider.getLanguage());
|
||||
Locale locale = LanguageUtils.ISO3ToLocale(ZimContentProvider.getLanguage());
|
||||
int result;
|
||||
if (locale == null
|
||||
|| (result = tts.isLanguageAvailable(locale)) == TextToSpeech.LANG_MISSING_DATA
|
||||
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
|
||||
Log.d(TAG_KIWIX, "TextToSpeech: language not supported: " +
|
||||
ZimContentProvider.getLanguage() + " (" + locale.getLanguage() + ")");
|
||||
ZimContentProvider.getLanguage() + " (" + locale.getLanguage() + ")");
|
||||
Toast.makeText(context,
|
||||
context.getResources().getString(R.string.tts_lang_not_supported),
|
||||
Toast.LENGTH_LONG).show();
|
||||
context.getResources().getString(R.string.tts_lang_not_supported),
|
||||
Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
tts.setLanguage(locale);
|
||||
|
||||
// We use JavaScript to get the content of the page conveniently, earlier making some
|
||||
// changes in the page
|
||||
webView.loadUrl("javascript:" +
|
||||
"body = document.getElementsByTagName('body')[0].cloneNode(true);" +
|
||||
// Remove some elements that are shouldn't be read (table of contents,
|
||||
// references numbers, thumbnail captions, duplicated title, etc.)
|
||||
"toRemove = body.querySelectorAll('sup.reference, #toc, .thumbcaption, " +
|
||||
" title, .navbox');" +
|
||||
"Array.prototype.forEach.call(toRemove, function(elem) {" +
|
||||
" elem.parentElement.removeChild(elem);" +
|
||||
"});" +
|
||||
"tts.speakAloud(body.innerText);");
|
||||
}
|
||||
// We use JavaScript to get the content of the page conveniently, earlier making some
|
||||
// changes in the page
|
||||
webView.loadUrl("javascript:" +
|
||||
"body = document.getElementsByTagName('body')[0].cloneNode(true);" +
|
||||
// Remove some elements that are shouldn't be read (table of contents,
|
||||
// references numbers, thumbnail captions, duplicated title, etc.)
|
||||
"toRemove = body.querySelectorAll('sup.reference, #toc, .thumbcaption, " +
|
||||
" title, .navbox');" +
|
||||
"Array.prototype.forEach.call(toRemove, function(elem) {" +
|
||||
" elem.parentElement.removeChild(elem);" +
|
||||
"});" +
|
||||
"tts.speakAloud(body.innerText);");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,7 +149,30 @@ public class KiwixTextToSpeech {
|
||||
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 {
|
||||
|
||||
@JavascriptInterface
|
||||
@SuppressWarnings("unused")
|
||||
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;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebChromeClient;
|
||||
import android.webkit.WebSettings.LayoutAlgorithm;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.ZoomButtonsController;
|
||||
import android.webkit.WebSettings.LayoutAlgorithm;
|
||||
import android.os.Build;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import static org.kiwix.kiwixmobile.BackwardsCompatibilityTools.newApi;
|
||||
@ -44,34 +45,34 @@ public class KiwixWebView extends WebView {
|
||||
|
||||
public KiwixWebView(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
init();
|
||||
}
|
||||
|
||||
public KiwixWebView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
init();
|
||||
}
|
||||
|
||||
public KiwixWebView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
init();
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
setWebChromeClient(new WebChromeClient());
|
||||
setWebViewClient(new WebViewClient());
|
||||
getSettings().setJavaScriptEnabled(true);
|
||||
getSettings().setSupportMultipleWindows(true);
|
||||
getSettings().setSupportZoom(true);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
setWebChromeClient(new WebChromeClient());
|
||||
setWebViewClient(new WebViewClient());
|
||||
getSettings().setJavaScriptEnabled(true);
|
||||
getSettings().setSupportMultipleWindows(true);
|
||||
getSettings().setSupportZoom(true);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
|
||||
// Avoid crash with WebViewClassic
|
||||
try {
|
||||
getSettings().setLayoutAlgorithm(LayoutAlgorithm.TEXT_AUTOSIZING);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
// Avoid crash with WebViewClassic
|
||||
try {
|
||||
getSettings().setLayoutAlgorithm(LayoutAlgorithm.TEXT_AUTOSIZING);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -90,14 +91,14 @@ public class KiwixWebView extends WebView {
|
||||
super.onScrollChanged(l, t, oldl, oldt);
|
||||
int windowHeight = getMeasuredHeight();
|
||||
|
||||
// It seems that in a few cases, getMeasuredHeight() returns 0
|
||||
if (windowHeight > 0) {
|
||||
int pages = getContentHeight() / windowHeight;
|
||||
int page = t / windowHeight;
|
||||
if (mChangeListener != null) {
|
||||
mChangeListener.onPageChanged(page, pages);
|
||||
}
|
||||
}
|
||||
// It seems that in a few cases, getMeasuredHeight() returns 0
|
||||
if (windowHeight > 0) {
|
||||
int pages = getContentHeight() / windowHeight;
|
||||
int page = t / windowHeight;
|
||||
if (mChangeListener != null) {
|
||||
mChangeListener.onPageChanged(page, pages);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void disableZoomControlls(boolean disable) {
|
||||
@ -142,6 +143,7 @@ public class KiwixWebView extends WebView {
|
||||
}
|
||||
|
||||
public interface OnPageChangeListener {
|
||||
|
||||
public void onPageChanged(int page, int maxPages);
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,8 @@ public class LanguageUtils {
|
||||
Locale.setDefault(locale);
|
||||
Configuration config = new Configuration();
|
||||
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");
|
||||
|
||||
// Reduce the text size
|
||||
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textView.getTextSize() - 2f);
|
||||
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX,
|
||||
textView.getTextSize() - 2f);
|
||||
}
|
||||
});
|
||||
|
||||
return view;
|
||||
|
||||
} 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) {
|
||||
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,13 +23,12 @@ import android.content.ContentProvider;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.webkit.MimeTypeMap;
|
||||
import android.net.Uri;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.ParcelFileDescriptor.AutoCloseOutputStream;
|
||||
import android.util.Log;
|
||||
import android.webkit.MimeTypeMap;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
@ -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
|
||||
public boolean onCreate() {
|
||||
jniKiwix = new JNIKiwix();
|
||||
setIcuDataDirectory();
|
||||
setIcuDataDirectory();
|
||||
return (true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType(Uri uri) {
|
||||
String mimeType;
|
||||
String mimeType;
|
||||
|
||||
// This is the code which makes a guess based on the file extenstion
|
||||
String extension = MimeTypeMap.getFileExtensionFromUrl(uri.toString().toLowerCase());
|
||||
mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
|
||||
// This is the code which makes a guess based on the file extenstion
|
||||
String extension = MimeTypeMap.getFileExtensionFromUrl(uri.toString().toLowerCase());
|
||||
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
|
||||
if (mimeType.isEmpty() && jniKiwix != null && uri == null) {
|
||||
String t = uri.toString();
|
||||
@ -177,20 +203,20 @@ public class ZimContentProvider extends ContentProvider {
|
||||
t = t.substring(0, pos);
|
||||
}
|
||||
|
||||
mimeType = jniKiwix.getMimeType(t);
|
||||
mimeType = jniKiwix.getMimeType(t);
|
||||
|
||||
// Truncate mime-type (everything after the first space
|
||||
mimeType = mimeType.replaceAll("^([^ ]+).*$", "$1");
|
||||
// Truncate mime-type (everything after the first space
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParcelFileDescriptor openFile(Uri uri, String mode)
|
||||
throws FileNotFoundException {
|
||||
ParcelFileDescriptor[] pipe = null;
|
||||
throws FileNotFoundException {
|
||||
ParcelFileDescriptor[] pipe = null;
|
||||
|
||||
try {
|
||||
pipe = ParcelFileDescriptor.createPipe();
|
||||
@ -226,6 +252,16 @@ public class ZimContentProvider extends ContentProvider {
|
||||
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 {
|
||||
|
||||
Uri articleUri;
|
||||
@ -266,60 +302,28 @@ public class ZimContentProvider extends ContentProvider {
|
||||
JNIKiwixString mime = new JNIKiwixString();
|
||||
JNIKiwixInt size = new JNIKiwixInt();
|
||||
byte[] data = jniKiwix.getContent(articleZimUrl, mime, size);
|
||||
out.write(data, 0, data.length);
|
||||
out.write(data, 0, data.length);
|
||||
out.flush();
|
||||
|
||||
Log.d(TAG_KIWIX, "reading " + articleZimUrl
|
||||
+ "(mime: " + mime.value + ", size: " + size.value + ") finished.");
|
||||
+ "(mime: " + mime.value + ", size: " + size.value + ") finished.");
|
||||
} 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) {
|
||||
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 {
|
||||
try {
|
||||
out.close();
|
||||
} 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;
|
||||
|
||||
import com.actionbarsherlock.app.SherlockActivity;
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
import com.actionbarsherlock.view.Menu;
|
||||
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.Loader;
|
||||
import android.support.v4.widget.SimpleCursorAdapter;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.AlphaAnimation;
|
||||
@ -52,7 +48,6 @@ import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@ -235,7 +230,8 @@ public class ZimFileSelectActivity extends SherlockFragmentActivity
|
||||
protected void startQuery() {
|
||||
|
||||
// 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
|
||||
int[] mZimListItems = {android.R.id.text1, android.R.id.text2};
|
||||
|
@ -32,7 +32,8 @@ public class KiwixSettingsActivityHC extends Activity {
|
||||
public void onCreate(Bundle 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 {
|
||||
|
@ -114,7 +114,8 @@ public class SettingsHelper {
|
||||
String version;
|
||||
|
||||
try {
|
||||
version = getContext().getPackageManager().getPackageInfo("org.kiwix.kiwixmobile", 0).versionName;
|
||||
version = getContext().getPackageManager()
|
||||
.getPackageInfo("org.kiwix.kiwixmobile", 0).versionName;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
return;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user