Fix header protection interactions
Bug: 184711608
Bug: 187790639
Preview: https://drive.google.com/file/d/1MDh71t8DQn0SxTQY3-GZTfIlGECQs_Kn/view?usp=sharing&resourcekey=0-ep9C3q9Meo8cQShVJqnKEw
Test: Manual
Change-Id: I9c939a894adc3e9cd1ed1beb7c11f9c2dd673824
diff --git a/res/layout/all_apps_personal_work_tabs.xml b/res/layout/all_apps_personal_work_tabs.xml
index 31fa5cf..f089f83 100644
--- a/res/layout/all_apps_personal_work_tabs.xml
+++ b/res/layout/all_apps_personal_work_tabs.xml
@@ -1,5 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
+<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (C) 2021 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,8 +14,7 @@
~ limitations under the License.
-->
-<com.android.launcher3.workprofile.PersonalWorkSlidingTabStrip
- xmlns:android="http://schemas.android.com/apk/res/android"
+<com.android.launcher3.workprofile.PersonalWorkSlidingTabStrip xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="@dimen/all_apps_header_pill_height"
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index fd1a29c..451f82b 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -93,6 +93,7 @@
<dimen name="all_apps_background_canvas_height">475dp</dimen>
<dimen name="all_apps_header_pill_height">36dp</dimen>
<dimen name="all_apps_header_pill_corner_radius">18dp</dimen>
+ <dimen name="all_apps_header_pills_width">320dp</dimen>
<dimen name="all_apps_header_tab_height">48dp</dimen>
<dimen name="all_apps_tabs_indicator_height">2dp</dimen>
<dimen name="all_apps_header_top_padding">36dp</dimen>
diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java
index 1620d08..9df95bf 100644
--- a/src/com/android/launcher3/allapps/AllAppsContainerView.java
+++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java
@@ -720,7 +720,7 @@
mHeaderPaint.setColor(mHeaderColor);
mHeaderPaint.setAlpha((int) (getAlpha() * Color.alpha(mHeaderColor)));
if (mHeaderPaint.getColor() != mScrimColor && mHeaderPaint.getColor() != 0) {
- canvas.drawRect(0, 0, getWidth(), mHeaderTopPadding + getTranslationY(),
+ canvas.drawRect(0, 0, getWidth(), mSearchContainer.getTop() + getTranslationY(),
mHeaderPaint);
}
}
@@ -830,10 +830,13 @@
protected void updateHeaderScroll(int scrolledOffset) {
float prog = Math.max(0, Math.min(1, (float) scrolledOffset / mHeaderThreshold));
- int headerColor = ColorUtils.setAlphaComponent(mHeaderProtectionColor, (int) (prog * 255));
+ int viewBG = ColorUtils.blendARGB(mScrimColor, mHeaderProtectionColor, prog);
+ int headerColor = ColorUtils.setAlphaComponent(viewBG,
+ (int) (getSearchView().getAlpha() * 255));
if (headerColor != mHeaderColor) {
mHeaderColor = headerColor;
- getSearchView().setBackgroundColor(mHeaderColor);
+ getSearchView().setBackgroundColor(viewBG);
+ getFloatingHeaderView().setHeaderColor(viewBG);
invalidateHeader();
}
}
diff --git a/src/com/android/launcher3/allapps/FloatingHeaderView.java b/src/com/android/launcher3/allapps/FloatingHeaderView.java
index 733d867..f55ab25 100644
--- a/src/com/android/launcher3/allapps/FloatingHeaderView.java
+++ b/src/com/android/launcher3/allapps/FloatingHeaderView.java
@@ -17,6 +17,9 @@
import android.animation.ValueAnimator;
import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.Rect;
import android.util.ArrayMap;
@@ -50,26 +53,28 @@
private final Rect mClip = new Rect(0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE);
private final ValueAnimator mAnimator = ValueAnimator.ofInt(0, 0);
private final Point mTempOffset = new Point();
- private final RecyclerView.OnScrollListener mOnScrollListener = new RecyclerView.OnScrollListener() {
- @Override
- public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
- }
+ private final Paint mBGPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
+ private final RecyclerView.OnScrollListener mOnScrollListener =
+ new RecyclerView.OnScrollListener() {
+ @Override
+ public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
+ }
- @Override
- public void onScrolled(RecyclerView rv, int dx, int dy) {
- if (rv != mCurrentRV) {
- return;
- }
+ @Override
+ public void onScrolled(RecyclerView rv, int dx, int dy) {
+ if (rv != mCurrentRV) {
+ return;
+ }
- if (mAnimator.isStarted()) {
- mAnimator.cancel();
- }
+ if (mAnimator.isStarted()) {
+ mAnimator.cancel();
+ }
- int current = -mCurrentRV.getCurrentScrollY();
- moved(current);
- applyVerticalMove();
- }
- };
+ int current = -mCurrentRV.getCurrentScrollY();
+ moved(current);
+ applyVerticalMove();
+ }
+ };
private final int mHeaderTopPadding;
@@ -80,9 +85,10 @@
private AllAppsRecyclerView mWorkRV;
private AllAppsRecyclerView mCurrentRV;
private ViewGroup mParent;
- private boolean mHeaderCollapsed;
+ public boolean mHeaderCollapsed;
private int mSnappedScrolledY;
private int mTranslationY;
+ private int mHeaderColor;
private boolean mForwardToRecyclerView;
@@ -219,7 +225,7 @@
}
private AllAppsRecyclerView setupRV(AllAppsRecyclerView old, AllAppsRecyclerView updated) {
- if (old != updated && updated != null ) {
+ if (old != updated && updated != null) {
updated.addOnScrollListener(mOnScrollListener);
}
return updated;
@@ -262,6 +268,7 @@
}
} else {
mHeaderCollapsed = false;
+ invalidate();
}
mTranslationY = currentScrollY;
} else if (!mHeaderCollapsed) {
@@ -274,10 +281,28 @@
} else if (mTranslationY <= -mMaxTranslation) { // hide or stay hidden
mHeaderCollapsed = true;
mSnappedScrolledY = -mMaxTranslation;
+ invalidate();
}
}
}
+ /**
+ * Set current header protection background color
+ */
+ public void setHeaderColor(int color) {
+ mHeaderColor = color;
+ invalidate();
+ }
+
+ @Override
+ protected void dispatchDraw(Canvas canvas) {
+ if (mHeaderCollapsed && mHeaderColor != Color.TRANSPARENT) {
+ mBGPaint.setColor(mHeaderColor);
+ canvas.drawRect(0, 0, getWidth(), getHeight() + mTranslationY, mBGPaint);
+ }
+ super.dispatchDraw(canvas);
+ }
+
protected void applyVerticalMove() {
int uncappedTranslationY = mTranslationY;
mTranslationY = Math.max(mTranslationY, -mMaxTranslation);
diff --git a/src/com/android/launcher3/workprofile/PersonalWorkSlidingTabStrip.java b/src/com/android/launcher3/workprofile/PersonalWorkSlidingTabStrip.java
index 47328d6..8039fd1 100644
--- a/src/com/android/launcher3/workprofile/PersonalWorkSlidingTabStrip.java
+++ b/src/com/android/launcher3/workprofile/PersonalWorkSlidingTabStrip.java
@@ -29,14 +29,12 @@
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.pageindicators.PageIndicator;
-import com.android.launcher3.util.Themes;
/**
* Supports two indicator colors, dedicated for personal and work tabs.
*/
public class PersonalWorkSlidingTabStrip extends LinearLayout implements PageIndicator {
private final Paint mSelectedIndicatorPaint;
- private final Paint mDividerPaint;
private int mSelectedIndicatorHeight;
private final int mSelectedIndicatorRadius;
@@ -52,7 +50,6 @@
public PersonalWorkSlidingTabStrip(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
- setOrientation(HORIZONTAL);
setWillNotDraw(false);
mSelectedIndicatorHeight =
@@ -64,11 +61,6 @@
mSelectedIndicatorPaint = new Paint();
mSelectedIndicatorPaint.setColor(context.getColor(R.color.all_apps_tab_bg));
- mDividerPaint = new Paint();
- mDividerPaint.setColor(Themes.getAttrColor(context, android.R.attr.colorControlHighlight));
- mDividerPaint.setStrokeWidth(
- getResources().getDimensionPixelSize(R.dimen.all_apps_divider_height));
-
mIsRtl = Utilities.isRtl(getResources());
}
@@ -120,8 +112,6 @@
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
-
- float y = getHeight() - mDividerPaint.getStrokeWidth();
canvas.drawRoundRect(mIndicatorLeft, getHeight() - mSelectedIndicatorHeight,
mIndicatorRight, getHeight(), mSelectedIndicatorRadius, mSelectedIndicatorRadius,
mSelectedIndicatorPaint);