Java Code Examples for com.google.android.gms.wearable.DataMap#getDouble()

The following examples show how to use com.google.android.gms.wearable.DataMap#getDouble() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BIGChart.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public void addDataMap(DataMap dataMap) {//KS
    double sgv = dataMap.getDouble("sgvDouble");
    double high = dataMap.getDouble("high");
    double low = dataMap.getDouble("low");
    double timestamp = dataMap.getDouble("timestamp");

    //Log.d(TAG, "addToWatchSet entry=" + dataMap);

    final int size = bgDataList.size();
    BgWatchData bgdata = new BgWatchData(sgv, high, low, timestamp);
    if (size > 0) {
        if (bgDataList.contains(bgdata)) {
            int i = bgDataList.indexOf(bgdata);
            BgWatchData bgd = bgDataList.get(bgDataList.indexOf(bgdata));
            //Log.d(TAG, "addToWatchSet replace indexOf=" + i + " bgDataList.sgv=" + bgd.sgv + " bgDataList.timestamp" + bgd.timestamp);
            bgDataList.set(i, bgdata);
        } else {
            //Log.d(TAG, "addToWatchSet add " + " entry.sgv=" + bgdata.sgv + " entry.timestamp" + bgdata.timestamp);
            bgDataList.add(bgdata);
        }
    }
    else {
        bgDataList.add(bgdata);
    }
}
 
Example 2
Source File: ListenerService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public synchronized static void createTreatment(DataMap dataMap, Context context) {
    Log.d(TAG, "createTreatment dataMap=" + dataMap);
    double timeoffset = dataMap.getDouble("timeoffset", 0);
    double carbs = dataMap.getDouble("carbs", 0);
    double insulin = dataMap.getDouble("insulin", 0);
    double bloodtest = dataMap.getDouble("bloodtest", 0);
    String notes = dataMap.getString("notes", "");

    long timestamp_ms = Treatments.getTimeStampWithOffset(timeoffset);
    Treatments treatment = Treatments.create(carbs, insulin, notes, timestamp_ms);
    if (bloodtest > 0) {
        Log.d(TAG, "createTreatment bloodtest=" + bloodtest);
        BloodTest.createFromCal(bloodtest, timeoffset, "Manual Entry", treatment.uuid);
    }
    else Log.d(TAG, "createTreatment bloodtest=0 " + bloodtest);
    showTreatments(context, "all");
    SendData(context, SYNC_TREATMENTS_PATH, null);
    //requestData(context);//send to phone if connected
}
 
Example 3
Source File: ListenerService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private boolean resetDataToLatest(DataMap dataMap, Context context) {//KS
    if (dataMap != null) {
        Double dmTimestamp = dataMap.getDouble("timestamp");
        Log.d(TAG, "resetDataToLatest dataMap.datetime=" + JoH.dateTimeText(dmTimestamp.longValue()) + " dataMap.sgvDouble=" + dataMap.getDouble("sgvDouble"));
        // todo ratelimit
        Sensor.InitDb(context);//ensure database has already been initialized
        final BgReading last = BgReading.last();
        if (last != null) {
            long bgTimestamp = last.timestamp;
            Log.d(TAG, "resetDataToLatest last.timestamp=" + JoH.dateTimeText(bgTimestamp) + " last.calculated_value=" + last.calculated_value);
            if (bgTimestamp > dmTimestamp) {
                dataMap(dataMap, last, mPrefs, new com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder(context));
                return true;
            }
        }
    }
    return false;
}
 
