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

The following examples show how to use com.google.android.gms.wearable.DataMap#putInt() . 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: 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 2
Source File: MainActivity.java    From android-Quiz with Apache License 2.0 6 votes vote down vote up
@Override
protected void onStop() {
    Wearable.DataApi.removeListener(mGoogleApiClient, this);
    Wearable.MessageApi.removeListener(mGoogleApiClient, this);

    // Tell the wearable to end the quiz (counting unanswered questions as skipped), and then
    // disconnect mGoogleApiClient.
    DataMap dataMap = new DataMap();
    dataMap.putInt(NUM_CORRECT, mNumCorrect);
    dataMap.putInt(NUM_INCORRECT, mNumIncorrect);
    if (mHasQuestionBeenAsked) {
        mNumSkipped += 1;
    }
    mNumSkipped += mFutureQuestions.size();
    dataMap.putInt(NUM_SKIPPED, mNumSkipped);
    if (mNumCorrect + mNumIncorrect + mNumSkipped > 0) {
        sendMessageToWearable(QUIZ_EXITED_PATH, dataMap.toByteArray());
    }

    clearQuizStatus();
    super.onStop();
}
 
Example 3
Source File: RawDisplayDataBgEntriesTest.java    From AndroidAPS with GNU Affero General Public License v3.0 6 votes vote down vote up
private DataMap dataMapForEntries() {

        DataMap dataMap = new DataMap();
        ArrayList<DataMap> entries = new ArrayList<>();
        for (int i=0; i<12; i++) {
            DataMap entry = new DataMap();
            entry.putLong("timestamp", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*4*(16-i));
            entry.putDouble("sgvDouble", 145.0-5*i);
            entry.putDouble("high", 170.0);
            entry.putDouble("low", 80.0);
            entry.putInt("color", 0);
            entries.add(entry);
        }
        dataMap.putDataMapArrayList("entries", entries);

        return dataMap;
    }
 
Example 4
Source File: WearableService.java    From sms-ticket with Apache License 2.0 6 votes vote down vote up
private void syncTicketsToWear(String path) {
    Uri uri = Uri.parse(path);
    final ArrayList<DataMap> dataCities = new ArrayList<DataMap>();
    String cityName = uri.getLastPathSegment();

    List<City> cities = CityManager.get(getApplicationContext()).getTicketsInCity(cityName, getApplicationContext());

    for (final City city : cities) {
        final DataMap dataMap = new DataMap();
        dataMap.putLong("id", city.id);
        dataMap.putString("city", city.city);
        dataMap.putString("country", city.country);
        dataMap.putInt("validity", city.validity);
        dataMap.putString("price", city.price);
        dataMap.putString("currency", city.currency);
        dataMap.putString("price_note", city.priceNote);
        dataMap.putString("note", city.note);

        dataCities.add(dataMap);
    }
    PutDataMapRequest data = PutDataMapRequest.createWithAutoAppendedId("/tickets");
    data.getDataMap().putDataMapArrayList("tickets", dataCities);
    syncDataItem(data);
}
 
Example 5
Source File: IncomingRequestPhoneService.java    From wear-os-samples with Apache License 2.0 6 votes vote down vote up
private void promptUserForStoragePermission(String nodeId) {
    boolean storagePermissionApproved =
            ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
                    == PackageManager.PERMISSION_GRANTED;

    if (storagePermissionApproved) {
        DataMap dataMap = new DataMap();
        dataMap.putInt(Constants.KEY_COMM_TYPE,
                Constants.COMM_TYPE_RESPONSE_USER_APPROVED_PERMISSION);
        sendMessage(nodeId, dataMap);
    } else {
        // Launch Phone Activity to grant storage permissions.
        Intent startIntent = new Intent(this, PhonePermissionRequestActivity.class);
        startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        /* This extra is included to alert MainPhoneActivity to send back the permission
         * results after the user has made their decision in PhonePermissionRequestActivity
         * and it finishes.
         */
        startIntent.putExtra(MainPhoneActivity.EXTRA_PROMPT_PERMISSION_FROM_WEAR, true);
        startActivity(startIntent);
    }
}
 
Example 6
Source File: UARTConfigurationSynchronizer.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 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(googleApiClient, request);
}
 
Example 7
Source File: MainPhoneActivity.java    From wear-os-samples with Apache License 2.0 6 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Log.d(TAG, "onActivityResult()");
    if (requestCode == REQUEST_WEAR_PERMISSION_RATIONALE) {

        if (resultCode == Activity.RESULT_OK) {
            logToUi("Requested permission on wear device(s).");

            DataMap dataMap = new DataMap();
            dataMap.putInt(Constants.KEY_COMM_TYPE,
                    Constants.COMM_TYPE_REQUEST_PROMPT_PERMISSION);
            sendMessage(dataMap);
        }
    }
}
 
Example 8
Source File: MainActivity.java    From AndroidWearable-Samples with Apache License 2.0 6 votes vote down vote up
/**
 * Asks the next enqueued question if it exists, otherwise ends the quiz.
 */
