Java 类com.google.android.gms.wearable.PutDataMapRequest 实例源码

项目:Android-DFU-App    文件:UARTConfigurationSynchronizer.java   
/**
 * Synchronizes the UART configurations between handheld and wearables.
 * Call this when configuration has been created or altered.
 * @return pending result
 */
public PendingResult<DataApi.DataItemResult> onConfigurationAddedOrEdited(final long id, final UartConfiguration configuration) {
    if (mGoogleApiClient == null || !mGoogleApiClient.isConnected())
        return null;

    final PutDataMapRequest mapRequest = PutDataMapRequest.create(Constants.UART.CONFIGURATIONS + "/" + id);
    final DataMap map = mapRequest.getDataMap();
    map.putString(Constants.UART.Configuration.NAME, configuration.getName());
    final ArrayList<DataMap> commands = new ArrayList<>(UartConfiguration.COMMANDS_COUNT);
    for (Command command : configuration.getCommands()) {
        if (command != null && command.isActive()) {
            final DataMap item = new DataMap();
            item.putInt(Constants.UART.Configuration.Command.ICON_ID, command.getIconIndex());
            item.putString(Constants.UART.Configuration.Command.MESSAGE, command.getCommand());
            item.putInt(Constants.UART.Configuration.Command.EOL, command.getEolIndex());
            commands.add(item);
        }
    }
    map.putDataMapArrayList(Constants.UART.Configuration.COMMANDS, commands);
    final PutDataRequest request = mapRequest.asPutDataRequest();
    return Wearable.DataApi.putDataItem(mGoogleApiClient, request);
}
项目:ibm-wearables-android-sdk    文件:DataManager.java   
/**
 * Create new Data Request and send it to the phone
 */
private void sendNextGestureData() {
    PutDataMapRequest dataMapRequest = getNewSensorsDataMapRequest();
    DataMap dataMap = dataMapRequest.getDataMap();

    List<GestureDataHolder.EventData> nextAccelerometerData = gestureDataHolder.pollNextAccelerometerData();
    if (nextAccelerometerData.size() > 0){
        dataMap.putDataMapArrayList("accelerometer", convertEventsToDataMapList(nextAccelerometerData));
    }

    List<GestureDataHolder.EventData> nextGyroscopeData = gestureDataHolder.pollNextGyroscopeData();
    if (nextGyroscopeData.size() > 0){
        dataMap.putDataMapArrayList("gyroscope", convertEventsToDataMapList(nextGyroscopeData));
    }

    dataSender.sendData(dataMapRequest);
}
项目:adrenaline_watch_face    文件:WatchFaceUtil.java   
/**
 * Overwrites the current config {@link DataItem}'s {@link DataMap} with {@code newConfig}.
 * If the config DataItem doesn't exist, it's created.
 */
public static void putConfigDataItem(GoogleApiClient googleApiClient, DataMap newConfig) {
    PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(PATH_WITH_FEATURE);
    DataMap configToPut = putDataMapRequest.getDataMap();
    configToPut.putAll(newConfig);
    PutDataRequest putDataRequest = putDataMapRequest.asPutDataRequest();
    putDataRequest.setUrgent();
    Wearable.DataApi.putDataItem(googleApiClient, putDataRequest)
            .setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
                @Override
                public void onResult(DataApi.DataItemResult dataItemResult) {
                    if (Log.isLoggable(TAG, Log.DEBUG)) {
                        Log.d(TAG, "putDataItem result status: " + dataItemResult.getStatus());
                    }
                }
            });
}
项目:SunshineApp    文件:DigitalWatchFaceUtil.java   
/**
 * Overwrites the current config {@link DataItem}'s {@link DataMap} with {@code newConfig}.
 * If the config DataItem doesn't exist, it's created.
 */
