Pebble: map owm conditions to TimeStyle icons

This is probably not the way we should do it, just experimenting for personal use :P
This commit is contained in:
Andreas Shimokawa 2016-12-11 00:08:57 +01:00
parent a6a2c6d6d6
commit f63a7db5f9
1 changed files with 71 additions and 4 deletions

View File

@ -22,22 +22,89 @@ public class AppMessageHandlerTimeStylePebble extends AppMessageHandler {
private static final int MESSAGE_KEY_WeatherUseNightIcon = 10025; 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); private static final Logger LOG = LoggerFactory.getLogger(AppMessageHandlerTimeStylePebble.class);
public AppMessageHandlerTimeStylePebble(UUID uuid, PebbleProtocol pebbleProtocol) { public AppMessageHandlerTimeStylePebble(UUID uuid, PebbleProtocol pebbleProtocol) {
super(uuid, 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() { private byte[] encodeTimeStylePebbleWeather() {
ArrayList<Pair<Integer, Object>> pairs = new ArrayList<>(); ArrayList<Pair<Integer, Object>> pairs = new ArrayList<>();
ParcelableWeather2 weather = Weather.getInstance().getWeather2(); ParcelableWeather2 weather = Weather.getInstance().getWeather2();
boolean isNight = false; //TODO: use the night icons when night
if (weather != null) { if (weather != null) {
//TODO: use the night icons when night pairs.add(new Pair<>(MESSAGE_KEY_WeatherUseNightIcon, (Object) (isNight ? 1 : 0)));
pairs.add(new Pair<>(MESSAGE_KEY_WeatherUseNightIcon, (Object) 1));
pairs.add(new Pair<>(MESSAGE_KEY_WeatherTemperature, (Object) (weather.currentTemp - 273))); 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_WeatherCondition, (Object) (getIconForConditionCode(weather.currentConditionCode, isNight))));
pairs.add(new Pair<>(MESSAGE_KEY_WeatherForecastCondition, (Object) (weather.forecastConditionCode))); 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_WeatherForecastHighTemp, (Object) (weather.highTemp - 273)));
pairs.add(new Pair<>(MESSAGE_KEY_WeatherForecastLowTemp, (Object) (weather.lowTemp - 273))); pairs.add(new Pair<>(MESSAGE_KEY_WeatherForecastLowTemp, (Object) (weather.lowTemp - 273)));
} }