Setting transparency for clear-all button.

See visual spec: https://gallery.googleplex.com/projects/MCHbtQVoQ2HCZdNNRhNUDzOW/files/MCEf7JcwkS_N8QTSAba7WiJQwMSJbxAVNpw

Bug: 72222505
Test: Manual
Change-Id: I61c7e4ccc89396827a17450db4a5e1017a5579a1
This commit is contained in:
Vadim Tryshev 2018-04-18 16:41:55 -07:00
parent 9d1e0f116f
commit 2670fde01e
2 changed files with 55 additions and 1 deletions

View File

@ -35,7 +35,6 @@ public class FallbackRecentsView extends RecentsView<RecentsActivity> {
public FallbackRecentsView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
setOverviewStateEnabled(true);
updateEmptyMessage();
}
@Override

View File

@ -213,6 +213,7 @@ public abstract class RecentsView<T extends BaseActivity>
mEmptyMessagePadding = getResources()
.getDimensionPixelSize(R.dimen.recents_empty_message_text_padding);
setWillNotDraw(false);
updateEmptyMessage();
}
@Override
@ -310,6 +311,56 @@ public abstract class RecentsView<T extends BaseActivity>
}
}
private float calculateClearAllButtonAlpha() {
if (mClearAllButton.getVisibility() != View.VISIBLE) 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;
// 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;
// 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
// where the button reaches 0 alpha.
final float rightOfAlphaChange = Math.min(
mClearAllButton.getX() + mClearAllButton.getWidth(), carouselMotionLimit);
return Utilities.boundToRange(
(rightOfAlphaChange - carouselCurrentRight) /
(rightOfAlphaChange - leftOfAlphaChange), 0, 1);
}
private void updateClearAllButtonAlpha() {
if (mClearAllButton != null) {
mClearAllButton.setAlpha(calculateClearAllButtonAlpha() * mContentAlpha);
}
}
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);
updateClearAllButtonAlpha();
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (DEBUG_SHOW_CLEAR_ALL_BUTTON && ev.getAction() == MotionEvent.ACTION_DOWN
@ -864,6 +915,7 @@ public abstract class RecentsView<T extends BaseActivity>
int alphaInt = Math.round(alpha * 255);
mEmptyMessagePaint.setAlpha(alphaInt);
mEmptyIcon.setAlpha(alphaInt);
updateClearAllButtonAlpha();
}
public void setAdjacentScale(float adjacentScale) {
@ -948,6 +1000,7 @@ public abstract class RecentsView<T extends BaseActivity>
mEmptyTextLayout = null;
mLastMeasureSize.set(getWidth(), getHeight());
}
updateClearAllButtonVisibility();
if (!mShowEmptyMessage) return;
@ -1138,8 +1191,10 @@ public abstract class RecentsView<T extends BaseActivity>
}
private void updateClearAllButtonVisibility() {
if (mClearAllButton == null) return;
mClearAllButton.setVisibility(
!DEBUG_SHOW_CLEAR_ALL_BUTTON || mShowEmptyMessage ? GONE : VISIBLE);
updateClearAllButtonAlpha();
}
public void setClearAllButton(View clearAllButton) {