public static void putConfigDataItem(GoogleApiClient googleApiClient, DataMap newConfig) {
    PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(PATH_WITH_FEATURE);
    putDataMapRequest.setUrgent();
    DataMap configToPut = putDataMapRequest.getDataMap();
    configToPut.putAll(newConfig);
    Wearable.DataApi.putDataItem(googleApiClient, putDataMapRequest.asPutDataRequest())
            .setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
                @Override
                public void onResult(DataApi.DataItemResult dataItemResult) {
                    if (Log.isLoggable(TAG, Log.DEBUG)) {
                        Log.d(TAG, "putDataItem result status: " + dataItemResult.getStatus());
                    }
                }
            });
}
项目:hombot-control    文件:WearListenerService.java   
private void sendBotList() {
    PutDataMapRequest request = PutDataMapRequest.create(WearMessages.MESSAGE_BOT_LIST);
    DataMap map = request.getDataMap();

    HombotDataOpenHelper dataHelper = new HombotDataOpenHelper(this);
    final SQLiteDatabase db = dataHelper.getReadableDatabase();
    Cursor botCursor = db.query(HombotDataContract.BotEntry.TABLE_NAME, new String[]{HombotDataContract.BotEntry._ID, HombotDataContract.BotEntry.COLUMN_NAME_NAME, HombotDataContract.BotEntry.COLUMN_NAME_ADDRESS}, null, new String[0], null, null, HombotDataContract.BotEntry.COLUMN_NAME_NAME);

    ArrayList<DataMap> botList = new ArrayList<>();

    for (int i = 0; i < botCursor.getCount(); i++) {
        botCursor.moveToPosition(i);
        DataMap botMap = new DataMap();
        botMap.putString(WearMessages.MAPENTRY_BOT_NAME, botCursor.getString(botCursor.getColumnIndexOrThrow(HombotDataContract.BotEntry.COLUMN_NAME_NAME)));
        botMap.putString(WearMessages.MAPENTRY_BOT_ADDRESS, botCursor.getString(botCursor.getColumnIndexOrThrow(HombotDataContract.BotEntry.COLUMN_NAME_ADDRESS)));
        botMap.putLong(WearMessages.MAPENTRY_BOT_ID, botCursor.getLong(botCursor.getColumnIndexOrThrow(HombotDataContract.BotEntry.COLUMN_NAME_ADDRESS)));
        botList.add(botMap);
    }

    map.putLong("HASH", System.currentTimeMillis()); // NEED TO DO THIS BECAUSE OTHERWHISE DATA DIT NOT CHANGE AND WEAR EVENT DOES NOT TRIGGER
    map.putDataMapArrayList(WearMessages.MAPENTRY_BOT_LIST, botList);
    Wearable.DataApi.putDataItem(mGoogleApiClient, request.asPutDataRequest());
}
项目:SpritzerWear    文件:StorySender.java   
private void sendData(ArrayList<Story> storiesToSend) {
    if(storiesToSend == null || storiesToSend.size() == 0){
        return;
    }
    PutDataMapRequest dataMap = PutDataMapRequest.create(Tools.WEAR_PATH);
    DataMap dataMapToPut = dataMap.getDataMap();
    JSONArray contentList = new JSONArray();
    for(Story story : storiesToSend){
        contentList.put(story.toJSONObject());
    }

    dataMapToPut.putString(Tools.WEAR_KEY, contentList.toString());
    PutDataRequest request = dataMap.asPutDataRequest();
    PendingResult<DataApi.DataItemResult> pendingResult = Wearable.DataApi.putDataItem(mGoogleAppiClient, request);
    pendingResult.setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
        @Override
        public void onResult(DataApi.DataItemResult dataItemResult) {
            mGoogleAppiClient.disconnect();
        }
    });

}
项目:fantasywear    文件:LeagueData.java   
/**
 * Obtain a {@link PutDataRequest} to update a league's current state.
 *
 * @param account the account which owns the team competing in the league
 * @param league a proto describing the league
 * @param matchup a proto describing the account's team's current matchup
 * @param logo an Asset containing the user's logo image. The image should be square with size
 *             {@link com.jeffpdavidson.fantasywear.common.R.dimen#logo_size}.
 * @param opponentLogo an Asset containing the user's opponent's logo image. The image should be
 *                     square with size
 *                     {@link com.jeffpdavidson.fantasywear.common.R.dimen#logo_size}.
 * @param forceUpdate if true, will ensure that listening devices see the update even if no
 *                    fields have changed since the last update. Use conservatively as this will
 */
public static PutDataRequest getUpdateRequest(Account account, League league, Matchup matchup,
        Asset logo, Asset opponentLogo, boolean forceUpdate) {
    PutDataMapRequest request =
            PutDataMapRequest.create(getLeagueUri(account, league).toString());
    DataMap map = request.getDataMap();
    map.putInt(KEY_APP_VERSION, BuildConfig.VERSION_CODE);
    map.putString(KEY_MATCHUP, WireUtil.encodeToString(matchup));
    map.putAsset(KEY_LOGO, logo);
    map.putAsset(KEY_OPPONENT_LOGO, opponentLogo);
    if (forceUpdate) {
        // Play services suppresses updates if the payload exactly matches the last one, so when
        // forcing an update, include the current time to guarantee a unique payload.
        map.putLong(KEY_TIMESTAMP, System.currentTimeMillis());
    }
    return request.asPutDataRequest();
}
项目:easy-a    文件:TaskProvider.java   
/**
 * This method is called when someone wants to insert something
 * into our content provider.
 */
@Override
public Uri insert(Uri uri, ContentValues values) {
    // you can't choose your own task id
    if( values.containsKey(COLUMN_TASKID))
        throw new UnsupportedOperationException();

    long id = db.insertOrThrow(DATABASE_TABLE, null,
            values);
    getContext().getContentResolver().notifyChange(uri, null);

    // Save to google Play for wearable support
    PutDataMapRequest dataMap = PutDataMapRequest.create(
            PLAY_BASE_URL + "/" + id);
    DataMap map = dataMap.getDataMap();
    map.putLong(COLUMN_TASKID, id);
    map.putString(COLUMN_TITLE, values.getAsString(COLUMN_TITLE));
    map.putLong(COLUMN_DATE_TIME, values.getAsLong(COLUMN_DATE_TIME));
    map.putString(COLUMN_NOTES, values.getAsString(COLUMN_NOTES));
    PutDataRequest request = dataMap.asPutDataRequest();
    Wearable.DataApi.putDataItem(googleApiClient, request);


    return ContentUris.withAppendedId(uri, id);
}
项目:DoorCodeNotifier    文件:WearHelper.java   
@WorkerThread
public void putNotification(String title, String textShort, String textLong, @Nullable Bitmap photo, Uri contactUri, @Nullable String phoneNumber) {
    Log.d();
    // First remove any old notification
    Wearable.DataApi.deleteDataItems(mGoogleApiClient, createUri(PATH_NOTIFICATION)).await();

    // Create new notification
    PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(PATH_NOTIFICATION);

    DataMap dataMap = putDataMapRequest.getDataMap();
    dataMap.putString(EXTRA_TITLE, title);
    dataMap.putString(EXTRA_TEXT_SHORT, textShort);
    dataMap.putString(EXTRA_TEXT_LONG, textLong);
    if (photo != null) dataMap.putAsset(EXTRA_PHOTO, createAssetFromBitmap(photo));
    byte[] contactUriBytes = ParcelableUtil.parcel(contactUri);
    dataMap.putByteArray(EXTRA_CONTACT_URI, contactUriBytes);
    if (phoneNumber != null) dataMap.putString(EXTRA_PHONE_NUMBER, phoneNumber);

    PutDataRequest request = putDataMapRequest.asPutDataRequest();
    Wearable.DataApi.putDataItem(mGoogleApiClient, request).await();
}
项目:Android-nRF-Toolbox    文件:UARTConfigurationSynchronizer.java   
/**
 * Synchronizes the UART configurations between handheld and wearables.
 * Call this when configuration has been created or altered.
 * @return pending result
 */
public PendingResult<DataApi.DataItemResult> onConfigurationAddedOrEdited(final long id, final UartConfiguration configuration) {
    if (!hasConnectedApi())
        return null;

    final PutDataMapRequest mapRequest = PutDataMapRequest.create(Constants.UART.CONFIGURATIONS + "/" + id);
    final DataMap map = mapRequest.getDataMap();
    map.putString(Constants.UART.Configuration.NAME, configuration.getName());
    final ArrayList<DataMap> commands = new ArrayList<>(UartConfiguration.COMMANDS_COUNT);
    for (Command command : configuration.getCommands()) {
        if (command != null && command.isActive()) {
            final DataMap item = new DataMap();
            item.putInt(Constants.UART.Configuration.Command.ICON_ID, command.getIconIndex());
            item.putString(Constants.UART.Configuration.Command.MESSAGE, command.getCommand());
            item.putInt(Constants.UART.Configuration.Command.EOL, command.getEolIndex());
            commands.add(item);
        }
    }
    map.putDataMapArrayList(Constants.UART.Configuration.COMMANDS, commands);
    final PutDataRequest request = mapRequest.asPutDataRequest();
    return Wearable.DataApi.putDataItem(mGoogleApiClient, request);
}
项目:saarang-iosched    文件:PagerActivity.java   
/**
 * Builds a {@link com.google.android.gms.wearable.PutDataRequest} which holds a JSON
 * representation of the feedback collected.
 */
private PutDataRequest buildDataRequest() throws JSONException {
    PutDataMapRequest putDataMapRequest = PutDataMapRequest
            .create(HomeListenerService.PATH_RESPONSE);
    DataMap dataMap = putDataMapRequest.getDataMap();

    JSONArray jsonArray = new JSONArray();
    if (!responses.isEmpty()) {
        JSONObject sessionObj = new JSONObject();
        sessionObj.put("s", mSessionId);
        jsonArray.put(0, sessionObj);
        int i = 1;
        for (Integer key : responses.keySet()) {
            JSONObject obj = new JSONObject();
            obj.put("q", key);
            obj.put("a", responses.get(key));
            jsonArray.put(i++, obj);
        }
    }
    String response = jsonArray.toString();
    LOGD(TAG, "JSON representation of the response: " + response);
    dataMap.putString("response", response);
    return putDataMapRequest.asPutDataRequest();
}
项目:ubiquitous    文件:SunshineSyncIntentService.java   
private void updateWearWeather(int weather_id, double high_temp, double low_temp){
    PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(WEATHER_PATH).setUrgent();
    putDataMapRequest.getDataMap().putInt(WEATHER_ID, weather_id);
    Log.d(LOG_TAG, "value of weather put : "+weather_id);
    putDataMapRequest.getDataMap().putDouble(HIGH_TEMP, high_temp);
    putDataMapRequest.getDataMap().putDouble(LOW_TEMP, low_temp);
    PutDataRequest putDataRequest = putDataMapRequest.asPutDataRequest().setUrgent();
    PendingResult<DataApi.DataItemResult> pendingResult = Wearable.DataApi.putDataItem(mWearClient, putDataRequest);

    pendingResult.setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
        @Override
        public void onResult(@NonNull DataApi.DataItemResult dataItemResult) {
            if (dataItemResult.getStatus().isSuccess()) {
                Log.d(LOG_TAG, "Data item set: " + dataItemResult.getDataItem().getUri());

            } else {
                Log.d(LOG_TAG, "Error in sending data to watch");
            }
        }

    });
}
项目:Advanced_Android_Development_Wear    文件:DigitalWatchFaceUtil.java   
public static void putConfigDataItem(GoogleApiClient googleApiClient, DataMap newConfig, String path) {
    PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(path);
    DataMap configToPut = putDataMapRequest.getDataMap();
    configToPut.putAll(newConfig);
    Wearable.DataApi.putDataItem(googleApiClient, putDataMapRequest.asPutDataRequest())
            .setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
                @Override
                public void onResult(DataApi.DataItemResult dataItemResult) {
                    if (Log.isLoggable(TAG, Log.DEBUG)) {
                        Log.d(TAG, "putDataItem result status: " + dataItemResult.getStatus());
                    }
                }
            });
}
项目:ibm-wearables-android-sdk    文件:DataManager.java   
/**
 * Create next data to send of the hear rate
 * @param event sensor event
 */
private void sendHeartRateData(SensorEvent event){
    PutDataMapRequest dataMapRequest = getNewSensorsDataMapRequest();

    DataMap dataMap = dataMapRequest.getDataMap();
    dataMap.putFloat("heartrate",event.values[0]);

    dataSender.sendData(dataMapRequest);
}
项目:Athletica    文件:ConfigurationHelper.java   
/**
 * Overwrites the current config {@link DataItem}'s {@link DataMap} with {@code newConfig}.
 * If the config DataItem doesn't exist, it's created.
 */
