- added long click support to disable/enabled all layers

- some refactoring
This commit is contained in:
Philipp Schaefer 2013-08-04 00:43:37 +02:00
parent 8563498ded
commit 756dabacfa
9 changed files with 293 additions and 263 deletions

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cradle.iitc_mobile" package="com.cradle.iitc_mobile"
android:versionCode="33" android:versionCode="34"
android:versionName="0.5.2"> android:versionName="0.5.3">
<uses-sdk <uses-sdk
android:minSdkVersion="14" android:minSdkVersion="14"

View File

@ -9,7 +9,7 @@
<string name="layer_chooser">Layer Chooser</string> <string name="layer_chooser">Layer Chooser</string>
<string name="locate">Get Location</string> <string name="locate">Get Location</string>
<string name="local">local</string> <string name="local">local</string>
<string name="close">close</string> <string name="close">Close</string>
<string name="build_version">Build Version</string> <string name="build_version">Build Version</string>
<string name="iitc_version">IITC Version</string> <string name="iitc_version">IITC Version</string>
<string name="about">About</string> <string name="about">About</string>
@ -71,4 +71,8 @@
<string name="tab_map">Map</string> <string name="tab_map">Map</string>
<string name="tab_share">Share</string> <string name="tab_share">Share</string>
<string name="tab_browser">Browser</string> <string name="tab_browser">Browser</string>
<string name="base_layers">Base Layers</string>
<string name="overlay_layers">Overlay Layers</string>
<string name="toggle_layer_selection">Deselect/Select all</string>
</resources> </resources>

View File

