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

The following examples show how to use com.google.android.gms.wearable.DataMap#containsKey() . 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: DigitalWatchFaceService.java    From wear-os-samples with Apache License 2.0 6 votes vote down vote up
private void updateUiForConfigDataMap(final DataMap config) {
    boolean uiUpdated = false;
    for (String configKey : config.keySet()) {
        if (!config.containsKey(configKey)) {
            continue;
        }
        int color = config.getInt(configKey);
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "Found watch face config key: " + configKey + " -> "
                    + Integer.toHexString(color));
        }
        if (updateUiForKey(configKey, color)) {
            uiUpdated = true;
        }
    }
    if (uiUpdated) {
        invalidate();
    }
}
 
Example 2
Source File: AndroidWear.java    From ibm-wearables-android-sdk with Apache License 2.0 6 votes vote down vote up
private void triggerAccelerometerUpdate(DataMap dataMap){

        final String ACCELEROMETER_KEY = "accelerometer";

        if (dataMap.containsKey(ACCELEROMETER_KEY)){
            ArrayList<DataMap> accelerometerDataArrayList = dataMap.getDataMapArrayList(ACCELEROMETER_KEY);

            for (DataMap accelerometerDataMap : accelerometerDataArrayList){

                float[] values = accelerometerDataMap.getFloatArray("values");

                AccelerometerData data = new AccelerometerData();
                data.x = values[0];
                data.y = values[1];
                data.z = values[2];

                accelerometerSensorEvents.dataEvent.trigger(data);
            }
        }
    }
 
Example 3
Source File: SunsetsWatchFace.java    From american-sunsets-watch-face with Apache License 2.0 6 votes vote down vote up
private void updateUiForConfigDataMap(final DataMap config) {
    boolean uiUpdated = false;
    for (String configKey : config.keySet()) {
        if (!config.containsKey(configKey)) {
            continue;
        }
        int color = config.getInt(configKey);
        Log.d(TAG, "Found watch face config key: " + configKey + " -> "
                    + color);

        if (updateUiForKey(configKey, color)) {
            uiUpdated = true;
        }
    }
    if (uiUpdated) {
        invalidate();
    }
}
 
Example 4
Source File: AndroidWear.java    From ibm-wearables-android-sdk with Apache License 2.0 5 votes vote down vote up
private void trigerHeartRateUpdate(DataMap dataMap) {
    final String HEART_RATE_KEY = "heartrate";

    if (dataMap.containsKey(HEART_RATE_KEY)){
        float heartRate = dataMap.getFloat(HEART_RATE_KEY);

        HeartRateData data = new HeartRateData(heartRate);
        heartRateSensorEvents.dataEvent.trigger(data);
    }
}
 
Example 5
Source File: ListenerService.java    From sms-ticket with Apache License 2.0 5 votes vote down vote up
/**
 * Handles received data.
 */
private void handleDataChanged(DataMap data) {
    if (data.containsKey("cities")) {
        processCityList(data);
    } else if (data.containsKey("tickets")) {
        processTicketsList(data);
    } else if (data.containsKey("notification")) {
        processNotification(data);
    } else if (data.containsKey("error_message")) {
        BusProvider.getInstance().post(new ErrorEvent(data.getString("error_message")));
    }
}
 
Example 6
Source File: ListenerService.java    From PowerSwitch_Android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * This method converts received data contained in a DataMap Array back to Scenes.
 *
 * @param dataMapArrayList received data
 * @return List of Rooms containing the appropriate Receivers and Buttons
 */
public static ArrayList<Scene> extractSceneDataMapItems(ArrayList<DataMap> dataMapArrayList) {
    ArrayList<Scene> scenes = new ArrayList<>();

    for (DataMap dataMapItem : dataMapArrayList) {
        if (dataMapItem.containsKey(WearableConstants.SCENE_NAME_DATAMAP_KEY)) {
            long sceneId = dataMapItem.getLong(WearableConstants.SCENE_ID_DATAMAP_KEY);
            String sceneName = dataMapItem.getString(WearableConstants.SCENE_NAME_DATAMAP_KEY);
            Scene scene = new Scene(sceneId, sceneName);
            scenes.add(scene);
        }
    }

    return scenes;
}
 