public static void putConfigDataItem(GoogleApiClient googleApiClient, DataMap newConfig) {
    PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(PATH_WITH_FEATURE);
    putDataMapRequest.setUrgent();
    DataMap configToPut = putDataMapRequest.getDataMap();
    configToPut.putAll(newConfig);
    Wearable.DataApi.putDataItem(googleApiClient, putDataMapRequest.asPutDataRequest())
            .setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
                @Override
                public void onResult(@NonNull DataApi.DataItemResult dataItemResult) {
                    Log.d(TAG, "putDataItem result status: " + dataItemResult.getStatus());
                }
            });
}
项目:ubiquitous    文件:SunshineSyncIntentService.java   
private void updateWearWeather(int weather_id, double high_temp, double low_temp){
    PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(WEATHER_PATH).setUrgent();
    putDataMapRequest.getDataMap().putInt(WEATHER_ID, weather_id);
    Log.d(LOG_TAG, "value of weather put : "+weather_id);
    putDataMapRequest.getDataMap().putDouble(HIGH_TEMP, high_temp);
    putDataMapRequest.getDataMap().putDouble(LOW_TEMP, low_temp);
    PutDataRequest putDataRequest = putDataMapRequest.asPutDataRequest().setUrgent();
    PendingResult<DataApi.DataItemResult> pendingResult = Wearable.DataApi.putDataItem(mWearClient, putDataRequest);

    pendingResult.setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
        @Override
        public void onResult(@NonNull DataApi.DataItemResult dataItemResult) {
            if (dataItemResult.getStatus().isSuccess()) {
                Log.d(LOG_TAG, "Data item set: " + dataItemResult.getDataItem().getUri());

            } else {
                Log.d(LOG_TAG, "Error in sending data to watch");
            }
        }

    });
}
项目:android-samples    文件:TrackActivity.java   
/**
 * Send the current status of the step count tracking weather it is running or not. This message
 * is important and we should have guarantee of delivery to maintain the state of tracking status
 * on the phone. That is why we are using DataMap to communicate. So, if the phone is not connected
 * the message won't get lost. As soon as the phone connects, this status message will pass to the
 * phone application.
 *
 * @param isTracking true if the tracking is running
 */
private void sendTrackingStatusDataMap(boolean isTracking) {
    PutDataMapRequest dataMapRequest = PutDataMapRequest.create(STEP_TRACKING_STATUS_PATH);

    dataMapRequest.getDataMap().putBoolean("status", isTracking);
    dataMapRequest.getDataMap().putLong("status-time", System.currentTimeMillis());

    PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
    Wearable.DataApi.putDataItem(mGoogleApiClient, putDataRequest)
            .setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
                @Override
                public void onResult(@NonNull DataApi.DataItemResult dataItemResult) {
                    //check if the message is delivered?
                    //If the status is failed, that means that the currently device is
                    //not connected. The data will get deliver when phone gets connected to the watch.
                    Log.d("Data saving", dataItemResult.getStatus().isSuccess() ? "Success" : "Failed");
                }
            });

}
项目:android-samples    文件:WatchFaceConfigActivity.java   
private void notifyWear(String newBgColor) {
    PutDataMapRequest dataMapRequest = PutDataMapRequest.create("/bg_change");

    dataMapRequest.getDataMap().putString("new_color", newBgColor);

    PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
    Wearable.DataApi.putDataItem(mGoogleApiClient, putDataRequest)
            .setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
                @Override
                public void onResult(@NonNull DataApi.DataItemResult dataItemResult) {
                    //check if the message is delivered?
                    //If the status is failed, that means that the currently device is
                    //not connected. The data will get deliver when phone gets connected to the watch.
                    Log.d("Data saving", dataItemResult.getStatus().isSuccess() ? "Success" : "Failed");
                }
            });
}
项目:adrenaline_watch_face    文件:WatchFaceUtil.java   
/**
 * Overwrites the current config {@link DataItem}'s {@link DataMap} with {@code newConfig}.
 * If the config DataItem doesn't exist, it's created.
 */
