From cdc98de35069b9f324abe41fde86b2e0d2064dea Mon Sep 17 00:00:00 2001 From: fkloft Date: Wed, 18 Sep 2013 12:59:40 +0200 Subject: [PATCH 1/7] Move activity labels to strings.xml (and some code formatting) --- mobile/AndroidManifest.xml | 44 +++++----- mobile/res/values/strings.xml | 15 ++-- .../IITC_PluginPreferenceActivity.java | 88 +++++++++---------- .../iitc_mobile/IITC_PreferenceActivity.java | 11 ++- 4 files changed, 79 insertions(+), 79 deletions(-) diff --git a/mobile/AndroidManifest.xml b/mobile/AndroidManifest.xml index f5659971..d369b1e9 100644 --- a/mobile/AndroidManifest.xml +++ b/mobile/AndroidManifest.xml @@ -1,8 +1,8 @@ + package="com.cradle.iitc_mobile" + android:versionCode="47" + android:versionName="0.6.3"> + android:theme="@style/AppBaseTheme"> @@ -37,7 +37,7 @@ - + @@ -49,12 +49,12 @@ + android:pathPrefix="/intel" + android:scheme="https"/> + android:pathPrefix="/intel" + android:scheme="http"/> @@ -68,24 +68,24 @@ - + + android:configChanges="orientation|keyboard|keyboardHidden|screenSize" + android:label="@string/activity_settings" + android:theme="@style/AppBaseTheme"/> - + android:configChanges="orientation|keyboard|keyboardHidden|screenSize" + android:label="@string/activity_plugins" + android:theme="@style/AppBaseTheme"/> @@ -100,7 +100,7 @@ android:excludeFromRecents="true" android:exported="false" android:icon="@drawable/copy" - android:label="Copy to clipboard" + android:label="@string/activity_share_to_clipboard" android:noHistory="false"> @@ -137,4 +137,4 @@ android:value="com.cradle.iitc_mobile.IITC_Mobile"/> - + \ No newline at end of file diff --git a/mobile/res/values/strings.xml b/mobile/res/values/strings.xml index c1265866..d4696eee 100644 --- a/mobile/res/values/strings.xml +++ b/mobile/res/values/strings.xml @@ -2,6 +2,10 @@ IITC Mobile + IITC Mobile Settings + IITC Plugins + Share using… + Copy to clipboard Settings Reload IITC Print Version @@ -17,7 +21,7 @@ About IITC Mobile - Ingress Intel Total Conversion Mobile

+Ingress Intel Total Conversion Mobile

by cradle and contributors

Icon by Giuseppe Lucido

