Java Code Examples for com.google.android.gms.wearable.DataMapItem#getDataMap()

The following examples show how to use com.google.android.gms.wearable.DataMapItem#getDataMap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DigitalWatchFaceService.java    From wear-os-samples with Apache License 2.0 6 votes vote down vote up
@Override // DataApi.DataListener
public void onDataChanged(DataEventBuffer dataEvents) {
    for (DataEvent dataEvent : dataEvents) {
        if (dataEvent.getType() != DataEvent.TYPE_CHANGED) {
            continue;
        }

        DataItem dataItem = dataEvent.getDataItem();
        if (!dataItem.getUri().getPath().equals(
                DigitalWatchFaceUtil.PATH_WITH_FEATURE)) {
            continue;
        }

        DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItem);
        DataMap config = dataMapItem.getDataMap();
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "Config DataItem updated:" + config);
        }
        updateUiForConfigDataMap(config);
    }
}
 
Example 2
Source File: SunsetsWatchFace.java    From american-sunsets-watch-face with Apache License 2.0 6 votes vote down vote up
@Override // DataApi.DataListener
public void onDataChanged(DataEventBuffer dataEvents) {
    for (DataEvent dataEvent : dataEvents) {
        if (dataEvent.getType() != DataEvent.TYPE_CHANGED) {
            continue;
        }

        DataItem dataItem = dataEvent.getDataItem();
        if (!dataItem.getUri().getPath().equals(
                SunsetsWatchFaceUtil.PATH_WITH_FEATURE)) {
            continue;
        }

        DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItem);
        DataMap config = dataMapItem.getDataMap();
        Log.d(TAG, "Config DataItem updated:" + config);

        updateUiForConfigDataMap(config);
    }
}
 
Example 3
Source File: WatchFaceCompanionConfigActivity.java    From american-sunsets-watch-face with Apache License 2.0 6 votes vote down vote up
@Override // DataApi.DataListener
public void onDataChanged(DataEventBuffer dataEvents) {
    for (DataEvent dataEvent : dataEvents) {
        if (dataEvent.getType() != DataEvent.TYPE_CHANGED) {
            continue;
        }

        DataItem dataItem = dataEvent.getDataItem();
        if (!dataItem.getUri().getPath().equals(SunsetsWatchFaceUtil.PATH_WITH_FEATURE)) {
            continue;
        }

        DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItem);
        DataMap config = dataMapItem.getDataMap();
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "Config DataItem updated:" + config);
        }
        updateUiForConfigDataMap(config);
    }
}
 
Example 4
Source File: DigitalWatchFaceUtil.java    From wear-os-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void onResult(DataApi.DataItemResult dataItemResult) {
    if (dataItemResult.getStatus().isSuccess()) {
        if (dataItemResult.getDataItem() != null) {
            DataItem configDataItem = dataItemResult.getDataItem();
            DataMapItem dataMapItem = DataMapItem.fromDataItem(configDataItem);
            DataMap config = dataMapItem.getDataMap();
            mCallback.onConfigDataMapFetched(config);
        } else {
            mCallback.onConfigDataMapFetched(new DataMap());
        }
    }
}
 
Example 5
Source File: DigitalWatchFaceCompanionConfigActivity.java    From wear-os-samples with Apache License 2.0 5 votes vote down vote up
@Override // ResultCallback<DataApi.DataItemResult>
public void onResult(DataApi.DataItemResult dataItemResult) {
    if (dataItemResult.getStatus().isSuccess() && dataItemResult.getDataItem() != null) {
        DataItem configDataItem = dataItemResult.getDataItem();
        DataMapItem dataMapItem = DataMapItem.fromDataItem(configDataItem);
        DataMap config = dataMapItem.getDataMap();
        setUpAllPickers(config);
    } else {
        // If DataItem with the current config can't be retrieved, select the default items on
        // each picker.
        setUpAllPickers(null);
    }
}
 
