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


Java Asset.createFromBytes方法代碼示例

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


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

示例1: 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

示例2: 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

示例3: toAsset

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

示例4: createPutDataRequest

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

示例5: createAssetFromBitmap

import com.google.android.gms.wearable.Asset; //導入方法依賴的package包/類
private static Asset createAssetFromBitmap(Bitmap bitmap) {
    ByteArrayOutputStream byteStream = null;
    try {
        byteStream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.WEBP, 30, byteStream);
        return Asset.createFromBytes(byteStream.toByteArray());
    } finally {
        if (byteStream != null) {
            try {
                byteStream.close();
            } catch (IOException e) {
                // ignore
            }
        }
    }
}
 
開發者ID:grubFX,項目名稱:WearCam,代碼行數:17,代碼來源:MainActivity.java

示例6: assetFromFile

import com.google.android.gms.wearable.Asset; //導入方法依賴的package包/類
public static Asset assetFromFile(String path) {
    try {
        return Asset.createFromBytes(readFile(path));
    } catch (IOException e) {
        return null;
    }
}
 
開發者ID:LadyViktoria,項目名稱:wearDrip,代碼行數:8,代碼來源:Tools.java

示例7: syncAsset

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

示例8: getWeatherAsset

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

示例9: getLogoAssetForBitmap

import com.google.android.gms.wearable.Asset; //導入方法依賴的package包/類
@VisibleForTesting
public static Asset getLogoAssetForBitmap(Bitmap bitmap, int size) {
    // If the bitmap is less than the desired size, scale it up.
    if (bitmap.getWidth() < size) {
        bitmap = Bitmap.createScaledBitmap(bitmap, size, size, true);
    }
    ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteStream);
    return Asset.createFromBytes(byteStream.toByteArray());
}
 
開發者ID:jpd236,項目名稱:fantasywear,代碼行數:11,代碼來源:SyncAdapter.java

示例10: createNewMomentDataMap

import com.google.android.gms.wearable.Asset; //導入方法依賴的package包/類
public static PutDataMapRequest createNewMomentDataMap(MomentResponse moment, Bitmap drawing) {
    final ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
    drawing.compress(Bitmap.CompressFormat.PNG, 0 /*Ignored*/, byteStream);
    Asset asset = Asset.createFromBytes(byteStream.toByteArray());

    PutDataMapRequest dataMap = PutDataMapRequest.create(Constants.PATH_MOMENT_NOTIFICATION);
    dataMap.getDataMap().putLong(Constants.KEY_MOMENT_ID, moment.getMomentId());
    dataMap.getDataMap().putLong(Constants.KEY_SENDER_ID, moment.getSenderId());
    dataMap.getDataMap().putString(Constants.KEY_SENDER_NAME, moment.getSenderName());
    dataMap.getDataMap().putAsset(Constants.KEY_DRAWING, asset);
    dataMap.getDataMap().putLong(Constants.KEY_FORCE_UPDATE, System.currentTimeMillis());
    return dataMap;
}
 
開發者ID:AndrewJack,項目名稱:moment-for-android-wear,代碼行數:14,代碼來源:DataMapCreatorUtil.java

示例11: createAssetFromBitmap

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

示例12: notifyWearable

import com.google.android.gms.wearable.Asset; //導入方法依賴的package包/類
private void notifyWearable() {
    final Context context = getContext();
    final String preferredLocation = Utility.getPreferredLocation(getContext());

    final Uri uri = WeatherContract.WeatherEntry.buildWeatherLocationWithDate(preferredLocation, System.currentTimeMillis());
    Cursor query = context.getContentResolver().query(uri, WEARABLE_WEATHER_PROJECTION, null, null, null);

    if (null == query) {
        return;
    }

    if(!query.moveToFirst()){
        query.close();
        return;
    }

    PutDataMapRequest sendRequest = PutDataMapRequest.create("/SunshineWearListenerService/Data");

    double highTemp = query.getDouble(INDEX_MAX_TEMP);
    double lowTemp = query.getDouble(INDEX_MIN_TEMP);

    int highTempInt = Utility.isMetric(context) ? (int)highTemp : (int)((highTemp * 1.8) + 32);
    int lowTempInt = Utility.isMetric(context) ? (int)lowTemp : (int)((lowTemp * 1.8) + 32);

    sendRequest.getDataMap().putInt("dataHigh", highTempInt);
    sendRequest.getDataMap().putInt("dataLow", lowTempInt);
    sendRequest.getDataMap().putLong("dataTime", System.currentTimeMillis());

    final ByteArrayOutputStream imageBytes = new ByteArrayOutputStream();
    String artUrl = Utility.getArtUrlForWeatherCondition(context, query.getInt(INDEX_WEATHER_ID));

    int artResourceId = Utility.getArtResourceForWeatherCondition(query.getInt(INDEX_WEATHER_ID));
    int size = context.getResources().getDimensionPixelSize(R.dimen.wearable_large_icon_default);

    try {
        Bitmap weatherIcon = Glide.with(context)
                .load(artUrl)
                .asBitmap()
                .error(artResourceId)
                .fitCenter()
                .into(size, size)
                .get();

        weatherIcon.compress(Bitmap.CompressFormat.PNG, 100, imageBytes);
        Asset weatherIconAsset = Asset.createFromBytes(imageBytes.toByteArray());
        sendRequest.getDataMap().putAsset("dataIcon", weatherIconAsset);
    } catch(Exception ex){
        Log.e(LOG_TAG, ex.toString());
    }

    PutDataRequest putDataRequest = sendRequest.asPutDataRequest();

    GoogleApiClient googleApiClient = getGoogleApiClient();
    googleApiClient.connect();

    Wearable.DataApi.putDataItem(googleApiClient, putDataRequest);
}
 
開發者ID:hieple7985,項目名稱:nano-go-ubiquitous,代碼行數:58,代碼來源:SunshineSyncAdapter.java

示例13: createAssetFromBitmap

import com.google.android.gms.wearable.Asset; //導入方法依賴的package包/類
private static Asset createAssetFromBitmap(Bitmap bitmap) {
    final ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteStream);
    return Asset.createFromBytes(byteStream.toByteArray());
}
 
開發者ID:frank-tan,項目名稱:Sunshine-Android-Wear,代碼行數:6,代碼來源:SunshineSyncAdapter.java

示例14: createAssetFromBitmap

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

示例15: createAssetFromBitmap

import com.google.android.gms.wearable.Asset; //導入方法依賴的package包/類
public static Asset createAssetFromBitmap(Bitmap bitmap) {
    final ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteStream);
    return Asset.createFromBytes(byteStream.toByteArray());
}
 
開發者ID:wlky,項目名稱:AnkiDroid-Wear,代碼行數:6,代碼來源:CardMedia.java


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