IITC Mobile is an optimized mobile browser for the @@ -67,9 +71,9 @@ Press back button twice to exit Avoids accidental exits Developer options - Enable developer mode - If enabled, all IITC sources will be loaded from external storage of the Android device. - Please copy all sources from $IITC_folder/build/mobile/ to /sdcard/IITC_Mobile/dev/. + Enable developer mode + If enabled, all IITC sources will be loaded from external storage of the Android device. + Please copy all sources from $IITC_folder/build/mobile/ to /sdcard/IITC_Mobile/dev/. Display advanced menu In addition to the default IITC buttons the advanced menu contains a debug pane plus an option to clear cookies @@ -99,4 +103,5 @@ Base Layers Overlay Layers Deselect/Select all -
+ + \ No newline at end of file diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_PluginPreferenceActivity.java b/mobile/src/com/cradle/iitc_mobile/IITC_PluginPreferenceActivity.java index d05562cc..701ae608 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_PluginPreferenceActivity.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_PluginPreferenceActivity.java @@ -1,6 +1,14 @@ package com.cradle.iitc_mobile; -import android.app.ActionBar; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Scanner; +import java.util.TreeMap; + import android.content.Context; import android.content.res.AssetManager; import android.os.Bundle; @@ -16,15 +24,6 @@ import android.widget.ArrayAdapter; import android.widget.ListAdapter; import android.widget.TextView; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Scanner; -import java.util.TreeMap; - public class IITC_PluginPreferenceActivity extends PreferenceActivity { private List
mHeaders; @@ -43,9 +42,8 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity { @Override public void onBuildHeaders(List
target) { - ActionBar bar = getActionBar(); - bar.setTitle("IITC Plugins"); - bar.setDisplayHomeAsUpEnabled(true); + getActionBar().setDisplayHomeAsUpEnabled(true); + mHeaders = target; // since the plugins container is static, // it is enough to parse the plugin only on first start. @@ -62,8 +60,7 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity { @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { - // exit settings when home button (iitc icon) is pressed - case android.R.id.home: + case android.R.id.home: // exit settings when home button (iitc icon) is pressed onBackPressed(); return true; default: @@ -157,8 +154,7 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity { } } - void addPluginPreference(String src, String plugin_key, - boolean user) { + void addPluginPreference(String src, String plugin_key, boolean user) { // now parse plugin name, description and category String header = src.substring(src.indexOf("==UserScript=="), @@ -306,20 +302,20 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity { if (convertView == null) { holder = new HeaderViewHolder(); switch (headerType) { - case HEADER_TYPE_CATEGORY: - view = new TextView(getContext(), null, - android.R.attr.listSeparatorTextViewStyle); - holder.title = (TextView) view; - break; + case HEADER_TYPE_CATEGORY: + view = new TextView(getContext(), null, + android.R.attr.listSeparatorTextViewStyle); + holder.title = (TextView) view; + break; - case HEADER_TYPE_NORMAL: - view = mInflater.inflate(R.layout.preference_header_item, - parent, false); - holder.title = (TextView) view - .findViewById(R.id.plug_pref_title); - holder.summary = (TextView) view - .findViewById(R.id.plug_pref_summary); - break; + case HEADER_TYPE_NORMAL: + view = mInflater.inflate(R.layout.preference_header_item, + parent, false); + holder.title = (TextView) view + .findViewById(R.id.plug_pref_title); + holder.summary = (TextView) view + .findViewById(R.id.plug_pref_summary); + break; } view.setTag(holder); } else { @@ -330,22 +326,22 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity { // All view fields must be updated every time, because the view may // be recycled switch (headerType) { - case HEADER_TYPE_CATEGORY: - holder.title.setText(header.getTitle(getContext() - .getResources())); - break; - case HEADER_TYPE_NORMAL: - holder.title.setText(header.getTitle(getContext() - .getResources())); - CharSequence summary = header.getSummary(getContext() - .getResources()); - if (!TextUtils.isEmpty(summary)) { - holder.summary.setVisibility(View.VISIBLE); - holder.summary.setText(summary); - } else { - holder.summary.setVisibility(View.GONE); - } - break; + case HEADER_TYPE_CATEGORY: + holder.title.setText(header.getTitle(getContext() + .getResources())); + break; + case HEADER_TYPE_NORMAL: + holder.title.setText(header.getTitle(getContext() + .getResources())); + CharSequence summary = header.getSummary(getContext() + .getResources()); + if (!TextUtils.isEmpty(summary)) { + holder.summary.setVisibility(View.VISIBLE); + holder.summary.setText(summary); + } else { + holder.summary.setVisibility(View.GONE); + } + break; } return view; diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_PreferenceActivity.java b/mobile/src/com/cradle/iitc_mobile/IITC_PreferenceActivity.java index ad222eff..2595d41b 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_PreferenceActivity.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_PreferenceActivity.java @@ -14,8 +14,6 @@ public class IITC_PreferenceActivity extends Activity { MainSettings settings = new MainSettings(); - // set action bar title - getActionBar().setTitle("IITC Mobile Settings"); getActionBar().setHomeButtonEnabled(true); // iitc version @@ -23,15 +21,16 @@ public class IITC_PreferenceActivity extends Activity { settings.setArguments(bundle); // Display the fragment as the main content. - getFragmentManager().beginTransaction() - .replace(android.R.id.content, settings).commit(); + getFragmentManager() + .beginTransaction() + .replace(android.R.id.content, settings) + .commit(); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { - // exit settings when home button (iitc icon) is pressed - case android.R.id.home: + case android.R.id.home: // exit settings when home button (iitc icon) is pressed onBackPressed(); return true; default: From eee9ce78e014629fdac65735a02519a0fb997cf7 Mon Sep 17 00:00:00 2001 From: fkloft Date: Wed, 18 Sep 2013 15:31:50 +0200 Subject: [PATCH 2/7] But ActionBar related stuff into new class ActionBarHelper --- .../cradle/iitc_mobile/ActionBarHelper.java | 102 ++++++++++++++ .../cradle/iitc_mobile/IITC_JSInterface.java | 53 ++------ .../com/cradle/iitc_mobile/IITC_Mobile.java | 124 ++++++++---------- 3 files changed, 174 insertions(+), 105 deletions(-) create mode 100644 mobile/src/com/cradle/iitc_mobile/ActionBarHelper.java diff --git a/mobile/src/com/cradle/iitc_mobile/ActionBarHelper.java b/mobile/src/com/cradle/iitc_mobile/ActionBarHelper.java new file mode 100644 index 00000000..912957e8 --- /dev/null +++ b/mobile/src/com/cradle/iitc_mobile/ActionBarHelper.java @@ -0,0 +1,102 @@ +package com.cradle.iitc_mobile; + +import android.app.ActionBar; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; +import android.widget.Toast; + +public class ActionBarHelper { + /* + * Show/hide the up arrow on the left end + * getActionBar().setDisplayHomeAsUpEnabled(enabled); + * + * Show/hide the activity icon/logo + * getActionBar().setDisplayShowHomeEnabled(enabled); + * + * Show/hide the activity title + * getActionBar().setDisplayShowTitleEnabled(enabled); + * + * Makes the icon/title clickable + * getActionBar().setHomeButtonEnabled(enabled); + */ + + private ActionBar mActionBar; + private IITC_Mobile mIitc; + private SharedPreferences mPrefs; + + private boolean mDesktopMode = false; + private boolean mFullscreen = false; + private boolean mHideInFullscreen = false; + private int mPane = android.R.id.home; + + public ActionBarHelper(IITC_Mobile activity, ActionBar bar) { + mIitc = activity; + mActionBar = bar; + mPrefs = PreferenceManager.getDefaultSharedPreferences(activity); + + mActionBar.setDisplayShowHomeEnabled(true); // show icon + + onPrefChanged(); // also calls updateActionBar() + } + + private void updateActionBar() { + if (mDesktopMode) { + mActionBar.setDisplayHomeAsUpEnabled(false); // Hide "up" indicator + mActionBar.setHomeButtonEnabled(false); // Make icon unclickable + mActionBar.setTitle(mIitc.getString(R.string.app_name)); + } else { + if (mPane != android.R.id.home) + { + mActionBar.setDisplayHomeAsUpEnabled(true); // Show "up" indicator + mActionBar.setHomeButtonEnabled(true);// Make icon clickable + } + else + { + mActionBar.setDisplayHomeAsUpEnabled(false); // Hide "up" indicator + mActionBar.setHomeButtonEnabled(false); // Make icon unclickable + } + mActionBar.setTitle(IITC_Mobile.PANE_TITLES.get(mPane, mIitc.getString(R.string.app_name))); + } + + if (mFullscreen && mHideInFullscreen) + mActionBar.hide(); + else + mActionBar.show(); + } + + @Deprecated + public void goHome() { + switchTo(android.R.id.home); + } + + public boolean hideInFullscreen() { + return mHideInFullscreen; + } + + public void onPrefChanged() { + mDesktopMode = mPrefs.getBoolean("pref_force_desktop", false); + mHideInFullscreen = mPrefs.getBoolean("pref_fullscreen_actionbar", false); + updateActionBar(); + } + + public void reset() + { + mPane = android.R.id.home; + updateActionBar(); + } + + public void setFullscreen(boolean fullscreen) { + mFullscreen = fullscreen; + if (mFullscreen && mHideInFullscreen) { + // show a toast with instructions to exit the fullscreen mode again + Toast.makeText(mIitc, "Press back button to exit fullscreen", Toast.LENGTH_SHORT).show(); + } + + updateActionBar(); + } + + public void switchTo(int button) { + mPane = button; + updateActionBar(); + } +} diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java b/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java index e6a84364..66eecbad 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java @@ -96,46 +96,20 @@ public class IITC_JSInterface { } @JavascriptInterface - public void switchToPane(String id) { - + public void switchToPane(final String id) { final IITC_Mobile iitcm = (IITC_Mobile) mContext; - final int button_id; - final String title; - if (id.equals("map")) { - button_id = android.R.id.home; - title = iitcm.getString(R.string.app_name); - } else if (id.equals("info")) { - button_id = R.id.menu_info; - title = "Info"; - } else if (id.equals("full")) { - button_id = R.id.menu_full; - title = "Full"; - } else if (id.equals("compact")) { - button_id = R.id.menu_compact; - title = "Compact"; - } else if (id.equals("public")) { - button_id = R.id.menu_public; - title = "Public"; - } else if (id.equals("faction")) { - button_id = R.id.menu_faction; - title = "Faction"; - } else if (id.equals("debug")) { - button_id = R.id.menu_debug; - title = "Debug"; - } - // default - else { - button_id = android.R.id.home; - title = iitcm.getString(R.string.app_name); - } - - Log.d("iitcm", "switch to pane " + id); iitcm.runOnUiThread(new Runnable() { @Override public void run() { - iitcm.getActionBar().setTitle(title); - iitcm.backStackUpdate(button_id); + ActionBarHelper actionbar = iitcm.getActionBarHelper(); + Integer button = IITC_Mobile.PANES.get(id); + + if (button == null) + button = android.R.id.home; + + actionbar.switchTo(button); + iitcm.backStackUpdate(button); } }); } @@ -169,10 +143,10 @@ public class IITC_JSInterface { public void setLayers(String base_layer, String overlay_layer) { /* - * the layer strings have a form like: - * [{"layerId":27,"name":"MapQuest OSM","active":true}, - * {"layerId":28,"name":"Default Ingress Map","active":false}] - * Put it in a JSONArray and parse it + * the layer strings have a form like: + * [{"layerId":27,"name":"MapQuest OSM","active":true}, + * {"layerId":28,"name":"Default Ingress Map","active":false}] + * Put it in a JSONArray and parse it */ JSONArray base_layersJSON = null; JSONArray overlay_layersJSON = null; @@ -287,6 +261,7 @@ public class IITC_JSInterface { final ListView list = dialog.getListView(); list.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { boolean disable = false; + @Override public boolean onItemLongClick(AdapterView adapterView, View view, int i, long l) { int j = 0; diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java index 63278c8b..42794353 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java @@ -1,5 +1,10 @@ package com.cradle.iitc_mobile; +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.HashMap; + import android.app.ActionBar; import android.app.Activity; import android.app.AlertDialog; @@ -16,11 +21,11 @@ import android.location.LocationManager; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.Uri; -import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.preference.PreferenceManager; import android.util.Log; +import android.util.SparseArray; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -32,10 +37,6 @@ import android.webkit.WebView; import android.widget.SearchView; import android.widget.Toast; -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.ArrayList; - public class IITC_Mobile extends Activity { private static final int REQUEST_LOGIN = 1; @@ -48,8 +49,6 @@ public class IITC_Mobile extends Activity { private LocationManager mLocMngr = null; private LocationListener mLocListener = null; private boolean mFullscreenMode = false; - private boolean mFullscreenActionbar = false; - private ActionBar mActionBar; private IITC_DeviceAccountLogin mLogin; private MenuItem mSearchMenuItem; private boolean mDesktopMode = false; @@ -57,6 +56,7 @@ public class IITC_Mobile extends Activity { private boolean mReloadNeeded = false; private final ArrayList mDialogStack = new ArrayList(); private SharedPreferences mSharedPrefs; + private ActionBarHelper mActionBarHelper; // Used for custom back stack handling private final ArrayList mBackStack = new ArrayList(); @@ -64,6 +64,27 @@ public class IITC_Mobile extends Activity { private int mCurrentPane = android.R.id.home; private boolean mBackButtonPressed = false; + public static final SparseArray PANE_TITLES = new SparseArray(); + public static final HashMap PANES = new HashMap(); + + static { + PANES.put("map", android.R.id.home); + PANES.put("info", R.id.menu_info); + PANES.put("full", R.id.menu_full); + PANES.put("compact", R.id.menu_compact); + PANES.put("public", R.id.menu_public); + PANES.put("faction", R.id.menu_faction); + PANES.put("debug", R.id.menu_debug); + + // No need to declare android.R.id.home - that title is default + PANE_TITLES.append(R.id.menu_info, "Info"); + PANE_TITLES.append(R.id.menu_full, "Full"); + PANE_TITLES.append(R.id.menu_compact, "Compact"); + PANE_TITLES.append(R.id.menu_public, "Public"); + PANE_TITLES.append(R.id.menu_faction, "Faction"); + PANE_TITLES.append(R.id.menu_debug, "Debug"); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -74,13 +95,8 @@ public class IITC_Mobile extends Activity { setContentView(R.layout.activity_main); mIitcWebView = (IITC_WebView) findViewById(R.id.iitc_webview); - // fetch actionbar, set display flags, title and enable home button - mActionBar = this.getActionBar(); - mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME - | ActionBar.DISPLAY_USE_LOGO | ActionBar.DISPLAY_SHOW_TITLE); - mActionBar.setTitle(getString(R.string.app_name)); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) - mActionBar.setHomeButtonEnabled(true); + // pass ActionBar to helper because we deprecated getActionBar + mActionBarHelper = new ActionBarHelper(this, super.getActionBar()); // do something if user changed something in the settings mSharedPrefs = PreferenceManager @@ -91,21 +107,14 @@ public class IITC_Mobile extends Activity { SharedPreferences sharedPreferences, String key) { if (key.equals("pref_force_desktop")) { mDesktopMode = sharedPreferences.getBoolean("pref_force_desktop", false); - if (mDesktopMode) { - setActionBarHomeEnabledWithUp(false); - mActionBar.setTitle(getString(R.string.app_name)); - } else mActionBar.setHomeButtonEnabled(true); + mActionBarHelper.onPrefChanged(); invalidateOptionsMenu(); } if (key.equals("pref_user_loc")) mIsLocEnabled = sharedPreferences.getBoolean("pref_user_loc", false); if (key.equals("pref_fullscreen_actionbar")) { - mFullscreenActionbar = sharedPreferences.getBoolean("pref_fullscreen_actionbar", - false); - if (mFullscreenMode) - IITC_Mobile.this.getActionBar().hide(); - // no iitc reload needed here + mActionBarHelper.onPrefChanged(); return; } if (key.equals("pref_advanced_menu")) { @@ -142,8 +151,7 @@ public class IITC_Mobile extends Activity { mLastLocation = location; } - public void onStatusChanged(String provider, int status, - Bundle extras) { + public void onStatusChanged(String provider, int status, Bundle extras) { } public void onProviderEnabled(String provider) { @@ -163,11 +171,8 @@ public class IITC_Mobile extends Activity { mLocListener); } - mFullscreenActionbar = mSharedPrefs.getBoolean("pref_fullscreen_actionbar", false); - // Clear the back stack mBackStack.clear(); - setActionBarHomeEnabledWithUp(false); handleIntent(getIntent(), true); } @@ -222,7 +227,7 @@ public class IITC_Mobile extends Activity { (SearchView) mSearchMenuItem.getActionView(); searchView.setQuery(query, false); searchView.clearFocus(); - mActionBar.setTitle(getString(R.string.app_name)); + mActionBarHelper.switchTo(android.R.id.home); backStackUpdate(android.R.id.home); mIitcWebView.loadUrl("javascript:search('" + query + "');"); return; @@ -345,7 +350,7 @@ public class IITC_Mobile extends Activity { } // exit fullscreen mode if it is enabled and action bar is disabled // or the back stack is empty - if (mFullscreenMode && (mBackStack.isEmpty() || mFullscreenActionbar)) { + if (mFullscreenMode && (mBackStack.isEmpty() || mActionBarHelper.hideInFullscreen())) { this.toggleFullscreen(); } else if (!mBackStack.isEmpty()) { // Pop last item from backstack and pretend the relevant menu item was clicked @@ -367,19 +372,12 @@ public class IITC_Mobile extends Activity { } } - private void setActionBarHomeEnabledWithUp(boolean enabled) { - mActionBar.setDisplayHomeAsUpEnabled(enabled); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) - mActionBar.setHomeButtonEnabled(enabled); - } - public void backStackPop() { // shouldn't be called when back stack is empty // catch wrong usage if (mBackStack.isEmpty()) { // Empty back stack means we should be at home (ie map) screen - setActionBarHomeEnabledWithUp(false); - mActionBar.setTitle(getString(R.string.app_name)); + mActionBarHelper.switchTo(android.R.id.home); mIitcWebView.loadUrl("javascript: window.show('map');"); return; } @@ -403,13 +401,6 @@ public class IITC_Mobile extends Activity { } mCurrentPane = itemId; - if (mBackStack.size() >= 1) { - setActionBarHomeEnabledWithUp(true); - } else { - // if we popped our last item from stack...illustrate it on home button - // Empty back stack means we should be at home (ie map) screen - setActionBarHomeEnabledWithUp(false); - } } @Override @@ -456,14 +447,13 @@ public class IITC_Mobile extends Activity { // the getLayers function calls the setLayers method of IITC_JSInterface mIitcWebView.loadUrl("javascript: window.layerChooser.getLayers()"); return true; - // get the users current location and focus it on map - case R.id.locate: + case R.id.locate: // get the users current location and focus it on map mIitcWebView.loadUrl("javascript: window.show('map');"); // get location from network by default if (!mIsLocEnabled) { mIitcWebView.loadUrl("javascript: " + "window.map.locate({setView : true, maxZoom: 15});"); - // if gps location is displayed we can use a better location without any costs + // if gps location is displayed we can use a better location without any costs } else { if (mLastLocation != null) mIitcWebView.loadUrl("javascript: window.map.setView(new L.LatLng(" + @@ -471,8 +461,7 @@ public class IITC_Mobile extends Activity { mLastLocation.getLongitude() + "), 15);"); } return true; - // start settings activity - case R.id.action_settings: + case R.id.action_settings: // start settings activity Intent intent = new Intent(this, IITC_PreferenceActivity.class); intent.putExtra("iitc_version", mIitcWebView.getWebViewClient() .getIITCVersion()); @@ -506,9 +495,8 @@ public class IITC_Mobile extends Activity { } public void reloadIITC() { - mActionBar.setTitle(getString(R.string.app_name)); + mActionBarHelper.reset(); mBackStack.clear(); - setActionBarHomeEnabledWithUp(false); // iitc starts on map after reload mCurrentPane = android.R.id.home; this.loadUrl(mIntelUrl); @@ -556,19 +544,9 @@ public class IITC_Mobile extends Activity { } public void toggleFullscreen() { - if (mFullscreenMode) { - if (mFullscreenActionbar) - this.getActionBar().show(); - this.mFullscreenMode = false; - } else { - if (mFullscreenActionbar) { - this.getActionBar().hide(); - // show a toast with instructions to exit the fc mode again - Toast.makeText(this, "Press back button to exit fullscreen", - Toast.LENGTH_SHORT).show(); - } - this.mFullscreenMode = true; - } + mFullscreenMode = !mFullscreenMode; + mActionBarHelper.setFullscreen(mFullscreenMode); + // toggle notification bar WindowManager.LayoutParams attrs = getWindow().getAttributes(); attrs.flags ^= WindowManager.LayoutParams.FLAG_FULLSCREEN; @@ -604,7 +582,7 @@ public class IITC_Mobile extends Activity { * called by IITC_WebViewClient when the Google login form is opened. */ public void onReceivedLoginRequest(IITC_WebViewClient client, WebView view, - String realm, String account, String args) { + String realm, String account, String args) { Log.d("iitcm", "logging in...set caching mode to default"); mIitcWebView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); mLogin = new IITC_DeviceAccountLogin(this, view, client); @@ -665,4 +643,18 @@ public class IITC_Mobile extends Activity { item = menu.findItem(R.id.menu_clear_cookies); item.setVisible(mAdvancedMenu); } + + /** + * @deprecated ActionBar related stuff should be handled by ActionBarHelper + */ + @Deprecated + @Override + public ActionBar getActionBar() { + return super.getActionBar(); + } + + public ActionBarHelper getActionBarHelper() + { + return mActionBarHelper; + } } From 6290ef56aa54ef1749cdc77a749ee28d1094a13e Mon Sep 17 00:00:00 2001 From: fkloft Date: Wed, 18 Sep 2013 16:29:10 +0200 Subject: [PATCH 3/7] Use reloadIITC() if mReloadNeeded == true --- .../com/cradle/iitc_mobile/IITC_Mobile.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java index 42794353..e5eac879 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java @@ -99,8 +99,7 @@ public class IITC_Mobile extends Activity { mActionBarHelper = new ActionBarHelper(this, super.getActionBar()); // do something if user changed something in the settings - mSharedPrefs = PreferenceManager - .getDefaultSharedPreferences(this); + mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); mSharedPrefChangeListener = new OnSharedPreferenceChangeListener() { @Override public void onSharedPreferenceChanged( @@ -289,23 +288,21 @@ public class IITC_Mobile extends Activity { // enough idle...let's do some work Log.d("iitcm", "resuming...reset idleTimer"); - mIitcWebView.loadUrl("javascript: window.idleReset();"); mIitcWebView.updateCaching(); if (mIsLocEnabled) { // Register the mSharedPrefChangeListener with the Location Manager to receive // location updates - mLocMngr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, - 0, 0, mLocListener); - mLocMngr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, - mLocListener); + mLocMngr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, mLocListener); + mLocMngr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mLocListener); } if (mReloadNeeded) { Log.d("iitcm", "preference had changed...reload needed"); - this.loadUrl(mIntelUrl); - mReloadNeeded = false; + reloadIITC(); } + else + mIitcWebView.loadUrl("javascript: window.idleReset();"); } @Override @@ -499,7 +496,8 @@ public class IITC_Mobile extends Activity { mBackStack.clear(); // iitc starts on map after reload mCurrentPane = android.R.id.home; - this.loadUrl(mIntelUrl); + loadUrl(mIntelUrl); + mReloadNeeded = false; } private void loadIITC() { From daaef1575ea5e0d677ba7a27edee1c1f716bf9a3 Mon Sep 17 00:00:00 2001 From: fkloft Date: Wed, 18 Sep 2013 16:43:12 +0200 Subject: [PATCH 4/7] Show portal highlighters in action bar --- code/portal_highlighter.js | 14 ++++ .../cradle/iitc_mobile/ActionBarHelper.java | 81 ++++++++++++++++--- .../cradle/iitc_mobile/IITC_JSInterface.java | 22 +++++ 3 files changed, 104 insertions(+), 13 deletions(-) diff --git a/code/portal_highlighter.js b/code/portal_highlighter.js index e9de1edc..ee03a883 100644 --- a/code/portal_highlighter.js +++ b/code/portal_highlighter.js @@ -11,14 +11,26 @@ window.addPortalHighlighter = function(name, callback) { _highlighters = {}; } _highlighters[name] = callback; + + if (typeof android !== 'undefined' && android && android.addPortalHighlighter) + android.addPortalHighlighter(name); + if(localStorage.portal_highlighter === undefined) { _current_highlighter = name; + if (typeof android !== 'undefined' && android && android.setActiveHighlighter) + android.setActiveHighlighter(name); + localStorage.portal_highlighter = name; } portalHighlighterControl(); } window.portalHighlighterControl = function() { + if (typeof android !== 'undefined' && android && android.addPortalHighlighter) { + $('#portal_highlight_select').remove(); + return; + } + if(_highlighters !== null) { if($('#portal_highlight_select').length === 0) { $("body").append(""); @@ -46,6 +58,8 @@ window.portalHighlighterControl = function() { window.changePortalHighlights = function(name) { _current_highlighter = name; + if (typeof android !== 'undefined' && android && android.setActiveHighlighter) + android.setActiveHighlighter(name); resetHighlightedPortals(); localStorage.portal_highlighter = name; } diff --git a/mobile/src/com/cradle/iitc_mobile/ActionBarHelper.java b/mobile/src/com/cradle/iitc_mobile/ActionBarHelper.java index 912957e8..c8499b8e 100644 --- a/mobile/src/com/cradle/iitc_mobile/ActionBarHelper.java +++ b/mobile/src/com/cradle/iitc_mobile/ActionBarHelper.java @@ -1,11 +1,13 @@ package com.cradle.iitc_mobile; import android.app.ActionBar; +import android.app.ActionBar.OnNavigationListener; import android.content.SharedPreferences; import android.preference.PreferenceManager; +import android.widget.ArrayAdapter; import android.widget.Toast; -public class ActionBarHelper { +public class ActionBarHelper implements OnNavigationListener { /* * Show/hide the up arrow on the left end * getActionBar().setDisplayHomeAsUpEnabled(enabled); @@ -20,10 +22,31 @@ public class ActionBarHelper { * getActionBar().setHomeButtonEnabled(enabled); */ - private ActionBar mActionBar; - private IITC_Mobile mIitc; - private SharedPreferences mPrefs; + private class HighlighterAdapter extends ArrayAdapter { + public HighlighterAdapter() { + super(mIitc, android.R.layout.simple_list_item_1); + clear(); + } + @Override + public void add(String object) { + super.remove(object); // to avoid duplicates + super.add(object); + } + + @Override + public void clear() { + super.clear(); + add("No Highlights");// Probably must be the same as window._no_highlighter + } + } + + private IITC_Mobile mIitc; + private ActionBar mActionBar; + private SharedPreferences mPrefs; + private HighlighterAdapter mHighlighters; + + private String mActiveHighlighter = null; private boolean mDesktopMode = false; private boolean mFullscreen = false; private boolean mHideInFullscreen = false; @@ -33,58 +56,90 @@ public class ActionBarHelper { mIitc = activity; mActionBar = bar; mPrefs = PreferenceManager.getDefaultSharedPreferences(activity); + mHighlighters = new HighlighterAdapter(); mActionBar.setDisplayShowHomeEnabled(true); // show icon + mActionBar.setListNavigationCallbacks(mHighlighters, this); onPrefChanged(); // also calls updateActionBar() } private void updateActionBar() { + boolean showHighlighter = true; + if (mDesktopMode) { mActionBar.setDisplayHomeAsUpEnabled(false); // Hide "up" indicator mActionBar.setHomeButtonEnabled(false); // Make icon unclickable mActionBar.setTitle(mIitc.getString(R.string.app_name)); } else { - if (mPane != android.R.id.home) - { + if (mPane != android.R.id.home) { mActionBar.setDisplayHomeAsUpEnabled(true); // Show "up" indicator mActionBar.setHomeButtonEnabled(true);// Make icon clickable + showHighlighter = false; } - else - { + else { mActionBar.setDisplayHomeAsUpEnabled(false); // Hide "up" indicator mActionBar.setHomeButtonEnabled(false); // Make icon unclickable } mActionBar.setTitle(IITC_Mobile.PANE_TITLES.get(mPane, mIitc.getString(R.string.app_name))); } + if (mHighlighters.getCount() < 2) // there should always be "No Highlights" + showHighlighter = false; + + if (showHighlighter) { + mActionBar.setDisplayShowTitleEnabled(false); // Hide title + mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); + } else { + mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); + mActionBar.setDisplayShowTitleEnabled(true); // Show title + } if (mFullscreen && mHideInFullscreen) mActionBar.hide(); else mActionBar.show(); } - @Deprecated - public void goHome() { - switchTo(android.R.id.home); + public void addPortalHighlighter(String name) { + mHighlighters.add(name); + + if (name.equals(mActiveHighlighter)) + setActiveHighlighter(name); + + updateActionBar(); } public boolean hideInFullscreen() { return mHideInFullscreen; } + @Override + public boolean onNavigationItemSelected(int position, long itemId) { + String name = mHighlighters.getItem(position); + mIitc.getWebView().loadUrl("javascript: window.changePortalHighlights('" + name + "')"); + return true; + } + public void onPrefChanged() { mDesktopMode = mPrefs.getBoolean("pref_force_desktop", false); mHideInFullscreen = mPrefs.getBoolean("pref_fullscreen_actionbar", false); updateActionBar(); } - public void reset() - { + public void reset() { + mHighlighters.clear(); mPane = android.R.id.home; updateActionBar(); } + public void setActiveHighlighter(String name) { + int position = mHighlighters.getPosition(name); + if (position >= 0) + mActionBar.setSelectedNavigationItem(position); + + mActiveHighlighter = name; + } + public void setFullscreen(boolean fullscreen) { mFullscreen = fullscreen; if (mFullscreen && mHideInFullscreen) { diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java b/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java index 66eecbad..99dc95bb 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java @@ -230,6 +230,28 @@ public class IITC_JSInterface { showMultiSelection(); } + @JavascriptInterface + public void addPortalHighlighter(final String name) { + final IITC_Mobile iitc = ((IITC_Mobile) mContext); + iitc.runOnUiThread(new Runnable() { + @Override + public void run() { + iitc.getActionBarHelper().addPortalHighlighter(name); + } + }); + } + + @JavascriptInterface + public void setActiveHighlighter(final String name) { + final IITC_Mobile iitc = ((IITC_Mobile) mContext); + iitc.runOnUiThread(new Runnable() { + @Override + public void run() { + iitc.getActionBarHelper().setActiveHighlighter(name); + } + }); + } + // show all overlay layers in a multi selection list dialog private void showMultiSelection() { // build the layer chooser dialog From 1a1008c70e9714a9712af4bb6ac036c8fa7cd035 Mon Sep 17 00:00:00 2001 From: fkloft Date: Wed, 18 Sep 2013 16:48:30 +0200 Subject: [PATCH 5/7] Code formatting, removed dead code, fixed warning --- .../com/cradle/iitc_mobile/IITC_Mobile.java | 24 ++-------- .../iitc_mobile/async/CheckHttpResponse.java | 17 ++++--- .../iitc_mobile/share/IntentFragment.java | 3 +- .../iitc_mobile/share/IntentListView.java | 15 ++---- .../iitc_mobile/share/ShareActivity.java | 46 +++++++++---------- 5 files changed, 40 insertions(+), 65 deletions(-) diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java index e5eac879..40ed984b 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java @@ -18,8 +18,6 @@ import android.content.res.Configuration; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; -import android.net.ConnectivityManager; -import android.net.NetworkInfo; import android.net.Uri; import android.os.Bundle; import android.os.Handler; @@ -256,17 +254,13 @@ public class IITC_Mobile extends Activity { throw use; } - if (parts.length > 1) // query string present - { + if (parts.length > 1) { // query string present // search for z= for (String param : parts[1].split("&")) { - if (param.startsWith("z=")) - { - try - { + if (param.startsWith("z=")) { + try { z = Integer.valueOf(param.substring(2)); - } catch (NumberFormatException e) - { + } catch (NumberFormatException e) { URISyntaxException use = new URISyntaxException(uri.toString(), "could not parse zoom level"); use.initCause(e); throw use; @@ -307,13 +301,6 @@ public class IITC_Mobile extends Activity { @Override protected void onStop() { - ConnectivityManager conMan = - (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); - - NetworkInfo mobile = conMan - .getNetworkInfo(ConnectivityManager.TYPE_MOBILE); - NetworkInfo wifi = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI); - Log.d("iitcm", "stopping iitcm"); mIitcWebView.loadUrl("javascript: window.idleSet();"); @@ -651,8 +638,7 @@ public class IITC_Mobile extends Activity { return super.getActionBar(); } - public ActionBarHelper getActionBarHelper() - { + public ActionBarHelper getActionBarHelper() { return mActionBarHelper; } } diff --git a/mobile/src/com/cradle/iitc_mobile/async/CheckHttpResponse.java b/mobile/src/com/cradle/iitc_mobile/async/CheckHttpResponse.java index 861677c3..ff64d42f 100644 --- a/mobile/src/com/cradle/iitc_mobile/async/CheckHttpResponse.java +++ b/mobile/src/com/cradle/iitc_mobile/async/CheckHttpResponse.java @@ -1,5 +1,13 @@ package com.cradle.iitc_mobile.async; +import java.io.IOException; + +import org.apache.http.HttpResponse; +import org.apache.http.HttpStatus; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.DefaultHttpClient; + import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; @@ -8,15 +16,6 @@ import android.util.Log; import com.cradle.iitc_mobile.IITC_JSInterface; import com.cradle.iitc_mobile.IITC_Mobile; -import com.cradle.iitc_mobile.IITC_WebView; - -import org.apache.http.HttpResponse; -import org.apache.http.HttpStatus; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.DefaultHttpClient; - -import java.io.IOException; /* * this class parses the http response of a web page. diff --git a/mobile/src/com/cradle/iitc_mobile/share/IntentFragment.java b/mobile/src/com/cradle/iitc_mobile/share/IntentFragment.java index 2d8b3780..b1b15682 100644 --- a/mobile/src/com/cradle/iitc_mobile/share/IntentFragment.java +++ b/mobile/src/com/cradle/iitc_mobile/share/IntentFragment.java @@ -42,8 +42,7 @@ public class IntentFragment extends Fragment implements OnScrollListener, OnItem } @Override - public void onItemClick(AdapterView parent, View view, int position, long id) - { + public void onItemClick(AdapterView parent, View view, int position, long id) { Intent intent = mListView.getTargetIntent(position); startActivity(intent); } diff --git a/mobile/src/com/cradle/iitc_mobile/share/IntentListView.java b/mobile/src/com/cradle/iitc_mobile/share/IntentListView.java index 669e8fa3..435edc6c 100644 --- a/mobile/src/com/cradle/iitc_mobile/share/IntentListView.java +++ b/mobile/src/com/cradle/iitc_mobile/share/IntentListView.java @@ -35,10 +35,8 @@ public class IntentListView extends ListView { } } - private class IntentAdapter extends ArrayAdapter - { - private IntentAdapter() - { + private class IntentAdapter extends ArrayAdapter { + private IntentAdapter() { super(IntentListView.this.getContext(), android.R.layout.simple_list_item_1); } @@ -126,8 +124,7 @@ public class IntentListView extends ListView { setIntents(intentList); } - public void setIntents(ArrayList intents) - { + public void setIntents(ArrayList intents) { mAdapter.setNotifyOnChange(false); mAdapter.clear(); @@ -154,10 +151,8 @@ public class IntentListView extends ListView { ActivityInfo activity = info.activityInfo; // remove all IITCm intents, except for SendToClipboard in case Drive is not installed - if (activity.packageName.equals(packageName)) - { - if (hasCopyIntent || !activity.name.equals(SendToClipboard.class.getCanonicalName())) - { + if (activity.packageName.equals(packageName)) { + if (hasCopyIntent || !activity.name.equals(SendToClipboard.class.getCanonicalName())) { activityList.remove(i); i--; continue; diff --git a/mobile/src/com/cradle/iitc_mobile/share/ShareActivity.java b/mobile/src/com/cradle/iitc_mobile/share/ShareActivity.java index fdf6eb4f..4a442ab6 100644 --- a/mobile/src/com/cradle/iitc_mobile/share/ShareActivity.java +++ b/mobile/src/com/cradle/iitc_mobile/share/ShareActivity.java @@ -1,5 +1,9 @@ package com.cradle.iitc_mobile.share; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.util.ArrayList; + import android.app.ActionBar; import android.app.FragmentTransaction; import android.content.Intent; @@ -14,11 +18,6 @@ import android.view.MenuItem; import com.cradle.iitc_mobile.R; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.text.DecimalFormatSymbols; -import java.util.ArrayList; - public class ShareActivity extends FragmentActivity implements ActionBar.TabListener { private boolean mIsPortal; private String mLl; @@ -28,15 +27,7 @@ public class ShareActivity extends FragmentActivity implements ActionBar.TabList IntentFragmentAdapter mFragmentAdapter; ViewPager mViewPager; - private void addTab(Intent intent, int label, int icon) - { - ArrayList intents = new ArrayList(1); - intents.add(intent); - addTab(intents, label, icon); - } - - private void addTab(ArrayList intents, int label, int icon) - { + private void addTab(ArrayList intents, int label, int icon) { IntentFragment fragment = new IntentFragment(); Bundle args = new Bundle(); args.putParcelableArrayList("intents", intents); @@ -46,6 +37,12 @@ public class ShareActivity extends FragmentActivity implements ActionBar.TabList mFragmentAdapter.add(fragment); } + private void addTab(Intent intent, int label, int icon) { + ArrayList intents = new ArrayList(1); + intents.add(intent); + addTab(intents, label, icon); + } + private String getUrl() { String url = "http://www.ingress.com/intel?ll=" + mLl + "&z=" + mZoom; if (mIsPortal) @@ -64,15 +61,6 @@ public class ShareActivity extends FragmentActivity implements ActionBar.TabList .apply(); } - private void setupShareIntent(String str) { - Intent intent = new Intent(Intent.ACTION_SEND); - intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); - intent.setType("text/plain"); - intent.putExtra(Intent.EXTRA_TEXT, str); - intent.putExtra(Intent.EXTRA_SUBJECT, mTitle); - addTab(intent, R.string.tab_share, R.drawable.share); - } - private void setupIntents() { setupShareIntent(getUrl()); @@ -98,6 +86,15 @@ public class ShareActivity extends FragmentActivity implements ActionBar.TabList addTab(intent, R.string.tab_browser, R.drawable.browser); } + private void setupShareIntent(String str) { + Intent intent = new Intent(Intent.ACTION_SEND); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); + intent.setType("text/plain"); + intent.putExtra(Intent.EXTRA_TEXT, str); + intent.putExtra(Intent.EXTRA_SUBJECT, mTitle); + addTab(intent, R.string.tab_share, R.drawable.share); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -146,8 +143,7 @@ public class ShareActivity extends FragmentActivity implements ActionBar.TabList mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); int selected = mSharedPrefs.getInt("pref_share_selected_tab", 0); - if (selected < mFragmentAdapter.getCount()) - { + if (selected < mFragmentAdapter.getCount()) { mViewPager.setCurrentItem(selected); actionBar.setSelectedNavigationItem(selected); } From bf229f7f05c7b70732f7e4a99b5d26c051d0a014 Mon Sep 17 00:00:00 2001 From: fkloft Date: Wed, 18 Sep 2013 17:40:05 +0200 Subject: [PATCH 6/7] Code formatting --- mobile/res/values/strings.xml | 2 +- ...arHelper.java => IITC_ActionBarHelper.java} | 10 +++++----- .../cradle/iitc_mobile/IITC_JSInterface.java | 12 ++++++------ .../com/cradle/iitc_mobile/IITC_Mobile.java | 16 ++++++++-------- .../IITC_PluginPreferenceActivity.java | 18 +++++++++--------- .../iitc_mobile/async/CheckHttpResponse.java | 16 ++++++++-------- .../share/IntentFragmentAdapter.java | 6 +++--- .../iitc_mobile/share/IntentListView.java | 10 +++++----- .../iitc_mobile/share/SendToClipboard.java | 1 + .../iitc_mobile/share/ShareActivity.java | 8 ++++---- 10 files changed, 50 insertions(+), 49 deletions(-) rename mobile/src/com/cradle/iitc_mobile/{ActionBarHelper.java => IITC_ActionBarHelper.java} (96%) diff --git a/mobile/res/values/strings.xml b/mobile/res/values/strings.xml index d4696eee..2e067082 100644 --- a/mobile/res/values/strings.xml +++ b/mobile/res/values/strings.xml @@ -21,7 +21,7 @@ About IITC Mobile -Ingress Intel Total Conversion Mobile

+ Ingress Intel Total Conversion Mobile

by cradle and contributors

Icon by Giuseppe Lucido

IITC Mobile is an optimized mobile browser for the diff --git a/mobile/src/com/cradle/iitc_mobile/ActionBarHelper.java b/mobile/src/com/cradle/iitc_mobile/IITC_ActionBarHelper.java similarity index 96% rename from mobile/src/com/cradle/iitc_mobile/ActionBarHelper.java rename to mobile/src/com/cradle/iitc_mobile/IITC_ActionBarHelper.java index c8499b8e..fe9f8bbe 100644 --- a/mobile/src/com/cradle/iitc_mobile/ActionBarHelper.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_ActionBarHelper.java @@ -7,17 +7,17 @@ import android.preference.PreferenceManager; import android.widget.ArrayAdapter; import android.widget.Toast; -public class ActionBarHelper implements OnNavigationListener { +public class IITC_ActionBarHelper implements OnNavigationListener { /* * Show/hide the up arrow on the left end * getActionBar().setDisplayHomeAsUpEnabled(enabled); - * + * * Show/hide the activity icon/logo * getActionBar().setDisplayShowHomeEnabled(enabled); - * + * * Show/hide the activity title * getActionBar().setDisplayShowTitleEnabled(enabled); - * + * * Makes the icon/title clickable * getActionBar().setHomeButtonEnabled(enabled); */ @@ -52,7 +52,7 @@ public class ActionBarHelper implements OnNavigationListener { private boolean mHideInFullscreen = false; private int mPane = android.R.id.home; - public ActionBarHelper(IITC_Mobile activity, ActionBar bar) { + public IITC_ActionBarHelper(IITC_Mobile activity, ActionBar bar) { mIitc = activity; mActionBar = bar; mPrefs = PreferenceManager.getDefaultSharedPreferences(activity); diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java b/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java index 99dc95bb..cd3cbf94 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java @@ -1,10 +1,5 @@ package com.cradle.iitc_mobile; -import java.util.HashMap; - -import org.json.JSONArray; -import org.json.JSONException; - import android.app.Activity; import android.app.AlertDialog; import android.content.ClipData; @@ -25,6 +20,11 @@ import android.widget.Toast; import com.cradle.iitc_mobile.share.ShareActivity; +import org.json.JSONArray; +import org.json.JSONException; + +import java.util.HashMap; + // provide communication between IITC script and android app public class IITC_JSInterface { @@ -102,7 +102,7 @@ public class IITC_JSInterface { iitcm.runOnUiThread(new Runnable() { @Override public void run() { - ActionBarHelper actionbar = iitcm.getActionBarHelper(); + IITC_ActionBarHelper actionbar = iitcm.getActionBarHelper(); Integer button = IITC_Mobile.PANES.get(id); if (button == null) diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java index 40ed984b..9678ce6c 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java @@ -1,10 +1,5 @@ package com.cradle.iitc_mobile; -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.HashMap; - import android.app.ActionBar; import android.app.Activity; import android.app.AlertDialog; @@ -35,6 +30,11 @@ import android.webkit.WebView; import android.widget.SearchView; import android.widget.Toast; +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.HashMap; + public class IITC_Mobile extends Activity { private static final int REQUEST_LOGIN = 1; @@ -54,7 +54,7 @@ public class IITC_Mobile extends Activity { private boolean mReloadNeeded = false; private final ArrayList mDialogStack = new ArrayList(); private SharedPreferences mSharedPrefs; - private ActionBarHelper mActionBarHelper; + private IITC_ActionBarHelper mActionBarHelper; // Used for custom back stack handling private final ArrayList mBackStack = new ArrayList(); @@ -94,7 +94,7 @@ public class IITC_Mobile extends Activity { mIitcWebView = (IITC_WebView) findViewById(R.id.iitc_webview); // pass ActionBar to helper because we deprecated getActionBar - mActionBarHelper = new ActionBarHelper(this, super.getActionBar()); + mActionBarHelper = new IITC_ActionBarHelper(this, super.getActionBar()); // do something if user changed something in the settings mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); @@ -638,7 +638,7 @@ public class IITC_Mobile extends Activity { return super.getActionBar(); } - public ActionBarHelper getActionBarHelper() { + public IITC_ActionBarHelper getActionBarHelper() { return mActionBarHelper; } } diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_PluginPreferenceActivity.java b/mobile/src/com/cradle/iitc_mobile/IITC_PluginPreferenceActivity.java index 701ae608..0f4ff502 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_PluginPreferenceActivity.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_PluginPreferenceActivity.java @@ -1,14 +1,5 @@ package com.cradle.iitc_mobile; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Scanner; -import java.util.TreeMap; - import android.content.Context; import android.content.res.AssetManager; import android.os.Bundle; @@ -24,6 +15,15 @@ import android.widget.ArrayAdapter; import android.widget.ListAdapter; import android.widget.TextView; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Scanner; +import java.util.TreeMap; + public class IITC_PluginPreferenceActivity extends PreferenceActivity { private List
mHeaders; diff --git a/mobile/src/com/cradle/iitc_mobile/async/CheckHttpResponse.java b/mobile/src/com/cradle/iitc_mobile/async/CheckHttpResponse.java index ff64d42f..e7df6056 100644 --- a/mobile/src/com/cradle/iitc_mobile/async/CheckHttpResponse.java +++ b/mobile/src/com/cradle/iitc_mobile/async/CheckHttpResponse.java @@ -1,13 +1,5 @@ package com.cradle.iitc_mobile.async; -import java.io.IOException; - -import org.apache.http.HttpResponse; -import org.apache.http.HttpStatus; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.DefaultHttpClient; - import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; @@ -17,6 +9,14 @@ import android.util.Log; import com.cradle.iitc_mobile.IITC_JSInterface; import com.cradle.iitc_mobile.IITC_Mobile; +import org.apache.http.HttpResponse; +import org.apache.http.HttpStatus; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.DefaultHttpClient; + +import java.io.IOException; + /* * this class parses the http response of a web page. * since network operations shouldn't be done on main UI thread diff --git a/mobile/src/com/cradle/iitc_mobile/share/IntentFragmentAdapter.java b/mobile/src/com/cradle/iitc_mobile/share/IntentFragmentAdapter.java index 1460348c..68743a08 100644 --- a/mobile/src/com/cradle/iitc_mobile/share/IntentFragmentAdapter.java +++ b/mobile/src/com/cradle/iitc_mobile/share/IntentFragmentAdapter.java @@ -1,12 +1,12 @@ package com.cradle.iitc_mobile.share; -import java.util.ArrayList; -import java.util.List; - import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; +import java.util.ArrayList; +import java.util.List; + public class IntentFragmentAdapter extends FragmentPagerAdapter { private List mTabs; diff --git a/mobile/src/com/cradle/iitc_mobile/share/IntentListView.java b/mobile/src/com/cradle/iitc_mobile/share/IntentListView.java index 435edc6c..d0a72cc6 100644 --- a/mobile/src/com/cradle/iitc_mobile/share/IntentListView.java +++ b/mobile/src/com/cradle/iitc_mobile/share/IntentListView.java @@ -1,10 +1,5 @@ package com.cradle.iitc_mobile.share; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; - import android.app.Activity; import android.content.ComponentName; import android.content.Context; @@ -24,6 +19,11 @@ import android.widget.TextView; import com.cradle.iitc_mobile.R; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; + public class IntentListView extends ListView { private static class CopyHandler extends Pair { public CopyHandler(ResolveInfo resolveInfo) { diff --git a/mobile/src/com/cradle/iitc_mobile/share/SendToClipboard.java b/mobile/src/com/cradle/iitc_mobile/share/SendToClipboard.java index 2f9b332f..3134452e 100644 --- a/mobile/src/com/cradle/iitc_mobile/share/SendToClipboard.java +++ b/mobile/src/com/cradle/iitc_mobile/share/SendToClipboard.java @@ -7,6 +7,7 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.widget.Toast; + import com.cradle.iitc_mobile.R; public class SendToClipboard extends Activity { diff --git a/mobile/src/com/cradle/iitc_mobile/share/ShareActivity.java b/mobile/src/com/cradle/iitc_mobile/share/ShareActivity.java index 4a442ab6..71200af3 100644 --- a/mobile/src/com/cradle/iitc_mobile/share/ShareActivity.java +++ b/mobile/src/com/cradle/iitc_mobile/share/ShareActivity.java @@ -1,9 +1,5 @@ package com.cradle.iitc_mobile.share; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.util.ArrayList; - import android.app.ActionBar; import android.app.FragmentTransaction; import android.content.Intent; @@ -18,6 +14,10 @@ import android.view.MenuItem; import com.cradle.iitc_mobile.R; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.util.ArrayList; + public class ShareActivity extends FragmentActivity implements ActionBar.TabListener { private boolean mIsPortal; private String mLl; From def3dd698cde5fb5c052e59c3a45cc796c68f5c7 Mon Sep 17 00:00:00 2001 From: fkloft Date: Wed, 18 Sep 2013 18:08:29 +0200 Subject: [PATCH 7/7] Fix: Highlighter was not remembered after IITC restart --- code/portal_highlighter.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/code/portal_highlighter.js b/code/portal_highlighter.js index ee03a883..cd2333db 100644 --- a/code/portal_highlighter.js +++ b/code/portal_highlighter.js @@ -6,6 +6,12 @@ window._highlighters = null; window._current_highlighter = localStorage.portal_highlighter; window._no_highlighter = 'No Highlights'; +if(window._current_highlighter !== undefined) { + if (typeof android !== 'undefined' && android && android.setActiveHighlighter) + android.setActiveHighlighter(window._current_highlighter); +} + + window.addPortalHighlighter = function(name, callback) { if(_highlighters === null) { _highlighters = {};