Example 6
Source File: DataLayerListenerService.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
@Override
public void onDataChanged(final DataEventBuffer dataEvents) {
    super.onDataChanged(dataEvents);
    for (DataEvent event : dataEvents) {
        Uri uri = event.getDataItem().getUri();
        if (event.getType() == DataEvent.TYPE_CHANGED
                && uri.getPath().startsWith(WearConst.PATH_CANVAS)) {

            DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem());
            DataMap map = dataMapItem.getDataMap();
            List<String> segments = uri.getPathSegments();

            String selfId = ((WearApplication) getApplication()).getSelfId();
            String wearId = segments.get(2);
            if (selfId == null || !selfId.equals(wearId)) {
                //WearのIDが違っていれば無視
                return;
            }
            String nodeId = uri.getHost();
            String requestId = segments.get(3);
            Asset profileAsset = map.getAsset(WearConst.PARAM_BITMAP);
            int x = map.getInt(WearConst.PARAM_X);
            int y = map.getInt(WearConst.PARAM_Y);
            int mode = map.getInt(WearConst.PARAM_MODE);
            Intent intent = new Intent();
            intent.setClass(this, CanvasActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.putExtra(WearConst.PARAM_SOURCE_ID, nodeId);
            intent.putExtra(WearConst.PARAM_REQUEST_ID, requestId);
            intent.putExtra(WearConst.PARAM_BITMAP, profileAsset);
            intent.putExtra(WearConst.PARAM_X, x);
            intent.putExtra(WearConst.PARAM_Y, y);
            intent.putExtra(WearConst.PARAM_MODE, mode);
            startActivity(intent);
        }
    }
}
 
Example 7
Source File: SunsetsWatchFaceUtil.java    From american-sunsets-watch-face with Apache License 2.0 5 votes vote down vote up
@Override
public void onResult(DataApi.DataItemResult dataItemResult) {
    if (dataItemResult.getStatus().isSuccess()) {
        if (dataItemResult.getDataItem() != null) {
            DataItem configDataItem = dataItemResult.getDataItem();
            DataMapItem dataMapItem = DataMapItem.fromDataItem(configDataItem);
            DataMap config = dataMapItem.getDataMap();
            mCallback.onConfigDataMapFetched(config);
        } else {
            mCallback.onConfigDataMapFetched(new DataMap());
        }
    }
}
 
Example 8
Source File: WatchFaceCompanionConfigActivity.java    From american-sunsets-watch-face with Apache License 2.0 5 votes vote down vote up
@Override // ResultCallback<DataApi.DataItemResult>
public void onResult(DataApi.DataItemResult dataItemResult) {
    if (dataItemResult.getStatus().isSuccess() && dataItemResult.getDataItem() != null) {
        DataItem configDataItem = dataItemResult.getDataItem();
        DataMapItem dataMapItem = DataMapItem.fromDataItem(configDataItem);
        DataMap config = dataMapItem.getDataMap();
        Log.d(TAG,"startup setup UI...");
        updateUiForConfigDataMap(config);
        //setUpAllPickers(config);
    } else {
        // If DataItem with the current config can't be retrieved, select the default items on
        // each picker.
        //setUpAllPickers(null);
    }
}
 
Example 9
Source File: SunsetsWatchFaceUtil.java    From american-sunsets-watch-face with Apache License 2.0 5 votes vote down vote up
@Override
public void onResult(DataApi.DataItemResult dataItemResult) {
    if (dataItemResult.getStatus().isSuccess()) {
        if (dataItemResult.getDataItem() != null) {
            DataItem configDataItem = dataItemResult.getDataItem();
            DataMapItem dataMapItem = DataMapItem.fromDataItem(configDataItem);
            DataMap config = dataMapItem.getDataMap();
            mCallback.onConfigDataMapFetched(config);
        } else {
            mCallback.onConfigDataMapFetched(new DataMap());
        }
    }
}
 
