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,20 +4,25 @@ 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 BookmarkDialogListener listen;
|
||||||
|
|
||||||
private String[] contents;
|
private String[] contents;
|
||||||
|
|
||||||
private boolean isBookmarked;
|
private boolean isBookmarked;
|
||||||
public BookmarkDialog(String[] contents, boolean isBookmarked){
|
|
||||||
|
public BookmarkDialog(String[] contents, boolean isBookmarked) {
|
||||||
this.contents = contents;
|
this.contents = contents;
|
||||||
this.isBookmarked = isBookmarked;
|
this.isBookmarked = isBookmarked;
|
||||||
}
|
}
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState){
|
|
||||||
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
AlertDialog.Builder build = new AlertDialog.Builder(getActivity());
|
AlertDialog.Builder build = new AlertDialog.Builder(getActivity());
|
||||||
//build.setTitle(R.string.menu_bookmarks);
|
//build.setTitle(R.string.menu_bookmarks);
|
||||||
String buttonText;
|
String buttonText;
|
||||||
@ -48,15 +53,17 @@ public class BookmarkDialog extends DialogFragment {
|
|||||||
public void onAttach(Activity a) {
|
public void onAttach(Activity a) {
|
||||||
super.onAttach(a);
|
super.onAttach(a);
|
||||||
try {
|
try {
|
||||||
listen=(BookmarkDialogListener)a;
|
listen = (BookmarkDialogListener) a;
|
||||||
} catch (ClassCastException e){
|
} catch (ClassCastException e) {
|
||||||
throw new ClassCastException(a.toString()
|
throw new ClassCastException(a.toString()
|
||||||
+ " must implement BookmarkDialogListener");
|
+ " must implement BookmarkDialogListener");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface BookmarkDialogListener{
|
public interface BookmarkDialogListener {
|
||||||
|
|
||||||
public void onListItemSelect(String choice);
|
public void onListItemSelect(String choice);
|
||||||
|
|
||||||
public void onBookmarkButtonPressed();
|
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);
|
||||||
|
@ -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";
|
||||||
|
|
||||||
@ -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);
|
||||||
}
|
}
|
||||||
@ -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
|
||||||
|
@ -86,8 +86,8 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
@ -169,7 +169,7 @@ public class KiwixMobileFragment extends SherlockFragment {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
bookmarks=new ArrayList<String>();
|
bookmarks = new ArrayList<String>();
|
||||||
refreshBookmarks();
|
refreshBookmarks();
|
||||||
requestClearHistoryAfterLoad = false;
|
requestClearHistoryAfterLoad = false;
|
||||||
requestWebReloadOnFinished = 0;
|
requestWebReloadOnFinished = 0;
|
||||||
@ -211,7 +211,8 @@ public class KiwixMobileFragment extends SherlockFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
Bundle savedInstanceState) {
|
||||||
|
|
||||||
View root = inflater.inflate(R.layout.main, container, false);
|
View root = inflater.inflate(R.layout.main, container, false);
|
||||||
|
|
||||||
@ -225,7 +226,8 @@ public class KiwixMobileFragment extends SherlockFragment {
|
|||||||
|
|
||||||
articleSearchBar = (LinearLayout) root.findViewById(R.id.articleSearchBar);
|
articleSearchBar = (LinearLayout) root.findViewById(R.id.articleSearchBar);
|
||||||
|
|
||||||
articleSearchtextView = (AutoCompleteTextView) root.findViewById(R.id.articleSearchTextView);
|
articleSearchtextView = (AutoCompleteTextView) root
|
||||||
|
.findViewById(R.id.articleSearchTextView);
|
||||||
|
|
||||||
setUpExitFullscreenButton();
|
setUpExitFullscreenButton();
|
||||||
|
|
||||||
@ -308,13 +310,15 @@ public class KiwixMobileFragment extends SherlockFragment {
|
|||||||
SharedPreferences settings = getActivity().getSharedPreferences(PREF_KIWIX_MOBILE, 0);
|
SharedPreferences settings = getActivity().getSharedPreferences(PREF_KIWIX_MOBILE, 0);
|
||||||
String zimFile = settings.getString(TAG_CURRENTZIMFILE, null);
|
String zimFile = settings.getString(TAG_CURRENTZIMFILE, null);
|
||||||
if (zimFile != null) {
|
if (zimFile != null) {
|
||||||
Log.d(TAG_KIWIX, " Kiwix normal start, zimFile loaded last time -> Open last used zimFile "
|
Log.d(TAG_KIWIX,
|
||||||
|
" Kiwix normal start, zimFile loaded last time -> Open last used zimFile "
|
||||||
+ zimFile);
|
+ zimFile);
|
||||||
openZimFile(new File(zimFile), false);
|
openZimFile(new File(zimFile), false);
|
||||||
// Alternative would be to restore webView state. But more effort to implement, and actually
|
// Alternative would be to restore webView state. But more effort to implement, and actually
|
||||||
// fits better normal android behavior if after closing app ("back" button) state is not maintained.
|
// fits better normal android behavior if after closing app ("back" button) state is not maintained.
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG_KIWIX, " Kiwix normal start, no zimFile loaded last time -> display welcome page");
|
Log.d(TAG_KIWIX,
|
||||||
|
" Kiwix normal start, no zimFile loaded last time -> display welcome page");
|
||||||
showWelcome();
|
showWelcome();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -330,7 +334,8 @@ public class KiwixMobileFragment extends SherlockFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
articleSearchtextView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
|
articleSearchtextView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
|
||||||
int height = articleSearchtextView.getMeasuredHeight() - articleSearchtextView.getPaddingTop()
|
int height = articleSearchtextView.getMeasuredHeight() - articleSearchtextView
|
||||||
|
.getPaddingTop()
|
||||||
- articleSearchtextView.getPaddingBottom();
|
- articleSearchtextView.getPaddingBottom();
|
||||||
|
|
||||||
clearIcon.setBounds(0, 0, height, height);
|
clearIcon.setBounds(0, 0, height, height);
|
||||||
@ -358,7 +363,8 @@ public class KiwixMobileFragment extends SherlockFragment {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (event.getX() > articleSearchtextView.getWidth()
|
if (event.getX() > articleSearchtextView.getWidth()
|
||||||
- articleSearchtextView.getPaddingRight() - mClearIcon.getIntrinsicWidth()) {
|
- articleSearchtextView.getPaddingRight() - mClearIcon
|
||||||
|
.getIntrinsicWidth()) {
|
||||||
articleSearchtextView.setText("");
|
articleSearchtextView.setText("");
|
||||||
articleSearchtextView.setCompoundDrawables(mSearchIcon, null, null, null);
|
articleSearchtextView.setCompoundDrawables(mSearchIcon, null, null, null);
|
||||||
}
|
}
|
||||||
@ -377,7 +383,8 @@ public class KiwixMobileFragment extends SherlockFragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||||
articleSearchtextView.setCompoundDrawables(mSearchIcon, null,
|
articleSearchtextView.setCompoundDrawables(mSearchIcon, null,
|
||||||
articleSearchtextView.getText().toString().equals("") ? null : mClearIcon, null);
|
articleSearchtextView.getText().toString().equals("") ? null : mClearIcon,
|
||||||
|
null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -433,7 +440,8 @@ public class KiwixMobileFragment extends SherlockFragment {
|
|||||||
|
|
||||||
case DragEvent.ACTION_DRAG_ENDED:
|
case DragEvent.ACTION_DRAG_ENDED:
|
||||||
mTabDeleteCross.startAnimation(
|
mTabDeleteCross.startAnimation(
|
||||||
AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_out));
|
AnimationUtils
|
||||||
|
.loadAnimation(getActivity(), android.R.anim.fade_out));
|
||||||
mTabDeleteCross.setVisibility(View.INVISIBLE);
|
mTabDeleteCross.setVisibility(View.INVISIBLE);
|
||||||
mTabDeleteCross.getBackground().clearColorFilter();
|
mTabDeleteCross.getBackground().clearColorFilter();
|
||||||
}
|
}
|
||||||
@ -455,7 +463,8 @@ public class KiwixMobileFragment extends SherlockFragment {
|
|||||||
mBackToTopButton.setVisibility(View.VISIBLE);
|
mBackToTopButton.setVisibility(View.VISIBLE);
|
||||||
if (isAdded()) {
|
if (isAdded()) {
|
||||||
mBackToTopButton.startAnimation(
|
mBackToTopButton.startAnimation(
|
||||||
AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_in));
|
AnimationUtils.loadAnimation(getActivity(),
|
||||||
|
android.R.anim.fade_in));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -463,7 +472,8 @@ public class KiwixMobileFragment extends SherlockFragment {
|
|||||||
mBackToTopButton.setVisibility(View.INVISIBLE);
|
mBackToTopButton.setVisibility(View.INVISIBLE);
|
||||||
if (isAdded()) {
|
if (isAdded()) {
|
||||||
mBackToTopButton.startAnimation(
|
mBackToTopButton.startAnimation(
|
||||||
AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_out));
|
AnimationUtils.loadAnimation(getActivity(),
|
||||||
|
android.R.anim.fade_out));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -491,7 +501,8 @@ public class KiwixMobileFragment extends SherlockFragment {
|
|||||||
if (handleEvent) {
|
if (handleEvent) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
|
|
||||||
builder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(android.R.string.yes,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
mFragmentCommunicator.addNewTab(url);
|
mFragmentCommunicator.addNewTab(url);
|
||||||
}
|
}
|
||||||
@ -521,7 +532,8 @@ public class KiwixMobileFragment extends SherlockFragment {
|
|||||||
url = url.substring(url.lastIndexOf('/') + 1);
|
url = url.substring(url.lastIndexOf('/') + 1);
|
||||||
url = url.replaceAll(":", "_");
|
url = url.replaceAll(":", "_");
|
||||||
int dotIndex = url.lastIndexOf('.');
|
int dotIndex = url.lastIndexOf('.');
|
||||||
File storageDir = new File(Environment.getExternalStoragePublicDirectory(
|
File storageDir = new File(
|
||||||
|
Environment.getExternalStoragePublicDirectory(
|
||||||
Environment.DIRECTORY_PICTURES), url);
|
Environment.DIRECTORY_PICTURES), url);
|
||||||
String newurl = url;
|
String newurl = url;
|
||||||
for (int i = 2; storageDir.exists(); i++) {
|
for (int i = 2; storageDir.exists(); i++) {
|
||||||
@ -547,7 +559,9 @@ public class KiwixMobileFragment extends SherlockFragment {
|
|||||||
ostream.write(buffer, 0, len);
|
ostream.write(buffer, 0, len);
|
||||||
contentSize += len;
|
contentSize += len;
|
||||||
}
|
}
|
||||||
Log.i(TAG_KIWIX, "Save media " + source + " to " + storageDir + " (size: " + contentSize + ")");
|
Log.i(TAG_KIWIX,
|
||||||
|
"Save media " + source + " to " + storageDir + " (size: "
|
||||||
|
+ contentSize + ")");
|
||||||
|
|
||||||
istream.close();
|
istream.close();
|
||||||
ostream.close();
|
ostream.close();
|
||||||
@ -556,7 +570,8 @@ public class KiwixMobileFragment extends SherlockFragment {
|
|||||||
toastText = getResources().getString(R.string.save_media_error);
|
toastText = getResources().getString(R.string.save_media_error);
|
||||||
} finally {
|
} finally {
|
||||||
toastText = String
|
toastText = String
|
||||||
.format(getResources().getString(R.string.save_media_saved), newurl);
|
.format(getResources().getString(R.string.save_media_saved),
|
||||||
|
newurl);
|
||||||
}
|
}
|
||||||
|
|
||||||
Toast.makeText(getActivity(), toastText, Toast.LENGTH_LONG).show();
|
Toast.makeText(getActivity(), toastText, Toast.LENGTH_LONG).show();
|
||||||
@ -581,7 +596,8 @@ public class KiwixMobileFragment extends SherlockFragment {
|
|||||||
// Image long-press
|
// Image long-press
|
||||||
webView.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
|
webView.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
|
public void onCreateContextMenu(ContextMenu menu, View v,
|
||||||
|
ContextMenu.ContextMenuInfo menuInfo) {
|
||||||
final HitTestResult result = ((WebView) v).getHitTestResult();
|
final HitTestResult result = ((WebView) v).getHitTestResult();
|
||||||
if (result.getType() == HitTestResult.IMAGE_ANCHOR_TYPE
|
if (result.getType() == HitTestResult.IMAGE_ANCHOR_TYPE
|
||||||
|| result.getType() == HitTestResult.IMAGE_TYPE
|
|| result.getType() == HitTestResult.IMAGE_TYPE
|
||||||
@ -749,7 +765,8 @@ public class KiwixMobileFragment extends SherlockFragment {
|
|||||||
} else if (pref_zoom.equals(LARGE)) {
|
} else if (pref_zoom.equals(LARGE)) {
|
||||||
webView.getSettings().setDefaultZoom(WebSettings.ZoomDensity.CLOSE);
|
webView.getSettings().setDefaultZoom(WebSettings.ZoomDensity.CLOSE);
|
||||||
} else {
|
} else {
|
||||||
Log.w(TAG_KIWIX, "pref_displayZoom value (" + pref_zoom + " unknown. Assuming automatic");
|
Log.w(TAG_KIWIX,
|
||||||
|
"pref_displayZoom value (" + pref_zoom + " unknown. Assuming automatic");
|
||||||
webView.getSettings().setDefaultZoom(WebSettings.ZoomDensity.MEDIUM);
|
webView.getSettings().setDefaultZoom(WebSettings.ZoomDensity.MEDIUM);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -818,7 +835,8 @@ public class KiwixMobileFragment extends SherlockFragment {
|
|||||||
// densities, we will just use the previously added white cross icon and apply a red filter on it.
|
// densities, we will just use the previously added white cross icon and apply a red filter on it.
|
||||||
mTabDeleteCross.getBackground().setColorFilter(Color.RED, PorterDuff.Mode.MULTIPLY);
|
mTabDeleteCross.getBackground().setColorFilter(Color.RED, PorterDuff.Mode.MULTIPLY);
|
||||||
mTabDeleteCross.setVisibility(View.VISIBLE);
|
mTabDeleteCross.setVisibility(View.VISIBLE);
|
||||||
mTabDeleteCross.startAnimation(AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_in));
|
mTabDeleteCross.startAnimation(
|
||||||
|
AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_in));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showWelcome() {
|
public void showWelcome() {
|
||||||
@ -913,7 +931,7 @@ public class KiwixMobileFragment extends SherlockFragment {
|
|||||||
public void toggleBookmark() {
|
public void toggleBookmark() {
|
||||||
String title = webView.getTitle();
|
String title = webView.getTitle();
|
||||||
|
|
||||||
if (title!=null && !bookmarks.contains(title)){
|
if (title != null && !bookmarks.contains(title)) {
|
||||||
bookmarks.add(title);
|
bookmarks.add(title);
|
||||||
} else {
|
} else {
|
||||||
bookmarks.remove(title);
|
bookmarks.remove(title);
|
||||||
@ -922,21 +940,24 @@ public class KiwixMobileFragment extends SherlockFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void viewBookmarks() {
|
public void viewBookmarks() {
|
||||||
new BookmarkDialog(bookmarks.toArray(new String[bookmarks.size()]),bookmarks.contains(webView.getTitle())).show(getActivity().getSupportFragmentManager(), "BookmarkDialog");
|
new BookmarkDialog(bookmarks.toArray(new String[bookmarks.size()]),
|
||||||
|
bookmarks.contains(webView.getTitle()))
|
||||||
|
.show(getActivity().getSupportFragmentManager(), "BookmarkDialog");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshBookmarks() {
|
private void refreshBookmarks() {
|
||||||
bookmarks.clear();
|
bookmarks.clear();
|
||||||
if (ZimContentProvider.getId()!=null) {
|
if (ZimContentProvider.getId() != null) {
|
||||||
try {
|
try {
|
||||||
InputStream stream = getActivity().openFileInput(ZimContentProvider.getId()+".txt");
|
InputStream stream = getActivity()
|
||||||
|
.openFileInput(ZimContentProvider.getId() + ".txt");
|
||||||
String in;
|
String in;
|
||||||
if (stream!= null) {
|
if (stream != null) {
|
||||||
BufferedReader read = new BufferedReader(new InputStreamReader(stream));
|
BufferedReader read = new BufferedReader(new InputStreamReader(stream));
|
||||||
while((in=read.readLine())!=null) {
|
while ((in = read.readLine()) != null) {
|
||||||
bookmarks.add(in);
|
bookmarks.add(in);
|
||||||
}
|
}
|
||||||
Log.d(TAG_KIWIX, "Switched to bookmarkfile "+ZimContentProvider.getId());
|
Log.d(TAG_KIWIX, "Switched to bookmarkfile " + ZimContentProvider.getId());
|
||||||
}
|
}
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
Log.e(TAG_KIWIX, "File not found: " + e.toString());
|
Log.e(TAG_KIWIX, "File not found: " + e.toString());
|
||||||
@ -948,13 +969,14 @@ public class KiwixMobileFragment extends SherlockFragment {
|
|||||||
|
|
||||||
private void saveBookmarks() {
|
private void saveBookmarks() {
|
||||||
try {
|
try {
|
||||||
OutputStream stream = getActivity().openFileOutput(ZimContentProvider.getId()+".txt", Context.MODE_PRIVATE);
|
OutputStream stream = getActivity()
|
||||||
if (stream!= null) {
|
.openFileOutput(ZimContentProvider.getId() + ".txt", Context.MODE_PRIVATE);
|
||||||
for(String s:bookmarks){
|
if (stream != null) {
|
||||||
stream.write((s+"\n").getBytes());
|
for (String s : bookmarks) {
|
||||||
|
stream.write((s + "\n").getBytes());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.d(TAG_KIWIX, "Saved data in bookmarkfile "+ZimContentProvider.getId());
|
Log.d(TAG_KIWIX, "Saved data in bookmarkfile " + ZimContentProvider.getId());
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
Log.e(TAG_KIWIX, "File not found: " + e.toString());
|
Log.e(TAG_KIWIX, "File not found: " + e.toString());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -963,12 +985,13 @@ public class KiwixMobileFragment extends SherlockFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean openArticleFromBookmark(String bookmarkTitle) {
|
public boolean openArticleFromBookmark(String bookmarkTitle) {
|
||||||
Log.d(TAG_KIWIX, "openArticleFromBookmark: "+articleSearchtextView.getText());
|
Log.d(TAG_KIWIX, "openArticleFromBookmark: " + articleSearchtextView.getText());
|
||||||
return openArticle(ZimContentProvider.getPageUrlFromTitle(bookmarkTitle));
|
return openArticle(ZimContentProvider.getPageUrlFromTitle(bookmarkTitle));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean openArticle(String articleUrl) {
|
private boolean openArticle(String articleUrl) {
|
||||||
Log.d(TAG_KIWIX, articleSearchtextView + " onEditorAction. TextView: " + articleSearchtextView
|
Log.d(TAG_KIWIX,
|
||||||
|
articleSearchtextView + " onEditorAction. TextView: " + articleSearchtextView
|
||||||
.getText() + " articleUrl: " + articleUrl);
|
.getText() + " articleUrl: " + articleUrl);
|
||||||
|
|
||||||
if (articleUrl != null) {
|
if (articleUrl != null) {
|
||||||
@ -976,9 +999,11 @@ public class KiwixMobileFragment extends SherlockFragment {
|
|||||||
webView.loadUrl(Uri.parse(ZimContentProvider.CONTENT_URI
|
webView.loadUrl(Uri.parse(ZimContentProvider.CONTENT_URI
|
||||||
+ articleUrl).toString());
|
+ articleUrl).toString());
|
||||||
} else {
|
} else {
|
||||||
String errorString = String.format(getResources().getString(R.string.error_articlenotfound),
|
String errorString = String
|
||||||
|
.format(getResources().getString(R.string.error_articlenotfound),
|
||||||
articleSearchtextView.getText().toString());
|
articleSearchtextView.getText().toString());
|
||||||
Toast.makeText(getActivity().getWindow().getContext(), errorString, Toast.LENGTH_SHORT).show();
|
Toast.makeText(getActivity().getWindow().getContext(), errorString, Toast.LENGTH_SHORT)
|
||||||
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -1228,13 +1253,16 @@ public class KiwixMobileFragment extends SherlockFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
|
public void onReceivedError(WebView view, int errorCode, String description,
|
||||||
|
String failingUrl) {
|
||||||
|
|
||||||
String errorString = String.format(getResources().getString(R.string.error_articleurlnotfound),
|
String errorString = String
|
||||||
|
.format(getResources().getString(R.string.error_articleurlnotfound),
|
||||||
failingUrl);
|
failingUrl);
|
||||||
// TODO apparently screws up back/forward
|
// TODO apparently screws up back/forward
|
||||||
webView.loadDataWithBaseURL("file://error",
|
webView.loadDataWithBaseURL("file://error",
|
||||||
"<html><body>" + errorString + "</body></html>", "text/html", "utf-8", failingUrl);
|
"<html><body>" + errorString + "</body></html>", "text/html", "utf-8",
|
||||||
|
failingUrl);
|
||||||
String title = getResources().getString(R.string.app_name);
|
String title = getResources().getString(R.string.app_name);
|
||||||
getSherlockActivity().getSupportActionBar().setTitle(title);
|
getSherlockActivity().getSupportActionBar().setTitle(title);
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -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) {
|
||||||
@ -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;
|
||||||
@ -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,13 +23,12 @@ 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;
|
||||||
@ -147,6 +146,33 @@ 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();
|
||||||
@ -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;
|
||||||
@ -272,54 +308,22 @@ public class ZimContentProvider extends ContentProvider {
|
|||||||
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