diff --git a/mobile/AndroidManifest.xml b/mobile/AndroidManifest.xml index 6b67a11c..f44e7286 100644 --- a/mobile/AndroidManifest.xml +++ b/mobile/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="34" + android:versionName="0.5.3"> Layer Chooser Get Location local - close + Close Build Version IITC Version About @@ -71,4 +71,8 @@ Map Share Browser + + Base Layers + Overlay Layers + Deselect/Select all diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_AboutDialogPreference.java b/mobile/src/com/cradle/iitc_mobile/IITC_AboutDialogPreference.java index 1549e768..54600070 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_AboutDialogPreference.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_AboutDialogPreference.java @@ -12,23 +12,23 @@ import android.widget.TextView; public class IITC_AboutDialogPreference extends DialogPreference { - private final Context context; + private final Context mContext; public IITC_AboutDialogPreference(Context context, AttributeSet attrs) { super(context, attrs); - this.context = context; + this.mContext = context; } /* - * start a little about-dialog srsly...I found no better way for clickable + * start an about-dialog...I found no better way for clickable * links in a TextView then using Html.fromHtml...Linkify is just broken and * does not understand html href tags...so let's tag the @string/about_msg * with CDATA and use Html.fromHtml(...) for clickable hrefs with tags. */ @Override protected void onPrepareDialogBuilder(Builder builder) { - final TextView message = new TextView(context); - String about_msg = context.getText(R.string.pref_about_msg).toString(); + final TextView message = new TextView(mContext); + String about_msg = mContext.getText(R.string.pref_about_msg).toString(); message.setText(Html.fromHtml(about_msg)); message.setMovementMethod(LinkMovementMethod.getInstance()); builder.setView(message).setTitle(R.string.about) diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java b/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java index 92a4550d..7cefd839 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java @@ -6,6 +6,7 @@ import org.json.JSONArray; import org.json.JSONException; import android.app.AlertDialog; +import android.app.LauncherActivity; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; @@ -16,6 +17,9 @@ import android.content.Intent; import android.util.Log; import android.view.View; import android.webkit.JavascriptInterface; +import android.widget.AdapterView; +import android.widget.Button; +import android.widget.ListView; import android.widget.Toast; import com.cradle.iitc_mobile.share.ShareActivity; @@ -24,29 +28,29 @@ import com.cradle.iitc_mobile.share.ShareActivity; public class IITC_JSInterface { // context of main activity - private final Context context; - private final HashMap layer_ids; - private boolean[] overlay_is_active; - private int active_base_layer; - private String[] overlay_layers, base_layers; - private int num_base_layers; - private int num_overlay_layers; + private final Context mContext; + private final HashMap mLayerIds; + private boolean[] mOverlayIsActive; + private int mActiveBaseLayer; + private String[] mOverlayLayers, mBaseLayers; + private int mNumBaseLayers; + private int mNumOverlayLayers; IITC_JSInterface(Context c) { - layer_ids = new HashMap(); - context = c; + mLayerIds = new HashMap(); + mContext = c; } // open dialog to send geo intent for navigation apps like gmaps or waze etc... @JavascriptInterface public void intentPosLink(double lat, double lng, int zoom, String title, boolean isPortal) { - Intent intent = new Intent(context, ShareActivity.class); + Intent intent = new Intent(mContext, ShareActivity.class); intent.putExtra("lat", lat); intent.putExtra("lng", lng); intent.putExtra("zoom", zoom); intent.putExtra("title", title); intent.putExtra("isPortal", isPortal); - context.startActivity(intent); + mContext.startActivity(intent); } // disable javascript injection while spinner is enabled @@ -54,24 +58,24 @@ public class IITC_JSInterface { @JavascriptInterface public void spinnerEnabled(boolean en) { Log.d("iitcm", "disableJS? " + en); - ((IITC_Mobile) context).getWebView().disableJS(en); + ((IITC_Mobile) mContext).getWebView().disableJS(en); } // copy link to specific portal to android clipboard @JavascriptInterface public void copy(String s) { - ClipboardManager clipboard = (ClipboardManager) context + ClipboardManager clipboard = (ClipboardManager) mContext .getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("Copied Text ", s); clipboard.setPrimaryClip(clip); - Toast.makeText(context, "copied to clipboard", Toast.LENGTH_SHORT) + Toast.makeText(mContext, "copied to clipboard", Toast.LENGTH_SHORT) .show(); } @JavascriptInterface public void switchToPane(String id) { - final IITC_Mobile iitcm = (IITC_Mobile) context; + final IITC_Mobile iitcm = (IITC_Mobile) mContext; final int button_id; final String title; @@ -115,18 +119,18 @@ public class IITC_JSInterface { @JavascriptInterface public void dialogOpened(String id, boolean open) { - ((IITC_Mobile) context).dialogOpened(id, open); + ((IITC_Mobile) mContext).dialogOpened(id, open); } @JavascriptInterface public void dialogFocused(String id) { - ((IITC_Mobile) context).setFocusedDialog(id); + ((IITC_Mobile) mContext).setFocusedDialog(id); } @JavascriptInterface public void iitcLoaded() { Log.d("iitcm", "iitc loaded completely"); - final IITC_Mobile iitc = ((IITC_Mobile) context); + final IITC_Mobile iitc = ((IITC_Mobile) mContext); iitc.runOnUiThread(new Runnable() { @Override @@ -149,7 +153,6 @@ public class IITC_JSInterface { */ JSONArray base_layersJSON = null; JSONArray overlay_layersJSON = null; - Log.d("iitcm", base_layer); try { base_layersJSON = new JSONArray(base_layer); overlay_layersJSON = new JSONArray(overlay_layer); @@ -158,15 +161,15 @@ public class IITC_JSInterface { } // get length and initialize arrays - num_base_layers = base_layersJSON.length(); - num_overlay_layers = overlay_layersJSON.length(); - overlay_is_active = new boolean[num_overlay_layers]; - overlay_layers = new String[num_overlay_layers]; - base_layers = new String[num_base_layers]; - layer_ids.clear(); + mNumBaseLayers = base_layersJSON.length(); + mNumOverlayLayers = overlay_layersJSON.length(); + mOverlayIsActive = new boolean[mNumOverlayLayers]; + mOverlayLayers = new String[mNumOverlayLayers]; + mBaseLayers = new String[mNumBaseLayers]; + mLayerIds.clear(); // --------------- base layers ------------------------ - for (int i = 0; i < num_base_layers; ++i) { + for (int i = 0; i < mNumBaseLayers; ++i) { try { String layer = base_layersJSON.getString(i); layer = layer.replace("{", ""); @@ -192,9 +195,9 @@ public class IITC_JSInterface { if (values[0].contains("name")) name = values[1]; } name = name.replace("\"", ""); - layer_ids.put(name, id); - this.base_layers[i] = name; - if (isActive) active_base_layer = i; + mLayerIds.put(name, id); + this.mBaseLayers[i] = name; + if (isActive) mActiveBaseLayer = i; } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -202,7 +205,7 @@ public class IITC_JSInterface { } // --------------- overlay layers ------------------------ - for (int i = 0; i < num_overlay_layers; ++i) { + for (int i = 0; i < mNumOverlayLayers; ++i) { try { String layer = overlay_layersJSON.getString(i); layer = layer.replace("{", ""); @@ -218,83 +221,105 @@ public class IITC_JSInterface { if (values[0].contains("name")) name = values[1]; } name = name.replace("\"", ""); - layer_ids.put(name, id); - this.overlay_layers[i] = name; - this.overlay_is_active[i] = isActive; + mLayerIds.put(name, id); + this.mOverlayLayers[i] = name; + this.mOverlayIsActive[i] = isActive; } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } // show overlay layers by default - show_multi_selection(); + showMultiSelection(); } // show all overlay layers in a multi selection list dialog - private void show_multi_selection() { + private void showMultiSelection() { // build the layer chooser dialog - AlertDialog.Builder d_m = new AlertDialog.Builder(context); + AlertDialog.Builder d_m = new AlertDialog.Builder(mContext); OnMultiChoiceClickListener m_listener = new OnMultiChoiceClickListener() { - @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { // activate clicked layer - ((IITC_Mobile) context).getWebView().loadUrl("javascript: " + + ((IITC_Mobile) mContext).getWebView().loadUrl("javascript: " + "window.layerChooser.showLayer(" - + layer_ids.get(overlay_layers[which]) + "," - + overlay_is_active[which] + ");"); + + mLayerIds.get(mOverlayLayers[which]) + "," + + isChecked + ");"); } }; - - d_m.setMultiChoiceItems(overlay_layers, overlay_is_active, m_listener); + d_m.setMultiChoiceItems(mOverlayLayers, mOverlayIsActive, m_listener); // switch to base layers - d_m.setPositiveButton("Base Layers", new OnClickListener() { + d_m.setPositiveButton(R.string.base_layers, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - show_single_selection(); - dialog.cancel(); + showSingleSelection(); + dialog.dismiss(); } }); - d_m.setNegativeButton("Close", new OnClickListener() { + d_m.setNegativeButton(R.string.close, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - dialog.cancel(); + dialog.dismiss(); } }); - d_m.setTitle("Overlay Layers"); - d_m.show(); + d_m.setTitle(R.string.overlay_layers); + final AlertDialog dialog = d_m.create(); + 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; + for (String layer : mOverlayLayers) { + if (!mOverlayLayers[j].contains("DEBUG")) { + // uncheck the item + set the boolean in the isActive array + mOverlayIsActive[j] = disable; + list.setItemChecked(j, disable); + ((IITC_Mobile) mContext).getWebView().loadUrl("javascript: " + + "window.layerChooser.showLayer(" + + mLayerIds.get(layer) + "," + + disable + ");"); + } + ++j; + } + disable = !disable; + return true; + } + }); + dialog.show(); } // show all base layers in a single selection list dialog - private void show_single_selection() { + private void showSingleSelection() { OnClickListener s_listener = new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // activate clicked layer - ((IITC_Mobile) context).getWebView().loadUrl("javascript: " + + ((IITC_Mobile) mContext).getWebView().loadUrl("javascript: " + "window.layerChooser.showLayer(" - + layer_ids.get(base_layers[which]) + "," + + mLayerIds.get(mBaseLayers[which]) + "," + true + ");"); - active_base_layer = which; + mActiveBaseLayer = which; } }; - AlertDialog.Builder d_s = new AlertDialog.Builder(context); - d_s.setSingleChoiceItems(base_layers, active_base_layer, s_listener); + AlertDialog.Builder d_s = new AlertDialog.Builder(mContext); + d_s.setSingleChoiceItems(mBaseLayers, mActiveBaseLayer, s_listener); // switch to overlay layers - d_s.setPositiveButton("Overlay Layers", new OnClickListener() { + d_s.setPositiveButton(R.string.overlay_layers, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - show_multi_selection(); - dialog.cancel(); + showMultiSelection(); + dialog.dismiss(); } }); - d_s.setNegativeButton("Close", new OnClickListener() { + d_s.setNegativeButton(R.string.close, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - dialog.cancel(); + dialog.dismiss(); } }); - d_s.setTitle("Base Layers"); - d_s.show(); + d_s.setTitle(R.string.base_layers); + final AlertDialog dialog = d_s.create(); + dialog.show(); } } diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java index e61faf7b..a2bb312c 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java @@ -39,28 +39,28 @@ public class IITC_Mobile extends Activity { private static final int REQUEST_LOGIN = 1; - private IITC_WebView iitc_view; - private OnSharedPreferenceChangeListener listener; - private final String intel_url = "https://www.ingress.com/intel"; - private boolean is_loc_enabled = false; - private Location last_location = null; - private LocationManager loc_mngr = null; - private LocationListener loc_listener = null; - private boolean fullscreen_mode = false; - private boolean fullscreen_actionbar = false; - private ActionBar actionBar; + private IITC_WebView mIitcWebView; + private OnSharedPreferenceChangeListener mSharedPrefChangeListener; + private final String mIntelUrl = "https://www.ingress.com/intel"; + private boolean mIsLocEnabled = false; + private Location mLastLocation = null; + 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 searchMenuItem; - private boolean desktop = false; - private boolean reload_needed = false; - private final ArrayList dialogStack = new ArrayList(); - private SharedPreferences sharedPref; + private MenuItem mSearchMenuItem; + private boolean mDesktopMode = false; + private boolean mReloadNeeded = false; + private final ArrayList mDialogStack = new ArrayList(); + private SharedPreferences mSharedPrefs; // Used for custom back stack handling - private final ArrayList backStack = new ArrayList(); - private boolean backStack_push = true; - private int currentPane = android.R.id.home; - private boolean back_button_pressed = false; + private final ArrayList mBackStack = new ArrayList(); + private boolean mBackStackPush = true; + private int mCurrentPane = android.R.id.home; + private boolean mBackButtonPressed = false; @Override protected void onCreate(Bundle savedInstanceState) { @@ -70,38 +70,38 @@ public class IITC_Mobile extends Activity { requestWindowFeature(Window.FEATURE_PROGRESS); setContentView(R.layout.activity_main); - iitc_view = (IITC_WebView) findViewById(R.id.iitc_webview); + mIitcWebView = (IITC_WebView) findViewById(R.id.iitc_webview); // fetch actionbar, set display flags, title and enable home button - actionBar = this.getActionBar(); - actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME + mActionBar = this.getActionBar(); + mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_USE_LOGO | ActionBar.DISPLAY_SHOW_TITLE); - actionBar.setTitle(getString(R.string.app_name)); + mActionBar.setTitle(getString(R.string.app_name)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) - actionBar.setHomeButtonEnabled(true); + mActionBar.setHomeButtonEnabled(true); // do something if user changed something in the settings - sharedPref = PreferenceManager + mSharedPrefs = PreferenceManager .getDefaultSharedPreferences(this); - listener = new OnSharedPreferenceChangeListener() { + mSharedPrefChangeListener = new OnSharedPreferenceChangeListener() { @Override public void onSharedPreferenceChanged( SharedPreferences sharedPreferences, String key) { if (key.equals("pref_force_desktop")) { - desktop = sharedPreferences.getBoolean("pref_force_desktop", false); - if (desktop) { + mDesktopMode = sharedPreferences.getBoolean("pref_force_desktop", false); + if (mDesktopMode) { setActionBarHomeEnabledWithUp(false); - actionBar.setTitle(getString(R.string.app_name)); - } else actionBar.setHomeButtonEnabled(true); + mActionBar.setTitle(getString(R.string.app_name)); + } else mActionBar.setHomeButtonEnabled(true); invalidateOptionsMenu(); } if (key.equals("pref_user_loc")) - is_loc_enabled = sharedPreferences.getBoolean("pref_user_loc", + mIsLocEnabled = sharedPreferences.getBoolean("pref_user_loc", false); if (key.equals("pref_fullscreen_actionbar")) { - fullscreen_actionbar = sharedPreferences.getBoolean("pref_fullscreen_actionbar", + mFullscreenActionbar = sharedPreferences.getBoolean("pref_fullscreen_actionbar", false); - if (fullscreen_mode) + if (mFullscreenMode) IITC_Mobile.this.getActionBar().hide(); // no iitc reload needed here return; @@ -110,25 +110,25 @@ public class IITC_Mobile extends Activity { if (key.equals("pref_press_twice_to_exit") || key.equals("pref_share_selected_tab")) return; - reload_needed = true; + mReloadNeeded = true; } }; - sharedPref.registerOnSharedPreferenceChangeListener(listener); + mSharedPrefs.registerOnSharedPreferenceChangeListener(mSharedPrefChangeListener); - // enable/disable desktop mode on menu create and url load - desktop = sharedPref.getBoolean("pref_force_desktop", false); + // enable/disable mDesktopMode mode on menu create and url load + mDesktopMode = mSharedPrefs.getBoolean("pref_force_desktop", false); // Acquire a reference to the system Location Manager - loc_mngr = (LocationManager) this + mLocMngr = (LocationManager) this .getSystemService(Context.LOCATION_SERVICE); - // Define a listener that responds to location updates - loc_listener = new LocationListener() { + // Define a mSharedPrefChangeListener that responds to location updates + mLocListener = new LocationListener() { public void onLocationChanged(Location location) { // Called when a new location is found by the network location // provider. drawMarker(location); - last_location = location; + mLastLocation = location; } public void onStatusChanged(String provider, int status, @@ -142,20 +142,20 @@ public class IITC_Mobile extends Activity { } }; - is_loc_enabled = sharedPref.getBoolean("pref_user_loc", false); - if (is_loc_enabled) { - // Register the listener with the Location Manager to receive + mIsLocEnabled = mSharedPrefs.getBoolean("pref_user_loc", false); + if (mIsLocEnabled) { + // Register the mSharedPrefChangeListener with the Location Manager to receive // location updates - loc_mngr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, - 0, 0, loc_listener); - loc_mngr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, - loc_listener); + mLocMngr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, + 0, 0, mLocListener); + mLocMngr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, + mLocListener); } - fullscreen_actionbar = sharedPref.getBoolean("pref_fullscreen_actionbar", false); + mFullscreenActionbar = mSharedPrefs.getBoolean("pref_fullscreen_actionbar", false); // Clear the back stack - backStack.clear(); + mBackStack.clear(); setActionBarHomeEnabledWithUp(false); handleIntent(getIntent(), true); @@ -208,17 +208,17 @@ public class IITC_Mobile extends Activity { String query = intent.getStringExtra(SearchManager.QUERY); query = query.replace("'", "''"); final SearchView searchView = - (SearchView) searchMenuItem.getActionView(); + (SearchView) mSearchMenuItem.getActionView(); searchView.setQuery(query, false); searchView.clearFocus(); - actionBar.setTitle(getString(R.string.app_name)); + mActionBar.setTitle(getString(R.string.app_name)); backStackUpdate(android.R.id.home); - iitc_view.loadUrl("javascript:search('" + query + "');"); + mIitcWebView.loadUrl("javascript:search('" + query + "');"); return; } if (onCreate) { - this.loadUrl(intel_url); + this.loadUrl(mIntelUrl); } } @@ -273,23 +273,23 @@ public class IITC_Mobile extends Activity { // enough idle...let's do some work Log.d("iitcm", "resuming...setting reset idleTimer"); - iitc_view.loadUrl("javascript: window.idleTime = 0"); - iitc_view.loadUrl("javascript: window.renderUpdateStatus()"); - iitc_view.updateCaching(); + mIitcWebView.loadUrl("javascript: window.idleTime = 0"); + mIitcWebView.loadUrl("javascript: window.renderUpdateStatus()"); + mIitcWebView.updateCaching(); - if (is_loc_enabled) { - // Register the listener with the Location Manager to receive + if (mIsLocEnabled) { + // Register the mSharedPrefChangeListener with the Location Manager to receive // location updates - loc_mngr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, - 0, 0, loc_listener); - loc_mngr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, - loc_listener); + mLocMngr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, + 0, 0, mLocListener); + mLocMngr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, + mLocListener); } - if (reload_needed) { + if (mReloadNeeded) { Log.d("iitcm", "preference had changed...reload needed"); - this.loadUrl(intel_url); - reload_needed = false; + this.loadUrl(mIntelUrl); + mReloadNeeded = false; } } @@ -312,25 +312,25 @@ public class IITC_Mobile extends Activity { Log.d("iitcm", "connected to mobile net...abort all running requests"); // cancel all current requests - iitc_view.loadUrl("javascript: window.requests.abort()"); + mIitcWebView.loadUrl("javascript: window.requests.abort()"); // set idletime to maximum...no need for more - iitc_view.loadUrl("javascript: window.idleTime = 999"); + mIitcWebView.loadUrl("javascript: window.idleTime = 999"); } else if (wifi.getState() == NetworkInfo.State.CONNECTED || wifi.getState() == NetworkInfo.State.CONNECTING) { - iitc_view.loadUrl("javascript: window.idleTime = 999"); + mIitcWebView.loadUrl("javascript: window.idleTime = 999"); } } else { Log.d("iitcm", "no mobile internet module detected...check wifi state"); if (wifi.getState() == NetworkInfo.State.CONNECTED || wifi.getState() == NetworkInfo.State.CONNECTING) { - iitc_view.loadUrl("javascript: window.idleTime = 999"); + mIitcWebView.loadUrl("javascript: window.idleTime = 999"); } } Log.d("iitcm", "stopping iitcm"); - if (is_loc_enabled) - loc_mngr.removeUpdates(loc_listener); + if (mIsLocEnabled) + mLocMngr.removeUpdates(mLocListener); super.onStop(); } @@ -340,18 +340,18 @@ public class IITC_Mobile extends Activity { super.onConfigurationChanged(newConfig); Log.d("iitcm", "configuration changed...restoring...reset idleTimer"); - iitc_view.loadUrl("javascript: window.idleTime = 0"); - iitc_view.loadUrl("javascript: window.renderUpdateStatus()"); + mIitcWebView.loadUrl("javascript: window.idleTime = 0"); + mIitcWebView.loadUrl("javascript: window.renderUpdateStatus()"); } // we want a self defined behavior for the back button @Override public void onBackPressed() { // first kill all open iitc dialogs - if (!dialogStack.isEmpty()) { - int last = dialogStack.size() - 1; - String id = dialogStack.get(last); - iitc_view.loadUrl("javascript: " + + if (!mDialogStack.isEmpty()) { + int last = mDialogStack.size() - 1; + String id = mDialogStack.get(last); + mIitcWebView.loadUrl("javascript: " + "var selector = $(window.DIALOGS['" + id + "']); " + "selector.dialog('close'); " + "selector.remove();"); @@ -359,22 +359,22 @@ 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 (fullscreen_mode && (backStack.isEmpty() || fullscreen_actionbar)) { + if (mFullscreenMode && (mBackStack.isEmpty() || mFullscreenActionbar)) { this.toggleFullscreen(); - } else if (!backStack.isEmpty()) { - // Pop last item from backStack and pretend the relevant menu item was clicked + } else if (!mBackStack.isEmpty()) { + // Pop last item from backstack and pretend the relevant menu item was clicked backStackPop(); } else { - if (back_button_pressed || !sharedPref.getBoolean("pref_press_twice_to_exit", false)) + if (mBackButtonPressed || !mSharedPrefs.getBoolean("pref_press_twice_to_exit", false)) super.onBackPressed(); else { - back_button_pressed = true; + mBackButtonPressed = true; Toast.makeText(this, "Press twice to exit", Toast.LENGTH_SHORT).show(); // reset back button after 2 seconds new Handler().postDelayed(new Runnable() { @Override public void run() { - back_button_pressed = false; + mBackButtonPressed = false; } }, 2000); } @@ -382,42 +382,42 @@ public class IITC_Mobile extends Activity { } private void setActionBarHomeEnabledWithUp(boolean enabled) { - actionBar.setDisplayHomeAsUpEnabled(enabled); + mActionBar.setDisplayHomeAsUpEnabled(enabled); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) - actionBar.setHomeButtonEnabled(enabled); + mActionBar.setHomeButtonEnabled(enabled); } public void backStackPop() { // shouldn't be called when back stack is empty // catch wrong usage - if (backStack.isEmpty()) { + if (mBackStack.isEmpty()) { // Empty back stack means we should be at home (ie map) screen setActionBarHomeEnabledWithUp(false); - actionBar.setTitle(getString(R.string.app_name)); - iitc_view.loadUrl("javascript: window.show('map');"); + mActionBar.setTitle(getString(R.string.app_name)); + mIitcWebView.loadUrl("javascript: window.show('map');"); return; } - int index = backStack.size() - 1; - int itemId = backStack.remove(index); - backStack_push = false; + int index = mBackStack.size() - 1; + int itemId = mBackStack.remove(index); + mBackStackPush = false; handleMenuItemSelected(itemId); } public void backStackUpdate(int itemId) { // ensure no double adds - if (itemId == currentPane) return; + if (itemId == mCurrentPane) return; if (itemId == android.R.id.home) { - backStack.clear(); - backStack_push = true; + mBackStack.clear(); + mBackStackPush = true; } else { - if (backStack_push) - backStack.add(currentPane); + if (mBackStackPush) + mBackStack.add(mCurrentPane); else - backStack_push = true; + mBackStackPush = true; } - currentPane = itemId; - if (backStack.size() >= 1) { + mCurrentPane = itemId; + if (mBackStack.size() >= 1) { setActionBarHomeEnabledWithUp(true); } else { // if we popped our last item from stack...illustrate it on home button @@ -432,14 +432,14 @@ public class IITC_Mobile extends Activity { getMenuInflater().inflate(R.menu.main, menu); // Get the SearchView and set the searchable configuration SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); - this.searchMenuItem = menu.findItem(R.id.menu_search); + this.mSearchMenuItem = menu.findItem(R.id.menu_search); final SearchView searchView = - (SearchView) searchMenuItem.getActionView(); + (SearchView) mSearchMenuItem.getActionView(); // Assumes current activity is the searchable activity searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default - // enable/disable desktop menu - enableDesktopUI(menu, desktop); + // enable/disable mDesktopMode menu + enableDesktopUI(menu, mDesktopMode); return true; } @@ -454,65 +454,65 @@ public class IITC_Mobile extends Activity { public boolean handleMenuItemSelected(int itemId) { switch (itemId) { case android.R.id.home: - iitc_view.loadUrl("javascript: window.show('map');"); + mIitcWebView.loadUrl("javascript: window.show('map');"); return true; case R.id.reload_button: - actionBar.setTitle(getString(R.string.app_name)); - backStack.clear(); + mActionBar.setTitle(getString(R.string.app_name)); + mBackStack.clear(); setActionBarHomeEnabledWithUp(false); // iitc starts on map after reload - currentPane = android.R.id.home; - this.loadUrl(intel_url); + mCurrentPane = android.R.id.home; + this.loadUrl(mIntelUrl); return true; case R.id.toggle_fullscreen: toggleFullscreen(); return true; case R.id.layer_chooser: // Force map view to handle potential issue with back stack - if (!backStack.isEmpty() && currentPane != android.R.id.home) - iitc_view.loadUrl("javascript: window.show('map');"); + if (!mBackStack.isEmpty() && mCurrentPane != android.R.id.home) + mIitcWebView.loadUrl("javascript: window.show('map');"); // the getLayers function calls the setLayers method of IITC_JSInterface - iitc_view.loadUrl("javascript: window.layerChooser.getLayers()"); + mIitcWebView.loadUrl("javascript: window.layerChooser.getLayers()"); return true; // get the users current location and focus it on map case R.id.locate: - iitc_view.loadUrl("javascript: window.show('map');"); + mIitcWebView.loadUrl("javascript: window.show('map');"); // get location from network by default - if (!is_loc_enabled) { - iitc_view.loadUrl("javascript: " + + 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 } else { - if (last_location != null) - iitc_view.loadUrl("javascript: window.map.setView(new L.LatLng(" + - last_location.getLatitude() + "," + - last_location.getLongitude() + "), 15);"); + if (mLastLocation != null) + mIitcWebView.loadUrl("javascript: window.map.setView(new L.LatLng(" + + mLastLocation.getLatitude() + "," + + mLastLocation.getLongitude() + "), 15);"); } return true; // start settings activity case R.id.action_settings: Intent intent = new Intent(this, IITC_Settings.class); - intent.putExtra("iitc_version", iitc_view.getWebViewClient() + intent.putExtra("iitc_version", mIitcWebView.getWebViewClient() .getIITCVersion()); startActivity(intent); return true; case R.id.menu_info: - iitc_view.loadUrl("javascript: window.show('info');"); + mIitcWebView.loadUrl("javascript: window.show('info');"); return true; case R.id.menu_full: - iitc_view.loadUrl("javascript: window.show('full');"); + mIitcWebView.loadUrl("javascript: window.show('full');"); return true; case R.id.menu_compact: - iitc_view.loadUrl("javascript: window.show('compact');"); + mIitcWebView.loadUrl("javascript: window.show('compact');"); return true; case R.id.menu_public: - iitc_view.loadUrl("javascript: window.show('public');"); + mIitcWebView.loadUrl("javascript: window.show('public');"); return true; case R.id.menu_faction: - iitc_view.loadUrl("javascript: window.show('faction');"); + mIitcWebView.loadUrl("javascript: window.show('faction');"); return true; case R.id.menu_debug: - iitc_view.loadUrl("javascript: window.show('debug')"); + mIitcWebView.loadUrl("javascript: window.show('debug')"); return true; default: return false; @@ -521,7 +521,7 @@ public class IITC_Mobile extends Activity { private void loadIITC() { try { - iitc_view.getWebViewClient().loadIITC_JS(this); + mIitcWebView.getWebViewClient().loadIITC_JS(this); } catch (IOException e1) { e1.printStackTrace(); } catch (NullPointerException e2) { @@ -529,9 +529,9 @@ public class IITC_Mobile extends Activity { } } - // vp=f enables desktop mode...vp=m is the defaul mobile view + // vp=f enables mDesktopMode mode...vp=m is the defaul mobile view private String addUrlParam(String url) { - if (desktop) + if (mDesktopMode) return (url + "?vp=f"); else return (url + "?vp=m"); @@ -543,7 +543,7 @@ public class IITC_Mobile extends Activity { showSplashScreen(); url = addUrlParam(url); loadIITC(); - iitc_view.loadUrl(url); + mIitcWebView.loadUrl(url); } // update the user location marker on the map @@ -551,25 +551,25 @@ public class IITC_Mobile extends Activity { // throw away all positions with accuracy > 100 meters // should avoid gps glitches if (loc.getAccuracy() < 100) { - iitc_view.loadUrl("javascript: " + mIitcWebView.loadUrl("javascript: " + "window.plugin.userLocation.updateLocation( " + loc.getLatitude() + ", " + loc.getLongitude() + ");"); } } public void toggleFullscreen() { - if (fullscreen_mode) { - if (fullscreen_actionbar) + if (mFullscreenMode) { + if (mFullscreenActionbar) this.getActionBar().show(); - this.fullscreen_mode = false; + this.mFullscreenMode = false; } else { - if (fullscreen_actionbar) { + 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.fullscreen_mode = true; + this.mFullscreenMode = true; } // toggle notification bar WindowManager.LayoutParams attrs = getWindow().getAttributes(); @@ -578,7 +578,7 @@ public class IITC_Mobile extends Activity { } public IITC_WebView getWebView() { - return this.iitc_view; + return this.mIitcWebView; } /** @@ -608,7 +608,7 @@ public class IITC_Mobile extends Activity { public void onReceivedLoginRequest(IITC_WebViewClient client, WebView view, String realm, String account, String args) { Log.d("iitcm", "logging in...set caching mode to default"); - iitc_view.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); + mIitcWebView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); mLogin = new IITC_DeviceAccountLogin(this, view, client); mLogin.startLogin(realm, account, args); } @@ -638,23 +638,23 @@ public class IITC_Mobile extends Activity { // focused dialogs should be closed first public void setFocusedDialog(String id) { Log.d("iitcm", "Dialog " + id + " focused"); - dialogStack.remove(id); - dialogStack.add(id); + mDialogStack.remove(id); + mDialogStack.add(id); } // called by the javascript interface public void dialogOpened(String id, boolean open) { if (open) { Log.d("iitcm", "Dialog " + id + " added"); - dialogStack.add(id); + mDialogStack.add(id); } else { Log.d("iitcm", "Dialog " + id + " closed"); - dialogStack.remove(id); + mDialogStack.remove(id); } } public void showSplashScreen() { - if (!sharedPref.getBoolean("pref_disable_splash", false)) { + if (!mSharedPrefs.getBoolean("pref_disable_splash", false)) { findViewById(R.id.iitc_webview).setVisibility(View.GONE); findViewById(R.id.imageLoading).setVisibility(View.VISIBLE); } diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_SettingsFragment.java b/mobile/src/com/cradle/iitc_mobile/IITC_SettingsFragment.java index f5fab725..65228058 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_SettingsFragment.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_SettingsFragment.java @@ -21,13 +21,13 @@ import java.util.Scanner; public class IITC_SettingsFragment extends PreferenceFragment { - private String iitc_version; + private String mIitcVersion; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - iitc_version = getArguments().getString("iitc_version"); + mIitcVersion = getArguments().getString("iitc_version"); addPreferencesFromResource(R.xml.preferences); @@ -49,7 +49,7 @@ public class IITC_SettingsFragment extends PreferenceFragment { // set iitc version ListPreference pref_iitc_version = (ListPreference) findPreference("pref_iitc_version"); - pref_iitc_version.setSummary(iitc_version); + pref_iitc_version.setSummary(mIitcVersion); // set iitc source EditTextPreference pref_iitc_source = (EditTextPreference) findPreference("pref_iitc_source"); @@ -60,7 +60,7 @@ public class IITC_SettingsFragment extends PreferenceFragment { Object newValue) { preference.setSummary(getString(R.string.pref_select_iitc_sum) + " " + newValue); - // TODO: update iitc_version when iitc source has + // TODO: update mIitcVersion when iitc source has // changed return true; } diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java b/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java index 7522ce1d..e095386d 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java @@ -19,26 +19,26 @@ import android.webkit.WebView; @SuppressLint("SetJavaScriptEnabled") public class IITC_WebView extends WebView { - private WebSettings settings; - private IITC_WebViewClient webclient; - private IITC_JSInterface js_interface; - private boolean disableJS = false; + private WebSettings mSettings; + private IITC_WebViewClient mIitcWebViewClient; + private IITC_JSInterface mJsInterface; + private boolean mDisableJs = false; // init web view private void iitc_init(Context c) { if (this.isInEditMode()) return; - settings = this.getSettings(); - settings.setJavaScriptEnabled(true); - settings.setDomStorageEnabled(true); - settings.setAllowFileAccess(true); - settings.setGeolocationEnabled(true); - settings.setAppCacheEnabled(true); - settings.setDatabasePath(this.getContext().getApplicationInfo().dataDir + mSettings = this.getSettings(); + mSettings.setJavaScriptEnabled(true); + mSettings.setDomStorageEnabled(true); + mSettings.setAllowFileAccess(true); + mSettings.setGeolocationEnabled(true); + mSettings.setAppCacheEnabled(true); + mSettings.setDatabasePath(this.getContext().getApplicationInfo().dataDir + "/databases/"); - settings.setAppCachePath(this.getContext().getCacheDir() + mSettings.setAppCachePath(this.getContext().getCacheDir() .getAbsolutePath()); - this.js_interface = new IITC_JSInterface(c); - this.addJavascriptInterface(js_interface, "android"); + this.mJsInterface = new IITC_JSInterface(c); + this.addJavascriptInterface(mJsInterface, "android"); this.setWebChromeClient(new WebChromeClient() { /** @@ -65,8 +65,8 @@ public class IITC_WebView extends WebView { } }); - webclient = new IITC_WebViewClient(c); - this.setWebViewClient(webclient); + mIitcWebViewClient = new IITC_WebViewClient(c); + this.setWebViewClient(mIitcWebViewClient); } // constructors ------------------------------------------------- @@ -105,7 +105,7 @@ public class IITC_WebView extends WebView { } } // do nothing if script is enabled; - if (this.disableJS) { + if (this.mDisableJs) { Log.d("iitcm", "javascript injection disabled...return"); return; } @@ -123,21 +123,21 @@ public class IITC_WebView extends WebView { } public IITC_WebViewClient getWebViewClient() { - return this.webclient; + return this.mIitcWebViewClient; } public IITC_JSInterface getJSInterface() { - return this.js_interface; + return this.mJsInterface; } public void updateCaching() { // use cache if on mobile network...saves traffic if (!this.isConnectedToWifi()) { Log.d("iitcm", "not connected to wifi...load tiles from cache"); - settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); + mSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); } else { Log.d("iitcm", "connected to wifi...load tiles from network"); - settings.setCacheMode(WebSettings.LOAD_DEFAULT); + mSettings.setCacheMode(WebSettings.LOAD_DEFAULT); } } @@ -159,7 +159,7 @@ public class IITC_WebView extends WebView { } public void disableJS(boolean val) { - this.disableJS = val; + this.mDisableJs = val; } } diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java b/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java index 16bd51cd..883a5f6a 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java @@ -39,21 +39,21 @@ public class IITC_WebViewClient extends WebViewClient { private static final ByteArrayInputStream EMPTY = new ByteArrayInputStream( "".getBytes()); - private String js = null; - private String iitc_path = null; - private final Context context; + private String mIitcScript = null; + private String mIitcPath = null; + private final Context mContext; public IITC_WebViewClient(Context c) { - this.context = c; - this.iitc_path = Environment.getExternalStorageDirectory().getPath() + this.mContext = c; + this.mIitcPath = Environment.getExternalStorageDirectory().getPath() + "/IITC_Mobile/"; } public String getIITCVersion() { String header = ""; - if (js != null) - header = js.substring(js.indexOf("==UserScript=="), - js.indexOf("==/UserScript==")); + if (mIitcScript != null) + header = mIitcScript.substring(mIitcScript.indexOf("==UserScript=="), + mIitcScript.indexOf("==/UserScript==")); // remove new line comments header = header.replace("\n//", ""); // get a list of key-value @@ -80,16 +80,16 @@ public class IITC_WebViewClient extends WebViewClient { // storage Log.d("iitcm", "adding iitc main script"); if (sharedPref.getBoolean("pref_dev_checkbox", false)) { - js = this.fileToString(iitc_path + js = this.fileToString(mIitcPath + "dev/total-conversion-build.user.js", false); if (js.equals("false")) { - Toast.makeText(context, "File " + iitc_path + + Toast.makeText(mContext, "File " + mIitcPath + "dev/total-conversion-build.user.js not found. " + "Disable developer mode or add iitc files to the dev folder.", Toast.LENGTH_LONG).show(); return; } else { - Toast.makeText(context, "Developer mode enabled", + Toast.makeText(mContext, "Developer mode enabled", Toast.LENGTH_SHORT).show(); } } else { @@ -114,7 +114,7 @@ public class IITC_WebViewClient extends WebViewClient { } } - PackageManager pm = context.getPackageManager(); + PackageManager pm = mContext.getPackageManager(); boolean hasMultitouch = pm .hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH); boolean forcedZoom = sharedPref.getBoolean("pref_user_zoom", false); @@ -138,7 +138,7 @@ public class IITC_WebViewClient extends WebViewClient { // Since the mobile client injects IITC by replacing the gen_dashboard // file, IITC runs to early. The document.ready delays IITC long enough // so it boots correctly. - this.js = "$(document).ready(function(){" + js + "});"; + this.mIitcScript = "$(document).ready(function(){" + js + "});"; } @@ -154,7 +154,7 @@ public class IITC_WebViewClient extends WebViewClient { if (url.startsWith("http://www.ingress.com/intel") || url.startsWith("https://www.ingress.com/intel")) { Log.d("iitcm", "injecting iitc.."); - view.loadUrl("javascript: " + this.js); + view.loadUrl("javascript: " + this.mIitcScript); } super.onPageFinished(view, url); } @@ -165,7 +165,7 @@ public class IITC_WebViewClient extends WebViewClient { @Override public void onReceivedLoginRequest(WebView view, String realm, String account, String args) { Log.d("iitcm", "Login requested: " + realm + " " + account + " " + args); - ((IITC_Mobile) context).onReceivedLoginRequest(this, view, realm, account, args); + ((IITC_Mobile) mContext).onReceivedLoginRequest(this, view, realm, account, args); } // parse all enabled iitc plugins @@ -174,7 +174,7 @@ public class IITC_WebViewClient extends WebViewClient { String js = ""; // get the plugin preferences SharedPreferences sharedPref = PreferenceManager - .getDefaultSharedPreferences(context); + .getDefaultSharedPreferences(mContext); boolean dev_enabled = sharedPref.getBoolean("pref_dev_checkbox", false); Map all_prefs = sharedPref.getAll(); @@ -184,10 +184,10 @@ public class IITC_WebViewClient extends WebViewClient { String plugin = entry.getKey(); if (plugin.endsWith("user.js") && entry.getValue().toString().equals("true")) { // load default iitc plugins - if (!plugin.startsWith(iitc_path)) { + if (!plugin.startsWith(mIitcPath)) { Log.d("iitcm", "adding plugin " + plugin); if (dev_enabled) - js += this.removePluginWrapper(iitc_path + "dev/plugins/" + js += this.removePluginWrapper(mIitcPath + "dev/plugins/" + plugin, false); else js += this.removePluginWrapper("plugins/" + plugin, true); @@ -211,7 +211,7 @@ public class IITC_WebViewClient extends WebViewClient { String js = ""; // load plugin from external storage if dev mode are enabled if (dev_enabled) - js = this.removePluginWrapper(iitc_path + "dev/user-location.user.js", false); + js = this.removePluginWrapper(mIitcPath + "dev/user-location.user.js", false); else // load plugin from asset folder js = this.removePluginWrapper("user-location.user.js", true); @@ -235,7 +235,7 @@ public class IITC_WebViewClient extends WebViewClient { } } else { // load plugins from asset folder - AssetManager am = context.getAssets(); + AssetManager am = mContext.getAssets(); try { s = new Scanner(am.open(file)).useDelimiter("\\A"); } catch (IOException e) { @@ -297,7 +297,7 @@ public class IITC_WebViewClient extends WebViewClient { if(url.contains("css/basic.css")) { Log.d("iitcm", "basic.css received...should be ingress intel login"); // get rid of loading screen to log in - IITC_Mobile iitc = (IITC_Mobile) context; + IITC_Mobile iitc = (IITC_Mobile) mContext; iitc.findViewById(R.id.iitc_webview).setVisibility(View.VISIBLE); iitc.findViewById(R.id.imageLoading).setVisibility(View.GONE); } @@ -342,7 +342,7 @@ public class IITC_WebViewClient extends WebViewClient { Log.d("iitcm", "should be an internal clicked position link...reload script for: " + url); - ((IITC_Mobile) context).loadUrl(url); + ((IITC_Mobile) mContext).loadUrl(url); } if (url.contains("logout")) { Log.d("iitcm", "logging out...set caching mode to default"); @@ -354,7 +354,7 @@ public class IITC_WebViewClient extends WebViewClient { "no ingress intel link, start external app to load url: " + url); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); - context.startActivity(intent); + mContext.startActivity(intent); return true; } } diff --git a/mobile/src/com/cradle/iitc_mobile/share/ShareActivity.java b/mobile/src/com/cradle/iitc_mobile/share/ShareActivity.java index de59f75a..d85aff49 100644 --- a/mobile/src/com/cradle/iitc_mobile/share/ShareActivity.java +++ b/mobile/src/com/cradle/iitc_mobile/share/ShareActivity.java @@ -80,7 +80,8 @@ public class ShareActivity extends FragmentActivity implements ActionBar.TabList String gMapsUri; if (decFormat.getDecimalSeparator() == '.') try { - gMapsUri = "http://maps.google.com/maps?q=loc:" + mLl + "%20(" + URLEncoder.encode(mTitle, "UTF-8") + ")&z=" + mZoom; + gMapsUri = "http://maps.google.com/maps?q=loc:" + mLl + + "%20(" + URLEncoder.encode(mTitle, "UTF-8") + ")&z=" + mZoom; } catch (UnsupportedEncodingException e) { gMapsUri = "http://maps.google.com/maps?ll=" + mLl + "&z=" + mZoom; e.printStackTrace();