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

The following examples show how to use com.google.android.gms.wearable.DataMap#putBoolean() . 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: CalendarQueryService.java    From AndroidWearable-Samples with Apache License 2.0 6 votes vote down vote up
public PutDataMapRequest toPutDataMapRequest(){
    final PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(
            makeDataItemPath(eventId, begin));
    DataMap data = putDataMapRequest.getDataMap();
    data.putString(DATA_ITEM_URI, putDataMapRequest.getUri().toString());
    data.putLong(ID, id);
    data.putLong(EVENT_ID, eventId);
    data.putString(TITLE, title);
    data.putLong(BEGIN, begin);
    data.putLong(END, end);
    data.putBoolean(ALL_DAY, allDay);
    data.putString(DESCRIPTION, description);
    data.putAsset(PROFILE_PIC, ownerProfilePic);

    return putDataMapRequest;
}
 
Example 2
Source File: WatchUpdaterService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private void sendActiveBtDeviceData() {//KS
    if (is_using_bt) {//only required for Collector running on watch
        forceGoogleApiConnect();
        ActiveBluetoothDevice btDevice = ActiveBluetoothDevice.first();
        if (btDevice != null) {
            if (wear_integration) {
                DataMap dataMap = new DataMap();
                Log.d(TAG, "sendActiveBtDeviceData name=" + btDevice.name + " address=" + btDevice.address + " connected=" + btDevice.connected);

                dataMap.putLong("time", new Date().getTime()); // MOST IMPORTANT LINE FOR TIMESTAMP

                dataMap.putString("name", btDevice.name);
                dataMap.putString("address", btDevice.address);
                dataMap.putBoolean("connected", btDevice.connected);

                new SendToDataLayerThread(WEARABLE_ACTIVEBTDEVICE_DATA_PATH, googleApiClient).executeOnExecutor(xdrip.executor, dataMap);
            }
        }
    } else {
        Log.d(TAG, "Not sending activebluetoothdevice data as we are not using bt");
    }
}
 
Example 3
Source File: MainActivity.java    From AndroidWearable-Samples with Apache License 2.0 6 votes vote down vote up
@Override
public void onResult(DataApi.DataItemResult dataItemResult) {
    if (dataItemResult.getStatus().isSuccess()) {
        PutDataMapRequest request = PutDataMapRequest.createFromDataMapItem(
                        DataMapItem.fromDataItem(dataItemResult.getDataItem()));
        DataMap dataMap = request.getDataMap();
        dataMap.putBoolean(QUESTION_WAS_ANSWERED, false);
        dataMap.putBoolean(QUESTION_WAS_DELETED, false);
        if (!mHasQuestionBeenAsked && dataMap.getInt(QUESTION_INDEX) == 0) {
            // Ask the first question now.
            Wearable.DataApi.putDataItem(mGoogleApiClient, request.asPutDataRequest());
            setHasQuestionBeenAsked(true);
        } else {
            // Enqueue future questions.
            mFutureQuestions.add(new Question(dataMap.getString(QUESTION),
                    dataMap.getInt(QUESTION_INDEX), dataMap.getStringArray(ANSWERS),
                    dataMap.getInt(CORRECT_ANSWER_INDEX)));
        }
    } else {
        Log.e(TAG, "Failed to reset data item " + dataItemResult.getDataItem().getUri());
    }
}
 
Example 4
Source File: WatchUpdaterService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private void sendActiveBtDeviceData() {//KS
    if (is_using_bt) {//only required for Collector running on watch
        forceGoogleApiConnect();
        ActiveBluetoothDevice btDevice = ActiveBluetoothDevice.first();
        if (btDevice != null) {
            if (wear_integration) {
                DataMap dataMap = new DataMap();
                Log.d(TAG, "sendActiveBtDeviceData name=" + btDevice.name + " address=" + btDevice.address + " connected=" + btDevice.connected);

                dataMap.putLong("time", new Date().getTime()); // MOST IMPORTANT LINE FOR TIMESTAMP

                dataMap.putString("name", btDevice.name);
                dataMap.putString("address", btDevice.address);
                dataMap.putBoolean("connected", btDevice.connected);

                new SendToDataLayerThread(WEARABLE_ACTIVEBTDEVICE_DATA_PATH, googleApiClient).executeOnExecutor(xdrip.executor, dataMap);
            }
        }
    } else {
        Log.d(TAG, "Not sending activebluetoothdevice data as we are not using bt");
    }
}
 
Example 5
Source File: DeleteQuestionService.java    From AndroidWearable-Samples with Apache License 2.0 6 votes vote down vote up
@Override
public void onHandleIntent(Intent intent) {
    mGoogleApiClient.blockingConnect(CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
    Uri dataItemUri = intent.getData();
    if (!mGoogleApiClient.isConnected()) {
        Log.e(TAG, "Failed to update data item " + dataItemUri
                + " because client is disconnected from Google Play Services");
        return;
    }
    DataApi.DataItemResult dataItemResult = Wearable.DataApi.getDataItem(
            mGoogleApiClient, dataItemUri).await();
    PutDataMapRequest putDataMapRequest = PutDataMapRequest
            .createFromDataMapItem(DataMapItem.fromDataItem(dataItemResult.getDataItem()));
    DataMap dataMap = putDataMapRequest.getDataMap();
    dataMap.putBoolean(QUESTION_WAS_DELETED, true);
    PutDataRequest request = putDataMapRequest.asPutDataRequest();
    Wearable.DataApi.putDataItem(mGoogleApiClient, request).await();
    mGoogleApiClient.disconnect();
}
 
Example 6
Source File: RawDisplayDataStatusTest.java    From AndroidAPS with GNU Affero General Public License v3.0 6 votes vote down vote up
private DataMap dataMapForStatus() {
    DataMap dataMap = new DataMap();
    dataMap.putString("currentBasal", "120%");
    dataMap.putString("battery", "76");
    dataMap.putString("rigBattery", "40%");
    dataMap.putBoolean("detailedIob", true);
    dataMap.putString("iobSum", "12.5") ;
    dataMap.putString("iobDetail","(11,2|1,3)");
    dataMap.putString("cob","5(10)g");
    dataMap.putString("bgi", "13");
    dataMap.putBoolean("showBgi", false);
    dataMap.putString("externalStatusString", "");
    dataMap.putInt("batteryLevel", 1);
    dataMap.putLong("openApsStatus", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*2);
    return dataMap;
}
 
Example 7
Source File: MainActivity.java    From android-Quiz with Apache License 2.0 6 votes vote down vote up
@Override
public void onResult(DataApi.DataItemResult dataItemResult) {
    if (dataItemResult.getStatus().isSuccess()) {
        PutDataMapRequest request = PutDataMapRequest.createFromDataMapItem(
                DataMapItem.fromDataItem(dataItemResult.getDataItem()));
        DataMap dataMap = request.getDataMap();
        dataMap.putBoolean(QUESTION_WAS_ANSWERED, false);
        dataMap.putBoolean(QUESTION_WAS_DELETED, false);
        if (!mHasQuestionBeenAsked && dataMap.getInt(QUESTION_INDEX) == 0) {
            // Ask the first question now.
            PutDataRequest putDataRequest = request.asPutDataRequest();
            // Set to high priority in case it isn't already.
            putDataRequest.setUrgent();
            Wearable.DataApi.putDataItem(mGoogleApiClient, putDataRequest);
            setHasQuestionBeenAsked(true);
        } else {
            // Enqueue future questions.
            mFutureQuestions.add(new Question(dataMap.getString(QUESTION),
                    dataMap.getInt(QUESTION_INDEX), dataMap.getStringArray(ANSWERS),
                    dataMap.getInt(CORRECT_ANSWER_INDEX)));
        }
    } else {
        Log.e(TAG, "Failed to reset data item " + dataItemResult.getDataItem().getUri());
    }
}
 
Example 8
Source File: DeleteQuestionService.java    From android-Quiz with Apache License 2.0 6 votes vote down vote up
@Override
public void onHandleIntent(Intent intent) {
    mGoogleApiClient.blockingConnect(CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
    Uri dataItemUri = intent.getData();
    if (!mGoogleApiClient.isConnected()) {
        Log.e(TAG, "Failed to update data item " + dataItemUri
                + " because client is disconnected from Google Play Services");
        return;
    }
    DataApi.DataItemResult dataItemResult = Wearable.DataApi.getDataItem(
            mGoogleApiClient, dataItemUri).await();
    PutDataMapRequest putDataMapRequest = PutDataMapRequest
            .createFromDataMapItem(DataMapItem.fromDataItem(dataItemResult.getDataItem()));
    DataMap dataMap = putDataMapRequest.getDataMap();
    dataMap.putBoolean(QUESTION_WAS_DELETED, true);
    PutDataRequest request = putDataMapRequest.asPutDataRequest();
    request.setUrgent();
    Wearable.DataApi.putDataItem(mGoogleApiClient, request).await();
    mGoogleApiClient.disconnect();
}
 
Example 9
Source File: UtilityService.java    From PowerSwitch_Android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get Wearable settings and put them into a DataMap
 *
 * @return DataMap containing all Wearable settings
 */
private DataMap getSettingsDataMap() {
    DataMap settingsDataMap = new DataMap();
    settingsDataMap.putBoolean(WearableSettingsConstants.AUTO_COLLAPSE_ROOMS_KEY, WearablePreferencesHandler
            .getAutoCollapseRooms());
    settingsDataMap.putBoolean(WearableSettingsConstants.HIGHLIGHT_LAST_ACTIVATED_BUTTON_KEY, WearablePreferencesHandler
            .getHighlightLastActivatedButton());
    settingsDataMap.putBoolean(WearableSettingsConstants.SHOW_ROOM_ALL_ON_OFF_KEY, WearablePreferencesHandler.getShowRoomAllOnOff());
    settingsDataMap.putInt(WearableSettingsConstants.THEME_KEY, WearablePreferencesHandler.getTheme());
    settingsDataMap.putBoolean(WearableSettingsConstants.VIBRATE_ON_BUTTON_PRESS_KEY, WearablePreferencesHandler
            .getVibrateOnButtonPress());
    settingsDataMap.putInt(WearableSettingsConstants.VIBRATION_DURATION_KEY, WearablePreferencesHandler.getVibrationDuration());

    return settingsDataMap;
}
 
Example 10
Source File: UpdateQuestionService.java    From AndroidWearable-Samples with Apache License 2.0 5 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {
    mGoogleApiClient.blockingConnect(TIME_OUT_MS, TimeUnit.MILLISECONDS);
    Uri dataItemUri = intent.getData();
    if (!mGoogleApiClient.isConnected()) {
        Log.e(TAG, "Failed to update data item " + dataItemUri
                + " because client is disconnected from Google Play Services");
        return;
    }
    DataApi.DataItemResult dataItemResult = Wearable.DataApi.getDataItem(
            mGoogleApiClient, dataItemUri).await();
    PutDataMapRequest putDataMapRequest = PutDataMapRequest
            .createFromDataMapItem(DataMapItem.fromDataItem(dataItemResult.getDataItem()));
    DataMap dataMap = putDataMapRequest.getDataMap();

    // Update quiz status variables, which will be reflected on the phone.
    int questionIndex = intent.getIntExtra(EXTRA_QUESTION_INDEX, -1);
    boolean chosenAnswerCorrect = intent.getBooleanExtra(EXTRA_QUESTION_CORRECT, false);
    dataMap.putInt(QUESTION_INDEX, questionIndex);
    dataMap.putBoolean(CHOSEN_ANSWER_CORRECT, chosenAnswerCorrect);
    dataMap.putBoolean(QUESTION_WAS_ANSWERED, true);
    PutDataRequest request = putDataMapRequest.asPutDataRequest();
    Wearable.DataApi.putDataItem(mGoogleApiClient, request).await();

    // Remove this question notification.
    ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).cancel(questionIndex);
    mGoogleApiClient.disconnect();
}
 
Example 11
Source File: UpdateQuestionService.java    From android-Quiz with Apache License 2.0 5 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {
    mGoogleApiClient.blockingConnect(TIME_OUT_MS, TimeUnit.MILLISECONDS);
    Uri dataItemUri = intent.getData();
    if (!mGoogleApiClient.isConnected()) {
        Log.e(TAG, "Failed to update data item " + dataItemUri
                + " because client is disconnected from Google Play Services");
        return;
    }
    DataApi.DataItemResult dataItemResult = Wearable.DataApi.getDataItem(
            mGoogleApiClient, dataItemUri).await();
    PutDataMapRequest putDataMapRequest = PutDataMapRequest
            .createFromDataMapItem(DataMapItem.fromDataItem(dataItemResult.getDataItem()));
    DataMap dataMap = putDataMapRequest.getDataMap();

    // Update quiz status variables, which will be reflected on the phone.
    int questionIndex = intent.getIntExtra(EXTRA_QUESTION_INDEX, -1);
    boolean chosenAnswerCorrect = intent.getBooleanExtra(EXTRA_QUESTION_CORRECT, false);
    dataMap.putInt(QUESTION_INDEX, questionIndex);
    dataMap.putBoolean(CHOSEN_ANSWER_CORRECT, chosenAnswerCorrect);
    dataMap.putBoolean(QUESTION_WAS_ANSWERED, true);
    PutDataRequest request = putDataMapRequest.asPutDataRequest();
    request.setUrgent();
    Wearable.DataApi.putDataItem(mGoogleApiClient, request).await();

    // Remove this question notification.
    ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).cancel(questionIndex);
    mGoogleApiClient.disconnect();
}
 
Example 12
Source File: ListenerService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private void sendPrefSettings() {//KS

        Log.d(TAG, "sendPrefSettings enter");
        forceGoogleApiConnect();
        DataMap dataMap = new DataMap();
        boolean enable_wearG5 = mPrefs.getBoolean("enable_wearG5", false);
        boolean force_wearG5 = mPrefs.getBoolean("force_wearG5", false);
        String node_wearG5 = mPrefs.getString("node_wearG5", "");
        String dex_txid = mPrefs.getString("dex_txid", "ABCDEF");
        boolean show_wear_treatments = mPrefs.getBoolean("show_wear_treatments", false);

        if (localnode == null || (localnode != null && localnode.isEmpty())) setLocalNodeName();
        Log.d(TAG, "sendPrefSettings enable_wearG5: " + enable_wearG5 + " force_wearG5:" + force_wearG5 + " node_wearG5:" + node_wearG5 + " localnode:" + localnode + " dex_txid:" + dex_txid + " show_wear_treatments:" + show_wear_treatments);
        dataMap.putLong("time", new Date().getTime()); // MOST IMPORTANT LINE FOR TIMESTAMP
        dataMap.putBoolean("enable_wearG5", enable_wearG5);
        dataMap.putBoolean("force_wearG5", force_wearG5);
        if (force_wearG5) {
            dataMap.putString("node_wearG5", localnode);
        } else {
            if (node_wearG5.equals(localnode)) {
                dataMap.putString("node_wearG5", "");
            } else {
                dataMap.putString("node_wearG5", node_wearG5);
            }
        }
        dataMap.putString("dex_txid", dex_txid);
        dataMap.putInt("bridge_battery", mPrefs.getInt("bridge_battery", -1));//Used in DexCollectionService
        dataMap.putInt("nfc_sensor_age", mPrefs.getInt("nfc_sensor_age", -1));//Used in DexCollectionService for LimiTTer
        dataMap.putBoolean("bg_notifications_watch", mPrefs.getBoolean("bg_notifications", false));
        dataMap.putBoolean("persistent_high_alert_enabled_watch", mPrefs.getBoolean("persistent_high_alert_enabled", false));
        dataMap.putBoolean("show_wear_treatments", show_wear_treatments);
        sendData(WEARABLE_PREF_DATA_PATH, dataMap.toByteArray());

        SharedPreferences.Editor prefs = PreferenceManager.getDefaultSharedPreferences(this).edit();
        if (!node_wearG5.equals(dataMap.getString("node_wearG5", ""))) {
            Log.d(TAG, "sendPrefSettings save to SharedPreferences - node_wearG5:" + dataMap.getString("node_wearG5", ""));
            prefs.putString("node_wearG5", dataMap.getString("node_wearG5", ""));
            prefs.apply();
        }
    }
 
Example 13
Source File: WatchUpdaterService.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
private DataMap treatmentMap(long date, double bolus, double carbs, boolean isSMB, boolean isValid) {
    DataMap dm = new DataMap();
    dm.putLong("date", date);
    dm.putDouble("bolus", bolus);
    dm.putDouble("carbs", carbs);
    dm.putBoolean("isSMB", isSMB);
    dm.putBoolean("isValid", isValid);
    return dm;
}
 
Example 14
Source File: RetrieveService.java    From wear-notify-for-reddit with Apache License 2.0 5 votes vote down vote up
private void sendPostsToWearable(@NonNull List<Post> posts, @NonNull final String msg,
                                 @Nullable SimpleArrayMap<String, Asset> assets) {
    if (mGoogleApiClient.isConnected()) {
        // convert to json for sending to watch and to save to shared prefs
        // don't need to preserve the order like having separate String lists, can more easily add/remove fields
        PutDataMapRequest mapRequest = PutDataMapRequest.create(Constants.PATH_REDDIT_POSTS);
        DataMap dataMap = mapRequest.getDataMap();

        if (assets != null && !assets.isEmpty()) {
            for (int i = 0; i < assets.size(); i++) {
                dataMap.putAsset(assets.keyAt(i), assets.valueAt(i));
            }
        }

        dataMap.putLong("timestamp", System.currentTimeMillis());
        dataMap.putString(Constants.KEY_REDDIT_POSTS, mGson.toJson(posts));
        dataMap.putBoolean(Constants.KEY_DISMISS_AFTER_ACTION,
                mUserStorage.openOnPhoneDismissesAfterAction());
        dataMap.putIntegerArrayList(Constants.KEY_ACTION_ORDER,
                mWearableActionStorage.getSelectedActionIds());

        PutDataRequest request = mapRequest.asPutDataRequest();
        Wearable.DataApi.putDataItem(mGoogleApiClient, request)
                .setResultCallback(dataItemResult -> {
                    Timber.d(msg + ", final timestamp: " + mUserStorage.getTimestamp() + " result: " + dataItemResult
                            .getStatus());

                    if (dataItemResult.getStatus().isSuccess()) {
                        if (mGoogleApiClient.isConnected()) {
                            mGoogleApiClient.disconnect();
                        }
                    } else {
                        Timber.d("Failed to send posts to wearable " + dataItemResult.getStatus()
                                .getStatusMessage());
                    }
                });
    }
}
 
Example 15
Source File: ListenerService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public synchronized static void sendTreatment(String notes) {
    Log.d(TAG, "sendTreatment WEARABLE_TREATMENT_PAYLOAD notes=" + notes);
    DataMap dataMap = new DataMap();
    dataMap.putDouble("timestamp", System.currentTimeMillis());
    dataMap.putBoolean("watchkeypad", true);
    dataMap.putString("notes", notes);
    dataMap.putBoolean("ismgdl", doMgdl(PreferenceManager.getDefaultSharedPreferences(xdrip.getAppContext())));
    Intent intent = new Intent(xdrip.getAppContext(), Simulation.class);
    intent.putExtra(WEARABLE_TREATMENT_PAYLOAD, dataMap.toBundle());
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    xdrip.getAppContext().startActivity(intent);
}
 
Example 16
Source File: ListenerService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private void sendPrefSettings() {//KS

        Log.d(TAG, "sendPrefSettings enter");
        forceGoogleApiConnect();
        DataMap dataMap = new DataMap();
        boolean enable_wearG5 = mPrefs.getBoolean("enable_wearG5", false);
        boolean force_wearG5 = mPrefs.getBoolean("force_wearG5", false);
        String node_wearG5 = mPrefs.getString("node_wearG5", "");
        String dex_txid = mPrefs.getString("dex_txid", "ABCDEF");
        boolean show_wear_treatments = mPrefs.getBoolean("show_wear_treatments", false);

        if (localnode == null || (localnode != null && localnode.isEmpty())) setLocalNodeName();
        Log.d(TAG, "sendPrefSettings enable_wearG5: " + enable_wearG5 + " force_wearG5:" + force_wearG5 + " node_wearG5:" + node_wearG5 + " localnode:" + localnode + " dex_txid:" + dex_txid + " show_wear_treatments:" + show_wear_treatments);
        dataMap.putLong("time", new Date().getTime()); // MOST IMPORTANT LINE FOR TIMESTAMP
        dataMap.putBoolean("enable_wearG5", enable_wearG5);
        dataMap.putBoolean("force_wearG5", force_wearG5);
        if (force_wearG5) {
            dataMap.putString("node_wearG5", localnode);
        } else {
            if (node_wearG5.equals(localnode)) {
                dataMap.putString("node_wearG5", "");
            } else {
                dataMap.putString("node_wearG5", node_wearG5);
            }
        }
        dataMap.putString("dex_txid", dex_txid);
        dataMap.putInt("bridge_battery", mPrefs.getInt("bridge_battery", -1));//Used in DexCollectionService
        dataMap.putInt("nfc_sensor_age", mPrefs.getInt("nfc_sensor_age", -1));//Used in DexCollectionService for LimiTTer
        dataMap.putBoolean("bg_notifications_watch", mPrefs.getBoolean("bg_notifications", false));
        dataMap.putBoolean("persistent_high_alert_enabled_watch", mPrefs.getBoolean("persistent_high_alert_enabled", false));
        dataMap.putBoolean("show_wear_treatments", show_wear_treatments);
        sendData(WEARABLE_PREF_DATA_PATH, dataMap.toByteArray());

        SharedPreferences.Editor prefs = PreferenceManager.getDefaultSharedPreferences(this).edit();
        if (!node_wearG5.equals(dataMap.getString("node_wearG5", ""))) {
            Log.d(TAG, "sendPrefSettings save to SharedPreferences - node_wearG5:" + dataMap.getString("node_wearG5", ""));
            prefs.putString("node_wearG5", dataMap.getString("node_wearG5", ""));
            prefs.apply();
        }
    }
 
