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

Commit 8b16b96b authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Fixing same drawable instance being used with 2 views

Drawable contain a reference to the view which is used to invalidate the view.
If the same drawable is used with two views, only once view will get invalidated.

Bug: 32575647
Change-Id: Ia22310a6bda55ce0a591712761ec8ab1cdbaccdf
parent cc42c5bd
Loading
Loading
Loading
Loading
+44 −43
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.launcher3;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
@@ -41,13 +40,9 @@ import com.android.launcher3.util.TransformingTouchDelegate;
public abstract class BaseContainerView extends FrameLayout
        implements DeviceProfile.LauncherLayoutChangeListener {

    protected int mContainerPaddingLeft;
    protected int mContainerPaddingRight;
    protected int mContainerPaddingTop;
    protected int mContainerPaddingBottom;
    private static final Rect sBgPaddingRect = new Rect();

    protected final Drawable mBaseDrawable;
    private final Rect mBgPaddingRect = new Rect();

    private View mRevealView;
    private View mContent;
@@ -109,26 +104,59 @@ public abstract class BaseContainerView extends FrameLayout
        updatePaddings();
    }

    @Override
    public void onLauncherLayoutChanged() {
        updatePaddings();
    }

    /**
     * Calculate the background padding as it can change due to insets/content padding change.
     */
    private void updatePaddings() {
        Context context = getContext();
        int paddingLeft;
        int paddingRight;
        int paddingTop;
        int paddingBottom;

        DeviceProfile grid = Launcher.getLauncher(context).getDeviceProfile();
        int[] padding = grid.getContainerPadding(context);
        paddingLeft = padding[0] + grid.edgeMarginPx;
        paddingRight = padding[1] + grid.edgeMarginPx;
        if (!grid.isVerticalBarLayout()) {
            paddingTop = paddingBottom = grid.edgeMarginPx;
        } else {
            paddingTop = paddingBottom = 0;
        }
        updateBackground(paddingLeft, paddingTop, paddingRight, paddingBottom);
    }

    /**
     * Update the background for the reveal view and content view based on the background padding.
     */
    protected void updateBackground(int paddingLeft, int paddingTop,
            int paddingRight, int paddingBottom) {
        mRevealView.setBackground(new InsetDrawable(mBaseDrawable,
                paddingLeft, paddingTop, paddingRight, paddingBottom));
        mContent.setBackground(new InsetDrawable(mBaseDrawable,
                paddingLeft, paddingTop, paddingRight, paddingBottom));
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
        getRevealView().getBackground().getPadding(mBgPaddingRect);

        View touchDelegateTargetView = getTouchDelegateTargetView();
        if (touchDelegateTargetView != null) {
            getRevealView().getBackground().getPadding(sBgPaddingRect);
            mTouchDelegate.setBounds(
                    touchDelegateTargetView.getLeft() - mBgPaddingRect.left,
                    touchDelegateTargetView.getTop() - mBgPaddingRect.top,
                    touchDelegateTargetView.getRight() + mBgPaddingRect.right,
                    touchDelegateTargetView.getBottom() + mBgPaddingRect.bottom);
                    touchDelegateTargetView.getLeft() - sBgPaddingRect.left,
                    touchDelegateTargetView.getTop() - sBgPaddingRect.top,
                    touchDelegateTargetView.getRight() + sBgPaddingRect.right,
                    touchDelegateTargetView.getBottom() + sBgPaddingRect.bottom);
        }
    }

    @Override
    public void onLauncherLayoutChanged() {
        updatePaddings();
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return handleTouchEvent(ev);
@@ -152,33 +180,6 @@ public abstract class BaseContainerView extends FrameLayout
        return mRevealView;
    }

    private void updatePaddings() {
        Context context = getContext();
        Launcher launcher = Launcher.getLauncher(context);

        if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP &&
                this instanceof AllAppsContainerView &&
                !launcher.getDeviceProfile().isVerticalBarLayout()) {
            mContainerPaddingLeft = mContainerPaddingRight = 0;
            mContainerPaddingTop = mContainerPaddingBottom = 0;
        } else {
            DeviceProfile grid = launcher.getDeviceProfile();
            int[] padding = grid.getContainerPadding(context);
            mContainerPaddingLeft = padding[0] + grid.edgeMarginPx;
            mContainerPaddingRight = padding[1] + grid.edgeMarginPx;
            if (!launcher.getDeviceProfile().isVerticalBarLayout()) {
                mContainerPaddingTop = mContainerPaddingBottom = grid.edgeMarginPx;
            } else {
                mContainerPaddingTop = mContainerPaddingBottom = 0;
            }
        }

        InsetDrawable revealDrawable = new InsetDrawable(mBaseDrawable,
                mContainerPaddingLeft, mContainerPaddingTop, mContainerPaddingRight,
                mContainerPaddingBottom);
        mRevealView.setBackground(revealDrawable);
        mContent.setBackground(revealDrawable);
    }

    /**
     * Handles the touch events that shows the workspace when clicking outside the bounds of the
+21 −0
Original line number Diff line number Diff line
@@ -16,7 +16,10 @@
package com.android.launcher3.allapps;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.InsetDrawable;
import android.support.v7.widget.RecyclerView;
import android.text.Selection;
import android.text.Spannable;
@@ -100,6 +103,24 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
        Selection.setSelection(mSearchQueryBuilder, 0);
    }

    @Override
    protected void updateBackground(
            int paddingLeft, int paddingTop, int paddingRight, int paddingBottom) {
        if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP) {
            if (mLauncher.getDeviceProfile().isVerticalBarLayout()) {
                getRevealView().setBackground(new InsetDrawable(mBaseDrawable,
                        paddingLeft, paddingTop, paddingRight, paddingBottom));
                getContentView().setBackground(
                        new InsetDrawable(new ColorDrawable(Color.TRANSPARENT),
                                paddingLeft, paddingTop, paddingRight, paddingBottom));
            } else {
                getRevealView().setBackground(mBaseDrawable);
            }
        } else {
            super.updateBackground(paddingLeft, paddingTop, paddingRight, paddingBottom);
        }
    }

    /**
     * Sets the current set of predicted apps.
     */