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

Commit b9465eec authored by Sunny Goyal's avatar Sunny Goyal Committed by Android (Google) Code Review
Browse files

Merge "Setting the callback for previewItems to folderIcon. This allows the...

Merge "Setting the callback for previewItems to folderIcon. This allows the FolderIcon to get updated without going through the child'draw pass. Also simplifying the draw code for the FolderIcon to remove any cycling invalidate calls" into ub-launcher3-dorval-polish
parents 451dc5df 828b11e5
Loading
Loading
Loading
Loading
+0 −13
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import android.graphics.Rect;
import android.graphics.Region;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.v4.graphics.ColorUtils;
import android.util.AttributeSet;
import android.util.Property;
@@ -48,7 +47,6 @@ import com.android.launcher3.IconCache.ItemInfoUpdateReceiver;
import com.android.launcher3.badge.BadgeInfo;
import com.android.launcher3.badge.BadgeRenderer;
import com.android.launcher3.folder.FolderIconPreviewVerifier;
import com.android.launcher3.folder.FolderPagedView;
import com.android.launcher3.graphics.DrawableFactory;
import com.android.launcher3.graphics.HolographicOutlineHelper;
import com.android.launcher3.graphics.IconPalette;
@@ -209,17 +207,6 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver {
        applyFromShortcutInfo(info, false);
    }

    @Override
    public void invalidateDrawable(@NonNull Drawable drawable) {
        super.invalidateDrawable(drawable);

        if (getParent() != null
                && getParent().getParent() != null
                && getParent().getParent().getParent() instanceof FolderPagedView) {
            ((FolderPagedView) getParent().getParent().getParent()).onIconInvalidated(this);
        }
    }

    public void applyFromShortcutInfo(ShortcutInfo info, boolean promiseStateChanged) {
        applyIconAndLabel(info.iconBitmap, info);
        setTag(info);
+0 −11
Original line number Diff line number Diff line
@@ -105,17 +105,6 @@ 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);
    }

