From dc22aaf4ddcc7af6c1655d1cf42e76466ac23369 Mon Sep 17 00:00:00 2001 From: Philipp Schaefer Date: Sun, 16 Jun 2013 13:28:41 +0200 Subject: [PATCH] more code formatting --- .../iitc_mobile/IITC_DeviceAccountLogin.java | 4 +- .../cradle/iitc_mobile/IITC_JSInterface.java | 52 ++++++++----------- .../com/cradle/iitc_mobile/IITC_Mobile.java | 13 +++-- .../com/cradle/iitc_mobile/IITC_Settings.java | 2 +- .../iitc_mobile/IITC_SettingsFragment.java | 3 +- .../com/cradle/iitc_mobile/IITC_WebView.java | 11 ++-- .../iitc_mobile/IITC_WebViewClient.java | 16 +++--- 7 files changed, 46 insertions(+), 55 deletions(-) diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_DeviceAccountLogin.java b/mobile/src/com/cradle/iitc_mobile/IITC_DeviceAccountLogin.java index 6e8c674a..e9a1f79e 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_DeviceAccountLogin.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_DeviceAccountLogin.java @@ -112,7 +112,7 @@ public class IITC_DeviceAccountLogin implements AccountManagerCallback { /** * called to start authenticating using AccountManager. - * + *

* After a token is created, AccountManager will call the run() method. */ private void startAuthentication() { @@ -164,7 +164,7 @@ public class IITC_DeviceAccountLogin implements AccountManagerCallback { /** * start authentication - * + *

* if we already have a username (e.g. because the existing login has timed out), we can directly start * authentication if an account with that username is found. */ diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java b/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java index 2c608c0e..0cf57fc4 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.AlertDialog; import android.content.ClipData; import android.content.ClipboardManager; @@ -18,6 +13,11 @@ import android.util.Log; import android.webkit.JavascriptInterface; import android.widget.Toast; +import org.json.JSONArray; +import org.json.JSONException; + +import java.util.HashMap; + // provide communication between IITC script and android app public class IITC_JSInterface { @@ -74,28 +74,22 @@ public class IITC_JSInterface { if (id.equals("map")) { button_id = android.R.id.home; title = iitcm.getString(R.string.app_name); - } - else if (id.equals("info")) { + } else if (id.equals("info")) { button_id = R.id.menu_info; title = "Info"; - } - else if (id.equals("full")) { + } else if (id.equals("full")) { button_id = R.id.menu_full; title = "Full"; - } - else if (id.equals("compact")) { + } else if (id.equals("compact")) { button_id = R.id.menu_compact; title = "Compact"; - } - else if (id.equals("public")) { + } else if (id.equals("public")) { button_id = R.id.menu_public; title = "Public"; - } - else if (id.equals("faction")) { + } else if (id.equals("faction")) { button_id = R.id.menu_faction; title = "Faction"; - } - else if (id.equals("debug")) { + } else if (id.equals("debug")) { button_id = R.id.menu_debug; title = "Debug"; } @@ -215,7 +209,7 @@ public class IITC_JSInterface { // show all overlay layers in a multi selection list dialog private void show_multi_selection() { // build the layer chooser dialog - AlertDialog.Builder d_m = new AlertDialog.Builder(context); + AlertDialog.Builder d_m = new AlertDialog.Builder(context); OnMultiChoiceClickListener m_listener = new OnMultiChoiceClickListener() { @Override @@ -227,20 +221,20 @@ public class IITC_JSInterface { } }; - d_m.setMultiChoiceItems(overlay_layers, overlay_is_active , m_listener); + d_m.setMultiChoiceItems(overlay_layers, overlay_is_active, m_listener); // switch to base layers d_m.setPositiveButton("Base Layers", new OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - show_single_selection(); - dialog.cancel(); - } + @Override + public void onClick(DialogInterface dialog, int which) { + show_single_selection(); + dialog.cancel(); + } }); d_m.setNegativeButton("Close", new OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.cancel(); - } + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.cancel(); + } }); d_m.setTitle("Overlay Layers"); d_m.show(); @@ -256,7 +250,7 @@ public class IITC_JSInterface { + layer_ids.get(base_layers[which]) + "," + true + ");"); active_base_layer = which; - } + } }; AlertDialog.Builder d_s = new AlertDialog.Builder(context); d_s.setSingleChoiceItems(base_layers, active_base_layer, s_listener); diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java index 6a56326b..b93dcb5e 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java @@ -1,8 +1,5 @@ package com.cradle.iitc_mobile; -import java.io.IOException; -import java.util.ArrayList; - import android.app.ActionBar; import android.app.Activity; import android.app.SearchManager; @@ -31,6 +28,9 @@ import android.webkit.WebView; import android.widget.SearchView; import android.widget.Toast; +import java.io.IOException; +import java.util.ArrayList; + public class IITC_Mobile extends Activity { private static final int REQUEST_LOGIN = 1; @@ -92,8 +92,7 @@ public class IITC_Mobile extends Activity { if (desktop) { setActionBarHomeEnabledWithUp(false); actionBar.setTitle(getString(R.string.app_name)); - } - else actionBar.setHomeButtonEnabled(true); + } else actionBar.setHomeButtonEnabled(true); invalidateOptionsMenu(); } if (key.equals("pref_user_loc")) @@ -301,7 +300,7 @@ public class IITC_Mobile extends Activity { new Handler().postDelayed(new Runnable() { @Override public void run() { - back_button_pressed=false; + back_button_pressed = false; } }, 2000); } @@ -407,7 +406,7 @@ public class IITC_Mobile extends Activity { // get location from network by default if (!is_loc_enabled) { iitc_view.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 (last_location != null) iitc_view.loadUrl("javascript: window.map.setView(new L.LatLng(" + diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_Settings.java b/mobile/src/com/cradle/iitc_mobile/IITC_Settings.java index 99cb6424..4ac7efe6 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_Settings.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_Settings.java @@ -29,7 +29,7 @@ public class IITC_Settings extends Activity { 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: onBackPressed(); return true; default: diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_SettingsFragment.java b/mobile/src/com/cradle/iitc_mobile/IITC_SettingsFragment.java index c6ccf7b5..e72172ad 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_SettingsFragment.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_SettingsFragment.java @@ -6,7 +6,6 @@ import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.AssetManager; import android.os.Bundle; import android.os.Environment; -import android.preference.CheckBoxPreference; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; @@ -58,7 +57,7 @@ public class IITC_SettingsFragment extends PreferenceFragment { .setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, - Object newValue) { + Object newValue) { preference.setSummary(getString(R.string.pref_select_iitc_sum) + " " + newValue); // TODO: update iitc_version when iitc source has diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java b/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java index 9b4b9a0c..e1da083a 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java @@ -11,10 +11,10 @@ import android.os.Build; import android.preference.PreferenceManager; import android.util.AttributeSet; import android.util.Log; +import android.webkit.GeolocationPermissions; import android.webkit.WebChromeClient; import android.webkit.WebSettings; import android.webkit.WebView; -import android.webkit.GeolocationPermissions; @SuppressLint("SetJavaScriptEnabled") public class IITC_WebView extends WebView { @@ -26,7 +26,7 @@ public class IITC_WebView extends WebView { // init web view private void iitc_init(Context c) { - if ( this.isInEditMode() ) return; + if (this.isInEditMode()) return; settings = this.getSettings(); settings.setJavaScriptEnabled(true); settings.setDomStorageEnabled(true); @@ -44,12 +44,12 @@ public class IITC_WebView extends WebView { this.setWebChromeClient(new WebChromeClient() { /** * our webchromeclient should share geolocation with the iitc script - * + * * allow access by default */ @Override public void onGeolocationPermissionsShowPrompt(String origin, - GeolocationPermissions.Callback callback) { + GeolocationPermissions.Callback callback) { callback.invoke(origin, true, false); } @@ -95,8 +95,7 @@ public class IITC_WebView extends WebView { public void loadUrl(String url) { // if in edit text mode, don't load javascript otherwise the keyboard closes. HitTestResult testResult = this.getHitTestResult(); - if (url.startsWith("javascript:") && testResult != null && testResult.getType() == HitTestResult.EDIT_TEXT_TYPE) - { + if (url.startsWith("javascript:") && testResult != null && testResult.getType() == HitTestResult.EDIT_TEXT_TYPE) { // let window.show(...) interupt input // window.show(...) is called if one of the action bar buttons // is clicked diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java b/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java index 960e4fdc..993d0e7a 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java @@ -23,7 +23,6 @@ import java.io.IOException; import java.net.URL; import java.util.Map; import java.util.Scanner; -import java.util.Set; public class IITC_WebViewClient extends WebViewClient { private static final ByteArrayInputStream style = new ByteArrayInputStream( @@ -77,7 +76,7 @@ public class IITC_WebViewClient extends WebViewClient { js = this.fileToString(iitc_path + "dev/total-conversion-build.user.js", false); if (js.equals("false")) { - Toast.makeText( context, "File " + iitc_path + + Toast.makeText(context, "File " + iitc_path + "dev/total-conversion-build.user.js not found. " + "Disable developer mode or add iitc files to the dev folder.", Toast.LENGTH_LONG).show(); @@ -131,7 +130,7 @@ public class IITC_WebViewClient extends WebViewClient { // enable https @Override public void onReceivedSslError(WebView view, SslErrorHandler handler, - SslError error) { + SslError error) { handler.proceed(); } @@ -167,7 +166,7 @@ public class IITC_WebViewClient extends WebViewClient { Map all_prefs = sharedPref.getAll(); // iterate through all plugins - for(Map.Entry entry : all_prefs.entrySet()){ + for (Map.Entry entry : all_prefs.entrySet()) { String plugin = entry.getKey(); if (plugin.endsWith("user.js") && entry.getValue().toString().equals("true")) { // load default iitc plugins @@ -263,9 +262,9 @@ public class IITC_WebViewClient extends WebViewClient { String wrapper_start = "function wrapper() {"; String wrapper_end = "} // wrapper end"; String injection_code = "// inject code into site context\n" + - "var script = document.createElement('script');\n" + - "script.appendChild(document.createTextNode('('+ wrapper +')();'));\n" + - "(document.body || document.head || document.documentElement).appendChild(script);"; + "var script = document.createElement('script');\n" + + "script.appendChild(document.createTextNode('('+ wrapper +')();'));\n" + + "(document.body || document.head || document.documentElement).appendChild(script);"; if (js.contains(wrapper_start) && js.contains(wrapper_end) && js.contains(injection_code)) { js = js.replace(wrapper_start, ""); // remove the wrapper function @@ -278,6 +277,7 @@ public class IITC_WebViewClient extends WebViewClient { } return js; } + // Check every external resource if it’s okay to load it and maybe replace // it // with our own content. This is used to block loading Niantic resources @@ -285,7 +285,7 @@ public class IITC_WebViewClient extends WebViewClient { // via http://stackoverflow.com/a/8274881/1684530 @Override public WebResourceResponse shouldInterceptRequest(final WebView view, - String url) { + String url) { if (url.contains("/css/common.css")) { return new WebResourceResponse("text/css", "UTF-8", style); } else if (url.contains("gen_dashboard.js")) {