Example 7
Source File: SunsetsGeneralWearableConfigActivity.java    From american-sunsets-watch-face with Apache License 2.0 5 votes vote down vote up
private void updateUiForConfigDataMap(final DataMap config) {
    boolean uiUpdated = false;
    for (String configKey : config.keySet()) {
        if (!config.containsKey(configKey)) {
            continue;
        }
        int color = config.getInt(configKey);
        Log.d(TAG, "Found watch face config key: " + configKey + " -> "
                + color);

        if (updateUiForKey(configKey, color)) {
            uiUpdated = true;
        }
    }
}
 
Example 8
Source File: WatchFaceCompanionConfigActivity.java    From american-sunsets-watch-face with Apache License 2.0 5 votes vote down vote up
private void updateUiForConfigDataMap(final DataMap config) {
    boolean uiUpdated = false;
    for (String configKey : config.keySet()) {
        if (!config.containsKey(configKey)) {
            continue;
        }
        int color = config.getInt(configKey);
        Log.d(TAG, "Found watch face config key: " + configKey + " -> "
                    + color);

        if (updateUiForKey(configKey, color)) {
            uiUpdated = true;
        }
    }
}
 
Example 9
Source File: WearableLocationService.java    From android_packages_apps_GmsCore with Apache License 2.0 5 votes vote down vote up
public static Collection<LocationRequestInternal> readLocationRequestList(DataMap dataMap, Context context) {
    if (!dataMap.containsKey("REQUEST_LIST")) {
        Log.w(TAG, "malformed DataMap: missing key REQUEST_LIST");
        return Collections.emptyList();
    }
    List<DataMap> requestMapList = dataMap.getDataMapArrayList("REQUEST_LIST");
    List<LocationRequestInternal> locationRequests = new ArrayList<LocationRequestInternal>();
    for (DataMap map : requestMapList) {
        locationRequests.add(readLocationRequest(map, context));
    }
    return locationRequests;
}
 
Example 10
Source File: WearableLocationService.java    From android_packages_apps_GmsCore with Apache License 2.0 5 votes vote down vote up
private static LocationRequestInternal readLocationRequest(DataMap dataMap, Context context) {
    LocationRequestInternal request = new LocationRequestInternal();
    request.triggerUpdate = true;
    request.request = new LocationRequest();
    request.clients = Collections.emptyList();

    if (dataMap.containsKey("PRIORITY"))
        request.request.setPriority(dataMap.getInt("PRIORITY", 0));
    if (dataMap.containsKey("INTERVAL_MS"))
        request.request.setInterval(dataMap.getLong("INTERVAL_MS", 0));
    if (dataMap.containsKey("FASTEST_INTERVAL_MS"))
        request.request.setFastestInterval(dataMap.getLong("FASTEST_INTERVAL_MS", 0));
    //if (dataMap.containsKey("MAX_WAIT_TIME_MS"))
    if (dataMap.containsKey("SMALLEST_DISPLACEMENT_METERS"))
        request.request.setSmallestDisplacement(dataMap.getFloat("SMALLEST_DISPLACEMENT_METERS", 0));
    if (dataMap.containsKey("NUM_UPDATES"))
        request.request.setNumUpdates(dataMap.getInt("NUM_UPDATES", 0));
    if (dataMap.containsKey("EXPIRATION_DURATION_MS"))
        request.request.setExpirationDuration(dataMap.getLong("EXPIRATION_DURATION_MS", 0));
    if (dataMap.containsKey("TAG"))
        request.tag = dataMap.getString("TAG");
    if (dataMap.containsKey("CLIENTS_PACKAGE_ARRAY")) {
        String[] packages = dataMap.getStringArray("CLIENTS_PACKAGE_ARRAY");
        if (packages != null) {
            request.clients = new ArrayList<ClientIdentity>();
            for (String packageName : packages) {
                request.clients.add(generateClientIdentity(packageName, context));
            }
        }
    }

    return request;
}
 
Example 11
Source File: DigitalWatchFaceService.java    From wear-os-samples with Apache License 2.0 4 votes vote down vote up
private void addIntKeyIfMissing(DataMap config, String key, int color) {
    if (!config.containsKey(key)) {
        config.putInt(key, color);
    }
}
 
