From 3920b3f977895247ea49d3b722b764829c3c85b2 Mon Sep 17 00:00:00 2001 From: Daniele Gobbetti Date: Fri, 4 Mar 2016 17:43:43 +0100 Subject: [PATCH 1/2] Do not override the configured settings with our old stored values (but keep them around) --- .../service/devices/pebble/AppMessageHandlerPebStyle.java | 6 ++++++ .../devices/pebble/AppMessageHandlerTimeStylePebble.java | 3 +++ 2 files changed, 9 insertions(+) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerPebStyle.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerPebStyle.java index c29460da..8b90c5a6 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerPebStyle.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerPebStyle.java @@ -96,18 +96,24 @@ public class AppMessageHandlerPebStyle extends AppMessageHandler { @Override public GBDeviceEvent[] handleMessage(ArrayList> pairs) { + return null; + /* GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes(); ByteBuffer buf = ByteBuffer.allocate(encodeAck().length + encodePebStyleConfig().length); buf.put(encodeAck()); buf.put(encodePebStyleConfig()); sendBytes.encodedBytes = buf.array(); return new GBDeviceEvent[]{sendBytes}; + */ } @Override public GBDeviceEvent[] pushMessage() { + return null; + /* GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes(); sendBytes.encodedBytes = encodePebStyleConfig(); return new GBDeviceEvent[]{sendBytes}; + */ } } \ No newline at end of file diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerTimeStylePebble.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerTimeStylePebble.java index 11b8cf78..fb1583f7 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerTimeStylePebble.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerTimeStylePebble.java @@ -100,8 +100,11 @@ public class AppMessageHandlerTimeStylePebble extends AppMessageHandler { @Override public GBDeviceEvent[] handleMessage(ArrayList> pairs) { + return null; + /* GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes(); sendBytes.encodedBytes = encodeTimeStylePebbleConfig(); return new GBDeviceEvent[]{sendBytes}; + */ } } From 6d4b98719a64cab406d0be1fbd44284039b1bf7c Mon Sep 17 00:00:00 2001 From: Daniele Gobbetti Date: Fri, 4 Mar 2016 17:44:42 +0100 Subject: [PATCH 2/2] Implement some further JS methods to make additional watchapps happy --- .../app_config/js/gadgetbridge_boilerplate.js | 45 ++++++++++++++++--- .../activities/ExternalPebbleJSActivity.java | 10 +++++ .../gadgetbridge/util/PebbleUtils.java | 12 +++++ 3 files changed, 61 insertions(+), 6 deletions(-) diff --git a/app/src/main/assets/app_config/js/gadgetbridge_boilerplate.js b/app/src/main/assets/app_config/js/gadgetbridge_boilerplate.js index af68a965..760a2ec8 100644 --- a/app/src/main/assets/app_config/js/gadgetbridge_boilerplate.js +++ b/app/src/main/assets/app_config/js/gadgetbridge_boilerplate.js @@ -34,6 +34,9 @@ function gbPebble() { this.configurationValues = null; this.addEventListener = function(e, f) { + if(e == 'ready') { + this.ready = f; + } if(e == 'showConfiguration') { this.showConfiguration = f; } @@ -45,6 +48,20 @@ function gbPebble() { } } + this.removeEventListener = function(e, f) { + if(e == 'ready') { + this.ready = null; + } + if(e == 'showConfiguration') { + this.showConfiguration = null; + } + if(e == 'webviewclosed') { + this.parseconfig = null; + } + if(e == 'appmessage') { + this.appmessage = null; + } + } this.actuallyOpenURL = function() { window.open(this.configurationURL.toString(), "config"); } @@ -64,15 +81,31 @@ function gbPebble() { return JSON.parse(GBjs.getActiveWatchInfo()); } - this.sendAppMessage = function (dict, callback){ - this.configurationValues = JSON.stringify(dict); - document.getElementById("jsondata").innerHTML=this.configurationValues; - return callback; + this.sendAppMessage = function (dict, callbackAck, callbackNack){ + try { + this.configurationValues = JSON.stringify(dict); + document.getElementById("jsondata").innerHTML=this.configurationValues; + return callbackAck; + } + catch (e) { + GBjs.gbLog("sendAppMessage failed"); + return callbackNack; + } } - this.ready = function(e) { - GBjs.gbLog("ready called"); + this.getAccountToken = function() { + return ''; } + + this.getWatchToken = function() { + return GBjs.getWatchToken(); + } + + this.showSimpleNotificationOnPebble = function(title, body) { + GBjs.gbLog("app wanted to show: " + title + " body: "+ body); + } + + } var Pebble = new gbPebble(); 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 61ee95e7..36e8101e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ExternalPebbleJSActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ExternalPebbleJSActivity.java @@ -131,7 +131,11 @@ public class ExternalPebbleJSActivity extends Activity { public String getActiveWatchInfo() { JSONObject wi = new JSONObject(); try { + 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"); } catch (JSONException e) { e.printStackTrace(); } @@ -157,6 +161,12 @@ 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(); + } } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/PebbleUtils.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/PebbleUtils.java index b925c3fb..0e13e925 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/PebbleUtils.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/PebbleUtils.java @@ -12,4 +12,16 @@ public class PebbleUtils { } return platformName; } + public static String getModel(String hwRev) { + //TODO: get real data? + String model; + if (hwRev.startsWith("snowy")) { + model = "pebble_time_black"; + } else if (hwRev.startsWith("spalding")) { + model = "pebble_time_round_black_20mm"; + } else { + model = "pebble_black"; + } + return model; + } }