Search in sources :

Example 56 with DataMap

use of com.google.android.gms.wearable.DataMap in project xDrip-plus by jamorham.

the class ListenerService method sendLocalToast.

private void sendLocalToast(String msg, int length) {
    DataMap dataMap = new DataMap();
    dataMap.putString("msg", msg);
    dataMap.putInt("length", length);
    sendLocalMessage("msg", dataMap);
}
Also used : DataMap(com.google.android.gms.wearable.DataMap)

Example 57 with DataMap

use of com.google.android.gms.wearable.DataMap in project xDrip-plus by jamorham.

the class ListenerService method dataMap.

private DataMap dataMap(TransmitterData bg) {
    // KS
    DataMap dataMap = new DataMap();
    String json = bg.toS();
    Log.d(TAG, "dataMap BG GSON: " + json);
    dataMap.putString("bgs", json);
    return dataMap;
}
Also used : DataMap(com.google.android.gms.wearable.DataMap)

Example 58 with DataMap

use of com.google.android.gms.wearable.DataMap in project xDrip-plus by jamorham.

the class ListenerService method onDataChanged.

@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    DataMap dataMap;
    // KS
    mPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    String msg;
    Context context = getApplicationContext();
    for (DataEvent event : dataEvents) {
        if (event.getType() == DataEvent.TYPE_CHANGED) {
            String path = event.getDataItem().getUri().getPath();
            if (path.equals(OPEN_SETTINGS)) {
                // TODO: OpenSettings
                Intent intent = new Intent(this, NWPreferences.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
            } else if (path.equals(NEW_STATUS_PATH)) {
                dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
                boolean showExternalStatus = mPrefs.getBoolean("showExternalStatus", true);
                Log.d(TAG, "onDataChanged NEW_STATUS_PATH=" + path + " showExternalStatus=" + showExternalStatus);
                if (showExternalStatus) {
                    sendLocalMessage("status", dataMap);
                    String externalStatusString = dataMap.getString("externalStatusString");
                    PersistentStore.setString("remote-status-string", externalStatusString);
                    CustomComplicationProviderService.refresh();
                }
            } else if (path.equals(WEARABLE_TOAST_LOCAL_NOTIFICATON)) {
                dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
                sendLocalMessage("msg", dataMap);
                Log.d(TAG, "onDataChanged WEARABLE_TOAST_LOCAL_NOTIFICATON=" + path);
            } else if (path.equals(WEARABLE_DATA_PATH)) {
                dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
                Log.d(TAG, "onDataChanged WEARABLE_DATA_PATH=" + path);
                if (resetDataToLatest(dataMap, getApplicationContext())) {
                    Log.d(TAG, "onDataChanged dataMap reset to watch BgReading.Last()");
                }
                Intent messageIntent = new Intent();
                messageIntent.setAction(Intent.ACTION_SEND);
                DataMap stepsDataMap = BgSendQueue.getSensorSteps(mPrefs);
                if (stepsDataMap != null) {
                    messageIntent.putExtra("steps", stepsDataMap.toBundle());
                }
                messageIntent.putExtra("data", dataMap.toBundle());
                LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
                if (!mPrefs.getBoolean("enable_wearG5", false)) {
                    ListenerService.SendData(context, ListenerService.SYNC_ALL_DATA, null);
                }
            } else if (path.equals(WEARABLE_TREATMENT_PAYLOAD)) {
                dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
                Intent intent = new Intent(getApplicationContext(), Simulation.class);
                intent.putExtra(WEARABLE_TREATMENT_PAYLOAD, dataMap.toBundle());
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                getApplicationContext().startActivity(intent);
            } else if (path.equals(WEARABLE_TOAST_NOTIFICATON)) {
                dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
                Intent intent = new Intent(getApplicationContext(), Simulation.class);
                intent.putExtra(path, dataMap.toBundle());
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                getApplicationContext().startActivity(intent);
            } else if (path.equals(WEARABLE_SNOOZE_ALERT)) {
                Log.d(TAG, "onDataChanged WEARABLE_SNOOZE_ALERT=" + path);
                dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
                if (dataMap != null) {
                    msg = dataMap.getString("repeatTime", "");
                    int snooze;
                    try {
                        snooze = Integer.parseInt(msg);
                    } catch (NumberFormatException e) {
                        snooze = 30;
                    }
                    Log.d(TAG, "Received wearable: snooze payload: " + snooze);
                    AlertPlayer.getPlayer().Snooze(xdrip.getAppContext(), snooze, true);
                    sendLocalToast(getResources().getString(R.string.alert_snoozed_by_phone), Toast.LENGTH_SHORT);
                }
            } else if (path.equals(SYNC_DB_PATH)) {
                // KS  || path.equals(RESET_DB_PATH)
                Log.d(TAG, "onDataChanged SYNC_DB_PATH=" + path);
                final PowerManager.WakeLock wl = JoH.getWakeLock(getApplicationContext(), "watchlistener-SYNC_DB_PATH", 120000);
                // BgReading.deleteALL();
                // Calibration.deleteALL();
                // retain 3 days for Table Views
                long retainFrom = Pref.getBooleanDefaultFalse("extra_status_stats_24h") ? last_send_previous - three_days_ms : StatsResult.getTodayTimestamp();
                Log.d(TAG, "onDataChanged SYNC_DB_PATH delete BgReading and Calibration < retainFrom=" + JoH.dateTimeText(retainFrom));
                BgReading.cleanup(retainFrom);
                Calibration.cleanup(retainFrom);
                Log.d(TAG, "onDataChanged SYNC_DB_PATH delete UserError < last_send_previous_log=" + JoH.dateTimeText(last_send_previous_log));
                UserError.cleanup(last_send_previous_log);
                Log.d(TAG, "onDataChanged SYNC_DB_PATH delete TransmitterData < last_send_previous=" + JoH.dateTimeText(last_send_previous));
                TransmitterData.cleanup(last_send_previous);
                Log.d(TAG, "onDataChanged SYNC_DB_PATH delete PebbleMovement < last_send_previous=" + JoH.dateTimeText(last_send_previous_step_sensor));
                // retain 2 days
                PebbleMovement.cleanup(2);
                // retain 2 days
                HeartRate.cleanup(2);
                // retain 3 day for Table Views
                Treatments.cleanup(last_send_previous_treatments - three_days_ms);
                BloodTest.cleanup(3);
                JoH.releaseWakeLock(wl);
            } else if (path.equals(RESET_DB_PATH)) {
                // KS
                Log.d(TAG, "onDataChanged RESET_DB_PATH=" + path);
                final PowerManager.WakeLock wl = JoH.getWakeLock(getApplicationContext(), "watchlistener-RESET_DB_PATH", 120000);
                /* Sensor.DeleteAndInitDb(getApplicationContext());
                    PersistentStore.setLong(pref_last_send_previous, 0);
                    PersistentStore.setLong(pref_last_send_previous_log, 0);
                    PersistentStore.setLong(pref_last_send_previous_step_sensor, 0);*/
                // remotely callabale method to do the above
                resetDatabase();
                /* TODO remove once confirm not needed
                    if (isSafeToDeleteDB()) {
                        doDeleteDB = false;
                        Sensor.DeleteAndInitDb(getApplicationContext());
                        PersistentStore.setLong(pref_last_send_previous, 0);
                        PersistentStore.setLong(pref_last_send_previous_log, 0);
                    }
                    else {
                        doDeleteDB = true;
                        Log.d(TAG, "onDataChanged RESET_DB_PATH=" + path + " Unable to delete wear DB; wear data needs syncing.");
                    }*/
                JoH.releaseWakeLock(wl);
            } else if (path.equals(SYNC_LOGS_PATH)) {
                Log.d(TAG, "onDataChanged SYNC_LOGS_PATH=" + path);
                // requestData();
                dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
                if (dataMap != null) {
                    msg = dataMap.getString("syncLogsRequested", "");
                    int syncLogsRequested;
                    try {
                        syncLogsRequested = Integer.parseInt(msg);
                    } catch (NumberFormatException e) {
                        syncLogsRequested = 0;
                    }
                    Log.d(TAG, "onDataChanged Received SYNC_LOGS_PATH request syncLogsRequested=" + syncLogsRequested);
                    dataMap = getWearLogData(send_log_count, last_send_previous_log, (send_log_count / 3), syncLogsRequested);
                    if (dataMap != null) {
                        Log.i(TAG, "onDataChanged SYNC_LOGS_PATH Request from last log processed " + JoH.dateTimeText(last_send_previous_log));
                        sendData(SYNC_LOGS_PATH, dataMap.toByteArray());
                    } else {
                        Log.d(TAG, "SYNC_LOGS_PATH received! No outstanding logs! ACTION_SYNC_LOGS request completed!! Ongoing requests syncLogsRequested=" + syncLogsRequested);
                        if (syncLogsRequested > 0) {
                            sendSyncRequested(SYNC_LOGS_REQUESTED_PATH, syncLogsRequested);
                        }
                    }
                }
            } else if (path.equals(CLEAR_LOGS_PATH)) {
                Log.d(TAG, "onDataChanged CLEAR_LOGS_PATH=" + path);
                try {
                    UserError.cleanup();
                } catch (Exception e) {
                    Log.e(TAG, "onDataChanged CLEAR_LOGS_PATH exception on UserError ", e);
                }
            } else if (path.equals(CLEAR_TREATMENTS_PATH)) {
                Log.d(TAG, "onDataChanged CLEAR_TREATMENTS_PATH=" + path + " last_send_previous_treatments=" + JoH.dateTimeText(last_send_previous_treatments));
                try {
                    Treatments.cleanup(last_send_previous_treatments);
                } catch (Exception e) {
                    Log.e(TAG, "onDataChanged CLEAR_TREATMENTS_PATH exception on Treatments ", e);
                }
            } else if (path.equals(START_COLLECTOR_PATH)) {
                Log.d(TAG, "onDataChanged START_COLLECTOR_PATH=" + path);
                stopBtService();
                if (processConnect()) {
                    msg = getResources().getString(R.string.notify_collector_started, DexCollectionType.getDexCollectionType());
                    sendReplyMsg(msg, 0, path, true, Toast.LENGTH_SHORT);
                }
            } else if (path.equals(STATUS_COLLECTOR_PATH)) {
                Log.d(TAG, "onDataChanged path=" + path);
                dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
                G5CollectionService.getBatteryStatusNow = dataMap.getBoolean("getBatteryStatusNow", false);
                Ob1G5CollectionService.getBatteryStatusNow = dataMap.getBoolean("getBatteryStatusNow", false);
                sendCollectorStatus(getApplicationContext(), path);
                sendPersistentStore();
            } else if (path.equals(WEARABLE_SENSOR_DATA_PATH)) {
                // KS
                dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
                Log.d(TAG, "onDataChanged path=" + path + " DataMap=" + dataMap);
                syncSensorData(dataMap, getApplicationContext());
            } else if (path.equals(WEARABLE_ACTIVEBTDEVICE_DATA_PATH)) {
                // KS
                dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
                Log.d(TAG, "onDataChanged path=" + path + " DataMap=" + dataMap);
                syncActiveBtDeviceData(dataMap, getApplicationContext());
            } else if (path.equals(WEARABLE_ALERTTYPE_DATA_PATH)) {
                // KS
                dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
                Log.d(TAG, "onDataChanged path=" + path + " DataMap=" + dataMap);
                syncAlertTypeData(dataMap, getApplicationContext());
            } else if (path.equals(WEARABLE_TREATMENTS_DATA_PATH)) {
                // KS
                dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
                Log.d(TAG, "onDataChanged path=" + path + " DataMap=" + dataMap);
                syncTreatmentsData(dataMap, getApplicationContext());
            } else if (path.equals(WEARABLE_BLOODTEST_DATA_PATH)) {
                // KS
                dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
                Log.d(TAG, "onDataChanged path=" + path + " DataMap=" + dataMap);
                syncBloodTestData(dataMap, getApplicationContext());
            } else if (path.equals(WEARABLE_CALIBRATION_DATA_PATH)) {
                // KS
                dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
                Log.d(TAG, "onDataChanged path=" + path + " DataMap=" + dataMap);
                syncCalibrationData(dataMap, getApplicationContext());
            } else if (path.equals(WEARABLE_BG_DATA_PATH)) {
                // KS
                dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
                Log.d(TAG, "onDataChanged path=" + path + " DataMap=" + dataMap);
                syncBgData(dataMap, getApplicationContext());
            } else if (path.equals(WEARABLE_PREF_DATA_PATH)) {
                // KS
                dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
                Log.d(TAG, "onDataChanged path=" + path + " DataMap=" + dataMap);
                syncPrefData(dataMap);
            } else if (path.equals(WEARABLE_LOCALE_CHANGED_PATH)) {
                // KS
                dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
                Log.d(TAG, "onDataChanged path=" + path + " DataMap=" + dataMap);
                overrideLocale(dataMap);
            } else if (path.equals(DATA_ITEM_RECEIVED_PATH)) {
                // KS
                dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
                Log.d(TAG, "onDataChanged path=" + path + " DataMap=" + dataMap);
                String type = dataMap.getString("type", "");
                long timeOfLastEntry = dataMap.getLong("timeOfLastEntry", 0);
                long syncLogsRequested = dataMap.getLong("syncLogsRequested", -1);
                msg = dataMap.getString("msg", "");
                if (type != null && !type.isEmpty() && timeOfLastEntry > 0) {
                    // TODO duplicated sync tracking routines could be functionalized
                    switch(type) {
                        case "BG":
                            Log.d(TAG, "DATA_ITEM_RECEIVED_PATH received! Current last_send_previous=" + JoH.dateTimeText(last_send_previous));
                            Log.i(TAG, "DATA_ITEM_RECEIVED_PATH received! Received BGs confirmed up to " + JoH.dateTimeText(timeOfLastEntry));
                            if (timeOfLastEntry >= last_send_previous) {
                                last_send_previous = timeOfLastEntry;
                                PersistentStore.setLong(pref_last_send_previous, last_send_previous);
                                Log.d(TAG, "DATA_ITEM_RECEIVED_PATH received!  Updated last_send_previous=" + JoH.dateTimeText(last_send_previous));
                            } else {
                                Log.d(TAG, "DATA_ITEM_RECEIVED_PATH received! Duplicate confirmation! Ignore timeOfLastEntry=" + JoH.dateTimeText(timeOfLastEntry));
                            }
                            if (mPrefs.getBoolean("enable_wearG5", false)) {
                                dataMap = getWearTransmitterData(send_bg_count, last_send_previous, (send_bg_count / 3));
                                if (dataMap != null) {
                                    Log.i(TAG, "DATA_ITEM_RECEIVED_PATH received! New Request to sync BGs from " + JoH.dateTimeText(last_send_previous));
                                    sendData(SYNC_BGS_PATH, dataMap.toByteArray());
                                }
                            }
                            break;
                        case "LOG":
                            Log.d(TAG, "DATA_ITEM_RECEIVED_PATH received! Current last_send_previous_log=" + JoH.dateTimeText(last_send_previous_log));
                            Log.i(TAG, "DATA_ITEM_RECEIVED_PATH received! Received LOGS confirmed up to " + JoH.dateTimeText(timeOfLastEntry));
                            if (timeOfLastEntry >= last_send_previous_log) {
                                last_send_previous_log = timeOfLastEntry;
                                PersistentStore.setLong(pref_last_send_previous_log, last_send_previous_log);
                                Log.d(TAG, "DATA_ITEM_RECEIVED_PATH received!  Updated last_send_previous_log=" + JoH.dateTimeText(last_send_previous_log));
                            } else {
                                Log.d(TAG, "DATA_ITEM_RECEIVED_PATH received! Duplicate confirmation! Ignore timeOfLastEntry=" + JoH.dateTimeText(timeOfLastEntry));
                            }
                            if (mPrefs.getBoolean("sync_wear_logs", false)) {
                                dataMap = getWearLogData(send_log_count, last_send_previous_log, (send_log_count / 3), syncLogsRequested);
                                if (dataMap != null) {
                                    Log.i(TAG, "DATA_ITEM_RECEIVED_PATH received! New Request to sync LOGS from " + JoH.dateTimeText(last_send_previous_log));
                                    sendData(SYNC_LOGS_PATH, dataMap.toByteArray());
                                } else // Indicates this request was triggered by phone ACTION_SYNC_LOGS request; -1 indicates request was triggered by watch in doBackground()
                                if (syncLogsRequested > -1) {
                                    Log.d(TAG, "DATA_ITEM_RECEIVED_PATH received! No outstanding logs! ACTION_SYNC_LOGS request completed!! Ongoing requests syncLogsRequested=" + syncLogsRequested);
                                    sendSyncRequested(SYNC_LOGS_REQUESTED_PATH, syncLogsRequested);
                                } else
                                    Log.d(TAG, "DATA_ITEM_RECEIVED_PATH received! No outstanding logs! SYNC_LOGS_PATH request triggered by watch doBackground.  syncLogsRequested=" + syncLogsRequested);
                            }
                            break;
                        case "STEP":
                            Log.d(TAG, "DATA_ITEM_RECEIVED_PATH received! Current last_send_previous_step_sensor=" + JoH.dateTimeText(last_send_previous_step_sensor));
                            Log.i(TAG, "DATA_ITEM_RECEIVED_PATH received! Received Steps confirmed up to " + JoH.dateTimeText(timeOfLastEntry));
                            last_send_previous_step_sensor = timeOfLastEntry;
                            PersistentStore.setLong(pref_last_send_previous_step_sensor, last_send_previous_step_sensor);
                            Log.d(TAG, "DATA_ITEM_RECEIVED_PATH received!  Updated last_send_previous_step_sensor=" + JoH.dateTimeText(last_send_previous_step_sensor));
                            if (mPrefs.getBoolean("use_wear_health", false)) {
                                dataMap = getWearStepSensorData(send_step_count, last_send_previous_step_sensor, (send_step_count / 3));
                                if (dataMap != null) {
                                    Log.i(TAG, "DATA_ITEM_RECEIVED_PATH received! New Request to sync Steps from " + JoH.dateTimeText(last_send_previous_step_sensor));
                                    sendData(SYNC_STEP_SENSOR_PATH, dataMap.toByteArray());
                                }
                            }
                            break;
                        case "HEART":
                            Log.d(TAG, "DATA_ITEM_RECEIVED_PATH received! Current last_send_previous_heart_sensor=" + JoH.dateTimeText(last_send_previous_heart_sensor));
                            Log.i(TAG, "DATA_ITEM_RECEIVED_PATH received! Received Heart confirmed up to " + JoH.dateTimeText(timeOfLastEntry));
                            last_send_previous_heart_sensor = timeOfLastEntry;
                            PersistentStore.setLong(pref_last_send_previous_heart_sensor, last_send_previous_heart_sensor);
                            Log.d(TAG, "DATA_ITEM_RECEIVED_PATH received!  Updated last_send_previous_heart_sensor=" + JoH.dateTimeText(last_send_previous_heart_sensor));
                            if (mPrefs.getBoolean("use_wear_health", false)) {
                                dataMap = getWearHeartSensorData(send_heart_count, last_send_previous_heart_sensor, (send_heart_count / 3));
                                if (dataMap != null) {
                                    Log.i(TAG, "DATA_ITEM_RECEIVED_PATH received! New Request to sync heart from " + JoH.dateTimeText(last_send_previous_heart_sensor));
                                    sendData(SYNC_HEART_SENSOR_PATH, dataMap.toByteArray());
                                }
                            }
                            break;
                        case "TREATMENTS":
                            Log.d(TAG, "DATA_ITEM_RECEIVED_PATH received! Current last_send_previous_treatments=" + JoH.dateTimeText(last_send_previous_treatments));
                            Log.i(TAG, "DATA_ITEM_RECEIVED_PATH received! Received treatments confirmed up to " + JoH.dateTimeText(timeOfLastEntry));
                            if (timeOfLastEntry >= last_send_previous_treatments) {
                                last_send_previous_treatments = timeOfLastEntry;
                                PersistentStore.setLong(pref_last_send_previous_treatments, last_send_previous_treatments);
                                Log.d(TAG, "DATA_ITEM_RECEIVED_PATH received!  Updated last_send_previous_treatments=" + JoH.dateTimeText(last_send_previous_treatments));
                                // delete BloodTest entered via keypad
                                Treatments.cleanupBloodTest(last_send_previous_treatments);
                            } else {
                                Log.d(TAG, "DATA_ITEM_RECEIVED_PATH received! Duplicate confirmation! Ignore timeOfLastEntry=" + JoH.dateTimeText(timeOfLastEntry));
                            }
                            dataMap = getWearTreatmentsData(send_treatments_count, last_send_previous_treatments, (send_treatments_count / 4));
                            if (dataMap != null) {
                                Log.i(TAG, "DATA_ITEM_RECEIVED_PATH received! New Request to sync treatments from " + JoH.dateTimeText(last_send_previous_treatments));
                                sendData(SYNC_TREATMENTS_PATH, dataMap.toByteArray());
                            }
                            break;
                        case "BM":
                            Log.d(TAG, "Benchmark: onDataChanged received from sendDataReceived timeOfLastEntry=" + JoH.dateTimeText(timeOfLastEntry) + " Path=" + path);
                            Log.d(TAG, "Benchmark: onDataChanged DATA_ITEM_RECEIVED_PATH msg=" + msg);
                            break;
                    }
                }
            /* TODO remove once confirm not needed
                    if (doDeleteDB && isSafeToDeleteDB()) {
                        doDeleteDB = false;
                        Sensor.DeleteAndInitDb(getApplicationContext());
                        PersistentStore.setLong(pref_last_send_previous, 0);
                        PersistentStore.setLong(pref_last_send_previous_log, 0);
                        sendData(WEARABLE_INITDB_PATH, null);
                    }*/
            }
        }
    }
}
Also used : Context(android.content.Context) PowerManager(android.os.PowerManager) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) DataEvent(com.google.android.gms.wearable.DataEvent) DataMap(com.google.android.gms.wearable.DataMap)