public static void putConfigDataItem(GoogleApiClient googleApiClient, DataMap newConfig) {
    PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(PATH_WITH_FEATURE);
    DataMap configToPut = putDataMapRequest.getDataMap();
    configToPut.putAll(newConfig);
    Wearable.DataApi.putDataItem(googleApiClient, putDataMapRequest.asPutDataRequest())
            .setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
                @Override
                public void onResult(DataApi.DataItemResult dataItemResult) {
                    if (Log.isLoggable(TAG, Log.DEBUG)) {
                        Log.d(TAG, "putDataItem result status: " + dataItemResult.getStatus());
                    }
                }
            });
}
项目:wearDrip    文件:FileSender.java   
private void sendData(Asset asset) {
    if (asset == null) {
        return;
    }
    PutDataMapRequest dataMap = PutDataMapRequest.create(WEAR_PATH);
    byte[] arr = asset.getData();
    dataMap.getDataMap().putByteArray(DATA_ASSET_FILE, arr);
    dataMap.getDataMap().putLong("timestamp", Calendar.getInstance().getTimeInMillis());
    PutDataRequest request = dataMap.asPutDataRequest();
    PendingResult<DataApi.DataItemResult> pendingResult = Wearable.DataApi.putDataItem(mGoogleAppiClient, request);
    pendingResult.setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
        @Override
        public void onResult(DataApi.DataItemResult dataItemResult) {
            Log.d(TAG, "onResult result:" + dataItemResult.getStatus());
        }
    });
}
项目:WearApp    文件:MessageListenerService.java   
private void sendData() {
    ArrayList<Double> tempValues = ForecastFragment.getTempValues();
    Log.v("TAG", tempValues.size()+"");
    final DataMap dataMap = new DataMap();
    dataMap.putDouble("max", tempValues.get(0));
    dataMap.putDouble("min", tempValues.get(1));
    dataMap.putInt("icon", ForecastFragment.getIconId());
    dataMap.putLong("timestamp", System.currentTimeMillis());

    new Thread( new Runnable() {
        @Override
        public void run() {
            PutDataMapRequest dataMapRequest = PutDataMapRequest.create(MOBILE_MESSAGE_PATH).setUrgent();
            dataMapRequest.getDataMap().putAll(dataMap);
            PutDataRequest request = dataMapRequest.asPutDataRequest();

            DataApi.DataItemResult result = Wearable.DataApi.putDataItem(mApiClient, request).await();
            if(result.getStatus().isSuccess()){
                Log.v("TAG", "Sent successfully");
            }else {
                Log.v("TAG", "Failed to send");
            }
        }
    }).start();
}
项目:Smartwatch    文件:DatalayerUtil.java   
/**
 * Method that puts String data into the Wearable.DataApi layer.
 *
 * @param context
 * @param key key value of the data
 * @param data the data as string
 * @param path the path to store
 * @return Obsservable that emits the result
 */
