From dba7cbae1adfde615060598a55b5ee0edfedef9f Mon Sep 17 00:00:00 2001 From: Schneider Victor-tulias Date: Wed, 13 Mar 2024 14:04:02 -0400 Subject: [PATCH] Update KQS task view layouts to new specs The small size of the screenshots and make text look odd. Implementing new UI specs to improve this. - Updated icon position and size - Added some blur to the thumbnail Flag: LEGACY ENABLE_KEYBOARD_QUICK_SWITCH ENABLED Fixes: 328259439 Fixes: 328692456 Test: opened KQS in dark and light mode Change-Id: I2b20100ddeb562291edf5f0bacbce916002eee45 --- .../keyboard_quick_switch_taskview.xml | 34 ++++++----- .../layout/keyboard_quick_switch_taskview.xml | 34 ++++++----- ...board_quick_switch_taskview_thumbnail.xml} | 0 quickstep/res/values/dimens.xml | 3 +- .../taskbar/BlurredBitmapDrawable.kt | 59 +++++++++++++++++++ .../taskbar/KeyboardQuickSwitchTaskView.java | 39 +++++++----- 6 files changed, 121 insertions(+), 48 deletions(-) rename quickstep/res/layout/{keyboard_quick_switch_thumbnail.xml => keyboard_quick_switch_taskview_thumbnail.xml} (100%) create mode 100644 quickstep/src/com/android/launcher3/taskbar/BlurredBitmapDrawable.kt diff --git a/quickstep/res/layout-land/keyboard_quick_switch_taskview.xml b/quickstep/res/layout-land/keyboard_quick_switch_taskview.xml index 69e157433a..38df75659f 100644 --- a/quickstep/res/layout-land/keyboard_quick_switch_taskview.xml +++ b/quickstep/res/layout-land/keyboard_quick_switch_taskview.xml @@ -36,19 +36,19 @@ app:layout_constraintEnd_toEndOf="parent"> + app:layout_constraintEnd_toStartOf="@id/thumbnail_2"/> + app:layout_constraintTop_toTopOf="@id/thumbnail_1" + app:layout_constraintBottom_toBottomOf="@id/thumbnail_1" + app:layout_constraintStart_toStartOf="@id/thumbnail_1" + app:layout_constraintEnd_toEndOf="@id/thumbnail_1"/> + app:layout_constraintTop_toTopOf="@id/thumbnail_2" + app:layout_constraintBottom_toBottomOf="@id/thumbnail_2" + app:layout_constraintStart_toStartOf="@id/thumbnail_2" + app:layout_constraintEnd_toEndOf="@id/thumbnail_2"/> diff --git a/quickstep/res/layout/keyboard_quick_switch_taskview.xml b/quickstep/res/layout/keyboard_quick_switch_taskview.xml index 6ed3c6ede5..c0ace9a1ae 100644 --- a/quickstep/res/layout/keyboard_quick_switch_taskview.xml +++ b/quickstep/res/layout/keyboard_quick_switch_taskview.xml @@ -36,51 +36,53 @@ app:layout_constraintEnd_toEndOf="parent"> + app:layout_constraintTop_toTopOf="@id/thumbnail_1" + app:layout_constraintBottom_toBottomOf="@id/thumbnail_1" + app:layout_constraintStart_toStartOf="@id/thumbnail_1" + app:layout_constraintEnd_toEndOf="@id/thumbnail_1"/> + app:layout_constraintTop_toTopOf="@id/thumbnail_2" + app:layout_constraintBottom_toBottomOf="@id/thumbnail_2" + app:layout_constraintStart_toStartOf="@id/thumbnail_2" + app:layout_constraintEnd_toEndOf="@id/thumbnail_2"/> diff --git a/quickstep/res/layout/keyboard_quick_switch_thumbnail.xml b/quickstep/res/layout/keyboard_quick_switch_taskview_thumbnail.xml similarity index 100% rename from quickstep/res/layout/keyboard_quick_switch_thumbnail.xml rename to quickstep/res/layout/keyboard_quick_switch_taskview_thumbnail.xml diff --git a/quickstep/res/values/dimens.xml b/quickstep/res/values/dimens.xml index 0e18fb4f6c..fcc2effc8e 100644 --- a/quickstep/res/values/dimens.xml +++ b/quickstep/res/values/dimens.xml @@ -441,8 +441,7 @@ 4dp 104dp 134dp - 28dp - 4dp + 52dp 20dp 56dp 16dp diff --git a/quickstep/src/com/android/launcher3/taskbar/BlurredBitmapDrawable.kt b/quickstep/src/com/android/launcher3/taskbar/BlurredBitmapDrawable.kt new file mode 100644 index 0000000000..8aee1aada2 --- /dev/null +++ b/quickstep/src/com/android/launcher3/taskbar/BlurredBitmapDrawable.kt @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2024 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.Bitmap +import android.graphics.Canvas +import android.graphics.PixelFormat +import android.graphics.RenderEffect +import android.graphics.RenderNode +import android.graphics.Shader +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.DrawableWrapper + +/* BitmapDrawable that can blur the given bitmap. */ +class BlurredBitmapDrawable(bitmap: Bitmap?, radiusX: Float, radiusY: Float) : + DrawableWrapper(BitmapDrawable(bitmap)) { + private val mBlurRenderNode: RenderNode = RenderNode("BlurredConstraintLayoutBlurNode") + + constructor(bitmap: Bitmap?, radius: Float) : this(bitmap, radius, radius) + + init { + mBlurRenderNode.setRenderEffect( + RenderEffect.createBlurEffect(radiusX, radiusY, Shader.TileMode.CLAMP) + ) + } + + override fun draw(canvas: Canvas) { + if (!canvas.isHardwareAccelerated) { + super.draw(canvas) + return + } + mBlurRenderNode.setPosition(bounds) + if (!mBlurRenderNode.hasDisplayList()) { + // Record render node if its display list is not recorded or discarded + // (which happens when it's no longer drawn by anything). + val recordingCanvas = mBlurRenderNode.beginRecording() + super.draw(recordingCanvas) + mBlurRenderNode.endRecording() + } + canvas.drawRenderNode(mBlurRenderNode) + } + + override fun getOpacity(): Int { + return PixelFormat.OPAQUE + } +} diff --git a/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchTaskView.java b/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchTaskView.java index a9d50b9332..5b407f0b5d 100644 --- a/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchTaskView.java +++ b/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchTaskView.java @@ -23,6 +23,7 @@ import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.Canvas; +import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.view.View; import android.widget.ImageView; @@ -47,6 +48,8 @@ import kotlin.Unit; */ public class KeyboardQuickSwitchTaskView extends ConstraintLayout { + private static final float THUMBNAIL_BLUR_RADIUS = 1f; + @ColorInt private final int mBorderColor; @Nullable private BorderAnimator mBorderAnimator; @@ -89,10 +92,10 @@ public class KeyboardQuickSwitchTaskView extends ConstraintLayout { @Override protected void onFinishInflate() { super.onFinishInflate(); - mThumbnailView1 = findViewById(R.id.thumbnail1); - mThumbnailView2 = findViewById(R.id.thumbnail2); - mIcon1 = findViewById(R.id.icon1); - mIcon2 = findViewById(R.id.icon2); + mThumbnailView1 = findViewById(R.id.thumbnail_1); + mThumbnailView2 = findViewById(R.id.thumbnail_2); + mIcon1 = findViewById(R.id.icon_1); + mIcon2 = findViewById(R.id.icon_2); mContent = findViewById(R.id.content); Resources resources = mContext.getResources(); @@ -167,10 +170,7 @@ public class KeyboardQuickSwitchTaskView extends ConstraintLayout { @Nullable ImageView thumbnailView, @Nullable Task task, @Nullable ThumbnailUpdateFunction updateFunction) { - if (thumbnailView == null) { - return; - } - if (task == null) { + if (thumbnailView == null || task == null) { return; } if (updateFunction == null) { @@ -182,19 +182,30 @@ public class KeyboardQuickSwitchTaskView extends ConstraintLayout { } private void applyThumbnail( - @NonNull ImageView thumbnailView, ThumbnailData thumbnailData) { + @NonNull ImageView thumbnailView, + ThumbnailData thumbnailData) { Bitmap bm = thumbnailData == null ? null : thumbnailData.thumbnail; - thumbnailView.setVisibility(VISIBLE); - thumbnailView.setImageBitmap(bm); + if (thumbnailView.getVisibility() != VISIBLE) { + thumbnailView.setVisibility(VISIBLE); + } + thumbnailView.setImageDrawable(new BlurredBitmapDrawable(bm, THUMBNAIL_BLUR_RADIUS)); } private void applyIcon(@Nullable ImageView iconView, @Nullable Task task) { - if (iconView == null || task == null) { + if (iconView == null || task == null || task.icon == null) { return; } - iconView.setVisibility(VISIBLE); - iconView.setImageDrawable(task.icon); + Drawable.ConstantState constantState = task.icon.getConstantState(); + if (constantState == null) { + return; + } + if (iconView.getVisibility() != VISIBLE) { + iconView.setVisibility(VISIBLE); + } + // Use the bitmap directly since the drawable's scale can change + iconView.setImageDrawable( + constantState.newDrawable(getResources(), getContext().getTheme())); } protected interface ThumbnailUpdateFunction {