@ -12,23 +12,23 @@ import android.widget.TextView;
public class IITC_AboutDialogPreference extends DialogPreference { public class IITC_AboutDialogPreference extends DialogPreference {
private final Context context; private final Context mContext;
public IITC_AboutDialogPreference(Context context, AttributeSet attrs) { public IITC_AboutDialogPreference(Context context, AttributeSet attrs) {
super(context, 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 * 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 * 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. * with CDATA and use Html.fromHtml(...) for clickable hrefs with tags.
*/ */
@Override @Override
protected void onPrepareDialogBuilder(Builder builder) { protected void onPrepareDialogBuilder(Builder builder) {
final TextView message = new TextView(context); final TextView message = new TextView(mContext);
String about_msg = context.getText(R.string.pref_about_msg).toString(); String about_msg = mContext.getText(R.string.pref_about_msg).toString();
message.setText(Html.fromHtml(about_msg)); message.setText(Html.fromHtml(about_msg));
message.setMovementMethod(LinkMovementMethod.getInstance()); message.setMovementMethod(LinkMovementMethod.getInstance());
builder.setView(message).setTitle(R.string.about) builder.setView(message).setTitle(R.string.about)

View File

@ -6,6 +6,7 @@ import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.LauncherActivity;
import android.content.ClipData; import android.content.ClipData;
import android.content.ClipboardManager; import android.content.ClipboardManager;
import android.content.Context; import android.content.Context;
@ -16,6 +17,9 @@ import android.content.Intent;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.webkit.JavascriptInterface; import android.webkit.JavascriptInterface;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast; import android.widget.Toast;
import com.cradle.iitc_mobile.share.ShareActivity; import com.cradle.iitc_mobile.share.ShareActivity;
@ -24,29 +28,29 @@ import com.cradle.iitc_mobile.share.ShareActivity;
public class IITC_JSInterface { public class IITC_JSInterface {
// context of main activity // context of main activity
private final Context context; private final Context mContext;
private final HashMap<String, String> layer_ids; private final HashMap<String, String> mLayerIds;
private boolean[] overlay_is_active; private boolean[] mOverlayIsActive;
private int active_base_layer; private int mActiveBaseLayer;
private String[] overlay_layers, base_layers; private String[] mOverlayLayers, mBaseLayers;
private int num_base_layers; private int mNumBaseLayers;
private int num_overlay_layers; private int mNumOverlayLayers;
IITC_JSInterface(Context c) { IITC_JSInterface(Context c) {
layer_ids = new HashMap<String, String>(); mLayerIds = new HashMap<String, String>();
context = c; mContext = c;
} }
// open dialog to send geo intent for navigation apps like gmaps or waze etc... // open dialog to send geo intent for navigation apps like gmaps or waze etc...
@JavascriptInterface @JavascriptInterface
public void intentPosLink(double lat, double lng, int zoom, String title, boolean isPortal) { 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("lat", lat);
intent.putExtra("lng", lng); intent.putExtra("lng", lng);
intent.putExtra("zoom", zoom); intent.putExtra("zoom", zoom);
intent.putExtra("title", title); intent.putExtra("title", title);
intent.putExtra("isPortal", isPortal); intent.putExtra("isPortal", isPortal);
context.startActivity(intent); mContext.startActivity(intent);
} }
// disable javascript injection while spinner is enabled // disable javascript injection while spinner is enabled
@ -54,24 +58,24 @@ public class IITC_JSInterface {
@JavascriptInterface @JavascriptInterface
public void spinnerEnabled(boolean en) { public void spinnerEnabled(boolean en) {
Log.d("iitcm", "disableJS? " + 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 // copy link to specific portal to android clipboard
@JavascriptInterface @JavascriptInterface
public void copy(String s) { public void copy(String s) {
ClipboardManager clipboard = (ClipboardManager) context ClipboardManager clipboard = (ClipboardManager) mContext
.getSystemService(Context.CLIPBOARD_SERVICE); .getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Copied Text ", s); ClipData clip = ClipData.newPlainText("Copied Text ", s);
clipboard.setPrimaryClip(clip); clipboard.setPrimaryClip(clip);
Toast.makeText(context, "copied to clipboard", Toast.LENGTH_SHORT) Toast.makeText(mContext, "copied to clipboard", Toast.LENGTH_SHORT)
.show(); .show();
} }
@JavascriptInterface @JavascriptInterface
public void switchToPane(String id) { public void switchToPane(String id) {
final IITC_Mobile iitcm = (IITC_Mobile) context; final IITC_Mobile iitcm = (IITC_Mobile) mContext;
final int button_id; final int button_id;
final String title; final String title;
@ -115,18 +119,18 @@ public class IITC_JSInterface {
@JavascriptInterface @JavascriptInterface
public void dialogOpened(String id, boolean open) { public void dialogOpened(String id, boolean open) {
((IITC_Mobile) context).dialogOpened(id, open); ((IITC_Mobile) mContext).dialogOpened(id, open);
} }
@JavascriptInterface @JavascriptInterface
public void dialogFocused(String id) { public void dialogFocused(String id) {
((IITC_Mobile) context).setFocusedDialog(id); ((IITC_Mobile) mContext).setFocusedDialog(id);
} }
@JavascriptInterface @JavascriptInterface
public void iitcLoaded() { public void iitcLoaded() {
Log.d("iitcm", "iitc loaded completely"); Log.d("iitcm", "iitc loaded completely");
final IITC_Mobile iitc = ((IITC_Mobile) context); final IITC_Mobile iitc = ((IITC_Mobile) mContext);
iitc.runOnUiThread(new Runnable() { iitc.runOnUiThread(new Runnable() {
@Override @Override
@ -149,7 +153,6 @@ public class IITC_JSInterface {
*/ */
JSONArray base_layersJSON = null; JSONArray base_layersJSON = null;
JSONArray overlay_layersJSON = null; JSONArray overlay_layersJSON = null;
Log.d("iitcm", base_layer);
try { try {
base_layersJSON = new JSONArray(base_layer); base_layersJSON = new JSONArray(base_layer);
overlay_layersJSON = new JSONArray(overlay_layer); overlay_layersJSON = new JSONArray(overlay_layer);
@ -158,15 +161,15 @@ public class IITC_JSInterface {
} }
// get length and initialize arrays // get length and initialize arrays
num_base_layers = base_layersJSON.length(); mNumBaseLayers = base_layersJSON.length();
num_overlay_layers = overlay_layersJSON.length(); mNumOverlayLayers = overlay_layersJSON.length();
overlay_is_active = new boolean[num_overlay_layers]; mOverlayIsActive = new boolean[mNumOverlayLayers];
overlay_layers = new String[num_overlay_layers]; mOverlayLayers = new String[mNumOverlayLayers];
base_layers = new String[num_base_layers]; mBaseLayers = new String[mNumBaseLayers];
layer_ids.clear(); mLayerIds.clear();
// --------------- base layers ------------------------ // --------------- base layers ------------------------
for (int i = 0; i < num_base_layers; ++i) { for (int i = 0; i < mNumBaseLayers; ++i) {
try { try {
String layer = base_layersJSON.getString(i); String layer = base_layersJSON.getString(i);
layer = layer.replace("{", ""); layer = layer.replace("{", "");
@ -192,9 +195,9 @@ public class IITC_JSInterface {
if (values[0].contains("name")) name = values[1]; if (values[0].contains("name")) name = values[1];
} }
name = name.replace("\"", ""); name = name.replace("\"", "");
layer_ids.put(name, id); mLayerIds.put(name, id);
this.base_layers[i] = name; this.mBaseLayers[i] = name;
if (isActive) active_base_layer = i; if (isActive) mActiveBaseLayer = i;
} catch (JSONException e) { } catch (JSONException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
@ -202,7 +205,7 @@ public class IITC_JSInterface {
} }
// --------------- overlay layers ------------------------ // --------------- overlay layers ------------------------
for (int i = 0; i < num_overlay_layers; ++i) { for (int i = 0; i < mNumOverlayLayers; ++i) {
try { try {
String layer = overlay_layersJSON.getString(i); String layer = overlay_layersJSON.getString(i);
layer = layer.replace("{", ""); layer = layer.replace("{", "");
@ -218,83 +221,105 @@ public class IITC_JSInterface {
if (values[0].contains("name")) name = values[1]; if (values[0].contains("name")) name = values[1];
} }
name = name.replace("\"", ""); name = name.replace("\"", "");
layer_ids.put(name, id); mLayerIds.put(name, id);
this.overlay_layers[i] = name; this.mOverlayLayers[i] = name;
this.overlay_is_active[i] = isActive; this.mOverlayIsActive[i] = isActive;
} catch (JSONException e) { } catch (JSONException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
} }
// show overlay layers by default // show overlay layers by default
show_multi_selection(); showMultiSelection();
} }
// show all overlay layers in a multi selection list dialog // show all overlay layers in a multi selection list dialog
private void show_multi_selection() { private void showMultiSelection() {
// build the layer chooser dialog // 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() { OnMultiChoiceClickListener m_listener = new OnMultiChoiceClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) { public void onClick(DialogInterface dialog, int which, boolean isChecked) {
// activate clicked layer // activate clicked layer
((IITC_Mobile) context).getWebView().loadUrl("javascript: " + ((IITC_Mobile) mContext).getWebView().loadUrl("javascript: " +
"window.layerChooser.showLayer(" "window.layerChooser.showLayer("
+ layer_ids.get(overlay_layers[which]) + "," + mLayerIds.get(mOverlayLayers[which]) + ","
+ overlay_is_active[which] + ");"); + isChecked + ");");
} }
}; };
d_m.setMultiChoiceItems(mOverlayLayers, mOverlayIsActive, m_listener);
d_m.setMultiChoiceItems(overlay_layers, overlay_is_active, m_listener);
// switch to base layers // switch to base layers
d_m.setPositiveButton("Base Layers", new OnClickListener() { d_m.setPositiveButton(R.string.base_layers, new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
show_single_selection(); showSingleSelection();
dialog.cancel(); dialog.dismiss();
} }
}); });
d_m.setNegativeButton("Close", new OnClickListener() { d_m.setNegativeButton(R.string.close, new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
dialog.cancel(); dialog.dismiss();
} }
}); });
d_m.setTitle("Overlay Layers"); d_m.setTitle(R.string.overlay_layers);
d_m.show(); 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 // show all base layers in a single selection list dialog
private void show_single_selection() { private void showSingleSelection() {
OnClickListener s_listener = new OnClickListener() { OnClickListener s_listener = new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
// activate clicked layer // activate clicked layer
((IITC_Mobile) context).getWebView().loadUrl("javascript: " + ((IITC_Mobile) mContext).getWebView().loadUrl("javascript: " +
"window.layerChooser.showLayer(" "window.layerChooser.showLayer("
+ layer_ids.get(base_layers[which]) + "," + mLayerIds.get(mBaseLayers[which]) + ","
+ true + ");"); + true + ");");
active_base_layer = which; mActiveBaseLayer = which;
} }
}; };
AlertDialog.Builder d_s = new AlertDialog.Builder(context); AlertDialog.Builder d_s = new AlertDialog.Builder(mContext);
d_s.setSingleChoiceItems(base_layers, active_base_layer, s_listener); d_s.setSingleChoiceItems(mBaseLayers, mActiveBaseLayer, s_listener);
// switch to overlay layers // switch to overlay layers
d_s.setPositiveButton("Overlay Layers", new OnClickListener() { d_s.setPositiveButton(R.string.overlay_layers, new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
show_multi_selection(); showMultiSelection();
dialog.cancel(); dialog.dismiss();
} }
}); });
d_s.setNegativeButton("Close", new OnClickListener() { d_s.setNegativeButton(R.string.close, new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
dialog.cancel(); dialog.dismiss();
} }
}); });
d_s.setTitle("Base Layers"); d_s.setTitle(R.string.base_layers);
d_s.show(); final AlertDialog dialog = d_s.create();
dialog.show();
} }
} }

View File

@ -39,28 +39,28 @@ public class IITC_Mobile extends Activity {
private static final int REQUEST_LOGIN = 1; private static final int REQUEST_LOGIN = 1;
private IITC_WebView iitc_view; private IITC_WebView mIitcWebView;
private OnSharedPreferenceChangeListener listener; private OnSharedPreferenceChangeListener mSharedPrefChangeListener;
private final String intel_url = "https://www.ingress.com/intel"; private final String mIntelUrl = "https://www.ingress.com/intel";
private boolean is_loc_enabled = false; private boolean mIsLocEnabled = false;
private Location last_location = null; private Location mLastLocation = null;
private LocationManager loc_mngr = null; private LocationManager mLocMngr = null;
private LocationListener loc_listener = null; private LocationListener mLocListener = null;
private boolean fullscreen_mode = false; private boolean mFullscreenMode = false;
private boolean fullscreen_actionbar = false; private boolean mFullscreenActionbar = false;
private ActionBar actionBar; private ActionBar mActionBar;
private IITC_DeviceAccountLogin mLogin; private IITC_DeviceAccountLogin mLogin;
private MenuItem searchMenuItem; private MenuItem mSearchMenuItem;
private boolean desktop = false; private boolean mDesktopMode = false;
private boolean reload_needed = false; private boolean mReloadNeeded = false;
private final ArrayList<String> dialogStack = new ArrayList<String>(); private final ArrayList<String> mDialogStack = new ArrayList<String>();
private SharedPreferences sharedPref; private SharedPreferences mSharedPrefs;
// Used for custom back stack handling // Used for custom back stack handling
private final ArrayList<Integer> backStack = new ArrayList<Integer>(); private final ArrayList<Integer> mBackStack = new ArrayList<Integer>();
private boolean backStack_push = true; private boolean mBackStackPush = true;
private int currentPane = android.R.id.home; private int mCurrentPane = android.R.id.home;
private boolean back_button_pressed = false; private boolean mBackButtonPressed = false;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -70,38 +70,38 @@ public class IITC_Mobile extends Activity {
requestWindowFeature(Window.FEATURE_PROGRESS); requestWindowFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.activity_main); 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 // fetch actionbar, set display flags, title and enable home button
actionBar = this.getActionBar(); mActionBar = this.getActionBar();
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME
| ActionBar.DISPLAY_USE_LOGO | ActionBar.DISPLAY_SHOW_TITLE); | 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) 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 // do something if user changed something in the settings
sharedPref = PreferenceManager mSharedPrefs = PreferenceManager
.getDefaultSharedPreferences(this); .getDefaultSharedPreferences(this);
listener = new OnSharedPreferenceChangeListener() { mSharedPrefChangeListener = new OnSharedPreferenceChangeListener() {
@Override @Override
public void onSharedPreferenceChanged( public void onSharedPreferenceChanged(
SharedPreferences sharedPreferences, String key) { SharedPreferences sharedPreferences, String key) {
if (key.equals("pref_force_desktop")) { if (key.equals("pref_force_desktop")) {
desktop = sharedPreferences.getBoolean("pref_force_desktop", false); mDesktopMode = sharedPreferences.getBoolean("pref_force_desktop", false);
if (desktop) { if (mDesktopMode) {
setActionBarHomeEnabledWithUp(false); setActionBarHomeEnabledWithUp(false);
actionBar.setTitle(getString(R.string.app_name)); mActionBar.setTitle(getString(R.string.app_name));
} else actionBar.setHomeButtonEnabled(true); } else mActionBar.setHomeButtonEnabled(true);
invalidateOptionsMenu(); invalidateOptionsMenu();
} }
if (key.equals("pref_user_loc")) if (key.equals("pref_user_loc"))
is_loc_enabled = sharedPreferences.getBoolean("pref_user_loc", mIsLocEnabled = sharedPreferences.getBoolean("pref_user_loc",
false); false);
if (key.equals("pref_fullscreen_actionbar")) { if (key.equals("pref_fullscreen_actionbar")) {
fullscreen_actionbar = sharedPreferences.getBoolean("pref_fullscreen_actionbar", mFullscreenActionbar = sharedPreferences.getBoolean("pref_fullscreen_actionbar",
false); false);
if (fullscreen_mode) if (mFullscreenMode)
IITC_Mobile.this.getActionBar().hide(); IITC_Mobile.this.getActionBar().hide();
// no iitc reload needed here // no iitc reload needed here
return; 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")) if (key.equals("pref_press_twice_to_exit") || key.equals("pref_share_selected_tab"))
return; return;
reload_needed = true; mReloadNeeded = true;
} }
}; };
sharedPref.registerOnSharedPreferenceChangeListener(listener); mSharedPrefs.registerOnSharedPreferenceChangeListener(mSharedPrefChangeListener);
// enable/disable desktop mode on menu create and url load // enable/disable mDesktopMode mode on menu create and url load
desktop = sharedPref.getBoolean("pref_force_desktop", false); mDesktopMode = mSharedPrefs.getBoolean("pref_force_desktop", false);
// Acquire a reference to the system Location Manager // Acquire a reference to the system Location Manager
loc_mngr = (LocationManager) this mLocMngr = (LocationManager) this
.getSystemService(Context.LOCATION_SERVICE); .getSystemService(Context.LOCATION_SERVICE);
// Define a listener that responds to location updates // Define a mSharedPrefChangeListener that responds to location updates
loc_listener = new LocationListener() { mLocListener = new LocationListener() {
public void onLocationChanged(Location location) { public void onLocationChanged(Location location) {
// Called when a new location is found by the network location // Called when a new location is found by the network location
// provider. // provider.
drawMarker(location); drawMarker(location);
last_location = location; mLastLocation = location;
} }
public void onStatusChanged(String provider, int status, 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); mIsLocEnabled = mSharedPrefs.getBoolean("pref_user_loc", false);
if (is_loc_enabled) { if (mIsLocEnabled) {
// Register the listener with the Location Manager to receive // Register the mSharedPrefChangeListener with the Location Manager to receive
// location updates // location updates
loc_mngr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, mLocMngr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
0, 0, loc_listener); 0, 0, mLocListener);
loc_mngr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mLocMngr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
loc_listener); mLocListener);
} }
fullscreen_actionbar = sharedPref.getBoolean("pref_fullscreen_actionbar", false); mFullscreenActionbar = mSharedPrefs.getBoolean("pref_fullscreen_actionbar", false);
// Clear the back stack // Clear the back stack
backStack.clear(); mBackStack.clear();
setActionBarHomeEnabledWithUp(false); setActionBarHomeEnabledWithUp(false);
handleIntent(getIntent(), true); handleIntent(getIntent(), true);
@ -208,17 +208,17 @@ public class IITC_Mobile extends Activity {
String query = intent.getStringExtra(SearchManager.QUERY); String query = intent.getStringExtra(SearchManager.QUERY);
query = query.replace("'", "''"); query = query.replace("'", "''");
final SearchView searchView = final SearchView searchView =
(SearchView) searchMenuItem.getActionView(); (SearchView) mSearchMenuItem.getActionView();
searchView.setQuery(query, false); searchView.setQuery(query, false);
searchView.clearFocus(); searchView.clearFocus();
actionBar.setTitle(getString(R.string.app_name)); mActionBar.setTitle(getString(R.string.app_name));
backStackUpdate(android.R.id.home); backStackUpdate(android.R.id.home);
iitc_view.loadUrl("javascript:search('" + query + "');"); mIitcWebView.loadUrl("javascript:search('" + query + "');");
return; return;
} }
if (onCreate) { 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 // enough idle...let's do some work
Log.d("iitcm", "resuming...setting reset idleTimer"); Log.d("iitcm", "resuming...setting reset idleTimer");
iitc_view.loadUrl("javascript: window.idleTime = 0"); mIitcWebView.loadUrl("javascript: window.idleTime = 0");
iitc_view.loadUrl("javascript: window.renderUpdateStatus()"); mIitcWebView.loadUrl("javascript: window.renderUpdateStatus()");
iitc_view.updateCaching(); mIitcWebView.updateCaching();
if (is_loc_enabled) { if (mIsLocEnabled) {
// Register the listener with the Location Manager to receive // Register the mSharedPrefChangeListener with the Location Manager to receive
// location updates // location updates
loc_mngr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, mLocMngr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
0, 0, loc_listener); 0, 0, mLocListener);
loc_mngr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mLocMngr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
loc_listener); mLocListener);
} }
if (reload_needed) { if (mReloadNeeded) {
Log.d("iitcm", "preference had changed...reload needed"); Log.d("iitcm", "preference had changed...reload needed");
this.loadUrl(intel_url); this.loadUrl(mIntelUrl);
reload_needed = false; mReloadNeeded = false;
} }
} }
@ -312,25 +312,25 @@ public class IITC_Mobile extends Activity {
Log.d("iitcm", Log.d("iitcm",
"connected to mobile net...abort all running requests"); "connected to mobile net...abort all running requests");
// cancel all current 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 // 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 } else if (wifi.getState() == NetworkInfo.State.CONNECTED
|| wifi.getState() == NetworkInfo.State.CONNECTING) { || wifi.getState() == NetworkInfo.State.CONNECTING) {
iitc_view.loadUrl("javascript: window.idleTime = 999"); mIitcWebView.loadUrl("javascript: window.idleTime = 999");
} }
} else { } else {
Log.d("iitcm", Log.d("iitcm",
"no mobile internet module detected...check wifi state"); "no mobile internet module detected...check wifi state");
if (wifi.getState() == NetworkInfo.State.CONNECTED if (wifi.getState() == NetworkInfo.State.CONNECTED
|| wifi.getState() == NetworkInfo.State.CONNECTING) { || wifi.getState() == NetworkInfo.State.CONNECTING) {
iitc_view.loadUrl("javascript: window.idleTime = 999"); mIitcWebView.loadUrl("javascript: window.idleTime = 999");
} }
} }
Log.d("iitcm", "stopping iitcm"); Log.d("iitcm", "stopping iitcm");
if (is_loc_enabled) if (mIsLocEnabled)
loc_mngr.removeUpdates(loc_listener); mLocMngr.removeUpdates(mLocListener);
super.onStop(); super.onStop();
} }
@ -340,18 +340,18 @@ public class IITC_Mobile extends Activity {
super.onConfigurationChanged(newConfig); super.onConfigurationChanged(newConfig);
Log.d("iitcm", "configuration changed...restoring...reset idleTimer"); Log.d("iitcm", "configuration changed...restoring...reset idleTimer");
iitc_view.loadUrl("javascript: window.idleTime = 0"); mIitcWebView.loadUrl("javascript: window.idleTime = 0");
iitc_view.loadUrl("javascript: window.renderUpdateStatus()"); mIitcWebView.loadUrl("javascript: window.renderUpdateStatus()");
} }
// we want a self defined behavior for the back button // we want a self defined behavior for the back button
@Override @Override
public void onBackPressed() { public void onBackPressed() {
// first kill all open iitc dialogs // first kill all open iitc dialogs
if (!dialogStack.isEmpty()) { if (!mDialogStack.isEmpty()) {
int last = dialogStack.size() - 1; int last = mDialogStack.size() - 1;
String id = dialogStack.get(last); String id = mDialogStack.get(last);
iitc_view.loadUrl("javascript: " + mIitcWebView.loadUrl("javascript: " +
"var selector = $(window.DIALOGS['" + id + "']); " + "var selector = $(window.DIALOGS['" + id + "']); " +
"selector.dialog('close'); " + "selector.dialog('close'); " +
"selector.remove();"); "selector.remove();");
@ -359,22 +359,22 @@ public class IITC_Mobile extends Activity {
} }
// exit fullscreen mode if it is enabled and action bar is disabled // exit fullscreen mode if it is enabled and action bar is disabled
// or the back stack is empty // or the back stack is empty
if (fullscreen_mode && (backStack.isEmpty() || fullscreen_actionbar)) { if (mFullscreenMode && (mBackStack.isEmpty() || mFullscreenActionbar)) {
this.toggleFullscreen(); this.toggleFullscreen();
} else if (!backStack.isEmpty()) { } else if (!mBackStack.isEmpty()) {
// Pop last item from backStack and pretend the relevant menu item was clicked // Pop last item from backstack and pretend the relevant menu item was clicked
backStackPop(); backStackPop();
} else { } 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(); super.onBackPressed();
else { else {
back_button_pressed = true; mBackButtonPressed = true;
Toast.makeText(this, "Press twice to exit", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "Press twice to exit", Toast.LENGTH_SHORT).show();
// reset back button after 2 seconds // reset back button after 2 seconds
new Handler().postDelayed(new Runnable() { new Handler().postDelayed(new Runnable() {
@Override @Override
public void run() { public void run() {
back_button_pressed = false; mBackButtonPressed = false;
} }
}, 2000); }, 2000);
} }
@ -382,42 +382,42 @@ public class IITC_Mobile extends Activity {
} }
private void setActionBarHomeEnabledWithUp(boolean enabled) { private void setActionBarHomeEnabledWithUp(boolean enabled) {
actionBar.setDisplayHomeAsUpEnabled(enabled); mActionBar.setDisplayHomeAsUpEnabled(enabled);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
actionBar.setHomeButtonEnabled(enabled); mActionBar.setHomeButtonEnabled(enabled);
} }
public void backStackPop() { public void backStackPop() {
// shouldn't be called when back stack is empty // shouldn't be called when back stack is empty
// catch wrong usage // catch wrong usage
if (backStack.isEmpty()) { if (mBackStack.isEmpty()) {
// Empty back stack means we should be at home (ie map) screen // Empty back stack means we should be at home (ie map) screen
setActionBarHomeEnabledWithUp(false); setActionBarHomeEnabledWithUp(false);
actionBar.setTitle(getString(R.string.app_name)); mActionBar.setTitle(getString(R.string.app_name));
iitc_view.loadUrl("javascript: window.show('map');"); mIitcWebView.loadUrl("javascript: window.show('map');");
return; return;
} }
int index = backStack.size() - 1; int index = mBackStack.size() - 1;
int itemId = backStack.remove(index); int itemId = mBackStack.remove(index);
backStack_push = false; mBackStackPush = false;
handleMenuItemSelected(itemId); handleMenuItemSelected(itemId);
} }
public void backStackUpdate(int itemId) { public void backStackUpdate(int itemId) {
// ensure no double adds // ensure no double adds
if (itemId == currentPane) return; if (itemId == mCurrentPane) return;
if (itemId == android.R.id.home) { if (itemId == android.R.id.home) {
backStack.clear(); mBackStack.clear();
backStack_push = true; mBackStackPush = true;
} else { } else {
if (backStack_push) if (mBackStackPush)
backStack.add(currentPane); mBackStack.add(mCurrentPane);
else else
backStack_push = true; mBackStackPush = true;
} }
currentPane = itemId; mCurrentPane = itemId;
if (backStack.size() >= 1) { if (mBackStack.size() >= 1) {
setActionBarHomeEnabledWithUp(true); setActionBarHomeEnabledWithUp(true);
} else { } else {
// if we popped our last item from stack...illustrate it on home button // 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); getMenuInflater().inflate(R.menu.main, menu);
// Get the SearchView and set the searchable configuration // Get the SearchView and set the searchable configuration
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); 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 = final SearchView searchView =
(SearchView) searchMenuItem.getActionView(); (SearchView) mSearchMenuItem.getActionView();
// Assumes current activity is the searchable activity // Assumes current activity is the searchable activity
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default
// enable/disable desktop menu // enable/disable mDesktopMode menu
enableDesktopUI(menu, desktop); enableDesktopUI(menu, mDesktopMode);
return true; return true;
} }
@ -454,65 +454,65 @@ public class IITC_Mobile extends Activity {
public boolean handleMenuItemSelected(int itemId) { public boolean handleMenuItemSelected(int itemId) {
switch (itemId) { switch (itemId) {
case android.R.id.home: case android.R.id.home:
iitc_view.loadUrl("javascript: window.show('map');"); mIitcWebView.loadUrl("javascript: window.show('map');");
return true; return true;
case R.id.reload_button: case R.id.reload_button:
actionBar.setTitle(getString(R.string.app_name)); mActionBar.setTitle(getString(R.string.app_name));
backStack.clear(); mBackStack.clear();
setActionBarHomeEnabledWithUp(false); setActionBarHomeEnabledWithUp(false);
// iitc starts on map after reload // iitc starts on map after reload
currentPane = android.R.id.home; mCurrentPane = android.R.id.home;
this.loadUrl(intel_url); this.loadUrl(mIntelUrl);
return true; return true;
case R.id.toggle_fullscreen: case R.id.toggle_fullscreen:
toggleFullscreen(); toggleFullscreen();
return true; return true;
case R.id.layer_chooser: case R.id.layer_chooser:
// Force map view to handle potential issue with back stack // Force map view to handle potential issue with back stack
if (!backStack.isEmpty() && currentPane != android.R.id.home) if (!mBackStack.isEmpty() && mCurrentPane != android.R.id.home)
iitc_view.loadUrl("javascript: window.show('map');"); mIitcWebView.loadUrl("javascript: window.show('map');");
// the getLayers function calls the setLayers method of IITC_JSInterface // 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; return true;
// get the users current location and focus it on map // get the users current location and focus it on map
case R.id.locate: case R.id.locate:
iitc_view.loadUrl("javascript: window.show('map');"); mIitcWebView.loadUrl("javascript: window.show('map');");
// get location from network by default // get location from network by default
if (!is_loc_enabled) { if (!mIsLocEnabled) {
iitc_view.loadUrl("javascript: " + mIitcWebView.loadUrl("javascript: " +
"window.map.locate({setView : true, maxZoom: 15});"); "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 { } else {
if (last_location != null) if (mLastLocation != null)
iitc_view.loadUrl("javascript: window.map.setView(new L.LatLng(" + mIitcWebView.loadUrl("javascript: window.map.setView(new L.LatLng(" +
last_location.getLatitude() + "," + mLastLocation.getLatitude() + "," +
last_location.getLongitude() + "), 15);"); mLastLocation.getLongitude() + "), 15);");
} }
return true; return true;
// start settings activity // start settings activity
case R.id.action_settings: case R.id.action_settings:
Intent intent = new Intent(this, IITC_Settings.class); Intent intent = new Intent(this, IITC_Settings.class);
intent.putExtra("iitc_version", iitc_view.getWebViewClient() intent.putExtra("iitc_version", mIitcWebView.getWebViewClient()
.getIITCVersion()); .getIITCVersion());
startActivity(intent); startActivity(intent);
return true; return true;
case R.id.menu_info: case R.id.menu_info:
iitc_view.loadUrl("javascript: window.show('info');"); mIitcWebView.loadUrl("javascript: window.show('info');");
return true; return true;
case R.id.menu_full: case R.id.menu_full:
iitc_view.loadUrl("javascript: window.show('full');"); mIitcWebView.loadUrl("javascript: window.show('full');");
return true; return true;
case R.id.menu_compact: case R.id.menu_compact:
iitc_view.loadUrl("javascript: window.show('compact');"); mIitcWebView.loadUrl("javascript: window.show('compact');");
return true; return true;
case R.id.menu_public: case R.id.menu_public:
iitc_view.loadUrl("javascript: window.show('public');"); mIitcWebView.loadUrl("javascript: window.show('public');");
return true; return true;
case R.id.menu_faction: case R.id.menu_faction:
iitc_view.loadUrl("javascript: window.show('faction');"); mIitcWebView.loadUrl("javascript: window.show('faction');");
return true; return true;
case R.id.menu_debug: case R.id.menu_debug:
iitc_view.loadUrl("javascript: window.show('debug')"); mIitcWebView.loadUrl("javascript: window.show('debug')");
return true; return true;
default: default:
return false; return false;
@ -521,7 +521,7 @@ public class IITC_Mobile extends Activity {
private void loadIITC() { private void loadIITC() {
try { try {
iitc_view.getWebViewClient().loadIITC_JS(this); mIitcWebView.getWebViewClient().loadIITC_JS(this);
} catch (IOException e1) { } catch (IOException e1) {
e1.printStackTrace(); e1.printStackTrace();
} catch (NullPointerException e2) { } 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) { private String addUrlParam(String url) {
if (desktop) if (mDesktopMode)
return (url + "?vp=f"); return (url + "?vp=f");
else else
return (url + "?vp=m"); return (url + "?vp=m");
@ -543,7 +543,7 @@ public class IITC_Mobile extends Activity {
showSplashScreen(); showSplashScreen();
url = addUrlParam(url); url = addUrlParam(url);
loadIITC(); loadIITC();
iitc_view.loadUrl(url); mIitcWebView.loadUrl(url);
} }
// update the user location marker on the map // 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 // throw away all positions with accuracy > 100 meters
// should avoid gps glitches // should avoid gps glitches
if (loc.getAccuracy() < 100) { if (loc.getAccuracy() < 100) {
iitc_view.loadUrl("javascript: " mIitcWebView.loadUrl("javascript: "
+ "window.plugin.userLocation.updateLocation( " + "window.plugin.userLocation.updateLocation( "
+ loc.getLatitude() + ", " + loc.getLongitude() + ");"); + loc.getLatitude() + ", " + loc.getLongitude() + ");");
} }
} }
public void toggleFullscreen() { public void toggleFullscreen() {
if (fullscreen_mode) { if (mFullscreenMode) {
if (fullscreen_actionbar) if (mFullscreenActionbar)
this.getActionBar().show(); this.getActionBar().show();
this.fullscreen_mode = false; this.mFullscreenMode = false;
} else { } else {
if (fullscreen_actionbar) { if (mFullscreenActionbar) {
this.getActionBar().hide(); this.getActionBar().hide();
// show a toast with instructions to exit the fc mode again // show a toast with instructions to exit the fc mode again
Toast.makeText(this, "Press back button to exit fullscreen", Toast.makeText(this, "Press back button to exit fullscreen",
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
} }
this.fullscreen_mode = true; this.mFullscreenMode = true;
} }
// toggle notification bar // toggle notification bar
WindowManager.LayoutParams attrs = getWindow().getAttributes(); WindowManager.LayoutParams attrs = getWindow().getAttributes();
@ -578,7 +578,7 @@ public class IITC_Mobile extends Activity {
} }
public IITC_WebView getWebView() { 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, 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"); 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 = new IITC_DeviceAccountLogin(this, view, client);
mLogin.startLogin(realm, account, args); mLogin.startLogin(realm, account, args);
} }
@ -638,23 +638,23 @@ public class IITC_Mobile extends Activity {
// focused dialogs should be closed first // focused dialogs should be closed first
public void setFocusedDialog(String id) { public void setFocusedDialog(String id) {
Log.d("iitcm", "Dialog " + id + " focused"); Log.d("iitcm", "Dialog " + id + " focused");
dialogStack.remove(id); mDialogStack.remove(id);
dialogStack.add(id); mDialogStack.add(id);
} }
// called by the javascript interface // called by the javascript interface
public void dialogOpened(String id, boolean open) { public void dialogOpened(String id, boolean open) {
if (open) { if (open) {
Log.d("iitcm", "Dialog " + id + " added"); Log.d("iitcm", "Dialog " + id + " added");
dialogStack.add(id); mDialogStack.add(id);
} else { } else {
Log.d("iitcm", "Dialog " + id + " closed"); Log.d("iitcm", "Dialog " + id + " closed");
dialogStack.remove(id); mDialogStack.remove(id);
} }
} }
public void showSplashScreen() { 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.iitc_webview).setVisibility(View.GONE);
findViewById(R.id.imageLoading).setVisibility(View.VISIBLE); findViewById(R.id.imageLoading).setVisibility(View.VISIBLE);
} }

View File

@ -21,13 +21,13 @@ import java.util.Scanner;
public class IITC_SettingsFragment extends PreferenceFragment { public class IITC_SettingsFragment extends PreferenceFragment {
private String iitc_version; private String mIitcVersion;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
iitc_version = getArguments().getString("iitc_version"); mIitcVersion = getArguments().getString("iitc_version");
addPreferencesFromResource(R.xml.preferences); addPreferencesFromResource(R.xml.preferences);
@ -49,7 +49,7 @@ public class IITC_SettingsFragment extends PreferenceFragment {
// set iitc version // set iitc version
ListPreference pref_iitc_version = (ListPreference) findPreference("pref_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 // set iitc source
EditTextPreference pref_iitc_source = (EditTextPreference) findPreference("pref_iitc_source"); EditTextPreference pref_iitc_source = (EditTextPreference) findPreference("pref_iitc_source");
@ -60,7 +60,7 @@ public class IITC_SettingsFragment extends PreferenceFragment {
Object newValue) { Object newValue) {
preference.setSummary(getString(R.string.pref_select_iitc_sum) + preference.setSummary(getString(R.string.pref_select_iitc_sum) +
" " + newValue); " " + newValue);
// TODO: update iitc_version when iitc source has // TODO: update mIitcVersion when iitc source has
// changed // changed
return true; return true;
} }

View File

@ -19,26 +19,26 @@ import android.webkit.WebView;
@SuppressLint("SetJavaScriptEnabled") @SuppressLint("SetJavaScriptEnabled")
public class IITC_WebView extends WebView { public class IITC_WebView extends WebView {
private WebSettings settings; private WebSettings mSettings;
private IITC_WebViewClient webclient; private IITC_WebViewClient mIitcWebViewClient;
private IITC_JSInterface js_interface; private IITC_JSInterface mJsInterface;
private boolean disableJS = false; private boolean mDisableJs = false;
// init web view // init web view
private void iitc_init(Context c) { private void iitc_init(Context c) {
if (this.isInEditMode()) return; if (this.isInEditMode()) return;
settings = this.getSettings(); mSettings = this.getSettings();
settings.setJavaScriptEnabled(true); mSettings.setJavaScriptEnabled(true);
settings.setDomStorageEnabled(true); mSettings.setDomStorageEnabled(true);
settings.setAllowFileAccess(true); mSettings.setAllowFileAccess(true);
settings.setGeolocationEnabled(true); mSettings.setGeolocationEnabled(true);
settings.setAppCacheEnabled(true); mSettings.setAppCacheEnabled(true);
settings.setDatabasePath(this.getContext().getApplicationInfo().dataDir mSettings.setDatabasePath(this.getContext().getApplicationInfo().dataDir
+ "/databases/"); + "/databases/");
settings.setAppCachePath(this.getContext().getCacheDir() mSettings.setAppCachePath(this.getContext().getCacheDir()
.getAbsolutePath()); .getAbsolutePath());
this.js_interface = new IITC_JSInterface(c); this.mJsInterface = new IITC_JSInterface(c);
this.addJavascriptInterface(js_interface, "android"); this.addJavascriptInterface(mJsInterface, "android");
this.setWebChromeClient(new WebChromeClient() { this.setWebChromeClient(new WebChromeClient() {
/** /**
@ -65,8 +65,8 @@ public class IITC_WebView extends WebView {
} }
}); });
webclient = new IITC_WebViewClient(c); mIitcWebViewClient = new IITC_WebViewClient(c);
this.setWebViewClient(webclient); this.setWebViewClient(mIitcWebViewClient);
} }
// constructors ------------------------------------------------- // constructors -------------------------------------------------
@ -105,7 +105,7 @@ public class IITC_WebView extends WebView {
} }
} }
// do nothing if script is enabled; // do nothing if script is enabled;
if (this.disableJS) { if (this.mDisableJs) {
Log.d("iitcm", "javascript injection disabled...return"); Log.d("iitcm", "javascript injection disabled...return");
return; return;
} }
@ -123,21 +123,21 @@ public class IITC_WebView extends WebView {
} }
public IITC_WebViewClient getWebViewClient() { public IITC_WebViewClient getWebViewClient() {
return this.webclient; return this.mIitcWebViewClient;
} }
public IITC_JSInterface getJSInterface() { public IITC_JSInterface getJSInterface() {
return this.js_interface; return this.mJsInterface;
} }
public void updateCaching() { public void updateCaching() {
// use cache if on mobile network...saves traffic // use cache if on mobile network...saves traffic
if (!this.isConnectedToWifi()) { if (!this.isConnectedToWifi()) {
Log.d("iitcm", "not connected to wifi...load tiles from cache"); 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 { } else {
Log.d("iitcm", "connected to wifi...load tiles from network"); 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) { public void disableJS(boolean val) {
this.disableJS = val; this.mDisableJs = val;
} }
} }

View File

@ -39,21 +39,21 @@ public class IITC_WebViewClient extends WebViewClient {
private static final ByteArrayInputStream EMPTY = new ByteArrayInputStream( private static final ByteArrayInputStream EMPTY = new ByteArrayInputStream(
"".getBytes()); "".getBytes());
private String js = null; private String mIitcScript = null;
private String iitc_path = null; private String mIitcPath = null;
private final Context context; private final Context mContext;
public IITC_WebViewClient(Context c) { public IITC_WebViewClient(Context c) {
this.context = c; this.mContext = c;
this.iitc_path = Environment.getExternalStorageDirectory().getPath() this.mIitcPath = Environment.getExternalStorageDirectory().getPath()
+ "/IITC_Mobile/"; + "/IITC_Mobile/";
} }
public String getIITCVersion() { public String getIITCVersion() {
String header = ""; String header = "";
if (js != null) if (mIitcScript != null)
header = js.substring(js.indexOf("==UserScript=="), header = mIitcScript.substring(mIitcScript.indexOf("==UserScript=="),
js.indexOf("==/UserScript==")); mIitcScript.indexOf("==/UserScript=="));
// remove new line comments // remove new line comments
header = header.replace("\n//", ""); header = header.replace("\n//", "");
// get a list of key-value // get a list of key-value
@ -80,16 +80,16 @@ public class IITC_WebViewClient extends WebViewClient {
// storage // storage
Log.d("iitcm", "adding iitc main script"); Log.d("iitcm", "adding iitc main script");
if (sharedPref.getBoolean("pref_dev_checkbox", false)) { if (sharedPref.getBoolean("pref_dev_checkbox", false)) {
js = this.fileToString(iitc_path js = this.fileToString(mIitcPath
+ "dev/total-conversion-build.user.js", false); + "dev/total-conversion-build.user.js", false);
if (js.equals("false")) { if (js.equals("false")) {
Toast.makeText(context, "File " + iitc_path + Toast.makeText(mContext, "File " + mIitcPath +
"dev/total-conversion-build.user.js not found. " + "dev/total-conversion-build.user.js not found. " +
"Disable developer mode or add iitc files to the dev folder.", "Disable developer mode or add iitc files to the dev folder.",
Toast.LENGTH_LONG).show(); Toast.LENGTH_LONG).show();
return; return;
} else { } else {
Toast.makeText(context, "Developer mode enabled", Toast.makeText(mContext, "Developer mode enabled",
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
} }
} else { } else {
@ -114,7 +114,7 @@ public class IITC_WebViewClient extends WebViewClient {
} }
} }
PackageManager pm = context.getPackageManager(); PackageManager pm = mContext.getPackageManager();
boolean hasMultitouch = pm boolean hasMultitouch = pm
.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH); .hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH);
boolean forcedZoom = sharedPref.getBoolean("pref_user_zoom", false); 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 // Since the mobile client injects IITC by replacing the gen_dashboard
// file, IITC runs to early. The document.ready delays IITC long enough // file, IITC runs to early. The document.ready delays IITC long enough
// so it boots correctly. // 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") if (url.startsWith("http://www.ingress.com/intel")
|| url.startsWith("https://www.ingress.com/intel")) { || url.startsWith("https://www.ingress.com/intel")) {
Log.d("iitcm", "injecting iitc.."); Log.d("iitcm", "injecting iitc..");
view.loadUrl("javascript: " + this.js); view.loadUrl("javascript: " + this.mIitcScript);
} }
super.onPageFinished(view, url); super.onPageFinished(view, url);
} }
@ -165,7 +165,7 @@ public class IITC_WebViewClient extends WebViewClient {
@Override @Override
public void onReceivedLoginRequest(WebView view, String realm, String account, String args) { public void onReceivedLoginRequest(WebView view, String realm, String account, String args) {
Log.d("iitcm", "Login requested: " + realm + " " + account + " " + 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 // parse all enabled iitc plugins
@ -174,7 +174,7 @@ public class IITC_WebViewClient extends WebViewClient {
String js = ""; String js = "";
// get the plugin preferences // get the plugin preferences
SharedPreferences sharedPref = PreferenceManager SharedPreferences sharedPref = PreferenceManager
.getDefaultSharedPreferences(context); .getDefaultSharedPreferences(mContext);
boolean dev_enabled = sharedPref.getBoolean("pref_dev_checkbox", false); boolean dev_enabled = sharedPref.getBoolean("pref_dev_checkbox", false);
Map<String, ?> all_prefs = sharedPref.getAll(); Map<String, ?> all_prefs = sharedPref.getAll();
@ -184,10 +184,10 @@ public class IITC_WebViewClient extends WebViewClient {
String plugin = entry.getKey(); String plugin = entry.getKey();
if (plugin.endsWith("user.js") && entry.getValue().toString().equals("true")) { if (plugin.endsWith("user.js") && entry.getValue().toString().equals("true")) {
// load default iitc plugins // load default iitc plugins
if (!plugin.startsWith(iitc_path)) { if (!plugin.startsWith(mIitcPath)) {
Log.d("iitcm", "adding plugin " + plugin); Log.d("iitcm", "adding plugin " + plugin);
if (dev_enabled) if (dev_enabled)
js += this.removePluginWrapper(iitc_path + "dev/plugins/" js += this.removePluginWrapper(mIitcPath + "dev/plugins/"
+ plugin, false); + plugin, false);
else else
js += this.removePluginWrapper("plugins/" + plugin, true); js += this.removePluginWrapper("plugins/" + plugin, true);
@ -211,7 +211,7 @@ public class IITC_WebViewClient extends WebViewClient {
String js = ""; String js = "";
// load plugin from external storage if dev mode are enabled // load plugin from external storage if dev mode are enabled
if (dev_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 else
// load plugin from asset folder // load plugin from asset folder
js = this.removePluginWrapper("user-location.user.js", true); js = this.removePluginWrapper("user-location.user.js", true);
@ -235,7 +235,7 @@ public class IITC_WebViewClient extends WebViewClient {
} }
} else { } else {
// load plugins from asset folder // load plugins from asset folder
AssetManager am = context.getAssets(); AssetManager am = mContext.getAssets();
try { try {
s = new Scanner(am.open(file)).useDelimiter("\\A"); s = new Scanner(am.open(file)).useDelimiter("\\A");
} catch (IOException e) { } catch (IOException e) {
@ -297,7 +297,7 @@ public class IITC_WebViewClient extends WebViewClient {
if(url.contains("css/basic.css")) { if(url.contains("css/basic.css")) {
Log.d("iitcm", "basic.css received...should be ingress intel login"); Log.d("iitcm", "basic.css received...should be ingress intel login");
// get rid of loading screen to log in // 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.iitc_webview).setVisibility(View.VISIBLE);
iitc.findViewById(R.id.imageLoading).setVisibility(View.GONE); iitc.findViewById(R.id.imageLoading).setVisibility(View.GONE);
} }
@ -342,7 +342,7 @@ public class IITC_WebViewClient extends WebViewClient {
Log.d("iitcm", Log.d("iitcm",
"should be an internal clicked position link...reload script for: " "should be an internal clicked position link...reload script for: "
+ url); + url);
((IITC_Mobile) context).loadUrl(url); ((IITC_Mobile) mContext).loadUrl(url);
} }
if (url.contains("logout")) { if (url.contains("logout")) {
Log.d("iitcm", "logging out...set caching mode to default"); 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: " "no ingress intel link, start external app to load url: "
+ url); + url);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
context.startActivity(intent); mContext.startActivity(intent);
return true; return true;
} }
} }

View File

@ -80,7 +80,8 @@ public class ShareActivity extends FragmentActivity implements ActionBar.TabList
String gMapsUri; String gMapsUri;
if (decFormat.getDecimalSeparator() == '.') if (decFormat.getDecimalSeparator() == '.')
try { 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) { } catch (UnsupportedEncodingException e) {
gMapsUri = "http://maps.google.com/maps?ll=" + mLl + "&z=" + mZoom; gMapsUri = "http://maps.google.com/maps?ll=" + mLl + "&z=" + mZoom;
e.printStackTrace(); e.printStackTrace();