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

The following examples show how to use com.google.android.gms.wearable.DataMapItem#fromDataItem() . 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 DaVinci with Apache License 2.0 6 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    for (DataEvent event : dataEvents) {

        if (event.getType() == DataEvent.TYPE_CHANGED && event.getDataItem().getUri().getPath().startsWith("/elements/")) {
            DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem());
            List<DataMap> elementsDataMap = dataMapItem.getDataMap().getDataMapArrayList("/list/");

            if (elementList == null || elementList.isEmpty()) {
                elementList = new ArrayList<>();

                for (DataMap dataMap : elementsDataMap) {
                    elementList.add(getElement(dataMap));
                }

                startMainScreen();
            }

        }
    }
}
 
Example 2
Source File: DaVinci.java    From DaVinci with Apache License 2.0 6 votes vote down vote up
public Bitmap getBitmapFromDataApi(String path) {
    final Uri uri = getUriForDataItem(path);

    Log.d(TAG, "Load bitmap " + path + " " + uri.toString());

    if (uri != null) {
        final DataApi.DataItemResult result = Wearable.DataApi.getDataItem(mApiClient, uri).await();
        if (result != null && result.getDataItem() != null) {

            Log.d(TAG, "From DataApi");

            final DataMapItem dataMapItem = DataMapItem.fromDataItem(result.getDataItem());
            final Asset firstAsset = dataMapItem.getDataMap().getAsset(imageAssetName);
            if (firstAsset != null) {
                Bitmap bitmap = loadBitmapFromAsset(firstAsset);
                return bitmap;
            }
        }
    }

    Log.d(TAG, "can't find " + path + " [" + imageAssetName + "] in DataApi");

    return null;
}
 
Example 3
Source File: MainActivity.java    From TutosAndroidFrance with MIT License 6 votes vote down vote up
/**
 * Récupère une bitmap partagée avec le smartphone depuis une position
 */
public Bitmap getBitmap(int position) {
    final Uri uri = getUriForDataItem("/image/" + position);
    if (uri != null) {
        final DataApi.DataItemResult result = Wearable.DataApi.getDataItem(mApiClient, uri).await();
        if (result != null && result.getDataItem() != null) {

            final DataMapItem dataMapItem = DataMapItem.fromDataItem(result.getDataItem());
            final Asset firstAsset = dataMapItem.getDataMap().getAsset("image");
            if (firstAsset != null) {
                return loadBitmapFromAsset(firstAsset);

            }
        }
    }
    return null;
}
 
Example 4
Source File: WearDataLayerListenerService.java    From climb-tracker with Apache License 2.0 6 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    Log.d(TAG, "onDataChanged: " + dataEvents);
    final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents);
    dataEvents.close();
    for (DataEvent event : events) {
        Log.d(TAG, "Event: " + event.getDataItem().toString());
        Uri uri = event.getDataItem().getUri();
        String path = uri.getPath();

        if (path.equals(Path.GRADE_SYSTEM)) {
            DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem());
            String gradeSystem = dataMapItem.getDataMap().getString(Path.GRADE_SYSTEM_KEY);
            if (gradeSystem != null) {
                SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
                SharedPreferences.Editor editor = sharedPref.edit();
                editor.putString(Path.PREF_GRAD_SYSTEM_TYPE, gradeSystem);
                editor.commit();
            }
        }
    }
}
 
Example 5
Source File: MainActivity.java    From wearable with Apache License 2.0 6 votes vote down vote up
@Override
public void onDataChanged(@NonNull DataEventBuffer dataEventBuffer) {
    Log.d(TAG, "onDataChanged: " + dataEventBuffer);
    for (DataEvent event : dataEventBuffer) {
        if (event.getType() == DataEvent.TYPE_CHANGED) {
            String path = event.getDataItem().getUri().getPath();
            if (datapath.equals(path)) {
                DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem());
                String message = dataMapItem.getDataMap().getString("message");
                Log.v(TAG, "Wear activity received message: " + message);
                // Display message in UI
                mTextView.setText(message);

            } else {
                Log.e(TAG, "Unrecognized path: " + path);
            }
        } else if (event.getType() == DataEvent.TYPE_DELETED) {
            Log.v(TAG, "Data deleted : " + event.getDataItem().toString());
        } else {
            Log.e(TAG, "Unknown data event Type = " + event.getType());
        }
    }
}
 
