package com.owenlarosa.sunshineforwear;

import android.net.Uri;

import com.google.android.gms.wearable.DataEvent;
import com.google.android.gms.wearable.DataEventBuffer;
import com.google.android.gms.wearable.DataMap;
import com.google.android.gms.wearable.DataMapItem;
import com.google.android.gms.wearable.WearableListenerService;

/**
 * Created by Owen LaRosa on 1/25/17.
 */

public class DataLayerListenerService extends WearableListenerService {

    // keys for values in weather data items

    // Units of the temperature: "F" for Imperial or "C" for metric
    private static final String KEY_UNITS = "units";
    // high temperature as int
    private static final String KEY_HIGH = "high";
    // low temperature as int
    private static final String KEY_LOW = "low";
    // string describing the type of weather
    private static final String KEY_TYPE = "type";

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public void onDataChanged(DataEventBuffer dataEventBuffer) {
        super.onDataChanged(dataEventBuffer);

        for (DataEvent event : dataEventBuffer) {
            Uri uri = event.getDataItem().getUri();
            String path = uri.getPath();
            if (path.equals("/weather")) {
                final DataMap dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
                WatchFace.units = dataMap.getString(KEY_UNITS);
                WatchFace.high = dataMap.getInt(KEY_HIGH);
                WatchFace.low = dataMap.getInt(KEY_LOW);
                WatchFace.type = dataMap.getInt(KEY_TYPE);
                // temp color should be calculated after all the other values have been set
                WatchFace.setTempColor();
                WatchFace.setWeatherTextColor();
                WatchFace.setWeatherBackgroundColor();
                int imageId = Utils.getDrawableForWeatherCondition(WatchFace.type);
                WatchFace.weatherImageBitmap = Utils.getBitmap(this, imageId);
                WatchFace.setWeatherTypeText();
            }
        }
    }
}

@@ -1443,26 +1443,20 @@
         
-WatchFace.
+int 
 high = d
@@ -1496,26 +1496,20 @@
         
-WatchFace.
+int 
 low = da
@@ -1513,27 +1513,24 @@
  dataMap.get
-Int
 (KEY_LOW);%0A 
@@ -1528,16 +1528,334 @@
 Y_LOW);%0A
+                if (WatchFace.units.equals(%22C%22)) %7B%0A                    WatchFace.high = high;%0A                    WatchFace.low = low;%0A                %7D else %7B%0A                    WatchFace.high = (int) ((float) high * 1.8f + 32);%0A                    WatchFace.low = (int) ((float) low * 1.8f + 32);%0A                %7D%0A
         

Convert temp for Fahrenheit