From f63a7db5f98c453c81449f471761bf62571e25a0 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Sun, 11 Dec 2016 00:08:57 +0100 Subject: [PATCH] Pebble: map owm conditions to TimeStyle icons This is probably not the way we should do it, just experimenting for personal use :P --- .../AppMessageHandlerTimeStylePebble.java | 75 ++++++++++++++++++- 1 file changed, 71 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerTimeStylePebble.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerTimeStylePebble.java index 4d31c4b8..d20aa615 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerTimeStylePebble.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerTimeStylePebble.java @@ -22,22 +22,89 @@ public class AppMessageHandlerTimeStylePebble extends AppMessageHandler { private static final int MESSAGE_KEY_WeatherUseNightIcon = 10025; + private static final int ICON_CLEAR_DAY = 0; + private static final int ICON_CLEAR_NIGHT = 1; + private static final int ICON_CLOUDY_DAY = 2; + private static final int ICON_HEAVY_RAIN = 3; + private static final int ICON_HEAVY_SNOW = 4; + private static final int ICON_LIGHT_RAIN = 5; + private static final int ICON_LIGHT_SNOW = 6; + private static final int ICON_PARTLY_CLOUDY_NIGHT = 7; + private static final int ICON_PARTLY_CLOUDY = 8; + private static final int ICON_RAINING_AND_SNOWING = 9; + private static final int ICON_THUNDERSTORM = 10; + private static final int ICON_WEATHER_GENERIC = 11; + private static final Logger LOG = LoggerFactory.getLogger(AppMessageHandlerTimeStylePebble.class); public AppMessageHandlerTimeStylePebble(UUID uuid, PebbleProtocol pebbleProtocol) { super(uuid, pebbleProtocol); } + /* + * converted to JAVA from original JS + */ + private int getIconForConditionCode(int conditionCode, boolean isNight) { + int generalCondition = conditionCode / 100; + int iconToLoad; + // determine the correct icon + switch (generalCondition) { + case 2: //thunderstorm + iconToLoad = ICON_THUNDERSTORM; + break; + case 3: //drizzle + iconToLoad = ICON_LIGHT_RAIN; + break; + case 5: //rain + if (conditionCode == 500) { + iconToLoad = ICON_LIGHT_RAIN; + } else if (conditionCode < 505) { + iconToLoad = ICON_HEAVY_RAIN; + } else if (conditionCode == 511) { + iconToLoad = ICON_RAINING_AND_SNOWING; + } else { + iconToLoad = ICON_LIGHT_RAIN; + } + break; + case 6: //snow + if (conditionCode == 600 || conditionCode == 620) { + iconToLoad = ICON_LIGHT_SNOW; + } else if (conditionCode > 610 && conditionCode < 620) { + iconToLoad = ICON_RAINING_AND_SNOWING; + } else { + iconToLoad = ICON_HEAVY_SNOW; + } + break; + case 7: // fog, dust, etc + iconToLoad = ICON_CLOUDY_DAY; + break; + case 8: // clouds + if (conditionCode == 800) { + iconToLoad = (!isNight) ? ICON_CLEAR_DAY : ICON_CLEAR_NIGHT; + } else if (conditionCode < 803) { + iconToLoad = (!isNight) ? ICON_PARTLY_CLOUDY : ICON_PARTLY_CLOUDY_NIGHT; + } else { + iconToLoad = ICON_CLOUDY_DAY; + } + break; + default: + iconToLoad = ICON_WEATHER_GENERIC; + break; + } + + return iconToLoad; + } + private byte[] encodeTimeStylePebbleWeather() { ArrayList> pairs = new ArrayList<>(); ParcelableWeather2 weather = Weather.getInstance().getWeather2(); + boolean isNight = false; //TODO: use the night icons when night if (weather != null) { - //TODO: use the night icons when night - pairs.add(new Pair<>(MESSAGE_KEY_WeatherUseNightIcon, (Object) 1)); + pairs.add(new Pair<>(MESSAGE_KEY_WeatherUseNightIcon, (Object) (isNight ? 1 : 0))); pairs.add(new Pair<>(MESSAGE_KEY_WeatherTemperature, (Object) (weather.currentTemp - 273))); - pairs.add(new Pair<>(MESSAGE_KEY_WeatherCondition, (Object) (weather.currentConditionCode))); - pairs.add(new Pair<>(MESSAGE_KEY_WeatherForecastCondition, (Object) (weather.forecastConditionCode))); + pairs.add(new Pair<>(MESSAGE_KEY_WeatherCondition, (Object) (getIconForConditionCode(weather.currentConditionCode, isNight)))); + pairs.add(new Pair<>(MESSAGE_KEY_WeatherForecastCondition, (Object) (getIconForConditionCode(weather.forecastConditionCode, isNight)))); pairs.add(new Pair<>(MESSAGE_KEY_WeatherForecastHighTemp, (Object) (weather.highTemp - 273))); pairs.add(new Pair<>(MESSAGE_KEY_WeatherForecastLowTemp, (Object) (weather.lowTemp - 273))); }