Search in sources :

Example 21 with VectorDrawable

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;
    }
    if (!(d instanceof BitmapDrawable)) {
        Log.e(TAG, "Tinting not implemented for type " + d.getClass().getSimpleName());
        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);
}
Also used : Bitmap(android.graphics.Bitmap) Rect(android.graphics.Rect) Canvas(android.graphics.Canvas) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Paint(android.graphics.Paint) VectorDrawable(android.graphics.drawable.VectorDrawable)

Example 22 with VectorDrawable

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

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

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

the class RecentController method setGravityAndImageResources.

/**
     * Calculate main gravity based on layout direction and user gravity value.
     * Set and update all resources and notify the different layouts about the change.
     */
private void setGravityAndImageResources() {
    // Calculate and set gravitiy.
    if (mLayoutDirection == View.LAYOUT_DIRECTION_RTL) {
        mMainGravity = reverseGravity(mUserGravity);
    } else {
        mMainGravity = mUserGravity;
    }
    // Set layout direction.
    mRecentContainer.setLayoutDirection(mLayoutDirection);
    // Reset all backgrounds.
    mRecentContent.setBackgroundResource(0);
    mRecentWarningContent.setBackgroundResource(0);
    mEmptyRecentView.setImageResource(0);
    // Set correct backgrounds based on calculated main gravity.
    int warningColor = mContext.getResources().getColor(R.color.recent_warning_background);
    mRecentWarningContent.setBackgroundColor(warningColor);
    int tintColor = getEmptyRecentColor();
    int backgroundColor = mPanelColor;
    if (backgroundColor == 0x00ffffff) {
        backgroundColor = mContext.getResources().getColor(R.color.recent_background);
    }
    VectorDrawable vd = (VectorDrawable) mContext.getResources().getDrawable(R.drawable.ic_empty_recent);
    vd.setTint(getEmptyRecentColor());
    mEmptyRecentView.setImageDrawable(vd);
    VectorDrawable vd1 = (VectorDrawable) mContext.getResources().getDrawable(R.drawable.ic_recent_keyguard);
    vd1.setTint(tintColor);
    mKeyguardImage.setImageDrawable(vd1);
    mKeyguardText.setTextColor(tintColor);
    int padding = mContext.getResources().getDimensionPixelSize(R.dimen.slim_recents_elevation);
    if (mMainGravity == Gravity.LEFT) {
        mRecentContainer.setPadding(0, 0, padding, 0);
        mEmptyRecentView.setRotation(180);
    } else {
        mRecentContainer.setPadding(padding, 0, 0, 0);
        mEmptyRecentView.setRotation(0);
    }
    // Notify panel view about new main gravity.
    if (mRecentPanelView != null) {
        mRecentPanelView.setMainGravity(mMainGravity);
    }
    // Set custom background color (or reset to default, as the case may be
    if (mRecentContent != null) {
        mRecentContent.setElevation(50);
        mRecentContent.setBackgroundColor(backgroundColor);
    }
    if (mKeyguardView != null) {
        mKeyguardView.setBackgroundColor(backgroundColor);
    }
}
Also used : Point(android.graphics.Point) VectorDrawable(android.graphics.drawable.VectorDrawable)

Example 24 with VectorDrawable

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

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);
    }
}
Also used : Bitmap(android.graphics.Bitmap) ColorMatrix(android.graphics.ColorMatrix) Matrix(android.graphics.Matrix) Canvas(android.graphics.Canvas) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Paint(android.graphics.Paint) VectorDrawable(android.graphics.drawable.VectorDrawable) Paint(android.graphics.Paint)

Example 25 with VectorDrawable

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

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);
}
Also used : Bitmap(android.graphics.Bitmap) Rect(android.graphics.Rect) Canvas(android.graphics.Canvas) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Paint(android.graphics.Paint) 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