private void askNextQuestionIfExists() {
    if (mFutureQuestions.isEmpty()) {
        // Quiz has been completed - send message to wearable to display end report.
        DataMap dataMap = new DataMap();
        dataMap.putInt(NUM_CORRECT, mNumCorrect);
        dataMap.putInt(NUM_INCORRECT, mNumIncorrect);
        dataMap.putInt(NUM_SKIPPED, mNumSkipped);
        sendMessageToWearable(QUIZ_ENDED_PATH, dataMap.toByteArray());
        setHasQuestionBeenAsked(false);
    } else {
        // Ask next question by putting a DataItem that will be received on the wearable.
        Wearable.DataApi.putDataItem(mGoogleApiClient,
                mFutureQuestions.remove().toPutDataRequest());
        setHasQuestionBeenAsked(true);
    }
}
 
Example 9
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 10
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 11
Source File: Message.java    From DronesWear with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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;
}
 
Example 12
Source File: MainActivity.java    From AndroidWearable-Samples with Apache License 2.0 5 votes vote down vote up
public PutDataRequest toPutDataRequest() {
    PutDataMapRequest request = PutDataMapRequest.create("/question/" + questionIndex);
    DataMap dataMap = request.getDataMap();
    dataMap.putString(QUESTION, question);
    dataMap.putInt(QUESTION_INDEX, questionIndex);
    dataMap.putStringArray(ANSWERS, answers);
    dataMap.putInt(CORRECT_ANSWER_INDEX, correctAnswerIndex);
    return request.asPutDataRequest();
}
 
Example 13
Source File: DexCollectionService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static DataMap getWatchStatus() {
    DataMap dataMap = new DataMap();
    dataMap.putString("lastState", lastState);
    if (last_transmitter_Data != null)
        dataMap.putLong("timestamp", last_transmitter_Data.timestamp);
    dataMap.putInt("mStaticState", mStaticState);
    dataMap.putInt("last_battery_level", last_battery_level);
    dataMap.putLong("retry_time", retry_time);
    dataMap.putLong("failover_time", failover_time);
    dataMap.putString("static_last_hexdump", static_last_hexdump);
    dataMap.putString("static_last_sent_hexdump", static_last_sent_hexdump);
    return dataMap;
}
 
Example 14
Source File: MainWearActivity.java    From wear-os-samples with Apache License 2.0 5 votes vote down vote up
public void onClickPhoneStorage(View view) {

        logToUi("Requested info from phone. New approval may be required.");
        DataMap dataMap = new DataMap();
        dataMap.putInt(Constants.KEY_COMM_TYPE,
                Constants.COMM_TYPE_REQUEST_DATA);
        sendMessage(dataMap);
    }
 
Example 15
Source File: DexCollectionService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static DataMap getWatchStatus() {
    DataMap dataMap = new DataMap();
    dataMap.putString("lastState", lastState);
    if (last_transmitter_Data != null)
        dataMap.putLong("timestamp", last_transmitter_Data.timestamp);
    dataMap.putInt("mStaticState", mStaticState);
    dataMap.putInt("last_battery_level", last_battery_level);
    dataMap.putLong("retry_time", retry_time);
    dataMap.putLong("failover_time", failover_time);
    dataMap.putString("static_last_hexdump", static_last_hexdump);
    dataMap.putString("static_last_sent_hexdump", static_last_sent_hexdump);
    return dataMap;
}
 
Example 16
Source File: WatchFaceCompanionConfigActivity.java    From american-sunsets-watch-face with Apache License 2.0 5 votes vote down vote up
private void sendConfigUpdateMessage(String configKey, int color) {
    if (mPeerId != null) {
        DataMap config = new DataMap();
        config.putInt(configKey, color);
        byte[] rawData = config.toByteArray();
        Wearable.MessageApi.sendMessage(mGoogleApiClient, mPeerId, SunsetsWatchFaceUtil.PATH_WITH_FEATURE, rawData);

        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "Sent watch face config message: " + configKey + " -> "
                    + Integer.toHexString(color));
        }
    }
}
 
