Merge branch 'feature-configuration' of https://github.com/Freeyourgadget/Gadgetbridge into feature-configuration
This commit is contained in:
commit
fa6b572172
|
@ -34,6 +34,9 @@ function gbPebble() {
|
||||||
this.configurationValues = null;
|
this.configurationValues = null;
|
||||||
|
|
||||||
this.addEventListener = function(e, f) {
|
this.addEventListener = function(e, f) {
|
||||||
|
if(e == 'ready') {
|
||||||
|
this.ready = f;
|
||||||
|
}
|
||||||
if(e == 'showConfiguration') {
|
if(e == 'showConfiguration') {
|
||||||
this.showConfiguration = f;
|
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() {
|
this.actuallyOpenURL = function() {
|
||||||
window.open(this.configurationURL.toString(), "config");
|
window.open(this.configurationURL.toString(), "config");
|
||||||
}
|
}
|
||||||
|
@ -64,15 +81,31 @@ function gbPebble() {
|
||||||
return JSON.parse(GBjs.getActiveWatchInfo());
|
return JSON.parse(GBjs.getActiveWatchInfo());
|
||||||
}
|
}
|
||||||
|
|
||||||
this.sendAppMessage = function (dict, callback){
|
this.sendAppMessage = function (dict, callbackAck, callbackNack){
|
||||||
this.configurationValues = JSON.stringify(dict);
|
try {
|
||||||
document.getElementById("jsondata").innerHTML=this.configurationValues;
|
this.configurationValues = JSON.stringify(dict);
|
||||||
return callback;
|
document.getElementById("jsondata").innerHTML=this.configurationValues;
|
||||||
|
return callbackAck;
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
GBjs.gbLog("sendAppMessage failed");
|
||||||
|
return callbackNack;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.ready = function(e) {
|
this.getAccountToken = function() {
|
||||||
GBjs.gbLog("ready called");
|
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();
|
var Pebble = new gbPebble();
|
||||||
|
|
|
@ -131,7 +131,11 @@ public class ExternalPebbleJSActivity extends Activity {
|
||||||
public String getActiveWatchInfo() {
|
public String getActiveWatchInfo() {
|
||||||
JSONObject wi = new JSONObject();
|
JSONObject wi = new JSONObject();
|
||||||
try {
|
try {
|
||||||
|
wi.put("firmware",mGBDevice.getFirmwareVersion());
|
||||||
wi.put("platform", PebbleUtils.getPlatformName(mGBDevice.getHardwareVersion()));
|
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) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -157,6 +161,12 @@ public class ExternalPebbleJSActivity extends Activity {
|
||||||
public String getAppUUID() {
|
public String getAppUUID() {
|
||||||
return appUuid.toString();
|
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
|
@Override
|
||||||
|
|
|
@ -96,18 +96,24 @@ public class AppMessageHandlerPebStyle extends AppMessageHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GBDeviceEvent[] handleMessage(ArrayList<Pair<Integer, Object>> pairs) {
|
public GBDeviceEvent[] handleMessage(ArrayList<Pair<Integer, Object>> pairs) {
|
||||||
|
return null;
|
||||||
|
/*
|
||||||
GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
|
GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
|
||||||
ByteBuffer buf = ByteBuffer.allocate(encodeAck().length + encodePebStyleConfig().length);
|
ByteBuffer buf = ByteBuffer.allocate(encodeAck().length + encodePebStyleConfig().length);
|
||||||
buf.put(encodeAck());
|
buf.put(encodeAck());
|
||||||
buf.put(encodePebStyleConfig());
|
buf.put(encodePebStyleConfig());
|
||||||
sendBytes.encodedBytes = buf.array();
|
sendBytes.encodedBytes = buf.array();
|
||||||
return new GBDeviceEvent[]{sendBytes};
|
return new GBDeviceEvent[]{sendBytes};
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GBDeviceEvent[] pushMessage() {
|
public GBDeviceEvent[] pushMessage() {
|
||||||
|
return null;
|
||||||
|
/*
|
||||||
GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
|
GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
|
||||||
sendBytes.encodedBytes = encodePebStyleConfig();
|
sendBytes.encodedBytes = encodePebStyleConfig();
|
||||||
return new GBDeviceEvent[]{sendBytes};
|
return new GBDeviceEvent[]{sendBytes};
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -100,8 +100,11 @@ public class AppMessageHandlerTimeStylePebble extends AppMessageHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GBDeviceEvent[] handleMessage(ArrayList<Pair<Integer, Object>> pairs) {
|
public GBDeviceEvent[] handleMessage(ArrayList<Pair<Integer, Object>> pairs) {
|
||||||
|
return null;
|
||||||
|
/*
|
||||||
GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
|
GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
|
||||||
sendBytes.encodedBytes = encodeTimeStylePebbleConfig();
|
sendBytes.encodedBytes = encodeTimeStylePebbleConfig();
|
||||||
return new GBDeviceEvent[]{sendBytes};
|
return new GBDeviceEvent[]{sendBytes};
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,4 +12,16 @@ public class PebbleUtils {
|
||||||
}
|
}
|
||||||
return platformName;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue