summaryrefslogtreecommitdiffstats
path: root/quickstep/src/com
diff options
context:
space:
mode:
authorVadim Tryshev <vadimt@google.com>2018-04-26 10:47:05 -0700
committerVadim Tryshev <vadimt@google.com>2018-04-27 13:32:28 -0700
commitcc0c98ad945a911499e92bcf3a5bc364acdf6e3b (patch)
treec8837ea7edf09cac7b9e8afddbdde8db13ecee09 /quickstep/src/com
parentdcb74be7a6c72458fbba81c76a588a34663d82ec (diff)
downloadandroid_packages_apps_Trebuchet-cc0c98ad945a911499e92bcf3a5bc364acdf6e3b.tar.gz
android_packages_apps_Trebuchet-cc0c98ad945a911499e92bcf3a5bc364acdf6e3b.tar.bz2
android_packages_apps_Trebuchet-cc0c98ad945a911499e92bcf3a5bc364acdf6e3b.zip
Enable Clear-all button by default
Making it work with all 4 combinations of RTL and flip-recents. Bug: 72222505 Test: Manual Change-Id: Ifb2428e006674abfe9a2609fd3d8f3f648eff0b8
Diffstat (limited to 'quickstep/src/com')
-rw-r--r--quickstep/src/com/android/quickstep/views/RecentsView.java95
-rw-r--r--quickstep/src/com/android/quickstep/views/RecentsViewContainer.java10
2 files changed, 65 insertions, 40 deletions
diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java
index 5fff51cd1..b60fda9e2 100644
--- a/quickstep/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/src/com/android/quickstep/views/RecentsView.java
@@ -88,8 +88,6 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
private static final String TAG = RecentsView.class.getSimpleName();
- public static final boolean DEBUG_SHOW_CLEAR_ALL_BUTTON = false;
-
private final Rect mTempRect = new Rect();
public static final FloatProperty<RecentsView> ADJACENT_SCALE =
@@ -104,7 +102,7 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
return recentsView.mAdjacentScale;
}
};
- private static final boolean FLIP_RECENTS = true;
+ public static final boolean FLIP_RECENTS = true;
private static final int DISMISS_TASK_DURATION = 300;
protected final T mActivity;
@@ -303,41 +301,55 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
}
private float calculateClearAllButtonAlpha() {
- if (mClearAllButton.getVisibility() != View.VISIBLE || getChildCount() == 0) return 0;
-
- // Current visible coordinate of the right border of the rightmost task.
- final int carouselCurrentRight = getChildAt(getChildCount() - 1).getRight() - getScrollX();
-
- // As the right border (let's call it E aka carouselCurrentRight) of the carousel moves
- // over Clear all button, the button changes trasparency.
- // leftOfAlphaChange < rightOfAlphaChange; these are the points of the 100% and 0% alpha
- // correspondingly. Alpha changes linearly between 100% and 0% as E moves through this
- // range. It doesn't change outside of the range.
-
- // Once E hits the left border of the Clear-All button, the whole button is uncovered,
- // and it should have alpha 100%.
- final float leftOfAlphaChange = mClearAllButton.getX();
-
- // The rightmost possible right coordinate of the carousel.
- final int carouselMotionLimit = getScrollForPage(getChildCount() - 1) + getWidth()
- - getPaddingRight() - mInsets.right;
+ final int childCount = getChildCount();
+ if (mClearAllButton.getVisibility() != View.VISIBLE || childCount == 0) return 0;
+
+ // Current visible coordinate of the end of the oldest task.
+ final View lastChild = getChildAt(childCount - 1);
+ final int carouselCurrentEnd =
+ (mIsRtl ? lastChild.getLeft() : lastChild.getRight()) - getScrollX();
+
+ // As the end (let's call it E aka carouselCurrentEnd) of the carousel moves over Clear
+ // all button, the button changes trasparency.
+ // fullAlphaX and zeroAlphaX are the points of the 100% and 0% alpha correspondingly.
+ // Alpha changes linearly between 100% and 0% as E moves through this range. It doesn't
+ // change outside of the range.
+
+ // Once E hits the border of the Clear-All button that looks towards the most recent
+ // task, the whole button is uncovered, and it should have alpha 100%.
+ final float fullAlphaX = mIsRtl ?
+ mClearAllButton.getX() + mClearAllButton.getWidth() :
+ mClearAllButton.getX();
+
+ // X coordinate of the carousel scrolled as far as possible in the direction towards the
+ // button. Logically, the button is "behind" the least recent task. This is the
+ // coordinate of the end of the least recent task in the carousel just after opening,
+ // with the most recent task in the center, and the rest of tasks go from that point
+ // towards and potentially behind the button.
+ final int carouselMotionLimit = getScrollForPage(childCount - 1) - getScrollForPage(0) +
+ (mIsRtl ?
+ getPaddingLeft() + mInsets.left :
+ getWidth() - getPaddingRight() - mInsets.right);
// The carousel might not be able to ever cover a part of the Clear-all button. Then
// always show the button as 100%. Technically, this check also prevents dividing by zero
- // or a negative number when calculating the transparency ratio below.
- if (carouselMotionLimit <= leftOfAlphaChange) return 1;
+ // or getting a negative transparency ratio.
+ if (mIsRtl ? carouselMotionLimit >= fullAlphaX : carouselMotionLimit <= fullAlphaX) {
+ return 1;
+ }
// If the carousel is able to cover the button completely, we make the button completely
- // transparent when E hits the right border of the button.
- // Or, the carousel may not be able to move that far to the right so it completely covers
- // the button. Then we set the rightmost possible position of the carousel as the point
+ // transparent when E hits the border of the button farthest from the most recent task.
+ // Or, the carousel may not be able to move that far towards the button so it completely
+ // covers the it. Then we set the motion limit position of the carousel as the point
// where the button reaches 0 alpha.
- final float rightOfAlphaChange = Math.min(
- mClearAllButton.getX() + mClearAllButton.getWidth(), carouselMotionLimit);
+ final float zeroAlphaX = mIsRtl ?
+ Math.max(mClearAllButton.getX(), carouselMotionLimit) :
+ Math.min(mClearAllButton.getX() + mClearAllButton.getWidth(), carouselMotionLimit);
return Utilities.boundToRange(
- (rightOfAlphaChange - carouselCurrentRight) /
- (rightOfAlphaChange - leftOfAlphaChange), 0, 1);
+ (zeroAlphaX - carouselCurrentEnd) /
+ (zeroAlphaX - fullAlphaX), 0, 1);
}
private void updateClearAllButtonAlpha() {
@@ -354,9 +366,8 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
@Override
public boolean onTouchEvent(MotionEvent ev) {
- if (DEBUG_SHOW_CLEAR_ALL_BUTTON && ev.getAction() == MotionEvent.ACTION_DOWN
- && mTouchState == TOUCH_STATE_REST && mScroller.isFinished()
- && mClearAllButton.getVisibility() == View.VISIBLE) {
+ if (ev.getAction() == MotionEvent.ACTION_DOWN && mTouchState == TOUCH_STATE_REST
+ && mScroller.isFinished() && mClearAllButton.getVisibility() == View.VISIBLE) {
mClearAllButton.getHitRect(mTempRect);
mTempRect.offset(-getLeft(), -getTop());
if (mTempRect.contains((int) ev.getX(), (int) ev.getY())) {
@@ -1206,21 +1217,29 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
return "";
}
+ private int additionalScrollForClearAllButton() {
+ return (int) getResources().getDimension(
+ R.dimen.clear_all_container_width) - getPaddingEnd();
+ }
+
@Override
protected int computeMaxScrollX() {
- if (!DEBUG_SHOW_CLEAR_ALL_BUTTON || getChildCount() == 0) {
+ if (getChildCount() == 0) {
return super.computeMaxScrollX();
}
// Allow a clear_all_container_width-sized gap after the last task.
- return super.computeMaxScrollX() + (int) getResources().getDimension(
- R.dimen.clear_all_container_width) - getPaddingEnd();
+ return super.computeMaxScrollX() + (mIsRtl ? 0 : additionalScrollForClearAllButton());
+ }
+
+ @Override
+ protected int offsetForPageScrolls() {
+ return mIsRtl ? additionalScrollForClearAllButton() : 0;
}
private void updateClearAllButtonVisibility() {
if (mClearAllButton == null) return;
- mClearAllButton.setVisibility(
- !DEBUG_SHOW_CLEAR_ALL_BUTTON || mShowEmptyMessage ? GONE : VISIBLE);
+ mClearAllButton.setVisibility(mShowEmptyMessage ? GONE : VISIBLE);
updateClearAllButtonAlpha();
}
diff --git a/quickstep/src/com/android/quickstep/views/RecentsViewContainer.java b/quickstep/src/com/android/quickstep/views/RecentsViewContainer.java
index 988b3ad1f..6b89b66f4 100644
--- a/quickstep/src/com/android/quickstep/views/RecentsViewContainer.java
+++ b/quickstep/src/com/android/quickstep/views/RecentsViewContainer.java
@@ -4,6 +4,7 @@ import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.FloatProperty;
+import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
@@ -43,6 +44,10 @@ public class RecentsViewContainer extends InsettableFrameLayout {
});
mRecentsView = (RecentsView) findViewById(R.id.overview_panel);
+ final InsettableFrameLayout.LayoutParams params =
+ (InsettableFrameLayout.LayoutParams) mClearAllButton.getLayoutParams();
+ params.gravity = Gravity.TOP | (RecentsView.FLIP_RECENTS ? Gravity.START : Gravity.END);
+ mClearAllButton.setLayoutParams(params);
mRecentsView.setClearAllButton(mClearAllButton);
}
@@ -53,8 +58,9 @@ public class RecentsViewContainer extends InsettableFrameLayout {
mRecentsView.getTaskSize(mTempRect);
mClearAllButton.setTranslationX(
- (mClearAllButton.getMeasuredWidth() - getResources().getDimension(
- R.dimen.clear_all_container_width)) / 2);
+ (mRecentsView.isRtl() ? 1 : -1) *
+ (getResources().getDimension(R.dimen.clear_all_container_width)
+ - mClearAllButton.getMeasuredWidth()) / 2);
mClearAllButton.setTranslationY(
mTempRect.top + (mTempRect.height() - mClearAllButton.getMeasuredHeight()) / 2
- mClearAllButton.getTop());