This commit is contained in:
Jon Atkins 2013-06-16 20:10:06 +01:00
commit c1b751c1e4
10 changed files with 121 additions and 126 deletions

View File

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

View File

@ -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);

View File

@ -54,19 +54,20 @@ public class IITC_DeviceAccountLogin implements AccountManagerCallback<Bundle> {
}
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)
* 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) {
@ -77,7 +78,8 @@ public class IITC_DeviceAccountLogin implements AccountManagerCallback<Bundle> {
}
};
public IITC_DeviceAccountLogin(IITC_Mobile activity, WebView webView, WebViewClient webViewClient) {
public IITC_DeviceAccountLogin(IITC_Mobile activity, WebView webView,
WebViewClient webViewClient) {
mActivity = activity;
mWebView = webView;
mAccountManager = AccountManager.get(activity);
@ -112,7 +114,7 @@ public class IITC_DeviceAccountLogin implements AccountManagerCallback<Bundle> {
/**
* called to start authenticating using AccountManager.
*
* <p/>
* After a token is created, AccountManager will call the run() method.
*/
private void startAuthentication() {
@ -142,16 +144,17 @@ public class IITC_DeviceAccountLogin implements AccountManagerCallback<Bundle> {
try {
Intent launch = (Intent) value.getResult().get(AccountManager.KEY_INTENT);
if (launch != null) {
// There is a reason we need to start the given activity if we want an authentication token.
// (Could be user confirmation or something else. Whatever, we have to start it)
// IITC_Mobile will call it using startActivityForResult
// There is a reason we need to start the given activity if we want an
// authentication token. (Could be user confirmation or something else. Whatever,
// we have to start it) IITC_Mobile will call it using startActivityForResult
mActivity.startLoginActivity(launch);
return;
}
String result = value.getResult().getString(AccountManager.KEY_AUTHTOKEN);
if (result != null) {
// authentication succeded, we can load the given url, which will redirect back to the intel map
// authentication succeded, we can load the given url, which will redirect
// back to the intel map
mWebView.loadUrl(result);
mActivity.loginSucceeded();
} else {
@ -164,9 +167,9 @@ public class IITC_DeviceAccountLogin implements AccountManagerCallback<Bundle> {
/**
* 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.
* <p/>
* 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.
*/
public void startLogin(String realm, String accountName, String args) {
mAccounts = mAccountManager.getAccountsByType(realm);

View File

@ -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,17 +13,22 @@ 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 {
// context of main activity
Context context;
HashMap<String, String> 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<String, String> 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<String, String>();
@ -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";
}
@ -126,7 +120,8 @@ public class IITC_JSInterface {
/*
* the layer strings have a form like:
* [{"layerId":27,"name":"MapQuest OSM","active":true},{"layerId":28,"name":"Default Ingress Map","active":false}]
* [{"layerId":27,"name":"MapQuest OSM","active":true},
* {"layerId":28,"name":"Default Ingress Map","active":false}]
* Put it in a JSONArray and parse it
*/
JSONArray base_layersJSON = null;
@ -167,8 +162,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 +188,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];
@ -221,7 +216,8 @@ public class IITC_JSInterface {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
// activate clicked layer
((IITC_Mobile) context).getWebView().loadUrl("javascript: window.layerChooser.showLayer("
((IITC_Mobile) context).getWebView().loadUrl("javascript: " +
"window.layerChooser.showLayer("
+ layer_ids.get(overlay_layers[which]) + ","
+ overlay_is_active[which] + ");");
}
@ -252,7 +248,8 @@ public class IITC_JSInterface {
@Override
public void onClick(DialogInterface dialog, int which) {
// activate clicked layer
((IITC_Mobile) context).getWebView().loadUrl("javascript: window.layerChooser.showLayer("
((IITC_Mobile) context).getWebView().loadUrl("javascript: " +
"window.layerChooser.showLayer("
+ layer_ids.get(base_layers[which]) + ","
+ true + ");");
active_base_layer = which;

View File

@ -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,13 +28,16 @@ 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;
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<String> dialogStack = new ArrayList<String>();
private final ArrayList<String> dialogStack = new ArrayList<String>();
private SharedPreferences sharedPref;
// Used for custom back stack handling
private ArrayList<Integer> backStack = new ArrayList<Integer>();
private final ArrayList<Integer> backStack = new ArrayList<Integer>();
private boolean backStack_push = true;
private int currentPane = android.R.id.home;
private boolean back_button_pressed = false;
@ -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"))
@ -144,7 +143,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 +205,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,
@ -224,7 +223,8 @@ public class IITC_Mobile extends Activity {
@Override
protected void onStop() {
ConnectivityManager conMan = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
ConnectivityManager conMan =
(ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mobile = conMan
.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
@ -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();
@ -285,7 +285,8 @@ public class IITC_Mobile extends Activity {
"selector.remove();");
return;
}
// exit fullscreen mode if it is enabled and action bar is disabled or the back stack is empty
// 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)) {
this.toggleFullscreen();
} else if (!backStack.isEmpty()) {
@ -375,8 +376,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) {
@ -407,7 +407,8 @@ public class IITC_Mobile extends Activity {
iitc_view.loadUrl("javascript: window.show('map');");
// get location from network by default
if (!is_loc_enabled) {
iitc_view.loadUrl("javascript: window.map.locate({setView : true, maxZoom: 15});");
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
} else {
if (last_location != null)
@ -510,8 +511,8 @@ public class IITC_Mobile extends Activity {
}
/**
* It can occur that in order to authenticate, an external activity has to be launched. (This could for example be a
* confirmation dialog.)
* It can occur that in order to authenticate, an external activity has to be launched.
* (This could for example be a confirmation dialog.)
*/
public void startLoginActivity(Intent launch) {
startActivityForResult(launch, REQUEST_LOGIN); // REQUEST_LOGIN is to recognize the result

View File

@ -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;
@ -22,7 +21,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 +59,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 +87,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 +101,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 <storage-path>/IITC_Mobile/plugins/
@ -113,23 +112,24 @@ 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);
}
}
}
void addPluginPreference(PreferenceScreen root, String src, String plugin_key, boolean additional) {
void addPluginPreference(PreferenceScreen root, String src, String plugin_key,
boolean additional) {
// now parse plugin name, description and category
String header = src.substring(src.indexOf("==UserScript=="),

View File

@ -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 {
@ -95,8 +95,8 @@ 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
@ -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;
}
@ -152,7 +152,8 @@ public class IITC_WebView extends WebView {
// is ticked as mobile hotspot or not.
// --> IITC_WebView.isConnectedToWifi should return 'false' if connected to mobile hotspot
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
return ((wifi.getState() == NetworkInfo.State.CONNECTED) && !conMan.isActiveNetworkMetered());
return ((wifi.getState() == NetworkInfo.State.CONNECTED) &&
!conMan.isActiveNetworkMetered());
}
return (wifi.getState() == NetworkInfo.State.CONNECTED);
}

View File

@ -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(
@ -35,7 +34,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 +125,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 +161,6 @@ public class IITC_WebViewClient extends WebViewClient {
// get the plugin preferences
SharedPreferences sharedPref = PreferenceManager
.getDefaultSharedPreferences(context);
Set<String> plugin_list = sharedPref.getStringSet("pref_plugins", null);
boolean dev_enabled = sharedPref.getBoolean("pref_dev_checkbox", false);
Map<String, ?> all_prefs = sharedPref.getAll();
@ -170,7 +168,7 @@ public class IITC_WebViewClient extends WebViewClient {
// iterate through all plugins
for (Map.Entry<String, ?> 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 +256,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() {";
@ -279,6 +277,7 @@ public class IITC_WebViewClient extends WebViewClient {
}
return js;
}
// Check every external resource if its okay to load it and maybe replace
// it
// with our own content. This is used to block loading Niantic resources

View File

@ -303,18 +303,12 @@
// If it's a map
if(typeList == 'bkmrk_maps'){
if(bkmrk['label']==''){ label = bkmrk['latlng']+' ['+bkmrk['z']+']'; }
if (!window.isSmartphone())
btn_link = '<a class="bookmarksLink" onclick="map.setView(['+latlng+'], '+bkmrk['z']+');return false;">'+label+'</a>';
else
btn_link = '<a class="bookmarksLink" onclick="map.setView(['+latlng+'], '+bkmrk['z']+'); window.show(\'map\'); return false;">'+label+'</a>';
}
// If it's a portal
else if(typeList == 'bkmrk_portals'){
var guid = bkmrk['guid'];
if (!window.isSmartphone())
var btn_link = '<a class="bookmarksLink" onclick="window.zoomToAndShowPortal(\''+guid+'\', ['+latlng+']);return false;">'+label+'</a>';
else
var btn_link = '<a class="bookmarksLink" onclick="window.zoomToAndShowPortal(\''+guid+'\', ['+latlng+']); window.show(\'map\'); return false;">'+label+'</a>';
}
// Create the bookmark
elementTemp += '<li class="bkmrk" id="'+idBkmrk+'">'+btn_remove+btn_link+'</li>';