/**
* 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);
}
获取图片资源方式且转为PixelMap
/**
* 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();
}
获取图片资源方式且转为PixelMapElement
/**
* 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);
}
通过Color设置组件背景色
public static Element buildDrawableByColor(int color) {
ShapeElement drawable = new ShapeElement();
drawable.setShape(ShapeElement.RECTANGLE);
drawable.setRgbColor(RgbColor.fromArgbInt(color));
return drawable;
}
通过Color设置组件带圆角的背景色
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;
}
获取Color
public static Color getNewColor(Context context, int id) {
Log.info(TAG, "Entering getNewColor");
Color result = new Color(getColor(context, id));
return result;
}
获取Vector矢量图片资源方式 /** * 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) {