Update KQS recents apps and desktop mode launching UX
- Updated recent apps KQS task view - Added a desktop mode KQS task view - Did some code cleanup to support this more cleanly Flag: EXEMPT ENABLE_KEYBOARD_QUICK_SWITCH Fixes: 357512178 Test: Used KQS with and without desktop mode; opened recent apps and desktop mode Change-Id: Ib47a8a7f41b56af1ba9d0cbec65ababf8aad7881
This commit is contained in:
@@ -36,14 +36,12 @@ import android.view.ViewOutlineProvider;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.animation.Interpolator;
|
||||
import android.widget.HorizontalScrollView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.core.content.res.ResourcesCompat;
|
||||
|
||||
import com.android.app.animation.Interpolators;
|
||||
import com.android.internal.jank.Cuj;
|
||||
@@ -52,9 +50,7 @@ import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.anim.AnimatedFloat;
|
||||
import com.android.launcher3.testing.TestLogging;
|
||||
import com.android.launcher3.testing.shared.TestProtocol;
|
||||
import com.android.quickstep.util.DesktopTask;
|
||||
import com.android.quickstep.util.GroupTask;
|
||||
import com.android.systemui.shared.recents.model.Task;
|
||||
import com.android.systemui.shared.system.InteractionJankMonitorWrapper;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -102,9 +98,13 @@ public class KeyboardQuickSwitchView extends ConstraintLayout {
|
||||
private int mTaskViewWidth;
|
||||
private int mTaskViewHeight;
|
||||
private int mSpacing;
|
||||
private int mSmallSpacing;
|
||||
private int mOutlineRadius;
|
||||
private boolean mIsRtl;
|
||||
|
||||
private int mOverviewTaskIndex = -1;
|
||||
private int mDesktopTaskIndex = -1;
|
||||
|
||||
@Nullable private AnimatorSet mOpenAnimation;
|
||||
|
||||
@Nullable private KeyboardQuickSwitchViewController.ViewCallbacks mViewCallbacks;
|
||||
@@ -141,6 +141,8 @@ public class KeyboardQuickSwitchView extends ConstraintLayout {
|
||||
mTaskViewHeight = resources.getDimensionPixelSize(
|
||||
R.dimen.keyboard_quick_switch_taskview_height);
|
||||
mSpacing = resources.getDimensionPixelSize(R.dimen.keyboard_quick_switch_view_spacing);
|
||||
mSmallSpacing = resources.getDimensionPixelSize(
|
||||
R.dimen.keyboard_quick_switch_view_small_spacing);
|
||||
mOutlineRadius = resources.getDimensionPixelSize(R.dimen.keyboard_quick_switch_view_radius);
|
||||
mIsRtl = Utilities.isRtl(resources);
|
||||
}
|
||||
@@ -148,6 +150,7 @@ public class KeyboardQuickSwitchView extends ConstraintLayout {
|
||||
private KeyboardQuickSwitchTaskView createAndAddTaskView(
|
||||
int index,
|
||||
boolean isFinalView,
|
||||
boolean useSmallStartSpacing,
|
||||
@LayoutRes int resId,
|
||||
@NonNull LayoutInflater layoutInflater,
|
||||
@Nullable View previousView) {
|
||||
@@ -156,7 +159,7 @@ public class KeyboardQuickSwitchView extends ConstraintLayout {
|
||||
taskView.setId(View.generateViewId());
|
||||
taskView.setOnClickListener(v -> mViewCallbacks.launchTaskAt(index));
|
||||
|
||||
LayoutParams lp = new LayoutParams(mTaskViewWidth, mTaskViewHeight);
|
||||
LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||
// Create a left-to-right ordering of views (or right-to-left in RTL locales)
|
||||
if (previousView != null) {
|
||||
lp.startToEnd = previousView.getId();
|
||||
@@ -166,7 +169,7 @@ public class KeyboardQuickSwitchView extends ConstraintLayout {
|
||||
lp.topToTop = PARENT_ID;
|
||||
lp.bottomToBottom = PARENT_ID;
|
||||
// Add spacing between views
|
||||
lp.setMarginStart(mSpacing);
|
||||
lp.setMarginStart(useSmallStartSpacing ? mSmallSpacing : mSpacing);
|
||||
if (isFinalView) {
|
||||
// Add spacing to the end of the final view so that scrolling ends with some padding.
|
||||
lp.endToEnd = PARENT_ID;
|
||||
@@ -185,7 +188,8 @@ public class KeyboardQuickSwitchView extends ConstraintLayout {
|
||||
int numHiddenTasks,
|
||||
boolean updateTasks,
|
||||
int currentFocusIndexOverride,
|
||||
@NonNull KeyboardQuickSwitchViewController.ViewCallbacks viewCallbacks) {
|
||||
@NonNull KeyboardQuickSwitchViewController.ViewCallbacks viewCallbacks,
|
||||
boolean useDesktopTaskView) {
|
||||
mViewCallbacks = viewCallbacks;
|
||||
Resources resources = context.getResources();
|
||||
Resources.Theme theme = context.getTheme();
|
||||
@@ -197,57 +201,60 @@ public class KeyboardQuickSwitchView extends ConstraintLayout {
|
||||
GroupTask groupTask = groupTasks.get(i);
|
||||
KeyboardQuickSwitchTaskView currentTaskView = createAndAddTaskView(
|
||||
i,
|
||||
/* isFinalView= */ i == tasksToDisplay - 1 && numHiddenTasks == 0,
|
||||
groupTask instanceof DesktopTask
|
||||
? R.layout.keyboard_quick_switch_textonly_taskview
|
||||
: R.layout.keyboard_quick_switch_taskview,
|
||||
/* isFinalView= */ i == tasksToDisplay - 1
|
||||
&& numHiddenTasks == 0 && !useDesktopTaskView,
|
||||
/* useSmallStartSpacing= */ false,
|
||||
R.layout.keyboard_quick_switch_taskview,
|
||||
layoutInflater,
|
||||
previousTaskView);
|
||||
|
||||
if (groupTask instanceof DesktopTask desktopTask) {
|
||||
HashMap<String, Integer> args = new HashMap<>();
|
||||
args.put("count", desktopTask.tasks.size());
|
||||
final boolean firstTaskIsLeftTopTask =
|
||||
groupTask.mSplitBounds == null
|
||||
|| groupTask.mSplitBounds.leftTopTaskId == groupTask.task1.key.id
|
||||
|| groupTask.task2 == null;
|
||||
currentTaskView.setThumbnails(
|
||||
firstTaskIsLeftTopTask ? groupTask.task1 : groupTask.task2,
|
||||
firstTaskIsLeftTopTask ? groupTask.task2 : groupTask.task1,
|
||||
updateTasks ? mViewCallbacks::updateThumbnailInBackground : null,
|
||||
updateTasks ? mViewCallbacks::updateIconInBackground : null);
|
||||
|
||||
currentTaskView.<ImageView>findViewById(R.id.icon).setImageDrawable(
|
||||
ResourcesCompat.getDrawable(resources, R.drawable.ic_desktop, theme));
|
||||
currentTaskView.<TextView>findViewById(R.id.text).setText(new MessageFormat(
|
||||
resources.getString(R.string.quick_switch_desktop),
|
||||
Locale.getDefault()).format(args));
|
||||
} else {
|
||||
final boolean firstTaskIsLeftTopTask =
|
||||
groupTask.mSplitBounds == null
|
||||
|| groupTask.mSplitBounds.leftTopTaskId == groupTask.task1.key.id;
|
||||
final Task leftTopTask = firstTaskIsLeftTopTask
|
||||
? groupTask.task1 : groupTask.task2;
|
||||
final Task rightBottomTask = firstTaskIsLeftTopTask
|
||||
? groupTask.task2 : groupTask.task1;
|
||||
currentTaskView.setThumbnails(
|
||||
leftTopTask,
|
||||
rightBottomTask,
|
||||
updateTasks ? mViewCallbacks::updateThumbnailInBackground : null,
|
||||
updateTasks ? mViewCallbacks::updateIconInBackground : null);
|
||||
}
|
||||
previousTaskView = currentTaskView;
|
||||
}
|
||||
|
||||
if (numHiddenTasks > 0) {
|
||||
HashMap<String, Integer> args = new HashMap<>();
|
||||
args.put("count", numHiddenTasks);
|
||||
|
||||
mOverviewTaskIndex = getTaskCount();
|
||||
View overviewButton = createAndAddTaskView(
|
||||
MAX_TASKS,
|
||||
/* isFinalView= */ true,
|
||||
R.layout.keyboard_quick_switch_textonly_taskview,
|
||||
mOverviewTaskIndex,
|
||||
/* isFinalView= */ !useDesktopTaskView,
|
||||
/* useSmallStartSpacing= */ false,
|
||||
R.layout.keyboard_quick_switch_overview_taskview,
|
||||
layoutInflater,
|
||||
previousTaskView);
|
||||
|
||||
overviewButton.<ImageView>findViewById(R.id.icon).setImageDrawable(
|
||||
ResourcesCompat.getDrawable(resources, R.drawable.view_carousel, theme));
|
||||
overviewButton.<TextView>findViewById(R.id.text).setText(new MessageFormat(
|
||||
overviewButton.<TextView>findViewById(R.id.large_text).setText(
|
||||
String.format(Locale.getDefault(), "%d", numHiddenTasks));
|
||||
overviewButton.<TextView>findViewById(R.id.small_text).setText(new MessageFormat(
|
||||
resources.getString(R.string.quick_switch_overflow),
|
||||
Locale.getDefault()).format(args));
|
||||
|
||||
previousTaskView = overviewButton;
|
||||
}
|
||||
mDisplayingRecentTasks = !groupTasks.isEmpty();
|
||||
if (useDesktopTaskView) {
|
||||
mDesktopTaskIndex = getTaskCount();
|
||||
View desktopButton = createAndAddTaskView(
|
||||
mDesktopTaskIndex,
|
||||
/* isFinalView= */ true,
|
||||
/* useSmallStartSpacing= */ numHiddenTasks > 0,
|
||||
R.layout.keyboard_quick_switch_desktop_taskview,
|
||||
layoutInflater,
|
||||
previousTaskView);
|
||||
|
||||
desktopButton.<TextView>findViewById(R.id.text).setText(
|
||||
resources.getString(R.string.quick_switch_desktop));
|
||||
}
|
||||
mDisplayingRecentTasks = !groupTasks.isEmpty() || useDesktopTaskView;
|
||||
|
||||
getViewTreeObserver().addOnGlobalLayoutListener(
|
||||
new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@@ -260,6 +267,14 @@ public class KeyboardQuickSwitchView extends ConstraintLayout {
|
||||
});
|
||||
}
|
||||
|
||||
int getOverviewTaskIndex() {
|
||||
return mOverviewTaskIndex;
|
||||
}
|
||||
|
||||
int getDesktopTaskIndex() {
|
||||
return mDesktopTaskIndex;
|
||||
}
|
||||
|
||||
protected Animator getCloseAnimation() {
|
||||
AnimatorSet closeAnimation = new AnimatorSet();
|
||||
|
||||
@@ -370,7 +385,7 @@ public class KeyboardQuickSwitchView extends ConstraintLayout {
|
||||
}
|
||||
});
|
||||
animateFocusMove(-1, Math.min(
|
||||
mContent.getChildCount() - 1,
|
||||
getTaskCount() - 1,
|
||||
currentFocusIndexOverride == -1 ? 1 : currentFocusIndexOverride));
|
||||
displayedContent.setVisibility(VISIBLE);
|
||||
setVisibility(VISIBLE);
|
||||
@@ -577,7 +592,11 @@ public class KeyboardQuickSwitchView extends ConstraintLayout {
|
||||
|
||||
@Nullable
|
||||
protected KeyboardQuickSwitchTaskView getTaskAt(int index) {
|
||||
return !mDisplayingRecentTasks || index < 0 || index >= mContent.getChildCount()
|
||||
return !mDisplayingRecentTasks || index < 0 || index >= getTaskCount()
|
||||
? null : (KeyboardQuickSwitchTaskView) mContent.getChildAt(index);
|
||||
}
|
||||
|
||||
public int getTaskCount() {
|
||||
return mContent.getChildCount();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user