Example 10
Source File: ConfigHelper.java    From FORMWatchFace with Apache License 2.0 5 votes vote down vote up
private DataMap readConfigDataMapFromDataLayer() {
    long latestTimestamp = 0;
    DataItemBuffer dataItemBuffer = Wearable.DataApi.getDataItems(mGoogleApiClient).await();
    if (!dataItemBuffer.getStatus().isSuccess()) {
        Log.e(TAG, "Error getting all data items: " + dataItemBuffer.getStatus().getStatusMessage());
    }

    DataMap configDataMap = null;

    Iterator<DataItem> dataItemIterator = dataItemBuffer.singleRefIterator();
    while (dataItemIterator.hasNext()) {
        DataItem dataItem = dataItemIterator.next();
        if (!dataItem.getUri().getPath().equals("/config")) {
            continue;
        }

        DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItem);
        DataMap dataMap = dataMapItem.getDataMap();
        long timestamp = dataMap.getLong("timestamp");
        if (timestamp >= latestTimestamp) {
            configDataMap = dataMapItem.getDataMap().getDataMap("config");
            latestTimestamp = timestamp;
        }
    }

    dataItemBuffer.release();
    return configDataMap;
}
 
Example 11
Source File: HomeListenerService.java    From AndroidWearable-Samples with Apache License 2.0 4 votes vote down vote up
/**
 * Posts a local notification to show calendar card.
 */
private void UpdateNotificationForDataItem(DataItem dataItem) {
    DataMapItem mapDataItem = DataMapItem.fromDataItem(dataItem);
    DataMap data = mapDataItem.getDataMap();

    String description = data.getString(DESCRIPTION);
    if (TextUtils.isEmpty(description)) {
        description = "";
    } else {
        // Add a space between the description and the time of the event.
        description += " ";
    }
    String contentText;
    if (data.getBoolean(ALL_DAY)) {
        contentText = getString(R.string.desc_all_day, description);
    } else {
        String startTime = DateFormat.getTimeFormat(this).format(new Date(data.getLong(BEGIN)));
        String endTime = DateFormat.getTimeFormat(this).format(new Date(data.getLong(END)));
        contentText = getString(R.string.desc_time_period, description, startTime, endTime);
    }

    Intent deleteOperation = new Intent(this, DeleteService.class);
    // Use a unique identifier for the delete action.
    String deleteAction = "action_delete" + dataItem.getUri().toString() + sNotificationId;
    deleteOperation.setAction(deleteAction);
    deleteOperation.setData(dataItem.getUri());
    PendingIntent deleteIntent = PendingIntent.getService(this, 0, deleteOperation,
            PendingIntent.FLAG_ONE_SHOT);
    PendingIntent silentDeleteIntent = PendingIntent.getService(this, 1,
            deleteOperation.putExtra(EXTRA_SILENT, true), PendingIntent.FLAG_ONE_SHOT);

    Notification.Builder notificationBuilder = new Notification.Builder(this)
            .setContentTitle(data.getString(TITLE))
            .setContentText(contentText)
            .setSmallIcon(R.drawable.ic_launcher)
            .addAction(R.drawable.ic_menu_delete, getText(R.string.delete), deleteIntent)
            .setDeleteIntent(silentDeleteIntent)  // Delete DataItem if notification dismissed.
            .setLocalOnly(true)
            .setPriority(Notification.PRIORITY_MIN);

    // Set the event owner's profile picture as the notification background.
    Asset asset = data.getAsset(PROFILE_PIC);
    if (null != asset) {
        if (mGoogleApiClient.isConnected()) {
            DataApi.GetFdForAssetResult assetFdResult =
                    Wearable.DataApi.getFdForAsset(mGoogleApiClient, asset).await();
            if (assetFdResult.getStatus().isSuccess()) {
                Bitmap profilePic = BitmapFactory.decodeStream(assetFdResult.getInputStream());
                notificationBuilder.extend(new Notification.WearableExtender()
                        .setBackground(profilePic));
            } else if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "asset fetch failed with statusCode: "
                        + assetFdResult.getStatus().getStatusCode());
            }
        } else {
            Log.e(TAG, "Failed to set notification background"
                     + " - Client disconnected from Google Play Services");
        }
    }
    Notification card = notificationBuilder.build();

    ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
            .notify(sNotificationId, card);

    sNotificationIdByDataItemUri.put(dataItem.getUri(), sNotificationId++);
}