/** * Extracts byte array data from an * {@link com.google.android.gms.wearable.Asset}, in a blocking way, hence should not be called * on the UI thread. This may return {@code null}. */ public byte[] loadAssetSynchronous(Asset asset) throws IOException { assertApiConnectivity(); WearUtil.assertNonUiThread(); if (asset == null) { throw new IllegalArgumentException("Asset must be non-null"); } InputStream assetInputStream = Wearable.DataApi.getFdForAsset( mGoogleApiClient, asset).await().getInputStream(); if (assetInputStream == null) { Log.w(TAG, "Requested an unknown Asset."); return null; } ByteArrayOutputStream output = new ByteArrayOutputStream(); int n = 0; byte[] buffer = new byte[4096]; while (-1 != (n = assetInputStream.read(buffer))) { output.write(buffer, 0, n); } return output.toByteArray(); }
/** * Obtain a {@link PutDataRequest} to update a league's current state. * * @param account the account which owns the team competing in the league * @param league a proto describing the league * @param matchup a proto describing the account's team's current matchup * @param logo an Asset containing the user's logo image. The image should be square with size * {@link com.jeffpdavidson.fantasywear.common.R.dimen#logo_size}. * @param opponentLogo an Asset containing the user's opponent's logo image. The image should be * square with size * {@link com.jeffpdavidson.fantasywear.common.R.dimen#logo_size}. * @param forceUpdate if true, will ensure that listening devices see the update even if no * fields have changed since the last update. Use conservatively as this will */ public static PutDataRequest getUpdateRequest(Account account, League league, Matchup matchup, Asset logo, Asset opponentLogo, boolean forceUpdate) { PutDataMapRequest request = PutDataMapRequest.create(getLeagueUri(account, league).toString()); DataMap map = request.getDataMap(); map.putInt(KEY_APP_VERSION, BuildConfig.VERSION_CODE); map.putString(KEY_MATCHUP, WireUtil.encodeToString(matchup)); map.putAsset(KEY_LOGO, logo); map.putAsset(KEY_OPPONENT_LOGO, opponentLogo); if (forceUpdate) { // Play services suppresses updates if the payload exactly matches the last one, so when // forcing an update, include the current time to guarantee a unique payload. map.putLong(KEY_TIMESTAMP, System.currentTimeMillis()); } return request.asPutDataRequest(); }
private void alarmCommand(Intent intent) { AlarmCommand commandData = intent.getParcelableExtra(KEY_COMMAND_DATA); LiteAlarmCommand liteAlarmCommand = new LiteAlarmCommand(commandData); PutDataRequest putDataRequest = PutDataRequest.create(CommPaths.COMMAND_ALARM); putDataRequest.setData(ParcelPacker.getData(liteAlarmCommand)); if (commandData.getIcon() != null) { putDataRequest.putAsset(CommPaths.ASSET_ICON, Asset.createFromBytes(commandData.getIcon())); } if (commandData.getBackgroundBitmap() != null) { putDataRequest.putAsset(CommPaths.ASSET_BACKGROUND, Asset.createFromBytes(commandData.getBackgroundBitmap())); } putDataRequest.setUrgent(); Wearable.DataApi.putDataItem(googleApiClient, putDataRequest).await(); }
private Bitmap loadBitmapFromAsset(GoogleApiClient apiClient, Asset asset) { if (asset == null) { throw new IllegalArgumentException("Asset must be non-null"); } /*InputStream assetInputStream = Wearable.DataApi.getFdForAsset( apiClient, asset).await().getInputStream(); */ final InputStream[] assetInputStream = new InputStream[1]; Wearable.DataApi.getFdForAsset(apiClient, asset).setResultCallback(new ResultCallback<DataApi.GetFdForAssetResult>() { @Override public void onResult(DataApi.GetFdForAssetResult getFdForAssetResult) { assetInputStream[0] = getFdForAssetResult.getInputStream(); } }); if (assetInputStream[0] == null) { Log.w(TAG, "Requested an unknown Asset."); return null; } return BitmapFactory.decodeStream(assetInputStream[0]); }
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 } } } }
@Override public void onDataChanged(DataEventBuffer dataEvents) { for (int i = 0; i < dataEvents.getCount(); i++) { DataEvent event = dataEvents.get(i); if (event.getType() == DataEvent.TYPE_CHANGED && event.getDataItem().getUri().getPath().equals(APP_DATA_UPDATE_REQUEST)) { DataMap dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap(); Asset asset = dataMap.getAsset("dataIcon"); WatchFaceService.highTemp = dataMap.getInt("dataHigh"); WatchFaceService.lowTemp = dataMap.getInt("dataLow"); doLoadBitmap(asset); } } }
private void doLoadBitmap(Asset asset) { if (null == asset) { return; } final GoogleApiClient googleApiClient = getGoogleApiClient(); googleApiClient.connect(); InputStream assetInputStream = Wearable.DataApi.getFdForAsset(googleApiClient, asset).await().getInputStream(); googleApiClient.disconnect(); if (assetInputStream == null) { return; } WatchFaceService.currCondImage = BitmapFactory.decodeStream(assetInputStream); WatchFaceService.updateClockFace(); }
private void sendData(Asset asset) { if (asset == null) { return; } PutDataMapRequest dataMap = PutDataMapRequest.create(WEAR_PATH); byte[] arr = asset.getData(); dataMap.getDataMap().putByteArray(DATA_ASSET_FILE, arr); dataMap.getDataMap().putLong("timestamp", Calendar.getInstance().getTimeInMillis()); PutDataRequest request = dataMap.asPutDataRequest(); PendingResult<DataApi.DataItemResult> pendingResult = Wearable.DataApi.putDataItem(mGoogleAppiClient, request); pendingResult.setResultCallback(new ResultCallback<DataApi.DataItemResult>() { @Override public void onResult(DataApi.DataItemResult dataItemResult) { Log.d(TAG, "onResult result:" + dataItemResult.getStatus()); } }); }
/** * Sends payload, should be only called from this class and its subclasses * * @param path * @param data */ protected void sendDataItemWithoutConnectionCheck(DataPath path, TimeStampStorable data) { Logger.logD(getClass().getSimpleName(), "Sending " + path); PutDataRequest request = PutDataRequest.create(path.getPath()); final byte[] dataToSend = data.getAsBytes(); // check data size whether to send as and asset or plain data item if (dataToSend.length >= MAX_DATA_ITEM_SIZE_B) { request.putAsset(DataPath.DEFAULT_ASSET_KEY, Asset.createFromBytes(dataToSend)); } else { request.setData(dataToSend); } if (path.isUrgent()) { request.setUrgent(); } PendingResult<DataApi.DataItemResult> pendingResult = Wearable.DataApi.putDataItem(mGoogleApiClient, request); }
@Override protected Bitmap doInBackground(Asset... params) { if (params.length > 0) { Asset asset = params[0]; InputStream assetInputStream = Wearable.DataApi.getFdForAsset( mGoogleApiClient, asset).await().getInputStream(); if (assetInputStream == null) { Log.w(TAG, "Requested an unknown Asset."); return null; } return BitmapFactory.decodeStream(assetInputStream); } else { Log.e(TAG, "Asset must be non-null"); return null; } }
public static Asset toAsset(int artResource, Context context) { Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), artResource); 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 } } } }
private void sendTodayForecast(double maxTemp, double minTemp, int weatherId) { PutDataMapRequest dataMap = PutDataMapRequest.create(FORECAST_PATH).setUrgent(); String lowString = Utility.formatTemperature(getContext(), minTemp); String highString = Utility.formatTemperature(getContext(), maxTemp); dataMap.getDataMap().putString(MAX_TEMP_KEY, highString); dataMap.getDataMap().putString(MIN_TEMP_KEY, lowString); int artResource = Utility.getArtResourceForWeatherCondition(weatherId); Asset weatherIcon = Utility.toAsset(artResource, getContext()); dataMap.getDataMap().putAsset(WEATHER_ICON_KEY, weatherIcon); dataMap.getDataMap().putLong(TIMESTAMP_KEY, System.currentTimeMillis()); PutDataRequest request = dataMap.asPutDataRequest(); Wearable.DataApi.putDataItem(mGoogleApiClient, request) .setResultCallback(new ResultCallback<DataApi.DataItemResult>() { @Override public void onResult(DataApi.DataItemResult dataItemResult) { if (!dataItemResult.getStatus().isSuccess()) { Log.e(LOG_TAG, "ERROR: failed to putDataItem, status code: " + dataItemResult.getStatus().getStatusCode()); } } }); }
private void stopLogger() { File dir = getFilesDir(); File[] subFiles = dir.listFiles(); if (subFiles != null) { for (File file : subFiles) { if (file.getName().contains(recentIgcFileName)) { if (debugMode) Log.d(TAG, "Now checking File " + file.getName()); Asset asset = createAssetFromTextfile(file); PutDataMapRequest dataMap = PutDataMapRequest.create(Statics.DATAIGC + file.getName()); dataMap.getDataMap().putString("igcname", file.getName()); dataMap.getDataMap().putAsset("igcfile", asset); PutDataRequest request = dataMap.asPutDataRequest(); request.setUrgent(); Wearable.DataApi.putDataItem(mGoogleApiClient, request); } } } loggerRunning = false; loggerState.setText(""); }
/** * Adds a {@code bitmap} image to a data item asynchronously. Caller can * specify a {@link ResultCallback} or pass a {@code null}; if a {@code null} is passed, a * default {@link ResultCallback} will be used (see * {@link #putDataItem(PutDataRequest, ResultCallback)} for details). * * @param bitmap The bitmap to be added. * @param path The path for the data item. * @param key The key to be used for this item in the data map. * @param isUrgent If {@code true}, request will be set as urgent. * @param addTimestamp If {@code true}, adds a timestamp to the data map to always create a new * data item even if an identical data item with the same bitmap has * already * been added * @param callback The callback to be notified of the result (can be {@code null}). */ public void putImageData(Bitmap bitmap, String path, String key, boolean isUrgent, boolean addTimestamp, @Nullable ResultCallback<? super DataApi.DataItemResult> callback) { WearUtil.assertNotNull(bitmap, "bitmap"); WearUtil.assertNotEmpty(path, "path"); WearUtil.assertNotEmpty(key, "key"); Asset imageAsset = WearUtil.toAsset(bitmap); PutDataMapRequest dataMap = PutDataMapRequest.create(path); dataMap.getDataMap().putAsset(key, imageAsset); if (addTimestamp) { dataMap.getDataMap().putLong(Constants.KEY_TIMESTAMP, new Date().getTime()); } PutDataRequest request = dataMap.asPutDataRequest(); if (isUrgent) { request.setUrgent(); } putDataItem(request, callback); }
/** * Extracts {@link Bitmap} data from an * {@link com.google.android.gms.wearable.Asset}, in a blocking way, hence should not be called * on the UI thread. This may return {@code null}. */ public Bitmap loadBitmapFromAssetSynchronous(Asset asset) { assertApiConnectivity(); WearUtil.assertNonUiThread(); if (asset == null) { Log.e(TAG, "Asset must be non-null"); } InputStream assetInputStream = Wearable.DataApi.getFdForAsset( mGoogleApiClient, asset).await().getInputStream(); if (assetInputStream == null) { Log.w(TAG, "Requested an unknown Asset."); return null; } return BitmapFactory.decodeStream(assetInputStream); }
/** * 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. */ public 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 } } } }
@NonNull private PutDataRequest buildWeatherRequest(double high, double low, Asset weatherAsset) { PutDataMapRequest weatherDataMapRequest = PutDataMapRequest.create(PATH_DATA_WEATHER + System.currentTimeMillis()); DataMap weatherRequestDataMap = weatherDataMapRequest.getDataMap(); weatherRequestDataMap.putDouble("high", high); weatherRequestDataMap.putDouble("low", low); weatherRequestDataMap.putAsset("icon", weatherAsset); PutDataRequest weatherRequest = weatherDataMapRequest.asPutDataRequest(); weatherRequest.setUrgent(); return weatherRequest; }
/** * Load bit map from asset provided * @param asset */ public void loadBitmapFromAsset(Asset asset) { if (asset == null) { Log.e("WATCH", "Asset received on watch face is null"); return; } // convert asset into a file descriptor and get notified when it's ready Wearable.DataApi.getFdForAsset( mGoogleApiClient, asset).setResultCallback(new ResultCallback<DataApi.GetFdForAssetResult>() { @Override public void onResult(DataApi.GetFdForAssetResult getFdForAssetResult) { InputStream assetInputStream = getFdForAssetResult.getInputStream(); if (assetInputStream == null) { Log.w("WATCH", "Requested an unknown Asset."); return; } mWeatherIconBitmap = BitmapFactory.decodeStream(assetInputStream); } }); }
private void sendData(Asset asset) { if(asset == null){ return; } PutDataMapRequest dataMap = PutDataMapRequest.create(Tools.WEAR_PATH); byte[] arr = asset.getData(); dataMap.getDataMap().putByteArray(Tools.DATA_ASSET_FILE, arr); dataMap.getDataMap().putLong("timestamp", Calendar.getInstance().getTimeInMillis()); PutDataRequest request = dataMap.asPutDataRequest(); PendingResult<DataApi.DataItemResult> pendingResult = Wearable.DataApi.putDataItem(mGoogleAppiClient, request); pendingResult.setResultCallback(new ResultCallback<DataApi.DataItemResult>() { @Override public void onResult(DataApi.DataItemResult dataItemResult) { Log.d(TAG, "onResult result:" + dataItemResult.getStatus()); } }); }
/** * 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); if (asset == null) { return null; } 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()); PutDataRequest request = dataMap.asPutDataRequest(); return request; }
/** * 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; }
/** * Permet d'envoyer une image à la montre */ protected void sendImage(String url, int position) { //télécharge l'image Bitmap bitmap = getBitmapFromURL(url); if (bitmap != null) { Asset asset = createAssetFromBitmap(bitmap); //créé un emplacement mémoire "image/[url_image]" final PutDataMapRequest putDataMapRequest = PutDataMapRequest.create("/image/" + position); //ajoute la date de mise à jour, important pour que les données soient mises à jour putDataMapRequest.getDataMap().putString("timestamp", new Date().toString()); //ajoute l'image à la requête putDataMapRequest.getDataMap().putAsset("image", asset); //envoie la donnée à la montre if (mApiClient.isConnected()) Wearable.DataApi.putDataItem(mApiClient, putDataMapRequest.asPutDataRequest()); } }
public Bitmap loadBitmapFromAsset(Asset asset) { if (asset == null) { throw new IllegalArgumentException("Asset must be non-null"); } ConnectionResult result = mGoogleApiClient.blockingConnect(100, TimeUnit.MILLISECONDS); if (!result.isSuccess()) { return null; } InputStream assetInputStream = Wearable.DataApi.getFdForAsset(mGoogleApiClient, asset).await().getInputStream(); if (assetInputStream == null) { Log.w(TAG, "Requested an unknown Asset."); return null; } return BitmapFactory.decodeStream(assetInputStream); }
private void sendStoredImageToPhone() { BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.ARGB_8888; Bitmap bitmap = BitmapFactory.decodeFile(imagePaths.get(index % imagePaths.size()), options); Bitmap resizedBitmap = Bitmap.createScaledBitmap(bitmap, bitmap.getWidth() / 2, bitmap.getHeight() / 2, true); Asset asset = createAssetFromBitmap(resizedBitmap); PutDataMapRequest dataMap = PutDataMapRequest.create(MyConstants.PATH_GALLERY_IMAGE); dataMap.getDataMap().putAsset(MyConstants.DATA_ITEM_IMAGE, asset); dataMap.getDataMap().putLong(MyConstants.DATA_ITEM_TIMESTAMP, System.currentTimeMillis()); PutDataRequest request = dataMap.asPutDataRequest(); PendingResult<DataApi.DataItemResult> pendingResult = Wearable.DataApi .putDataItem(mGoogleApiClient, request); pendingResult.setResultCallback(new ResultCallback<DataApi.DataItemResult>() { @Override public void onResult(DataApi.DataItemResult dataItemResult) { Log.i(TAG, "onResult of sending data: " + dataItemResult.getStatus()); } }); }
private byte[] loadBytesFromAsset(Asset asset) { if (asset == null) { throw new IllegalArgumentException("Asset must be non-null"); } ConnectionResult result = mGoogleApiClient.blockingConnect(TIMEOUT_MS, TimeUnit.MILLISECONDS); if (!result.isSuccess()) { return null; } InputStream assetInputStream = Wearable.DataApi.getFdForAsset( mGoogleApiClient, asset).await().getInputStream(); mGoogleApiClient.disconnect(); if (assetInputStream == null) { Log.w(TAG, "Requested an unknown Asset."); return null; } try { byte[] targetArray = ByteStreams.toByteArray(assetInputStream); return targetArray; } catch (IOException e) { e.printStackTrace(); return null; } }
/** * Convert an asset into a bitmap object synchronously. Only call this * method from a background thread (it should never be called from the * main/UI thread as it blocks). */ public static Bitmap loadBitmapFromAsset(GoogleApiClient googleApiClient, Asset asset) { if (asset == null) { throw new IllegalArgumentException("Asset must be non-null"); } // convert asset into a file descriptor and block until it's ready InputStream assetInputStream = Wearable.DataApi.getFdForAsset( googleApiClient, asset).await().getInputStream(); if (assetInputStream == null) { Log.w(TAG, "Requested an unknown Asset."); return null; } // decode the stream into a bitmap return BitmapFactory.decodeStream(assetInputStream); }
public Bitmap loadBitmapFromAsset(Asset asset) { if (asset == null) { throw new IllegalArgumentException("Asset must be non-null"); } ConnectionResult result = googleApiClient.blockingConnect(5000, TimeUnit.MILLISECONDS); if (!result.isSuccess()) { return null; } // convert asset into a file descriptor and block until it's ready InputStream assetInputStream = Wearable.DataApi.getFdForAsset( googleApiClient, asset).await().getInputStream(); if (assetInputStream == null) { Timber.e("Requested an unknown Asset."); return null; } // decode the stream into a bitmap return BitmapFactory.decodeStream(assetInputStream); }
public Bitmap loadBitmapFromAsset(Asset asset) { if (asset == null) { throw new IllegalArgumentException("Asset must be non-null"); } final ConnectionResult result = mApiClient.blockingConnect(3000, TimeUnit.MILLISECONDS); if (!result.isSuccess()) { return null; } // convert asset into a file descriptor and block until it's ready final InputStream assetInputStream = Wearable.DataApi.getFdForAsset( mApiClient, asset).await().getInputStream(); //mApiClient.disconnect(); if (assetInputStream == null) { Log.w(TAG, "Requested an unknown Asset."); return null; } // decode the stream into a bitmap return BitmapFactory.decodeStream(assetInputStream); }
public static Asset assetFromFile(String path) { try { return Asset.createFromBytes(readFile(path)); } catch (IOException e) { return null; } }
public static Asset assetFromFile(File file) { try { return Asset.createFromBytes(readFile(file)); } catch (IOException e) { return null; } }
@Override public void onConnected(@Nullable Bundle bundle) { if (debugMode) Log.d(TAG, "on connected"); Wearable.DataApi.addListener(mGoogleApiClient, this); PendingResult<DataItemBuffer> results = Wearable.DataApi.getDataItems(mGoogleApiClient); results.setResultCallback(new ResultCallback<DataItemBuffer>() { @Override public void onResult(@NonNull DataItemBuffer dataItems) { if (dataItems.getCount() != 0) { for (DataItem item : dataItems) { if (item.getUri().getPath().contains(Statics.DATAPREFERENCES)) { updatePreferencesFromDataItem(item); } else if (item.getUri().getPath().contains(Statics.DATADELETE)) { deleteSingleIgcFile(item); } } } dataItems.release(); } }); File dir = getFilesDir(); File[] subFiles = dir.listFiles(); if (subFiles != null) { for (File file : subFiles) { if (!file.getName().contains(".igc")) continue; Asset asset = createAssetFromTextfile(file); PutDataMapRequest dataMap = PutDataMapRequest.create(Statics.DATAIGC + file.getName()); dataMap.getDataMap().putString("igcname", file.getName()); dataMap.getDataMap().putAsset("igcfile", asset); PutDataRequest request = dataMap.asPutDataRequest(); request.setUrgent(); Wearable.DataApi.putDataItem(mGoogleApiClient, request); } } requestLocationUpdates(); //throw new RuntimeException("This is a wear croshhhhh"); }
private Asset createAssetFromTextfile(File filename) { FileInputStream fis = null; ByteArrayOutputStream byteStream = null; try { fis = new FileInputStream(filename); byte[] buffer = new byte[4096]; byteStream = new ByteArrayOutputStream(); int read; while ((read = fis.read(buffer)) != -1) { byteStream.write(buffer, 0, read); } } catch (IOException e) { reportException(e); } finally { try { if (byteStream != null) byteStream.close(); } catch (IOException e) { reportException(e); } try { if (fis != null) fis.close(); } catch (IOException e) { reportException(e); } } assert byteStream != null; return Asset.createFromBytes(byteStream.toByteArray()); }
public void syncAsset(String path, String key, byte[] bytes, boolean isUrgent) { WearUtil.assertNotEmpty(path, "path"); WearUtil.assertNotEmpty(key, "key"); PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(path); Asset asset = Asset.createFromBytes(bytes); putDataMapRequest.getDataMap().putAsset(key, asset); syncData(putDataMapRequest, isUrgent); }
private void fetchWeatherIconAsynchronously(DataMap weatherDataMap) { Asset iconAsset = weatherDataMap.getAsset(WeatherRequestKeys.ICON); if (googleApiClient.isConnected()) { PendingResult<DataApi.GetFdForAssetResult> fileDescriptorForIconAsset = Wearable.DataApi.getFdForAsset(googleApiClient, iconAsset); obtainWeatherIconUsingFileDescriptor(fileDescriptorForIconAsset); } }
private void updateWearables(Context context) { Cursor cursor = getWeatherCursor(context); if (cursor.moveToFirst()) { double high = cursor.getDouble(INDEX_MAX_TEMP); double low = cursor.getDouble(INDEX_MIN_TEMP); int weatherId = cursor.getInt(INDEX_WEATHER_ID); Asset weatherAsset = getWeatherAsset(weatherId); Wearable.DataApi.putDataItem(googleApiClient, buildWeatherRequest(high, low, weatherAsset)); } }
private Asset getWeatherAsset(int weatherId) { int iconId = Utility.getIconResourceForWeatherCondition(weatherId); Bitmap weatherIcon = BitmapFactory.decodeResource(getContext().getResources(), iconId); ByteArrayOutputStream weatherIconByteStream = new ByteArrayOutputStream(); weatherIcon.compress(Bitmap.CompressFormat.PNG, 100, weatherIconByteStream); return Asset.createFromBytes(weatherIconByteStream.toByteArray()); }
/** * Get weather info from the dataMap object provided * @param dataMap */ void extractWeatherData (DataMap dataMap) { mHighTemp = dataMap.getString(HIGH_TEMP); mLowTemp = dataMap.getString(LOW_TEMP); Log.i("WATCH","High temp: "+mHighTemp); Log.i("WATCH", "Low temp: " + mLowTemp); Asset weatherIconAsset = dataMap.getAsset(WEATHER_ICON); loadBitmapFromAsset(weatherIconAsset); }