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

Commit 6d8f29f8 authored by Alex Chau's avatar Alex Chau Committed by Automerger Merge Worker
Browse files

Merge "Add a scrim to AllApps and Widgets" into tm-dev am: 7c89ac5d

parents f0b4091d 7c89ac5d
Loading
Loading
Loading
Loading
+23 −14
Original line number Original line Diff line number Diff line
@@ -388,34 +388,34 @@ public abstract class BaseAllAppsContainerView<T extends Context & ActivityConte
        mInsets.set(insets);
        mInsets.set(insets);
        DeviceProfile grid = mActivityContext.getDeviceProfile();
        DeviceProfile grid = mActivityContext.getDeviceProfile();


        for (int i = 0; i < mAH.size(); i++) {
        applyAdapterPaddings(grid);
            mAH.get(i).mPadding.bottom = insets.bottom;
            mAH.get(i).mPadding.left = mAH.get(i).mPadding.right = grid.allAppsLeftRightPadding;
            mAH.get(i).applyPadding();
        }


        MarginLayoutParams mlp = (MarginLayoutParams) getLayoutParams();
        MarginLayoutParams mlp = (MarginLayoutParams) getLayoutParams();
        int leftRightMargin = grid.allAppsLeftRightMargin;
        mlp.leftMargin = insets.left;
        mlp.leftMargin = insets.left + leftRightMargin;
        mlp.rightMargin = insets.right;
        mlp.rightMargin = insets.right + leftRightMargin;
        setLayoutParams(mlp);
        setLayoutParams(mlp);


        if (grid.isVerticalBarLayout()) {
        if (grid.isVerticalBarLayout()) {
            setPadding(grid.workspacePadding.left, 0, grid.workspacePadding.right, 0);
            setPadding(grid.workspacePadding.left, 0, grid.workspacePadding.right, 0);
        } else {
        } else {
            setPadding(0, grid.allAppsTopPadding, 0, 0);
            setPadding(grid.allAppsLeftRightMargin, grid.allAppsTopPadding,
                    grid.allAppsLeftRightMargin, 0);
        }
        }


        InsettableFrameLayout.dispatchInsets(this, insets);
        InsettableFrameLayout.dispatchInsets(this, insets);
    }
    }


    /**
     * Returns a padding in case a scrim is shown on the bottom of the view and a padding is needed.
     */
    protected int getNavBarScrimHeight(WindowInsets insets) {
        return 0;
    }

    @Override
    @Override
    public WindowInsets dispatchApplyWindowInsets(WindowInsets insets) {
    public WindowInsets dispatchApplyWindowInsets(WindowInsets insets) {
        if (Utilities.ATLEAST_Q) {
        mNavBarScrimHeight = getNavBarScrimHeight(insets);
            mNavBarScrimHeight = insets.getTappableElementInsets().bottom;
        applyAdapterPaddings(mActivityContext.getDeviceProfile());
        } else {
            mNavBarScrimHeight = insets.getStableInsetBottom();
        }
        return super.dispatchApplyWindowInsets(insets);
        return super.dispatchApplyWindowInsets(insets);
    }
    }


