From 097883c1eecdb49209348d0c6ef591126445df9c Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Tue, 21 Jun 2011 20:48:20 +0000 Subject: [PATCH] - Delete old temp files on startup - Catch loadUrl() exception - Stub out settings and menus - Enable double-tap to zoom in webview on Droid --- AndroidManifest.xml | 14 +++++--- res/layout/main.xml | 6 ++-- res/menu/menu1.xml | 17 +++++++++ res/raw/releasenotes_txt | 3 +- res/xml/settings1.xml | 6 ++++ scripts/setversion.sh | 2 +- .../router/activity/I2PActivityBase.java | 35 +++++++++++++++++++ .../router/activity/I2PWebViewClient.java | 14 ++++++-- .../android/router/activity/NewsActivity.java | 2 ++ .../router/activity/SettingsActivity.java | 15 ++++++++ .../android/router/activity/WebActivity.java | 2 ++ src/net/i2p/android/router/service/Init.java | 18 ++++++++-- 12 files changed, 120 insertions(+), 14 deletions(-) create mode 100755 res/menu/menu1.xml create mode 100644 res/xml/settings1.xml create mode 100644 src/net/i2p/android/router/activity/SettingsActivity.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 2363507be..229ff16c2 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -16,7 +16,7 @@ android:label="@string/app_name" android:icon="@drawable/ic_launcher_itoopie" /> <activity android:name=".activity.MainActivity" - android:label="@string/app_name" + android:label="I2P Main Page" android:icon="@drawable/ic_launcher_itoopie" android.theme="@android:style/Theme.NoTitleBar" android:launchMode="singleTask" > @@ -26,19 +26,23 @@ </intent-filter> </activity> <activity android:name=".activity.NewsActivity" - android:label="@string/app_name" + android:label="I2P News" android.theme="@android:style/Theme.NoTitleBar" > </activity> <activity android:name=".activity.TextResourceActivity" - android:label="@string/app_name" + android:label="I2P Information" android.theme="@android:style/Theme.NoTitleBar" > </activity> <activity android:name=".activity.LicenseActivity" - android:label="@string/app_name" + android:label="Licenses" android.theme="@android:style/Theme.NoTitleBar" > </activity> <activity android:name=".activity.WebActivity" - android:label="@string/app_name" + android:label="Web Browser" + android.theme="@android:style/Theme.NoTitleBar" > + </activity> + <activity android:name=".activity.SettingsActivity" + android:label="Settings" android.theme="@android:style/Theme.NoTitleBar" > </activity> </application> diff --git a/res/layout/main.xml b/res/layout/main.xml index eb19eff23..b16744faa 100644 --- a/res/layout/main.xml +++ b/res/layout/main.xml @@ -24,19 +24,19 @@ android:id="@+id/website_button" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="Web Site" + android:text="Web Site\n(non-anon)" /> <Button android:id="@+id/faq_button" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="FAQ" + android:text="FAQ\n(non-anon)" /> <Button android:id="@+id/welcome_button" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="Welcome" + android:text="Welcome\nPage" /> </LinearLayout> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" diff --git a/res/menu/menu1.xml b/res/menu/menu1.xml new file mode 100755 index 000000000..9ef1eb1af --- /dev/null +++ b/res/menu/menu1.xml @@ -0,0 +1,17 @@ +<menu xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:title="Preferences" + android:titleCondensed="Settings" + android:id="@+id/menu_settings" + android:icon="@android:drawable/ic_menu_preferences" > + </item> + <item android:title="Start Router" + android:id="@+id/menu_start" + android:titleCondensed="Start" + android:icon="@drawable/ic_menu_play_clip" > + </item> + <item android:title="Stop Router" + android:id="@+id/menu_stop" + android:titleCondensed="Stop" + android:icon="@android:drawable/ic_menu_close_clear_cancel" > + </item> +</menu> diff --git a/res/raw/releasenotes_txt b/res/raw/releasenotes_txt index f15307819..c20d3834f 100644 --- a/res/raw/releasenotes_txt +++ b/res/raw/releasenotes_txt @@ -2,7 +2,7 @@ WARNING - This is ALPHA SOFTWARE. It may crash your phone. Do not rely upon it for strong anonymity. Tunnels may be as short as one hop. -Minimum Android OS is 2.1 (SDK 7). The app is only tested on the Motorola Droid. It uses a lot of RAM. You need at least 256 MB of RAM. 512 should be much better. +Minimum Android OS is 2.2 (API 8). The app is only tested on the Motorola Droid. It uses a lot of RAM. You need at least 256 MB of RAM. 512 should be much better. The app may use a lot of RAM even after the router has stopped and there is no icon in the notification bar. Go to Settings -> Applications -> Running Services and stop the I2P service if necessary. Or Settings -> Applications -> Manage Applications -> Running -> I2P and force stop. @@ -35,6 +35,7 @@ For eepsites, there are several other things to note: - No way to type in addresses - No addressbook app yet, so you only have what is in the standard hosts.txt - Eepsites are not found in the cache when hitting the back button + - Fetches are aborted when you rotate the screen Using clients with the router diff --git a/res/xml/settings1.xml b/res/xml/settings1.xml new file mode 100644 index 000000000..d83230f0d --- /dev/null +++ b/res/xml/settings1.xml @@ -0,0 +1,6 @@ +<PreferenceScreen + xmlns:android="http://schemas.android.com/apk/res/android" + android:key="settings1"> + <CheckBoxPreference + android:key="test" android:title="Check it or not"/> +</PreferenceScreen> diff --git a/scripts/setversion.sh b/scripts/setversion.sh index cb60fb3f4..51b5ff7bd 100755 --- a/scripts/setversion.sh +++ b/scripts/setversion.sh @@ -26,7 +26,7 @@ SDK=`grep 'android:minSdkVersion' $MANIFEST | \ cut -d '"' -f 2` # don't let build number get too long -VERSIONSTRING="${CORE}-${ROUTERBUILD}_b$(($ANDROIDBUILD % 256))-SDK$SDK" +VERSIONSTRING="${CORE}-${ROUTERBUILD}_b$(($ANDROIDBUILD % 512))-API$SDK" # # Android version code is an integer. diff --git a/src/net/i2p/android/router/activity/I2PActivityBase.java b/src/net/i2p/android/router/activity/I2PActivityBase.java index 0fd14f02b..38e014cb9 100644 --- a/src/net/i2p/android/router/activity/I2PActivityBase.java +++ b/src/net/i2p/android/router/activity/I2PActivityBase.java @@ -6,7 +6,11 @@ import android.content.Intent; import android.content.ServiceConnection; import android.os.Bundle; import android.os.IBinder; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import net.i2p.android.router.R; import net.i2p.android.router.binder.RouterBinder; import net.i2p.android.router.service.RouterService; import net.i2p.router.CommSystemFacade; @@ -98,6 +102,35 @@ public abstract class I2PActivityBase extends Activity { super.onDestroy(); } + @Override + public boolean onCreateOptionsMenu(Menu menu) { + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.menu1, menu); + return true; + } + + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + // add/hide items here + return super.onPrepareOptionsMenu(menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.menu_settings: + Intent intent = new Intent(I2PActivityBase.this, SettingsActivity.class); + startActivityForResult(intent, 0); + return true; + case R.id.menu_start: + case R.id.menu_stop: + default: + return super.onOptionsItemSelected(item); + } + } + + ////// Service stuff + protected boolean bindRouter() { Intent intent = new Intent(); intent.setClassName(this, "net.i2p.android.router.service.RouterService"); @@ -130,6 +163,8 @@ public abstract class I2PActivityBase extends Activity { } } + ////// Router stuff + protected RouterContext getRouterContext() { if (_routerService == null || !_isBound) return null; diff --git a/src/net/i2p/android/router/activity/I2PWebViewClient.java b/src/net/i2p/android/router/activity/I2PWebViewClient.java index 8a5c870b3..69d613555 100644 --- a/src/net/i2p/android/router/activity/I2PWebViewClient.java +++ b/src/net/i2p/android/router/activity/I2PWebViewClient.java @@ -127,7 +127,12 @@ class I2PWebViewClient extends WebViewClient { protected Integer doInBackground(String... urls) { publishProgress(Integer.valueOf(-1)); - _view.loadUrl(urls[0]); + try { + _view.loadUrl(urls[0]); + } catch (Exception e) { + // CalledFromWrongThreadException + cancel(false); + } return Integer.valueOf(0); } @@ -181,7 +186,12 @@ class I2PWebViewClient extends WebViewClient { System.err.println("Fetch cancelled for " + url); return Integer.valueOf(0); } - _view.loadDataWithBaseURL(url, d, t, e, url); + try { + _view.loadDataWithBaseURL(url, d, t, e, url); + } catch (Exception exc) { + // CalledFromWrongThreadException + cancel(false); + } return Integer.valueOf(0); } diff --git a/src/net/i2p/android/router/activity/NewsActivity.java b/src/net/i2p/android/router/activity/NewsActivity.java index 9b2c9a1c2..e48d9e90e 100644 --- a/src/net/i2p/android/router/activity/NewsActivity.java +++ b/src/net/i2p/android/router/activity/NewsActivity.java @@ -38,6 +38,8 @@ public class NewsActivity extends I2PActivityBase { setContentView(R.layout.news); WebView wv = (WebView) findViewById(R.id.news_webview); wv.getSettings().setLoadsImagesAutomatically(false); + // http://stackoverflow.com/questions/2369310/webview-double-tap-zoom-not-working-on-a-motorola-droid-a855 + wv.getSettings().setUseWideViewPort(true); _wvClient = new I2PWebViewClient(); wv.setWebViewClient(_wvClient); wv.getSettings().setBuiltInZoomControls(true); diff --git a/src/net/i2p/android/router/activity/SettingsActivity.java b/src/net/i2p/android/router/activity/SettingsActivity.java new file mode 100644 index 000000000..a7aca9e58 --- /dev/null +++ b/src/net/i2p/android/router/activity/SettingsActivity.java @@ -0,0 +1,15 @@ +package net.i2p.android.router.activity; + +import android.os.Bundle; +import android.preference.PreferenceActivity; + +import net.i2p.android.router.R; + +public class SettingsActivity extends PreferenceActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + addPreferencesFromResource(R.xml.settings1); + } +} diff --git a/src/net/i2p/android/router/activity/WebActivity.java b/src/net/i2p/android/router/activity/WebActivity.java index 88d7845c4..8d263f373 100644 --- a/src/net/i2p/android/router/activity/WebActivity.java +++ b/src/net/i2p/android/router/activity/WebActivity.java @@ -36,6 +36,8 @@ public class WebActivity extends I2PActivityBase { _wvClient = new I2PWebViewClient(); wv.setWebViewClient(_wvClient); wv.getSettings().setBuiltInZoomControls(true); + // http://stackoverflow.com/questions/2369310/webview-double-tap-zoom-not-working-on-a-motorola-droid-a855 + wv.getSettings().setUseWideViewPort(true); Intent intent = getIntent(); Uri uri = intent.getData(); if (uri != null) { diff --git a/src/net/i2p/android/router/service/Init.java b/src/net/i2p/android/router/service/Init.java index c99341add..9f0c4fac9 100644 --- a/src/net/i2p/android/router/service/Init.java +++ b/src/net/i2p/android/router/service/Init.java @@ -19,8 +19,9 @@ import net.i2p.data.DataHelper; import net.i2p.router.Router; import net.i2p.router.RouterContext; import net.i2p.router.RouterLaunch; -import net.i2p.util.OrderedProperties; +import net.i2p.util.FileUtil; import net.i2p.util.NativeBigInteger; +import net.i2p.util.OrderedProperties; class Init { @@ -93,7 +94,7 @@ class Init { copyResourceToFile(R.raw.blocklist_txt, "blocklist.txt"); } - (new File(myDir, "wrapper.log")).delete(); + deleteOldFiles(); // Set up the locations so Router and WorkingDir can find them System.setProperty("i2p.dir.base", myDir); @@ -200,4 +201,17 @@ class Init { } return newVersion; } + + private void deleteOldFiles() { + (new File(myDir, "wrapper.log")).delete(); + File tmp = new File(myDir, "tmp"); + File[] files = tmp.listFiles(); + if (files != null) { + for (int i = 0; i < files.length; i++) { + File f = files[i]; + System.err.println("Deleting old file/dir " + f); + FileUtil.rmdir(f, false); + } + } + } } -- GitLab