Example 6
Source File: ListenerService.java    From io2015-codelabs with Apache License 2.0 6 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    Log.d(TAG, "onDataChanged: " + dataEvents);

    final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents);

    for (DataEvent event : events) {
        if (event.getType() == DataEvent.TYPE_CHANGED
                && event.getDataItem() != null
                && Constants.ATTRACTION_PATH.equals(event.getDataItem().getUri().getPath())) {

            DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem());
            ArrayList<DataMap> attractionsData =
                    dataMapItem.getDataMap().getDataMapArrayList(Constants.EXTRA_ATTRACTIONS);
            showNotification(dataMapItem.getUri(), attractionsData);
        }
    }
}
 
Example 7
Source File: ListenerService.java    From io2015-codelabs with Apache License 2.0 6 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    Log.d(TAG, "onDataChanged: " + dataEvents);

    final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents);

    for (DataEvent event : events) {
        if (event.getType() == DataEvent.TYPE_CHANGED
                && event.getDataItem() != null
                && Constants.ATTRACTION_PATH.equals(event.getDataItem().getUri().getPath())) {

            DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem());
            ArrayList<DataMap> attractionsData =
                    dataMapItem.getDataMap().getDataMapArrayList(Constants.EXTRA_ATTRACTIONS);
            showNotification(dataMapItem.getUri(), attractionsData);
        }
    }
}
 
Example 8
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 9
Source File: WatchfaceLoader.java    From APDE with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
	// Use only the most recent asset
	// I don't think we will ever get more than one at once,
	// but there's no sense in installing an old version of the APK
	
	Asset asset = null;
	
	for (DataEvent dataEvent : dataEvents) {
		if (dataEvent.getType() == DataEvent.TYPE_CHANGED) {
			DataMapItem dataMapItem = DataMapItem.fromDataItem(dataEvent.getDataItem());
			asset = dataMapItem.getDataMap().getAsset("apk");
		}
	}
	
	// We tried displaying a toast, but it causes problems
	
	// Make apk file in internal storage
	File apkFile = WatchFaceUtil.getSketchApk(this);
	
	if (asset != null && makeFileFromAsset(asset, apkFile)) {
		clearAssets();
		unpackAssets(apkFile);
		clearSharedPrefs();
		updateServiceType();
		updateWatchFaceVisibility();
		launchWatchFaceChooser();
	}
}
 
Example 10
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 11
Source File: CrashReport.java    From AndroidWearCrashReport with Apache License 2.0 5 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    for (DataEvent event : dataEvents) {
        if (event.getType() == DataEvent.TYPE_CHANGED &&
                event.getDataItem().getUri().getPath().contains("/EXCEPTION")) {

            //A new Exception has been received
            DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem());

            //Get the exception
            byte[] serializedException = dataMapItem.getDataMap().getByteArray("ex");
            Throwable throwable = (Throwable) Utils.deserializeObject(serializedException);

            //Send it with the listener
            if (throwable != null) {

                if (onCrashListener != null) {
                    currentCrashInfo = new CrashInfo.Builder(throwable)
                            .fingerprint(dataMapItem.getDataMap().getString("fingerprint"))
                            .manufacturer(dataMapItem.getDataMap().getString("manufacturer"))
                            .model(dataMapItem.getDataMap().getString("model"))
                            .product(dataMapItem.getDataMap().getString("product"))
                            .versionCode(dataMapItem.getDataMap().getInt("versionCode"))
                            .versionName(dataMapItem.getDataMap().getString("versionName"))
                            .build();
                    onCrashListener.onCrashReceived(currentCrashInfo);
                }
                this.currentException = throwable;
            }
        }
    }
}
 
