use of nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.menu.SetCommuteMenuMessage in project Gadgetbridge by Freeyourgadget.
the class FossilHRWatchAdapter method handleBackgroundCharacteristic.
@Override
protected void handleBackgroundCharacteristic(BluetoothGattCharacteristic characteristic) {
super.handleBackgroundCharacteristic(characteristic);
byte[] value = characteristic.getValue();
byte requestType = value[1];
if (requestType == (byte) 0x04) {
if (value[7] == 0x00 || value[7] == 0x01) {
handleCallRequest(value);
} else if (value[7] == 0x02) {
handleDeleteNotification(value);
} else if (value[7] == 0x03) {
handleQuickReplyRequest(value);
}
} else if (requestType == (byte) 0x05) {
handleMusicRequest(value);
} else if (requestType == (byte) 0x01) {
int eventId = value[2];
LOG.info("got event id " + eventId);
try {
String jsonString = new String(value, 3, value.length - 3);
// logger.info(jsonString);
JSONObject requestJson = new JSONObject(jsonString);
JSONObject request = requestJson.getJSONObject("req");
int requestId = request.getInt("id");
if (request.has("ringMyPhone")) {
String action = request.getJSONObject("ringMyPhone").getString("action");
LOG.info("got ringMyPhone request; " + action);
GBDeviceEventFindPhone findPhoneEvent = new GBDeviceEventFindPhone();
JSONObject responseObject = new JSONObject().put("res", new JSONObject().put("id", requestId).put("set", new JSONObject().put("ringMyPhone", new JSONObject())));
if ("on".equals(action)) {
findPhoneEvent.event = GBDeviceEventFindPhone.Event.START;
getDeviceSupport().evaluateGBDeviceEvent(findPhoneEvent);
responseObject.getJSONObject("res").getJSONObject("set").getJSONObject("ringMyPhone").put("result", "on");
queueWrite(new JsonPutRequest(responseObject, this));
} else if ("off".equals(action)) {
findPhoneEvent.event = GBDeviceEventFindPhone.Event.STOP;
getDeviceSupport().evaluateGBDeviceEvent(findPhoneEvent);
responseObject.getJSONObject("res").getJSONObject("set").getJSONObject("ringMyPhone").put("result", "off");
queueWrite(new JsonPutRequest(responseObject, this));
}
} else if (request.has("weatherInfo") || request.has("weatherApp._.config.locations")) {
LOG.info("Got weatherInfo request");
WeatherSpec weatherSpec = Weather.getInstance().getWeatherSpec();
if (weatherSpec != null) {
onSendWeather(weatherSpec);
} else {
LOG.info("no weather data available - ignoring request");
}
} else if (request.has("commuteApp._.config.commute_info")) {
String action = request.getJSONObject("commuteApp._.config.commute_info").getString("dest");
String startStop = request.getJSONObject("commuteApp._.config.commute_info").getString("action");
if (startStop.equals("stop")) {
// overwriteButtons(null);
return;
}
queueWrite(new SetCommuteMenuMessage(getContext().getString(R.string.fossil_hr_commute_processing), false, this));
Intent menuIntent = new Intent(QHybridSupport.QHYBRID_EVENT_COMMUTE_MENU);
menuIntent.putExtra("EXTRA_ACTION", action);
getContext().sendBroadcast(menuIntent);
} else if (request.has("master._.config.app_status")) {
queueWrite(new ConfirmAppStatusRequest(requestId, this));
} else {
LOG.warn("Unhandled request from watch: " + requestJson.toString());
}
} catch (JSONException e) {
LOG.error("Error while handling received characteristic", e);
}
}
}
Aggregations