Example 17
Source File: MainPhoneActivity.java    From wear-os-samples with Apache License 2.0 4 votes vote down vote up
public void onMessageReceived(MessageEvent messageEvent) {
    Log.d(TAG, "onMessageReceived(): " + messageEvent);

    String messagePath = messageEvent.getPath();

    if (messagePath.equals(Constants.MESSAGE_PATH_PHONE)) {
        DataMap dataMap = DataMap.fromByteArray(messageEvent.getData());

        int commType = dataMap.getInt(Constants.KEY_COMM_TYPE, 0);

        if (commType == Constants.COMM_TYPE_RESPONSE_PERMISSION_REQUIRED) {
            mWearBodySensorsPermissionApproved = false;
            updateWearButtonOnUiThread();

            /* Because our request for remote data requires a remote permission, we now launch
             * a splash activity informing the user we need those permissions (along with
             * other helpful information to approve).
             */
            Intent wearPermissionRationale =
                    new Intent(this, WearPermissionRequestActivity.class);
            startActivityForResult(wearPermissionRationale, REQUEST_WEAR_PERMISSION_RATIONALE);

        } else if (commType == Constants.COMM_TYPE_RESPONSE_USER_APPROVED_PERMISSION) {
            mWearBodySensorsPermissionApproved = true;
            updateWearButtonOnUiThread();
            logToUi("User approved permission on remote device, requesting data again.");
            DataMap outgoingDataRequestDataMap = new DataMap();
            outgoingDataRequestDataMap.putInt(Constants.KEY_COMM_TYPE,
                    Constants.COMM_TYPE_REQUEST_DATA);
            sendMessage(outgoingDataRequestDataMap);

        } else if (commType == Constants.COMM_TYPE_RESPONSE_USER_DENIED_PERMISSION) {
            mWearBodySensorsPermissionApproved = false;
            updateWearButtonOnUiThread();
            logToUi("User denied permission on remote device.");

        } else if (commType == Constants.COMM_TYPE_RESPONSE_DATA) {
            mWearBodySensorsPermissionApproved = true;
            String storageDetails = dataMap.getString(Constants.KEY_PAYLOAD);
            updateWearButtonOnUiThread();
            logToUi(storageDetails);

        } else {
            Log.d(TAG, "Unrecognized communication type received.");
        }
    }
}
 
Example 18
Source File: RawDisplayDataBasalsTest.java    From AndroidAPS with GNU Affero General Public License v3.0 4 votes vote down vote up
private DataMap dataMapForBasals() {

        DataMap dataMap = new DataMap();

        ArrayList<DataMap> temps = new ArrayList<>();
        DataMap temp = new DataMap();
        temp.putLong("starttime", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*20);
        temp.putDouble("startBasal", 1.5);
        temp.putLong("endtime", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*10);
        temp.putDouble("endbasal", 1.5);
        temp.putDouble("amount", 1.8);
        temps.add(temp);

        DataMap temp2 = new DataMap();
        temp2.putLong("starttime", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*10);
        temp2.putDouble("startBasal", 1.3);
        temp2.putLong("endtime", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*2);
        temp2.putDouble("endbasal", 1.3);
        temp2.putDouble("amount", 2.3);
        temps.add(temp2);
        dataMap.putDataMapArrayList("temps", temps);

        ArrayList<DataMap> basals = new ArrayList<>();
        DataMap basal = new DataMap();
        basal.putLong("starttime", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*20);
        basal.putLong("endtime", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*2);
        basal.putDouble("amount", 1.2);
        basals.add(basal);
        dataMap.putDataMapArrayList("basals", basals);

        ArrayList<DataMap> boluses = new ArrayList<>();
        DataMap bolus = new DataMap();
        bolus.putLong("date", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*17);
        bolus.putDouble("bolus", 5.5);
        bolus.putDouble("carbs", 20.0);
        bolus.putBoolean("isSMB", false);
        bolus.putBoolean("isValid", true);
        boluses.add(bolus);

        DataMap bolus2 = new DataMap();
        bolus2.putLong("date", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*11);
        bolus2.putDouble("bolus", 3.0);
        bolus2.putDouble("carbs", 0.0);
        bolus2.putBoolean("isSMB", false);
        bolus2.putBoolean("isValid", true);
        boluses.add(bolus2);

        DataMap bolus3 = new DataMap();
        bolus3.putLong("date", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*3);
        bolus3.putDouble("bolus", 0.0);
        bolus3.putDouble("carbs", 15.0);
        bolus3.putBoolean("isSMB", true);
        bolus3.putBoolean("isValid", false);
        boluses.add(bolus3);

        dataMap.putDataMapArrayList("boluses", boluses);

        ArrayList<DataMap> predictions = new ArrayList<>();
        for (int i=0; i<10; i++) {
            DataMap prediction = new DataMap();
            prediction.putLong("timestamp", WearUtilMocker.REF_NOW + Constants.MINUTE_IN_MS*i);
            prediction.putDouble("sgv", 160-4*i);
            prediction.putInt("color", 0);
            predictions.add(prediction);
        }
        dataMap.putDataMapArrayList("predictions", predictions);

        return dataMap;
    }
 
Example 19
Source File: SunsetsGeneralWearableConfigActivity.java    From american-sunsets-watch-face with Apache License 2.0 4 votes vote down vote up
private void updateConfigDataItem(String key, final int colorID) {
    DataMap configKeysToOverwrite = new DataMap();
    configKeysToOverwrite.putInt(key,
            colorID);
    SunsetsWatchFaceUtil.overwriteKeysInConfigDataMap(mGoogleApiClient, configKeysToOverwrite);
}
 
Example 20
Source File: ListenerService.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
private void sendSensorLocalMessage(int steps, long timestamp) {
    DataMap dataMap = new DataMap();
    dataMap.putInt("steps", steps);
    dataMap.putLong("steps_timestamp", timestamp);
    sendLocalMessage("steps", dataMap);
}