Example 12
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 13
Source File: WatchService.java    From WearPay with GNU General Public License v2.0 5 votes vote down vote up
@DebugLog
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    for (DataEvent event : dataEvents) {
        Uri uri = event.getDataItem().getUri();
        String path = uri.getPath();
        if (Common.PATH_CODE.equals(path)) {
            //
        } else if (Common.PATH_QR_CODE.equals(path)) {
            DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem());
            final Asset qrPhoto = dataMapItem.getDataMap().getAsset(Common.KEY_QR_CODE);
            final Asset barPhoto = dataMapItem.getDataMap().getAsset(Common.KEY_BAR_CODE);

            new AsyncTask<Asset, Void, Bitmap[]>() {
                @Override
                protected Bitmap[] doInBackground(Asset... assets) {

                    return new Bitmap[]{loadBitmapFromAsset(assets[0]), loadBitmapFromAsset(assets[1])};
                }

                @Override
                protected void onPostExecute(Bitmap[] bitmaps) {
                    wearPayBinder.onCodeChange(bitmaps[0], bitmaps[1]);
                }
            }.execute(barPhoto, qrPhoto);

        }
    }
}
 
Example 14
Source File: ListenerService.java    From ETSMobile-Android2 with Apache License 2.0 5 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEvents) {

    Log.d(TAG, "onDataChanged: " + dataEvents);

    for (DataEvent event : dataEvents) {
        if (event.getType() == DataEvent.TYPE_CHANGED
                && event.getDataItem() != null
                && event.getDataItem().getUri().getPath().equals("/today_req")) {

            DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem());
            ArrayList<DataMap> seancesDataMapList = dataMapItem.getDataMap().getDataMapArrayList("list_seances");

            ArrayList<Seances> seances = new ArrayList<>();

            for (DataMap seanceDataMap : seancesDataMapList) {
                Seances seance = new Seances();
                seance.getData(seanceDataMap);
                seances.add(seance);
            }

            Intent intent = new Intent("seances_update");
            intent.putExtra("seances", seances);
            LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
        }
    }
    super.onDataChanged(dataEvents);
}
 
Example 15
Source File: DataApiHandler.java    From PowerSwitch_Android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 16
Source File: OngoingNotificationListenerService.java    From WearOngoingNotificationSample with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
    public void onDataChanged(DataEventBuffer dataEvents) {
        final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents);
        dataEvents.close();

        if (!mGoogleApiClient.isConnected()) {
            ConnectionResult connectionResult = mGoogleApiClient
                    .blockingConnect(30, TimeUnit.SECONDS);
            if (!connectionResult.isSuccess()) {
                Log.e(TAG, "Service failed to connect to GoogleApiClient.");
                return;
            }
        }

        for (DataEvent event : events) {
            if (event.getType() == DataEvent.TYPE_CHANGED) {
                String path = event.getDataItem().getUri().getPath();
                if (Constants.PATH_NOTIFICATION.equals(path)) {
                    // Get the data out of the event
                    DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem());
                    final String title = dataMapItem.getDataMap().getString(Constants.KEY_TITLE);
                    Asset asset = dataMapItem.getDataMap().getAsset(Constants.KEY_IMAGE);

                    // Build the intent to display our custom notification
                    Intent notificationIntent = new Intent(this, NotificationActivity.class);
                    notificationIntent.putExtra(NotificationActivity.EXTRA_TITLE, title);
                    notificationIntent.putExtra(NotificationActivity.EXTRA_IMAGE, asset);
                    PendingIntent notificationPendingIntent = PendingIntent.getActivity(
                            this,
                            0,
                            notificationIntent,
                            PendingIntent.FLAG_UPDATE_CURRENT);

                    // Create the ongoing notification

                    // Use this for multipage notifications
//                    Notification secondPageNotification =
//                            new Notification.Builder(this)
//                                    .extend(new Notification.WearableExtender()
//                                            .setDisplayIntent(notificationPendingIntent))
//                                    .build();

                    Notification.Builder notificationBuilder =
                            new Notification.Builder(this)
                                    .setSmallIcon(R.drawable.ic_launcher)
                                    .extend(new Notification.WearableExtender()
                                            .setDisplayIntent(notificationPendingIntent)
//                                            .addPage(secondPageNotification)
                                    );

                    ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
                            .notify(NOTIFICATION_ID, notificationBuilder.build());
                } else {
                    Log.d(TAG, "Unrecognized path: " + path);
                }
            }
        }
    }
 
