Java Code Examples for com.google.android.gms.wearable.Asset#createFromBytes()
The following examples show how to use
com.google.android.gms.wearable.Asset#createFromBytes() .
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: WatchServices.java From WearPay with GNU General Public License v2.0 | 6 votes |
/** * Builds an {@link com.google.android.gms.wearable.Asset} from a bitmap. The image that we get * back from the camera in "data" is a thumbnail size. Typically, your image should not exceed * 320x320 and if you want to have zoom and parallax effect in your app, limit the size of your * image to 640x400. Resize your image before transferring to your wearable device. */ private static Asset toAsset(Bitmap bitmap) { ByteArrayOutputStream byteStream = null; try { byteStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 50, byteStream); return Asset.createFromBytes(byteStream.toByteArray()); } finally { if (null != byteStream) { try { byteStream.close(); } catch (IOException e) { // ignore } } } }
Example 2
Source File: MainActivity.java From AndroidWearable-Samples with Apache License 2.0 | 6 votes |
/** * Builds an {@link com.google.android.gms.wearable.Asset} from a bitmap. The image that we get * back from the camera in "data" is a thumbnail size. Typically, your image should not exceed * 320x320 and if you want to have zoom and parallax effect in your app, limit the size of your * image to 640x400. Resize your image before transferring to your wearable device. */ private static Asset toAsset(Bitmap bitmap) { ByteArrayOutputStream byteStream = null; try { byteStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteStream); return Asset.createFromBytes(byteStream.toByteArray()); } finally { if (null != byteStream) { try { byteStream.close(); } catch (IOException e) { // ignore } } } }
Example 3
Source File: CalendarQueryService.java From AndroidWearable-Samples with Apache License 2.0 | 6 votes |
private static Asset getProfilePicture(ContentResolver contentResolver, Context context, long contactId) { if (contactId != -1) { // Try to retrieve the profile picture for the given contact. Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId); InputStream inputStream = Contacts.openContactPhotoInputStream(contentResolver, contactUri, true /*preferHighres*/); if (null != inputStream) { try { Bitmap bitmap = BitmapFactory.decodeStream(inputStream); if (bitmap != null) { return Asset.createFromBytes(toByteArray(bitmap)); } else { Log.e(TAG, "Cannot decode profile picture for contact " + contactId); } } finally { closeQuietly(inputStream); } } } // Use a default background image if the user has no profile picture or there was an error. return getDefaultProfile(context.getResources()); }
Example 4
Source File: Utils.java From wear-os-samples with Apache License 2.0 | 5 votes |
/** * Create a wearable asset from a bitmap. */ public static Asset createAssetFromBitmap(Bitmap bitmap) { if (bitmap != null) { final ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteStream); return Asset.createFromBytes(byteStream.toByteArray()); } return null; }
Example 5
Source File: WatchUpdaterService.java From xDrip with GNU General Public License v3.0 | 5 votes |
private void sendBlob(String path, final byte[] blob) { forceGoogleApiConnect(); if (googleApiClient.isConnected()) { final Asset asset = Asset.createFromBytes(blob); Log.d(TAG, "sendBlob asset size: " + asset.getData().length); final PutDataMapRequest request = PutDataMapRequest.create(path); request.getDataMap().putLong("time", new Date().getTime()); request.getDataMap().putByteArray("asset", blob); request.setUrgent(); final PendingResult result = Wearable.DataApi.putDataItem(googleApiClient, request.asPutDataRequest()); result.setResultCallback(new ResultCallback<DataApi.DataItemResult>() { @Override public void onResult(DataApi.DataItemResult sendMessageResult) { if (!sendMessageResult.getStatus().isSuccess()) { UserError.Log.e(TAG, "ERROR: failed to sendblob Status=" + sendMessageResult.getStatus().getStatusMessage()); } else { UserError.Log.i(TAG, "Sendblob Status=: " + sendMessageResult.getStatus().getStatusMessage()); } } }); Log.d(TAG, "sendBlob: Sending asset of size " + blob.length); } else { Log.e(TAG, "sendBlob: No connection to wearable available!"); } }
Example 6
Source File: WatchUpdaterService.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
private void sendBlob(String path, final byte[] blob) { forceGoogleApiConnect(); if (googleApiClient.isConnected()) { final Asset asset = Asset.createFromBytes(blob); Log.d(TAG, "sendBlob asset size: " + asset.getData().length); final PutDataMapRequest request = PutDataMapRequest.create(path); request.getDataMap().putLong("time", new Date().getTime()); request.getDataMap().putByteArray("asset", blob); request.setUrgent(); final PendingResult result = Wearable.DataApi.putDataItem(googleApiClient, request.asPutDataRequest()); result.setResultCallback(new ResultCallback<DataApi.DataItemResult>() { @Override public void onResult(DataApi.DataItemResult sendMessageResult) { if (!sendMessageResult.getStatus().isSuccess()) { UserError.Log.e(TAG, "ERROR: failed to sendblob Status=" + sendMessageResult.getStatus().getStatusMessage()); } else { UserError.Log.i(TAG, "Sendblob Status=: " + sendMessageResult.getStatus().getStatusMessage()); } } }); Log.d(TAG, "sendBlob: Sending asset of size " + blob.length); } else { Log.e(TAG, "sendBlob: No connection to wearable available!"); } }
Example 7
Source File: WearManager.java From DeviceConnect-Android with MIT License | 5 votes |
/** * PutDataRequestを作成する. * * @param nodeId ノードID * @param requestId リクエストID * @param data requestに格納する画像 * @param x x座標 * @param y y座標 * @param mode 描画モード * @return PutDataRequestのインスタンス */ private PutDataRequest createPutDataRequest(final String nodeId, final String requestId, final byte[] data, final int x, final int y, final int mode) { Asset asset = Asset.createFromBytes(data); PutDataMapRequest dataMap = PutDataMapRequest.create(WearConst.PATH_CANVAS + "/" + nodeId + "/" + requestId); dataMap.getDataMap().putAsset(WearConst.PARAM_BITMAP, asset); dataMap.getDataMap().putInt(WearConst.PARAM_X, x); dataMap.getDataMap().putInt(WearConst.PARAM_Y, y); dataMap.getDataMap().putInt(WearConst.PARAM_MODE, mode); dataMap.getDataMap().putLong(WearConst.TIMESTAMP, System.currentTimeMillis()); return dataMap.asPutDataRequest(); }
Example 8
Source File: Utils.java From io2015-codelabs with Apache License 2.0 | 5 votes |
/** * Create a wearable asset from a bitmap. */ public static Asset createAssetFromBitmap(Bitmap bitmap) { if (bitmap != null) { final ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteStream); return Asset.createFromBytes(byteStream.toByteArray()); } return null; }
Example 9
Source File: Utils.java From io2015-codelabs with Apache License 2.0 | 5 votes |
/** * Create a wearable asset from a bitmap. */ public static Asset createAssetFromBitmap(Bitmap bitmap) { if (bitmap != null) { final ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteStream); return Asset.createFromBytes(byteStream.toByteArray()); } return null; }
Example 10
Source File: MessageHandler.java From android_packages_apps_GmsCore with Apache License 2.0 | 5 votes |
@Override public void onSetAsset(SetAsset setAsset) { Log.d(TAG, "onSetAsset: " + setAsset); Asset asset; if (setAsset.data != null) { asset = Asset.createFromBytes(setAsset.data.toByteArray()); } else { asset = Asset.createFromRef(setAsset.digest); } wearable.addAssetToDatabase(asset, setAsset.appkeys.appKeys); }
Example 11
Source File: WearService.java From TutosAndroidFrance with MIT License | 4 votes |
/** * Les bitmap transferés depuis les DataApi doivent être empaquetées en Asset */ public static Asset createAssetFromBitmap(Bitmap bitmap) { final ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteStream); return Asset.createFromBytes(byteStream.toByteArray()); }
Example 12
Source File: AssetUtil.java From OkWear with Apache License 2.0 | 4 votes |
protected static Asset createAssetFromBitmap(final Bitmap bitmap, final Bitmap.CompressFormat format, final int quality) { final ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); bitmap.compress(format, quality, byteStream); return Asset.createFromBytes(byteStream.toByteArray()); }
Example 13
Source File: CardMedia.java From AnkiDroid-Wear with GNU General Public License v2.0 | 4 votes |
public static Asset createAssetFromBitmap(Bitmap bitmap) { final ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteStream); return Asset.createFromBytes(byteStream.toByteArray()); }
Example 14
Source File: DaVinciDaemon.java From DaVinci with Apache License 2.0 | 4 votes |
public static Asset createAssetFromBitmap(Bitmap bitmap) { final ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteStream); return Asset.createFromBytes(byteStream.toByteArray()); }
Example 15
Source File: CalendarQueryService.java From AndroidWearable-Samples with Apache License 2.0 | 4 votes |
private static Asset getDefaultProfile(Resources res) { Bitmap bitmap = BitmapFactory.decodeResource(res, R.drawable.nobody); return Asset.createFromBytes(toByteArray(bitmap)); }
Example 16
Source File: MainActivity.java From WearOngoingNotificationSample with BSD 3-Clause "New" or "Revised" License | 4 votes |
private static Asset createAssetFromBitmap(Bitmap bitmap) { final ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteStream); return Asset.createFromBytes(byteStream.toByteArray()); }