use of com.google.android.gms.wearable.DataItem in project muzei by romannurik.
the class ArtworkCacheIntentService method onHandleIntent.
@Override
protected void onHandleIntent(Intent intent) {
GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this).addApi(Wearable.API).build();
ConnectionResult connectionResult = googleApiClient.blockingConnect(30, TimeUnit.SECONDS);
if (!connectionResult.isSuccess()) {
Log.e(TAG, "Failed to connect to GoogleApiClient: " + connectionResult.getErrorCode());
return;
}
// Read all DataItems
DataItemBuffer dataItemBuffer = Wearable.DataApi.getDataItems(googleApiClient).await();
if (!dataItemBuffer.getStatus().isSuccess()) {
Log.e(TAG, "Error getting all data items: " + dataItemBuffer.getStatus().getStatusMessage());
}
Iterator<DataItem> dataItemIterator = dataItemBuffer.singleRefIterator();
boolean foundArtwork = false;
while (dataItemIterator.hasNext()) {
DataItem dataItem = dataItemIterator.next();
foundArtwork = foundArtwork || processDataItem(googleApiClient, dataItem);
}
dataItemBuffer.release();
if (foundArtwork) {
// Enable the Full Screen Activity and Artwork Complication Provider Service only if we've found artwork
enableComponents(FullScreenActivity.class, ArtworkComplicationProviderService.class);
}
if (!foundArtwork && intent != null && intent.getBooleanExtra(SHOW_ACTIVATE_NOTIFICATION_EXTRA, false)) {
ActivateMuzeiIntentService.maybeShowActivateMuzeiNotification(this);
} else {
ActivateMuzeiIntentService.clearNotifications(this);
}
googleApiClient.disconnect();
}
use of com.google.android.gms.wearable.DataItem in project Memento-Calendar by alexstyl.
the class ContactEventsProviderService method onComplicationUpdate.
@Override
public void onComplicationUpdate(final int complicationId, final int dataType, final ComplicationManager complicationManager) {
GoogleApiClient.ConnectionCallbacks connectionCallbacks = new GoogleApiClient.ConnectionCallbacks() {
@Override
public void onConnected(@Nullable Bundle bundle) {
wearCommunicationService.loadDataItems(new WearCommunicationService.Callback() {
@Override
public void onDataItemsLoaded(DataItem item) {
ComplicationData complicationData = createComplicationData(item, dataType);
if (complicationData != null) {
complicationManager.updateComplicationData(complicationId, complicationData);
}
}
@Override
public void onNoDataItemsAvailable() {
ComplicationData emptyComplicationData = createComplicationData(dataType, NO_DATE_AVAILABLE, Collections.<String>emptyList());
complicationManager.updateComplicationData(complicationId, emptyComplicationData);
}
});
}
@Override
public void onConnectionSuspended(int i) {
// no-op
}
};
GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this).addApi(Wearable.API).addConnectionCallbacks(connectionCallbacks).build();
wearCommunicationService = new WearCommunicationService(googleApiClient);
googleApiClient.connect();
}
Aggregations