Merge branch 'master' of https://github.com/jonatkins/ingress-intel-total-conversion
This commit is contained in:
commit
c1b751c1e4
@ -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="28"
|
android:versionCode="29"
|
||||||
android:versionName="0.4.7">
|
android:versionName="0.4.8">
|
||||||
|
|
||||||
<uses-sdk
|
<uses-sdk
|
||||||
android:minSdkVersion="14"
|
android:minSdkVersion="14"
|
||||||
|
@ -12,7 +12,7 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
public class IITC_AboutDialogPreference extends DialogPreference {
|
public class IITC_AboutDialogPreference extends DialogPreference {
|
||||||
|
|
||||||
private Context context;
|
private final Context context;
|
||||||
|
|
||||||
public IITC_AboutDialogPreference(Context context, AttributeSet attrs) {
|
public IITC_AboutDialogPreference(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
|
@ -54,19 +54,20 @@ public class IITC_DeviceAccountLogin implements AccountManagerCallback<Bundle> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Account mAccount;
|
private Account mAccount;
|
||||||
private AccountAdapter mAccountAdapter;
|
private final AccountAdapter mAccountAdapter;
|
||||||
private AccountManager mAccountManager;
|
private final AccountManager mAccountManager;
|
||||||
private Account[] mAccounts;
|
private Account[] mAccounts;
|
||||||
private IITC_Mobile mActivity;
|
private final IITC_Mobile mActivity;
|
||||||
private String mAuthToken;
|
private String mAuthToken;
|
||||||
private AlertDialog mProgressbar;
|
private final AlertDialog mProgressbar;
|
||||||
private WebView mWebView;
|
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
|
* This listener is invoked when an item in the account list is selected.
|
||||||
* is clicked, (in which case `index` is <0)
|
* (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
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int index) {
|
public void onClick(DialogInterface dialog, int index) {
|
||||||
if (index >= 0 && index < mAccounts.length) {
|
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;
|
mActivity = activity;
|
||||||
mWebView = webView;
|
mWebView = webView;
|
||||||
mAccountManager = AccountManager.get(activity);
|
mAccountManager = AccountManager.get(activity);
|
||||||
@ -112,7 +114,7 @@ public class IITC_DeviceAccountLogin implements AccountManagerCallback<Bundle> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* called to start authenticating using AccountManager.
|
* called to start authenticating using AccountManager.
|
||||||
*
|
* <p/>
|
||||||
* After a token is created, AccountManager will call the run() method.
|
* After a token is created, AccountManager will call the run() method.
|
||||||
*/
|
*/
|
||||||
private void startAuthentication() {
|
private void startAuthentication() {
|
||||||
@ -142,16 +144,17 @@ public class IITC_DeviceAccountLogin implements AccountManagerCallback<Bundle> {
|
|||||||
try {
|
try {
|
||||||
Intent launch = (Intent) value.getResult().get(AccountManager.KEY_INTENT);
|
Intent launch = (Intent) value.getResult().get(AccountManager.KEY_INTENT);
|
||||||
if (launch != null) {
|
if (launch != null) {
|
||||||
// There is a reason we need to start the given activity if we want an authentication token.
|
// There is a reason we need to start the given activity if we want an
|
||||||
// (Could be user confirmation or something else. Whatever, we have to start it)
|
// authentication token. (Could be user confirmation or something else. Whatever,
|
||||||
// IITC_Mobile will call it using startActivityForResult
|
// we have to start it) IITC_Mobile will call it using startActivityForResult
|
||||||
mActivity.startLoginActivity(launch);
|
mActivity.startLoginActivity(launch);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String result = value.getResult().getString(AccountManager.KEY_AUTHTOKEN);
|
String result = value.getResult().getString(AccountManager.KEY_AUTHTOKEN);
|
||||||
if (result != null) {
|
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);
|
mWebView.loadUrl(result);
|
||||||
mActivity.loginSucceeded();
|
mActivity.loginSucceeded();
|
||||||
} else {
|
} else {
|
||||||
@ -164,9 +167,9 @@ public class IITC_DeviceAccountLogin implements AccountManagerCallback<Bundle> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* start authentication
|
* start authentication
|
||||||
*
|
* <p/>
|
||||||
* if we already have a username (e.g. because the existing login has timed out), we can directly start
|
* if we already have a username (e.g. because the existing login has timed out),
|
||||||
* authentication if an account with that username is found.
|
* we can directly start authentication if an account with that username is found.
|
||||||
*/
|
*/
|
||||||
public void startLogin(String realm, String accountName, String args) {
|
public void startLogin(String realm, String accountName, String args) {
|
||||||
mAccounts = mAccountManager.getAccountsByType(realm);
|
mAccounts = mAccountManager.getAccountsByType(realm);
|
||||||
|
@ -1,10 +1,5 @@
|
|||||||
package com.cradle.iitc_mobile;
|
package com.cradle.iitc_mobile;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONException;
|
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.ClipData;
|
import android.content.ClipData;
|
||||||
import android.content.ClipboardManager;
|
import android.content.ClipboardManager;
|
||||||
@ -18,17 +13,22 @@ import android.util.Log;
|
|||||||
import android.webkit.JavascriptInterface;
|
import android.webkit.JavascriptInterface;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
// provide communication between IITC script and android app
|
// provide communication between IITC script and android app
|
||||||
public class IITC_JSInterface {
|
public class IITC_JSInterface {
|
||||||
|
|
||||||
// context of main activity
|
// context of main activity
|
||||||
Context context;
|
private final Context context;
|
||||||
HashMap<String, String> layer_ids;
|
private final HashMap<String, String> layer_ids;
|
||||||
boolean[] overlay_is_active;
|
private boolean[] overlay_is_active;
|
||||||
int active_base_layer;
|
private int active_base_layer;
|
||||||
String[] overlay_layers, base_layers;
|
private String[] overlay_layers, base_layers;
|
||||||
int num_base_layers;
|
private int num_base_layers;
|
||||||
int num_overlay_layers;
|
private int num_overlay_layers;
|
||||||
|
|
||||||
IITC_JSInterface(Context c) {
|
IITC_JSInterface(Context c) {
|
||||||
layer_ids = new HashMap<String, String>();
|
layer_ids = new HashMap<String, String>();
|
||||||
@ -74,28 +74,22 @@ public class IITC_JSInterface {
|
|||||||
if (id.equals("map")) {
|
if (id.equals("map")) {
|
||||||
button_id = android.R.id.home;
|
button_id = android.R.id.home;
|
||||||
title = iitcm.getString(R.string.app_name);
|
title = iitcm.getString(R.string.app_name);
|
||||||
}
|
} else if (id.equals("info")) {
|
||||||
else if (id.equals("info")) {
|
|
||||||
button_id = R.id.menu_info;
|
button_id = R.id.menu_info;
|
||||||
title = "Info";
|
title = "Info";
|
||||||
}
|
} else if (id.equals("full")) {
|
||||||
else if (id.equals("full")) {
|
|
||||||
button_id = R.id.menu_full;
|
button_id = R.id.menu_full;
|
||||||
title = "Full";
|
title = "Full";
|
||||||
}
|
} else if (id.equals("compact")) {
|
||||||
else if (id.equals("compact")) {
|
|
||||||
button_id = R.id.menu_compact;
|
button_id = R.id.menu_compact;
|
||||||
title = "Compact";
|
title = "Compact";
|
||||||
}
|
} else if (id.equals("public")) {
|
||||||
else if (id.equals("public")) {
|
|
||||||
button_id = R.id.menu_public;
|
button_id = R.id.menu_public;
|
||||||
title = "Public";
|
title = "Public";
|
||||||
}
|
} else if (id.equals("faction")) {
|
||||||
else if (id.equals("faction")) {
|
|
||||||
button_id = R.id.menu_faction;
|
button_id = R.id.menu_faction;
|
||||||
title = "Faction";
|
title = "Faction";
|
||||||
}
|
} else if (id.equals("debug")) {
|
||||||
else if (id.equals("debug")) {
|
|
||||||
button_id = R.id.menu_debug;
|
button_id = R.id.menu_debug;
|
||||||
title = "Debug";
|
title = "Debug";
|
||||||
}
|
}
|
||||||
@ -126,7 +120,8 @@ public class IITC_JSInterface {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* the layer strings have a form like:
|
* 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
|
* Put it in a JSONArray and parse it
|
||||||
*/
|
*/
|
||||||
JSONArray base_layersJSON = null;
|
JSONArray base_layersJSON = null;
|
||||||
@ -167,8 +162,8 @@ public class IITC_JSInterface {
|
|||||||
String id = "";
|
String id = "";
|
||||||
String name = "";
|
String name = "";
|
||||||
boolean isActive = false;
|
boolean isActive = false;
|
||||||
for (int j = 0; j < layers.length; ++j) {
|
for (String b_layer : layers) {
|
||||||
String[] values = layers[j].split(":");
|
String[] values = b_layer.split(":");
|
||||||
if (values[0].contains("active")) isActive = values[1].equals("true");
|
if (values[0].contains("active")) isActive = values[1].equals("true");
|
||||||
if (values[0].contains("layerId")) id = values[1];
|
if (values[0].contains("layerId")) id = values[1];
|
||||||
if (values[0].contains("name")) name = values[1];
|
if (values[0].contains("name")) name = values[1];
|
||||||
@ -193,8 +188,8 @@ public class IITC_JSInterface {
|
|||||||
String id = "";
|
String id = "";
|
||||||
String name = "";
|
String name = "";
|
||||||
boolean isActive = false;
|
boolean isActive = false;
|
||||||
for (int j = 0; j < layers.length; ++j) {
|
for (String o_layer : layers) {
|
||||||
String[] values = layers[j].split(":");
|
String[] values = o_layer.split(":");
|
||||||
if (values[0].contains("active")) isActive = values[1].equals("true");
|
if (values[0].contains("active")) isActive = values[1].equals("true");
|
||||||
if (values[0].contains("layerId")) id = values[1];
|
if (values[0].contains("layerId")) id = values[1];
|
||||||
if (values[0].contains("name")) name = values[1];
|
if (values[0].contains("name")) name = values[1];
|
||||||
@ -215,32 +210,33 @@ public class IITC_JSInterface {
|
|||||||
// 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 show_multi_selection() {
|
||||||
// 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(context);
|
||||||
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: window.layerChooser.showLayer("
|
((IITC_Mobile) context).getWebView().loadUrl("javascript: " +
|
||||||
|
"window.layerChooser.showLayer("
|
||||||
+ layer_ids.get(overlay_layers[which]) + ","
|
+ layer_ids.get(overlay_layers[which]) + ","
|
||||||
+ overlay_is_active[which] + ");");
|
+ overlay_is_active[which] + ");");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
d_m.setMultiChoiceItems(overlay_layers, overlay_is_active , 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("Base Layers", new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
show_single_selection();
|
show_single_selection();
|
||||||
dialog.cancel();
|
dialog.cancel();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
d_m.setNegativeButton("Close", new OnClickListener() {
|
d_m.setNegativeButton("Close", new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
dialog.cancel();
|
dialog.cancel();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
d_m.setTitle("Overlay Layers");
|
d_m.setTitle("Overlay Layers");
|
||||||
d_m.show();
|
d_m.show();
|
||||||
@ -252,11 +248,12 @@ public class IITC_JSInterface {
|
|||||||
@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: window.layerChooser.showLayer("
|
((IITC_Mobile) context).getWebView().loadUrl("javascript: " +
|
||||||
|
"window.layerChooser.showLayer("
|
||||||
+ layer_ids.get(base_layers[which]) + ","
|
+ layer_ids.get(base_layers[which]) + ","
|
||||||
+ true + ");");
|
+ true + ");");
|
||||||
active_base_layer = which;
|
active_base_layer = which;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
AlertDialog.Builder d_s = new AlertDialog.Builder(context);
|
AlertDialog.Builder d_s = new AlertDialog.Builder(context);
|
||||||
d_s.setSingleChoiceItems(base_layers, active_base_layer, s_listener);
|
d_s.setSingleChoiceItems(base_layers, active_base_layer, s_listener);
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
package com.cradle.iitc_mobile;
|
package com.cradle.iitc_mobile;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import android.app.ActionBar;
|
import android.app.ActionBar;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.SearchManager;
|
import android.app.SearchManager;
|
||||||
@ -31,13 +28,16 @@ import android.webkit.WebView;
|
|||||||
import android.widget.SearchView;
|
import android.widget.SearchView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class IITC_Mobile extends Activity {
|
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 iitc_view;
|
||||||
private OnSharedPreferenceChangeListener listener;
|
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 boolean is_loc_enabled = false;
|
||||||
private Location last_location = null;
|
private Location last_location = null;
|
||||||
private LocationManager loc_mngr = null;
|
private LocationManager loc_mngr = null;
|
||||||
@ -49,11 +49,11 @@ public class IITC_Mobile extends Activity {
|
|||||||
private MenuItem searchMenuItem;
|
private MenuItem searchMenuItem;
|
||||||
private boolean desktop = false;
|
private boolean desktop = false;
|
||||||
private boolean reload_needed = false;
|
private boolean reload_needed = false;
|
||||||
private ArrayList<String> dialogStack = new ArrayList<String>();
|
private final ArrayList<String> dialogStack = new ArrayList<String>();
|
||||||
private SharedPreferences sharedPref;
|
private SharedPreferences sharedPref;
|
||||||
|
|
||||||
// Used for custom back stack handling
|
// 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 boolean backStack_push = true;
|
||||||
private int currentPane = android.R.id.home;
|
private int currentPane = android.R.id.home;
|
||||||
private boolean back_button_pressed = false;
|
private boolean back_button_pressed = false;
|
||||||
@ -92,8 +92,7 @@ public class IITC_Mobile extends Activity {
|
|||||||
if (desktop) {
|
if (desktop) {
|
||||||
setActionBarHomeEnabledWithUp(false);
|
setActionBarHomeEnabledWithUp(false);
|
||||||
actionBar.setTitle(getString(R.string.app_name));
|
actionBar.setTitle(getString(R.string.app_name));
|
||||||
}
|
} else actionBar.setHomeButtonEnabled(true);
|
||||||
else actionBar.setHomeButtonEnabled(true);
|
|
||||||
invalidateOptionsMenu();
|
invalidateOptionsMenu();
|
||||||
}
|
}
|
||||||
if (key.equals("pref_user_loc"))
|
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);
|
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
|
// Register the listener with the Location Manager to receive
|
||||||
// location updates
|
// location updates
|
||||||
loc_mngr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
|
loc_mngr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
|
||||||
@ -206,7 +205,7 @@ public class IITC_Mobile extends Activity {
|
|||||||
iitc_view.loadUrl("javascript: window.renderUpdateStatus()");
|
iitc_view.loadUrl("javascript: window.renderUpdateStatus()");
|
||||||
iitc_view.updateCaching();
|
iitc_view.updateCaching();
|
||||||
|
|
||||||
if (is_loc_enabled == true) {
|
if (is_loc_enabled) {
|
||||||
// Register the listener with the Location Manager to receive
|
// Register the listener with the Location Manager to receive
|
||||||
// location updates
|
// location updates
|
||||||
loc_mngr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
|
loc_mngr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
|
||||||
@ -224,7 +223,8 @@ public class IITC_Mobile extends Activity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
ConnectivityManager conMan = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
ConnectivityManager conMan =
|
||||||
|
(ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
|
||||||
NetworkInfo mobile = conMan
|
NetworkInfo mobile = conMan
|
||||||
.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
|
.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
|
||||||
@ -257,7 +257,7 @@ public class IITC_Mobile extends Activity {
|
|||||||
}
|
}
|
||||||
Log.d("iitcm", "stopping iitcm");
|
Log.d("iitcm", "stopping iitcm");
|
||||||
|
|
||||||
if (is_loc_enabled == true)
|
if (is_loc_enabled)
|
||||||
loc_mngr.removeUpdates(loc_listener);
|
loc_mngr.removeUpdates(loc_listener);
|
||||||
|
|
||||||
super.onStop();
|
super.onStop();
|
||||||
@ -285,7 +285,8 @@ public class IITC_Mobile extends Activity {
|
|||||||
"selector.remove();");
|
"selector.remove();");
|
||||||
return;
|
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)) {
|
if (fullscreen_mode && (backStack.isEmpty() || fullscreen_actionbar)) {
|
||||||
this.toggleFullscreen();
|
this.toggleFullscreen();
|
||||||
} else if (!backStack.isEmpty()) {
|
} else if (!backStack.isEmpty()) {
|
||||||
@ -301,7 +302,7 @@ public class IITC_Mobile extends Activity {
|
|||||||
new Handler().postDelayed(new Runnable() {
|
new Handler().postDelayed(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
back_button_pressed=false;
|
back_button_pressed = false;
|
||||||
}
|
}
|
||||||
}, 2000);
|
}, 2000);
|
||||||
}
|
}
|
||||||
@ -375,8 +376,7 @@ public class IITC_Mobile extends Activity {
|
|||||||
// Handle item selection
|
// Handle item selection
|
||||||
final int itemId = item.getItemId();
|
final int itemId = item.getItemId();
|
||||||
boolean result = handleMenuItemSelected(itemId);
|
boolean result = handleMenuItemSelected(itemId);
|
||||||
if (!result) return super.onOptionsItemSelected(item);
|
return result || super.onOptionsItemSelected(item);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean handleMenuItemSelected(int itemId) {
|
public boolean handleMenuItemSelected(int itemId) {
|
||||||
@ -407,8 +407,9 @@ public class IITC_Mobile extends Activity {
|
|||||||
iitc_view.loadUrl("javascript: window.show('map');");
|
iitc_view.loadUrl("javascript: window.show('map');");
|
||||||
// get location from network by default
|
// get location from network by default
|
||||||
if (!is_loc_enabled) {
|
if (!is_loc_enabled) {
|
||||||
iitc_view.loadUrl("javascript: window.map.locate({setView : true, maxZoom: 15});");
|
iitc_view.loadUrl("javascript: " +
|
||||||
// if gps location is displayed we can use a better location without any costs
|
"window.map.locate({setView : true, maxZoom: 15});");
|
||||||
|
// if gps location is displayed we can use a better location without any costs
|
||||||
} else {
|
} else {
|
||||||
if (last_location != null)
|
if (last_location != null)
|
||||||
iitc_view.loadUrl("javascript: window.map.setView(new L.LatLng(" +
|
iitc_view.loadUrl("javascript: window.map.setView(new L.LatLng(" +
|
||||||
@ -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
|
* It can occur that in order to authenticate, an external activity has to be launched.
|
||||||
* confirmation dialog.)
|
* (This could for example be a confirmation dialog.)
|
||||||
*/
|
*/
|
||||||
public void startLoginActivity(Intent launch) {
|
public void startLoginActivity(Intent launch) {
|
||||||
startActivityForResult(launch, REQUEST_LOGIN); // REQUEST_LOGIN is to recognize the result
|
startActivityForResult(launch, REQUEST_LOGIN); // REQUEST_LOGIN is to recognize the result
|
||||||
|
@ -29,7 +29,7 @@ public class IITC_Settings extends Activity {
|
|||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
// exit settings when home button (iitc icon) is pressed
|
// exit settings when home button (iitc icon) is pressed
|
||||||
case android.R.id.home :
|
case android.R.id.home:
|
||||||
onBackPressed();
|
onBackPressed();
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
|
@ -6,7 +6,6 @@ import android.content.pm.PackageManager.NameNotFoundException;
|
|||||||
import android.content.res.AssetManager;
|
import android.content.res.AssetManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.preference.CheckBoxPreference;
|
|
||||||
import android.preference.EditTextPreference;
|
import android.preference.EditTextPreference;
|
||||||
import android.preference.ListPreference;
|
import android.preference.ListPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
@ -22,7 +21,7 @@ import java.util.Scanner;
|
|||||||
|
|
||||||
public class IITC_SettingsFragment extends PreferenceFragment {
|
public class IITC_SettingsFragment extends PreferenceFragment {
|
||||||
|
|
||||||
String iitc_version;
|
private String iitc_version;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
@ -58,9 +57,9 @@ public class IITC_SettingsFragment extends PreferenceFragment {
|
|||||||
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference,
|
public boolean onPreferenceChange(Preference preference,
|
||||||
Object newValue) {
|
Object newValue) {
|
||||||
preference.setSummary(getString(R.string.pref_select_iitc_sum) +
|
preference.setSummary(getString(R.string.pref_select_iitc_sum) +
|
||||||
" " + (CharSequence) newValue);
|
" " + newValue);
|
||||||
// TODO: update iitc_version when iitc source has
|
// TODO: update iitc_version when iitc source has
|
||||||
// changed
|
// changed
|
||||||
return true;
|
return true;
|
||||||
@ -88,12 +87,12 @@ public class IITC_SettingsFragment extends PreferenceFragment {
|
|||||||
e.printStackTrace();
|
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
|
// find user plugin name for user readable entries
|
||||||
Scanner s = null;
|
Scanner s = null;
|
||||||
String src = "";
|
String src = "";
|
||||||
try {
|
try {
|
||||||
s = new Scanner(am.open("plugins/" + asset_array[i]))
|
s = new Scanner(am.open("plugins/" + anAsset_array))
|
||||||
.useDelimiter("\\A");
|
.useDelimiter("\\A");
|
||||||
} catch (IOException e2) {
|
} catch (IOException e2) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
@ -102,7 +101,7 @@ public class IITC_SettingsFragment extends PreferenceFragment {
|
|||||||
if (s != null)
|
if (s != null)
|
||||||
src = s.hasNext() ? s.next() : "";
|
src = s.hasNext() ? s.next() : "";
|
||||||
// now we have all stuff together and can build the pref screen
|
// 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/
|
// load additional plugins from <storage-path>/IITC_Mobile/plugins/
|
||||||
@ -113,23 +112,24 @@ public class IITC_SettingsFragment extends PreferenceFragment {
|
|||||||
if (files != null) {
|
if (files != null) {
|
||||||
Scanner s = null;
|
Scanner s = null;
|
||||||
String src = "";
|
String src = "";
|
||||||
for (int i = 0; i < files.length; ++i) {
|
for (File file : files) {
|
||||||
try {
|
try {
|
||||||
s = new Scanner(files[i]).useDelimiter("\\A");
|
s = new Scanner(file).useDelimiter("\\A");
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Log.d("iitcm", "failed to parse file " + files[i]);
|
Log.d("iitcm", "failed to parse file " + file);
|
||||||
}
|
}
|
||||||
if (s != null)
|
if (s != null)
|
||||||
src = s.hasNext() ? s.next() : "";
|
src = s.hasNext() ? s.next() : "";
|
||||||
|
|
||||||
// now we have all stuff together and can build the pref screen
|
// 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
|
// now parse plugin name, description and category
|
||||||
String header = src.substring(src.indexOf("==UserScript=="),
|
String header = src.substring(src.indexOf("==UserScript=="),
|
||||||
|
@ -11,10 +11,10 @@ import android.os.Build;
|
|||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.webkit.GeolocationPermissions;
|
||||||
import android.webkit.WebChromeClient;
|
import android.webkit.WebChromeClient;
|
||||||
import android.webkit.WebSettings;
|
import android.webkit.WebSettings;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
import android.webkit.GeolocationPermissions;
|
|
||||||
|
|
||||||
@SuppressLint("SetJavaScriptEnabled")
|
@SuppressLint("SetJavaScriptEnabled")
|
||||||
public class IITC_WebView extends WebView {
|
public class IITC_WebView extends WebView {
|
||||||
@ -26,7 +26,7 @@ public class IITC_WebView extends WebView {
|
|||||||
|
|
||||||
// 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();
|
settings = this.getSettings();
|
||||||
settings.setJavaScriptEnabled(true);
|
settings.setJavaScriptEnabled(true);
|
||||||
settings.setDomStorageEnabled(true);
|
settings.setDomStorageEnabled(true);
|
||||||
@ -44,12 +44,12 @@ public class IITC_WebView extends WebView {
|
|||||||
this.setWebChromeClient(new WebChromeClient() {
|
this.setWebChromeClient(new WebChromeClient() {
|
||||||
/**
|
/**
|
||||||
* our webchromeclient should share geolocation with the iitc script
|
* our webchromeclient should share geolocation with the iitc script
|
||||||
*
|
*
|
||||||
* allow access by default
|
* allow access by default
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onGeolocationPermissionsShowPrompt(String origin,
|
public void onGeolocationPermissionsShowPrompt(String origin,
|
||||||
GeolocationPermissions.Callback callback) {
|
GeolocationPermissions.Callback callback) {
|
||||||
callback.invoke(origin, true, false);
|
callback.invoke(origin, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,8 +95,8 @@ public class IITC_WebView extends WebView {
|
|||||||
public void loadUrl(String url) {
|
public void loadUrl(String url) {
|
||||||
// if in edit text mode, don't load javascript otherwise the keyboard closes.
|
// if in edit text mode, don't load javascript otherwise the keyboard closes.
|
||||||
HitTestResult testResult = this.getHitTestResult();
|
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
|
// let window.show(...) interupt input
|
||||||
// window.show(...) is called if one of the action bar buttons
|
// window.show(...) is called if one of the action bar buttons
|
||||||
// is clicked
|
// is clicked
|
||||||
@ -106,7 +106,7 @@ public class IITC_WebView extends WebView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// do nothing if script is enabled;
|
// do nothing if script is enabled;
|
||||||
if (this.disableJS == true) {
|
if (this.disableJS) {
|
||||||
Log.d("iitcm", "javascript injection disabled...return");
|
Log.d("iitcm", "javascript injection disabled...return");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -152,7 +152,8 @@ public class IITC_WebView extends WebView {
|
|||||||
// is ticked as mobile hotspot or not.
|
// is ticked as mobile hotspot or not.
|
||||||
// --> IITC_WebView.isConnectedToWifi should return 'false' if connected to mobile hotspot
|
// --> IITC_WebView.isConnectedToWifi should return 'false' if connected to mobile hotspot
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
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);
|
return (wifi.getState() == NetworkInfo.State.CONNECTED);
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@ import java.io.IOException;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class IITC_WebViewClient extends WebViewClient {
|
public class IITC_WebViewClient extends WebViewClient {
|
||||||
private static final ByteArrayInputStream style = new ByteArrayInputStream(
|
private static final ByteArrayInputStream style = new ByteArrayInputStream(
|
||||||
@ -35,7 +34,7 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
private WebResourceResponse iitcjs;
|
private WebResourceResponse iitcjs;
|
||||||
private String js = null;
|
private String js = null;
|
||||||
private String iitc_path = null;
|
private String iitc_path = null;
|
||||||
Context context;
|
private final Context context;
|
||||||
|
|
||||||
public IITC_WebViewClient(Context c) {
|
public IITC_WebViewClient(Context c) {
|
||||||
this.context = c;
|
this.context = c;
|
||||||
@ -77,7 +76,7 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
js = this.fileToString(iitc_path
|
js = this.fileToString(iitc_path
|
||||||
+ "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(context, "File " + iitc_path +
|
||||||
"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();
|
||||||
@ -126,14 +125,14 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
|
|
||||||
iitcjs = new WebResourceResponse("text/javascript", "UTF-8",
|
iitcjs = new WebResourceResponse("text/javascript", "UTF-8",
|
||||||
new ByteArrayInputStream(js.getBytes()));
|
new ByteArrayInputStream(js.getBytes()));
|
||||||
};
|
}
|
||||||
|
|
||||||
// enable https
|
// enable https
|
||||||
@Override
|
@Override
|
||||||
public void onReceivedSslError(WebView view, SslErrorHandler handler,
|
public void onReceivedSslError(WebView view, SslErrorHandler handler,
|
||||||
SslError error) {
|
SslError error) {
|
||||||
handler.proceed();
|
handler.proceed();
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this method is called automatically when the Google login form is opened.
|
* this method is called automatically when the Google login form is opened.
|
||||||
@ -162,15 +161,14 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
// get the plugin preferences
|
// get the plugin preferences
|
||||||
SharedPreferences sharedPref = PreferenceManager
|
SharedPreferences sharedPref = PreferenceManager
|
||||||
.getDefaultSharedPreferences(context);
|
.getDefaultSharedPreferences(context);
|
||||||
Set<String> plugin_list = sharedPref.getStringSet("pref_plugins", null);
|
|
||||||
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();
|
||||||
|
|
||||||
// iterate through all plugins
|
// iterate through all plugins
|
||||||
for(Map.Entry<String, ?> entry : all_prefs.entrySet()){
|
for (Map.Entry<String, ?> entry : all_prefs.entrySet()) {
|
||||||
String plugin = entry.getKey();
|
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
|
// load default iitc plugins
|
||||||
if (!plugin.startsWith(iitc_path)) {
|
if (!plugin.startsWith(iitc_path)) {
|
||||||
Log.d("iitcm", "adding plugin " + plugin);
|
Log.d("iitcm", "adding plugin " + plugin);
|
||||||
@ -258,15 +256,15 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
public String removePluginWrapper(String file, boolean asset) {
|
public String removePluginWrapper(String file, boolean asset) {
|
||||||
if (!file.endsWith("user.js")) return "";
|
if (!file.endsWith("user.js")) return "";
|
||||||
String js = fileToString(file, asset);
|
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", "\n"); //convert CR-LF pairs to LF - windows format text files
|
||||||
js = js.replaceAll("\r", "\n"); //convert remaining CR to LF - Mac format files(?)
|
js = js.replaceAll("\r", "\n"); //convert remaining CR to LF - Mac format files(?)
|
||||||
String wrapper_start = "function wrapper() {";
|
String wrapper_start = "function wrapper() {";
|
||||||
String wrapper_end = "} // wrapper end";
|
String wrapper_end = "} // wrapper end";
|
||||||
String injection_code = "// inject code into site context\n" +
|
String injection_code = "// inject code into site context\n" +
|
||||||
"var script = document.createElement('script');\n" +
|
"var script = document.createElement('script');\n" +
|
||||||
"script.appendChild(document.createTextNode('('+ wrapper +')();'));\n" +
|
"script.appendChild(document.createTextNode('('+ wrapper +')();'));\n" +
|
||||||
"(document.body || document.head || document.documentElement).appendChild(script);";
|
"(document.body || document.head || document.documentElement).appendChild(script);";
|
||||||
if (js.contains(wrapper_start) && js.contains(wrapper_end) && js.contains(injection_code)) {
|
if (js.contains(wrapper_start) && js.contains(wrapper_end) && js.contains(injection_code)) {
|
||||||
js = js.replace(wrapper_start, "");
|
js = js.replace(wrapper_start, "");
|
||||||
// remove the wrapper function
|
// remove the wrapper function
|
||||||
@ -279,6 +277,7 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
}
|
}
|
||||||
return js;
|
return js;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check every external resource if it’s okay to load it and maybe replace
|
// Check every external resource if it’s okay to load it and maybe replace
|
||||||
// it
|
// it
|
||||||
// with our own content. This is used to block loading Niantic resources
|
// with our own content. This is used to block loading Niantic resources
|
||||||
@ -286,7 +285,7 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
// via http://stackoverflow.com/a/8274881/1684530
|
// via http://stackoverflow.com/a/8274881/1684530
|
||||||
@Override
|
@Override
|
||||||
public WebResourceResponse shouldInterceptRequest(final WebView view,
|
public WebResourceResponse shouldInterceptRequest(final WebView view,
|
||||||
String url) {
|
String url) {
|
||||||
if (url.contains("/css/common.css")) {
|
if (url.contains("/css/common.css")) {
|
||||||
return new WebResourceResponse("text/css", "UTF-8", style);
|
return new WebResourceResponse("text/css", "UTF-8", style);
|
||||||
} else if (url.contains("gen_dashboard.js")) {
|
} else if (url.contains("gen_dashboard.js")) {
|
||||||
|
@ -303,18 +303,12 @@
|
|||||||
// If it's a map
|
// If it's a map
|
||||||
if(typeList == 'bkmrk_maps'){
|
if(typeList == 'bkmrk_maps'){
|
||||||
if(bkmrk['label']==''){ label = bkmrk['latlng']+' ['+bkmrk['z']+']'; }
|
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>';
|
||||||
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
|
// If it's a portal
|
||||||
else if(typeList == 'bkmrk_portals'){
|
else if(typeList == 'bkmrk_portals'){
|
||||||
var guid = bkmrk['guid'];
|
var guid = bkmrk['guid'];
|
||||||
if (!window.isSmartphone())
|
var btn_link = '<a class="bookmarksLink" onclick="window.zoomToAndShowPortal(\''+guid+'\', ['+latlng+']);return false;">'+label+'</a>';
|
||||||
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
|
// Create the bookmark
|
||||||
elementTemp += '<li class="bkmrk" id="'+idBkmrk+'">'+btn_remove+btn_link+'</li>';
|
elementTemp += '<li class="bkmrk" id="'+idBkmrk+'">'+btn_remove+btn_link+'</li>';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user