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

Commit 62339981 authored by Shamali P's avatar Shamali P
Browse files

Use full-width two picker in both orientations in tablets

The change is really for enabling display of categorical suggestions,
so using the same flag.

Bug: 315055849
Bug: 318410881
Test: See screenshots
Flag: ACONFIG com.android.launcher3.enable_categorized_widget_recommendations DEVELOPMENT
Change-Id: Ia98fdd6b827f31a63264128617f6a16ee0716bcc
parent 5fbb0ccc
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
package com.android.launcher3.widget;

import static com.android.app.animation.Interpolators.EMPHASIZED;
import static com.android.launcher3.Flags.enableCategorizedWidgetSuggestions;
import static com.android.launcher3.Flags.enableUnfoldedTwoPanePicker;
import static com.android.launcher3.LauncherPrefs.WIDGETS_EDUCATION_TIP_SEEN;

@@ -62,8 +63,10 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<BaseActivity>

    protected final Rect mInsets = new Rect();

    @Px protected int mContentHorizontalMargin;
    @Px protected int mWidgetCellHorizontalPadding;
    @Px
    protected int mContentHorizontalMargin;
    @Px
    protected int mWidgetCellHorizontalPadding;

    protected int mNavBarScrimHeight;
    private final Paint mNavBarScrimPaint;
@@ -196,7 +199,7 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<BaseActivity>
        DeviceProfile deviceProfile = mActivityContext.getDeviceProfile();
        int widthUsed;
        if (deviceProfile.isTablet) {
            widthUsed = Math.max(2 * getTabletMargin(deviceProfile),
            widthUsed = Math.max(2 * getTabletHorizontalMargin(deviceProfile),
                    2 * (mInsets.left + mInsets.right));
        } else if (mInsets.bottom > 0) {
            widthUsed = mInsets.left + mInsets.right;
@@ -212,7 +215,11 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<BaseActivity>
                MeasureSpec.getSize(heightMeasureSpec));
    }

    private int getTabletMargin(DeviceProfile deviceProfile) {
    private int getTabletHorizontalMargin(DeviceProfile deviceProfile) {
        // All bottom-sheets showing widgets will be full-width across all devices.
        if (enableCategorizedWidgetSuggestions()) {
            return 0;
        }
        if (deviceProfile.isLandscape && !deviceProfile.isTwoPanels) {
            return getResources().getDimensionPixelSize(
                    R.dimen.widget_picker_landscape_tablet_left_right_margin);
+27 −12
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ package com.android.launcher3.widget.picker;

import static android.view.View.MeasureSpec.makeMeasureSpec;

import static com.android.launcher3.Flags.enableCategorizedWidgetSuggestions;
import static com.android.launcher3.Flags.enableUnfoldedTwoPanePicker;
import static com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_Y;
import static com.android.launcher3.LauncherPrefs.WIDGETS_EDUCATION_DIALOG_SEEN;
@@ -699,7 +700,9 @@ public class WidgetsFullSheet extends BaseWidgetSheet

    private static int getWidgetSheetId(BaseActivity activity) {
        boolean isTwoPane = (activity.getDeviceProfile().isTablet
                && activity.getDeviceProfile().isLandscape
                // Enables two pane picker for tablets in all orientations when the
                // enableCategorizedWidgetSuggestions flag is on.
                && (activity.getDeviceProfile().isLandscape || enableCategorizedWidgetSuggestions())
                && !activity.getDeviceProfile().isTwoPanels)
                // Enables two pane picker for unfolded foldables if the flag is on.
                || (activity.getDeviceProfile().isTwoPanels && enableUnfoldedTwoPanePicker());
@@ -813,28 +816,40 @@ public class WidgetsFullSheet extends BaseWidgetSheet
    public void onDeviceProfileChanged(DeviceProfile dp) {
        super.onDeviceProfileChanged(dp);

        if (mDeviceProfile.isLandscape != dp.isLandscape && dp.isTablet && !dp.isTwoPanels) {
            handleClose(false);
            show(BaseActivity.fromContext(getContext()), false);
        } else if (!isTwoPane()) {
            reset();
            resetExpandedHeaders();
        }

        // When folding/unfolding the foldables, we need to switch between the regular widget picker
        // and the two pane picker, so we rebuild the picker with the correct layout.
        if (mDeviceProfile.isTwoPanels != dp.isTwoPanels && enableUnfoldedTwoPanePicker()) {
        if (shouldRecreateLayout(/*oldDp=*/ mDeviceProfile, /*newDp=*/ dp)) {
            SparseArray<Parcelable> widgetsState = new SparseArray<>();
            saveHierarchyState(widgetsState);
            handleClose(false);
            WidgetsFullSheet sheet = show(BaseActivity.fromContext(getContext()), false);
            sheet.restoreHierarchyState(widgetsState);
            sheet.restorePreviousAdapterHolderType(getCurrentAdapterHolderType());
        } else if (!isTwoPane()) {
            reset();
            resetExpandedHeaders();
        }

        mDeviceProfile = dp;
    }

    /**
     * Indicates if layout should be re-created on device profile change - so that a different
     * layout can be displayed.
     */
    private static boolean shouldRecreateLayout(DeviceProfile oldDp, DeviceProfile newDp) {
        // When folding/unfolding the foldables, we need to switch between the regular widget picker
        // and the two pane picker, so we rebuild the picker with the correct layout.
        boolean isFoldUnFold =
                oldDp.isTwoPanels != newDp.isTwoPanels && enableUnfoldedTwoPanePicker();
        // In tablets, on orientation change we switch between single and two pane picker unless the
        // categorized suggestions flag was on. With the categorized suggestions feature, we use a
        // two pane picker across all orientations.
        boolean useDifferentLayoutOnOrientationChange =
                (!enableCategorizedWidgetSuggestions() && (newDp.isTablet && !newDp.isTwoPanels
                        && oldDp.isLandscape != newDp.isLandscape));

        return isFoldUnFold || useDifferentLayoutOnOrientationChange;
    }

    @Override
    public void onBackInvoked() {
        if (mIsInSearchMode) {