From 712ce1aa8b368d388a06ac4ef04e59609877e484 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Tue, 24 Jan 2017 18:50:43 +0100 Subject: [PATCH] Pebble: dynamic keys support for healthify --- .../pebble/AppMessageHandlerHealthify.java | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerHealthify.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerHealthify.java index 29dad593..1ae46cdb 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerHealthify.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerHealthify.java @@ -1,25 +1,41 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.pebble; import android.util.Pair; +import android.widget.Toast; +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.IOException; import java.nio.ByteBuffer; import java.util.ArrayList; +import java.util.HashMap; import java.util.UUID; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes; import nodomain.freeyourgadget.gadgetbridge.model.Weather; import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec; +import nodomain.freeyourgadget.gadgetbridge.util.GB; class AppMessageHandlerHealthify extends AppMessageHandler { - private static final int KEY_TEMPERATURE = 10021; - private static final int KEY_CONDITIONS = 10022; + private Integer KEY_TEMPERATURE; + private Integer KEY_CONDITIONS; AppMessageHandlerHealthify(UUID uuid, PebbleProtocol pebbleProtocol) { super(uuid, pebbleProtocol); + + messageKeys = new HashMap<>(); + try { + JSONObject appKeys = getAppKeys(); + KEY_TEMPERATURE = appKeys.getInt("TEMPERATURE"); + KEY_CONDITIONS = appKeys.getInt("CONDITIONS"); + } catch (IOException | JSONException e) { + GB.toast("There was an error accessing the watchface configuration.", Toast.LENGTH_LONG, GB.ERROR); + } } - private byte[] encodeMarioWeatherMessage(WeatherSpec weatherSpec) { + private byte[] encodeHelthifyWeatherMessage(WeatherSpec weatherSpec) { if (weatherSpec == null) { return null; } @@ -43,12 +59,12 @@ class AppMessageHandlerHealthify extends AppMessageHandler { return new GBDeviceEvent[]{null}; } GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes(); - sendBytes.encodedBytes = encodeMarioWeatherMessage(weatherSpec); + sendBytes.encodedBytes = encodeHelthifyWeatherMessage(weatherSpec); return new GBDeviceEvent[]{sendBytes}; } @Override public byte[] encodeUpdateWeather(WeatherSpec weatherSpec) { - return encodeMarioWeatherMessage(weatherSpec); + return encodeHelthifyWeatherMessage(weatherSpec); } }