Search in sources :

Example 1 with DataItem

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();
}
Also used : GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) DataItem(com.google.android.gms.wearable.DataItem) ConnectionResult(com.google.android.gms.common.ConnectionResult) DataItemBuffer(com.google.android.gms.wearable.DataItemBuffer)

Example 2 with DataItem

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();
}
Also used : GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) DataItem(com.google.android.gms.wearable.DataItem) Bundle(android.os.Bundle) ComplicationData(android.support.wearable.complications.ComplicationData) Nullable(android.support.annotation.Nullable)

Aggregations

GoogleApiClient (com.google.android.gms.common.api.GoogleApiClient)2 DataItem (com.google.android.gms.wearable.DataItem)2 Bundle (android.os.Bundle)1 Nullable (android.support.annotation.Nullable)1 ComplicationData (android.support.wearable.complications.ComplicationData)1 ConnectionResult (com.google.android.gms.common.ConnectionResult)1 DataItemBuffer (com.google.android.gms.wearable.DataItemBuffer)1