Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 55cb70bf authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Adding an overridable DrawableFactory to allow creating custom icon drawables

> Adding ItemInfo as a parameter for creating drawable

Change-Id: I793acb0381d2b8df4db0a08317dddf1464788ebc
parent 4633be64
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -79,6 +79,9 @@
    <!-- Name of an icon provider class. -->
    <string name="icon_provider_class" translatable="false"></string>

    <!-- Name of a drawable factory class. -->
    <string name="drawable_factory_class" translatable="false"></string>

    <!-- Package name of the default wallpaper picker. -->
    <string name="wallpaper_picker_package" translatable="false"></string>

+3 −17
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.launcher3;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
@@ -26,9 +25,7 @@ import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Region;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.AttributeSet;
import android.util.SparseArray;
import android.util.TypedValue;
@@ -42,6 +39,7 @@ import android.widget.TextView;

import com.android.launcher3.IconCache.IconLoadRequest;
import com.android.launcher3.folder.FolderIcon;
import com.android.launcher3.graphics.DrawableFactory;
import com.android.launcher3.graphics.HolographicOutlineHelper;
import com.android.launcher3.model.PackageItemInfo;

@@ -190,7 +188,7 @@ public class BubbleTextView extends TextView
    }

    private void applyIconAndLabel(Bitmap icon, ItemInfo info) {
        FastBitmapDrawable iconDrawable = mLauncher.createIconDrawable(icon);
        FastBitmapDrawable iconDrawable = DrawableFactory.get(getContext()).newIcon(icon, info);
        iconDrawable.setIsDisabled(info.isDisabled());
        setIcon(iconDrawable);
        setText(info.title);
@@ -201,15 +199,6 @@ public class BubbleTextView extends TextView
        }
    }

    /**
     * Used for measurement only, sets some dummy values on this view.
     */
    public void applyDummyInfo() {
        ColorDrawable d = new ColorDrawable();
        setIcon(mLauncher.resizeIconDrawable(d));
        setText("");
    }

    /**
     * Overrides the default long press timeout.
     */
@@ -528,12 +517,9 @@ public class BubbleTextView extends TextView
    /**
     * Sets the icon for this view based on the layout direction.
     */
    @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
    private void setIcon(Drawable icon) {
        mIcon = icon;
        if (mIconSize != -1) {
        mIcon.setBounds(0, 0, mIconSize, mIconSize);
        }
        applyCompoundDrawables(mIcon);
    }

+15 −4
Original line number Diff line number Diff line
@@ -94,7 +94,7 @@ public class FastBitmapDrawable extends Drawable {
    private static final ColorMatrix sTempBrightnessMatrix = new ColorMatrix();
    private static final ColorMatrix sTempFilterMatrix = new ColorMatrix();

    private final Paint mPaint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG);
    protected final Paint mPaint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG);
    private final Bitmap mBitmap;
    private State mState = State.NORMAL;
    private boolean mIsDisabled;
@@ -116,6 +116,17 @@ public class FastBitmapDrawable extends Drawable {

    @Override
    public void draw(Canvas canvas) {
        drawInternal(canvas);
    }

    public void drawWithBrightness(Canvas canvas, float brightness) {
        float oldBrightness = getBrightness();
        setBrightness(brightness);
        drawInternal(canvas);
        setBrightness(oldBrightness);
    }

    protected void drawInternal(Canvas canvas) {
        canvas.drawBitmap(mBitmap, null, getBounds(), mPaint);
    }

@@ -278,7 +289,7 @@ public class FastBitmapDrawable extends Drawable {
    /**
     * Sets the saturation of this icon, 0 [full color] -> 1 [desaturated]
     */
    public void setDesaturation(float desaturation) {
    private void setDesaturation(float desaturation) {
        int newDesaturation = (int) Math.floor(desaturation * REDUCED_FILTER_VALUE_SPACE);
        if (mDesaturation != newDesaturation) {
            mDesaturation = newDesaturation;
@@ -293,7 +304,7 @@ public class FastBitmapDrawable extends Drawable {
    /**
     * Sets the brightness of this icon, 0 [no add. brightness] -> 1 [2bright2furious]
     */
    public void setBrightness(float brightness) {
    private void setBrightness(float brightness) {
        int newBrightness = (int) Math.floor(brightness * REDUCED_FILTER_VALUE_SPACE);
        if (mBrightness != newBrightness) {
            mBrightness = newBrightness;
@@ -301,7 +312,7 @@ public class FastBitmapDrawable extends Drawable {
        }
    }

    public float getBrightness() {
    private float getBrightness() {
        return (float) mBrightness / REDUCED_FILTER_VALUE_SPACE;
    }

+3 −2
Original line number Diff line number Diff line
@@ -129,14 +129,15 @@ public class Hotseat extends FrameLayout
        if (!FeatureFlags.NO_ALL_APPS_ICON) {
            // Add the Apps button
            Context context = getContext();
            int allAppsButtonRank = mLauncher.getDeviceProfile().inv.getAllAppsButtonRank();
            DeviceProfile grid = mLauncher.getDeviceProfile();
            int allAppsButtonRank = grid.inv.getAllAppsButtonRank();

            LayoutInflater inflater = LayoutInflater.from(context);
            TextView allAppsButton = (TextView)
                    inflater.inflate(R.layout.all_apps_button, mContent, false);
            Drawable d = context.getResources().getDrawable(R.drawable.all_apps_button_icon);
            d.setBounds(0, 0, grid.iconSizePx, grid.iconSizePx);

            mLauncher.resizeIconDrawable(d);
            int scaleDownPx = getResources().getDimensionPixelSize(R.dimen.all_apps_button_scale_down);
            Rect bounds = d.getBounds();
            d.setBounds(bounds.left, bounds.top + scaleDownPx / 2, bounds.right - scaleDownPx,
+0 −18
Original line number Diff line number Diff line
@@ -4034,24 +4034,6 @@ public class Launcher extends Activity
        mWorkspace.moveToDefaultScreen(false);
    }

    /**
     * Returns a FastBitmapDrawable with the icon, accurately sized.
     */
    public FastBitmapDrawable createIconDrawable(Bitmap icon) {
        FastBitmapDrawable d = new FastBitmapDrawable(icon);
        d.setFilterBitmap(true);
        resizeIconDrawable(d);
        return d;
    }

    /**
     * Resizes an icon drawable to the correct icon size.
     */
    public Drawable resizeIconDrawable(Drawable icon) {
        icon.setBounds(0, 0, mDeviceProfile.iconSizePx, mDeviceProfile.iconSizePx);
        return icon;
    }

    /**
     * Prints out out state for debugging.
     */
Loading