Pebble: dynamic keys support for healthify

here
Andreas Shimokawa 2017-01-24 18:50:43 +01:00
parent 3233432ee1
commit 712ce1aa8b
1 changed files with 21 additions and 5 deletions

View File

@ -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);
}
}