From d378b4eb7bda400a790feface95beb35e3b4ac94 Mon Sep 17 00:00:00 2001 From: danielegobbetti Date: Tue, 8 Mar 2016 21:44:12 +0100 Subject: [PATCH 1/2] Intercept clay pebblejs://close url --- .../activities/ExternalPebbleJSActivity.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ExternalPebbleJSActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ExternalPebbleJSActivity.java index 36e8101e..122a2969 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ExternalPebbleJSActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ExternalPebbleJSActivity.java @@ -9,6 +9,7 @@ import android.view.MenuItem; import android.webkit.JavascriptInterface; import android.webkit.WebSettings; import android.webkit.WebView; +import android.webkit.WebViewClient; import android.widget.Toast; import org.json.JSONException; @@ -61,6 +62,7 @@ public class ExternalPebbleJSActivity extends Activity { WebView myWebView = (WebView) findViewById(R.id.configureWebview); myWebView.clearCache(true); + myWebView.setWebViewClient(new GBWebClient()); WebSettings webSettings = myWebView.getSettings(); webSettings.setJavaScriptEnabled(true); //needed to access the DOM @@ -87,6 +89,16 @@ public class ExternalPebbleJSActivity extends Activity { return null; } + private class GBWebClient extends WebViewClient { + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) { + url = url.replaceFirst("^pebblejs://close#", "file:///android_asset/app_config/configure.html?config=true&json="); + view.loadUrl(url); + return true; + + } + } + private class JSInterface { public JSInterface() { From ea855a4cc28acd4707d85f6ee5751d00c842ac1b Mon Sep 17 00:00:00 2001 From: danielegobbetti Date: Sun, 13 Mar 2016 08:31:50 +0100 Subject: [PATCH 2/2] Also open public URLs with an external browser. --- .../activities/ExternalPebbleJSActivity.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ExternalPebbleJSActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ExternalPebbleJSActivity.java index 122a2969..9e783eb5 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ExternalPebbleJSActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ExternalPebbleJSActivity.java @@ -1,6 +1,7 @@ package nodomain.freeyourgadget.gadgetbridge.activities; import android.app.Activity; +import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.support.v4.app.NavUtils; @@ -92,8 +93,15 @@ public class ExternalPebbleJSActivity extends Activity { private class GBWebClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { - url = url.replaceFirst("^pebblejs://close#", "file:///android_asset/app_config/configure.html?config=true&json="); - view.loadUrl(url); + if (url.startsWith("http://") || url.startsWith("https://")) { + Intent i = new Intent(Intent.ACTION_VIEW, + Uri.parse(url)); + startActivity(i); + } else { + url = url.replaceFirst("^pebblejs://close#", "file:///android_asset/app_config/configure.html?config=true&json="); + view.loadUrl(url); + } + return true; } @@ -143,11 +151,11 @@ public class ExternalPebbleJSActivity extends Activity { public String getActiveWatchInfo() { JSONObject wi = new JSONObject(); try { - wi.put("firmware",mGBDevice.getFirmwareVersion()); + wi.put("firmware", mGBDevice.getFirmwareVersion()); wi.put("platform", PebbleUtils.getPlatformName(mGBDevice.getHardwareVersion())); wi.put("model", PebbleUtils.getModel(mGBDevice.getHardwareVersion())); //TODO: use real info - wi.put("language","en"); + wi.put("language", "en"); } catch (JSONException e) { e.printStackTrace(); } @@ -173,11 +181,11 @@ public class ExternalPebbleJSActivity extends Activity { public String getAppUUID() { return appUuid.toString(); } - + @JavascriptInterface public String getWatchToken() { //specification says: A string that is is guaranteed to be identical for each Pebble device for the same app across different mobile devices. The token is unique to your app and cannot be used to track Pebble devices across applications. see https://developer.pebble.com/docs/js/Pebble/ - return "gb"+appUuid.toString(); + return "gb" + appUuid.toString(); } }