From 3c039b838f6757c811e50727f696d02042223f73 Mon Sep 17 00:00:00 2001 From: leCradle Date: Fri, 8 Mar 2013 15:27:33 +0100 Subject: [PATCH] added getLocation/clear cache and print version buttons to menu --- mobile/AndroidManifest.xml | 3 ++- mobile/res/menu/main.xml | 15 +++++++++++ mobile/res/values/strings.xml | 3 +++ .../com/cradle/iitc_mobile/IITC_Mobile.java | 25 +++++++++++++++++-- .../com/cradle/iitc_mobile/IITC_WebView.java | 12 +++++++++ 5 files changed, 55 insertions(+), 3 deletions(-) diff --git a/mobile/AndroidManifest.xml b/mobile/AndroidManifest.xml index 31c4833e..a5253bcd 100644 --- a/mobile/AndroidManifest.xml +++ b/mobile/AndroidManifest.xml @@ -2,13 +2,14 @@ + android:versionName="0.1.5" > + + + + + + + \ No newline at end of file diff --git a/mobile/res/values/strings.xml b/mobile/res/values/strings.xml index 0a05e741..f87553aa 100644 --- a/mobile/res/values/strings.xml +++ b/mobile/res/values/strings.xml @@ -4,5 +4,8 @@ IITC mobile Settings Reload IITC + Print Version + Clear Cache + Get Location \ No newline at end of file diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java index aacf8b65..1f2d4000 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java @@ -5,12 +5,13 @@ import com.cradle.iitc_mobile.R; import android.os.Bundle; import android.os.Handler; import android.app.Activity; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager.NameNotFoundException; import android.view.Menu; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; -import android.webkit.WebChromeClient; import android.widget.Toast; public class IITC_Mobile extends Activity { @@ -31,7 +32,6 @@ public class IITC_Mobile extends Activity { else { // load new iitc web view with ingress intel page iitc_view= (IITC_WebView) findViewById(R.id.webview); - iitc_view.setWebChromeClient(new WebChromeClient()); iitc_view.loadUrl("https://www.ingress.com/intel"); // listen to touches (think we need this) @@ -95,6 +95,27 @@ public class IITC_Mobile extends Activity { case R.id.reload_button: iitc_view.reload(); return true; + // print version number + case R.id.version_num: + PackageInfo pinfo; + try { + pinfo = getPackageManager().getPackageInfo(getPackageName(), 0); + Toast.makeText(this, "Build version: " + pinfo.versionName, Toast.LENGTH_SHORT).show(); + } catch (NameNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return true; + // clear cache + case R.id.cache_clear: + iitc_view.clearHistory(); + iitc_view.clearFormData(); + iitc_view.clearCache(true); + return true; + // clear cache + case R.id.locate: + iitc_view.loadUrl("javascript: window.map.locate({setView : true, maxZoom: 13});"); + return true; default: return super.onOptionsItemSelected(item); } diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java b/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java index d82ca25b..88b18db1 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java @@ -3,8 +3,10 @@ package com.cradle.iitc_mobile; import android.annotation.SuppressLint; import android.content.Context; import android.util.AttributeSet; +import android.webkit.WebChromeClient; import android.webkit.WebSettings; import android.webkit.WebView; +import android.webkit.GeolocationPermissions; @SuppressLint("SetJavaScriptEnabled") public class IITC_WebView extends WebView { @@ -18,6 +20,16 @@ public class IITC_WebView extends WebView { settings.setJavaScriptEnabled(true); settings.setDomStorageEnabled(true); settings.setAllowFileAccess(true); + settings.setGeolocationEnabled(true); + + // our webchromeclient should share geolocation with the iitc script + // allow access by default + this.setWebChromeClient(new WebChromeClient() { + @Override + public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) { + callback.invoke(origin, true, false); + } + }); webclient = new IITC_WebViewClient(); this.setWebViewClient(webclient);