Merge branch 'master' of https://github.com/jonatkins/ingress-intel-total-conversion
This commit is contained in:
commit
3d17f67e95
@ -176,3 +176,18 @@ window.useAndroidPanes = function() {
|
||||
return (typeof android !== 'undefined' && android && android.addPane && window.isSmartphone());
|
||||
}
|
||||
|
||||
if(typeof android !== 'undefined' && android && android.getFileRequestUrlPrefix) {
|
||||
window.requestFile = function(callback) {
|
||||
do {
|
||||
var funcName = "onFileSelected" + parseInt(Math.random()*0xFFFF).toString(16);
|
||||
} while(window[funcName] !== undefined)
|
||||
|
||||
window[funcName] = function(filename, content) {
|
||||
callback(decodeURIComponent(filename), atob(content));
|
||||
};
|
||||
var script = document.createElement('script');
|
||||
script.src = android.getFileRequestUrlPrefix() + funcName;
|
||||
(document.body || document.head || document.documentElement).appendChild(script);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@
|
||||
android:theme="@style/AppTheme">
|
||||
<activity
|
||||
android:name=".IITC_Mobile"
|
||||
android:configChanges="orientation|keyboard|keyboardHidden|screenSize"
|
||||
android:configChanges="orientation|keyboard|keyboardHidden|screenSize|uiMode"
|
||||
android:label="@string/app_name"
|
||||
android:launchMode="singleTop">
|
||||
<intent-filter>
|
||||
|
@ -91,7 +91,6 @@
|
||||
|
||||
<string name="pref_ui_cat">UI</string>
|
||||
<string name="pref_misc_cat">Misc</string>
|
||||
<string name="pref_developer_options_cat">Developer options</string>
|
||||
<string name="pref_tweaks_cat">Tweaks</string>
|
||||
<string name="pref_plugins">IITC Plugins</string>
|
||||
<string name="pref_plugins_title">Available plugins</string>
|
||||
@ -111,6 +110,7 @@
|
||||
<string name="pref_press_twice_to_exit">Press back button twice to exit</string>
|
||||
<string name="pref_press_twice_to_exit_sum">Avoids accidental exits</string>
|
||||
<string name="pref_advanced_options">Advanced settings</string>
|
||||
<string name="pref_advanced_options_sum">Developer options and advanced tweaks</string>
|
||||
<string name="pref_enable_dev_mode">Enable developer mode</string>
|
||||
<string name="pref_enable_dev_mode_sum">If enabled, all IITC sources will be loaded from external storage of the Android device.
|
||||
Please copy all sources from $IITC_folder/build/mobile/ to /sdcard/IITC_Mobile/dev/.</string>
|
||||
|
@ -1,16 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<PreferenceScreen
|
||||
android:key="pref_about_screen"
|
||||
android:persistent="false"
|
||||
android:title="@string/pref_about_title">
|
||||
<com.cradle.iitc_mobile.IITC_AboutDialogPreference
|
||||
android:dialogIcon="@android:drawable/ic_dialog_info"
|
||||
android:key="pref_about"
|
||||
android:title="@string/pref_about_title"/>
|
||||
</PreferenceScreen>
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="pref_ui_cat"
|
||||
android:title="@string/pref_ui_cat">
|
||||
@ -41,8 +30,8 @@
|
||||
android:title="@string/pref_force_desktop"/>
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
android:key="pref_mics"
|
||||
android:title="@string/pref_misc_cat">
|
||||
android:key="pref_tweaks_cat"
|
||||
android:title="@string/pref_tweaks_cat">
|
||||
<PreferenceScreen
|
||||
android:fragment="com.cradle.iitc_mobile.fragments.PluginsFragment"
|
||||
android:key="pref_plugins"
|
||||
@ -70,12 +59,13 @@
|
||||
android:title="@string/pref_press_twice_to_exit"/>
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
android:key="pref_developer_options"
|
||||
android:title="@string/pref_developer_options_cat">
|
||||
android:key="pref_mics"
|
||||
android:title="@string/pref_misc_cat">
|
||||
<PreferenceScreen
|
||||
android:key="pref_developer_screen"
|
||||
android:persistent="false"
|
||||
android:title="@string/pref_advanced_options">
|
||||
android:title="@string/pref_advanced_options"
|
||||
android:summary="@string/pref_advanced_options_sum">
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:key="pref_dev_checkbox"
|
||||
@ -111,6 +101,15 @@
|
||||
android:title="@string/pref_fake_user_agent"/>
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
<PreferenceScreen
|
||||
android:key="pref_about_screen"
|
||||
android:persistent="false"
|
||||
android:title="@string/pref_about_title">
|
||||
<com.cradle.iitc_mobile.IITC_AboutDialogPreference
|
||||
android:dialogIcon="@android:drawable/ic_dialog_info"
|
||||
android:key="pref_about"
|
||||
android:title="@string/pref_about_title"/>
|
||||
</PreferenceScreen>
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
@ -18,10 +18,12 @@ import android.widget.BaseAdapter;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.cradle.iitc_mobile.IITC_Mobile.ResponseHandler;
|
||||
|
||||
/**
|
||||
* this class manages automatic login using the Google account stored on the device
|
||||
*/
|
||||
public class IITC_DeviceAccountLogin implements AccountManagerCallback<Bundle> {
|
||||
public class IITC_DeviceAccountLogin implements AccountManagerCallback<Bundle>, ResponseHandler {
|
||||
/**
|
||||
* Adapter to show available accounts in a ListView. Accounts are read from mAccounts
|
||||
*/
|
||||
@ -32,21 +34,21 @@ public class IITC_DeviceAccountLogin implements AccountManagerCallback<Bundle> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Account getItem(int position) {
|
||||
public Account getItem(final int position) {
|
||||
return mAccounts[position];
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
public long getItemId(final int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
LayoutInflater inflater = mActivity.getLayoutInflater();
|
||||
View v = inflater.inflate(android.R.layout.simple_list_item_1, parent, false);
|
||||
public View getView(final int position, final View convertView, final ViewGroup parent) {
|
||||
final LayoutInflater inflater = mIitc.getLayoutInflater();
|
||||
final View v = inflater.inflate(android.R.layout.simple_list_item_1, parent, false);
|
||||
|
||||
TextView tv = (TextView) v.findViewById(android.R.id.text1);
|
||||
final TextView tv = (TextView) v.findViewById(android.R.id.text1);
|
||||
tv.setText(mAccounts[position].name);
|
||||
|
||||
return tv;
|
||||
@ -57,7 +59,7 @@ public class IITC_DeviceAccountLogin implements AccountManagerCallback<Bundle> {
|
||||
private final AccountAdapter mAccountAdapter;
|
||||
private final AccountManager mAccountManager;
|
||||
private Account[] mAccounts;
|
||||
private final IITC_Mobile mActivity;
|
||||
private final IITC_Mobile mIitc;
|
||||
private String mAuthToken;
|
||||
private final AlertDialog mProgressbar;
|
||||
private final WebView mWebView;
|
||||
@ -69,7 +71,7 @@ public class IITC_DeviceAccountLogin implements AccountManagerCallback<Bundle> {
|
||||
private final DialogInterface.OnClickListener onClickListener =
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int index) {
|
||||
public void onClick(final DialogInterface dialog, final int index) {
|
||||
if (index >= 0 && index < mAccounts.length) {
|
||||
mAccount = mAccounts[index];
|
||||
startAuthentication();
|
||||
@ -78,17 +80,17 @@ public class IITC_DeviceAccountLogin implements AccountManagerCallback<Bundle> {
|
||||
}
|
||||
};
|
||||
|
||||
public IITC_DeviceAccountLogin(IITC_Mobile activity, WebView webView,
|
||||
WebViewClient webViewClient) {
|
||||
mActivity = activity;
|
||||
public IITC_DeviceAccountLogin(final IITC_Mobile iitc, final WebView webView,
|
||||
final WebViewClient webViewClient) {
|
||||
mIitc = iitc;
|
||||
mWebView = webView;
|
||||
mAccountManager = AccountManager.get(activity);
|
||||
mAccountManager = AccountManager.get(iitc);
|
||||
mAccountAdapter = new AccountAdapter();
|
||||
|
||||
// dialog that serves as a progress bar overlay
|
||||
mProgressbar = new AlertDialog.Builder(mActivity)
|
||||
mProgressbar = new AlertDialog.Builder(mIitc)
|
||||
.setCancelable(false)
|
||||
.setView(mActivity.getLayoutInflater().inflate(R.layout.dialog_progressbar, null))
|
||||
.setView(mIitc.getLayoutInflater().inflate(R.layout.dialog_progressbar, null))
|
||||
.create();
|
||||
}
|
||||
|
||||
@ -96,20 +98,19 @@ public class IITC_DeviceAccountLogin implements AccountManagerCallback<Bundle> {
|
||||
* display all available accounts to the user
|
||||
*/
|
||||
private void displayAccountList() {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity)
|
||||
new AlertDialog.Builder(mIitc)
|
||||
.setTitle(R.string.choose_account_to_login)
|
||||
.setSingleChoiceItems(mAccountAdapter, 0, onClickListener)
|
||||
.setNegativeButton(android.R.string.cancel, onClickListener);
|
||||
|
||||
AlertDialog dialog = builder.create();
|
||||
dialog.show();
|
||||
.setNegativeButton(android.R.string.cancel, onClickListener)
|
||||
.create()
|
||||
.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* called when something failed. Shows a toast message. Classic login is still available
|
||||
*/
|
||||
private void onLoginFailed() {
|
||||
Toast.makeText(mActivity, R.string.login_failed, Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(mIitc, R.string.login_failed, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -120,16 +121,16 @@ public class IITC_DeviceAccountLogin implements AccountManagerCallback<Bundle> {
|
||||
private void startAuthentication() {
|
||||
mProgressbar.show();
|
||||
|
||||
mAccountManager.getAuthToken(mAccount, mAuthToken, null, mActivity, this, null);
|
||||
mAccountManager.getAuthToken(mAccount, mAuthToken, null, mIitc, this, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* called by IITC_Mobile when the authentication activity has finished.
|
||||
*/
|
||||
public void onActivityResult(int resultCode, Intent data) {
|
||||
if (resultCode == Activity.RESULT_OK)
|
||||
@Override
|
||||
public void onActivityResult(final int resultCode, final Intent data) {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
// authentication activity succeeded, request token again
|
||||
{
|
||||
startAuthentication();
|
||||
} else {
|
||||
onLoginFailed();
|
||||
@ -140,29 +141,29 @@ public class IITC_DeviceAccountLogin implements AccountManagerCallback<Bundle> {
|
||||
* called by AccountManager
|
||||
*/
|
||||
@Override
|
||||
public void run(AccountManagerFuture<Bundle> value) {
|
||||
public void run(final AccountManagerFuture<Bundle> value) {
|
||||
mProgressbar.hide();
|
||||
|
||||
try {
|
||||
Intent launch = (Intent) value.getResult().get(AccountManager.KEY_INTENT);
|
||||
final 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
|
||||
mActivity.startLoginActivity(launch);
|
||||
mIitc.startActivityForResult(launch, this);
|
||||
return;
|
||||
}
|
||||
|
||||
String result = value.getResult().getString(AccountManager.KEY_AUTHTOKEN);
|
||||
final String result = value.getResult().getString(AccountManager.KEY_AUTHTOKEN);
|
||||
if (result != null) {
|
||||
// authentication succeeded, we can load the given url, which will redirect
|
||||
// back to the intel map
|
||||
mWebView.loadUrl(result);
|
||||
mActivity.loginSucceeded();
|
||||
mIitc.loginSucceeded();
|
||||
} else {
|
||||
onLoginFailed();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
onLoginFailed();
|
||||
}
|
||||
}
|
||||
@ -170,21 +171,19 @@ public class IITC_DeviceAccountLogin implements AccountManagerCallback<Bundle> {
|
||||
/**
|
||||
* start authentication
|
||||
* <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.
|
||||
* 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) {
|
||||
public void startLogin(final String realm, final String accountName, final String args) {
|
||||
mAccounts = mAccountManager.getAccountsByType(realm);
|
||||
mAccountAdapter.notifyDataSetChanged();
|
||||
mAuthToken = "weblogin:" + args;
|
||||
|
||||
if (mAccounts.length == 0) {
|
||||
return;
|
||||
}
|
||||
if (mAccounts.length == 0) return;
|
||||
|
||||
for (Account account : mAccounts) {
|
||||
for (final Account account : mAccounts) {
|
||||
if (account.name.equals(accountName)) {
|
||||
mAccountManager.getAuthToken(account, mAuthToken, null, mActivity, this, null);
|
||||
mAccountManager.getAuthToken(account, mAuthToken, null, mIitc, this, null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,19 @@
|
||||
package com.cradle.iitc_mobile;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.AssetManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Environment;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Base64;
|
||||
import android.util.Base64OutputStream;
|
||||
import android.webkit.WebResourceResponse;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.cradle.iitc_mobile.IITC_Mobile.ResponseHandler;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
@ -16,7 +24,11 @@ import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PipedInputStream;
|
||||
import java.io.PipedOutputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class IITC_FileManager {
|
||||
@ -29,8 +41,38 @@ public class IITC_FileManager {
|
||||
|
||||
public static final String DOMAIN = ".iitcm.localhost";
|
||||
|
||||
public static HashMap<String, String> getScriptInfo(String js) {
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
/**
|
||||
* copies the contents of a stream into another stream and (optionally) closes the output stream afterwards
|
||||
*
|
||||
* @param inStream
|
||||
* the stream to read from
|
||||
* @param outStream
|
||||
* the stream to write to
|
||||
* @param closeOutput
|
||||
* whether to close the output stream when finished
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void copyStream(final InputStream inStream, final OutputStream outStream, final boolean closeOutput)
|
||||
throws IOException
|
||||
{
|
||||
// in case Android includes Apache commons IO in the future, this function should be replaced by IOUtils.copy
|
||||
final int bufferSize = 1024;
|
||||
final byte[] buffer = new byte[bufferSize];
|
||||
int len = 0;
|
||||
|
||||
try {
|
||||
while ((len = inStream.read(buffer)) != -1) {
|
||||
outStream.write(buffer, 0, len);
|
||||
}
|
||||
} finally {
|
||||
if (outStream != null && closeOutput)
|
||||
outStream.close();
|
||||
}
|
||||
}
|
||||
|
||||
public static HashMap<String, String> getScriptInfo(final String js) {
|
||||
final HashMap<String, String> map = new HashMap<String, String>();
|
||||
String header = "";
|
||||
if (js != null) {
|
||||
header = js.substring(js.indexOf("==UserScript=="),
|
||||
@ -39,7 +81,7 @@ public class IITC_FileManager {
|
||||
// remove new line comments
|
||||
header = header.replace("\n//", " ");
|
||||
// get a list of key-value
|
||||
String[] attributes = header.split(" +");
|
||||
final String[] attributes = header.split(" +");
|
||||
// add default values
|
||||
map.put("version", "not found");
|
||||
map.put("name", "unknown");
|
||||
@ -64,45 +106,53 @@ public class IITC_FileManager {
|
||||
return map;
|
||||
}
|
||||
|
||||
private AssetManager mAssetManager;
|
||||
private IITC_Mobile mIitc;
|
||||
private String mIitcPath;
|
||||
private final AssetManager mAssetManager;
|
||||
private final IITC_Mobile mIitc;
|
||||
private final String mIitcPath;
|
||||
private final SharedPreferences mPrefs;
|
||||
|
||||
private SharedPreferences mPrefs;
|
||||
|
||||
public IITC_FileManager(IITC_Mobile iitc) {
|
||||
public IITC_FileManager(final IITC_Mobile iitc) {
|
||||
mIitc = iitc;
|
||||
mIitcPath = Environment.getExternalStorageDirectory().getPath() + "/IITC_Mobile/";
|
||||
mPrefs = PreferenceManager.getDefaultSharedPreferences(iitc);
|
||||
mAssetManager = mIitc.getAssets();
|
||||
}
|
||||
|
||||
private InputStream getAssetFile(String filename) throws IOException {
|
||||
private InputStream getAssetFile(final String filename) throws IOException {
|
||||
if (mPrefs.getBoolean("pref_dev_checkbox", false)) {
|
||||
File file = new File(mIitcPath + "dev/" + filename);
|
||||
final File file = new File(mIitcPath + "dev/" + filename);
|
||||
try {
|
||||
return new FileInputStream(file);
|
||||
} catch (FileNotFoundException e) {
|
||||
} catch (final FileNotFoundException e) {
|
||||
mIitc.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(mIitc, "File " + mIitcPath +
|
||||
"dev/" + filename + " not found. " +
|
||||
"Disable developer mode or add iitc files to the dev folder.",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
Log.w(e);
|
||||
}
|
||||
}
|
||||
|
||||
String source = mPrefs.getString("pref_iitc_source", "local");
|
||||
final String source = mPrefs.getString("pref_iitc_source", "local");
|
||||
if (!source.equals("local")) {
|
||||
// load iitc script from web or asset folder
|
||||
if (source.contains("http")) {
|
||||
try {
|
||||
URL context = new URL(source);
|
||||
URL url = new URL(context, filename);
|
||||
final URL context = new URL(source);
|
||||
final URL url = new URL(context, filename);
|
||||
return url.openStream();
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
Log.w(e);
|
||||
}
|
||||
} else {
|
||||
File file = new File(source + File.separatorChar + filename);
|
||||
final File file = new File(source + File.separatorChar + filename);
|
||||
try {
|
||||
return new FileInputStream(file);
|
||||
} catch (FileNotFoundException e) {
|
||||
} catch (final FileNotFoundException e) {
|
||||
Log.w(e);
|
||||
}
|
||||
}
|
||||
@ -112,25 +162,29 @@ public class IITC_FileManager {
|
||||
return mAssetManager.open(filename);
|
||||
}
|
||||
|
||||
private WebResourceResponse getScript(Uri uri) {
|
||||
private WebResourceResponse getFileRequest(final Uri uri) {
|
||||
return new FileRequest(uri);
|
||||
}
|
||||
|
||||
private WebResourceResponse getScript(final Uri uri) {
|
||||
InputStream stream;
|
||||
try {
|
||||
stream = getAssetFile(uri.getPath().substring(1));
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
Log.w(e);
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
InputStream data = prepareUserScript(stream);
|
||||
final InputStream data = prepareUserScript(stream);
|
||||
|
||||
return new WebResourceResponse("application/x-javascript", "UTF-8", data);
|
||||
}
|
||||
|
||||
private HashMap<String, String> getScriptInfo(InputStream stream) {
|
||||
private HashMap<String, String> getScriptInfo(final InputStream stream) {
|
||||
return getScriptInfo(readStream(stream));
|
||||
}
|
||||
|
||||
private WebResourceResponse getUserPlugin(Uri uri) {
|
||||
private WebResourceResponse getUserPlugin(final Uri uri) {
|
||||
if (!mPrefs.getBoolean(uri.getPath(), false)) {
|
||||
Log.e("Attempted to inject user script that is not enabled by user: " + uri.getPath());
|
||||
return EMPTY;
|
||||
@ -139,53 +193,57 @@ public class IITC_FileManager {
|
||||
InputStream stream;
|
||||
try {
|
||||
stream = new FileInputStream(new File(uri.getPath()));
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
Log.w(e);
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
InputStream data = prepareUserScript(stream);
|
||||
final InputStream data = prepareUserScript(stream);
|
||||
|
||||
return new WebResourceResponse("application/x-javascript", "UTF-8", data);
|
||||
}
|
||||
|
||||
private InputStream prepareUserScript(InputStream stream) {
|
||||
private InputStream prepareUserScript(final InputStream stream) {
|
||||
String content = readStream(stream);
|
||||
HashMap<String, String> info = getScriptInfo(content);
|
||||
final HashMap<String, String> info = getScriptInfo(content);
|
||||
|
||||
JSONObject jObject = new JSONObject(info);
|
||||
String gmInfo = "var GM_info={\"script\":" + jObject.toString() + "}";
|
||||
final JSONObject jObject = new JSONObject(info);
|
||||
final String gmInfo = "var GM_info={\"script\":" + jObject.toString() + "}";
|
||||
|
||||
content = content.replace(WRAPPER_OLD, WRAPPER_NEW);
|
||||
|
||||
return new ByteArrayInputStream((gmInfo + content).getBytes());
|
||||
}
|
||||
|
||||
private String readStream(InputStream stream) {
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[4096];
|
||||
private String readStream(final InputStream stream) {
|
||||
final ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
final byte[] buffer = new byte[4096];
|
||||
|
||||
try {
|
||||
while (true) {
|
||||
int read = stream.read(buffer);
|
||||
final int read = stream.read(buffer);
|
||||
if (read == -1)
|
||||
break;
|
||||
os.write(buffer, 0, read);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
Log.w(e);
|
||||
return "";
|
||||
}
|
||||
return os.toString();
|
||||
}
|
||||
|
||||
public String getFileRequestPrefix() {
|
||||
return "//file-request" + DOMAIN + "/";
|
||||
}
|
||||
|
||||
public String getIITCVersion() throws IOException {
|
||||
InputStream stream = getAssetFile("total-conversion-build.user.js");
|
||||
final InputStream stream = getAssetFile("total-conversion-build.user.js");
|
||||
|
||||
return getScriptInfo(stream).get("version");
|
||||
}
|
||||
|
||||
public WebResourceResponse getResponse(Uri uri) {
|
||||
public WebResourceResponse getResponse(final Uri uri) {
|
||||
String host = uri.getHost();
|
||||
if (!host.endsWith(DOMAIN))
|
||||
return EMPTY;
|
||||
@ -196,8 +254,88 @@ public class IITC_FileManager {
|
||||
return getScript(uri);
|
||||
if ("user-plugin".equals(host))
|
||||
return getUserPlugin(uri);
|
||||
if ("file-request".equals(host))
|
||||
return getFileRequest(uri);
|
||||
|
||||
Log.e("could not generate response for url: " + uri);
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
private class FileRequest extends WebResourceResponse implements ResponseHandler, Runnable {
|
||||
private Intent mData;
|
||||
private final String mFunctionName;
|
||||
private int mResultCode;
|
||||
private PipedOutputStream mStreamOut;
|
||||
|
||||
private FileRequest(final Uri uri) {
|
||||
// create two connected streams we can write to after the file has been read
|
||||
super("application/x-javascript", "UTF-8", new PipedInputStream());
|
||||
|
||||
try {
|
||||
mStreamOut = new PipedOutputStream((PipedInputStream) getData());
|
||||
} catch (final IOException e) {
|
||||
Log.w(e);
|
||||
}
|
||||
|
||||
// the function to call
|
||||
mFunctionName = uri.getPathSegments().get(0);
|
||||
|
||||
// create the chooser Intent
|
||||
final Intent target = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
target.setType("file/*");
|
||||
target.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
|
||||
try {
|
||||
mIitc.startActivityForResult(Intent.createChooser(target, "Choose file"), this);
|
||||
} catch (final ActivityNotFoundException e) {
|
||||
Toast.makeText(mIitc, "No activity to select a file found." +
|
||||
"Please install a file browser of your choice!", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(final int resultCode, final Intent data) {
|
||||
mIitc.deleteResponseHandler(this); // to enable garbage collection
|
||||
|
||||
mResultCode = resultCode;
|
||||
mData = data;
|
||||
|
||||
// read file in new thread using Runnable interface, see run()
|
||||
new Thread(this, "FileRequestReader").start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (mResultCode == Activity.RESULT_OK && mData != null) {
|
||||
final Uri uri = mData.getData();
|
||||
final File file = new File(uri.getPath());
|
||||
|
||||
// now create a resource that basically looks like:
|
||||
// someFunctionName('<url encoded filename>', '<base64 encoded content>');
|
||||
|
||||
mStreamOut.write(
|
||||
(mFunctionName + "('" + URLEncoder.encode(file.getName(), "UTF-8") + "', '").getBytes());
|
||||
|
||||
final Base64OutputStream encoder =
|
||||
new Base64OutputStream(mStreamOut, Base64.NO_CLOSE | Base64.NO_WRAP | Base64.DEFAULT);
|
||||
|
||||
final FileInputStream fileinput = new FileInputStream(file);
|
||||
|
||||
copyStream(fileinput, encoder, true);
|
||||
|
||||
mStreamOut.write("');".getBytes());
|
||||
}
|
||||
|
||||
} catch (final IOException e) {
|
||||
Log.w(e);
|
||||
} finally {
|
||||
// try to close stream, but ignore errors
|
||||
try {
|
||||
mStreamOut.close();
|
||||
} catch (final IOException e1) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -224,4 +224,9 @@ public class IITC_JSInterface {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public String getFileRequestUrlPrefix() {
|
||||
return mIitc.getFileManager().getFileRequestPrefix();
|
||||
}
|
||||
}
|
||||
|
@ -42,10 +42,9 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Stack;
|
||||
import java.util.Vector;
|
||||
|
||||
public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeListener {
|
||||
|
||||
private static final int REQUEST_LOGIN = 1;
|
||||
private static final String mIntelUrl = "https://www.ingress.com/intel";
|
||||
|
||||
private SharedPreferences mSharedPrefs;
|
||||
@ -55,6 +54,7 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
private IITC_NavigationHelper mNavigationHelper;
|
||||
private IITC_MapSettings mMapSettings;
|
||||
private IITC_DeviceAccountLogin mLogin;
|
||||
private final Vector<ResponseHandler> mResponseHandlers = new Vector<ResponseHandler>();
|
||||
private boolean mDesktopMode = false;
|
||||
private boolean mAdvancedMenu = false;
|
||||
private MenuItem mSearchMenuItem;
|
||||
@ -76,13 +76,13 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
|
||||
private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
public void onReceive(final Context context, final Intent intent) {
|
||||
((IITC_Mobile) context).installIitcUpdate();
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// enable progress bar above action bar
|
||||
@ -97,11 +97,11 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
mEditCommand = (EditText) findViewById(R.id.editCommand);
|
||||
mEditCommand.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||
@Override
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
public boolean onEditorAction(final TextView v, final int actionId, final KeyEvent event) {
|
||||
if (EditorInfo.IME_ACTION_GO == actionId) {
|
||||
onBtnRunCodeClick(v);
|
||||
|
||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
||||
|
||||
return true;
|
||||
@ -146,12 +146,12 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences, final String key) {
|
||||
if (key.equals("pref_force_desktop")) {
|
||||
mDesktopMode = sharedPreferences.getBoolean("pref_force_desktop", false);
|
||||
mNavigationHelper.onPrefChanged();
|
||||
} else if (key.equals("pref_user_location_mode")) {
|
||||
int mode = Integer.parseInt(mSharedPrefs.getString("pref_user_location_mode", "0"));
|
||||
final int mode = Integer.parseInt(mSharedPrefs.getString("pref_user_location_mode", "0"));
|
||||
if (mUserLocation.setLocationMode(mode))
|
||||
mReloadNeeded = true;
|
||||
return;
|
||||
@ -179,23 +179,23 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
protected void onNewIntent(final Intent intent) {
|
||||
setIntent(intent);
|
||||
handleIntent(intent, false);
|
||||
}
|
||||
|
||||
private void handleIntent(Intent intent, boolean onCreate) {
|
||||
private void handleIntent(final Intent intent, final boolean onCreate) {
|
||||
// load new iitc web view with ingress intel page
|
||||
String action = intent.getAction();
|
||||
final String action = intent.getAction();
|
||||
if (Intent.ACTION_VIEW.equals(action)) {
|
||||
Uri uri = intent.getData();
|
||||
final Uri uri = intent.getData();
|
||||
Log.d("intent received url: " + uri.toString());
|
||||
|
||||
if (uri.getScheme().equals("http") || uri.getScheme().equals("https")) {
|
||||
if (uri.getHost() != null
|
||||
&& (uri.getHost().equals("ingress.com") || uri.getHost().endsWith(".ingress.com"))) {
|
||||
Log.d("loading url...");
|
||||
this.loadUrl(uri.toString());
|
||||
loadUrl(uri.toString());
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -204,14 +204,14 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
try {
|
||||
handleGeoUri(uri);
|
||||
return;
|
||||
} catch (URISyntaxException e) {
|
||||
} catch (final URISyntaxException e) {
|
||||
Log.w(e);
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle(R.string.intent_error)
|
||||
.setMessage(e.getReason())
|
||||
.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
public void onClick(final DialogInterface dialog, final int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
})
|
||||
@ -235,38 +235,37 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
}
|
||||
|
||||
if (onCreate) {
|
||||
this.loadUrl(mIntelUrl);
|
||||
loadUrl(mIntelUrl);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleGeoUri(Uri uri) throws URISyntaxException {
|
||||
String[] parts = uri.getSchemeSpecificPart().split("\\?", 2);
|
||||
private void handleGeoUri(final Uri uri) throws URISyntaxException {
|
||||
final String[] parts = uri.getSchemeSpecificPart().split("\\?", 2);
|
||||
Double lat, lon;
|
||||
Integer z = null;
|
||||
|
||||
// parts[0] may contain an 'uncertainty' parameter, delimited by a semicolon
|
||||
String[] pos = parts[0].split(";", 2)[0].split(",", 2);
|
||||
if (pos.length != 2) {
|
||||
throw new URISyntaxException(uri.toString(), "URI does not contain a valid position");
|
||||
}
|
||||
final String[] pos = parts[0].split(";", 2)[0].split(",", 2);
|
||||
if (pos.length != 2) throw new URISyntaxException(uri.toString(), "URI does not contain a valid position");
|
||||
|
||||
try {
|
||||
lat = Double.valueOf(pos[0]);
|
||||
lon = Double.valueOf(pos[1]);
|
||||
} catch (NumberFormatException e) {
|
||||
URISyntaxException use = new URISyntaxException(uri.toString(), "position could not be parsed");
|
||||
} catch (final NumberFormatException e) {
|
||||
final URISyntaxException use = new URISyntaxException(uri.toString(), "position could not be parsed");
|
||||
use.initCause(e);
|
||||
throw use;
|
||||
}
|
||||
|
||||
if (parts.length > 1) { // query string present
|
||||
// search for z=
|
||||
for (String param : parts[1].split("&")) {
|
||||
for (final String param : parts[1].split("&")) {
|
||||
if (param.startsWith("z=")) {
|
||||
try {
|
||||
z = Integer.valueOf(param.substring(2));
|
||||
} catch (NumberFormatException e) {
|
||||
URISyntaxException use = new URISyntaxException(uri.toString(), "could not parse zoom level");
|
||||
} catch (final NumberFormatException e) {
|
||||
final URISyntaxException use = new URISyntaxException(
|
||||
uri.toString(), "could not parse zoom level");
|
||||
use.initCause(e);
|
||||
throw use;
|
||||
}
|
||||
@ -279,7 +278,7 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
if (z != null) {
|
||||
url += "&z=" + z;
|
||||
}
|
||||
this.loadUrl(url);
|
||||
loadUrl(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -330,7 +329,7 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
public void onConfigurationChanged(final Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
|
||||
mNavigationHelper.onConfigurationChanged(newConfig);
|
||||
@ -341,7 +340,7 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostCreate(Bundle savedInstanceState) {
|
||||
protected void onPostCreate(final Bundle savedInstanceState) {
|
||||
super.onPostCreate(savedInstanceState);
|
||||
mNavigationHelper.onPostCreate(savedInstanceState);
|
||||
}
|
||||
@ -363,7 +362,7 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
|
||||
// kill all open iitc dialogs
|
||||
if (!mDialogStack.isEmpty()) {
|
||||
String id = mDialogStack.pop();
|
||||
final String id = mDialogStack.pop();
|
||||
mIitcWebView.loadUrl("javascript: " +
|
||||
"var selector = $(window.DIALOGS['" + id + "']); " +
|
||||
"selector.dialog('close'); " +
|
||||
@ -400,16 +399,18 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
mBackStack.push(Pane.MAP);
|
||||
}
|
||||
|
||||
Pane pane = mBackStack.pop();
|
||||
final Pane pane = mBackStack.pop();
|
||||
switchToPane(pane);
|
||||
}
|
||||
|
||||
public void setCurrentPane(Pane pane) {
|
||||
public void setCurrentPane(final Pane pane) {
|
||||
// ensure no double adds
|
||||
if (pane == mCurrentPane) return;
|
||||
|
||||
// map pane is top-lvl. clear stack.
|
||||
if (pane == Pane.MAP) mBackStack.clear();
|
||||
if (pane == Pane.MAP) {
|
||||
mBackStack.clear();
|
||||
}
|
||||
// don't push current pane to backstack if this method was called via back button
|
||||
else if (!mBackButtonPressed) mBackStack.push(mCurrentPane);
|
||||
|
||||
@ -418,16 +419,16 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
mNavigationHelper.switchTo(pane);
|
||||
}
|
||||
|
||||
public void switchToPane(Pane pane) {
|
||||
public void switchToPane(final Pane pane) {
|
||||
mIitcWebView.loadUrl("javascript: window.show('" + pane.name + "');");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
public boolean onCreateOptionsMenu(final Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.main, menu);
|
||||
// Get the SearchView and set the searchable configuration
|
||||
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
|
||||
final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
|
||||
mSearchMenuItem = menu.findItem(R.id.menu_search);
|
||||
final SearchView searchView =
|
||||
(SearchView) mSearchMenuItem.getActionView();
|
||||
@ -438,13 +439,13 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
public boolean onPrepareOptionsMenu(final Menu menu) {
|
||||
boolean visible = false;
|
||||
if (mNavigationHelper != null)
|
||||
visible = !mNavigationHelper.isDrawerOpened();
|
||||
|
||||
for (int i = 0; i < menu.size(); i++) {
|
||||
MenuItem item = menu.getItem(i);
|
||||
final MenuItem item = menu.getItem(i);
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_settings:
|
||||
@ -476,10 +477,8 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (mNavigationHelper.onOptionsItemSelected(item)) {
|
||||
return true;
|
||||
}
|
||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||
if (mNavigationHelper.onOptionsItemSelected(item)) return true;
|
||||
|
||||
// Handle item selection
|
||||
final int itemId = item.getItemId();
|
||||
@ -509,17 +508,17 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
}
|
||||
return true;
|
||||
case R.id.action_settings: // start settings activity
|
||||
Intent intent = new Intent(this, IITC_PreferenceActivity.class);
|
||||
final Intent intent = new Intent(this, IITC_PreferenceActivity.class);
|
||||
try {
|
||||
intent.putExtra("iitc_version", mFileManager.getIITCVersion());
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
Log.w(e);
|
||||
return true;
|
||||
}
|
||||
startActivity(intent);
|
||||
return true;
|
||||
case R.id.menu_clear_cookies:
|
||||
CookieManager cm = CookieManager.getInstance();
|
||||
final CookieManager cm = CookieManager.getInstance();
|
||||
cm.removeAllCookie();
|
||||
return true;
|
||||
case R.id.menu_debug:
|
||||
@ -552,7 +551,7 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
}
|
||||
|
||||
// vp=f enables mDesktopMode mode...vp=m is the default mobile view
|
||||
private String addUrlParam(String url) {
|
||||
private String addUrlParam(final String url) {
|
||||
if (mDesktopMode) {
|
||||
return (url + "?vp=f");
|
||||
} else {
|
||||
@ -569,25 +568,35 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
}
|
||||
|
||||
public IITC_WebView getWebView() {
|
||||
return this.mIitcWebView;
|
||||
return mIitcWebView;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
public void startActivityForResult(final Intent launch, final ResponseHandler handler) {
|
||||
int index = mResponseHandlers.indexOf(handler);
|
||||
if (index == -1) {
|
||||
mResponseHandlers.add(handler);
|
||||
index = mResponseHandlers.indexOf(handler);
|
||||
}
|
||||
|
||||
startActivityForResult(launch, RESULT_FIRST_USER + index);
|
||||
}
|
||||
|
||||
public void deleteResponseHandler(final ResponseHandler handler) {
|
||||
final int index = mResponseHandlers.indexOf(handler);
|
||||
if (index != -1) {
|
||||
// set value to null to enable garbage collection, but don't remove it to keep indexes
|
||||
mResponseHandlers.set(index, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
switch (requestCode) {
|
||||
case REQUEST_LOGIN:
|
||||
// authentication activity has returned. mLogin will continue authentication
|
||||
mLogin.onActivityResult(resultCode, data);
|
||||
break;
|
||||
default:
|
||||
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
|
||||
final int index = requestCode - RESULT_FIRST_USER;
|
||||
|
||||
try {
|
||||
final ResponseHandler handler = mResponseHandlers.get(index);
|
||||
handler.onActivityResult(resultCode, data);
|
||||
} catch (final ArrayIndexOutOfBoundsException e) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
}
|
||||
@ -595,8 +604,8 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
/**
|
||||
* called by IITC_WebViewClient when the Google login form is opened.
|
||||
*/
|
||||
public void onReceivedLoginRequest(IITC_WebViewClient client, WebView view,
|
||||
String realm, String account, String args) {
|
||||
public void onReceivedLoginRequest(final IITC_WebViewClient client, final WebView view, final String realm,
|
||||
final String account, final String args) {
|
||||
mLogin = new IITC_DeviceAccountLogin(this, view, client);
|
||||
mLogin.startLogin(realm, account, args);
|
||||
}
|
||||
@ -613,14 +622,14 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
// remove dialog and add it back again
|
||||
// to ensure it is the last element of the list
|
||||
// focused dialogs should be closed first
|
||||
public void setFocusedDialog(String id) {
|
||||
public void setFocusedDialog(final String id) {
|
||||
Log.d("Dialog " + id + " focused");
|
||||
mDialogStack.remove(id);
|
||||
mDialogStack.push(id);
|
||||
}
|
||||
|
||||
// called by the javascript interface
|
||||
public void dialogOpened(String id, boolean open) {
|
||||
public void dialogOpened(final String id, final boolean open) {
|
||||
if (open) {
|
||||
Log.d("Dialog " + id + " added");
|
||||
mDialogStack.push(id);
|
||||
@ -630,7 +639,7 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
}
|
||||
}
|
||||
|
||||
public void setLoadingState(boolean isLoading) {
|
||||
public void setLoadingState(final boolean isLoading) {
|
||||
mIsLoading = isLoading;
|
||||
|
||||
mNavigationHelper.onLoadingStateChanged();
|
||||
@ -652,7 +661,7 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
}
|
||||
} else {
|
||||
// if the debug container is invisible (and we are about to show it), select the text box
|
||||
boolean select = mViewDebug.getVisibility() != View.VISIBLE;
|
||||
final boolean select = mViewDebug.getVisibility() != View.VISIBLE;
|
||||
|
||||
mImageLoading.setVisibility(View.GONE); // never show splash screen while debugging
|
||||
mViewDebug.setVisibility(View.VISIBLE);
|
||||
@ -674,18 +683,18 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
}
|
||||
}
|
||||
|
||||
public void onBtnRunCodeClick(View v) {
|
||||
String code = mEditCommand.getText().toString();
|
||||
JSONObject obj = new JSONObject();
|
||||
public void onBtnRunCodeClick(final View v) {
|
||||
final String code = mEditCommand.getText().toString();
|
||||
final JSONObject obj = new JSONObject();
|
||||
try {
|
||||
obj.put("code", code);
|
||||
} catch (JSONException e) {
|
||||
} catch (final JSONException e) {
|
||||
Log.w(e);
|
||||
return;
|
||||
}
|
||||
|
||||
// throwing an exception will be reported by WebView
|
||||
String js = "(function(obj){var result;" +
|
||||
final String js = "(function(obj){var result;" +
|
||||
"console.log('>>> ' + obj.code);" +
|
||||
"try{result=eval(obj.code);}catch(e){if(e.stack) console.error(e.stack);throw e;}" +
|
||||
"if(result!==undefined) console.log(result.toString());" +
|
||||
@ -697,34 +706,34 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
/**
|
||||
* onClick handler for R.id.btnToggleMapVisibility, assigned in activity_main.xml
|
||||
*/
|
||||
public void onToggleMapVisibility(View v)
|
||||
public void onToggleMapVisibility(final View v)
|
||||
{
|
||||
mShowMapInDebug = !mShowMapInDebug;
|
||||
updateViews();
|
||||
}
|
||||
|
||||
private void deleteUpdateFile() {
|
||||
File file = new File(getExternalFilesDir(null).toString() + "/iitcUpdate.apk");
|
||||
final File file = new File(getExternalFilesDir(null).toString() + "/iitcUpdate.apk");
|
||||
if (file != null) file.delete();
|
||||
}
|
||||
|
||||
public void updateIitc(String url) {
|
||||
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
|
||||
public void updateIitc(final String url) {
|
||||
final DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
|
||||
request.setDescription(getString(R.string.download_description));
|
||||
request.setTitle("IITCm Update");
|
||||
request.allowScanningByMediaScanner();
|
||||
Uri fileUri = Uri.parse("file://" + getExternalFilesDir(null).toString() + "/iitcUpdate.apk");
|
||||
final Uri fileUri = Uri.parse("file://" + getExternalFilesDir(null).toString() + "/iitcUpdate.apk");
|
||||
request.setDestinationUri(fileUri);
|
||||
// remove old update file...we don't want to spam the external storage
|
||||
deleteUpdateFile();
|
||||
// get download service and enqueue file
|
||||
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
|
||||
final DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
|
||||
manager.enqueue(request);
|
||||
}
|
||||
|
||||
private void installIitcUpdate() {
|
||||
String iitcUpdatePath = getExternalFilesDir(null).toString() + "/iitcUpdate.apk";
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
final String iitcUpdatePath = getExternalFilesDir(null).toString() + "/iitcUpdate.apk";
|
||||
final Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setDataAndType(Uri.fromFile(new File(iitcUpdatePath)), "application/vnd.android.package-archive");
|
||||
startActivity(intent);
|
||||
// finish app, because otherwise it gets killed on update
|
||||
@ -764,4 +773,8 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
public IITC_UserLocation getUserLocation() {
|
||||
return mUserLocation;
|
||||
}
|
||||
|
||||
public interface ResponseHandler {
|
||||
void onActivityResult(int resultCode, Intent data);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,6 @@
|
||||
package com.cradle.iitc_mobile;
|
||||
|
||||
import android.app.ActionBar;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.content.DialogInterface.OnDismissListener;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
@ -12,15 +8,12 @@ import android.os.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.ActionBarDrawerToggle;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.text.Html;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
@ -51,17 +44,17 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnIt
|
||||
private Pane mPane = Pane.MAP;
|
||||
private String mHighlighter = null;
|
||||
|
||||
public IITC_NavigationHelper(IITC_Mobile activity, ActionBar bar) {
|
||||
super(activity, (DrawerLayout) activity.findViewById(R.id.drawer_layout),
|
||||
public IITC_NavigationHelper(final IITC_Mobile iitc, final ActionBar bar) {
|
||||
super(iitc, (DrawerLayout) iitc.findViewById(R.id.drawer_layout),
|
||||
R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close);
|
||||
|
||||
mIitc = activity;
|
||||
mIitc = iitc;
|
||||
mActionBar = bar;
|
||||
mDrawerLeft = (ListView) activity.findViewById(R.id.left_drawer);
|
||||
mDrawerRight = activity.findViewById(R.id.right_drawer);
|
||||
mDrawerLayout = (DrawerLayout) activity.findViewById(R.id.drawer_layout);
|
||||
mDrawerLeft = (ListView) iitc.findViewById(R.id.left_drawer);
|
||||
mDrawerRight = iitc.findViewById(R.id.right_drawer);
|
||||
mDrawerLayout = (DrawerLayout) iitc.findViewById(R.id.drawer_layout);
|
||||
|
||||
mPrefs = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||
mPrefs = PreferenceManager.getDefaultSharedPreferences(iitc);
|
||||
|
||||
mActionBar.setDisplayShowHomeEnabled(true); // show icon
|
||||
|
||||
@ -78,7 +71,7 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnIt
|
||||
}
|
||||
|
||||
private void updateViews() {
|
||||
int position = mNavigationAdapter.getPosition(mPane);
|
||||
final int position = mNavigationAdapter.getPosition(mPane);
|
||||
if (position >= 0 && position < mNavigationAdapter.getCount()) {
|
||||
mDrawerLeft.setItemChecked(position, true);
|
||||
} else {
|
||||
@ -117,7 +110,7 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnIt
|
||||
}
|
||||
}
|
||||
|
||||
boolean mapVisible = mDesktopMode || mPane == Pane.MAP;
|
||||
final boolean mapVisible = mDesktopMode || mPane == Pane.MAP;
|
||||
if ("No Highlights".equals(mHighlighter) || isDrawerOpened() || mIitc.isLoading() || !mapVisible) {
|
||||
mActionBar.setSubtitle(null);
|
||||
} else {
|
||||
@ -125,11 +118,11 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnIt
|
||||
}
|
||||
}
|
||||
|
||||
public void addPane(String name, String label, String icon) {
|
||||
public void addPane(final String name, final String label, final String icon) {
|
||||
mNotificationHelper.showNotice(IITC_NotificationHelper.NOTICE_PANES);
|
||||
|
||||
Resources res = mIitc.getResources();
|
||||
String packageName = res.getResourcePackageName(R.string.app_name);
|
||||
final Resources res = mIitc.getResources();
|
||||
final String packageName = res.getResourcePackageName(R.string.app_name);
|
||||
/*
|
||||
* since the package name is overridden in test builds
|
||||
* we can't use context.getPackageName() to get the package name
|
||||
@ -137,7 +130,7 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnIt
|
||||
* so we have to retrieve the package name of another resource with Resources.getResourcePackageName()
|
||||
* see http://www.piwai.info/renaming-android-manifest-package/
|
||||
*/
|
||||
int resId = mIitc.getResources().getIdentifier(icon, "drawable", packageName);
|
||||
final int resId = mIitc.getResources().getIdentifier(icon, "drawable", packageName);
|
||||
mNavigationAdapter.add(new Pane(name, label, resId));
|
||||
}
|
||||
|
||||
@ -145,9 +138,9 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnIt
|
||||
mDrawerLayout.closeDrawers();
|
||||
}
|
||||
|
||||
public Pane getPane(String id) {
|
||||
public Pane getPane(final String id) {
|
||||
for (int i = 0; i < mNavigationAdapter.getCount(); i++) {
|
||||
Pane pane = mNavigationAdapter.getItem(i);
|
||||
final Pane pane = mNavigationAdapter.getItem(i);
|
||||
if (pane.name.equals(id))
|
||||
return pane;
|
||||
}
|
||||
@ -163,7 +156,7 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnIt
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDrawerClosed(View drawerView) {
|
||||
public void onDrawerClosed(final View drawerView) {
|
||||
super.onDrawerClosed(drawerView);
|
||||
|
||||
mIitc.getWebView().onWindowFocusChanged(true);
|
||||
@ -178,7 +171,7 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnIt
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDrawerOpened(View drawerView) {
|
||||
public void onDrawerOpened(final View drawerView) {
|
||||
super.onDrawerOpened(drawerView);
|
||||
mIitc.getWebView().onWindowFocusChanged(false);
|
||||
mIitc.invalidateOptionsMenu();
|
||||
@ -187,8 +180,8 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnIt
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
Pane item = mNavigationAdapter.getItem(position);
|
||||
public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) {
|
||||
final Pane item = mNavigationAdapter.getItem(position);
|
||||
mIitc.switchToPane(item);
|
||||
|
||||
if (item == Pane.INFO) {
|
||||
@ -203,7 +196,7 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnIt
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
mDrawerLayout.closeDrawer(mDrawerRight);
|
||||
}
|
||||
@ -211,7 +204,7 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnIt
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
public void onPostCreate(Bundle savedInstanceState) {
|
||||
public void onPostCreate(final Bundle savedInstanceState) {
|
||||
// Sync the toggle state after onRestoreInstanceState has occurred.
|
||||
syncState();
|
||||
}
|
||||
@ -233,11 +226,11 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnIt
|
||||
updateViews();
|
||||
}
|
||||
|
||||
public void setDebugMode(boolean enabled) {
|
||||
public void setDebugMode(final boolean enabled) {
|
||||
mNavigationAdapter.reset();
|
||||
}
|
||||
|
||||
public void setHighlighter(String name) {
|
||||
public void setHighlighter(final String name) {
|
||||
mHighlighter = name;
|
||||
updateViews();
|
||||
}
|
||||
@ -246,7 +239,7 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnIt
|
||||
mActionBar.show();
|
||||
}
|
||||
|
||||
public void switchTo(Pane pane) {
|
||||
public void switchTo(final Pane pane) {
|
||||
mPane = pane;
|
||||
|
||||
updateViews();
|
||||
@ -260,9 +253,9 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnIt
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
TextView view = (TextView) super.getView(position, convertView, parent);
|
||||
Pane item = getItem(position);
|
||||
public View getView(final int position, final View convertView, final ViewGroup parent) {
|
||||
final TextView view = (TextView) super.getView(position, convertView, parent);
|
||||
final Pane item = getItem(position);
|
||||
view.setText(item.label);
|
||||
|
||||
if (item.icon != 0) {
|
||||
@ -291,22 +284,22 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnIt
|
||||
public static final Pane MAP = new Pane("map", "Map", R.drawable.ic_action_map);
|
||||
public static final Pane PUBLIC = new Pane("public", "Public", R.drawable.ic_action_group);
|
||||
|
||||
private int icon;
|
||||
private final int icon;
|
||||
public String label;
|
||||
public String name;
|
||||
|
||||
public Pane(String name, String label, int icon) {
|
||||
public Pane(final String name, final String label, final int icon) {
|
||||
this.name = name;
|
||||
this.label = label;
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
public boolean equals(final Object o) {
|
||||
if (o == null) return false;
|
||||
if (o.getClass() != getClass()) return false;
|
||||
|
||||
Pane pane = (Pane) o;
|
||||
final Pane pane = (Pane) o;
|
||||
return name.equals(pane.name);
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ public class IITC_NotificationHelper {
|
||||
private final SharedPreferences mPrefs;
|
||||
private int mDialogs = 0;
|
||||
|
||||
public IITC_NotificationHelper(Activity activity) {
|
||||
public IITC_NotificationHelper(final Activity activity) {
|
||||
mActivity = activity;
|
||||
mPrefs = PreferenceManager.getDefaultSharedPreferences(mActivity);
|
||||
}
|
||||
@ -45,30 +45,31 @@ public class IITC_NotificationHelper {
|
||||
break;
|
||||
case NOTICE_EXTPLUGINS:
|
||||
text = mActivity.getString(R.string.notice_extplugins);
|
||||
text = String.format(text, Environment.getExternalStorageDirectory().getPath() + "/IITC_Mobile/plugins/");
|
||||
text = String.format(text, Environment.getExternalStorageDirectory().getPath()
|
||||
+ "/IITC_Mobile/plugins/");
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
final View content = mActivity.getLayoutInflater().inflate(R.layout.dialog_notice, null);
|
||||
TextView message = (TextView) content.findViewById(R.id.tv_notice);
|
||||
final TextView message = (TextView) content.findViewById(R.id.tv_notice);
|
||||
message.setText(Html.fromHtml(text));
|
||||
message.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
|
||||
AlertDialog dialog = new AlertDialog.Builder(mActivity)
|
||||
final AlertDialog dialog = new AlertDialog.Builder(mActivity)
|
||||
.setView(content)
|
||||
.setCancelable(true)
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
public void onClick(final DialogInterface dialog, final int which) {
|
||||
dialog.cancel();
|
||||
}
|
||||
})
|
||||
.create();
|
||||
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
public void onDismiss(final DialogInterface dialog) {
|
||||
mDialogs &= ~which;
|
||||
if (((CheckBox) content.findViewById(R.id.cb_do_not_show_again)).isChecked()) {
|
||||
int value = mPrefs.getInt("pref_messages", 0);
|
||||
@ -85,6 +86,4 @@ public class IITC_NotificationHelper {
|
||||
mDialogs |= which;
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -66,6 +66,9 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
// on tablets, select a default fragment BEFORE calling super onCreate
|
||||
// otherwise the application will crash, because the first header (the
|
||||
// category) does not have a fragment assigned
|
||||
if (onIsMultiPane()) {
|
||||
getIntent()
|
||||
.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, PluginsFragment.class.getName());
|
||||
|
@ -10,10 +10,10 @@ import android.webkit.WebView;
|
||||
*/
|
||||
public class IITC_WebChromeClient extends WebChromeClient {
|
||||
|
||||
private IITC_Mobile mIitcm;
|
||||
private final IITC_Mobile mIitc;
|
||||
|
||||
public IITC_WebChromeClient(IITC_Mobile iitcm) {
|
||||
mIitcm = iitcm;
|
||||
public IITC_WebChromeClient(final IITC_Mobile iitc) {
|
||||
mIitc = iitc;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -22,7 +22,7 @@ public class IITC_WebChromeClient extends WebChromeClient {
|
||||
* allow access by default
|
||||
*/
|
||||
@Override
|
||||
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
|
||||
public void onGeolocationPermissionsShowPrompt(final String origin, final GeolocationPermissions.Callback callback) {
|
||||
callback.invoke(origin, true, false);
|
||||
}
|
||||
|
||||
@ -30,21 +30,21 @@ public class IITC_WebChromeClient extends WebChromeClient {
|
||||
* display progress bar in activity
|
||||
*/
|
||||
@Override
|
||||
public void onProgressChanged(WebView view, int newProgress) {
|
||||
public void onProgressChanged(final WebView view, final int newProgress) {
|
||||
super.onProgressChanged(view, newProgress);
|
||||
|
||||
// maximum for newProgress is 100
|
||||
// maximum for setProgress is 10,000
|
||||
mIitcm.setProgress(newProgress * 100);
|
||||
mIitc.setProgress(newProgress * 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* remove splash screen if any JS error occurs
|
||||
*/
|
||||
@Override
|
||||
public boolean onConsoleMessage(ConsoleMessage message) {
|
||||
public boolean onConsoleMessage(final ConsoleMessage message) {
|
||||
if (message.messageLevel() == ConsoleMessage.MessageLevel.ERROR) {
|
||||
mIitcm.setLoadingState(false);
|
||||
mIitc.setLoadingState(false);
|
||||
}
|
||||
|
||||
if (Log.log(message))
|
||||
|
@ -44,7 +44,7 @@ public class IITC_WebView extends WebView {
|
||||
" Gecko/20130810 Firefox/17.0 Iceweasel/17.0.8";
|
||||
|
||||
// init web view
|
||||
private void iitc_init(Context c) {
|
||||
private void iitc_init(final Context c) {
|
||||
if (isInEditMode()) return;
|
||||
mIitc = (IITC_Mobile) c;
|
||||
mSettings = getSettings();
|
||||
@ -86,19 +86,19 @@ public class IITC_WebView extends WebView {
|
||||
}
|
||||
|
||||
// constructors -------------------------------------------------
|
||||
public IITC_WebView(Context context) {
|
||||
public IITC_WebView(final Context context) {
|
||||
super(context);
|
||||
|
||||
iitc_init(context);
|
||||
}
|
||||
|
||||
public IITC_WebView(Context context, AttributeSet attrs) {
|
||||
public IITC_WebView(final Context context, final AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
iitc_init(context);
|
||||
}
|
||||
|
||||
public IITC_WebView(Context context, AttributeSet attrs, int defStyle) {
|
||||
public IITC_WebView(final Context context, final AttributeSet attrs, final int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
|
||||
iitc_init(context);
|
||||
@ -117,7 +117,7 @@ public class IITC_WebView extends WebView {
|
||||
loadJS(url.substring("javascript:".length()));
|
||||
} else {
|
||||
// force https if enabled in settings
|
||||
SharedPreferences sharedPref = PreferenceManager
|
||||
final SharedPreferences sharedPref = PreferenceManager
|
||||
.getDefaultSharedPreferences(getContext());
|
||||
if (sharedPref.getBoolean("pref_force_https", true)) {
|
||||
url = url.replace("http://", "https://");
|
||||
@ -133,12 +133,12 @@ public class IITC_WebView extends WebView {
|
||||
}
|
||||
|
||||
@TargetApi(19)
|
||||
public void loadJS(String js) {
|
||||
public void loadJS(final String js) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
evaluateJavascript(js, null);
|
||||
} else {
|
||||
// if in edit text mode, don't load javascript otherwise the keyboard closes.
|
||||
HitTestResult testResult = getHitTestResult();
|
||||
final HitTestResult testResult = getHitTestResult();
|
||||
if (testResult != null && testResult.getType() == HitTestResult.EDIT_TEXT_TYPE) {
|
||||
// let window.show(...) interrupt input
|
||||
// window.show(...) is called if one of the action bar buttons
|
||||
@ -153,14 +153,14 @@ public class IITC_WebView extends WebView {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
public boolean onTouchEvent(final MotionEvent event) {
|
||||
getHandler().removeCallbacks(mNavHider);
|
||||
getHandler().postDelayed(mNavHider, 3000);
|
||||
return super.onTouchEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSystemUiVisibility(int visibility) {
|
||||
public void setSystemUiVisibility(final int visibility) {
|
||||
if ((visibility & SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0) {
|
||||
getHandler().postDelayed(mNavHider, 3000);
|
||||
}
|
||||
@ -168,7 +168,7 @@ public class IITC_WebView extends WebView {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWindowFocusChanged(boolean hasWindowFocus) {
|
||||
public void onWindowFocusChanged(final boolean hasWindowFocus) {
|
||||
if (hasWindowFocus) {
|
||||
getHandler().postDelayed(mNavHider, 3000);
|
||||
} else {
|
||||
@ -180,7 +180,7 @@ public class IITC_WebView extends WebView {
|
||||
public void toggleFullscreen() {
|
||||
mFullscreenStatus ^= FS_ENABLED;
|
||||
|
||||
WindowManager.LayoutParams attrs = mIitc.getWindow().getAttributes();
|
||||
final WindowManager.LayoutParams attrs = mIitc.getWindow().getAttributes();
|
||||
// toggle notification bar
|
||||
if (isInFullscreen()) {
|
||||
// show a toast with instructions to exit the fullscreen mode again
|
||||
@ -206,14 +206,14 @@ public class IITC_WebView extends WebView {
|
||||
}
|
||||
|
||||
void updateFullscreenStatus() {
|
||||
Set<String> entries = mSharedPrefs.getStringSet("pref_fullscreen", new HashSet<String>());
|
||||
final Set<String> entries = mSharedPrefs.getStringSet("pref_fullscreen", new HashSet<String>());
|
||||
mFullscreenStatus &= FS_ENABLED;
|
||||
|
||||
// default values...android has no nice way to add default values to multiSelectListPreferences
|
||||
if (entries.isEmpty()) {
|
||||
mFullscreenStatus += FS_ACTIONBAR | FS_SYSBAR;
|
||||
}
|
||||
for (String entry : entries) {
|
||||
for (final String entry : entries) {
|
||||
mFullscreenStatus += Integer.parseInt(entry);
|
||||
}
|
||||
}
|
||||
@ -236,27 +236,28 @@ public class IITC_WebView extends WebView {
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
||||
public boolean isConnectedToWifi() {
|
||||
ConnectivityManager conMan = (ConnectivityManager) getContext()
|
||||
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo wifi = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
||||
final ConnectivityManager conMan = (ConnectivityManager) mIitc.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
final NetworkInfo wifi = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
||||
|
||||
// since jelly bean you can mark wifi networks as mobile hotspots
|
||||
// settings -> data usage -> menu -> mobile hotspots
|
||||
// ConnectivityManager.isActiveNetworkMeter returns if the currently used wifi-network
|
||||
// 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());
|
||||
if (conMan.isActiveNetworkMetered()) return false;
|
||||
}
|
||||
|
||||
return (wifi.getState() == NetworkInfo.State.CONNECTED);
|
||||
}
|
||||
|
||||
public void disableJS(boolean val) {
|
||||
public void disableJS(final boolean val) {
|
||||
mDisableJs = val;
|
||||
}
|
||||
|
||||
public void setUserAgent() {
|
||||
String ua = mSharedPrefs.getBoolean("pref_fake_user_agent", false) ? mDesktopUserAgent : mDefaultUserAgent;
|
||||
final String ua = mSharedPrefs.getBoolean("pref_fake_user_agent", false) ?
|
||||
mDesktopUserAgent : mDefaultUserAgent;
|
||||
Log.d("setting user agent to: " + ua);
|
||||
mSettings.setUserAgentString(ua);
|
||||
}
|
||||
|
@ -25,25 +25,25 @@ public class IITC_WebViewClient extends WebViewClient {
|
||||
private static final ByteArrayInputStream EMPTY = new ByteArrayInputStream("".getBytes());
|
||||
private static final String DOMAIN = IITC_FileManager.DOMAIN;
|
||||
|
||||
private String mIitcPath;
|
||||
private final String mIitcPath;
|
||||
private boolean mIitcInjected = false;
|
||||
private final IITC_Mobile mIitc;
|
||||
private final IITC_TileManager mTileManager;
|
||||
|
||||
public IITC_WebViewClient(IITC_Mobile iitc) {
|
||||
this.mIitc = iitc;
|
||||
this.mTileManager = new IITC_TileManager(mIitc);
|
||||
this.mIitcPath = Environment.getExternalStorageDirectory().getPath() + "/IITC_Mobile/";
|
||||
public IITC_WebViewClient(final IITC_Mobile iitc) {
|
||||
mIitc = iitc;
|
||||
mTileManager = new IITC_TileManager(mIitc);
|
||||
mIitcPath = Environment.getExternalStorageDirectory().getPath() + "/IITC_Mobile/";
|
||||
}
|
||||
|
||||
// enable https
|
||||
@Override
|
||||
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
|
||||
public void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error) {
|
||||
handler.proceed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageFinished(WebView view, String url) {
|
||||
public void onPageFinished(final WebView view, final String url) {
|
||||
if (url.startsWith("http://www.ingress.com/intel")
|
||||
|| url.startsWith("https://www.ingress.com/intel")) {
|
||||
if (mIitcInjected) return;
|
||||
@ -54,18 +54,18 @@ public class IITC_WebViewClient extends WebViewClient {
|
||||
super.onPageFinished(view, url);
|
||||
}
|
||||
|
||||
private void loadScripts(IITC_WebView view) {
|
||||
List<String> scripts = new LinkedList<String>();
|
||||
private void loadScripts(final IITC_WebView view) {
|
||||
final List<String> scripts = new LinkedList<String>();
|
||||
|
||||
scripts.add("script" + DOMAIN + "/total-conversion-build.user.js");
|
||||
|
||||
// get the plugin preferences
|
||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(mIitc);
|
||||
Map<String, ?> all_prefs = sharedPref.getAll();
|
||||
final SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(mIitc);
|
||||
final Map<String, ?> all_prefs = sharedPref.getAll();
|
||||
|
||||
// iterate through all plugins
|
||||
for (Map.Entry<String, ?> entry : all_prefs.entrySet()) {
|
||||
String plugin = entry.getKey();
|
||||
for (final Map.Entry<String, ?> entry : all_prefs.entrySet()) {
|
||||
final String plugin = entry.getKey();
|
||||
if (plugin.endsWith(".user.js") && entry.getValue().toString().equals("true")) {
|
||||
if (plugin.startsWith(mIitcPath)) {
|
||||
scripts.add("user-plugin" + DOMAIN + plugin);
|
||||
@ -80,7 +80,7 @@ public class IITC_WebViewClient extends WebViewClient {
|
||||
scripts.add("script" + DOMAIN + "/user-location.user.js");
|
||||
}
|
||||
|
||||
String js = "(function(){['" + TextUtils.join("','", scripts) + "'].forEach(function(src) {" +
|
||||
final String js = "(function(){['" + TextUtils.join("','", scripts) + "'].forEach(function(src) {" +
|
||||
"var script = document.createElement('script');script.src = '//'+src;" +
|
||||
"(document.body || document.head || document.documentElement).appendChild(script);" +
|
||||
"});})();";
|
||||
@ -92,7 +92,7 @@ public class IITC_WebViewClient extends WebViewClient {
|
||||
* this method is called automatically when the Google login form is opened.
|
||||
*/
|
||||
@Override
|
||||
public void onReceivedLoginRequest(WebView view, String realm, String account, String args) {
|
||||
public void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args) {
|
||||
mIitcInjected = false;
|
||||
// Log.d("iitcm", "Login requested: " + realm + " " + account + " " + args);
|
||||
// ((IITC_Mobile) mContext).onReceivedLoginRequest(this, view, realm, account, args);
|
||||
@ -104,7 +104,7 @@ public class IITC_WebViewClient extends WebViewClient {
|
||||
* via http://stackoverflow.com/a/8274881/1684530
|
||||
*/
|
||||
@Override
|
||||
public WebResourceResponse shouldInterceptRequest(final WebView view, String url) {
|
||||
public WebResourceResponse shouldInterceptRequest(final WebView view, final String url) {
|
||||
// if any tiles are requested, handle it with IITC_TileManager
|
||||
if (url.matches(".*tile.*jpg.*") // mapquest tiles | ovi tiles
|
||||
|| url.matches(".*tile.*png.*") // cloudmade tiles
|
||||
@ -115,7 +115,7 @@ public class IITC_WebViewClient extends WebViewClient {
|
||||
) {
|
||||
try {
|
||||
return mTileManager.getTile(url);
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
Log.w(e);
|
||||
return super.shouldInterceptRequest(view, url);
|
||||
}
|
||||
@ -140,7 +140,7 @@ public class IITC_WebViewClient extends WebViewClient {
|
||||
return new WebResourceResponse("text/plain", "UTF-8", EMPTY);
|
||||
}
|
||||
|
||||
Uri uri = Uri.parse(url);
|
||||
final Uri uri = Uri.parse(url);
|
||||
if (uri.getHost() != null && uri.getHost().endsWith(DOMAIN) &&
|
||||
("http".equals(uri.getScheme()) || "https".equals(uri.getScheme())))
|
||||
return mIitc.getFileManager().getResponse(uri);
|
||||
@ -150,7 +150,7 @@ public class IITC_WebViewClient extends WebViewClient {
|
||||
|
||||
// start non-ingress-intel-urls in another app...
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||
public boolean shouldOverrideUrlLoading(final WebView view, final String url) {
|
||||
if (url.contains("ingress.com") || url.contains("appengine.google.com")) {
|
||||
// reload iitc if a poslink is clicked inside the app
|
||||
if (url.contains("intel?ll=")
|
||||
@ -161,7 +161,7 @@ public class IITC_WebViewClient extends WebViewClient {
|
||||
return false;
|
||||
} else {
|
||||
Log.d("no ingress intel link, start external app to load url: " + url);
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
||||
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
||||
mIitc.startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
|
@ -37,20 +37,20 @@ public final class Log {
|
||||
Pattern.CASE_INSENSITIVE);
|
||||
};
|
||||
|
||||
private static synchronized void log(int priority, String tag, String msg, Throwable tr) {
|
||||
Date now = new Date();
|
||||
private static synchronized void log(final int priority, final String tag, final String msg, final Throwable tr) {
|
||||
final Date now = new Date();
|
||||
|
||||
Message message = new Message(now, priority, tag, msg, tr);
|
||||
for (Receiver receiver : RECEIVERS) {
|
||||
final Message message = new Message(now, priority, tag, msg, tr);
|
||||
for (final Receiver receiver : RECEIVERS) {
|
||||
receiver.handle(message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void addReceiver(Log.Receiver receiver) {
|
||||
public static void addReceiver(final Log.Receiver receiver) {
|
||||
RECEIVERS.add(receiver);
|
||||
}
|
||||
|
||||
public static void d(String msg) {
|
||||
public static void d(final String msg) {
|
||||
d(DEFAULT_TAG, msg);
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ public final class Log {
|
||||
* @deprecated A default tag is provided by {@link Log.d}
|
||||
*/
|
||||
@Deprecated
|
||||
public static void d(String tag, String msg) {
|
||||
public static void d(final String tag, final String msg) {
|
||||
log(android.util.Log.DEBUG, tag, msg, null);
|
||||
android.util.Log.d(tag, msg);
|
||||
}
|
||||
@ -67,20 +67,20 @@ public final class Log {
|
||||
* @deprecated A default tag is provided by {@link Log.d}
|
||||
*/
|
||||
@Deprecated
|
||||
public static void d(String tag, String msg, Throwable tr) {
|
||||
public static void d(final String tag, final String msg, final Throwable tr) {
|
||||
log(android.util.Log.DEBUG, tag, msg, tr);
|
||||
android.util.Log.d(tag, msg, tr);
|
||||
}
|
||||
|
||||
public static void d(String msg, Throwable tr) {
|
||||
public static void d(final String msg, final Throwable tr) {
|
||||
d(DEFAULT_TAG, msg, tr);
|
||||
}
|
||||
|
||||
public static void d(Throwable tr) {
|
||||
public static void d(final Throwable tr) {
|
||||
d("Unexpected " + tr, tr);
|
||||
}
|
||||
|
||||
public static void e(String msg) {
|
||||
public static void e(final String msg) {
|
||||
e(DEFAULT_TAG, msg);
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ public final class Log {
|
||||
* @deprecated A default tag is provided by {@link Log.e}
|
||||
*/
|
||||
@Deprecated
|
||||
public static void e(String tag, String msg) {
|
||||
public static void e(final String tag, final String msg) {
|
||||
log(android.util.Log.ERROR, tag, msg, null);
|
||||
android.util.Log.e(tag, msg);
|
||||
}
|
||||
@ -97,20 +97,20 @@ public final class Log {
|
||||
* @deprecated A default tag is provided by {@link Log.e}
|
||||
*/
|
||||
@Deprecated
|
||||
public static void e(String tag, String msg, Throwable tr) {
|
||||
public static void e(final String tag, final String msg, final Throwable tr) {
|
||||
log(android.util.Log.ERROR, tag, msg, tr);
|
||||
android.util.Log.e(tag, msg, tr);
|
||||
}
|
||||
|
||||
public static void e(String msg, Throwable tr) {
|
||||
public static void e(final String msg, final Throwable tr) {
|
||||
e(DEFAULT_TAG, msg, tr);
|
||||
}
|
||||
|
||||
public static void e(Throwable tr) {
|
||||
public static void e(final Throwable tr) {
|
||||
e("Unexpected " + tr, tr);
|
||||
}
|
||||
|
||||
public static void i(String msg) {
|
||||
public static void i(final String msg) {
|
||||
i(DEFAULT_TAG, msg);
|
||||
}
|
||||
|
||||
@ -118,7 +118,7 @@ public final class Log {
|
||||
* @deprecated A default tag is provided by {@link Log.i}
|
||||
*/
|
||||
@Deprecated
|
||||
public static void i(String tag, String msg) {
|
||||
public static void i(final String tag, final String msg) {
|
||||
log(android.util.Log.INFO, tag, msg, null);
|
||||
android.util.Log.i(tag, msg);
|
||||
}
|
||||
@ -127,26 +127,26 @@ public final class Log {
|
||||
* @deprecated A default tag is provided by {@link Log.i}
|
||||
*/
|
||||
@Deprecated
|
||||
public static void i(String tag, String msg, Throwable tr) {
|
||||
public static void i(final String tag, final String msg, final Throwable tr) {
|
||||
log(android.util.Log.INFO, tag, msg, tr);
|
||||
android.util.Log.i(tag, msg, tr);
|
||||
}
|
||||
|
||||
public static void i(String msg, Throwable tr) {
|
||||
public static void i(final String msg, final Throwable tr) {
|
||||
i(DEFAULT_TAG, msg, tr);
|
||||
}
|
||||
|
||||
public static void i(Throwable tr) {
|
||||
public static void i(final Throwable tr) {
|
||||
i("Unexpected " + tr, tr);
|
||||
}
|
||||
|
||||
public static boolean log(ConsoleMessage message) {
|
||||
public static boolean log(final ConsoleMessage message) {
|
||||
String msg = message.sourceId();
|
||||
|
||||
if (msg == null || "".equals(msg)) {
|
||||
msg = "<no source>";
|
||||
} else {
|
||||
Matcher matcher = URL_PATTERN.matcher(msg);
|
||||
final Matcher matcher = URL_PATTERN.matcher(msg);
|
||||
if (matcher.matches()) {
|
||||
msg = "<" + matcher.group(1) + "/" + matcher.group(2) + ">";
|
||||
}
|
||||
@ -167,7 +167,7 @@ public final class Log {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int println(int priority, String msg) {
|
||||
public static int println(final int priority, final String msg) {
|
||||
return println(priority, DEFAULT_TAG, msg);
|
||||
}
|
||||
|
||||
@ -175,16 +175,16 @@ public final class Log {
|
||||
* @deprecated A default tag is provided by {@link Log.println}
|
||||
*/
|
||||
@Deprecated
|
||||
public static int println(int priority, String tag, String msg) {
|
||||
public static int println(final int priority, final String tag, final String msg) {
|
||||
log(priority, tag, msg, null);
|
||||
return android.util.Log.println(priority, tag, msg);
|
||||
}
|
||||
|
||||
public static void removeReceiver(Log.Receiver receiver) {
|
||||
public static void removeReceiver(final Log.Receiver receiver) {
|
||||
RECEIVERS.remove(receiver);
|
||||
}
|
||||
|
||||
public static void v(String msg) {
|
||||
public static void v(final String msg) {
|
||||
v(DEFAULT_TAG, msg);
|
||||
}
|
||||
|
||||
@ -192,7 +192,7 @@ public final class Log {
|
||||
* @deprecated A default tag is provided by {@link Log.v}
|
||||
*/
|
||||
@Deprecated
|
||||
public static void v(String tag, String msg) {
|
||||
public static void v(final String tag, final String msg) {
|
||||
log(android.util.Log.VERBOSE, tag, msg, null);
|
||||
android.util.Log.v(tag, msg);
|
||||
}
|
||||
@ -201,20 +201,20 @@ public final class Log {
|
||||
* @deprecated A default tag is provided by {@link Log.v}
|
||||
*/
|
||||
@Deprecated
|
||||
public static void v(String tag, String msg, Throwable tr) {
|
||||
public static void v(final String tag, final String msg, final Throwable tr) {
|
||||
log(android.util.Log.VERBOSE, tag, msg, tr);
|
||||
android.util.Log.v(tag, msg, tr);
|
||||
}
|
||||
|
||||
public static void v(String msg, Throwable tr) {
|
||||
public static void v(final String msg, final Throwable tr) {
|
||||
v(DEFAULT_TAG, msg, tr);
|
||||
}
|
||||
|
||||
public static void v(Throwable tr) {
|
||||
public static void v(final Throwable tr) {
|
||||
v("Unexpected " + tr, tr);
|
||||
}
|
||||
|
||||
public static void w(String msg) {
|
||||
public static void w(final String msg) {
|
||||
w(DEFAULT_TAG, msg);
|
||||
}
|
||||
|
||||
@ -222,7 +222,7 @@ public final class Log {
|
||||
* @deprecated A default tag is provided by {@link Log.w}
|
||||
*/
|
||||
@Deprecated
|
||||
public static void w(String tag, String msg) {
|
||||
public static void w(final String tag, final String msg) {
|
||||
log(android.util.Log.WARN, tag, msg, null);
|
||||
android.util.Log.w(tag, msg);
|
||||
}
|
||||
@ -231,16 +231,16 @@ public final class Log {
|
||||
* @deprecated A default tag is provided by {@link Log.w}
|
||||
*/
|
||||
@Deprecated
|
||||
public static void w(String tag, String msg, Throwable tr) {
|
||||
public static void w(final String tag, final String msg, final Throwable tr) {
|
||||
log(android.util.Log.WARN, tag, msg, tr);
|
||||
android.util.Log.w(tag, msg, tr);
|
||||
}
|
||||
|
||||
public static void w(String msg, Throwable tr) {
|
||||
public static void w(final String msg, final Throwable tr) {
|
||||
w(DEFAULT_TAG, msg, tr);
|
||||
}
|
||||
|
||||
public static void w(Throwable tr) {
|
||||
public static void w(final Throwable tr) {
|
||||
w("Unexpected " + tr, tr);
|
||||
}
|
||||
|
||||
@ -250,13 +250,13 @@ public final class Log {
|
||||
}
|
||||
|
||||
public static class Message {
|
||||
private Date mDate;
|
||||
private String mMsg;
|
||||
private int mPriority;
|
||||
private String mTag;
|
||||
private Throwable mTr;
|
||||
private final Date mDate;
|
||||
private final String mMsg;
|
||||
private final int mPriority;
|
||||
private final String mTag;
|
||||
private final Throwable mTr;
|
||||
|
||||
private Message(Date date, int priority, String tag, String msg, Throwable tr) {
|
||||
private Message(final Date date, final int priority, final String tag, final String msg, final Throwable tr) {
|
||||
mDate = date;
|
||||
mPriority = priority;
|
||||
mTag = tag;
|
||||
@ -265,23 +265,23 @@ public final class Log {
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return this.mDate;
|
||||
return mDate;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return this.mMsg;
|
||||
return mMsg;
|
||||
}
|
||||
|
||||
public int getPriority() {
|
||||
return this.mPriority;
|
||||
return mPriority;
|
||||
}
|
||||
|
||||
public String getTag() {
|
||||
return this.mTag;
|
||||
return mTag;
|
||||
}
|
||||
|
||||
public Throwable getTr() {
|
||||
return this.mTr;
|
||||
return mTr;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package com.cradle.iitc_mobile.async;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import com.cradle.iitc_mobile.IITC_FileManager;
|
||||
import com.cradle.iitc_mobile.Log;
|
||||
|
||||
import java.io.File;
|
||||
@ -13,43 +14,37 @@ import java.net.URLConnection;
|
||||
|
||||
public class DownloadTile extends AsyncTask<String, Void, Boolean> {
|
||||
|
||||
private String mFilePath;
|
||||
private final String mFilePath;
|
||||
|
||||
public DownloadTile(String path) {
|
||||
public DownloadTile(final String path) {
|
||||
mFilePath = path;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(String... urls) {
|
||||
protected Boolean doInBackground(final String... urls) {
|
||||
URL tileUrl = null;
|
||||
URLConnection conn = null;
|
||||
try {
|
||||
tileUrl = new URL(urls[0]);
|
||||
conn = tileUrl.openConnection();
|
||||
File file = new File(mFilePath);
|
||||
final File file = new File(mFilePath);
|
||||
// update tile if needed, else return
|
||||
if (conn.getLastModified() < file.lastModified()) return true;
|
||||
InputStream is = null;
|
||||
is = conn.getInputStream();
|
||||
Log.d("writing to file: " + file.toString());
|
||||
writeTileToFile(is, file);
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void writeTileToFile(InputStream inStream, File file) throws IOException {
|
||||
private void writeTileToFile(final InputStream inStream, final File file) throws IOException {
|
||||
file.getParentFile().mkdirs();
|
||||
FileOutputStream outStream = new FileOutputStream(file);
|
||||
int bufferSize = 1024;
|
||||
byte[] buffer = new byte[bufferSize];
|
||||
int len = 0;
|
||||
while ((len = inStream.read(buffer)) != -1) {
|
||||
outStream.write(buffer, 0, len);
|
||||
}
|
||||
if (outStream != null)
|
||||
outStream.close();
|
||||
final FileOutputStream outStream = new FileOutputStream(file);
|
||||
|
||||
IITC_FileManager.copyStream(inStream, outStream, true);
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,59 @@ window.plugin.overlayKML.loadExternals = function() {
|
||||
@@INCLUDERAW:external/leaflet.filelayer.js@@
|
||||
try { console.log('done loading leaflet.filelayer JS'); } catch(e) {}
|
||||
|
||||
if (window.requestFile !== undefined) {
|
||||
try { console.log('Loading android webview extensions for leaflet.filelayer JS now'); } catch(e) {}
|
||||
var FileLoaderMixin = {
|
||||
parse: function (fileContent, fileName) {
|
||||
// Check file extension
|
||||
var ext = fileName.split('.').pop(),
|
||||
parser = this._parsers[ext];
|
||||
if (!parser) {
|
||||
window.alert("Unsupported file type " + file.type + '(' + ext + ')');
|
||||
return;
|
||||
}
|
||||
this.fire('data:loading', {filename: fileName, format: ext});
|
||||
var layer = parser.call(this, fileContent, ext);
|
||||
this.fire('data:loaded', {layer: layer, filename: fileName, format: ext});
|
||||
}
|
||||
};
|
||||
FileLoader.include(FileLoaderMixin);
|
||||
|
||||
var FileLayerLoadMixin = {
|
||||
getLoader: function () {
|
||||
return this.loader;
|
||||
},
|
||||
_initContainer: function () {
|
||||
// Create a button, and bind click on hidden file input
|
||||
var zoomName = 'leaflet-control-filelayer leaflet-control-zoom',
|
||||
barName = 'leaflet-bar',
|
||||
partName = barName + '-part',
|
||||
container = L.DomUtil.create('div', zoomName + ' ' + barName);
|
||||
var link = L.DomUtil.create('a', zoomName + '-in ' + partName, container);
|
||||
link.innerHTML = L.Control.FileLayerLoad.LABEL;
|
||||
link.href = '#';
|
||||
link.title = L.Control.FileLayerLoad.TITLE;
|
||||
|
||||
var stop = L.DomEvent.stopPropagation;
|
||||
L.DomEvent
|
||||
.on(link, 'click', stop)
|
||||
.on(link, 'mousedown', stop)
|
||||
.on(link, 'dblclick', stop)
|
||||
.on(link, 'click', L.DomEvent.preventDefault)
|
||||
.on(link, 'click', function (e) {
|
||||
window.requestFile(function(filename, content) {
|
||||
_fileLayerLoad.getLoader().parse(content, filename);
|
||||
});
|
||||
e.preventDefault();
|
||||
});
|
||||
return container;
|
||||
}
|
||||
};
|
||||
L.Control.FileLayerLoad.include(FileLayerLoadMixin);
|
||||
|
||||
try { console.log('done loading android webview extensions for leaflet.filelayer JS'); } catch(e) {}
|
||||
}
|
||||
|
||||
try { console.log('Loading KML JS now'); } catch(e) {}
|
||||
@@INCLUDERAW:external/KML.js@@
|
||||
try { console.log('done loading KML JS'); } catch(e) {}
|
||||
@ -37,6 +90,8 @@ window.plugin.overlayKML.loadExternals = function() {
|
||||
window.plugin.overlayKML.load();
|
||||
}
|
||||
|
||||
var _fileLayerLoad = null;
|
||||
|
||||
window.plugin.overlayKML.load = function() {
|
||||
// Provide popup window allow user to select KML to overlay
|
||||
|
||||
@ -50,13 +105,14 @@ window.plugin.overlayKML.load = function() {
|
||||
});
|
||||
|
||||
L.Control.FileLayerLoad.LABEL = '<img src="@@INCLUDEIMAGE:images/open-folder-icon_sml.png@@" alt="Open" />';
|
||||
L.Control.fileLayerLoad({
|
||||
_fileLayerLoad = L.Control.fileLayerLoad({
|
||||
fitBounds: true,
|
||||
layerOptions: {
|
||||
pointToLayer: function (data, latlng) {
|
||||
return L.marker(latlng, {icon: KMLIcon});
|
||||
}},
|
||||
}).addTo(map);
|
||||
});
|
||||
_fileLayerLoad.addTo(map);
|
||||
}
|
||||
|
||||
var setup = function() {
|
||||
@ -66,3 +122,4 @@ var setup = function() {
|
||||
// PLUGIN END //////////////////////////////////////////////////////////
|
||||
|
||||
@@PLUGINEND@@
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user