Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2da9bd5e authored by Tony Wickham's avatar Tony Wickham Committed by Automerger Merge Worker
Browse files

Merge "Move Taskbar background drawing to TaskbarBackgroundRenderer" into...

Merge "Move Taskbar background drawing to TaskbarBackgroundRenderer" into tm-dev am: 8bb0bdc4 am: 4e2dcdac

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



Change-Id: I85be082cbf2daeb5bae9835e2dd6e2d1ea58269b
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 1c1d2b5d 4e2dcdac
Loading
Loading
Loading
Loading
+9 −8
Original line number Diff line number Diff line
@@ -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.
+75 −0
Original line number Diff line number Diff line
/*
 * 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()
    }
}
+6 −45
Original line number Diff line number Diff line
@@ -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<TaskbarActivityContext> {

    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<TaskbarActivityContext> {
    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<TaskbarActivityContext> {
    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<TaskbarActivityContext> {
     * @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();
    }

+8 −65
Original line number Diff line number Diff line
@@ -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();
        }
    }
}
+0 −3
Original line number Diff line number Diff line
@@ -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);
    }

    /**