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

Commit 0adad244 authored by Andy Wickham's avatar Andy Wickham
Browse files

Adds header protection on tablet all apps panel.

Removes background and manually draws it while drawing scrim. Then
draws header protection on top as needed.

Currently this only applies to all apps from Launcher, as Taskbar
doesn't seem to use the same scrim flow. So taskbar adds the same
static background that was previously used.

Demo videos: https://drive.google.com/drive/folders/11PyFsrLV6-QhU_E-zD3s5bfzZK2nOU87?resourcekey=0-E41uw5TP9xuqTifLAs71yw&usp=sharing

Test: Manually on phone and tablet with dark/light mode, floating
search bar on/off, work profile present/absent, taskbar/home entry
Bug: 240670050

Change-Id: I81dcc956d9dbbc7552c8a227a49741bcf71eed71
parent 493831af
Loading
Loading
Loading
Loading
+9 −0
Original line number Original line Diff line number Diff line
@@ -19,6 +19,8 @@ import android.content.Context;
import android.util.AttributeSet;
import android.util.AttributeSet;
import android.view.WindowInsets;
import android.view.WindowInsets;


import com.android.launcher3.DeviceProfile;
import com.android.launcher3.R;
import com.android.launcher3.allapps.ActivityAllAppsContainerView;
import com.android.launcher3.allapps.ActivityAllAppsContainerView;
import com.android.launcher3.taskbar.overlay.TaskbarOverlayContext;
import com.android.launcher3.taskbar.overlay.TaskbarOverlayContext;


@@ -44,4 +46,11 @@ public class TaskbarAllAppsContainerView extends
    protected boolean isSearchSupported() {
    protected boolean isSearchSupported() {
        return false;
        return false;
    }
    }

    @Override
    protected void updateBackground(DeviceProfile deviceProfile) {
        super.updateBackground(deviceProfile);
        // TODO(b/240670050): Remove this and add header protection for the taskbar entrypoint.
        mBottomSheetBackground.setBackgroundResource(R.drawable.bg_rounded_corner_bottom_sheet);
    }
}
}
+1 −2
Original line number Original line Diff line number Diff line
@@ -16,8 +16,7 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/bottom_sheet_background"
    android:id="@+id/bottom_sheet_background"
    android:layout_width="match_parent"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_height="match_parent">
    android:background="@drawable/bg_rounded_corner_bottom_sheet">


    <View
    <View
        android:id="@+id/bottom_sheet_handle_area"
        android:id="@+id/bottom_sheet_handle_area"
