diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_AboutDialogPreference.java b/mobile/src/com/cradle/iitc_mobile/IITC_AboutDialogPreference.java index 9e33ed50..1549e768 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_AboutDialogPreference.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_AboutDialogPreference.java @@ -12,7 +12,7 @@ import android.widget.TextView; public class IITC_AboutDialogPreference extends DialogPreference { - private Context context; + private final Context context; public IITC_AboutDialogPreference(Context context, AttributeSet attrs) { super(context, attrs); diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_DeviceAccountLogin.java b/mobile/src/com/cradle/iitc_mobile/IITC_DeviceAccountLogin.java index db9511ff..6e8c674a 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_DeviceAccountLogin.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_DeviceAccountLogin.java @@ -54,19 +54,19 @@ public class IITC_DeviceAccountLogin implements AccountManagerCallback { } private Account mAccount; - private AccountAdapter mAccountAdapter; - private AccountManager mAccountManager; + private final AccountAdapter mAccountAdapter; + private final AccountManager mAccountManager; private Account[] mAccounts; - private IITC_Mobile mActivity; + private final IITC_Mobile mActivity; private String mAuthToken; - private AlertDialog mProgressbar; - private WebView mWebView; + private final AlertDialog mProgressbar; + private final WebView mWebView; /** * This listener is invoked when an item in the account list is selected. (It is also used when the 'cancel' button * is clicked, (in which case `index` is <0) */ - private DialogInterface.OnClickListener onClickListener = new DialogInterface.OnClickListener() { + private final DialogInterface.OnClickListener onClickListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int index) { if (index >= 0 && index < mAccounts.length) { diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java b/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java index fc6a7177..2c608c0e 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java @@ -22,13 +22,13 @@ import android.widget.Toast; public class IITC_JSInterface { // context of main activity - Context context; - HashMap layer_ids; - boolean[] overlay_is_active; - int active_base_layer; - String[] overlay_layers, base_layers; - int num_base_layers; - int num_overlay_layers; + 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; IITC_JSInterface(Context c) { layer_ids = new HashMap(); @@ -167,8 +167,8 @@ public class IITC_JSInterface { String id = ""; String name = ""; boolean isActive = false; - for (int j = 0; j < layers.length; ++j) { - String[] values = layers[j].split(":"); + for (String b_layer : layers) { + String[] values = b_layer.split(":"); if (values[0].contains("active")) isActive = values[1].equals("true"); if (values[0].contains("layerId")) id = values[1]; if (values[0].contains("name")) name = values[1]; @@ -193,8 +193,8 @@ public class IITC_JSInterface { String id = ""; String name = ""; boolean isActive = false; - for (int j = 0; j < layers.length; ++j) { - String[] values = layers[j].split(":"); + for (String o_layer : layers) { + String[] values = o_layer.split(":"); if (values[0].contains("active")) isActive = values[1].equals("true"); if (values[0].contains("layerId")) id = values[1]; if (values[0].contains("name")) name = values[1]; diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java index 3ef78e20..6a56326b 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java @@ -37,7 +37,7 @@ public class IITC_Mobile extends Activity { private IITC_WebView iitc_view; private OnSharedPreferenceChangeListener listener; - String intel_url = "https://www.ingress.com/intel"; + 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; @@ -49,11 +49,11 @@ public class IITC_Mobile extends Activity { private MenuItem searchMenuItem; private boolean desktop = false; private boolean reload_needed = false; - private ArrayList dialogStack = new ArrayList(); + private final ArrayList dialogStack = new ArrayList(); private SharedPreferences sharedPref; // Used for custom back stack handling - private ArrayList backStack = new ArrayList(); + private final ArrayList backStack = new ArrayList(); private boolean backStack_push = true; private int currentPane = android.R.id.home; private boolean back_button_pressed = false; @@ -144,7 +144,7 @@ public class IITC_Mobile extends Activity { }; is_loc_enabled = sharedPref.getBoolean("pref_user_loc", false); - if (is_loc_enabled == true) { + if (is_loc_enabled) { // Register the listener with the Location Manager to receive // location updates loc_mngr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, @@ -206,7 +206,7 @@ public class IITC_Mobile extends Activity { iitc_view.loadUrl("javascript: window.renderUpdateStatus()"); iitc_view.updateCaching(); - if (is_loc_enabled == true) { + if (is_loc_enabled) { // Register the listener with the Location Manager to receive // location updates loc_mngr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, @@ -257,7 +257,7 @@ public class IITC_Mobile extends Activity { } Log.d("iitcm", "stopping iitcm"); - if (is_loc_enabled == true) + if (is_loc_enabled) loc_mngr.removeUpdates(loc_listener); super.onStop(); @@ -375,8 +375,7 @@ public class IITC_Mobile extends Activity { // Handle item selection final int itemId = item.getItemId(); boolean result = handleMenuItemSelected(itemId); - if (!result) return super.onOptionsItemSelected(item); - return true; + return result || super.onOptionsItemSelected(item); } public boolean handleMenuItemSelected(int itemId) { diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_SettingsFragment.java b/mobile/src/com/cradle/iitc_mobile/IITC_SettingsFragment.java index 57b46833..c6ccf7b5 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_SettingsFragment.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_SettingsFragment.java @@ -22,7 +22,7 @@ import java.util.Scanner; public class IITC_SettingsFragment extends PreferenceFragment { - String iitc_version; + private String iitc_version; @Override public void onCreate(Bundle savedInstanceState) { @@ -60,7 +60,7 @@ public class IITC_SettingsFragment extends PreferenceFragment { public boolean onPreferenceChange(Preference preference, Object newValue) { preference.setSummary(getString(R.string.pref_select_iitc_sum) + - " " + (CharSequence) newValue); + " " + newValue); // TODO: update iitc_version when iitc source has // changed return true; @@ -88,12 +88,12 @@ public class IITC_SettingsFragment extends PreferenceFragment { e.printStackTrace(); } - for (int i = 0; i < asset_array.length; i++) { + for (String anAsset_array : asset_array) { // find user plugin name for user readable entries Scanner s = null; String src = ""; try { - s = new Scanner(am.open("plugins/" + asset_array[i])) + s = new Scanner(am.open("plugins/" + anAsset_array)) .useDelimiter("\\A"); } catch (IOException e2) { // TODO Auto-generated catch block @@ -102,7 +102,7 @@ public class IITC_SettingsFragment extends PreferenceFragment { if (s != null) src = s.hasNext() ? s.next() : ""; // now we have all stuff together and can build the pref screen - addPluginPreference(root, src, asset_array[i], false); + addPluginPreference(root, src, anAsset_array, false); } // load additional plugins from /IITC_Mobile/plugins/ @@ -113,18 +113,18 @@ public class IITC_SettingsFragment extends PreferenceFragment { if (files != null) { Scanner s = null; String src = ""; - for (int i = 0; i < files.length; ++i) { + for (File file : files) { try { - s = new Scanner(files[i]).useDelimiter("\\A"); + s = new Scanner(file).useDelimiter("\\A"); } catch (FileNotFoundException e) { e.printStackTrace(); - Log.d("iitcm", "failed to parse file " + files[i]); + Log.d("iitcm", "failed to parse file " + file); } if (s != null) src = s.hasNext() ? s.next() : ""; // now we have all stuff together and can build the pref screen - addPluginPreference(root, src, files[i].toString(), true); + addPluginPreference(root, src, file.toString(), true); } } } diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java b/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java index 2a910f2a..9b4b9a0c 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java @@ -106,7 +106,7 @@ public class IITC_WebView extends WebView { } } // do nothing if script is enabled; - if (this.disableJS == true) { + if (this.disableJS) { Log.d("iitcm", "javascript injection disabled...return"); return; } diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java b/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java index 5912002d..960e4fdc 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java @@ -35,7 +35,7 @@ public class IITC_WebViewClient extends WebViewClient { private WebResourceResponse iitcjs; private String js = null; private String iitc_path = null; - Context context; + private final Context context; public IITC_WebViewClient(Context c) { this.context = c; @@ -126,14 +126,14 @@ public class IITC_WebViewClient extends WebViewClient { iitcjs = new WebResourceResponse("text/javascript", "UTF-8", new ByteArrayInputStream(js.getBytes())); - }; + } // enable https @Override public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { handler.proceed(); - }; + } /** * this method is called automatically when the Google login form is opened. @@ -162,7 +162,6 @@ public class IITC_WebViewClient extends WebViewClient { // get the plugin preferences SharedPreferences sharedPref = PreferenceManager .getDefaultSharedPreferences(context); - Set plugin_list = sharedPref.getStringSet("pref_plugins", null); boolean dev_enabled = sharedPref.getBoolean("pref_dev_checkbox", false); Map all_prefs = sharedPref.getAll(); @@ -170,7 +169,7 @@ public class IITC_WebViewClient extends WebViewClient { // iterate through all plugins for(Map.Entry entry : all_prefs.entrySet()){ String plugin = entry.getKey(); - if (plugin.endsWith("user.js") && entry.getValue().toString() == "true") { + if (plugin.endsWith("user.js") && entry.getValue().toString().equals("true")) { // load default iitc plugins if (!plugin.startsWith(iitc_path)) { Log.d("iitcm", "adding plugin " + plugin); @@ -258,7 +257,7 @@ public class IITC_WebViewClient extends WebViewClient { public String removePluginWrapper(String file, boolean asset) { if (!file.endsWith("user.js")) return ""; String js = fileToString(file, asset); - if (js == "false") return ""; + if (js.equals("false")) return ""; js = js.replaceAll("\r\n", "\n"); //convert CR-LF pairs to LF - windows format text files js = js.replaceAll("\r", "\n"); //convert remaining CR to LF - Mac format files(?) String wrapper_start = "function wrapper() {";