public static Observable<DataApi.DataItemResult> putData(Context context, final String key, final String data, final String path) {
    return getGoogleApiClient(context)
            .flatMap(new Func1<GoogleApiClient, Observable<DataApi.DataItemResult>>() {
                @Override
                public Observable<DataApi.DataItemResult> call(final GoogleApiClient googleApiClient) {
                    return Observable.create(new Observable.OnSubscribe<DataApi.DataItemResult>() {
                        @Override
                        public void call(final Subscriber<? super DataApi.DataItemResult> subscriber) {
                            PutDataMapRequest putDataMapReq = PutDataMapRequest.create(path);
                            putDataMapReq.getDataMap().putString(key, data);
                            PutDataRequest putDataReq = putDataMapReq.asPutDataRequest();
                            Wearable.DataApi.putDataItem(googleApiClient, putDataReq).setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
                                @Override
                                public void onResult(@NonNull DataApi.DataItemResult dataItemResult) {
                                    subscriber.onNext(dataItemResult);
                                    subscriber.onCompleted();
                                }
                            });
                        }
                    });
                }
            });
}
项目:xDrip    文件:WatchUpdaterService.java   
private void sendDataReceived(String path, String notification, long timeOfLastEntry, String type, long watch_syncLogsRequested) {//KS
    Log.d(TAG, "sendDataReceived timeOfLastEntry=" + JoH.dateTimeText(timeOfLastEntry) + " Path=" + path);
    forceGoogleApiConnect();
    if (googleApiClient.isConnected()) {
        PutDataMapRequest dataMapRequest = PutDataMapRequest.create(path);
        dataMapRequest.setUrgent();
        dataMapRequest.getDataMap().putDouble("timestamp", System.currentTimeMillis());
        dataMapRequest.getDataMap().putLong("timeOfLastEntry", timeOfLastEntry);
        dataMapRequest.getDataMap().putLong("syncLogsRequested", watch_syncLogsRequested);
        dataMapRequest.getDataMap().putString("type", type);
        dataMapRequest.getDataMap().putString("msg", notification);
        PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
        Wearable.DataApi.putDataItem(googleApiClient, putDataRequest);
    } else {
        Log.e(TAG, "sendDataReceived No connection to wearable available!");
    }
}
项目:xDrip    文件:WatchUpdaterService.java   
public static void sendTreatment(double carbs, double insulin, double bloodtest, double timeoffset, String timestring) {
    if ((googleApiClient != null) && (googleApiClient.isConnected())) {
        PutDataMapRequest dataMapRequest = PutDataMapRequest.create(WEARABLE_TREATMENT_PAYLOAD);
        //unique content
        dataMapRequest.setUrgent();
        dataMapRequest.getDataMap().putDouble("timestamp", System.currentTimeMillis());
        dataMapRequest.getDataMap().putDouble("carbs", carbs);
        dataMapRequest.getDataMap().putDouble("insulin", insulin);
        dataMapRequest.getDataMap().putDouble("bloodtest", bloodtest);
        dataMapRequest.getDataMap().putDouble("timeoffset", timeoffset);
        dataMapRequest.getDataMap().putString("timestring", timestring);
        dataMapRequest.getDataMap().putBoolean("ismgdl", doMgdl(PreferenceManager.getDefaultSharedPreferences(xdrip.getAppContext())));
        PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
        Wearable.DataApi.putDataItem(googleApiClient, putDataRequest);
    } else {
        Log.e(TAG, "No connection to wearable available for send treatment!");
    }
}
项目:xDrip-plus    文件:WatchUpdaterService.java   
private void sendDataReceived(String path, String notification, long timeOfLastEntry, String type, long watch_syncLogsRequested) {//KS
    Log.d(TAG, "sendDataReceived timeOfLastEntry=" + JoH.dateTimeText(timeOfLastEntry) + " Path=" + path);
    forceGoogleApiConnect();
    if (googleApiClient.isConnected()) {
        PutDataMapRequest dataMapRequest = PutDataMapRequest.create(path);
        dataMapRequest.setUrgent();
        dataMapRequest.getDataMap().putDouble("timestamp", System.currentTimeMillis());
        dataMapRequest.getDataMap().putLong("timeOfLastEntry", timeOfLastEntry);
        dataMapRequest.getDataMap().putLong("syncLogsRequested", watch_syncLogsRequested);
        dataMapRequest.getDataMap().putString("type", type);
        dataMapRequest.getDataMap().putString("msg", notification);
        PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
        Wearable.DataApi.putDataItem(googleApiClient, putDataRequest);
    } else {
        Log.e(TAG, "sendDataReceived No connection to wearable available!");
    }
}
项目:xDrip-plus    文件:WatchUpdaterService.java   
public static void sendTreatment(double carbs, double insulin, double bloodtest, double timeoffset, String timestring) {
    if ((googleApiClient != null) && (googleApiClient.isConnected())) {
        PutDataMapRequest dataMapRequest = PutDataMapRequest.create(WEARABLE_TREATMENT_PAYLOAD);
        //unique content
        dataMapRequest.setUrgent();
        dataMapRequest.getDataMap().putDouble("timestamp", System.currentTimeMillis());
        dataMapRequest.getDataMap().putDouble("carbs", carbs);
        dataMapRequest.getDataMap().putDouble("insulin", insulin);
        dataMapRequest.getDataMap().putDouble("bloodtest", bloodtest);
        dataMapRequest.getDataMap().putDouble("timeoffset", timeoffset);
        dataMapRequest.getDataMap().putString("timestring", timestring);
        dataMapRequest.getDataMap().putBoolean("ismgdl", doMgdl(PreferenceManager.getDefaultSharedPreferences(xdrip.getAppContext())));
        PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
        Wearable.DataApi.putDataItem(googleApiClient, putDataRequest);
    } else {
        Log.e(TAG, "No connection to wearable available for send treatment!");
    }
}
项目:UdacityProject6    文件:SunshineWatchFace.java   
private void getWeatherInfo() {
    PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(KEY_PATH);
    String id = UUID.randomUUID().toString();
    putDataMapRequest.getDataMap().putString(KEY_UUID, id);

    Log.d(LOG_TAG,"getWeatherInfo id=" +id);
    PutDataRequest request = putDataMapRequest.asPutDataRequest();

    Wearable.DataApi.putDataItem(mGoogleApiClient, request)
            .setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
                @Override
                public void onResult(DataApi.DataItemResult dataItemResult) {
                    if (!dataItemResult.getStatus().isSuccess()) {
                        Log.d("WatchFaceService", "Data call failed");
                    }
                }
            });
}
项目:Sunshinewear    文件:SunshineSyncAdapter.java   
private void sendTodayForecast(double maxTemp, double minTemp, int weatherId) {

        PutDataMapRequest dataMap = PutDataMapRequest.create(FORECAST_PATH).setUrgent();
        String lowString = Utility.formatTemperature(getContext(), minTemp);
        String highString = Utility.formatTemperature(getContext(), maxTemp);
        dataMap.getDataMap().putString(MAX_TEMP_KEY, highString);
        dataMap.getDataMap().putString(MIN_TEMP_KEY, lowString);

        int artResource = Utility.getArtResourceForWeatherCondition(weatherId);
        Asset weatherIcon = Utility.toAsset(artResource, getContext());
        dataMap.getDataMap().putAsset(WEATHER_ICON_KEY, weatherIcon);
        dataMap.getDataMap().putLong(TIMESTAMP_KEY, System.currentTimeMillis());
        PutDataRequest request = dataMap.asPutDataRequest();

        Wearable.DataApi.putDataItem(mGoogleApiClient, request)
                .setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
                    @Override
                    public void onResult(DataApi.DataItemResult dataItemResult) {
                        if (!dataItemResult.getStatus().isSuccess()) {
                            Log.e(LOG_TAG, "ERROR: failed to putDataItem, status code: "
                                    + dataItemResult.getStatus().getStatusCode());
                        }
                    }
                });
    }
