com.google.android.gms.wearable.DataItemBuffer Java Examples
The following examples show how to use
com.google.android.gms.wearable.DataItemBuffer.
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: MainActivity.java From DronesWear with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void onConnected(Bundle bundle) { Wearable.DataApi.addListener(mGoogleApiClient, this); // get existing data PendingResult<DataItemBuffer> results = Wearable.DataApi.getDataItems(mGoogleApiClient); results.setResultCallback(new ResultCallback<DataItemBuffer>() { @Override public void onResult(@NonNull DataItemBuffer dataItems) { for (DataItem dataItem : dataItems) { switch (Message.getMessageType(dataItem)) { case ACTION_TYPE: int productAction = Message.decodeActionTypeMessage(dataItem); onActionTypeChanged(productAction); break; case INTERACTION_TYPE: int interactionType = Message.decodeInteractionTypeMessage(dataItem); onInteractionTypeChanged(interactionType); break; } } dataItems.release(); } }); }
Example #2
Source File: DataApiHandler.java From PowerSwitch_Android with GNU General Public License v3.0 | 6 votes |
/** * Retrieve wear settings from Wear cloud storage */ public void updateSettings(Context context) { if (!googleApiClient.isConnected()) { if (!blockingConnect()) { return; } } ArrayList<DataMap> data; DataItemBuffer dataItemBuffer = Wearable.DataApi.getDataItems(googleApiClient).await(); if (dataItemBuffer.getStatus().isSuccess()) { for (DataItem dataItem : dataItemBuffer) { DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItem); data = dataMapItem.getDataMap().getDataMapArrayList(WearableConstants.EXTRA_SETTINGS); if (data != null) { ListenerService.extractSettings(data); break; } } } dataItemBuffer.release(); }
Example #3
Source File: MainActivity.java From AndroidWearable-Samples with Apache License 2.0 | 6 votes |
public void onDeleteEventsClicked(View v) { if (mGoogleApiClient.isConnected()) { Wearable.DataApi.getDataItems(mGoogleApiClient) .setResultCallback(new ResultCallback<DataItemBuffer>() { @Override public void onResult(DataItemBuffer result) { if (result.getStatus().isSuccess()) { deleteDataItems(result); } else { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "onDeleteEventsClicked(): failed to get Data Items"); } } result.close(); } }); } else { Log.e(TAG, "Failed to delete data items" + " - Client disconnected from Google Play Services"); } }
Example #4
Source File: UARTConfigurationsActivity.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * This method read the UART configurations from the DataApi and populates the adapter with them. */ private void populateConfigurations() { if (googleApiClient.isConnected()) { final PendingResult<DataItemBuffer> results = Wearable.DataApi.getDataItems(googleApiClient, Uri.parse("wear:" + Constants.UART.CONFIGURATIONS), DataApi.FILTER_PREFIX); results.setResultCallback(dataItems -> { final List<UartConfiguration> configurations = new ArrayList<>(dataItems.getCount()); for (int i = 0; i < dataItems.getCount(); ++i) { final DataItem item = dataItems.get(i); final long id = ContentUris.parseId(item.getUri()); final DataMap dataMap = DataMapItem.fromDataItem(item).getDataMap(); final UartConfiguration configuration = new UartConfiguration(dataMap, id); configurations.add(configuration); } adapter.setConfigurations(configurations); dataItems.release(); }); } }
Example #5
Source File: DataApiHandler.java From PowerSwitch_Android with GNU General Public License v3.0 | 5 votes |
/** * Retrieve room data from Wear cloud storage * * @return List of Rooms */ public ArrayList<Room> getRoomData() { ArrayList<Room> rooms = new ArrayList<>(); if (!googleApiClient.isConnected()) { if (!blockingConnect()) { return null; } } ArrayList<DataMap> data; DataItemBuffer dataItemBuffer = Wearable.DataApi.getDataItems(googleApiClient).await(); if (dataItemBuffer.getStatus().isSuccess()) { for (DataItem dataItem : dataItemBuffer) { DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItem); data = dataMapItem.getDataMap().getDataMapArrayList(WearableConstants.EXTRA_DATA); if (data != null) { rooms = ListenerService.extractRoomDataMapItems(data); break; } } } dataItemBuffer.release(); return rooms; }
Example #6
Source File: MainActivity.java From AndroidWearable-Samples with Apache License 2.0 | 5 votes |
private void deleteDataItems(DataItemBuffer dataItems) { if (mGoogleApiClient.isConnected()) { // Store the DataItem URIs in a List and close the buffer. Then use these URIs // to delete the DataItems. final List<DataItem> dataItemList = FreezableUtils.freezeIterable(dataItems); dataItems.close(); for (final DataItem dataItem : dataItemList) { final Uri dataItemUri = dataItem.getUri(); // In a real calendar application, this might delete the corresponding calendar // event from the calendar data provider. In this sample, we simply delete the // DataItem, but leave the phone's calendar data intact. Wearable.DataApi.deleteDataItems(mGoogleApiClient, dataItemUri) .setResultCallback(new ResultCallback<DataApi.DeleteDataItemsResult>() { @Override public void onResult(DataApi.DeleteDataItemsResult deleteResult) { if (deleteResult.getStatus().isSuccess()) { appendLog("Successfully deleted data item: " + dataItemUri); } else { appendLog("Failed to delete data item:" + dataItemUri); } } }); } } else { Log.e(TAG, "Failed to delete data items" + " - Client disconnected from Google Play Services"); } }
Example #7
Source File: MainActivity.java From AndroidWearable-Samples with Apache License 2.0 | 5 votes |
/** * Clears the current quiz when user clicks on "New Quiz." * On this end, this involves clearing the quiz status layout and deleting all DataItems. The * wearable will then remove any outstanding question notifications upon receiving this change. */ public void newQuiz(View view) { clearQuizStatus(); if (mGoogleApiClient.isConnected()) { Wearable.DataApi.getDataItems(mGoogleApiClient) .setResultCallback(new ResultCallback<DataItemBuffer>() { @Override public void onResult(DataItemBuffer result) { if (result.getStatus().isSuccess()) { List<Uri> dataItemUriList = new ArrayList<Uri>(); for (final DataItem dataItem : result) { dataItemUriList.add(dataItem.getUri()); } result.close(); deleteDataItems(dataItemUriList); } else { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Clear quiz: failed to get Data Items for deletion"); } } result.close(); } }); } else { Log.e(TAG, "Failed to delete data items because client is disconnected from " + "Google Play Services"); } }
Example #8
Source File: MainActivity.java From AndroidWearable-Samples with Apache License 2.0 | 5 votes |
/** * Resets the current quiz when Reset Quiz is pressed. */ public void resetQuiz(View view) { // Reset quiz status in phone layout. for(int i = 0; i < questionsContainer.getChildCount(); i++) { LinearLayout questionStatusElement = (LinearLayout) questionsContainer.getChildAt(i); TextView questionText = (TextView) questionStatusElement.findViewById(R.id.question); TextView questionStatus = (TextView) questionStatusElement.findViewById(R.id.status); questionText.setTextColor(Color.WHITE); questionStatus.setText(R.string.question_unanswered); } // Reset data items and notifications on wearable. if (mGoogleApiClient.isConnected()) { Wearable.DataApi.getDataItems(mGoogleApiClient) .setResultCallback(new ResultCallback<DataItemBuffer>() { @Override public void onResult(DataItemBuffer result) { if (result.getStatus().isSuccess()) { List<DataItem> dataItemList = FreezableUtils.freezeIterable(result); result.close(); resetDataItems(dataItemList); } else { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Reset quiz: failed to get Data Items to reset"); } } result.close(); } }); } else { Log.e(TAG, "Failed to reset data items because client is disconnected from " + "Google Play Services"); } setHasQuestionBeenAsked(false); mNumCorrect = 0; mNumIncorrect = 0; mNumSkipped = 0; }
Example #9
Source File: MainActivity.java From android-Quiz with Apache License 2.0 | 5 votes |
/** * Clears the current quiz when user clicks on "New Quiz." * On this end, this involves clearing the quiz status layout and deleting all DataItems. The * wearable will then remove any outstanding question notifications upon receiving this change. */ public void newQuiz(View view) { clearQuizStatus(); if (mGoogleApiClient.isConnected()) { Wearable.DataApi.getDataItems(mGoogleApiClient) .setResultCallback(new ResultCallback<DataItemBuffer>() { @Override public void onResult(DataItemBuffer result) { try { if (result.getStatus().isSuccess()) { List<Uri> dataItemUriList = new ArrayList<Uri>(); for (final DataItem dataItem : result) { dataItemUriList.add(dataItem.getUri()); } deleteDataItems(dataItemUriList); } else { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Clear quiz: failed to get Data Items for " + "deletion"); } } } finally { result.release(); } } }); } else { Log.e(TAG, "Failed to delete data items because client is disconnected from " + "Google Play Services"); } }
Example #10
Source File: MainActivity.java From android-Quiz with Apache License 2.0 | 5 votes |
private void resetDataItems(DataItemBuffer dataItemList) { if (mGoogleApiClient.isConnected()) { for (final DataItem dataItem : dataItemList) { final Uri dataItemUri = dataItem.getUri(); Wearable.DataApi.getDataItem(mGoogleApiClient, dataItemUri) .setResultCallback(new ResetDataItemCallback()); } } else { Log.e(TAG, "Failed to reset data items because client is disconnected from " + "Google Play Services"); } }
Example #11
Source File: MainActivity.java From android-Quiz with Apache License 2.0 | 5 votes |
/** * Resets the current quiz when Reset Quiz is pressed. */ public void resetQuiz(View view) { // Reset quiz status in phone layout. for (int i = 0; i < questionsContainer.getChildCount(); i++) { LinearLayout questionStatusElement = (LinearLayout) questionsContainer.getChildAt(i); TextView questionText = (TextView) questionStatusElement.findViewById(R.id.question); TextView questionStatus = (TextView) questionStatusElement.findViewById(R.id.status); questionText.setTextColor(Color.WHITE); questionStatus.setText(R.string.question_unanswered); } // Reset data items and notifications on wearable. if (mGoogleApiClient.isConnected()) { Wearable.DataApi.getDataItems(mGoogleApiClient) .setResultCallback(new ResultCallback<DataItemBuffer>() { @Override public void onResult(DataItemBuffer result) { try { if (result.getStatus().isSuccess()) { resetDataItems(result); } else { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Reset quiz: failed to get Data Items to reset"); } } } finally { result.release(); } } }); } else { Log.e(TAG, "Failed to reset data items because client is disconnected from " + "Google Play Services"); } setHasQuestionBeenAsked(false); mNumCorrect = 0; mNumIncorrect = 0; mNumSkipped = 0; }
Example #12
Source File: ConfigHelper.java From FORMWatchFace with Apache License 2.0 | 5 votes |
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 #13
Source File: WatchFaceCompanionConfigActivity.java From american-sunsets-watch-face with Apache License 2.0 | 5 votes |
private void updateConfigDataItemAndUiOnStartup() { Log.d(TAG, "updateConfigDataItemAndUiOnStartup..."); PendingResult<DataItemBuffer> results = Wearable.DataApi.getDataItems(mGoogleApiClient); results.setResultCallback(new ResultCallback<DataItemBuffer>() { @Override public void onResult(DataItemBuffer dataItems) { if (dataItems.getCount() != 0) { DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItems.get(0)); // IMAGE int value = dataMapItem.getDataMap().getInt(SunsetsWatchFaceUtil.KEY_BACKGROUND_COLOR); updateUiForKey(SunsetsWatchFaceUtil.KEY_BACKGROUND_COLOR, value); //BATTERY SAVING MODE int value2 = dataMapItem.getDataMap().getInt(SunsetsWatchFaceUtil.KEY_FLUID_MODE); updateUiForKey(SunsetsWatchFaceUtil.KEY_FLUID_MODE, value2); Log.d(TAG, "aggiorno a startup background..."); } dataItems.release(); } }); }
Example #14
Source File: DataApiHandler.java From PowerSwitch_Android with GNU General Public License v3.0 | 5 votes |
/** * Retrieve scene data from Wear cloud storage * * @return List of Scenes */ public ArrayList<Scene> getSceneData() { ArrayList<Scene> scenes = new ArrayList<>(); if (!googleApiClient.isConnected()) { if (!blockingConnect()) { return null; } } ArrayList<DataMap> data; DataItemBuffer dataItemBuffer = Wearable.DataApi.getDataItems(googleApiClient).await(); if (dataItemBuffer.getStatus().isSuccess()) { for (DataItem dataItem : dataItemBuffer) { DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItem); data = dataMapItem.getDataMap().getDataMapArrayList(WearableConstants.EXTRA_DATA); if (data != null) { scenes = ListenerService.extractSceneDataMapItems(data); break; } } } dataItemBuffer.release(); return scenes; }
Example #15
Source File: FindPhoneService.java From android-FindMyPhone with Apache License 2.0 | 4 votes |
@Override protected void onHandleIntent(Intent intent) { mGoogleApiClient.blockingConnect(CONNECTION_TIME_OUT_MS, TimeUnit.MILLISECONDS); if (Log.isLoggable(TAG, Log.VERBOSE)) { Log.v(TAG, "FindPhoneService.onHandleIntent"); } if (mGoogleApiClient.isConnected()) { // Set the alarm off by default. boolean alarmOn = false; if (intent.getAction().equals(ACTION_TOGGLE_ALARM)) { // Get current state of the alarm. DataItemBuffer result = Wearable.DataApi.getDataItems(mGoogleApiClient).await(); try { if (result.getStatus().isSuccess()) { if (result.getCount() == 1) { alarmOn = DataMap.fromByteArray(result.get(0).getData()) .getBoolean(FIELD_ALARM_ON, false); } else { Log.e(TAG, "Unexpected number of DataItems found.\n" + "\tExpected: 1\n" + "\tActual: " + result.getCount()); } } else if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "onHandleIntent: failed to get current alarm state"); } } finally { result.release(); } // Toggle alarm. alarmOn = !alarmOn; // Change notification text based on new value of alarmOn. String notificationText = alarmOn ? getString(R.string.turn_alarm_off) : getString(R.string.turn_alarm_on); FindPhoneActivity.updateNotification(this, notificationText); } // Use alarmOn boolean to update the DataItem - phone will respond accordingly // when it receives the change. PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(PATH_SOUND_ALARM); putDataMapRequest.getDataMap().putBoolean(FIELD_ALARM_ON, alarmOn); putDataMapRequest.setUrgent(); Wearable.DataApi.putDataItem(mGoogleApiClient, putDataMapRequest.asPutDataRequest()) .await(); } else { Log.e(TAG, "Failed to toggle alarm on phone - Client disconnected from Google Play " + "Services"); } mGoogleApiClient.disconnect(); }
Example #16
Source File: DataApiImpl.java From android_external_GmsLib with Apache License 2.0 | 4 votes |
@Override public PendingResult<DataItemBuffer> getDataItems(GoogleApiClient client, Uri uri) { throw new UnsupportedOperationException(); }
Example #17
Source File: DataApiImpl.java From android_external_GmsLib with Apache License 2.0 | 4 votes |
@Override public PendingResult<DataItemBuffer> getDataItems(GoogleApiClient client) { throw new UnsupportedOperationException(); }
Example #18
Source File: FindPhoneService.java From AndroidWearable-Samples with Apache License 2.0 | 4 votes |
@Override protected void onHandleIntent(Intent intent) { mGoogleApiClient.blockingConnect(CONNECTION_TIME_OUT_MS, TimeUnit.MILLISECONDS); if (Log.isLoggable(TAG, Log.VERBOSE)) { Log.v(TAG, "FindPhoneService.onHandleIntent"); } if (mGoogleApiClient.isConnected()) { // Set the alarm off by default. boolean alarmOn = false; if (intent.getAction().equals(ACTION_TOGGLE_ALARM)) { // Get current state of the alarm. DataItemBuffer result = Wearable.DataApi.getDataItems(mGoogleApiClient).await(); if (result.getStatus().isSuccess()) { if (result.getCount() == 1) { alarmOn = DataMap.fromByteArray(result.get(0).getData()) .getBoolean(FIELD_ALARM_ON, false); } else { Log.e(TAG, "Unexpected number of DataItems found.\n" + "\tExpected: 1\n" + "\tActual: " + result.getCount()); } } else if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "onHandleIntent: failed to get current alarm state"); } result.close(); // Toggle alarm. alarmOn = !alarmOn; // Change notification text based on new value of alarmOn. String notificationText = alarmOn ? getString(R.string.turn_alarm_off) : getString(R.string.turn_alarm_on); FindPhoneActivity.updateNotification(this, notificationText); } // Use alarmOn boolean to update the DataItem - phone will respond accordingly // when it receives the change. PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(PATH_SOUND_ALARM); putDataMapRequest.getDataMap().putBoolean(FIELD_ALARM_ON, alarmOn); Wearable.DataApi.putDataItem(mGoogleApiClient, putDataMapRequest.asPutDataRequest()) .await(); } else { Log.e(TAG, "Failed to toggle alarm on phone - Client disconnected from Google Play " + "Services"); } mGoogleApiClient.disconnect(); }
Example #19
Source File: SunsetsGeneralWearableConfigActivity.java From american-sunsets-watch-face with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_general_config); colors = new String[]{getResources().getString(R.string.image),getResources().getString(R.string.fluid_motion)}; mHeader = (TextView) findViewById(R.id.header); listView = (WearableListView) findViewById(R.id.color_picker); BoxInsetLayout content = (BoxInsetLayout) findViewById(R.id.content); // BoxInsetLayout adds padding by default on round devices. Add some on square devices. content.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() { @Override public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) { if (!insets.isRound()) { v.setPaddingRelative( (int) getResources().getDimensionPixelSize(R.dimen.content_padding_start), v.getPaddingTop(), v.getPaddingEnd(), v.getPaddingBottom()); } return v.onApplyWindowInsets(insets); } }); listView.setHasFixedSize(true); listView.setClickListener(this); listView.addOnScrollListener(this); listView.setAdapter(new ColorListAdapter(colors)); mPeerId = getIntent().getStringExtra(WatchFaceCompanion.EXTRA_PEER_ID); mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { @Override public void onConnected(Bundle connectionHint) { Log.d(TAG, "onConnected: " + connectionHint); //Uri.Builder builder = new Uri.Builder(); //Uri uri = builder.scheme("wear").path(PATH_WITH_FEATURE).build(); //Wearable.DataApi.getDataItem(mGoogleApiClient, uri).setResultCallback(SunsetsGeneralWearableConfigActivity.this); new Thread() { @Override public void run() { PendingResult<DataItemBuffer> results = Wearable.DataApi.getDataItems(mGoogleApiClient,getUriForDataItem()); results.setResultCallback(new ResultCallback<DataItemBuffer>() { @Override public void onResult(DataItemBuffer dataItems) { if (dataItems.getCount() != 0) { for(int i=0; i<dataItems.getCount(); i++) { DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItems.get(i)); DataMap config = dataMapItem.getDataMap(); Log.d(TAG, "startup setup UI..."); updateUiForConfigDataMap(config); } } dataItems.release(); } }); } }.start(); Wearable.DataApi.addListener(mGoogleApiClient, SunsetsGeneralWearableConfigActivity.this); } @Override public void onConnectionSuspended(int cause) { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "onConnectionSuspended: " + cause); } } }) .addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() { @Override public void onConnectionFailed(ConnectionResult result) { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "onConnectionFailed: " + result); } } }) .addApi(Wearable.API) .build(); }