Merge branch 'master' of ssh://git.code.sf.net/p/kiwix/kiwix

This commit is contained in:
renaud gaudin 2013-04-08 19:37:47 +02:00
commit 113ced72fb
3 changed files with 42 additions and 44 deletions

View File

@ -20,6 +20,7 @@
<item android:id="@+id/menu_search" <item android:id="@+id/menu_search"
android:icon="@drawable/action_search" android:icon="@drawable/action_search"
android:title="@string/menu_search" android:title="@string/menu_search"
android:visible="false"
android:orderInCategory="0" android:orderInCategory="0"
android:showAsAction="ifRoom" /> android:showAsAction="ifRoom" />
@ -38,7 +39,8 @@
<item android:id="@+id/menu_home" <item android:id="@+id/menu_home"
android:title="@string/menu_home" android:title="@string/menu_home"
android:icon="@drawable/action_home" android:icon="@drawable/action_home"
android:visible="false"
android:orderInCategory="0" android:orderInCategory="0"
android:showAsAction="ifRoom" /> android:showAsAction="ifRoom" />
@ -50,10 +52,12 @@
<item android:id="@+id/menu_searchintext" <item android:id="@+id/menu_searchintext"
android:icon="@drawable/action_search" android:icon="@drawable/action_search"
android:title="@string/menu_searchintext" android:title="@string/menu_searchintext"
android:orderInCategory="0" android:orderInCategory="0"
android:showAsAction="never" /> android:showAsAction="never" />
<item android:id="@+id/menu_randomarticle" <item android:id="@+id/menu_randomarticle"
android:title="@string/menu_randomarticle" android:title="@string/menu_randomarticle"
android:visible="false"
android:orderInCategory="0" android:orderInCategory="0"
android:showAsAction="never" /> android:showAsAction="never" />

View File

