Merge "Move Taskbar background drawing to TaskbarBackgroundRenderer" into tm-dev am: 8bb0bdc42b
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/17766315 Change-Id: I23c67fd34b8726a5620e730e4bdeb0cace18dc8c Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -156,14 +156,7 @@ public class TaskbarActivityContext extends BaseTaskbarContext {
|
|||||||
updateIconSize(resources);
|
updateIconSize(resources);
|
||||||
mTaskbarHeightForIme = resources.getDimensionPixelSize(R.dimen.taskbar_ime_size);
|
mTaskbarHeightForIme = resources.getDimensionPixelSize(R.dimen.taskbar_ime_size);
|
||||||
|
|
||||||
// Inflate views.
|
// Get display and corners first, as views might use them in constructor.
|
||||||
mDragLayer = (TaskbarDragLayer) mLayoutInflater.inflate(
|
|
||||||
R.layout.taskbar, null, false);
|
|
||||||
TaskbarView taskbarView = mDragLayer.findViewById(R.id.taskbar_view);
|
|
||||||
TaskbarScrimView taskbarScrimView = mDragLayer.findViewById(R.id.taskbar_scrim);
|
|
||||||
FrameLayout navButtonsView = mDragLayer.findViewById(R.id.navbuttons_view);
|
|
||||||
StashedHandleView stashedHandleView = mDragLayer.findViewById(R.id.stashed_handle);
|
|
||||||
|
|
||||||
Display display = windowContext.getDisplay();
|
Display display = windowContext.getDisplay();
|
||||||
Context c = display.getDisplayId() == Display.DEFAULT_DISPLAY
|
Context c = display.getDisplayId() == Display.DEFAULT_DISPLAY
|
||||||
? windowContext.getApplicationContext()
|
? windowContext.getApplicationContext()
|
||||||
@@ -172,6 +165,14 @@ public class TaskbarActivityContext extends BaseTaskbarContext {
|
|||||||
mLeftCorner = display.getRoundedCorner(RoundedCorner.POSITION_BOTTOM_LEFT);
|
mLeftCorner = display.getRoundedCorner(RoundedCorner.POSITION_BOTTOM_LEFT);
|
||||||
mRightCorner = display.getRoundedCorner(RoundedCorner.POSITION_BOTTOM_RIGHT);
|
mRightCorner = display.getRoundedCorner(RoundedCorner.POSITION_BOTTOM_RIGHT);
|
||||||
|
|
||||||
|
// Inflate views.
|
||||||
|
mDragLayer = (TaskbarDragLayer) mLayoutInflater.inflate(
|
||||||
|
R.layout.taskbar, null, false);
|
||||||
|
TaskbarView taskbarView = mDragLayer.findViewById(R.id.taskbar_view);
|
||||||
|
TaskbarScrimView taskbarScrimView = mDragLayer.findViewById(R.id.taskbar_scrim);
|
||||||
|
FrameLayout navButtonsView = mDragLayer.findViewById(R.id.navbuttons_view);
|
||||||
|
StashedHandleView stashedHandleView = mDragLayer.findViewById(R.id.stashed_handle);
|
||||||
|
|
||||||
mAccessibilityDelegate = new TaskbarShortcutMenuAccessibilityDelegate(this);
|
mAccessibilityDelegate = new TaskbarShortcutMenuAccessibilityDelegate(this);
|
||||||
|
|
||||||
// Construct controllers.
|
// Construct controllers.
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 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.taskbar
|
||||||
|
|
||||||
|
import android.graphics.Canvas
|
||||||
|
import android.graphics.Paint
|
||||||
|
import android.graphics.Path
|
||||||
|
import com.android.launcher3.R
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helps draw the taskbar background, made up of a rectangle plus two inverted rounded corners.
|
||||||
|
*/
|
||||||
|
class TaskbarBackgroundRenderer(context: TaskbarActivityContext) {
|
||||||
|
|
||||||
|
val paint: Paint = Paint()
|
||||||
|
var backgroundHeight = context.deviceProfile.taskbarSize.toFloat()
|
||||||
|
|
||||||
|
private val leftCornerRadius = context.leftCornerRadius.toFloat()
|
||||||
|
private val rightCornerRadius = context.rightCornerRadius.toFloat()
|
||||||
|
private val invertedLeftCornerPath: Path = Path()
|
||||||
|
private val invertedRightCornerPath: Path = Path()
|
||||||
|
|
||||||
|
init {
|
||||||
|
paint.color = context.getColor(R.color.taskbar_background)
|
||||||
|
paint.flags = Paint.ANTI_ALIAS_FLAG
|
||||||
|
paint.style = Paint.Style.FILL
|
||||||
|
|
||||||
|
// Create the paths for the inverted rounded corners above the taskbar. Start with a filled
|
||||||
|
// square, and then subtract out a circle from the appropriate corner.
|
||||||
|
val square = Path()
|
||||||
|
square.addRect(0f, 0f, leftCornerRadius, leftCornerRadius, Path.Direction.CW)
|
||||||
|
val circle = Path()
|
||||||
|
circle.addCircle(leftCornerRadius, 0f, leftCornerRadius, Path.Direction.CW)
|
||||||
|
invertedLeftCornerPath.op(square, circle, Path.Op.DIFFERENCE)
|
||||||
|
square.reset()
|
||||||
|
square.addRect(0f, 0f, rightCornerRadius, rightCornerRadius, Path.Direction.CW)
|
||||||
|
circle.reset()
|
||||||
|
circle.addCircle(0f, 0f, rightCornerRadius, Path.Direction.CW)
|
||||||
|
invertedRightCornerPath.op(square, circle, Path.Op.DIFFERENCE)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws the background with the given paint and height, on the provided canvas.
|
||||||
|
*/
|
||||||
|
fun draw(canvas: Canvas) {
|
||||||
|
canvas.save()
|
||||||
|
canvas.translate(0f, canvas.height - backgroundHeight)
|
||||||
|
|
||||||
|
// Draw the background behind taskbar content.
|
||||||
|
canvas.drawRect(0f, 0f, canvas.width.toFloat(), backgroundHeight, paint)
|
||||||
|
|
||||||
|
// Draw the inverted rounded corners above the taskbar.
|
||||||
|
canvas.translate(0f, -leftCornerRadius)
|
||||||
|
canvas.drawPath(invertedLeftCornerPath, paint)
|
||||||
|
canvas.translate(0f, leftCornerRadius)
|
||||||
|
canvas.translate(canvas.width - rightCornerRadius, -rightCornerRadius)
|
||||||
|
canvas.drawPath(invertedRightCornerPath, paint)
|
||||||
|
|
||||||
|
canvas.restore()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,8 +20,6 @@ import static android.view.KeyEvent.KEYCODE_BACK;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Paint;
|
|
||||||
import android.graphics.Path;
|
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
@@ -31,7 +29,6 @@ import androidx.annotation.NonNull;
|
|||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import com.android.launcher3.AbstractFloatingView;
|
import com.android.launcher3.AbstractFloatingView;
|
||||||
import com.android.launcher3.R;
|
|
||||||
import com.android.launcher3.testing.TestLogging;
|
import com.android.launcher3.testing.TestLogging;
|
||||||
import com.android.launcher3.testing.TestProtocol;
|
import com.android.launcher3.testing.TestProtocol;
|
||||||
import com.android.launcher3.views.BaseDragLayer;
|
import com.android.launcher3.views.BaseDragLayer;
|
||||||
@@ -44,13 +41,11 @@ import com.android.systemui.shared.system.ViewTreeObserverWrapper.OnComputeInset
|
|||||||
*/
|
*/
|
||||||
public class TaskbarDragLayer extends BaseDragLayer<TaskbarActivityContext> {
|
public class TaskbarDragLayer extends BaseDragLayer<TaskbarActivityContext> {
|
||||||
|
|
||||||
private final Paint mTaskbarBackgroundPaint;
|
private final TaskbarBackgroundRenderer mBackgroundRenderer;
|
||||||
private final Path mInvertedLeftCornerPath, mInvertedRightCornerPath;
|
|
||||||
private final OnComputeInsetsListener mTaskbarInsetsComputer = this::onComputeTaskbarInsets;
|
private final OnComputeInsetsListener mTaskbarInsetsComputer = this::onComputeTaskbarInsets;
|
||||||
|
|
||||||
// Initialized in init.
|
// Initialized in init.
|
||||||
private TaskbarDragLayerController.TaskbarDragLayerCallbacks mControllerCallbacks;
|
private TaskbarDragLayerController.TaskbarDragLayerCallbacks mControllerCallbacks;
|
||||||
private float mLeftCornerRadius, mRightCornerRadius;
|
|
||||||
|
|
||||||
private float mTaskbarBackgroundOffset;
|
private float mTaskbarBackgroundOffset;
|
||||||
|
|
||||||
@@ -70,35 +65,13 @@ public class TaskbarDragLayer extends BaseDragLayer<TaskbarActivityContext> {
|
|||||||
public TaskbarDragLayer(@NonNull Context context, @Nullable AttributeSet attrs,
|
public TaskbarDragLayer(@NonNull Context context, @Nullable AttributeSet attrs,
|
||||||
int defStyleAttr, int defStyleRes) {
|
int defStyleAttr, int defStyleRes) {
|
||||||
super(context, attrs, 1 /* alphaChannelCount */);
|
super(context, attrs, 1 /* alphaChannelCount */);
|
||||||
mTaskbarBackgroundPaint = new Paint();
|
mBackgroundRenderer = new TaskbarBackgroundRenderer(mActivity);
|
||||||
mTaskbarBackgroundPaint.setColor(getResources().getColor(R.color.taskbar_background));
|
mBackgroundRenderer.getPaint().setAlpha(0);
|
||||||
mTaskbarBackgroundPaint.setAlpha(0);
|
|
||||||
mTaskbarBackgroundPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
|
|
||||||
mTaskbarBackgroundPaint.setStyle(Paint.Style.FILL);
|
|
||||||
|
|
||||||
// Will be set in init(), but this ensures they are always non-null.
|
|
||||||
mInvertedLeftCornerPath = new Path();
|
|
||||||
mInvertedRightCornerPath = new Path();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(TaskbarDragLayerController.TaskbarDragLayerCallbacks callbacks) {
|
public void init(TaskbarDragLayerController.TaskbarDragLayerCallbacks callbacks) {
|
||||||
mControllerCallbacks = callbacks;
|
mControllerCallbacks = callbacks;
|
||||||
|
|
||||||
// Create the paths for the inverted rounded corners above the taskbar. Start with a filled
|
|
||||||
// square, and then subtracting out a circle from the appropriate corner.
|
|
||||||
mLeftCornerRadius = mActivity.getLeftCornerRadius();
|
|
||||||
mRightCornerRadius = mActivity.getRightCornerRadius();
|
|
||||||
Path square = new Path();
|
|
||||||
square.addRect(0, 0, mLeftCornerRadius, mLeftCornerRadius, Path.Direction.CW);
|
|
||||||
Path circle = new Path();
|
|
||||||
circle.addCircle(mLeftCornerRadius, 0, mLeftCornerRadius, Path.Direction.CW);
|
|
||||||
mInvertedLeftCornerPath.op(square, circle, Path.Op.DIFFERENCE);
|
|
||||||
square.reset();
|
|
||||||
square.addRect(0, 0, mRightCornerRadius, mRightCornerRadius, Path.Direction.CW);
|
|
||||||
circle.reset();
|
|
||||||
circle.addCircle(0, 0, mRightCornerRadius, Path.Direction.CW);
|
|
||||||
mInvertedRightCornerPath.op(square, circle, Path.Op.DIFFERENCE);
|
|
||||||
|
|
||||||
recreateControllers();
|
recreateControllers();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,20 +124,8 @@ public class TaskbarDragLayer extends BaseDragLayer<TaskbarActivityContext> {
|
|||||||
protected void dispatchDraw(Canvas canvas) {
|
protected void dispatchDraw(Canvas canvas) {
|
||||||
float backgroundHeight = mControllerCallbacks.getTaskbarBackgroundHeight()
|
float backgroundHeight = mControllerCallbacks.getTaskbarBackgroundHeight()
|
||||||
* (1f - mTaskbarBackgroundOffset);
|
* (1f - mTaskbarBackgroundOffset);
|
||||||
canvas.save();
|
mBackgroundRenderer.setBackgroundHeight(backgroundHeight);
|
||||||
canvas.translate(0, canvas.getHeight() - backgroundHeight);
|
mBackgroundRenderer.draw(canvas);
|
||||||
|
|
||||||
// Draw the background behind taskbar content.
|
|
||||||
canvas.drawRect(0, 0, canvas.getWidth(), backgroundHeight, mTaskbarBackgroundPaint);
|
|
||||||
|
|
||||||
// Draw the inverted rounded corners above the taskbar.
|
|
||||||
canvas.translate(0, -mLeftCornerRadius);
|
|
||||||
canvas.drawPath(mInvertedLeftCornerPath, mTaskbarBackgroundPaint);
|
|
||||||
canvas.translate(0, mLeftCornerRadius);
|
|
||||||
canvas.translate(canvas.getWidth() - mRightCornerRadius, -mRightCornerRadius);
|
|
||||||
canvas.drawPath(mInvertedRightCornerPath, mTaskbarBackgroundPaint);
|
|
||||||
|
|
||||||
canvas.restore();
|
|
||||||
super.dispatchDraw(canvas);
|
super.dispatchDraw(canvas);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,7 +134,7 @@ public class TaskbarDragLayer extends BaseDragLayer<TaskbarActivityContext> {
|
|||||||
* @param alpha 0 is fully transparent, 1 is fully opaque.
|
* @param alpha 0 is fully transparent, 1 is fully opaque.
|
||||||
*/
|
*/
|
||||||
protected void setTaskbarBackgroundAlpha(float alpha) {
|
protected void setTaskbarBackgroundAlpha(float alpha) {
|
||||||
mTaskbarBackgroundPaint.setAlpha((int) (alpha * 255));
|
mBackgroundRenderer.getPaint().setAlpha((int) (alpha * 255));
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,22 +17,19 @@ package com.android.launcher3.taskbar;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Paint;
|
|
||||||
import android.graphics.Path;
|
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
|
import com.android.launcher3.views.ActivityContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* View that handles scrimming the taskbar and the inverted corners it draws. The scrim is used
|
* View that handles scrimming the taskbar and the inverted corners it draws. The scrim is used
|
||||||
* when bubbles is expanded.
|
* when bubbles is expanded.
|
||||||
*/
|
*/
|
||||||
public class TaskbarScrimView extends View {
|
public class TaskbarScrimView extends View {
|
||||||
private final Paint mTaskbarScrimPaint;
|
private final TaskbarBackgroundRenderer mRenderer;
|
||||||
private final Path mInvertedLeftCornerPath, mInvertedRightCornerPath;
|
|
||||||
|
|
||||||
private boolean mShowScrim;
|
private boolean mShowScrim;
|
||||||
private float mLeftCornerRadius, mRightCornerRadius;
|
|
||||||
private float mBackgroundHeight;
|
|
||||||
|
|
||||||
public TaskbarScrimView(Context context) {
|
public TaskbarScrimView(Context context) {
|
||||||
this(context, null);
|
this(context, null);
|
||||||
@@ -49,14 +46,9 @@ public class TaskbarScrimView extends View {
|
|||||||
public TaskbarScrimView(Context context, AttributeSet attrs, int defStyleAttr,
|
public TaskbarScrimView(Context context, AttributeSet attrs, int defStyleAttr,
|
||||||
int defStyleRes) {
|
int defStyleRes) {
|
||||||
super(context, attrs, defStyleAttr, defStyleRes);
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
|
mRenderer = new TaskbarBackgroundRenderer(ActivityContext.lookupContext(context));
|
||||||
mTaskbarScrimPaint = new Paint();
|
mRenderer.getPaint().setColor(getResources().getColor(
|
||||||
mTaskbarScrimPaint.setColor(getResources().getColor(android.R.color.system_neutral1_1000));
|
android.R.color.system_neutral1_1000));
|
||||||
mTaskbarScrimPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
|
|
||||||
mTaskbarScrimPaint.setStyle(Paint.Style.FILL);
|
|
||||||
|
|
||||||
mInvertedLeftCornerPath = new Path();
|
|
||||||
mInvertedRightCornerPath = new Path();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -64,31 +56,7 @@ public class TaskbarScrimView extends View {
|
|||||||
super.onDraw(canvas);
|
super.onDraw(canvas);
|
||||||
|
|
||||||
if (mShowScrim) {
|
if (mShowScrim) {
|
||||||
canvas.save();
|
mRenderer.draw(canvas);
|
||||||
canvas.translate(0, canvas.getHeight() - mBackgroundHeight);
|
|
||||||
|
|
||||||
// Scrim the taskbar itself.
|
|
||||||
canvas.drawRect(0, 0, canvas.getWidth(), mBackgroundHeight, mTaskbarScrimPaint);
|
|
||||||
|
|
||||||
// Scrim the inverted rounded corners above the taskbar.
|
|
||||||
canvas.translate(0, -mLeftCornerRadius);
|
|
||||||
canvas.drawPath(mInvertedLeftCornerPath, mTaskbarScrimPaint);
|
|
||||||
canvas.translate(0, mLeftCornerRadius);
|
|
||||||
canvas.translate(canvas.getWidth() - mRightCornerRadius, -mRightCornerRadius);
|
|
||||||
canvas.drawPath(mInvertedRightCornerPath, mTaskbarScrimPaint);
|
|
||||||
|
|
||||||
canvas.restore();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the height of the taskbar background.
|
|
||||||
* @param height the height of the background.
|
|
||||||
*/
|
|
||||||
protected void setBackgroundHeight(float height) {
|
|
||||||
mBackgroundHeight = height;
|
|
||||||
if (mShowScrim) {
|
|
||||||
invalidate();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,32 +66,7 @@ public class TaskbarScrimView extends View {
|
|||||||
*/
|
*/
|
||||||
protected void setScrimAlpha(float alpha) {
|
protected void setScrimAlpha(float alpha) {
|
||||||
mShowScrim = alpha > 0f;
|
mShowScrim = alpha > 0f;
|
||||||
mTaskbarScrimPaint.setAlpha((int) (alpha * 255));
|
mRenderer.getPaint().setAlpha((int) (alpha * 255));
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the radius of the left and right corners above the taskbar.
|
|
||||||
* @param leftCornerRadius the radius of the left corner.
|
|
||||||
* @param rightCornerRadius the radius of the right corner.
|
|
||||||
*/
|
|
||||||
protected void setCornerSizes(float leftCornerRadius, float rightCornerRadius) {
|
|
||||||
mLeftCornerRadius = leftCornerRadius;
|
|
||||||
mRightCornerRadius = rightCornerRadius;
|
|
||||||
|
|
||||||
Path square = new Path();
|
|
||||||
square.addRect(0, 0, mLeftCornerRadius, mLeftCornerRadius, Path.Direction.CW);
|
|
||||||
Path circle = new Path();
|
|
||||||
circle.addCircle(mLeftCornerRadius, 0, mLeftCornerRadius, Path.Direction.CW);
|
|
||||||
mInvertedLeftCornerPath.op(square, circle, Path.Op.DIFFERENCE);
|
|
||||||
square.reset();
|
|
||||||
square.addRect(0, 0, mRightCornerRadius, mRightCornerRadius, Path.Direction.CW);
|
|
||||||
circle.reset();
|
|
||||||
circle.addCircle(0, 0, mRightCornerRadius, Path.Direction.CW);
|
|
||||||
mInvertedRightCornerPath.op(square, circle, Path.Op.DIFFERENCE);
|
|
||||||
|
|
||||||
if (mShowScrim) {
|
|
||||||
invalidate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,9 +49,6 @@ public class TaskbarScrimViewController implements TaskbarControllers.LoggableTa
|
|||||||
public TaskbarScrimViewController(TaskbarActivityContext activity, TaskbarScrimView scrimView) {
|
public TaskbarScrimViewController(TaskbarActivityContext activity, TaskbarScrimView scrimView) {
|
||||||
mActivity = activity;
|
mActivity = activity;
|
||||||
mScrimView = scrimView;
|
mScrimView = scrimView;
|
||||||
mScrimView.setCornerSizes(mActivity.getLeftCornerRadius(),
|
|
||||||
mActivity.getRightCornerRadius());
|
|
||||||
mScrimView.setBackgroundHeight(mActivity.getDeviceProfile().taskbarSize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user