Example 4
Source File: CircleWatchface.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public void addDataMap(DataMap dataMap) {//KS
    double sgv = dataMap.getDouble("sgvDouble");
    double high = dataMap.getDouble("high");
    double low = dataMap.getDouble("low");
    double timestamp = dataMap.getDouble("timestamp");

    //Log.d(TAG, "addToWatchSet entry=" + dataMap);

    final int size = bgDataList.size();
    BgWatchData bgdata = new BgWatchData(sgv, high, low, timestamp);
    if (size > 0) {
        if (bgDataList.contains(bgdata)) {
            int i = bgDataList.indexOf(bgdata);
            BgWatchData bgd = bgDataList.get(bgDataList.indexOf(bgdata));
            //Log.d(TAG, "addToWatchSet replace indexOf=" + i + " bgDataList.sgv=" + bgd.sgv + " bgDataList.timestamp" + bgd.timestamp);
            bgDataList.set(i, bgdata);
        } else {
            //Log.d(TAG, "addToWatchSet add " + " entry.sgv=" + bgdata.sgv + " entry.timestamp" + bgdata.timestamp);
            bgDataList.add(bgdata);
        }
    }
    else {
        bgDataList.add(bgdata);
    }
}
 
Example 5
Source File: NOChart.java    From AndroidAPS with GNU Affero General Public License v3.0 6 votes vote down vote up
private void loadBasalsAndTemps(DataMap dataMap) {
    ArrayList<DataMap> temps = dataMap.getDataMapArrayList("temps");
    if (temps != null) {
        tempWatchDataList = new ArrayList<>();
        for (DataMap temp : temps) {
            TempWatchData twd = new TempWatchData();
            twd.startTime = temp.getLong("starttime");
            twd.startBasal =  temp.getDouble("startBasal");
            twd.endTime = temp.getLong("endtime");
            twd.endBasal = temp.getDouble("endbasal");
            twd.amount = temp.getDouble("amount");
            tempWatchDataList.add(twd);
        }
    }
    ArrayList<DataMap> basals = dataMap.getDataMapArrayList("basals");
    if (basals != null) {
        basalWatchDataList = new ArrayList<>();
        for (DataMap basal : basals) {
            BasalWatchData bwd = new BasalWatchData();
            bwd.startTime = basal.getLong("starttime");
            bwd.endTime = basal.getLong("endtime");
            bwd.amount = basal.getDouble("amount");
            basalWatchDataList.add(bwd);
        }
    }
}
 
Example 6
Source File: BaseWatchFace.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public void addDataMap(DataMap dataMap) {//KS
    double sgv = dataMap.getDouble("sgvDouble");
    double high = dataMap.getDouble("high");
    double low = dataMap.getDouble("low");
    double timestamp = dataMap.getDouble("timestamp");

    //Log.d(TAG, "addToWatchSet entry=" + dataMap);

    final int size = bgDataList.size();
    BgWatchData bgdata = new BgWatchData(sgv, high, low, timestamp);
    if (size > 0) {
        if (bgDataList.contains(bgdata)) {
            int i = bgDataList.indexOf(bgdata);
            BgWatchData bgd = bgDataList.get(bgDataList.indexOf(bgdata));
            //Log.d(TAG, "addToWatchSet replace indexOf=" + i + " bgDataList.sgv=" + bgd.sgv + " bgDataList.timestamp" + bgd.timestamp);
            bgDataList.set(i, bgdata);
        } else {
            //Log.d(TAG, "addToWatchSet add " + " entry.sgv=" + bgdata.sgv + " entry.timestamp" + bgdata.timestamp);
            bgDataList.add(bgdata);
        }
    }
    else {
        bgDataList.add(bgdata);
    }
}
 
Example 7
Source File: BIGChart.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public void addDataMap(DataMap dataMap) {//KS
    double sgv = dataMap.getDouble("sgvDouble");
    double high = dataMap.getDouble("high");
    double low = dataMap.getDouble("low");
    double timestamp = dataMap.getDouble("timestamp");

    //Log.d(TAG, "addToWatchSet entry=" + dataMap);

    final int size = bgDataList.size();
    BgWatchData bgdata = new BgWatchData(sgv, high, low, timestamp);
    if (size > 0) {
        if (bgDataList.contains(bgdata)) {
            int i = bgDataList.indexOf(bgdata);
            BgWatchData bgd = bgDataList.get(bgDataList.indexOf(bgdata));
            //Log.d(TAG, "addToWatchSet replace indexOf=" + i + " bgDataList.sgv=" + bgd.sgv + " bgDataList.timestamp" + bgd.timestamp);
            bgDataList.set(i, bgdata);
        } else {
            //Log.d(TAG, "addToWatchSet add " + " entry.sgv=" + bgdata.sgv + " entry.timestamp" + bgdata.timestamp);
            bgDataList.add(bgdata);
        }
    }
    else {
        bgDataList.add(bgdata);
    }
}
 