+4 −0
Original line number Original line Diff line number Diff line
@@ -282,6 +282,10 @@ public class ActivityAllAppsContainerView<T extends Context & AppLauncher
    @Override
    @Override
    public int getHeaderBottom() {
    public int getHeaderBottom() {
        if (FeatureFlags.ENABLE_FLOATING_SEARCH_BAR.get()) {
        if (FeatureFlags.ENABLE_FLOATING_SEARCH_BAR.get()) {
            if (mActivityContext.getDeviceProfile().isTablet) {
                return super.getHeaderBottom() + mHeader.getClipTop()
                        + mBottomSheetBackground.getTop();
            }
            return super.getHeaderBottom() + mHeader.getClipTop();
            return super.getHeaderBottom() + mHeader.getClipTop();
        }
        }
        return super.getHeaderBottom() + mSearchContainer.getBottom();
        return super.getHeaderBottom() + mSearchContainer.getBottom();
+76 −18
Original line number Original line Diff line number Diff line
@@ -26,8 +26,11 @@ import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Path.Direction;
import android.graphics.Point;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Bundle;
import android.os.Bundle;
import android.os.Parcelable;
import android.os.Parcelable;
import android.os.Process;
import android.os.Process;
@@ -35,6 +38,7 @@ import android.os.UserManager;
import android.util.AttributeSet;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Log;
import android.util.SparseArray;
import android.util.SparseArray;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View;
@@ -122,7 +126,7 @@ public abstract class BaseAllAppsContainerView<T extends Context & ActivityConte
    private SearchRecyclerView mSearchRecyclerView;
    private SearchRecyclerView mSearchRecyclerView;


    protected FloatingHeaderView mHeader;
    protected FloatingHeaderView mHeader;
    private View mBottomSheetBackground;
    protected View mBottomSheetBackground;
    private View mBottomSheetHandleArea;
    private View mBottomSheetHandleArea;
    @Nullable private View mSearchBarProtection;
    @Nullable private View mSearchBarProtection;


@@ -135,8 +139,12 @@ public abstract class BaseAllAppsContainerView<T extends Context & ActivityConte
    private final int mScrimColor;
    private final int mScrimColor;
    private final int mHeaderProtectionColor;
    private final int mHeaderProtectionColor;
    protected final float mHeaderThreshold;
    protected final float mHeaderThreshold;
    private final Path mTmpPath = new Path();
    private final RectF mTmpRectF = new RectF();
    private float[] mBottomSheetCornerRadii;
    private ScrimView mScrimView;
    private ScrimView mScrimView;
    private int mHeaderColor;
    private int mHeaderColor;
    private int mBottomSheetBackgroundColor;
    private int mTabsProtectionAlpha;
    private int mTabsProtectionAlpha;


    protected BaseAllAppsContainerView(Context context, AttributeSet attrs, int defStyleAttr) {
    protected BaseAllAppsContainerView(Context context, AttributeSet attrs, int defStyleAttr) {
@@ -237,6 +245,9 @@ public abstract class BaseAllAppsContainerView<T extends Context & ActivityConte


    protected void updateBackground(DeviceProfile deviceProfile) {
    protected void updateBackground(DeviceProfile deviceProfile) {
        mBottomSheetBackground.setVisibility(deviceProfile.isTablet ? View.VISIBLE : View.GONE);
        mBottomSheetBackground.setVisibility(deviceProfile.isTablet ? View.VISIBLE : View.GONE);
        // Note: For tablets, the opaque background and header protection are added in drawOnScrim.
        // For the taskbar entrypoint, the scrim is drawn differently, so a static background is
        // added in TaskbarAllAppsContainerView and header protection is not yet supported.
    }
    }


    private void onAppsUpdated() {
    private void onAppsUpdated() {
@@ -429,9 +440,22 @@ public abstract class BaseAllAppsContainerView<T extends Context & ActivityConte
        rebindAdapters(true /* force */);
        rebindAdapters(true /* force */);


        mBottomSheetBackground = findViewById(R.id.bottom_sheet_background);
        mBottomSheetBackground = findViewById(R.id.bottom_sheet_background);
        updateBackground(mActivityContext.getDeviceProfile());

        mBottomSheetHandleArea = findViewById(R.id.bottom_sheet_handle_area);
        mBottomSheetHandleArea = findViewById(R.id.bottom_sheet_handle_area);
        float cornerRadius = Themes.getDialogCornerRadius(getContext());
        mBottomSheetCornerRadii = new float[]{
                cornerRadius,
                cornerRadius, // Top left radius in px
                cornerRadius,
                cornerRadius, // Top right radius in px
                0,
                0, // Bottom right
                0,
                0 // Bottom left
        };
        final TypedValue value = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.colorBackground, value, true);
        mBottomSheetBackgroundColor = value.data;
        updateBackground(mActivityContext.getDeviceProfile());
    }
    }


    @Override
    @Override
@@ -744,6 +768,20 @@ public abstract class BaseAllAppsContainerView<T extends Context & ActivityConte


    @Override
    @Override
    public void drawOnScrim(Canvas canvas) {
    public void drawOnScrim(Canvas canvas) {
        boolean isTablet = mActivityContext.getDeviceProfile().isTablet;

        // Draw full background panel for tablets.
        if (isTablet) {
            mHeaderPaint.setColor(mBottomSheetBackgroundColor);
            View panel = (View) mBottomSheetBackground;
            float translationY = ((View) panel.getParent()).getTranslationY();
            mTmpRectF.set(panel.getLeft(), panel.getTop() + translationY,
                    panel.getRight(), panel.getBottom());
            mTmpPath.reset();
            mTmpPath.addRoundRect(mTmpRectF, mBottomSheetCornerRadii, Direction.CW);
            canvas.drawPath(mTmpPath, mHeaderPaint);
        }

        if (!mHeader.isHeaderProtectionSupported()) {
        if (!mHeader.isHeaderProtectionSupported()) {
            return;
            return;
        }
        }
@@ -754,14 +792,29 @@ public abstract class BaseAllAppsContainerView<T extends Context & ActivityConte
            mHeaderPaint.setColor(mHeaderColor);
            mHeaderPaint.setColor(mHeaderColor);
            mHeaderPaint.setAlpha((int) (getAlpha() * Color.alpha(mHeaderColor)));
            mHeaderPaint.setAlpha((int) (getAlpha() * Color.alpha(mHeaderColor)));
        }
        }
        if (mHeaderPaint.getColor() != mScrimColor && mHeaderPaint.getColor() != 0) {
        if (mHeaderPaint.getColor() == mScrimColor || mHeaderPaint.getColor() == 0) {
            return;
        }
        int bottom = getHeaderBottom();
        int bottom = getHeaderBottom();
        FloatingHeaderView headerView = getFloatingHeaderView();
        FloatingHeaderView headerView = getFloatingHeaderView();
        if (!mUsingTabs && !FeatureFlags.ENABLE_FLOATING_SEARCH_BAR.get()) {
        if (!mUsingTabs && !FeatureFlags.ENABLE_FLOATING_SEARCH_BAR.get()) {
            // Add protection which is otherwise added when tabs scroll up.
            // Add protection which is otherwise added when tabs scroll up.
            bottom += headerView.getTabsAdditionalPaddingTop();
            bottom += headerView.getTabsAdditionalPaddingTop();
        }
        }
        if (isTablet) {
            // Start adding header protection if search bar or tabs will attach to the top.
            if (!FeatureFlags.ENABLE_FLOATING_SEARCH_BAR.get() || mUsingTabs) {
                View panel = (View) mBottomSheetBackground;
                float translationY = ((View) panel.getParent()).getTranslationY();
                mTmpRectF.set(panel.getLeft(), panel.getTop() + translationY, panel.getRight(),
                        bottom);
                mTmpPath.reset();
                mTmpPath.addRoundRect(mTmpRectF, mBottomSheetCornerRadii, Direction.CW);
                canvas.drawPath(mTmpPath, mHeaderPaint);
            }
        } else {
            canvas.drawRect(0, 0, canvas.getWidth(), bottom, mHeaderPaint);
            canvas.drawRect(0, 0, canvas.getWidth(), bottom, mHeaderPaint);
        }
        int tabsHeight = headerView.getPeripheralProtectionHeight();
        int tabsHeight = headerView.getPeripheralProtectionHeight();
        if (mTabsProtectionAlpha > 0 && tabsHeight != 0) {
        if (mTabsProtectionAlpha > 0 && tabsHeight != 0) {
            if (DEBUG_HEADER_PROTECTION) {
            if (DEBUG_HEADER_PROTECTION) {
@@ -770,8 +823,13 @@ public abstract class BaseAllAppsContainerView<T extends Context & ActivityConte
            } else {
            } else {
                mHeaderPaint.setAlpha((int) (getAlpha() * mTabsProtectionAlpha));
                mHeaderPaint.setAlpha((int) (getAlpha() * mTabsProtectionAlpha));
            }
            }
                canvas.drawRect(0, bottom, canvas.getWidth(), bottom + tabsHeight, mHeaderPaint);
            int left = 0;
            int right = canvas.getWidth();
            if (isTablet) {
                left = mBottomSheetBackground.getLeft();
                right = mBottomSheetBackground.getRight();
            }
            }
            canvas.drawRect(left, bottom, right, bottom + tabsHeight, mHeaderPaint);
        }
        }
    }
    }