+1 −1
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ public class ClippedFolderIconLayoutRule implements FolderIcon.PreviewLayoutRule
    private float mBaselineIconScale;

    @Override
    public void init(int availableSpace, int intrinsicIconSize, boolean rtl) {
    public void init(int availableSpace, float intrinsicIconSize, boolean rtl) {
        mAvailableSpace = availableSpace;
        mRadius = ITEM_RADIUS_SCALE_FACTOR * availableSpace / 2f;
        mIconSize = intrinsicIconSize;
+26 −21
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.graphics.Region;
import android.graphics.Shader;
import android.graphics.drawable.Drawable;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import android.support.v4.graphics.ColorUtils;
import android.util.AttributeSet;
import android.util.Property;
@@ -116,7 +117,7 @@ public class FolderIcon extends FrameLayout implements FolderListener {

    // These variables are all associated with the drawing of the preview; they are stored
    // as member variables for shared usage and to avoid computation on each frame
    private int mIntrinsicIconSize = -1;
    private float mIntrinsicIconSize = -1;
    private int mTotalWidth = -1;
    private int mPrevTopPadding = -1;

@@ -132,7 +133,7 @@ public class FolderIcon extends FrameLayout implements FolderListener {

    FolderIconPreviewVerifier mPreviewVerifier;
    private PreviewItemDrawingParams mTmpParams = new PreviewItemDrawingParams(0, 0, 0, 0);
    private ArrayList<PreviewItemDrawingParams> mDrawingParams = new ArrayList<PreviewItemDrawingParams>();
    private ArrayList<PreviewItemDrawingParams> mDrawingParams = new ArrayList<>();
    private Drawable mReferenceDrawable = null;

    private Alarm mOpenAlarm = new Alarm();
@@ -510,24 +511,12 @@ public class FolderIcon extends FrameLayout implements FolderListener {
        Drawable d = params.drawable;

        if (d != null) {
            // Remove the callback to prevent invalidate as a result of property changes
            Drawable.Callback cb = d.getCallback();
            d.setCallback(null);

            mTempBounds.set(d.getBounds());
            d.setBounds(0, 0, mIntrinsicIconSize, mIntrinsicIconSize);
            boolean isPreloadIcon = d instanceof PreloadIconDrawable;
            if (!isPreloadIcon && d instanceof FastBitmapDrawable) {
                FastBitmapDrawable fd = (FastBitmapDrawable) d;
                fd.drawWithBrightness(canvas, params.overlayAlpha);
            } else {
                d.setColorFilter(Color.argb((int) (params.overlayAlpha * 255), 255, 255, 255),
                        PorterDuff.Mode.SRC_ATOP);
            Rect bounds = d.getBounds();
            canvas.save();
            canvas.translate(-bounds.left, -bounds.top);
            canvas.scale(mIntrinsicIconSize / bounds.width(), mIntrinsicIconSize / bounds.height());
            d.draw(canvas);
                d.clearColorFilter();
            }
            d.setBounds(mTempBounds);
            d.setCallback(cb);
            canvas.restore();
        }
        canvas.restore();
    }
@@ -1112,6 +1101,16 @@ public class FolderIcon extends FrameLayout implements FolderListener {
        return itemsToDisplay;
    }

    @Override
    protected boolean verifyDrawable(@NonNull Drawable who) {
        for (int i = 0; i < mDrawingParams.size(); i++) {
            if (mDrawingParams.get(i).drawable == who) {
                return true;
            }
        }
        return super.verifyDrawable(who);
    }

    private void updateItemDrawingParams(boolean animate) {
        List<BubbleTextView> items = getItemsToDisplay();
        int nItemsInPreview = items.size();
@@ -1130,6 +1129,12 @@ public class FolderIcon extends FrameLayout implements FolderListener {
            PreviewItemDrawingParams p = mDrawingParams.get(i);
            p.drawable = items.get(i).getCompoundDrawables()[1];

            if (p.drawable != null && !mFolder.isOpen()) {
                // Set the callback to FolderIcon as it is responsible to drawing the icon. The
                // callback will be release when the folder is opened.
                p.drawable.setCallback(this);
            }

            if (!animate || FeatureFlags.LAUNCHER3_LEGACY_FOLDER_ICON) {
                computePreviewItemDrawingParams(i, nItemsInPreview, p);
                if (mReferenceDrawable == null) {
@@ -1300,7 +1305,7 @@ public class FolderIcon extends FrameLayout implements FolderListener {
    public interface PreviewLayoutRule {
        PreviewItemDrawingParams computePreviewItemDrawingParams(int index, int curNumItems,
            PreviewItemDrawingParams params);
        void init(int availableSpace, int intrinsicIconSize, boolean rtl);
        void init(int availableSpace, float intrinsicIconSize, boolean rtl);
        float scaleForItem(int index, int totalNumItems);
        float getIconSize();
        int maxNumItems();
+11 −9
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.launcher3.folder;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.ArrayMap;
import android.util.AttributeSet;
import android.util.Log;
@@ -27,6 +28,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewDebug;
import android.view.animation.DecelerateInterpolator;

import com.android.launcher3.BubbleTextView;
import com.android.launcher3.CellLayout;
import com.android.launcher3.DeviceProfile;
@@ -44,6 +46,7 @@ import com.android.launcher3.Workspace.ItemOperator;
import com.android.launcher3.keyboard.ViewGroupFocusHelper;
import com.android.launcher3.pageindicators.PageIndicator;
import com.android.launcher3.util.Thunk;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
@@ -178,14 +181,6 @@ public class FolderPagedView extends PagedView {
        super.dispatchDraw(canvas);
    }

    public void onIconInvalidated(BubbleTextView icon) {
        FolderIcon folderIcon = mFolder.mFolderIcon;
        if (icon.getTag() instanceof ItemInfo
                && folderIcon.mPreviewVerifier.isItemInPreview(((ItemInfo) icon.getTag()).rank)) {
            folderIcon.invalidate();
        }
    }

    /**
     * Binds items to the layout.
     * @return list of items that could not be bound, probably because we hit the max size limit.
@@ -562,7 +557,14 @@ public class FolderPagedView extends PagedView {
        if (page != null) {
            ShortcutAndWidgetContainer parent = page.getShortcutsAndWidgets();
            for (int i = parent.getChildCount() - 1; i >= 0; i--) {
                ((BubbleTextView) parent.getChildAt(i)).verifyHighRes();
                BubbleTextView icon = ((BubbleTextView) parent.getChildAt(i));
                icon.verifyHighRes();
                // Set the callback back to the actual icon, in case
                // it was captured by the FolderIcon
                Drawable d = icon.getCompoundDrawables()[1];
                if (d != null) {
                    d.setCallback(icon);
                }
            }
        }
    }
Loading