Search in sources :

Example 31 with VectorDrawable

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

the class UtilsTest method createIconWithDrawable_VectorDrawable.

@Test
public void createIconWithDrawable_VectorDrawable() {
    final VectorDrawable drawable = VectorDrawable.create(mContext.getResources(), R.drawable.ic_settings_accent);
    final IconCompat icon = Utils.createIconWithDrawable(drawable);
    assertThat(icon.getBitmap()).isNotNull();
}
Also used : IconCompat(androidx.core.graphics.drawable.IconCompat) VectorDrawable(android.graphics.drawable.VectorDrawable) Test(org.junit.Test)

Example 32 with VectorDrawable

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

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 33 with VectorDrawable

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

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)

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