项目:Wristglider    文件:MainWearActivity.java   
private void stopLogger() {
    File dir = getFilesDir();
    File[] subFiles = dir.listFiles();
    if (subFiles != null) {
        for (File file : subFiles) {
            if (file.getName().contains(recentIgcFileName)) {
                if (debugMode) Log.d(TAG, "Now checking File " + file.getName());
                Asset asset = createAssetFromTextfile(file);
                PutDataMapRequest dataMap = PutDataMapRequest.create(Statics.DATAIGC + file.getName());
                dataMap.getDataMap().putString("igcname", file.getName());
                dataMap.getDataMap().putAsset("igcfile", asset);
                PutDataRequest request = dataMap.asPutDataRequest();
                request.setUrgent();
                Wearable.DataApi.putDataItem(mGoogleApiClient, request);
            }
        }
    }
    loggerRunning = false;
    loggerState.setText("");
}
项目:Wristglider    文件:MainActivity.java   
private void updatePreferences() {
    if (debugMode) Log.d(TAG, "update Preferences");
    PutDataMapRequest dataMap = PutDataMapRequest.create(Statics.DATAPREFERENCES);
    dataMap.getDataMap().putString(Statics.PREFPILOTNAME, prefs.getString(Statics.PREFPILOTNAME, "na"));
    dataMap.getDataMap().putString(Statics.PREFGLIDERTYPE, prefs.getString(Statics.PREFGLIDERTYPE, "na"));
    dataMap.getDataMap().putString(Statics.PREFGLIDERID, prefs.getString(Statics.PREFGLIDERID, "na"));
    dataMap.getDataMap().putLong(Statics.PREFLOGGERSECONDS, prefs.getLong(Statics.PREFLOGGERSECONDS, 1000));
    dataMap.getDataMap().putBoolean(Statics.PREFLOGGERAUTO, prefs.getBoolean(Statics.PREFLOGGERAUTO, false));
    dataMap.getDataMap().putBoolean(Statics.PREFROTATEVIEW, prefs.getBoolean(Statics.PREFROTATEVIEW, false));
    dataMap.getDataMap().putBoolean(Statics.PREFSCREENON, prefs.getBoolean(Statics.PREFSCREENON, false));
    dataMap.getDataMap().putString(Statics.PREFSPEEDUNIT, prefs.getString(Statics.PREFSPEEDUNIT, "km/h"));
    dataMap.getDataMap().putString(Statics.PREFHEIGTHUNIT, prefs.getString(Statics.PREFHEIGTHUNIT, "m"));
    dataMap.getDataMap().putString(Statics.PREFROTATEDEGREES, prefs.getString(Statics.PREFROTATEDEGREES, "0"));
    dataMap.getDataMap().putBoolean(Statics.PREFUSEBTVARIO, prefs.getBoolean(Statics.PREFUSEBTVARIO, false));
    dataMap.getDataMap().putString(Statics.PREFBTVARIOUNIT, prefs.getString(Statics.PREFBTVARIOUNIT, "m/s"));
    PutDataRequest request = dataMap.asPutDataRequest();
    request.setUrgent();
    Wearable.DataApi.putDataItem(mGoogleApiClient, request);
}
项目:GmsWear    文件:GmsWear.java   
/**
 * Adds a {@code bitmap} image to a data item asynchronously. Caller can
 * specify a {@link ResultCallback} or pass a {@code null}; if a {@code null} is passed, a
 * default {@link ResultCallback} will be used (see
 * {@link #putDataItem(PutDataRequest, ResultCallback)} for details).
 *
 * @param bitmap       The bitmap to be added.
 * @param path         The path for the data item.
 * @param key          The key to be used for this item in the data map.
 * @param isUrgent     If {@code true}, request will be set as urgent.
 * @param addTimestamp If {@code true}, adds a timestamp to the data map to always create a new
 *                     data item even if an identical data item with the same bitmap has
 *                     already
 *                     been added
 * @param callback     The callback to be notified of the result (can be {@code null}).
 */