@ -1,10 +1,8 @@
package org.kiwix.kiwixmobile; package org.kiwix.kiwixmobile;
import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
@ -48,12 +46,14 @@ public class KiwixMobileActivity extends Activity {
private WebView webView; private WebView webView;
private ArrayAdapter<String> adapter; private ArrayAdapter<String> adapter;
protected boolean requestClearHistoryAfterLoad; protected boolean requestClearHistoryAfterLoad;
protected boolean requestShowAllMenuItems;
protected int requestWebReloadOnFinished; protected int requestWebReloadOnFinished;
private static final int ZIMFILESELECT_REQUEST_CODE = 1234; private static final int ZIMFILESELECT_REQUEST_CODE = 1234;
private static final int PREFERENCES_REQUEST_CODE = 1235; private static final int PREFERENCES_REQUEST_CODE = 1235;
private static final String PREFS_KIWIX_MOBILE = "kiwix-mobile"; private static final String PREFS_KIWIX_MOBILE = "kiwix-mobile";
private AutoCompleteTextView articleSearchtextView; private AutoCompleteTextView articleSearchtextView;
private LinearLayout articleSearchBar; private LinearLayout articleSearchBar;
private Menu menu;
public class AutoCompleteAdapter extends ArrayAdapter<String> implements Filterable { public class AutoCompleteAdapter extends ArrayAdapter<String> implements Filterable {
@ -121,6 +121,7 @@ public class KiwixMobileActivity extends Activity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
requestClearHistoryAfterLoad=false; requestClearHistoryAfterLoad=false;
requestWebReloadOnFinished = 0; requestWebReloadOnFinished = 0;
requestShowAllMenuItems = false;
this.requestWindowFeature(Window.FEATURE_PROGRESS); this.requestWindowFeature(Window.FEATURE_PROGRESS);
@ -330,6 +331,11 @@ public class KiwixMobileActivity extends Activity {
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater(); MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu); inflater.inflate(R.menu.main, menu);
this.menu = menu;
if (requestShowAllMenuItems) {
showAllMenuItems();
}
return true; return true;
} }
@ -350,7 +356,7 @@ public class KiwixMobileActivity extends Activity {
webView.showFindDialog("", true); webView.showFindDialog("", true);
break; break;
case R.id.menu_home: case R.id.menu_home:
loadMainPage(); openMainPage();
break; break;
case R.id.menu_forward: case R.id.menu_forward:
if(webView.canGoForward() == true){ if(webView.canGoForward() == true){
@ -414,28 +420,7 @@ public class KiwixMobileActivity extends Activity {
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0); 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() { private void showWelcome() {
webView.loadUrl("file:///android_res/raw/welcome.html"); 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"); webView.loadUrl("file:///android_res/raw/help.html");
} }
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) { switch (requestCode) {
@ -494,7 +478,14 @@ public class KiwixMobileActivity extends Activity {
// but to be on save side don't clear history in such cases. // but to be on save side don't clear history in such cases.
if (clearHistory) if (clearHistory)
requestClearHistoryAfterLoad=true; 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; return true;
} else { } else {
Toast.makeText(this, getResources().getString(R.string.error_fileinvalid), Toast.LENGTH_LONG).show(); Toast.makeText(this, getResources().getString(R.string.error_fileinvalid), Toast.LENGTH_LONG).show();
@ -506,12 +497,14 @@ public class KiwixMobileActivity extends Activity {
return false; return false;
} }
private void loadMainPage() { private void showAllMenuItems() {
String article = ZimContentProvider.getMainPage(); menu.findItem(R.id.menu_home).setVisible(true);
webView.loadUrl(Uri.parse(ZimContentProvider.CONTENT_URI menu.findItem(R.id.menu_randomarticle).setVisible(true);
+ article).toString()); menu.findItem(R.id.menu_search).setVisible(true);
} }
@Override @Override
public boolean onKeyDown(int keyCode, KeyEvent event) { 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) { public boolean isTablet(Context context) {
return (context.getResources().getConfiguration().screenLayout return (context.getResources().getConfiguration().screenLayout

View File

@ -56,7 +56,7 @@ public class ZimContentProvider extends ContentProvider {
return zimFileName; return zimFileName;
} }
public static String getZimFileTitle() { public static String getZimFileTitle() {
if (jniKiwix==null) if (jniKiwix==null || zimFileName==null)
return null; return null;
else { else {
JNIKiwixString title = new JNIKiwixString(); 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 || zimFileName==null)
public static String getMainPage() {
if (jniKiwix==null)
return null; return null;
else { else {
return jniKiwix.getMainPage(); return jniKiwix.getMainPage();
@ -78,7 +76,7 @@ public class ZimContentProvider extends ContentProvider {
} }
public static boolean searchSuggestions(String prefix, int count) { public static boolean searchSuggestions(String prefix, int count) {
if (jniKiwix==null) if (jniKiwix==null || zimFileName==null)
return false; return false;
else { else {
return jniKiwix.searchSuggestions(prefix, count); return jniKiwix.searchSuggestions(prefix, count);
@ -86,7 +84,7 @@ public class ZimContentProvider extends ContentProvider {
} }
public static String getNextSuggestion() { public static String getNextSuggestion() {
if (jniKiwix==null) if (jniKiwix==null || zimFileName==null)
return null; return null;
else { else {
JNIKiwixString title=new JNIKiwixString(); JNIKiwixString title=new JNIKiwixString();
@ -100,7 +98,7 @@ public class ZimContentProvider extends ContentProvider {
} }
public static String getPageUrlFromTitle(String title) { public static String getPageUrlFromTitle(String title) {
if (jniKiwix==null) if (jniKiwix==null || zimFileName==null)
return null; return null;
else { else {
JNIKiwixString url=new JNIKiwixString(); JNIKiwixString url=new JNIKiwixString();
@ -113,7 +111,7 @@ public class ZimContentProvider extends ContentProvider {
} }
public static String getRandomArticleUrl() { public static String getRandomArticleUrl() {
if (jniKiwix==null) if (jniKiwix==null || zimFileName==null)
return null; return null;
else { else {
JNIKiwixString url=new JNIKiwixString(); JNIKiwixString url=new JNIKiwixString();