use of android.graphics.drawable.VectorDrawable in project android_frameworks_base by DirtyUnicorns.
the class VectorDrawablePerformance method create.
public static VectorDrawable create(Resources resources, int rid) {
try {
final XmlPullParser parser = resources.getXml(rid);
final AttributeSet attrs = Xml.asAttributeSet(parser);
int type;
while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
// Empty loop
}
if (type != XmlPullParser.START_TAG) {
throw new XmlPullParserException("No start tag found");
}
final VectorDrawable drawable = new VectorDrawable();
drawable.inflate(resources, parser, attrs);
return drawable;
} catch (XmlPullParserException e) {
Log.e(LOGCAT, "parser error", e);
} catch (IOException e) {
Log.e(LOGCAT, "parser error", e);
}
return null;
}
use of android.graphics.drawable.VectorDrawable in project android_frameworks_base by DirtyUnicorns.
the class NotificationColorUtil method isGrayscaleIcon.
/**
* Checks whether a Drawable is a small grayscale icon.
* Grayscale here means "very close to a perfect gray"; icon means "no larger than 64dp".
*
* @param d The drawable to test.
* @return True if the bitmap is grayscale; false if it is color or too large to examine.
*/
public boolean isGrayscaleIcon(Drawable d) {
if (d == null) {
return false;
} else if (d instanceof BitmapDrawable) {
BitmapDrawable bd = (BitmapDrawable) d;
return bd.getBitmap() != null && isGrayscaleIcon(bd.getBitmap());
} else if (d instanceof AnimationDrawable) {
AnimationDrawable ad = (AnimationDrawable) d;
int count = ad.getNumberOfFrames();
return count > 0 && isGrayscaleIcon(ad.getFrame(0));
} else if (d instanceof VectorDrawable) {
// We just assume you're doing the right thing if using vectors
return true;
} else {
return false;
}
}
use of android.graphics.drawable.VectorDrawable in project android_frameworks_base by ResurrectionRemix.
the class ImageHelper method resize.
public static Drawable resize(Context context, Drawable image, int size) {
if (image == null || context == null) {
return null;
}
if (image instanceof VectorDrawable) {
return image;
} else {
int newSize = Converter.dpToPx(context, size);
Bitmap bitmap = ((BitmapDrawable) image).getBitmap();
Bitmap scaledBitmap = Bitmap.createBitmap(newSize, newSize, Config.ARGB_8888);
float ratioX = newSize / (float) bitmap.getWidth();
float ratioY = newSize / (float) bitmap.getHeight();
float middleX = newSize / 2.0f;
float middleY = newSize / 2.0f;
final Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG);
paint.setAntiAlias(true);
Matrix scaleMatrix = new Matrix();
scaleMatrix.setScale(ratioX, ratioY, middleX, middleY);
Canvas canvas = new Canvas(scaledBitmap);
canvas.setMatrix(scaleMatrix);
canvas.drawBitmap(bitmap, middleX - bitmap.getWidth() / 2, middleY - bitmap.getHeight() / 2, paint);
return new BitmapDrawable(context.getResources(), scaledBitmap);
}
}
use of android.graphics.drawable.VectorDrawable in project android_frameworks_base by ResurrectionRemix.
the class ImageHelper method getColoredDrawable.
public static Drawable getColoredDrawable(Drawable d, int color) {
if (d == null) {
return null;
}
if (d instanceof VectorDrawable) {
d.setTint(color);
return d;
}
Bitmap colorBitmap = ((BitmapDrawable) d).getBitmap();
Bitmap grayscaleBitmap = toGrayscale(colorBitmap);
Paint pp = new Paint();
pp.setAntiAlias(true);
PorterDuffColorFilter frontFilter = new PorterDuffColorFilter(color, Mode.MULTIPLY);
pp.setColorFilter(frontFilter);
Canvas cc = new Canvas(grayscaleBitmap);
final Rect rect = new Rect(0, 0, grayscaleBitmap.getWidth(), grayscaleBitmap.getHeight());
cc.drawBitmap(grayscaleBitmap, rect, rect, pp);
return new BitmapDrawable(grayscaleBitmap);
}
use of android.graphics.drawable.VectorDrawable in project android_frameworks_base by ResurrectionRemix.
the class ColorHelper method getColoredDrawable.
public static Drawable getColoredDrawable(Drawable d, int color) {
if (d instanceof VectorDrawable) {
d.setTint(color);
return d;
}
Bitmap colorBitmap = ((BitmapDrawable) d).getBitmap();
Bitmap grayscaleBitmap = toGrayscale(colorBitmap);
Paint pp = new Paint();
PorterDuffColorFilter frontFilter = new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY);
pp.setColorFilter(frontFilter);
Canvas cc = new Canvas(grayscaleBitmap);
cc.drawBitmap(grayscaleBitmap, 0, 0, pp);
return new BitmapDrawable(grayscaleBitmap);
}
Aggregations