Search in sources :

Example 11 with VectorDrawable

use of android.graphics.drawable.VectorDrawable in project android_frameworks_base by AOSPA.

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;
    }
}
Also used : AnimationDrawable(android.graphics.drawable.AnimationDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) VectorDrawable(android.graphics.drawable.VectorDrawable)

Example 12 with VectorDrawable

use of android.graphics.drawable.VectorDrawable in project Stringlate by LonamiWebs.

the class ContextUtils method bitmapToDrawable.

public Bitmap bitmapToDrawable(@DrawableRes int drawableId) {
    Bitmap bitmap = null;
    Drawable drawable = ContextCompat.getDrawable(_context, drawableId);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && (drawable instanceof VectorDrawable || drawable instanceof VectorDrawableCompat)) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            drawable = (DrawableCompat.wrap(drawable)).mutate();
        }
        bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);
    } else if (drawable instanceof BitmapDrawable) {
        bitmap = ((BitmapDrawable) drawable).getBitmap();
    }
    return bitmap;
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) VectorDrawable(android.graphics.drawable.VectorDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) VectorDrawableCompat(android.support.graphics.drawable.VectorDrawableCompat) VectorDrawable(android.graphics.drawable.VectorDrawable)

Example 13 with VectorDrawable

use of android.graphics.drawable.VectorDrawable in project memetastic by gsantner.

the class ContextUtils method drawableToBitmap.

public Bitmap drawableToBitmap(Drawable drawable) {
    Bitmap bitmap = null;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && (drawable instanceof VectorDrawable || drawable instanceof VectorDrawableCompat)) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            drawable = (DrawableCompat.wrap(drawable)).mutate();
        }
        bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);
    } else if (drawable instanceof BitmapDrawable) {
        bitmap = ((BitmapDrawable) drawable).getBitmap();
    }
    return bitmap;
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) BitmapDrawable(android.graphics.drawable.BitmapDrawable) VectorDrawableCompat(android.support.graphics.drawable.VectorDrawableCompat) VectorDrawable(android.graphics.drawable.VectorDrawable)

Example 14 with VectorDrawable

use of android.graphics.drawable.VectorDrawable in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class Utils method setSafeIcon.

/**
 * Sets the preference icon with a drawable that is scaled down to to avoid crashing Settings if
 * it's too big.
 */
public static void setSafeIcon(Preference pref, Drawable icon) {
    Drawable safeIcon = icon;
    if ((icon != null) && !(icon instanceof VectorDrawable)) {
        safeIcon = getSafeDrawable(icon, 500, 500);
    }
    pref.setIcon(safeIcon);
}
Also used : Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) VectorDrawable(android.graphics.drawable.VectorDrawable) VectorDrawable(android.graphics.drawable.VectorDrawable)

Example 15 with VectorDrawable

use of android.graphics.drawable.VectorDrawable in project platform_frameworks_base by android.

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;
    }
}
Also used : AnimationDrawable(android.graphics.drawable.AnimationDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) VectorDrawable(android.graphics.drawable.VectorDrawable)

Aggregations

VectorDrawable (android.graphics.drawable.VectorDrawable)33 BitmapDrawable (android.graphics.drawable.BitmapDrawable)19 Bitmap (android.graphics.Bitmap)13 Canvas (android.graphics.Canvas)13 Paint (android.graphics.Paint)9 Button (android.widget.Button)8 GridLayout (android.widget.GridLayout)8 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)6 AnimationDrawable (android.graphics.drawable.AnimationDrawable)5 Resources (android.content.res.Resources)4 Rect (android.graphics.Rect)4 VectorDrawableCompat (android.support.graphics.drawable.VectorDrawableCompat)4 AttributeSet (android.util.AttributeSet)4 View (android.view.View)4 ViewGroup (android.view.ViewGroup)4 CheckBox (android.widget.CheckBox)4 CompoundButton (android.widget.CompoundButton)4 OnCheckedChangeListener (android.widget.CompoundButton.OnCheckedChangeListener)4 ScrollView (android.widget.ScrollView)4 TextView (android.widget.TextView)4