Example 17
Source File: AttractionsActivity.java    From io2015-codelabs with Apache License 2.0 4 votes vote down vote up
@Override
protected ArrayList<Attraction> doInBackground(Uri... params) {
    mAttractions.clear();

    // Connect to Play Services and the Wearable API
    GoogleApiClient googleApiClient = new GoogleApiClient.Builder(mContext)
            .addApi(Wearable.API)
            .build();

    ConnectionResult connectionResult = googleApiClient.blockingConnect(
            Constants.GOOGLE_API_CLIENT_TIMEOUT_S, TimeUnit.SECONDS);

    if (!connectionResult.isSuccess() || !googleApiClient.isConnected()) {
        Log.e(TAG, String.format(Constants.GOOGLE_API_CLIENT_ERROR_MSG,
                connectionResult.getErrorCode()));
        return null;
    }

    Uri attractionsUri = params[0];
    DataApi.DataItemResult dataItemResult =
            Wearable.DataApi.getDataItem(googleApiClient, attractionsUri).await();

    if (dataItemResult.getStatus().isSuccess() && dataItemResult.getDataItem() != null) {
        DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItemResult.getDataItem());
        List<DataMap> attractionsData =
                dataMapItem.getDataMap().getDataMapArrayList(Constants.EXTRA_ATTRACTIONS);

        // Loop through each attraction, adding them to the list
        Iterator<DataMap> itr = attractionsData.iterator();
        while (itr.hasNext()) {
            DataMap attractionData = itr.next();

            Attraction attraction = new Attraction();
            attraction.name = attractionData.getString(Constants.EXTRA_TITLE);
            attraction.description =
                    attractionData.getString(Constants.EXTRA_DESCRIPTION);
            attraction.city = attractionData.get(Constants.EXTRA_CITY);
            attraction.distance =
                    attractionData.getString(Constants.EXTRA_DISTANCE);
            attraction.location = new LatLng(
                    attractionData.getDouble(Constants.EXTRA_LOCATION_LAT),
                    attractionData.getDouble(Constants.EXTRA_LOCATION_LNG));
            attraction.image = Utils.loadBitmapFromAsset(googleApiClient,
                    attractionData.getAsset(Constants.EXTRA_IMAGE));
            attraction.secondaryImage = Utils.loadBitmapFromAsset(googleApiClient,
                    attractionData.getAsset(Constants.EXTRA_IMAGE_SECONDARY));

            mAttractions.add(attraction);
        }
    }

    googleApiClient.disconnect();

    return mAttractions;
}
 
Example 18
Source File: AttractionsActivity.java    From wear-os-samples with Apache License 2.0 4 votes vote down vote up
@Override
protected ArrayList<Attraction> doInBackground(Uri... params) {
    mAttractions.clear();

    // Connect to Play Services and the Wearable API
    GoogleApiClient googleApiClient = new GoogleApiClient.Builder(mContext)
            .addApi(Wearable.API)
            .build();

    ConnectionResult connectionResult = googleApiClient.blockingConnect(
            Constants.GOOGLE_API_CLIENT_TIMEOUT_S, TimeUnit.SECONDS);

    if (!connectionResult.isSuccess() || !googleApiClient.isConnected()) {
        Log.e(TAG, String.format(Constants.GOOGLE_API_CLIENT_ERROR_MSG,
                connectionResult.getErrorCode()));
        return null;
    }

    Uri attractionsUri = params[0];
    DataApi.DataItemResult dataItemResult =
            Wearable.DataApi.getDataItem(googleApiClient, attractionsUri).await();

    if (dataItemResult.getStatus().isSuccess() && dataItemResult.getDataItem() != null) {
        DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItemResult.getDataItem());
        List<DataMap> attractionsData =
                dataMapItem.getDataMap().getDataMapArrayList(Constants.EXTRA_ATTRACTIONS);

        // Loop through each attraction, adding them to the list
        Iterator<DataMap> itr = attractionsData.iterator();
        while (itr.hasNext()) {
            DataMap attractionData = itr.next();

            Attraction attraction = new Attraction();
            attraction.name = attractionData.getString(Constants.EXTRA_TITLE);
            attraction.description =
                    attractionData.getString(Constants.EXTRA_DESCRIPTION);
            attraction.city = attractionData.get(Constants.EXTRA_CITY);
            attraction.distance =
                    attractionData.getString(Constants.EXTRA_DISTANCE);
            attraction.location = new LatLng(
                    attractionData.getDouble(Constants.EXTRA_LOCATION_LAT),
                    attractionData.getDouble(Constants.EXTRA_LOCATION_LNG));
            attraction.image = Utils.loadBitmapFromAsset(googleApiClient,
                    attractionData.getAsset(Constants.EXTRA_IMAGE));
            attraction.secondaryImage = Utils.loadBitmapFromAsset(googleApiClient,
                    attractionData.getAsset(Constants.EXTRA_IMAGE_SECONDARY));

            mAttractions.add(attraction);
        }
    }

    googleApiClient.disconnect();

    return mAttractions;
}
 
