Updating the scrollbar to make the fastscroller more visible.
Bug: 20035978 Change-Id: I56a865262cd07e6af11b4374a7e6354710116dcd
This commit is contained in:
parent
a67cce2cb3
commit
6779595bec
|
@ -5,8 +5,8 @@
|
||||||
-keep class com.android.launcher3.BaseRecyclerViewFastScrollBar {
|
-keep class com.android.launcher3.BaseRecyclerViewFastScrollBar {
|
||||||
public void setThumbWidth(int);
|
public void setThumbWidth(int);
|
||||||
public int getThumbWidth();
|
public int getThumbWidth();
|
||||||
public void setTrackAlpha(int);
|
public void setTrackWidth(int);
|
||||||
public int getTrackAlpha();
|
public int getTrackWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
-keep class com.android.launcher3.BaseRecyclerViewFastScrollPopup {
|
-keep class com.android.launcher3.BaseRecyclerViewFastScrollPopup {
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
<color name="outline_color">#FFFFFFFF</color>
|
<color name="outline_color">#FFFFFFFF</color>
|
||||||
|
|
||||||
<!-- Containers -->
|
<!-- Containers -->
|
||||||
<color name="container_fastscroll_thumb_inactive_color">#42000000</color>
|
<color name="container_fastscroll_thumb_inactive_color">#009688</color>
|
||||||
<color name="container_fastscroll_thumb_active_color">#009688</color>
|
<color name="container_fastscroll_thumb_active_color">#009688</color>
|
||||||
|
|
||||||
<!-- All Apps -->
|
<!-- All Apps -->
|
||||||
|
|
|
@ -55,9 +55,9 @@
|
||||||
<!-- Notes: container_bounds_inset - quantum_panel_outer_padding -->
|
<!-- Notes: container_bounds_inset - quantum_panel_outer_padding -->
|
||||||
<dimen name="container_bounds_minus_quantum_panel_padding_inset">4dp</dimen>
|
<dimen name="container_bounds_minus_quantum_panel_padding_inset">4dp</dimen>
|
||||||
|
|
||||||
<dimen name="container_fastscroll_thumb_min_width">4dp</dimen>
|
<dimen name="container_fastscroll_thumb_min_width">5dp</dimen>
|
||||||
<dimen name="container_fastscroll_thumb_max_width">8dp</dimen>
|
<dimen name="container_fastscroll_thumb_max_width">9dp</dimen>
|
||||||
<dimen name="container_fastscroll_thumb_height">64dp</dimen>
|
<dimen name="container_fastscroll_thumb_height">72dp</dimen>
|
||||||
<dimen name="container_fastscroll_thumb_touch_inset">-24dp</dimen>
|
<dimen name="container_fastscroll_thumb_touch_inset">-24dp</dimen>
|
||||||
<dimen name="container_fastscroll_popup_size">72dp</dimen>
|
<dimen name="container_fastscroll_popup_size">72dp</dimen>
|
||||||
<dimen name="container_fastscroll_popup_text_size">48dp</dimen>
|
<dimen name="container_fastscroll_popup_text_size">48dp</dimen>
|
||||||
|
|
|
@ -23,6 +23,7 @@ import android.content.res.Resources;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.Path;
|
||||||
import android.graphics.Point;
|
import android.graphics.Point;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
@ -51,11 +52,14 @@ public class BaseRecyclerViewFastScrollBar {
|
||||||
private int mThumbActiveColor;
|
private int mThumbActiveColor;
|
||||||
@Thunk Point mThumbOffset = new Point(-1, -1);
|
@Thunk Point mThumbOffset = new Point(-1, -1);
|
||||||
@Thunk Paint mThumbPaint;
|
@Thunk Paint mThumbPaint;
|
||||||
private Paint mTrackPaint;
|
|
||||||
private int mThumbMinWidth;
|
private int mThumbMinWidth;
|
||||||
private int mThumbMaxWidth;
|
private int mThumbMaxWidth;
|
||||||
@Thunk int mThumbWidth;
|
@Thunk int mThumbWidth;
|
||||||
@Thunk int mThumbHeight;
|
@Thunk int mThumbHeight;
|
||||||
|
private int mThumbCurvature;
|
||||||
|
private Path mThumbPath = new Path();
|
||||||
|
private Paint mTrackPaint;
|
||||||
|
private int mTrackWidth;
|
||||||
private float mLastTouchY;
|
private float mLastTouchY;
|
||||||
// The inset is the buffer around which a point will still register as a click on the scrollbar
|
// The inset is the buffer around which a point will still register as a click on the scrollbar
|
||||||
private int mTouchInset;
|
private int mTouchInset;
|
||||||
|
@ -75,15 +79,18 @@ public class BaseRecyclerViewFastScrollBar {
|
||||||
mPopup = new BaseRecyclerViewFastScrollPopup(rv, res);
|
mPopup = new BaseRecyclerViewFastScrollPopup(rv, res);
|
||||||
mTrackPaint = new Paint();
|
mTrackPaint = new Paint();
|
||||||
mTrackPaint.setColor(rv.getFastScrollerTrackColor(Color.BLACK));
|
mTrackPaint.setColor(rv.getFastScrollerTrackColor(Color.BLACK));
|
||||||
mTrackPaint.setAlpha(0);
|
mTrackPaint.setAlpha(MAX_TRACK_ALPHA);
|
||||||
mThumbInactiveColor = rv.getFastScrollerThumbInactiveColor(
|
mThumbInactiveColor = rv.getFastScrollerThumbInactiveColor(
|
||||||
res.getColor(R.color.container_fastscroll_thumb_inactive_color));
|
res.getColor(R.color.container_fastscroll_thumb_inactive_color));
|
||||||
mThumbActiveColor = res.getColor(R.color.container_fastscroll_thumb_active_color);
|
mThumbActiveColor = res.getColor(R.color.container_fastscroll_thumb_active_color);
|
||||||
mThumbPaint = new Paint();
|
mThumbPaint = new Paint();
|
||||||
|
mThumbPaint.setAntiAlias(true);
|
||||||
mThumbPaint.setColor(mThumbInactiveColor);
|
mThumbPaint.setColor(mThumbInactiveColor);
|
||||||
|
mThumbPaint.setStyle(Paint.Style.FILL);
|
||||||
mThumbWidth = mThumbMinWidth = res.getDimensionPixelSize(R.dimen.container_fastscroll_thumb_min_width);
|
mThumbWidth = mThumbMinWidth = res.getDimensionPixelSize(R.dimen.container_fastscroll_thumb_min_width);
|
||||||
mThumbMaxWidth = res.getDimensionPixelSize(R.dimen.container_fastscroll_thumb_max_width);
|
mThumbMaxWidth = res.getDimensionPixelSize(R.dimen.container_fastscroll_thumb_max_width);
|
||||||
mThumbHeight = res.getDimensionPixelSize(R.dimen.container_fastscroll_thumb_height);
|
mThumbHeight = res.getDimensionPixelSize(R.dimen.container_fastscroll_thumb_height);
|
||||||
|
mThumbCurvature = mThumbMaxWidth - mThumbMinWidth;
|
||||||
mTouchInset = res.getDimensionPixelSize(R.dimen.container_fastscroll_thumb_touch_inset);
|
mTouchInset = res.getDimensionPixelSize(R.dimen.container_fastscroll_thumb_touch_inset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,10 +106,12 @@ public class BaseRecyclerViewFastScrollBar {
|
||||||
if (mThumbOffset.x == x && mThumbOffset.y == y) {
|
if (mThumbOffset.x == x && mThumbOffset.y == y) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mInvalidateRect.set(mThumbOffset.x, 0, mThumbOffset.x + mThumbWidth, mRv.getHeight());
|
mInvalidateRect.set(mThumbOffset.x - mThumbCurvature, mThumbOffset.y,
|
||||||
|
mThumbOffset.x + mThumbWidth, mThumbOffset.y + mThumbHeight);
|
||||||
mThumbOffset.set(x, y);
|
mThumbOffset.set(x, y);
|
||||||
mInvalidateRect.union(new Rect(mThumbOffset.x, 0, mThumbOffset.x + mThumbWidth,
|
updateThumbPath();
|
||||||
mRv.getHeight()));
|
mInvalidateRect.union(mThumbOffset.x - mThumbCurvature, mThumbOffset.y,
|
||||||
|
mThumbOffset.x + mThumbWidth, mThumbOffset.y + mThumbHeight);
|
||||||
mRv.invalidate(mInvalidateRect);
|
mRv.invalidate(mInvalidateRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,12 +119,14 @@ public class BaseRecyclerViewFastScrollBar {
|
||||||
return mThumbOffset;
|
return mThumbOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setter/getter for the search bar width for animations
|
// Setter/getter for the thumb bar width for animations
|
||||||
public void setThumbWidth(int width) {
|
public void setThumbWidth(int width) {
|
||||||
mInvalidateRect.set(mThumbOffset.x, 0, mThumbOffset.x + mThumbWidth, mRv.getHeight());
|
mInvalidateRect.set(mThumbOffset.x - mThumbCurvature, mThumbOffset.y,
|
||||||
|
mThumbOffset.x + mThumbWidth, mThumbOffset.y + mThumbHeight);
|
||||||
mThumbWidth = width;
|
mThumbWidth = width;
|
||||||
mInvalidateRect.union(new Rect(mThumbOffset.x, 0, mThumbOffset.x + mThumbWidth,
|
updateThumbPath();
|
||||||
mRv.getHeight()));
|
mInvalidateRect.union(mThumbOffset.x - mThumbCurvature, mThumbOffset.y,
|
||||||
|
mThumbOffset.x + mThumbWidth, mThumbOffset.y + mThumbHeight);
|
||||||
mRv.invalidate(mInvalidateRect);
|
mRv.invalidate(mInvalidateRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,15 +134,19 @@ public class BaseRecyclerViewFastScrollBar {
|
||||||
return mThumbWidth;
|
return mThumbWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setter/getter for the track background alpha for animations
|
// Setter/getter for the track bar width for animations
|
||||||
public void setTrackAlpha(int alpha) {
|
public void setTrackWidth(int width) {
|
||||||
mTrackPaint.setAlpha(alpha);
|
mInvalidateRect.set(mThumbOffset.x - mThumbCurvature, 0, mThumbOffset.x + mThumbWidth,
|
||||||
mInvalidateRect.set(mThumbOffset.x, 0, mThumbOffset.x + mThumbWidth, mRv.getHeight());
|
mRv.getHeight());
|
||||||
|
mTrackWidth = width;
|
||||||
|
updateThumbPath();
|
||||||
|
mInvalidateRect.union(mThumbOffset.x - mThumbCurvature, 0, mThumbOffset.x + mThumbWidth,
|
||||||
|
mRv.getHeight());
|
||||||
mRv.invalidate(mInvalidateRect);
|
mRv.invalidate(mInvalidateRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTrackAlpha() {
|
public int getTrackWidth() {
|
||||||
return mTrackPaint.getAlpha();
|
return mTrackWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getThumbHeight() {
|
public int getThumbHeight() {
|
||||||
|
@ -217,8 +232,7 @@ public class BaseRecyclerViewFastScrollBar {
|
||||||
if (mTrackPaint.getAlpha() > 0) {
|
if (mTrackPaint.getAlpha() > 0) {
|
||||||
canvas.drawRect(mThumbOffset.x, 0, mThumbOffset.x + mThumbWidth, mRv.getHeight(), mTrackPaint);
|
canvas.drawRect(mThumbOffset.x, 0, mThumbOffset.x + mThumbWidth, mRv.getHeight(), mTrackPaint);
|
||||||
}
|
}
|
||||||
canvas.drawRect(mThumbOffset.x, mThumbOffset.y, mThumbOffset.x + mThumbWidth,
|
canvas.drawPath(mThumbPath, mThumbPaint);
|
||||||
mThumbOffset.y + mThumbHeight, mThumbPaint);
|
|
||||||
|
|
||||||
// Draw the popup
|
// Draw the popup
|
||||||
mPopup.draw(canvas);
|
mPopup.draw(canvas);
|
||||||
|
@ -231,26 +245,45 @@ public class BaseRecyclerViewFastScrollBar {
|
||||||
if (mScrollbarAnimator != null) {
|
if (mScrollbarAnimator != null) {
|
||||||
mScrollbarAnimator.cancel();
|
mScrollbarAnimator.cancel();
|
||||||
}
|
}
|
||||||
ObjectAnimator trackAlphaAnim = ObjectAnimator.ofInt(this, "trackAlpha",
|
|
||||||
isScrolling ? MAX_TRACK_ALPHA : 0);
|
mScrollbarAnimator = new AnimatorSet();
|
||||||
|
ObjectAnimator trackWidthAnim = ObjectAnimator.ofInt(this, "trackWidth",
|
||||||
|
isScrolling ? mThumbMaxWidth : mThumbMinWidth);
|
||||||
ObjectAnimator thumbWidthAnim = ObjectAnimator.ofInt(this, "thumbWidth",
|
ObjectAnimator thumbWidthAnim = ObjectAnimator.ofInt(this, "thumbWidth",
|
||||||
isScrolling ? mThumbMaxWidth : mThumbMinWidth);
|
isScrolling ? mThumbMaxWidth : mThumbMinWidth);
|
||||||
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(),
|
mScrollbarAnimator.playTogether(trackWidthAnim, thumbWidthAnim);
|
||||||
mThumbPaint.getColor(), isScrolling ? mThumbActiveColor : mThumbInactiveColor);
|
if (mThumbActiveColor != mThumbInactiveColor) {
|
||||||
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(),
|
||||||
@Override
|
mThumbPaint.getColor(), isScrolling ? mThumbActiveColor : mThumbInactiveColor);
|
||||||
public void onAnimationUpdate(ValueAnimator animator) {
|
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
||||||
mThumbPaint.setColor((Integer) animator.getAnimatedValue());
|
@Override
|
||||||
mRv.invalidate(mThumbOffset.x, mThumbOffset.y, mThumbOffset.x + mThumbWidth,
|
public void onAnimationUpdate(ValueAnimator animator) {
|
||||||
mThumbOffset.y + mThumbHeight);
|
mThumbPaint.setColor((Integer) animator.getAnimatedValue());
|
||||||
}
|
mRv.invalidate(mThumbOffset.x, mThumbOffset.y, mThumbOffset.x + mThumbWidth,
|
||||||
});
|
mThumbOffset.y + mThumbHeight);
|
||||||
mScrollbarAnimator = new AnimatorSet();
|
}
|
||||||
mScrollbarAnimator.playTogether(trackAlphaAnim, thumbWidthAnim, colorAnimation);
|
});
|
||||||
|
mScrollbarAnimator.play(colorAnimation);
|
||||||
|
}
|
||||||
mScrollbarAnimator.setDuration(SCROLL_BAR_VIS_DURATION);
|
mScrollbarAnimator.setDuration(SCROLL_BAR_VIS_DURATION);
|
||||||
mScrollbarAnimator.start();
|
mScrollbarAnimator.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the path for the thumb drawable.
|
||||||
|
*/
|
||||||
|
private void updateThumbPath() {
|
||||||
|
mThumbCurvature = mThumbMaxWidth - mThumbWidth;
|
||||||
|
mThumbPath.reset();
|
||||||
|
mThumbPath.moveTo(mThumbOffset.x + mThumbWidth, mThumbOffset.y); // tr
|
||||||
|
mThumbPath.lineTo(mThumbOffset.x + mThumbWidth, mThumbOffset.y + mThumbHeight); // br
|
||||||
|
mThumbPath.lineTo(mThumbOffset.x, mThumbOffset.y + mThumbHeight); // bl
|
||||||
|
mThumbPath.cubicTo(mThumbOffset.x, mThumbOffset.y + mThumbHeight,
|
||||||
|
mThumbOffset.x - mThumbCurvature, mThumbOffset.y + mThumbHeight / 2,
|
||||||
|
mThumbOffset.x, mThumbOffset.y); // bl2tl
|
||||||
|
mThumbPath.close();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the specified points are near the scroll bar bounds.
|
* Returns whether the specified points are near the scroll bar bounds.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue