Merge "Add a no recent tasks message to the keyboard quick switch view" into udc-dev

This commit is contained in:
TreeHugger Robot
2023-05-16 06:49:52 +00:00
committed by Android (Google) Code Review
8 changed files with 88 additions and 19 deletions

View File

@@ -85,6 +85,8 @@ public class KeyboardQuickSwitchView extends ConstraintLayout {
private final AnimatedFloat mOutlineAnimationProgress = new AnimatedFloat(
this::invalidateOutline);
private boolean mDisplayingRecentTasks;
private View mNoRecentItemsPane;
private HorizontalScrollView mScrollView;
private ConstraintLayout mContent;
@@ -119,6 +121,7 @@ public class KeyboardQuickSwitchView extends ConstraintLayout {
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mNoRecentItemsPane = findViewById(R.id.no_recent_items_pane);
mScrollView = findViewById(R.id.scroll_view);
mContent = findViewById(R.id.content);
@@ -204,10 +207,6 @@ public class KeyboardQuickSwitchView extends ConstraintLayout {
boolean updateTasks,
int currentFocusIndexOverride,
@NonNull KeyboardQuickSwitchViewController.ViewCallbacks viewCallbacks) {
if (groupTasks.isEmpty()) {
// Do not show the quick switch view.
return;
}
mViewCallbacks = viewCallbacks;
Resources resources = context.getResources();
int width = resources.getDimensionPixelSize(R.dimen.keyboard_quick_switch_taskview_width);
@@ -237,6 +236,7 @@ public class KeyboardQuickSwitchView extends ConstraintLayout {
resources.getString(R.string.quick_switch_overflow),
Locale.getDefault()).format(args));
}
mDisplayingRecentTasks = !groupTasks.isEmpty();
getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
@@ -262,13 +262,16 @@ public class KeyboardQuickSwitchView extends ConstraintLayout {
alphaAnimation.setDuration(ALPHA_ANIMATION_DURATION_MS);
closeAnimation.play(alphaAnimation);
View displayedContent = mDisplayingRecentTasks ? mScrollView : mNoRecentItemsPane;
Animator translationYAnimation = ObjectAnimator.ofFloat(
mScrollView, TRANSLATION_Y, 0, -Utilities.dpToPx(CONTENT_START_TRANSLATION_Y_DP));
displayedContent,
TRANSLATION_Y,
0, -Utilities.dpToPx(CONTENT_START_TRANSLATION_Y_DP));
translationYAnimation.setDuration(CONTENT_TRANSLATION_Y_ANIMATION_DURATION_MS);
translationYAnimation.setInterpolator(CLOSE_TRANSLATION_Y_INTERPOLATOR);
closeAnimation.play(translationYAnimation);
Animator contentAlphaAnimation = ObjectAnimator.ofFloat(mScrollView, ALPHA, 1f, 0f);
Animator contentAlphaAnimation = ObjectAnimator.ofFloat(displayedContent, ALPHA, 1f, 0f);
contentAlphaAnimation.setDuration(CONTENT_ALPHA_ANIMATION_DURATION_MS);
closeAnimation.play(contentAlphaAnimation);
@@ -300,19 +303,24 @@ public class KeyboardQuickSwitchView extends ConstraintLayout {
alphaAnimation.setDuration(ALPHA_ANIMATION_DURATION_MS);
mOpenAnimation.play(alphaAnimation);
View displayedContent = mDisplayingRecentTasks ? mScrollView : mNoRecentItemsPane;
Animator translationXAnimation = ObjectAnimator.ofFloat(
mScrollView, TRANSLATION_X, -Utilities.dpToPx(CONTENT_START_TRANSLATION_X_DP), 0);
displayedContent,
TRANSLATION_X,
-Utilities.dpToPx(CONTENT_START_TRANSLATION_X_DP), 0);
translationXAnimation.setDuration(CONTENT_TRANSLATION_X_ANIMATION_DURATION_MS);
translationXAnimation.setInterpolator(OPEN_TRANSLATION_X_INTERPOLATOR);
mOpenAnimation.play(translationXAnimation);
Animator translationYAnimation = ObjectAnimator.ofFloat(
mScrollView, TRANSLATION_Y, -Utilities.dpToPx(CONTENT_START_TRANSLATION_Y_DP), 0);
displayedContent,
TRANSLATION_Y,
-Utilities.dpToPx(CONTENT_START_TRANSLATION_Y_DP), 0);
translationYAnimation.setDuration(CONTENT_TRANSLATION_Y_ANIMATION_DURATION_MS);
translationYAnimation.setInterpolator(OPEN_TRANSLATION_Y_INTERPOLATOR);
mOpenAnimation.play(translationYAnimation);
Animator contentAlphaAnimation = ObjectAnimator.ofFloat(mScrollView, ALPHA, 0f, 1f);
Animator contentAlphaAnimation = ObjectAnimator.ofFloat(displayedContent, ALPHA, 0f, 1f);
contentAlphaAnimation.setStartDelay(CONTENT_ALPHA_ANIMATION_START_DELAY_MS);
contentAlphaAnimation.setDuration(CONTENT_ALPHA_ANIMATION_DURATION_MS);
mOpenAnimation.play(contentAlphaAnimation);
@@ -353,7 +361,7 @@ public class KeyboardQuickSwitchView extends ConstraintLayout {
} else {
animateFocusMove(-1, currentFocusIndexOverride);
}
mScrollView.setVisibility(VISIBLE);
displayedContent.setVisibility(VISIBLE);
setVisibility(VISIBLE);
requestFocus();
}
@@ -372,6 +380,9 @@ public class KeyboardQuickSwitchView extends ConstraintLayout {
}
protected void animateFocusMove(int fromIndex, int toIndex) {
if (!mDisplayingRecentTasks) {
return;
}
KeyboardQuickSwitchTaskView focusedTask = getTaskAt(toIndex);
if (focusedTask == null) {
return;
@@ -425,11 +436,15 @@ public class KeyboardQuickSwitchView extends ConstraintLayout {
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
return (mViewCallbacks != null && mViewCallbacks.onKeyUp(keyCode, event, mIsRtl))
return (mViewCallbacks != null
&& mViewCallbacks.onKeyUp(keyCode, event, mIsRtl, mDisplayingRecentTasks))
|| super.onKeyUp(keyCode, event);
}
private void initializeScroll(int index, boolean shouldTruncateTarget) {
if (!mDisplayingRecentTasks) {
return;
}
View task = getTaskAt(index);
if (task == null) {
return;
@@ -449,6 +464,9 @@ public class KeyboardQuickSwitchView extends ConstraintLayout {
private void scrollRightTo(
@NonNull View targetTask, boolean shouldTruncateTarget, boolean smoothScroll) {
if (!mDisplayingRecentTasks) {
return;
}
if (smoothScroll && !shouldScroll(targetTask, shouldTruncateTarget)) {
return;
}
@@ -468,6 +486,9 @@ public class KeyboardQuickSwitchView extends ConstraintLayout {
private void scrollLeftTo(
@NonNull View targetTask, boolean shouldTruncateTarget, boolean smoothScroll) {
if (!mDisplayingRecentTasks) {
return;
}
if (smoothScroll && !shouldScroll(targetTask, shouldTruncateTarget)) {
return;
}
@@ -491,7 +512,7 @@ public class KeyboardQuickSwitchView extends ConstraintLayout {
@Nullable
protected KeyboardQuickSwitchTaskView getTaskAt(int index) {
return index < 0 || index >= mContent.getChildCount()
return !mDisplayingRecentTasks || index < 0 || index >= mContent.getChildCount()
? null : (KeyboardQuickSwitchTaskView) mContent.getChildAt(index);
}
}