diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java index a22398d7e3..89e54b8863 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java @@ -156,14 +156,7 @@ public class TaskbarActivityContext extends BaseTaskbarContext { updateIconSize(resources); mTaskbarHeightForIme = resources.getDimensionPixelSize(R.dimen.taskbar_ime_size); - // 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); - + // Get display and corners first, as views might use them in constructor. Display display = windowContext.getDisplay(); Context c = display.getDisplayId() == Display.DEFAULT_DISPLAY ? windowContext.getApplicationContext() @@ -172,6 +165,14 @@ public class TaskbarActivityContext extends BaseTaskbarContext { mLeftCorner = display.getRoundedCorner(RoundedCorner.POSITION_BOTTOM_LEFT); 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); // Construct controllers. diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarBackgroundRenderer.kt b/quickstep/src/com/android/launcher3/taskbar/TaskbarBackgroundRenderer.kt new file mode 100644 index 0000000000..1177bdb484 --- /dev/null +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarBackgroundRenderer.kt @@ -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() + } +} diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarDragLayer.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarDragLayer.java index 4a806650a5..089c26d3f9 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarDragLayer.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarDragLayer.java @@ -20,8 +20,6 @@ import static android.view.KeyEvent.KEYCODE_BACK; import android.content.Context; import android.graphics.Canvas; -import android.graphics.Paint; -import android.graphics.Path; import android.util.AttributeSet; import android.view.KeyEvent; import android.view.MotionEvent; @@ -31,7 +29,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.android.launcher3.AbstractFloatingView; -import com.android.launcher3.R; import com.android.launcher3.testing.TestLogging; import com.android.launcher3.testing.TestProtocol; import com.android.launcher3.views.BaseDragLayer; @@ -44,13 +41,11 @@ import com.android.systemui.shared.system.ViewTreeObserverWrapper.OnComputeInset */ public class TaskbarDragLayer extends BaseDragLayer { - private final Paint mTaskbarBackgroundPaint; - private final Path mInvertedLeftCornerPath, mInvertedRightCornerPath; + private final TaskbarBackgroundRenderer mBackgroundRenderer; private final OnComputeInsetsListener mTaskbarInsetsComputer = this::onComputeTaskbarInsets; // Initialized in init. private TaskbarDragLayerController.TaskbarDragLayerCallbacks mControllerCallbacks; - private float mLeftCornerRadius, mRightCornerRadius; private float mTaskbarBackgroundOffset; @@ -70,35 +65,13 @@ public class TaskbarDragLayer extends BaseDragLayer { public TaskbarDragLayer(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, 1 /* alphaChannelCount */); - mTaskbarBackgroundPaint = new Paint(); - mTaskbarBackgroundPaint.setColor(getResources().getColor(R.color.taskbar_background)); - 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(); + mBackgroundRenderer = new TaskbarBackgroundRenderer(mActivity); + mBackgroundRenderer.getPaint().setAlpha(0); } public void init(TaskbarDragLayerController.TaskbarDragLayerCallbacks 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(); } @@ -151,20 +124,8 @@ public class TaskbarDragLayer extends BaseDragLayer { protected void dispatchDraw(Canvas canvas) { float backgroundHeight = mControllerCallbacks.getTaskbarBackgroundHeight() * (1f - mTaskbarBackgroundOffset); - canvas.save(); - canvas.translate(0, canvas.getHeight() - backgroundHeight); - - // 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(); + mBackgroundRenderer.setBackgroundHeight(backgroundHeight); + mBackgroundRenderer.draw(canvas); super.dispatchDraw(canvas); } @@ -173,7 +134,7 @@ public class TaskbarDragLayer extends BaseDragLayer { * @param alpha 0 is fully transparent, 1 is fully opaque. */ protected void setTaskbarBackgroundAlpha(float alpha) { - mTaskbarBackgroundPaint.setAlpha((int) (alpha * 255)); + mBackgroundRenderer.getPaint().setAlpha((int) (alpha * 255)); invalidate(); } diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarScrimView.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarScrimView.java index 94a3307bc3..1d3757fca2 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarScrimView.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarScrimView.java @@ -17,22 +17,19 @@ package com.android.launcher3.taskbar; import android.content.Context; import android.graphics.Canvas; -import android.graphics.Paint; -import android.graphics.Path; import android.util.AttributeSet; 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 * when bubbles is expanded. */ public class TaskbarScrimView extends View { - private final Paint mTaskbarScrimPaint; - private final Path mInvertedLeftCornerPath, mInvertedRightCornerPath; + private final TaskbarBackgroundRenderer mRenderer; private boolean mShowScrim; - private float mLeftCornerRadius, mRightCornerRadius; - private float mBackgroundHeight; public TaskbarScrimView(Context context) { this(context, null); @@ -49,14 +46,9 @@ public class TaskbarScrimView extends View { public TaskbarScrimView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); - - mTaskbarScrimPaint = new Paint(); - mTaskbarScrimPaint.setColor(getResources().getColor(android.R.color.system_neutral1_1000)); - mTaskbarScrimPaint.setFlags(Paint.ANTI_ALIAS_FLAG); - mTaskbarScrimPaint.setStyle(Paint.Style.FILL); - - mInvertedLeftCornerPath = new Path(); - mInvertedRightCornerPath = new Path(); + mRenderer = new TaskbarBackgroundRenderer(ActivityContext.lookupContext(context)); + mRenderer.getPaint().setColor(getResources().getColor( + android.R.color.system_neutral1_1000)); } @Override @@ -64,31 +56,7 @@ public class TaskbarScrimView extends View { super.onDraw(canvas); if (mShowScrim) { - canvas.save(); - 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(); + mRenderer.draw(canvas); } } @@ -98,32 +66,7 @@ public class TaskbarScrimView extends View { */ protected void setScrimAlpha(float alpha) { mShowScrim = alpha > 0f; - mTaskbarScrimPaint.setAlpha((int) (alpha * 255)); + mRenderer.getPaint().setAlpha((int) (alpha * 255)); 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(); - } - } } diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarScrimViewController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarScrimViewController.java index 02bbae4d53..58ace17787 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarScrimViewController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarScrimViewController.java @@ -49,9 +49,6 @@ public class TaskbarScrimViewController implements TaskbarControllers.LoggableTa public TaskbarScrimViewController(TaskbarActivityContext activity, TaskbarScrimView scrimView) { mActivity = activity; mScrimView = scrimView; - mScrimView.setCornerSizes(mActivity.getLeftCornerRadius(), - mActivity.getRightCornerRadius()); - mScrimView.setBackgroundHeight(mActivity.getDeviceProfile().taskbarSize); } /**