Example 59 with DataMap

use of com.google.android.gms.wearable.DataMap in project xDrip-plus by jamorham.

the class ListenerService method overrideLocale.

public boolean overrideLocale(DataMap dataMap) {
    if (mPrefs.getBoolean("overrideLocale", false)) {
        String localeStr = dataMap.getString("locale", "");
        String[] locale = localeStr.split("_");
        final Locale newLocale = locale == null ? new Locale(localeStr) : locale.length > 1 ? new Locale(locale[0], locale[1]) : new Locale(locale[0]);
        final Locale oldLocale = Locale.getDefault();
        if (newLocale != null && !oldLocale.equals(newLocale)) {
            try {
                Log.d(TAG, "overrideLocale locale from " + oldLocale + " to " + newLocale);
                Context context = getApplicationContext();
                final Resources resources = context.getResources();
                final DisplayMetrics metrics = resources.getDisplayMetrics();
                final Configuration config = resources.getConfiguration();
                config.locale = newLocale;
                resources.updateConfiguration(config, metrics);
                Locale.setDefault(newLocale);
                Log.d(TAG, "overrideLocale default locale " + Locale.getDefault() + " resource locale " + context.getResources().getConfiguration().locale);
                DataMap dm = new DataMap();
                dm.putString("locale", localeStr);
                sendLocalMessage("locale", dm);
                return true;
            } catch (Exception e) {
                Log.e(TAG, "overrideLocale Exception e: " + e);
            }
        }
    }
    return false;
}
Also used : Locale(java.util.Locale) Context(android.content.Context) Configuration(android.content.res.Configuration) Resources(android.content.res.Resources) DisplayMetrics(android.util.DisplayMetrics) DataMap(com.google.android.gms.wearable.DataMap)