Example 17
Source File: ListenerService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public synchronized static void sendTreatment(String notes) {
    Log.d(TAG, "sendTreatment WEARABLE_TREATMENT_PAYLOAD notes=" + notes);
    DataMap dataMap = new DataMap();
    dataMap.putDouble("timestamp", System.currentTimeMillis());
    dataMap.putBoolean("watchkeypad", true);
    dataMap.putString("notes", notes);
    dataMap.putBoolean("ismgdl", doMgdl(PreferenceManager.getDefaultSharedPreferences(xdrip.getAppContext())));
    Intent intent = new Intent(xdrip.getAppContext(), Simulation.class);
    intent.putExtra(WEARABLE_TREATMENT_PAYLOAD, dataMap.toBundle());
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    xdrip.getAppContext().startActivity(intent);
}
 
Example 18
Source File: RequestListenerService.java    From arcgis-runtime-demos-android with Apache License 2.0 4 votes vote down vote up
/**
 * Handles issuing a response to a FeatureType response. A FeatureType response
 * indicates that the Wear devices wants a feature of the specified FeatureType
 * to be collected at the current device location.
 *
 * @param event the MessageEvent from the Wear device
 * @param client the Google API client used to communicate
 */
private void handleFeatureTypeResponse(final MessageEvent event, final GoogleApiClient client) {
  // Create a PutDataMapRequest with the status response path
  final PutDataMapRequest req = PutDataMapRequest.create(STATUS_RESPONSE);
  final DataMap dm = req.getDataMap();
  // Put the current time into the data map, which forces an onDataChanged event (this event
  // only occurs when data actually changes, so putting the time ensures something always changes)
  dm.putLong("Time", System.currentTimeMillis());
  try {
    // Request a single high precision location update
    LocationRequest request = LocationRequest.create()
            .setNumUpdates(1)
            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    LocationServices.FusedLocationApi.requestLocationUpdates(client, request, new LocationListener() {
      @Override
      public void onLocationChanged(Location location) {
        // When we've got a location, get the FeatureType that matches the specified name
        Log.i("Test", "Received location");
        String featureTypeName = new String(event.getData());
        FeatureType type = null;
        for (FeatureType ft : sArcGISFeatureLayer.getTypes()) {
          if (ft.getName().equals(featureTypeName)) {
            type = ft;
            break;
          }
        }
        // Only proceed if we found a matching type (which we always should)
        if (type != null) {
          // Create a new feature of the specified type at the current location
          Graphic g = sArcGISFeatureLayer.createFeatureWithType(type, new Point(location.getLongitude(), location.getLatitude()));
          // Apply the edit to the service
          sArcGISFeatureLayer.applyEdits(new Graphic[]{g}, null, null, new CallbackListener<FeatureEditResult[][]>() {
            @Override
            public void onCallback(FeatureEditResult[][] featureEditResults) {
              // Check that we have a success and report success
              if (featureEditResults[0].length > 0) {
                FeatureEditResult fer = featureEditResults[0][0];
                if (fer.isSuccess()) {
                  Log.i("Test", "Successfully added feature");
                  // Put a boolean indicating success into the data map
                  dm.putBoolean("success", true);
                } else {
                  Log.e("Test", "Failed to add feature: " + fer.getError().getDescription());
                  // Put a boolean indicating failure into the data map
                  dm.putBoolean("success", false);
                  // Put a string with the reason for failure into the data map
                  dm.putString("reason", "Error code: " + fer.getError().getCode());
                }
              }
              // Put the DataItem into the Data API stream
              Wearable.DataApi.putDataItem(client, req.asPutDataRequest());
            }

            @Override
            public void onError(Throwable throwable) {
              Log.d("Test", "Failed to add new graphic");
              // Put a boolean indicating failure into the data map
              dm.putBoolean("success", false);
              // Put a string with the reason for failure into the data map
              dm.putString("reason", throwable.getLocalizedMessage());
              // Put the DataItem into the Data API stream
              Wearable.DataApi.putDataItem(client, req.asPutDataRequest());
            }
          });
        } else {
          // If we don't have a matching feature type (which should never happen), log an error
          Log.e("Test", "Could not determine type");
          // Put a boolean indicating failure into the data map
          dm.putBoolean("success", false);
          // Put a string with the reason for failure into the data map
          dm.putString("reason", "Specified type not found");
          // Put the DataItem into the Data API stream
          Wearable.DataApi.putDataItem(client, req.asPutDataRequest());
        }
      }
    });
  } catch (SecurityException se) {
    // If we caught an exception trying to get the location, likelihood is that the location
    // permission has not been granted by the user
    Log.e("Test", "Could not access location");
    // Put a boolean indicating failure into the data map
    dm.putBoolean("success", false);
    // Put a string with the reason for failure into the data map
    dm.putString("reason", "Could not access location. Check permissions.");
    // Put the DataItem into the Data API stream
    Wearable.DataApi.putDataItem(client, req.asPutDataRequest());
  }
}
 
Example 19
Source File: WearableLocationService.java    From android_packages_apps_GmsCore with Apache License 2.0 4 votes vote down vote up
public static DataMap writeLocationCapability(DataMap dataMap, boolean locationCapable) {
    dataMap.putBoolean("CAPABILITY_LOCATION", locationCapable);
    return dataMap;
}
 
Example 20
Source File: DataBundleUtil.java    From android_external_GmsLib with Apache License 2.0 4 votes vote down vote up
@Override
void store(DataMap dataMap, String key, Boolean value) {
    if (value != null) dataMap.putBoolean(key, value);
}