public void putImageData(Bitmap bitmap, String path, String key, boolean isUrgent,
        boolean addTimestamp,
        @Nullable ResultCallback<? super DataApi.DataItemResult> callback) {
    WearUtil.assertNotNull(bitmap, "bitmap");
    WearUtil.assertNotEmpty(path, "path");
    WearUtil.assertNotEmpty(key, "key");
    Asset imageAsset = WearUtil.toAsset(bitmap);
    PutDataMapRequest dataMap = PutDataMapRequest.create(path);
    dataMap.getDataMap().putAsset(key, imageAsset);
    if (addTimestamp) {
        dataMap.getDataMap().putLong(Constants.KEY_TIMESTAMP, new Date().getTime());
    }
    PutDataRequest request = dataMap.asPutDataRequest();
    if (isUrgent) {
        request.setUrgent();
    }
    putDataItem(request, callback);
}
项目:GmsWear    文件:GmsWear.java   
private void syncData(PutDataMapRequest putDataMapRequest, boolean isUrgent) {
    assertApiConnectivity();
    if (isUrgent) {
        putDataMapRequest = putDataMapRequest.setUrgent();
    }
    PutDataRequest request = putDataMapRequest.asPutDataRequest();

    Wearable.DataApi.putDataItem(mGoogleApiClient, request)
            .setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
                @Override
                public void onResult(@NonNull DataApi.DataItemResult dataItemResult) {
                    if (dataItemResult.getStatus().isSuccess()) {
                        WearUtil.logD(TAG, "putDataItem success");
                    } else {
                        String errStr = dataItemResult.getStatus().getStatusMessage();
                        Log.e(TAG, "ERROR: failed to putDataItem, status code: "
                                + dataItemResult.getStatus().getStatusCode()
                                + ",status message:"
                                + errStr);

                    }
                }
            });
}
项目:AndroidAPS    文件:SendToDataLayerThread.java   
@Override
protected Void doInBackground(DataMap... params) {
    try {
        final NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient).await(15, TimeUnit.SECONDS);
        for (Node node : nodes.getNodes()) {
            for (DataMap dataMap : params) {
                PutDataMapRequest putDMR = PutDataMapRequest.create(path);
                putDMR.getDataMap().putAll(dataMap);
                PutDataRequest request = putDMR.asPutDataRequest();
                DataApi.DataItemResult result = Wearable.DataApi.putDataItem(googleApiClient, request).await(15, TimeUnit.SECONDS);
                if (result.getStatus().isSuccess()) {
                    Log.d(TAG, "DataMap: " + dataMap + " sent to: " + node.getDisplayName());
                } else {
                    Log.d(TAG, "ERROR: failed to send DataMap");
                }
            }
        }
    } catch (Exception e) {
        Log.e(TAG, "Got exception sending data to wear: " + e.toString());
    }
    return null;
}
项目:AndroidAPS    文件:WatchUpdaterService.java   
private void sendActionConfirmationRequest(String title, String message, String actionstring) {
    if (googleApiClient.isConnected()) {
        PutDataMapRequest dataMapRequest = PutDataMapRequest.create(ACTION_CONFIRMATION_REQUEST_PATH);
        //unique content
        dataMapRequest.getDataMap().putDouble("timestamp", System.currentTimeMillis());
        dataMapRequest.getDataMap().putString("actionConfirmationRequest", "actionConfirmationRequest");
        dataMapRequest.getDataMap().putString("title", title);
        dataMapRequest.getDataMap().putString("message", message);
        dataMapRequest.getDataMap().putString("actionstring", actionstring);

        log.debug("Requesting confirmation from wear: " + actionstring);

        PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
        Wearable.DataApi.putDataItem(googleApiClient, putDataRequest);
    } else {
        Log.e("confirmationRequest", "No connection to wearable available!");
    }
}
项目:SunshineApp    文件:WatchUpdaterReceiver.java   
@Override
public void onConnected(@Nullable Bundle bundle) {
    Log.d("WatchUpdaterReceiver", "onConnected: " + bundle);
    new Thread(new Runnable() {
        @Override
        public void run() {
            if(config!=null && config.size()>0) {
                    PutDataMapRequest putDMR = PutDataMapRequest.create(PATH_WITH_FEATURE);
                    putDMR.getDataMap().putAll(config);
                    PutDataRequest request = putDMR.asPutDataRequest().setUrgent();
                    DataApi.DataItemResult result = Wearable.DataApi.putDataItem(mGoogleApiClient, request).await();
                    if (result.getStatus().isSuccess()) {
                        Log.v("WatchUpdaterReceiver", "DataMap: " + config + " sent successfully to data layer ");
                    }
                    else {
                        // Log an error
                        Log.v("WatchUpdaterReceiver", "ERROR: failed to send DataMap to data layer");
                    }
            }
        }
    }).start();
}
项目:SunshineWear    文件:SunshineSyncAdapter.java   
@NonNull
private PutDataRequest buildWeatherRequest(double high, double low, Asset weatherAsset) {
    PutDataMapRequest weatherDataMapRequest = PutDataMapRequest.create(PATH_DATA_WEATHER + System.currentTimeMillis());
    DataMap weatherRequestDataMap = weatherDataMapRequest.getDataMap();
    weatherRequestDataMap.putDouble("high", high);
    weatherRequestDataMap.putDouble("low", low);
    weatherRequestDataMap.putAsset("icon", weatherAsset);
    PutDataRequest weatherRequest = weatherDataMapRequest.asPutDataRequest();
    weatherRequest.setUrgent();
    return weatherRequest;
}
项目:DronesWear    文件:Message.java   
public static PendingResult<DataApi.DataItemResult> sendAcceleroMessage(AccelerometerData accelerometerData, GoogleApiClient googleApiClient) {
    PutDataMapRequest dataMapRequest = PutDataMapRequest.create(ACC_PATH);
    acceleroMessageUri = dataMapRequest.getUri();
    DataMap dataMap = dataMapRequest.getDataMap();
    //Data set
    dataMap.putFloatArray(VALUE_STR, new float[]{accelerometerData.getAccX(), accelerometerData.getAccY(), accelerometerData.getAccZ()});

    // Data Push
    PutDataRequest request = dataMapRequest.asPutDataRequest();
    PendingResult<DataApi.DataItemResult> pendingResult = Wearable.DataApi.putDataItem(googleApiClient, request);

    return pendingResult;
}
项目:DronesWear    文件:Message.java   
public static PendingResult<DataApi.DataItemResult> sendJoystickMessage(JoystickData joystickData, GoogleApiClient googleApiClient) {
    PutDataMapRequest dataMapRequest = PutDataMapRequest.create(JOYSTICK_PATH);
    joystickMessageUri = dataMapRequest.getUri();
    DataMap dataMap = dataMapRequest.getDataMap();
    //Data set
    dataMap.putFloatArray(VALUE_STR, new float[]{joystickData.getPercentX(), joystickData.getPercentY()});

    // Data Push
    PutDataRequest request = dataMapRequest.asPutDataRequest();
    PendingResult<DataApi.DataItemResult> pendingResult = Wearable.DataApi.putDataItem(googleApiClient, request);

    return pendingResult;
}
项目:DronesWear    文件:Message.java   
public static PendingResult<DataApi.DataItemResult> sendInteractionTypeMessage(int interactionBitfield, GoogleApiClient googleApiClient) {
    PutDataMapRequest dataMapRequest = PutDataMapRequest.create(INTERACTION_TYPE_PATH);
    DataMap dataMap = dataMapRequest.getDataMap();
    //Data set
    dataMap.putInt(VALUE_STR, interactionBitfield);

    // Data Push
    PutDataRequest request = dataMapRequest.asPutDataRequest();
    PendingResult<DataApi.DataItemResult> pendingResult = Wearable.DataApi.putDataItem(googleApiClient, request);

    return pendingResult;
}
项目:DronesWear    文件:Message.java   
public static PendingResult<DataApi.DataItemResult> sendActionTypeMessage(int actionType, GoogleApiClient googleApiClient) {
    PutDataMapRequest dataMapRequest = PutDataMapRequest.create(ACTION_TYPE_PATH);
    DataMap dataMap = dataMapRequest.getDataMap();
    //Data set
    dataMap.putInt(VALUE_STR, actionType);

    // Data Push
    PutDataRequest request = dataMapRequest.asPutDataRequest();
    PendingResult<DataApi.DataItemResult> pendingResult = Wearable.DataApi.putDataItem(googleApiClient, request);

    return pendingResult;
}