當前位置: 首頁>>代碼示例>>Java>>正文


Java Asset類代碼示例

本文整理匯總了Java中com.google.android.gms.wearable.Asset的典型用法代碼示例。如果您正苦於以下問題:Java Asset類的具體用法?Java Asset怎麽用?Java Asset使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Asset類屬於com.google.android.gms.wearable包,在下文中一共展示了Asset類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: loadAssetSynchronous

import com.google.android.gms.wearable.Asset; //導入依賴的package包/類
/**
 * 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();
}
 
開發者ID:csarron,項目名稱:GmsWear,代碼行數:31,代碼來源:GmsWear.java

示例2: getUpdateRequest

import com.google.android.gms.wearable.Asset; //導入依賴的package包/類
/**
 * 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();
}
 
開發者ID:jpd236,項目名稱:fantasywear,代碼行數:31,代碼來源:LeagueData.java

示例3: alarmCommand

import com.google.android.gms.wearable.Asset; //導入依賴的package包/類
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();
}
 
開發者ID:matejdro,項目名稱:WearVibrationCenter,代碼行數:20,代碼來源:WatchCommander.java

示例4: loadBitmapFromAsset

import com.google.android.gms.wearable.Asset; //導入依賴的package包/類
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]);
            }
 
開發者ID:Hitesh880443,項目名稱:SunshineWithWear,代碼行數:25,代碼來源:MyDigitalWatchFace.java

示例5: toAsset

import com.google.android.gms.wearable.Asset; //導入依賴的package包/類
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
            }
        }
    }
}
 
開發者ID:Hitesh880443,項目名稱:SunshineWithWear,代碼行數:17,代碼來源:SunshineSyncAdapter.java

示例6: onDataChanged

import com.google.android.gms.wearable.Asset; //導入依賴的package包/類
@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);
        }
    }
}
 
開發者ID:hieple7985,項目名稱:nano-go-ubiquitous,代碼行數:19,代碼來源:SunshineWearListenerService.java

示例7: doLoadBitmap

import com.google.android.gms.wearable.Asset; //導入依賴的package包/類
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();
}
 
開發者ID:hieple7985,項目名稱:nano-go-ubiquitous,代碼行數:18,代碼來源:SunshineWearListenerService.java

示例8: sendData

import com.google.android.gms.wearable.Asset; //導入依賴的package包/類
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());
        }
    });
}
 
開發者ID:LadyViktoria,項目名稱:wearDrip,代碼行數:18,代碼來源:FileSender.java

示例9: sendDataItemWithoutConnectionCheck

import com.google.android.gms.wearable.Asset; //導入依賴的package包/類
/**
 * 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);
}
 
開發者ID:asamm,項目名稱:locus-addon-wearables,代碼行數:23,代碼來源:LocusWearCommService.java

示例10: doInBackground

import com.google.android.gms.wearable.Asset; //導入依賴的package包/類
@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;
    }
}
 
開發者ID:jainkamini,項目名稱:Sunshinewear,代碼行數:22,代碼來源:WatchFace.java

示例11: toAsset

import com.google.android.gms.wearable.Asset; //導入依賴的package包/類
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
            }
        }
    }
}
 
開發者ID:jainkamini,項目名稱:Sunshinewear,代碼行數:18,代碼來源:Utility.java

示例12: sendTodayForecast

import com.google.android.gms.wearable.Asset; //導入依賴的package包/類
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());
                        }
                    }
                });
    }
 
開發者ID:jainkamini,項目名稱:Sunshinewear,代碼行數:26,代碼來源:SunshineSyncAdapter.java

示例13: stopLogger

import com.google.android.gms.wearable.Asset; //導入依賴的package包/類
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("");
}
 
開發者ID:pulce,項目名稱:Wristglider,代碼行數:21,代碼來源:MainWearActivity.java

示例14: putImageData

import com.google.android.gms.wearable.Asset; //導入依賴的package包/類
/**
 * 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);
}
 
開發者ID:csarron,項目名稱:GmsWear,代碼行數:35,代碼來源:GmsWear.java

示例15: loadBitmapFromAssetSynchronous

import com.google.android.gms.wearable.Asset; //導入依賴的package包/類
/**
 * 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);
}
 
開發者ID:csarron,項目名稱:GmsWear,代碼行數:22,代碼來源:GmsWear.java


注:本文中的com.google.android.gms.wearable.Asset類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。