赞
踩
/**
* get the vector drawable
*
* @param context the context
* @param id the drawable id
* @return the vector drawable
*/
public static VectorElement getVectorDrawable(Context context, int id) {
Log.info(TAG, "Entering getVectorDrawable");
if (context == null) {
Log.info(TAG, "getVectorDrawable -> get null context");
return null;
}
return new VectorElement(context, id);
}
/** * get the pixel map * * @param context the context * @param id the id * @return the pixel map */ public static Optional<PixelMap> getPixelMap(Context context, int id) { Log.info(TAG, "Entering getPixelMap"); String path = getPathById(context, id); if (TextTool.isNullOrEmpty(path)) { return Optional.empty(); } RawFileEntry assetManager = context.getResourceManager().getRawFileEntry(path); ImageSource.SourceOptions options = new ImageSource.SourceOptions(); options.formatHint = "image/png"; ImageSource.DecodingOptions decodingOptions = new ImageSource.DecodingOptions(); try { Resource asset = assetManager.openRawFile(); ImageSource source = ImageSource.create(asset, options); return Optional.ofNullable(source.createPixelmap(decodingOptions)); } catch (IOException e) { Log.error("IOException", e.getMessage()); } return Optional.empty(); }
/**
* get the Pixel Map Element
*
* @param context the context
* @param resId the res id
* @return the Pixel Map Element
*/
public static PixelMapElement getPixelMapDrawable(Context context, int resId) {
Optional<PixelMap> optional = getPixelMap(context, resId);
return optional.map(PixelMapElement::new).orElse(null);
}
public static Element buildDrawableByColor(int color) {
ShapeElement drawable = new ShapeElement();
drawable.setShape(ShapeElement.RECTANGLE);
drawable.setRgbColor(RgbColor.fromArgbInt(color));
return drawable;
}
public static Element buildDrawableByColorRadius(int color, float radius) {
ShapeElement drawable = new ShapeElement();
drawable.setShape(ShapeElement.RECTANGLE);
drawable.setRgbColor(RgbColor.fromArgbInt(color));
drawable.setCornerRadius(radius);
return drawable;
}
public static Color getNewColor(Context context, int id) {
Log.info(TAG, "Entering getNewColor");
Color result = new Color(getColor(context, id));
return result;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。