Example 19
Source File: AttractionsActivity.java    From io2015-codelabs with Apache License 2.0 4 votes vote down vote up
@Override
protected ArrayList<Attraction> doInBackground(Uri... params) {
    mAttractions.clear();

    // Connect to Play Services and the Wearable API
    GoogleApiClient googleApiClient = new GoogleApiClient.Builder(mContext)
            .addApi(Wearable.API)
            .build();

    ConnectionResult connectionResult = googleApiClient.blockingConnect(
            Constants.GOOGLE_API_CLIENT_TIMEOUT_S, TimeUnit.SECONDS);

    if (!connectionResult.isSuccess() || !googleApiClient.isConnected()) {
        Log.e(TAG, String.format(Constants.GOOGLE_API_CLIENT_ERROR_MSG,
                connectionResult.getErrorCode()));
        return null;
    }

    Uri attractionsUri = params[0];
    DataApi.DataItemResult dataItemResult =
            Wearable.DataApi.getDataItem(googleApiClient, attractionsUri).await();

    if (dataItemResult.getStatus().isSuccess() && dataItemResult.getDataItem() != null) {
        DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItemResult.getDataItem());
        List<DataMap> attractionsData =
                dataMapItem.getDataMap().getDataMapArrayList(Constants.EXTRA_ATTRACTIONS);

        // Loop through each attraction, adding them to the list
        Iterator<DataMap> itr = attractionsData.iterator();
        while (itr.hasNext()) {
            DataMap attractionData = itr.next();

            Attraction attraction = new Attraction();
            attraction.name = attractionData.getString(Constants.EXTRA_TITLE);
            attraction.description =
                    attractionData.getString(Constants.EXTRA_DESCRIPTION);
            attraction.city = attractionData.get(Constants.EXTRA_CITY);
            attraction.distance =
                    attractionData.getString(Constants.EXTRA_DISTANCE);
            attraction.location = new LatLng(
                    attractionData.getDouble(Constants.EXTRA_LOCATION_LAT),
                    attractionData.getDouble(Constants.EXTRA_LOCATION_LNG));
            attraction.image = Utils.loadBitmapFromAsset(googleApiClient,
                    attractionData.getAsset(Constants.EXTRA_IMAGE));
            attraction.secondaryImage = Utils.loadBitmapFromAsset(googleApiClient,
                    attractionData.getAsset(Constants.EXTRA_IMAGE_SECONDARY));

            mAttractions.add(attraction);
        }
    }

    googleApiClient.disconnect();

    return mAttractions;
}
 
Example 20
Source File: Packager.java    From courier with Apache License 2.0 3 votes vote down vote up
/**
 * In general, this method will only be used by generated code. However, it may be suitable
 * to use this method in some cases (such as in a WearableListenerService).
 *
 * Unpacks the given DataItem into an object of the given class.
 *
 * This method will attempt to load a DataMap from the DataItem and then use generated code from
 * the {@link Deliverable} annotation to convert it to an object of the given class.
 *
 * If this is not possible, this method will then attempt to deserialize the byte array contained
 * in the DataItem using the {@link java.io.Serializable} system.
 *
 * @param context The Context that may be used to load Assets from the data.
 * @param data  The DataItem to load the object from.
 * @param targetClass The class of object to unpack.
 * @return An object of the given class.
 */
public static <T> T unpack(Context context, DataItem data, Class<T> targetClass) {
    try {
        final DataMapItem dataMapItem = DataMapItem.fromDataItem(data);
        return unpack(context, dataMapItem.getDataMap(), targetClass);
    }catch (Exception e) {
        return unpackSerializable(data.getData());
    }
}