Example 8
Source File: ListenerService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public synchronized static void createTreatment(DataMap dataMap, Context context) {
    Log.d(TAG, "createTreatment dataMap=" + dataMap);
    double timeoffset = dataMap.getDouble("timeoffset", 0);
    double carbs = dataMap.getDouble("carbs", 0);
    double insulin = dataMap.getDouble("insulin", 0);
    double bloodtest = dataMap.getDouble("bloodtest", 0);
    String notes = dataMap.getString("notes", "");

    long timestamp_ms = Treatments.getTimeStampWithOffset(timeoffset);
    Treatments treatment = Treatments.create(carbs, insulin, notes, timestamp_ms);
    if (bloodtest > 0) {
        Log.d(TAG, "createTreatment bloodtest=" + bloodtest);
        BloodTest.createFromCal(bloodtest, timeoffset, "Manual Entry", treatment.uuid);
    }
    else Log.d(TAG, "createTreatment bloodtest=0 " + bloodtest);
    showTreatments(context, "all");
    SendData(context, SYNC_TREATMENTS_PATH, null);
    //requestData(context);//send to phone if connected
}
 
Example 9
Source File: BIGChart.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public void addDataMapTreats(DataMap dataMap, ArrayList<BgWatchData> dataList) {//KS
    double sgv = dataMap.getDouble("sgvDouble");
    double high = dataMap.getDouble("high");//carbs
    double low = dataMap.getDouble("low");//insulin
    double timestamp = dataMap.getDouble("timestamp");

    if (d) Log.d(TAG, "addDataMapTreats entry=" + dataMap);

    final int size = (dataList != null ? dataList.size() : 0);
    BgWatchData bgdata = new BgWatchData(sgv, high, low, timestamp);
    if (d) Log.d(TAG, "addDataMapTreats bgdata.sgv=" + bgdata.sgv + " bgdata.carbs=" + bgdata.high  + " bgdata.insulin=" + bgdata.low + " bgdata.timestamp=" + bgdata.timestamp + " timestamp=" + JoH.dateTimeText((long)bgdata.timestamp));
    if (size > 0) {
        if (dataList.contains(bgdata)) {
            int i = dataList.indexOf(bgdata);
            if (d) {
                BgWatchData data = dataList.get(dataList.indexOf(bgdata));
                Log.d(TAG, "addDataMapTreats replace indexOf=" + i + " treatsDataList.carbs=" + data.high + " treatsDataList.insulin=" + data.low + " treatsDataList.timestamp=" + data.timestamp);
            }
            dataList.set(i, bgdata);
        } else {
            if (d) Log.d(TAG, "addDataMapTreats add " + " treatsDataList.carbs=" + bgdata.high  + " treatsDataList.insulin=" + bgdata.low + " entry.timestamp=" + bgdata.timestamp);
            dataList.add(bgdata);
        }
    }
    else {
        dataList.add(bgdata);
    }
    if (d) Log.d(TAG, "addDataMapTreats dataList.size()=" + dataList.size());
}
 