Example 12
Source File: PixelWatchFace.java    From PixelWatchFace with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
  String TAG = "onDataChanged";
  Log.d(TAG, "Data changed");
  DataMap dataMap = new DataMap();
  for (DataEvent event : dataEvents) {
    if (event.getType() == DataEvent.TYPE_CHANGED) {
      // DataItem changed
      DataItem item = event.getDataItem();
      Log.d(TAG, "DataItem uri: " + item.getUri());

      if (item.getUri().getPath().compareTo("/settings") == 0) {
        Log.d(TAG, "Companion app changed a setting!");
        dataMap = DataMapItem.fromDataItem(item).getDataMap();
        Log.d(TAG, dataMap.toString());

        // handle legacy nested data map
        if (dataMap.containsKey("com.corvettecole.pixelwatchface")) {
          dataMap = dataMap.getDataMap("com.corvettecole.pixelwatchface");
        }

        Log.d(TAG, dataMap.toString());

        for (UpdatesRequired updateRequired : mSettings.updateSettings(dataMap)) {
          switch (updateRequired) {
            case WEATHER:
              initWeatherUpdater(true);
              break;
            case FONT:
              updateFontConfig();
              break;
          }
        }

        invalidate();// forces redraw
        //syncToPhone();
      } else if (item.getUri().getPath().compareTo("/requests") == 0) {
        if (dataMap.containsKey("settings-update")) {

        }
      }


    } else if (event.getType() == DataEvent.TYPE_DELETED) {
      // DataItem deleted
    }
  }
}
 
Example 13
Source File: AndroidWear.java    From ibm-wearables-android-sdk with Apache License 2.0 4 votes vote down vote up
private void triggerGyroscopeUpdate(DataMap dataMap) {

        final String GYROSCOPE_KEY = "gyroscope";

        if (dataMap.containsKey(GYROSCOPE_KEY)){
            ArrayList<DataMap> gyroscopeDataArrayList = dataMap.getDataMapArrayList(GYROSCOPE_KEY);

            for (DataMap gyroscopeDataMap : gyroscopeDataArrayList){

                float[] values = gyroscopeDataMap.getFloatArray("values");

                GyroscopeData data = new GyroscopeData();

                data.x = values[0];
                data.y = values[1];
                data.z = values[2];

                gyroscopeSensorEvents.dataEvent.trigger(data);
            }
        }
    }
 
Example 14
Source File: SunsetsWatchFace.java    From american-sunsets-watch-face with Apache License 2.0 4 votes vote down vote up
private void addIntKeyIfMissing(DataMap config, String key, int color) {
    if (!config.containsKey(key)) {
        config.putInt(key, color);
    }
}
 
Example 15
Source File: NotificationListenerService.java    From wear-notify-for-reddit with Apache License 2.0 4 votes vote down vote up
private void createNotificationForPost(DataMap dataMap, boolean openOnPhoneDismisses,
                                       ArrayList<Integer> actionOrder, Bitmap themeBlueBitmap,
                                       NotificationManager notificationManager, Post post) {
    try {
        Bitmap backgroundBitmap = null;
        if (dataMap.containsKey(post.getId()) && dataMap.getAsset(post.getId()) != null) {
            backgroundBitmap = loadBitmapFromAsset(dataMap.getAsset(post.getId()));
        }

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setContentTitle(
                post.getTitle())
                .setContentText(post.getPostContents())
                .setSmallIcon(R.drawable.ic_launcher);

        boolean hasCachedImage;
        if (backgroundBitmap != null) {
            // If the post has a thumbnail, use it - this will filter out nfsw etc thumbnails
            // but will still allow the user to see the full image if they like
            builder.setLargeIcon(backgroundBitmap);
            hasCachedImage = cacheBackgroundToDisk(sNotificationId, backgroundBitmap);
        } else {
            hasCachedImage = false;
            setBlueBackground(themeBlueBitmap, builder);
            enableNotificationGrouping(builder);
        }

        addActions(actionOrder,
                openOnPhoneDismisses,
                hasCachedImage,
                post,
                sNotificationId,
                builder);

        if (hasCachedImage) {
            // When the notification is dismissed, we will remove this image from the file cache
            builder.setDeleteIntent(getDeletePendingIntent(sNotificationId));
        }

        notificationManager.notify(sNotificationId, builder.build());

        if (backgroundBitmap != null) {
            backgroundBitmap.recycle();
        }

        sNotificationId += NOTIFICATION_ID_INCREMENT;
        sendBroadcast(new Intent(getString(R.string.force_finish_main_activity)));
    } catch (Exception e) {
        logErrorToPhone("Failed to create notification for post: " + post, e);
    }
}