Example 60 with DataMap

use of com.google.android.gms.wearable.DataMap in project xDrip-plus by jamorham.

the class ListenerService method getWearTreatmentsData.

private synchronized DataMap getWearTreatmentsData(int count, long last_send_time, int min_count) {
    forceGoogleApiConnect();
    Log.d(TAG, "getWearTreatmentsData last_send_time:" + JoH.dateTimeText(last_send_time) + " max count=" + count + " min_count=" + min_count);
    Treatments last_log = Treatments.lastSystime();
    if (last_log != null) {
        Log.d(TAG, "getWearTreatmentsData last systimestamp: " + last_log.systimestamp + " " + JoH.dateTimeText((long) last_log.systimestamp));
    }
    if (last_log != null && last_log.systimestamp > 0 && last_send_time <= last_log.systimestamp) {
        // startTime
        long last_send_success = last_send_time;
        Log.d(TAG, "getWearTreatmentsData last_send_time < last_log.timestamp:" + JoH.dateTimeText((long) last_log.systimestamp));
        List<Treatments> logs = Treatments.latestForGraphSystime(count, last_send_time);
        if (!logs.isEmpty() && logs.size() > min_count) {
            // Log.d(TAG, "getWearLogData count = " + logs.size());
            DataMap entries = dataMap(last_log);
            final ArrayList<DataMap> dataMaps = new ArrayList<>(logs.size());
            for (Treatments log : logs) {
                dataMaps.add(dataMap(log));
                last_send_success = (long) log.systimestamp;
            // Log.d(TAG, "getWearTreatmentsData set last_send_sucess:" + JoH.dateTimeText(last_send_sucess) + " Log:" + log.toString());
            }
            // MOST IMPORTANT LINE FOR TIMESTAMP
            entries.putLong("time", new Date().getTime());
            entries.putDataMapArrayList("entries", dataMaps);
            Log.i(TAG, "getWearTreatmentsData SYNCED treatments up to " + JoH.dateTimeText(last_send_success) + " count = " + logs.size());
            return entries;
        } else
            Log.i(TAG, "getWearTreatmentsData SYNCED treatments up to " + JoH.dateTimeText(last_send_success) + " count = 0");
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) Treatments(com.eveningoutpost.dexdrip.Models.Treatments) Date(java.util.Date) DataMap(com.google.android.gms.wearable.DataMap)

Aggregations

DataMap (com.google.android.gms.wearable.DataMap)147 Date (java.util.Date)38 ArrayList (java.util.ArrayList)36 Gson (com.google.gson.Gson)18 Intent (android.content.Intent)17 GsonBuilder (com.google.gson.GsonBuilder)16 DateTypeAdapter (com.google.gson.internal.bind.DateTypeAdapter)16 BgReading (com.eveningoutpost.dexdrip.Models.BgReading)12 Sensor (com.eveningoutpost.dexdrip.Models.Sensor)12 PendingIntent (android.app.PendingIntent)11 Context (android.content.Context)8 Calibration (com.eveningoutpost.dexdrip.Models.Calibration)8 Treatments (com.eveningoutpost.dexdrip.Models.Treatments)8 Bundle (android.os.Bundle)6 HeartRate (com.eveningoutpost.dexdrip.Models.HeartRate)6 Paint (android.graphics.Paint)5 BloodTest (com.eveningoutpost.dexdrip.Models.BloodTest)5 BroadcastReceiver (android.content.BroadcastReceiver)4 SharedPreferences (android.content.SharedPreferences)4 Point (android.graphics.Point)4