Example 10
Source File: BaseWatchFace.java    From NightWatch with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    DataMap dataMap = DataMap.fromBundle(intent.getBundleExtra("data"));
    if (layoutSet) {
        wakeLock.acquire(50);
        sgvLevel = dataMap.getLong("sgvLevel");
        batteryLevel = dataMap.getInt("batteryLevel");
        datetime = dataMap.getDouble("timestamp");
        rawString = dataMap.getString("rawString");
        sgvString = dataMap.getString("sgvString");
        batteryString = dataMap.getString("battery");
        mSgv.setText(dataMap.getString("sgvString"));

        if(ageLevel()<=0) {
            mSgv.setPaintFlags(mSgv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
        } else {
            mSgv.setPaintFlags(mSgv.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
        }

        final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(BaseWatchFace.this);
        mTime.setText(timeFormat.format(System.currentTimeMillis()));

        showAgoRawBatt();

        mDirection.setText(dataMap.getString("slopeArrow"));
        mDelta.setText(dataMap.getString("delta"));

        if (chart != null) {
            addToWatchSet(dataMap);
            setupCharts();
        }
        mRelativeLayout.measure(specW, specH);
        mRelativeLayout.layout(0, 0, mRelativeLayout.getMeasuredWidth(),
                mRelativeLayout.getMeasuredHeight());
        invalidate();
    } else {
        Log.d("ERROR: ", "DATA IS NOT YET SET");
    }
    setColor();
}
 
Example 11
Source File: BaseWatchFace.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public void addDataMapTreats(DataMap dataMap, ArrayList<BgWatchData> dataList) {//KS
    double sgv = dataMap.getDouble("sgvDouble");
    double high = dataMap.getDouble("high");//carbs
    double low = dataMap.getDouble("low");//insulin
    double timestamp = dataMap.getDouble("timestamp");

     if (d) Log.d(TAG, "addDataMapTreats entry=" + dataMap);

    final int size = (dataList != null ? dataList.size() : 0);
    BgWatchData bgdata = new BgWatchData(sgv, high, low, timestamp);
    if (d) Log.d(TAG, "addDataMapTreats bgdata.sgv=" + bgdata.sgv + " bgdata.carbs=" + bgdata.high  + " bgdata.insulin=" + bgdata.low + " bgdata.timestamp=" + bgdata.timestamp + " timestamp=" + JoH.dateTimeText((long)bgdata.timestamp));
    if (size > 0) {
        if (dataList.contains(bgdata)) {
            int i = dataList.indexOf(bgdata);
            if (d) {
                BgWatchData data = dataList.get(dataList.indexOf(bgdata));
                Log.d(TAG, "addDataMapTreats replace indexOf=" + i + " treatsDataList.carbs=" + data.high + " treatsDataList.insulin=" + data.low + " treatsDataList.timestamp=" + data.timestamp);
            }
            dataList.set(i, bgdata);
        } else {
            if (d) Log.d(TAG, "addDataMapTreats add " + " treatsDataList.carbs=" + bgdata.high  + " treatsDataList.insulin=" + bgdata.low + " entry.timestamp=" + bgdata.timestamp);
            dataList.add(bgdata);
        }
    }
    else {
        dataList.add(bgdata);
    }
     if (d) Log.d(TAG, "addDataMapTreats dataList.size()=" + dataList.size());
}
 
Example 12
Source File: BaseWatchFace.java    From NightWatch with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    DataMap dataMap = DataMap.fromBundle(intent.getBundleExtra("data"));
    if (layoutSet) {
        wakeLock.acquire(50);
        sgvLevel = dataMap.getLong("sgvLevel");
        batteryLevel = dataMap.getInt("batteryLevel");
        datetime = dataMap.getDouble("timestamp");
        rawString = dataMap.getString("rawString");
        sgvString = dataMap.getString("sgvString");
        batteryString = dataMap.getString("battery");
        mSgv.setText(dataMap.getString("sgvString"));

        if(ageLevel()<=0) {
            mSgv.setPaintFlags(mSgv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
        } else {
            mSgv.setPaintFlags(mSgv.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
        }

        final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(BaseWatchFace.this);
        mTime.setText(timeFormat.format(System.currentTimeMillis()));

        showAgoRawBatt();

        mDirection.setText(dataMap.getString("slopeArrow"));
        mDelta.setText(dataMap.getString("delta"));

        if (chart != null) {
            addToWatchSet(dataMap);
            setupCharts();
        }
        mRelativeLayout.measure(specW, specH);
        mRelativeLayout.layout(0, 0, mRelativeLayout.getMeasuredWidth(),
                mRelativeLayout.getMeasuredHeight());
        invalidate();
    } else {
        Log.d("ERROR: ", "DATA IS NOT YET SET");
    }
    setColor();
}
 
Example 13
Source File: BIGChart.java    From NightWatch with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    DataMap dataMap = DataMap.fromBundle(intent.getBundleExtra("data"));
    if (layoutSet) {
        wakeLock.acquire(50);
        sgvLevel = dataMap.getLong("sgvLevel");
        batteryLevel = dataMap.getInt("batteryLevel");
        datetime = dataMap.getDouble("timestamp");
        rawString = dataMap.getString("rawString");
        sgvString = dataMap.getString("sgvString");
        batteryString = dataMap.getString("battery");
        mSgv.setText(dataMap.getString("sgvString"));

        if(ageLevel()<=0) {
            mSgv.setPaintFlags(mSgv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
        } else {
            mSgv.setPaintFlags(mSgv.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
        }

        final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(BIGChart.this);
        mTime.setText(timeFormat.format(System.currentTimeMillis()));

        showAgoRawBatt();

        String delta = dataMap.getString("delta");

        if (delta.endsWith(" mg/dl")) {
            mDelta.setText(delta.substring(0, delta.length() - 6));
        } else if (delta.endsWith(" mmol")) {
            mDelta.setText(delta.substring(0, delta.length() - 5));
        }

        if (chart != null) {
            addToWatchSet(dataMap);
            setupCharts();
        }
        mRelativeLayout.measure(specW, specH);
        mRelativeLayout.layout(0, 0, mRelativeLayout.getMeasuredWidth(),
                mRelativeLayout.getMeasuredHeight());
        invalidate();
        setColor();

        //start animation?
        // dataMap.getDataMapArrayList("entries") == null -> not on "resend data".
        if (sharedPrefs.getBoolean("animation", false) && dataMap.getDataMapArrayList("entries") == null && (sgvString.equals("100") || sgvString.equals("5.5") || sgvString.equals("5,5"))) {
            startAnimation();
        }


    } else {
        Log.d("ERROR: ", "DATA IS NOT YET SET");
    }
}
 
Example 14
Source File: AttractionsActivity.java    From io2015-codelabs with Apache License 2.0 4 votes vote down vote up
@Override
protected ArrayList<Attraction> doInBackground(Uri... params) {
    mAttractions.clear();

    // Connect to Play Services and the Wearable API
    GoogleApiClient googleApiClient = new GoogleApiClient.Builder(mContext)
            .addApi(Wearable.API)
            .build();

    ConnectionResult connectionResult = googleApiClient.blockingConnect(
            Constants.GOOGLE_API_CLIENT_TIMEOUT_S, TimeUnit.SECONDS);

    if (!connectionResult.isSuccess() || !googleApiClient.isConnected()) {
        Log.e(TAG, String.format(Constants.GOOGLE_API_CLIENT_ERROR_MSG,
                connectionResult.getErrorCode()));
        return null;
    }

    Uri attractionsUri = params[0];
    DataApi.DataItemResult dataItemResult =
            Wearable.DataApi.getDataItem(googleApiClient, attractionsUri).await();

    if (dataItemResult.getStatus().isSuccess() && dataItemResult.getDataItem() != null) {
        DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItemResult.getDataItem());
        List<DataMap> attractionsData =
                dataMapItem.getDataMap().getDataMapArrayList(Constants.EXTRA_ATTRACTIONS);

        // Loop through each attraction, adding them to the list
        Iterator<DataMap> itr = attractionsData.iterator();
        while (itr.hasNext()) {
            DataMap attractionData = itr.next();

            Attraction attraction = new Attraction();
            attraction.name = attractionData.getString(Constants.EXTRA_TITLE);
            attraction.description =
                    attractionData.getString(Constants.EXTRA_DESCRIPTION);
            attraction.city = attractionData.get(Constants.EXTRA_CITY);
            attraction.distance =
                    attractionData.getString(Constants.EXTRA_DISTANCE);
            attraction.location = new LatLng(
                    attractionData.getDouble(Constants.EXTRA_LOCATION_LAT),
                    attractionData.getDouble(Constants.EXTRA_LOCATION_LNG));
            attraction.image = Utils.loadBitmapFromAsset(googleApiClient,
                    attractionData.getAsset(Constants.EXTRA_IMAGE));
            attraction.secondaryImage = Utils.loadBitmapFromAsset(googleApiClient,
                    attractionData.getAsset(Constants.EXTRA_IMAGE_SECONDARY));

            mAttractions.add(attraction);
        }
    }

    googleApiClient.disconnect();

    return mAttractions;
}
 
Example 15
Source File: DataBundleUtil.java    From android_external_GmsLib with Apache License 2.0 4 votes vote down vote up
@Override
Double load(DataMap dataMap, String key) {
    return dataMap.getDouble(key);
}
 
Example 16
Source File: AttractionsActivity.java    From io2015-codelabs with Apache License 2.0 4 votes vote down vote up
@Override
protected ArrayList<Attraction> doInBackground(Uri... params) {
    mAttractions.clear();

    // Connect to Play Services and the Wearable API
    GoogleApiClient googleApiClient = new GoogleApiClient.Builder(mContext)
            .addApi(Wearable.API)
            .build();

    ConnectionResult connectionResult = googleApiClient.blockingConnect(
            Constants.GOOGLE_API_CLIENT_TIMEOUT_S, TimeUnit.SECONDS);

    if (!connectionResult.isSuccess() || !googleApiClient.isConnected()) {
        Log.e(TAG, String.format(Constants.GOOGLE_API_CLIENT_ERROR_MSG,
                connectionResult.getErrorCode()));
        return null;
    }

    Uri attractionsUri = params[0];
    DataApi.DataItemResult dataItemResult =
            Wearable.DataApi.getDataItem(googleApiClient, attractionsUri).await();

    if (dataItemResult.getStatus().isSuccess() && dataItemResult.getDataItem() != null) {
        DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItemResult.getDataItem());
        List<DataMap> attractionsData =
                dataMapItem.getDataMap().getDataMapArrayList(Constants.EXTRA_ATTRACTIONS);

        // Loop through each attraction, adding them to the list
        Iterator<DataMap> itr = attractionsData.iterator();
        while (itr.hasNext()) {
            DataMap attractionData = itr.next();

            Attraction attraction = new Attraction();
            attraction.name = attractionData.getString(Constants.EXTRA_TITLE);
            attraction.description =
                    attractionData.getString(Constants.EXTRA_DESCRIPTION);
            attraction.city = attractionData.get(Constants.EXTRA_CITY);
            attraction.distance =
                    attractionData.getString(Constants.EXTRA_DISTANCE);
            attraction.location = new LatLng(
                    attractionData.getDouble(Constants.EXTRA_LOCATION_LAT),
                    attractionData.getDouble(Constants.EXTRA_LOCATION_LNG));
            attraction.image = Utils.loadBitmapFromAsset(googleApiClient,
                    attractionData.getAsset(Constants.EXTRA_IMAGE));
            attraction.secondaryImage = Utils.loadBitmapFromAsset(googleApiClient,
                    attractionData.getAsset(Constants.EXTRA_IMAGE_SECONDARY));

            mAttractions.add(attraction);
        }
    }

    googleApiClient.disconnect();

    return mAttractions;
}
 
Example 17
Source File: BIGChart.java    From xDrip-Experimental with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getBundleExtra("data");
    if (bundle ==null){
        return;
    }
    DataMap dataMap = DataMap.fromBundle(bundle);
    if (layoutSet) {
        wakeLock.acquire(50);
        sgvLevel = dataMap.getLong("sgvLevel");
        batteryLevel = dataMap.getInt("batteryLevel");
        datetime = dataMap.getDouble("timestamp");
        rawString = dataMap.getString("rawString");
        sgvString = dataMap.getString("sgvString");
        batteryString = dataMap.getString("battery");
        mSgv.setText(dataMap.getString("sgvString"));

        if(ageLevel()<=0) {
            mSgv.setPaintFlags(mSgv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
        } else {
            mSgv.setPaintFlags(mSgv.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
        }

        final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(BIGChart.this);
        mTime.setText(timeFormat.format(System.currentTimeMillis()));

        showAgoRawBatt();

        String delta = dataMap.getString("delta");

        if (delta.endsWith(" mg/dl")) {
            mDelta.setText(delta.substring(0, delta.length() - 6));
        } else if (delta.endsWith(" mmol")) {
            mDelta.setText(delta.substring(0, delta.length() - 5));
        }

        if (chart != null) {
            addToWatchSet(dataMap);
            setupCharts();
        }
        mRelativeLayout.measure(specW, specH);
        mRelativeLayout.layout(0, 0, mRelativeLayout.getMeasuredWidth(),
                mRelativeLayout.getMeasuredHeight());
        invalidate();
        setColor();

        //start animation?
        // dataMap.getDataMapArrayList("entries") == null -> not on "resend data".
        if (sharedPrefs.getBoolean("animation", false) && dataMap.getDataMapArrayList("entries") == null && (sgvString.equals("100") || sgvString.equals("5.5") || sgvString.equals("5,5"))) {
            startAnimation();
        }


    } else {
        Log.d("ERROR: ", "DATA IS NOT YET SET");
    }
}
 
Example 18
Source File: BIGChart.java    From NightWatch with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    DataMap dataMap = DataMap.fromBundle(intent.getBundleExtra("data"));
    if (layoutSet) {
        wakeLock.acquire(50);
        sgvLevel = dataMap.getLong("sgvLevel");
        batteryLevel = dataMap.getInt("batteryLevel");
        datetime = dataMap.getDouble("timestamp");
        rawString = dataMap.getString("rawString");
        sgvString = dataMap.getString("sgvString");
        batteryString = dataMap.getString("battery");
        mSgv.setText(dataMap.getString("sgvString"));

        if(ageLevel()<=0) {
            mSgv.setPaintFlags(mSgv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
        } else {
            mSgv.setPaintFlags(mSgv.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
        }

        final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(BIGChart.this);
        mTime.setText(timeFormat.format(System.currentTimeMillis()));

        showAgoRawBatt();

        String delta = dataMap.getString("delta");

        if (delta.endsWith(" mg/dl")) {
            mDelta.setText(delta.substring(0, delta.length() - 6));
        } else if (delta.endsWith(" mmol")) {
            mDelta.setText(delta.substring(0, delta.length() - 5));
        }

        if (chart != null) {
            addToWatchSet(dataMap);
            setupCharts();
        }
        mRelativeLayout.measure(specW, specH);
        mRelativeLayout.layout(0, 0, mRelativeLayout.getMeasuredWidth(),
                mRelativeLayout.getMeasuredHeight());
        invalidate();
        setColor();

        //start animation?
        // dataMap.getDataMapArrayList("entries") == null -> not on "resend data".
        if (sharedPrefs.getBoolean("animation", false) && dataMap.getDataMapArrayList("entries") == null && (sgvString.equals("100") || sgvString.equals("5.5") || sgvString.equals("5,5"))) {
            startAnimation();
        }


    } else {
        Log.d("ERROR: ", "DATA IS NOT YET SET");
    }
}
 
Example 19
Source File: AttractionsActivity.java    From wear-os-samples with Apache License 2.0 4 votes vote down vote up
@Override
protected ArrayList<Attraction> doInBackground(Uri... params) {
    mAttractions.clear();

    // Connect to Play Services and the Wearable API
    GoogleApiClient googleApiClient = new GoogleApiClient.Builder(mContext)
            .addApi(Wearable.API)
            .build();

    ConnectionResult connectionResult = googleApiClient.blockingConnect(
            Constants.GOOGLE_API_CLIENT_TIMEOUT_S, TimeUnit.SECONDS);

    if (!connectionResult.isSuccess() || !googleApiClient.isConnected()) {
        Log.e(TAG, String.format(Constants.GOOGLE_API_CLIENT_ERROR_MSG,
                connectionResult.getErrorCode()));
        return null;
    }

    Uri attractionsUri = params[0];
    DataApi.DataItemResult dataItemResult =
            Wearable.DataApi.getDataItem(googleApiClient, attractionsUri).await();

    if (dataItemResult.getStatus().isSuccess() && dataItemResult.getDataItem() != null) {
        DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItemResult.getDataItem());
        List<DataMap> attractionsData =
                dataMapItem.getDataMap().getDataMapArrayList(Constants.EXTRA_ATTRACTIONS);

        // Loop through each attraction, adding them to the list
        Iterator<DataMap> itr = attractionsData.iterator();
        while (itr.hasNext()) {
            DataMap attractionData = itr.next();

            Attraction attraction = new Attraction();
            attraction.name = attractionData.getString(Constants.EXTRA_TITLE);
            attraction.description =
                    attractionData.getString(Constants.EXTRA_DESCRIPTION);
            attraction.city = attractionData.get(Constants.EXTRA_CITY);
            attraction.distance =
                    attractionData.getString(Constants.EXTRA_DISTANCE);
            attraction.location = new LatLng(
                    attractionData.getDouble(Constants.EXTRA_LOCATION_LAT),
                    attractionData.getDouble(Constants.EXTRA_LOCATION_LNG));
            attraction.image = Utils.loadBitmapFromAsset(googleApiClient,
                    attractionData.getAsset(Constants.EXTRA_IMAGE));
            attraction.secondaryImage = Utils.loadBitmapFromAsset(googleApiClient,
                    attractionData.getAsset(Constants.EXTRA_IMAGE_SECONDARY));

            mAttractions.add(attraction);
        }
    }

    googleApiClient.disconnect();

    return mAttractions;
}
 
Example 20
Source File: Emmet.java    From Wear-Emmet with Apache License 2.0 4 votes vote down vote up
private void callMethodOnObject(final Object object, final DataMap methodDataMap) {

        String methodName = methodDataMap.getString(METHOD_NAME);
        ArrayList<DataMap> methodDataMapList = methodDataMap.getDataMapArrayList(METHOD_PARAMS);

        List<Method> methodsList = getMethodWithName(object, methodName, methodDataMapList.size());
        for (Method method : methodsList) {
            try {
                if (method != null) {
                    int nbArgs = methodDataMapList.size();

                    Object[] params = new Object[nbArgs];

                    for (int argumentPos = 0; argumentPos < nbArgs; ++argumentPos) {
                        Class paramClass = method.getParameterTypes()[argumentPos];

                        DataMap map = methodDataMapList.get(argumentPos);

                        String type = map.getString(PARAM_TYPE);
                        switch (type) {
                            case (TYPE_INT):
                                params[argumentPos] = map.getInt(PARAM_VALUE);
                                break;
                            case (TYPE_FLOAT):
                                params[argumentPos] = map.getFloat(PARAM_VALUE);
                                break;
                            case (TYPE_DOUBLE):
                                params[argumentPos] = map.getDouble(PARAM_VALUE);
                                break;
                            case (TYPE_LONG):
                                params[argumentPos] = map.getLong(PARAM_VALUE);
                                break;
                            case (TYPE_STRING):
                                params[argumentPos] = map.getString(PARAM_VALUE);
                                break;
                            default: {
                                Type t = method.getGenericParameterTypes()[argumentPos];
                                Object deserialized = SerialisationUtilsGSON.deserialize(t, map.getString(PARAM_VALUE));
                                params[argumentPos] = deserialized;
                            }
                        }
                    }

                    //found the method
                    method.invoke(object, params);

                    //if call success, return / don't call other methods
                    return;
                }

            } catch (Exception e) {
                Log.e(TAG, "callMethodOnObject error", e);
            }
        }
    }