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
This commit is contained in:
Samuel Fufa 2021-05-17 09:23:04 -05:00
parent ca65ca4538
commit 0a709374ae
5 changed files with 53 additions and 36 deletions

View File

@ -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"

View File

@ -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>

View File

@ -720,7 +720,7 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
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 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
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();
}
}

View File

@ -17,6 +17,9 @@ package com.android.launcher3.allapps;
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 @@ public class FloatingHeaderView extends LinearLayout implements
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 @@ public class FloatingHeaderView extends LinearLayout implements
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 @@ public class FloatingHeaderView extends LinearLayout implements
}
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 @@ public class FloatingHeaderView extends LinearLayout implements
}
} else {
mHeaderCollapsed = false;
invalidate();
}
mTranslationY = currentScrollY;
} else if (!mHeaderCollapsed) {
@ -274,10 +281,28 @@ public class FloatingHeaderView extends LinearLayout implements
} 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);

View File

@ -29,14 +29,12 @@ import androidx.annotation.Nullable;
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 class PersonalWorkSlidingTabStrip extends LinearLayout implements PageInd
public PersonalWorkSlidingTabStrip(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
setOrientation(HORIZONTAL);
setWillNotDraw(false);
mSelectedIndicatorHeight =
@ -64,11 +61,6 @@ public class PersonalWorkSlidingTabStrip extends LinearLayout implements PageInd
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 @@ public class PersonalWorkSlidingTabStrip extends LinearLayout implements PageInd
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
float y = getHeight() - mDividerPaint.getStrokeWidth();
canvas.drawRoundRect(mIndicatorLeft, getHeight() - mSelectedIndicatorHeight,
mIndicatorRight, getHeight(), mSelectedIndicatorRadius, mSelectedIndicatorRadius,
mSelectedIndicatorPaint);