Search in sources :

Example 1 with ParcelableWeather2

use of ru.gelin.android.weather.notification.ParcelableWeather2 in project Gadgetbridge by Freeyourgadget.

the class AppMessageHandlerPebStyle method encodePebStyleConfig.

private byte[] encodePebStyleConfig() {
    ArrayList<Pair<Integer, Object>> pairs = new ArrayList<>();
    //settings that give good legibility on pebble time
    //1 enabled
    pairs.add(new Pair<>(KEY_SECOND_HAND, (Object) 0));
    //1 silent, 2 weak, up to 5
    pairs.add(new Pair<>(KEY_BLUETOOTH_ALERT, (Object) 0));
    //0 fahrenheit
    pairs.add(new Pair<>(KEY_TEMPERATURE_FORMAT, (Object) 1));
    //0 auto, 1 manual
    pairs.add(new Pair<>(KEY_LOCATION_SERVICE, (Object) 2));
    //0 right
    pairs.add(new Pair<>(KEY_SIDEBAR_LOCATION, (Object) 1));
    //1 custom
    pairs.add(new Pair<>(KEY_COLOR_SELECTION, (Object) 1));
    pairs.add(new Pair<>(KEY_MAIN_COLOR, (Object) PebbleColor.Black));
    pairs.add(new Pair<>(KEY_MAIN_BG_COLOR, (Object) PebbleColor.White));
    pairs.add(new Pair<>(KEY_SIDEBAR_BG_COLOR, (Object) PebbleColor.MediumSpringGreen));
    //DIGITAL settings
    /*
        pairs.add(new Pair<>(KEY_MAIN_CLOCK, (Object) 1)); //0 analog
        pairs.add(new Pair<>(KEY_SECONDARY_INFO_TYPE, (Object) 3)); //1 time, 2 location
        */
    //ANALOG + DIGITAL settings
    //0 analog, 1 digital
    pairs.add(new Pair<>(KEY_MAIN_CLOCK, (Object) 0));
    //1 time, 2 location
    pairs.add(new Pair<>(KEY_SECONDARY_INFO_TYPE, (Object) 1));
    //WEATHER
    ParcelableWeather2 weather = Weather.getInstance().getWeather2();
    if (weather != null) {
        //comment the same key in the general section above!
        //0 auto, 1 manual
        pairs.add(new Pair<>(KEY_LOCATION_SERVICE, (Object) 0));
        pairs.add(new Pair<>(KEY_WEATHER_CODE, (Object) Weather.mapToYahooCondition(weather.currentConditionCode)));
        pairs.add(new Pair<>(KEY_WEATHER_TEMP, (Object) (weather.currentTemp - 273)));
    }
    byte[] testMessage = mPebbleProtocol.encodeApplicationMessagePush(PebbleProtocol.ENDPOINT_APPLICATIONMESSAGE, mUUID, pairs);
    ByteBuffer buf = ByteBuffer.allocate(testMessage.length);
    // encode ack and put in front of push message (hack for acknowledging the last message)
    buf.put(testMessage);
    return buf.array();
}
Also used : ParcelableWeather2(ru.gelin.android.weather.notification.ParcelableWeather2) ArrayList(java.util.ArrayList) ByteBuffer(java.nio.ByteBuffer) Pair(android.util.Pair)

Example 2 with ParcelableWeather2

use of ru.gelin.android.weather.notification.ParcelableWeather2 in project Gadgetbridge by Freeyourgadget.

the class WeatherNotificationReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    if (!intent.getAction().contains("WEATHER_UPDATE_2")) {
        LOG.info("Wrong action");
        return;
    }
    ParcelableWeather2 weather = null;
    try {
        weather = intent.getParcelableExtra("ru.gelin.android.weather.notification.EXTRA_WEATHER");
    } catch (RuntimeException e) {
        e.printStackTrace();
    }
    if (weather != null) {
        Weather.getInstance().setWeather2(weather);
        LOG.info("weather in " + weather.location + " is " + weather.currentCondition + " (" + (weather.currentTemp - 273) + "°C)");
        WeatherSpec weatherSpec = new WeatherSpec();
        weatherSpec.timestamp = (int) (weather.queryTime / 1000);
        weatherSpec.location = weather.location;
        weatherSpec.currentTemp = weather.currentTemp;
        weatherSpec.currentCondition = weather.currentCondition;
        weatherSpec.currentConditionCode = weather.currentConditionCode;
        weatherSpec.todayMaxTemp = weather.todayHighTemp;
        weatherSpec.todayMinTemp = weather.todayLowTemp;
        weatherSpec.tomorrowConditionCode = weather.forecastConditionCode;
        weatherSpec.tomorrowMaxTemp = weather.forecastHighTemp;
        weatherSpec.tomorrowMinTemp = weather.forecastLowTemp;
        Weather.getInstance().setWeatherSpec(weatherSpec);
        GBApplication.deviceService().onSendWeather(weatherSpec);
    }
}
Also used : ParcelableWeather2(ru.gelin.android.weather.notification.ParcelableWeather2) WeatherSpec(nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec)

Aggregations

ParcelableWeather2 (ru.gelin.android.weather.notification.ParcelableWeather2)2 Pair (android.util.Pair)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 WeatherSpec (nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec)1