Merge branch 'master' into master

This commit is contained in:
Taavi
2018-01-26 13:15:30 +02:00
committed by GitHub
4 changed files with 47 additions and 38 deletions
@@ -85,21 +85,21 @@ function hideSteps() {
function gbPebble() {
this.configurationURL = null;
this.configurationValues = null;
this.appMessageCallbackACK = {};
this.appMessageCallbackNACK = {};
var self = this;
appMessageCallbackACK = {};
appMessageCallbackNACK = {};
function appMessageCallbackProcessed(transactionId) {
if (appMessageCallbackACK[transactionId]) {
self.removeEventListener("ACK"+transactionId, self.appMessageCallbackACK[transactionId]);
appMessageCallbackACK[transactionId] = undefined;
}
if (appMessageCallbackNACK[transactionId]) {
self.removeEventListener("NACK"+transactionId, self.appMessageCallbackNACK[transactionId]);
appMessageCallbackNACK[transactionId] = undefined;
}
self.appMessageCallbackProcessed = function (transactionId) {
if (self.appMessageCallbackACK[transactionId]) {
self.removeEventListener("ACK"+transactionId, self.appMessageCallbackACK[transactionId]);
self.appMessageCallbackACK[transactionId] = undefined;
}
if (self.appMessageCallbackNACK[transactionId]) {
self.removeEventListener("NACK"+transactionId, self.appMessageCallbackNACK[transactionId]);
self.appMessageCallbackNACK[transactionId] = undefined;
}
}
self.events = {};
//events processing: see http://stackoverflow.com/questions/10978311/implementing-events-in-my-own-object
@@ -198,7 +198,7 @@ function gbPebble() {
}
var transactionId = GBjs.sendAppMessage(JSON.stringify(dict), needsTransaction);
if (needsTransaction) {
if (callbackAck != undefined) {
if (typeof callbackAck != "undefined") {
self.appMessageCallbackACK[transactionId] = function(e) {
// console.log("ACK FOR " + JSON.stringify(e));
callbackAck(e);
@@ -208,7 +208,7 @@ function gbPebble() {
this.addEventListener("ACK"+transactionId, self.appMessageCallbackACK[transactionId]);
}
if (callbackNack != undefined) {
if (typeof callbackNack != "undefined") {
self.appMessageCallbackNACK[transactionId] = function(e) {
// console.log("NACK FOR " + JSON.stringify(e));
callbackNack(e);
@@ -221,7 +221,7 @@ function gbPebble() {
}
}
catch (e) {
GBjs.gbLog("sendAppMessage failed");
GBjs.gbLog("sendAppMessage failed: " + e);
}
}
@@ -308,10 +308,10 @@ public class SettingsActivity extends AbstractSettingsActivity {
public boolean onPreferenceChange(Preference preference, Object autoExportInterval) {
String summary = String.format(
getApplicationContext().getString(R.string.pref_summary_auto_export_interval),
Integer.parseInt((String) autoExportInterval));
Integer.valueOf((String) autoExportInterval));
preference.setSummary(summary);
boolean auto_export_enabled = GBApplication.getPrefs().getBoolean(GBPrefs.AUTO_EXPORT_ENABLED, false);
PeriodicExporter.sheduleAlarm(getApplicationContext(), Integer.parseInt((String) autoExportInterval), auto_export_enabled);
PeriodicExporter.sheduleAlarm(getApplicationContext(), Integer.valueOf((String) autoExportInterval), auto_export_enabled);
return true;
}
});
@@ -2238,18 +2238,23 @@ public class PebbleProtocol extends GBDeviceProtocol {
switch (command) {
case APPRUNSTATE_START:
LOG.info(ENDPOINT_NAME + ": started " + uuid);
currentRunningApp = uuid;
AppMessageHandler handler = mAppMessageHandlers.get(uuid);
if (handler != null) {
currentRunningApp = uuid;
return handler.onAppStart();
}
else {
GBDeviceEventAppManagement gbDeviceEventAppManagement = new GBDeviceEventAppManagement();
gbDeviceEventAppManagement.uuid = uuid;
gbDeviceEventAppManagement.type = GBDeviceEventAppManagement.EventType.START;
gbDeviceEventAppManagement.event = GBDeviceEventAppManagement.Event.SUCCESS;
return new GBDeviceEvent[] {gbDeviceEventAppManagement};
if (!uuid.equals(currentRunningApp)) {
currentRunningApp = uuid;
GBDeviceEventAppManagement gbDeviceEventAppManagement = new GBDeviceEventAppManagement();
gbDeviceEventAppManagement.uuid = uuid;
gbDeviceEventAppManagement.type = GBDeviceEventAppManagement.EventType.START;
gbDeviceEventAppManagement.event = GBDeviceEventAppManagement.Event.SUCCESS;
return new GBDeviceEvent[]{gbDeviceEventAppManagement};
}
}
break;
case APPRUNSTATE_STOP:
LOG.info(ENDPOINT_NAME + ": stopped " + uuid);
break;
@@ -2603,13 +2608,13 @@ public class PebbleProtocol extends GBDeviceProtocol {
LOG.info((endpoint == ENDPOINT_LAUNCHER ? "got LAUNCHER PUSH from UUID : " : "got APPLICATIONMESSAGE PUSH from UUID : ") + uuid);
AppMessageHandler handler = mAppMessageHandlers.get(uuid);
if (handler != null) {
currentRunningApp = uuid;
if (handler.isEnabled()) {
if (endpoint == ENDPOINT_APPLICATIONMESSAGE) {
ArrayList<Pair<Integer, Object>> dict = decodeDict(buf);
devEvts = handler.handleMessage(dict);
}
else {
currentRunningApp = uuid;
devEvts = handler.onAppStart();
}
} else {
@@ -2617,22 +2622,26 @@ public class PebbleProtocol extends GBDeviceProtocol {
}
} else {
try {
if (endpoint == ENDPOINT_APPLICATIONMESSAGE) {
devEvts = decodeDictToJSONAppMessage(uuid, buf);
}
else {
currentRunningApp = uuid;
GBDeviceEventAppManagement gbDeviceEventAppManagement = new GBDeviceEventAppManagement();
gbDeviceEventAppManagement.uuid = uuid;
gbDeviceEventAppManagement.type = GBDeviceEventAppManagement.EventType.START;
gbDeviceEventAppManagement.event = GBDeviceEventAppManagement.Event.SUCCESS;
devEvts = new GBDeviceEvent[] {gbDeviceEventAppManagement};
}
devEvts = decodeDictToJSONAppMessage(uuid, buf);
} catch (JSONException e) {
LOG.error(e.getMessage());
return null;
}
if (!uuid.equals(currentRunningApp)) {
GBDeviceEventAppManagement gbDeviceEventAppManagement = new GBDeviceEventAppManagement();
gbDeviceEventAppManagement.uuid = uuid;
gbDeviceEventAppManagement.type = GBDeviceEventAppManagement.EventType.START;
gbDeviceEventAppManagement.event = GBDeviceEventAppManagement.Event.SUCCESS;
// prepend the
GBDeviceEvent concatEvents[] = new GBDeviceEvent[(devEvts != null ? devEvts.length : 0) + 1];
concatEvents[0] = gbDeviceEventAppManagement;
if (devEvts != null) {
System.arraycopy(devEvts, 0, concatEvents, 1, devEvts.length);
}
devEvts = concatEvents;
}
}
currentRunningApp = uuid;
break;
case APPLICATIONMESSAGE_ACK:
case APPLICATIONMESSAGE_NACK:
@@ -86,7 +86,7 @@ public class GB {
Boolean connected = device.isInitialized();
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setContentTitle(deviceName)
.setTicker(deviceName + text)
.setTicker(deviceName + " - " + text)
.setContentText(text)
.setSmallIcon(connected ? R.drawable.ic_notification : R.drawable.ic_notification_disconnected)
.setContentIntent(getContentIntent(context))