mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 18:56:44 -04:00
Merge branch 'master' of ssh://git.code.sf.net/p/kiwix/kiwix
This commit is contained in:
commit
113ced72fb
@ -20,6 +20,7 @@
|
||||
<item android:id="@+id/menu_search"
|
||||
android:icon="@drawable/action_search"
|
||||
android:title="@string/menu_search"
|
||||
android:visible="false"
|
||||
android:orderInCategory="0"
|
||||
android:showAsAction="ifRoom" />
|
||||
|
||||
@ -38,7 +39,8 @@
|
||||
|
||||
<item android:id="@+id/menu_home"
|
||||
android:title="@string/menu_home"
|
||||
android:icon="@drawable/action_home"
|
||||
android:icon="@drawable/action_home"
|
||||
android:visible="false"
|
||||
android:orderInCategory="0"
|
||||
android:showAsAction="ifRoom" />
|
||||
|
||||
@ -50,10 +52,12 @@
|
||||
<item android:id="@+id/menu_searchintext"
|
||||
android:icon="@drawable/action_search"
|
||||
android:title="@string/menu_searchintext"
|
||||
android:orderInCategory="0"
|
||||
android:orderInCategory="0"
|
||||
android:showAsAction="never" />
|
||||
<item android:id="@+id/menu_randomarticle"
|
||||
android:title="@string/menu_randomarticle"
|
||||
android:visible="false"
|
||||
|
||||
android:orderInCategory="0"
|
||||
android:showAsAction="never" />
|
||||
|
||||
|
@ -1,10 +1,8 @@
|
||||
package org.kiwix.kiwixmobile;
|
||||
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
@ -48,12 +46,14 @@ public class KiwixMobileActivity extends Activity {
|
||||
private WebView webView;
|
||||
private ArrayAdapter<String> adapter;
|
||||
protected boolean requestClearHistoryAfterLoad;
|
||||
protected boolean requestShowAllMenuItems;
|
||||
protected int requestWebReloadOnFinished;
|
||||
private static final int ZIMFILESELECT_REQUEST_CODE = 1234;
|
||||
private static final int PREFERENCES_REQUEST_CODE = 1235;
|
||||
private static final String PREFS_KIWIX_MOBILE = "kiwix-mobile";
|
||||
private AutoCompleteTextView articleSearchtextView;
|
||||
private LinearLayout articleSearchBar;
|
||||
private Menu menu;
|
||||
|
||||
|
||||
public class AutoCompleteAdapter extends ArrayAdapter<String> implements Filterable {
|
||||
@ -121,6 +121,7 @@ public class KiwixMobileActivity extends Activity {
|
||||
super.onCreate(savedInstanceState);
|
||||
requestClearHistoryAfterLoad=false;
|
||||
requestWebReloadOnFinished = 0;
|
||||
requestShowAllMenuItems = false;
|
||||
|
||||
|
||||
this.requestWindowFeature(Window.FEATURE_PROGRESS);
|
||||
@ -330,6 +331,11 @@ public class KiwixMobileActivity extends Activity {
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.main, menu);
|
||||
|
||||
this.menu = menu;
|
||||
if (requestShowAllMenuItems) {
|
||||
showAllMenuItems();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -350,7 +356,7 @@ public class KiwixMobileActivity extends Activity {
|
||||
webView.showFindDialog("", true);
|
||||
break;
|
||||
case R.id.menu_home:
|
||||
loadMainPage();
|
||||
openMainPage();
|
||||
break;
|
||||
case R.id.menu_forward:
|
||||
if(webView.canGoForward() == true){
|
||||
@ -414,28 +420,7 @@ public class KiwixMobileActivity extends Activity {
|
||||
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
|
||||
}
|
||||
|
||||
private String readTextFromResource(int resourceID)
|
||||
{
|
||||
InputStream raw = getResources().openRawResource(resourceID);
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
int i;
|
||||
try
|
||||
{
|
||||
i = raw.read();
|
||||
while (i != -1)
|
||||
{
|
||||
stream.write(i);
|
||||
i = raw.read();
|
||||
}
|
||||
raw.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return stream.toString();
|
||||
}
|
||||
|
||||
|
||||
private void showWelcome() {
|
||||
webView.loadUrl("file:///android_res/raw/welcome.html");
|
||||
}
|
||||
@ -448,7 +433,6 @@ public class KiwixMobileActivity extends Activity {
|
||||
webView.loadUrl("file:///android_res/raw/help.html");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
switch (requestCode) {
|
||||
@ -494,7 +478,14 @@ public class KiwixMobileActivity extends Activity {
|
||||
// but to be on save side don't clear history in such cases.
|
||||
if (clearHistory)
|
||||
requestClearHistoryAfterLoad=true;
|
||||
loadMainPage();
|
||||
if (menu!=null) {
|
||||
showAllMenuItems();
|
||||
} else {
|
||||
// Menu may not be initialized yet. In this case
|
||||
// signal to menu create to show
|
||||
requestShowAllMenuItems = true;
|
||||
}
|
||||
openMainPage();
|
||||
return true;
|
||||
} else {
|
||||
Toast.makeText(this, getResources().getString(R.string.error_fileinvalid), Toast.LENGTH_LONG).show();
|
||||
@ -506,12 +497,14 @@ public class KiwixMobileActivity extends Activity {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void loadMainPage() {
|
||||
String article = ZimContentProvider.getMainPage();
|
||||
webView.loadUrl(Uri.parse(ZimContentProvider.CONTENT_URI
|
||||
+ article).toString());
|
||||
private void showAllMenuItems() {
|
||||
menu.findItem(R.id.menu_home).setVisible(true);
|
||||
menu.findItem(R.id.menu_randomarticle).setVisible(true);
|
||||
menu.findItem(R.id.menu_search).setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
@ -571,7 +564,10 @@ public class KiwixMobileActivity extends Activity {
|
||||
}
|
||||
|
||||
|
||||
|
||||
private boolean openMainPage() {
|
||||
String articleUrl = ZimContentProvider.getMainPage();
|
||||
return openArticle(articleUrl);
|
||||
}
|
||||
|
||||
public boolean isTablet(Context context) {
|
||||
return (context.getResources().getConfiguration().screenLayout
|
||||
|
@ -56,7 +56,7 @@ public class ZimContentProvider extends ContentProvider {
|
||||
return zimFileName;
|
||||
}
|
||||
public static String getZimFileTitle() {
|
||||
if (jniKiwix==null)
|
||||
if (jniKiwix==null || zimFileName==null)
|
||||
return null;
|
||||
else {
|
||||
JNIKiwixString title = new JNIKiwixString();
|
||||
@ -67,10 +67,8 @@ public class ZimContentProvider extends ContentProvider {
|
||||
}
|
||||
}
|
||||
|
||||
public native boolean getTitle(JNIKiwixString title);
|
||||
|
||||
public static String getMainPage() {
|
||||
if (jniKiwix==null)
|
||||
public static String getMainPage() {
|
||||
if (jniKiwix==null || zimFileName==null)
|
||||
return null;
|
||||
else {
|
||||
return jniKiwix.getMainPage();
|
||||
@ -78,7 +76,7 @@ public class ZimContentProvider extends ContentProvider {
|
||||
}
|
||||
|
||||
public static boolean searchSuggestions(String prefix, int count) {
|
||||
if (jniKiwix==null)
|
||||
if (jniKiwix==null || zimFileName==null)
|
||||
return false;
|
||||
else {
|
||||
return jniKiwix.searchSuggestions(prefix, count);
|
||||
@ -86,7 +84,7 @@ public class ZimContentProvider extends ContentProvider {
|
||||
}
|
||||
|
||||
public static String getNextSuggestion() {
|
||||
if (jniKiwix==null)
|
||||
if (jniKiwix==null || zimFileName==null)
|
||||
return null;
|
||||
else {
|
||||
JNIKiwixString title=new JNIKiwixString();
|
||||
@ -100,7 +98,7 @@ public class ZimContentProvider extends ContentProvider {
|
||||
}
|
||||
|
||||
public static String getPageUrlFromTitle(String title) {
|
||||
if (jniKiwix==null)
|
||||
if (jniKiwix==null || zimFileName==null)
|
||||
return null;
|
||||
else {
|
||||
JNIKiwixString url=new JNIKiwixString();
|
||||
@ -113,7 +111,7 @@ public class ZimContentProvider extends ContentProvider {
|
||||
}
|
||||
|
||||
public static String getRandomArticleUrl() {
|
||||
if (jniKiwix==null)
|
||||
if (jniKiwix==null || zimFileName==null)
|
||||
return null;
|
||||
else {
|
||||
JNIKiwixString url=new JNIKiwixString();
|
||||
|
Loading…
x
Reference in New Issue
Block a user