@@ -483,6 +483,15 @@ public abstract class BaseAllAppsContainerView<T extends Context & ActivityConte
        mAllAppsStore.registerIconContainer(mAH.get(AdapterHolder.WORK).mRecyclerView);
        mAllAppsStore.registerIconContainer(mAH.get(AdapterHolder.WORK).mRecyclerView);
    }
    }


    private void applyAdapterPaddings(DeviceProfile grid) {
        int bottomPadding = Math.max(mInsets.bottom, mNavBarScrimHeight);
        for (int i = 0; i < mAH.size(); i++) {
            mAH.get(i).mPadding.bottom = bottomPadding;
            mAH.get(i).mPadding.left = mAH.get(i).mPadding.right = grid.allAppsLeftRightPadding;
            mAH.get(i).applyPadding();
        }
    }

    private void setDeviceManagementResources() {
    private void setDeviceManagementResources() {
        if (mActivityContext.getStringCache() != null) {
        if (mActivityContext.getStringCache() != null) {
            Button personalTab = findViewById(R.id.tab_personal);
            Button personalTab = findViewById(R.id.tab_personal);
+11 −0
Original line number Original line Diff line number Diff line
@@ -18,9 +18,11 @@ package com.android.launcher3.allapps;
import android.content.Context;
import android.content.Context;
import android.util.AttributeSet;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.MotionEvent;
import android.view.WindowInsets;


import com.android.launcher3.Launcher;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState;
import com.android.launcher3.LauncherState;
import com.android.launcher3.Utilities;


/**
/**
 * AllAppsContainerView with launcher specific callbacks
 * AllAppsContainerView with launcher specific callbacks
@@ -58,4 +60,13 @@ public class LauncherAllAppsContainerView extends ActivityAllAppsContainerView<L
        }
        }
        return super.onTouchEvent(ev);
        return super.onTouchEvent(ev);
    }
    }

    @Override
    protected int getNavBarScrimHeight(WindowInsets insets) {
        if (Utilities.ATLEAST_Q) {
            return insets.getTappableElementInsets().bottom;
        } else {
            return insets.getStableInsetBottom();
        }
    }
}
}
+5 −13
Original line number Original line Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.launcher3.widget;


import static com.android.launcher3.Utilities.ATLEAST_R;
import static com.android.launcher3.Utilities.ATLEAST_R;
import static com.android.launcher3.anim.Interpolators.FAST_OUT_SLOW_IN;
import static com.android.launcher3.anim.Interpolators.FAST_OUT_SLOW_IN;
import static com.android.launcher3.widget.BaseWidgetSheet.MAX_WIDTH_SCALE_FOR_LARGER_SCREEN;


import android.animation.PropertyValuesHolder;
import android.animation.PropertyValuesHolder;
import android.annotation.SuppressLint;
import android.annotation.SuppressLint;
@@ -106,7 +105,10 @@ public class AddItemWidgetsBottomSheet extends AbstractSlideInView<AddItemActivi
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        DeviceProfile deviceProfile = mActivityContext.getDeviceProfile();
        DeviceProfile deviceProfile = mActivityContext.getDeviceProfile();
        int widthUsed;
        int widthUsed;
        if (mInsets.bottom > 0) {
        if (deviceProfile.isTablet) {
            int margin = deviceProfile.allAppsLeftRightMargin;
            widthUsed = Math.max(2 * margin, 2 * (mInsets.left + mInsets.right));
        } else if (mInsets.bottom > 0) {
            widthUsed = mInsets.left + mInsets.right;
            widthUsed = mInsets.left + mInsets.right;
        } else {
        } else {
            Rect padding = deviceProfile.workspacePadding;
            Rect padding = deviceProfile.workspacePadding;
@@ -114,18 +116,8 @@ public class AddItemWidgetsBottomSheet extends AbstractSlideInView<AddItemActivi
                    2 * (mInsets.left + mInsets.right));
                    2 * (mInsets.left + mInsets.right));
        }
        }


        if (deviceProfile.isTablet || deviceProfile.isTwoPanels) {
            // In large screen devices, we restrict the width of the widgets picker to show part of
            // the home screen. Let's ensure the minimum width used is at least the minimum width
            // that isn't taken by the widgets picker.
            int minUsedWidth = (int) (deviceProfile.availableWidthPx
                    * (1 - MAX_WIDTH_SCALE_FOR_LARGER_SCREEN));
            widthUsed = Math.max(widthUsed, minUsedWidth);
        }

        int heightUsed = mInsets.top + deviceProfile.edgeMarginPx;
        measureChildWithMargins(mContent, widthMeasureSpec,
        measureChildWithMargins(mContent, widthMeasureSpec,
                widthUsed, heightMeasureSpec, heightUsed);
                widthUsed, heightMeasureSpec, deviceProfile.bottomSheetTopPadding);
        setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec),
        setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec),
                MeasureSpec.getSize(heightMeasureSpec));
                MeasureSpec.getSize(heightMeasureSpec));
    }
    }
+40 −15
Original line number Original line Diff line number Diff line
@@ -16,6 +16,8 @@
package com.android.launcher3.widget;
package com.android.launcher3.widget;


import android.content.Context;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.AttributeSet;
@@ -23,6 +25,7 @@ import android.util.Log;
import android.view.View;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.View.OnLongClickListener;
import android.view.WindowInsets;
import android.widget.Toast;
import android.widget.Toast;


import androidx.annotation.GuardedBy;
import androidx.annotation.GuardedBy;
@@ -43,6 +46,7 @@ import com.android.launcher3.testing.TestProtocol;
import com.android.launcher3.touch.ItemLongClickListener;
import com.android.launcher3.touch.ItemLongClickListener;
import com.android.launcher3.util.SystemUiController;
import com.android.launcher3.util.SystemUiController;
import com.android.launcher3.util.Themes;
import com.android.launcher3.util.Themes;
import com.android.launcher3.util.window.WindowManagerProxy;
import com.android.launcher3.views.AbstractSlideInView;
import com.android.launcher3.views.AbstractSlideInView;
import com.android.launcher3.views.ActivityContext;
import com.android.launcher3.views.ActivityContext;
import com.android.launcher3.views.ArrowTipView;
import com.android.launcher3.views.ArrowTipView;
@@ -55,11 +59,6 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<Launcher>
        PopupDataProvider.PopupDataChangeListener, Insettable {
        PopupDataProvider.PopupDataChangeListener, Insettable {
    /** The default number of cells that can fit horizontally in a widget sheet. */
    /** The default number of cells that can fit horizontally in a widget sheet. */
    protected static final int DEFAULT_MAX_HORIZONTAL_SPANS = 4;
    protected static final int DEFAULT_MAX_HORIZONTAL_SPANS = 4;
    /**
     * The maximum scale, [0, 1], of the device screen width that the widgets picker can consume
     * on large screen devices.
     */
    protected static final float MAX_WIDTH_SCALE_FOR_LARGER_SCREEN = 0.89f;


    protected static final String KEY_WIDGETS_EDUCATION_TIP_SEEN =
    protected static final String KEY_WIDGETS_EDUCATION_TIP_SEEN =
            "launcher.widgets_education_tip_seen";
            "launcher.widgets_education_tip_seen";
@@ -70,10 +69,15 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<Launcher>


    private int mContentHorizontalMarginInPx;
    private int mContentHorizontalMarginInPx;


    protected int mNavBarScrimHeight;
    private final Paint mNavBarScrimPaint;

    public BaseWidgetSheet(Context context, AttributeSet attrs, int defStyleAttr) {
    public BaseWidgetSheet(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        super(context, attrs, defStyleAttr);
        mContentHorizontalMarginInPx = getResources().getDimensionPixelSize(
        mContentHorizontalMarginInPx = getResources().getDimensionPixelSize(
                R.dimen.widget_list_horizontal_margin);
                R.dimen.widget_list_horizontal_margin);
        mNavBarScrimPaint = new Paint();
        mNavBarScrimPaint.setColor(Themes.getAttrColor(context, R.attr.allAppsNavBarScrimColor));
    }
    }


    protected int getScrimColor(Context context) {
    protected int getScrimColor(Context context) {
@@ -83,6 +87,9 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<Launcher>
    @Override
    @Override
    protected void onAttachedToWindow() {
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        super.onAttachedToWindow();
        WindowInsets windowInsets = WindowManagerProxy.INSTANCE.get(getContext())
                .normalizeWindowInsets(getContext(), getRootWindowInsets(), new Rect());
        mNavBarScrimHeight = getNavBarScrimHeight(windowInsets);
        mActivityContext.getPopupDataProvider().setChangeListener(this);
        mActivityContext.getPopupDataProvider().setChangeListener(this);
    }
    }


@@ -136,6 +143,30 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<Launcher>
        }
        }
    }
    }


    private int getNavBarScrimHeight(WindowInsets insets) {
        if (Utilities.ATLEAST_Q) {
            return insets.getTappableElementInsets().bottom;
        } else {
            return insets.getStableInsetBottom();
        }
    }

    @Override
    public WindowInsets onApplyWindowInsets(WindowInsets insets) {
        mNavBarScrimHeight = getNavBarScrimHeight(insets);
        return super.onApplyWindowInsets(insets);
    }

    @Override
    protected void dispatchDraw(Canvas canvas) {
        super.dispatchDraw(canvas);

        if (mNavBarScrimHeight > 0) {
            canvas.drawRect(0, getHeight() - mNavBarScrimHeight, getWidth(), getHeight(),
                    mNavBarScrimPaint);
        }
    }

    /** Called when the horizontal margin of the content view has changed. */
    /** Called when the horizontal margin of the content view has changed. */
    protected abstract void onContentHorizontalMarginChanged(int contentHorizontalMarginInPx);
    protected abstract void onContentHorizontalMarginChanged(int contentHorizontalMarginInPx);


@@ -147,7 +178,10 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<Launcher>
    protected void doMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    protected void doMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        DeviceProfile deviceProfile = mActivityContext.getDeviceProfile();
        DeviceProfile deviceProfile = mActivityContext.getDeviceProfile();
        int widthUsed;
        int widthUsed;
        if (mInsets.bottom > 0) {
        if (deviceProfile.isTablet) {
            int margin = deviceProfile.allAppsLeftRightMargin;
            widthUsed = Math.max(2 * margin, 2 * (mInsets.left + mInsets.right));
        } else if (mInsets.bottom > 0) {
            widthUsed = mInsets.left + mInsets.right;
            widthUsed = mInsets.left + mInsets.right;
        } else {
        } else {
            Rect padding = deviceProfile.workspacePadding;
            Rect padding = deviceProfile.workspacePadding;
@@ -155,15 +189,6 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<Launcher>
                    2 * (mInsets.left + mInsets.right));
                    2 * (mInsets.left + mInsets.right));
        }
        }


        if (deviceProfile.isTablet || deviceProfile.isTwoPanels) {
            // In large screen devices, we restrict the width of the widgets picker to show part of
            // the home screen. Let's ensure the minimum width used is at least the minimum width
            // that isn't taken by the widgets picker.
            int minUsedWidth = (int) (deviceProfile.availableWidthPx
                    * (1 - MAX_WIDTH_SCALE_FOR_LARGER_SCREEN));
            widthUsed = Math.max(widthUsed, minUsedWidth);
        }

        measureChildWithMargins(mContent, widthMeasureSpec,
        measureChildWithMargins(mContent, widthMeasureSpec,
                widthUsed, heightMeasureSpec, deviceProfile.bottomSheetTopPadding);
                widthUsed, heightMeasureSpec, deviceProfile.bottomSheetTopPadding);
        setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec),
        setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec),
+4 −2
Original line number Original line Diff line number Diff line
@@ -247,10 +247,12 @@ public class WidgetsBottomSheet extends BaseWidgetSheet {
    @Override
    @Override
    public void setInsets(Rect insets) {
    public void setInsets(Rect insets) {
        super.setInsets(insets);
        super.setInsets(insets);
        int bottomPadding = Math.max(insets.bottom, mNavBarScrimHeight);


        mContent.setPadding(mContent.getPaddingStart(),
        mContent.setPadding(mContent.getPaddingStart(),
                mContent.getPaddingTop(), mContent.getPaddingEnd(), insets.bottom);
                mContent.getPaddingTop(), mContent.getPaddingEnd(),
        if (insets.bottom > 0) {
                bottomPadding);
        if (bottomPadding > 0) {
            setupNavBarColor();
            setupNavBarColor();
        } else {
        } else {
            clearNavBarColor();
            clearNavBarColor();
Loading