Merge "Draw the workspace scrim in the LauncherRootView instead of DragLayer" into sc-dev am: 12e547f2a8

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/13463974

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Ife11e4b17a1287979ee5612ec651654c405311eb
This commit is contained in:
Adam Cohen authored and Automerger Merge Worker committed 2021-02-10 23:44:21 +00:00
commit d71cbeea99
8 files changed
+165 -58

No files matched your search

@@ -139,7 +139,7 @@ public class StaggeredWorkspaceAnim {
addDepthAnimationForState(launcher, NORMAL, ALPHA_DURATION_MS);
mAnimators.play(launcher.getDragLayer().getScrim().createSysuiMultiplierAnim(0f, 1f)
mAnimators.play(launcher.getDragLayer().getSysUiScrim().createSysuiMultiplierAnim(0f, 1f)
.setDuration(ALPHA_DURATION_MS));
mAnimators.addListener(new AnimatorListenerAdapter() {
@Override
@@ -4,12 +4,14 @@ import static com.android.launcher3.config.FeatureFlags.SEPARATE_RECENTS_ACTIVIT
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.os.Build;
import android.util.AttributeSet;
import android.view.ViewDebug;
import android.view.WindowInsets;
import com.android.launcher3.graphics.SysUiScrim;
import com.android.launcher3.statemanager.StatefulActivity;
import java.util.Collections;
@@ -31,6 +33,8 @@ public class LauncherRootView extends InsettableFrameLayout {
@ViewDebug.ExportedProperty(category = "launcher")
private boolean mForceHideBackArrow;
private SysUiScrim mSysUiScrim;
public LauncherRootView(Context context, AttributeSet attrs) {
super(context, attrs);
mActivity = StatefulActivity.fromContext(context);
@@ -89,6 +93,18 @@ public class LauncherRootView extends InsettableFrameLayout {
}
}
public void setSysUiScrim(SysUiScrim scrim) {
mSysUiScrim = scrim;
}
@Override
protected void dispatchDraw(Canvas canvas) {
if (mSysUiScrim != null) {
mSysUiScrim.draw(canvas);
}
super.dispatchDraw(canvas);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
@@ -119,4 +135,4 @@ public class LauncherRootView extends InsettableFrameLayout {
void onWindowVisibilityChanged(int visibility);
}
}
}
+18 -1
View File
@@ -81,6 +81,7 @@ import com.android.launcher3.folder.FolderIcon;
import com.android.launcher3.folder.PreviewBackground;
import com.android.launcher3.graphics.DragPreviewProvider;
import com.android.launcher3.graphics.PreloadIconDrawable;
import com.android.launcher3.graphics.WorkspaceDragScrim;
import com.android.launcher3.icons.BitmapRenderer;
import com.android.launcher3.logger.LauncherAtom;
import com.android.launcher3.logging.StatsLogManager;
@@ -199,6 +200,9 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
private boolean mStripScreensOnPageStopMoving = false;
private DragPreviewProvider mOutlineProvider = null;
private WorkspaceDragScrim mWorkspaceDragScrim;
private boolean mWorkspaceFadeInAdjacentScreens;
final WallpaperOffsetInterpolator mWallpaperOffset;
@@ -1161,6 +1165,19 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
}
}
public void setWorkspaceDragScrim(WorkspaceDragScrim workspaceDragScrim) {
mWorkspaceDragScrim = workspaceDragScrim;
}
@Override
public void invalidate() {
// The workspace scrim may need to be re-rendered based on the workspace scroll
if (mWorkspaceDragScrim != null) {
mWorkspaceDragScrim.invalidate();
}
super.invalidate();
}
@Override
public void computeScroll() {
super.computeScroll();
@@ -2027,7 +2044,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
}
// Invalidating the scrim will also force this CellLayout
// to be invalidated so that it is highlighted if necessary.
mLauncher.getDragLayer().getScrim().invalidate();
mLauncher.getDragLayer().getWorkspaceDragScrim().invalidate();
}
public CellLayout getCurrentDragOverlappingLayout() {
@@ -32,7 +32,7 @@ import static com.android.launcher3.anim.Interpolators.LINEAR;
import static com.android.launcher3.anim.Interpolators.ZOOM_OUT;
import static com.android.launcher3.anim.PropertySetter.NO_ANIM_PROPERTY_SETTER;
import static com.android.launcher3.graphics.Scrim.SCRIM_PROGRESS;
import static com.android.launcher3.graphics.WorkspaceAndHotseatScrim.SYSUI_PROGRESS;
import static com.android.launcher3.graphics.SysUiScrim.SYSUI_PROGRESS;
import static com.android.launcher3.states.StateAnimationConfig.ANIM_HOTSEAT_SCALE;
import static com.android.launcher3.states.StateAnimationConfig.ANIM_HOTSEAT_TRANSLATE;
import static com.android.launcher3.states.StateAnimationConfig.ANIM_WORKSPACE_FADE;
@@ -49,7 +49,8 @@ import com.android.launcher3.allapps.AllAppsContainerView;
import com.android.launcher3.anim.PendingAnimation;
import com.android.launcher3.anim.PropertySetter;
import com.android.launcher3.anim.SpringAnimationBuilder;
import com.android.launcher3.graphics.WorkspaceAndHotseatScrim;
import com.android.launcher3.graphics.SysUiScrim;
import com.android.launcher3.graphics.WorkspaceDragScrim;
import com.android.launcher3.states.StateAnimationConfig;
import com.android.launcher3.util.DynamicResource;
import com.android.systemui.plugins.ResourceProvider;
@@ -183,10 +184,12 @@ public class WorkspaceStateTransitionAnimation {
}
public void setScrim(PropertySetter propertySetter, LauncherState state) {
WorkspaceAndHotseatScrim scrim = mLauncher.getDragLayer().getScrim();
propertySetter.setFloat(scrim, SCRIM_PROGRESS, state.getWorkspaceScrimAlpha(mLauncher),
LINEAR);
propertySetter.setFloat(scrim, SYSUI_PROGRESS,
WorkspaceDragScrim workspaceDragScrim = mLauncher.getDragLayer().getWorkspaceDragScrim();
propertySetter.setFloat(workspaceDragScrim, SCRIM_PROGRESS,
state.getWorkspaceScrimAlpha(mLauncher), LINEAR);
SysUiScrim sysUiScrim = mLauncher.getDragLayer().getSysUiScrim();
propertySetter.setFloat(sysUiScrim, SYSUI_PROGRESS,
state.hasFlag(FLAG_HAS_SYS_UI_SCRIM) ? 1 : 0, LINEAR);
}
@@ -41,12 +41,14 @@ import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.CellLayout;
import com.android.launcher3.DropTargetBar;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherRootView;
import com.android.launcher3.R;
import com.android.launcher3.ShortcutAndWidgetContainer;
import com.android.launcher3.Workspace;
import com.android.launcher3.folder.Folder;
import com.android.launcher3.graphics.OverviewScrim;
import com.android.launcher3.graphics.WorkspaceAndHotseatScrim;
import com.android.launcher3.graphics.SysUiScrim;
import com.android.launcher3.graphics.WorkspaceDragScrim;
import com.android.launcher3.keyboard.ViewGroupFocusHelper;
import com.android.launcher3.util.Thunk;
import com.android.launcher3.views.BaseDragLayer;
@@ -82,8 +84,10 @@ public class DragLayer extends BaseDragLayer<Launcher> {
// Related to adjacent page hints
private final ViewGroupFocusHelper mFocusIndicatorHelper;
private final WorkspaceAndHotseatScrim mWorkspaceScrim;
private final OverviewScrim mOverviewScrim;
private WorkspaceDragScrim mWorkspaceDragScrim;
private SysUiScrim mSysUiScrim;
private LauncherRootView mRootView;
/**
* Used to create a new DragLayer from XML.
@@ -99,14 +103,23 @@ public class DragLayer extends BaseDragLayer<Launcher> {
setChildrenDrawingOrderEnabled(true);
mFocusIndicatorHelper = new ViewGroupFocusHelper(this);
mWorkspaceScrim = new WorkspaceAndHotseatScrim(this);
mOverviewScrim = new OverviewScrim(this);
}
public void setup(DragController dragController, Workspace workspace) {
mDragController = dragController;
mWorkspaceScrim.setWorkspace(workspace);
recreateControllers();
mWorkspaceDragScrim = new WorkspaceDragScrim((this));
mWorkspaceDragScrim.setWorkspace(workspace);
// We delegate drawing of the workspace scrim to LauncherRootView (one level up), so as
// to avoid artifacts when translating the entire drag layer in the -1 transition.
mRootView = (LauncherRootView) getParent();
mSysUiScrim = new SysUiScrim(mRootView);
mRootView.setSysUiScrim(mSysUiScrim);
}
@Override
@@ -515,7 +528,7 @@ public class DragLayer extends BaseDragLayer<Launcher> {
@Override
protected void dispatchDraw(Canvas canvas) {
// Draw the background below children.
mWorkspaceScrim.draw(canvas);
mWorkspaceDragScrim.draw(canvas);
mOverviewScrim.updateCurrentScrimmedView(this);
mFocusIndicatorHelper.draw(canvas);
super.dispatchDraw(canvas);
@@ -535,18 +548,22 @@ public class DragLayer extends BaseDragLayer<Launcher> {
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mWorkspaceScrim.setSize(w, h);
mSysUiScrim.setSize(w, h);
}
@Override
public void setInsets(Rect insets) {
super.setInsets(insets);
mWorkspaceScrim.onInsetsChanged(insets, mAllowSysuiScrims);
mSysUiScrim.onInsetsChanged(insets, mAllowSysuiScrims);
mOverviewScrim.onInsetsChanged(insets);
}
public WorkspaceAndHotseatScrim getScrim() {
return mWorkspaceScrim;
public WorkspaceDragScrim getWorkspaceDragScrim() {
return mWorkspaceDragScrim;
}
public SysUiScrim getSysUiScrim() {
return mSysUiScrim;
}
public OverviewScrim getOverviewScrim() {
@@ -34,7 +34,6 @@ import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Region;
import android.graphics.Shader;
import android.graphics.drawable.Drawable;
import android.util.DisplayMetrics;
@@ -44,41 +43,39 @@ import android.view.WindowInsets;
import androidx.core.graphics.ColorUtils;
import com.android.launcher3.CellLayout;
import com.android.launcher3.R;
import com.android.launcher3.ResourceUtils;
import com.android.launcher3.Utilities;
import com.android.launcher3.Workspace;
import com.android.launcher3.uioverrides.WallpaperColorInfo;
import com.android.launcher3.util.Themes;
/**
* View scrim which draws behind hotseat and workspace
*/
public class WorkspaceAndHotseatScrim extends Scrim {
public class SysUiScrim extends Scrim {
public static final FloatProperty<WorkspaceAndHotseatScrim> SYSUI_PROGRESS =
new FloatProperty<WorkspaceAndHotseatScrim>("sysUiProgress") {
public static final FloatProperty<SysUiScrim> SYSUI_PROGRESS =
new FloatProperty<SysUiScrim>("sysUiProgress") {
@Override
public Float get(WorkspaceAndHotseatScrim scrim) {
public Float get(SysUiScrim scrim) {
return scrim.mSysUiProgress;
}
@Override
public void setValue(WorkspaceAndHotseatScrim scrim, float value) {
public void setValue(SysUiScrim scrim, float value) {
scrim.setSysUiProgress(value);
}
};
private static final FloatProperty<WorkspaceAndHotseatScrim> SYSUI_ANIM_MULTIPLIER =
new FloatProperty<WorkspaceAndHotseatScrim>("sysUiAnimMultiplier") {
private static final FloatProperty<SysUiScrim> SYSUI_ANIM_MULTIPLIER =
new FloatProperty<SysUiScrim>("sysUiAnimMultiplier") {
@Override
public Float get(WorkspaceAndHotseatScrim scrim) {
public Float get(SysUiScrim scrim) {
return scrim.mSysUiAnimMultiplier;
}
@Override
public void setValue(WorkspaceAndHotseatScrim scrim, float value) {
public void setValue(SysUiScrim scrim, float value) {
scrim.mSysUiAnimMultiplier = value;
scrim.reapplySysUiAlpha();
}
@@ -108,10 +105,6 @@ public class WorkspaceAndHotseatScrim extends Scrim {
private static final int ALPHA_MASK_BITMAP_DP = 200;
private static final int ALPHA_MASK_WIDTH_DP = 2;
private final Rect mHighlightRect = new Rect();
private Workspace mWorkspace;
private boolean mDrawTopScrim, mDrawBottomScrim;
private final RectF mFinalMaskRect = new RectF();
@@ -127,9 +120,8 @@ public class WorkspaceAndHotseatScrim extends Scrim {
private boolean mAnimateScrimOnNextDraw = false;
private float mSysUiAnimMultiplier = 1;
public WorkspaceAndHotseatScrim(View view) {
public SysUiScrim(View view) {
super(view);
mMaskHeight = ResourceUtils.pxFromDp(ALPHA_MASK_BITMAP_DP,
view.getResources().getDisplayMetrics());
mTopScrim = Themes.getAttrDrawable(view.getContext(), R.attr.workspaceStatusBarScrim);
@@ -139,28 +131,10 @@ public class WorkspaceAndHotseatScrim extends Scrim {
onExtractedColorsChanged(mWallpaperColorInfo);
}
public void setWorkspace(Workspace workspace) {
mWorkspace = workspace;
}
/**
* Draw the top and bottom scrims
*/
public void draw(Canvas canvas) {
// Draw the background below children.
if (mScrimAlpha > 0) {
// Update the scroll position first to ensure scrim cutout is in the right place.
mWorkspace.computeScrollWithoutInvalidation();
CellLayout currCellLayout = mWorkspace.getCurrentDragOverlappingLayout();
canvas.save();
if (currCellLayout != null && currCellLayout != mLauncher.getHotseat()) {
// Cut a hole in the darkening scrim on the page that should be highlighted, if any.
mLauncher.getDragLayer()
.getDescendantRectRelativeToSelf(currCellLayout, mHighlightRect);
canvas.clipRect(mHighlightRect, Region.Op.DIFFERENCE);
}
super.draw(canvas);
canvas.restore();
}
if (!mHideSysUiScrim) {
if (mSysUiProgress <= 0) {
mAnimateScrimOnNextDraw = false;
@@ -247,6 +221,11 @@ public class WorkspaceAndHotseatScrim extends Scrim {
super.onExtractedColorsChanged(wallpaperColorInfo);
}
/**
* Set the width and height of the view being scrimmed
* @param w
* @param h
*/
public void setSize(int w, int h) {
if (mTopScrim != null) {
mTopScrim.setBounds(0, 0, w, h);
@@ -0,0 +1,74 @@
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.launcher3.graphics;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.Region;
import android.view.View;
import com.android.launcher3.CellLayout;
import com.android.launcher3.Workspace;
/**
* Scrim drawn during SpringLoaded State (ie. Drag and Drop). Darkens the workspace except for
* the focused CellLayout.
*/
public class WorkspaceDragScrim extends Scrim {
private final Rect mHighlightRect = new Rect();
private Workspace mWorkspace;
public WorkspaceDragScrim(View view) {
super(view);
onExtractedColorsChanged(mWallpaperColorInfo);
}
/**
* Set the workspace that this scrim is acting on
* @param workspace
*/
public void setWorkspace(Workspace workspace) {
mWorkspace = workspace;
mWorkspace.setWorkspaceDragScrim(this);
}
/**
* Cut out the focused paged of the Workspace and then draw the scrim
* @param canvas
*/
public void draw(Canvas canvas) {
// Draw the background below children.
if (mScrimAlpha > 0) {
// Update the scroll position first to ensure scrim cutout is in the right place.
mWorkspace.computeScrollWithoutInvalidation();
CellLayout currCellLayout = mWorkspace.getCurrentDragOverlappingLayout();
canvas.save();
if (currCellLayout != null && currCellLayout != mLauncher.getHotseat()) {
// Cut a hole in the darkening scrim on the page that should be highlighted, if any.
mLauncher.getDragLayer()
.getDescendantRectRelativeToSelf(currCellLayout, mHighlightRect);
canvas.clipRect(mHighlightRect, Region.Op.DIFFERENCE);
}
super.draw(canvas);
canvas.restore();
}
}
}
@@ -543,7 +543,8 @@ public abstract class AbstractStateChangeTouchController
// case the user started interacting with it before the animation finished.
mLauncher.getStateManager().goToState(targetState, false /* animated */);
}
mLauncher.getDragLayer().getScrim().createSysuiMultiplierAnim(1f).setDuration(0).start();
mLauncher.getDragLayer().getSysUiScrim().createSysuiMultiplierAnim(
1f).setDuration(0).start();
}
private void logReachedState(LauncherState targetState) {