本文整理匯總了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
}
}
}
}
示例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
}
}
}
}
示例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
}
}
}
}
示例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;
}
示例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
}
}
}
}
示例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;
}
}
示例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);
}
示例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());
}
示例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());
}
示例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;
}
示例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;
}
示例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);
}
示例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());
}
示例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());
}
示例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());
}