Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package com.android.launcher3; |
| 17 | |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 18 | import android.animation.ObjectAnimator; |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 19 | import android.content.res.Resources; |
| 20 | import android.graphics.Canvas; |
| 21 | import android.graphics.Color; |
| 22 | import android.graphics.Paint; |
Winson | 6779595 | 2015-08-20 12:23:52 -0700 | [diff] [blame] | 23 | import android.graphics.Path; |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 24 | import android.graphics.Rect; |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 25 | import android.util.Property; |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 26 | import android.view.MotionEvent; |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 27 | import android.view.View; |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 28 | import android.view.ViewConfiguration; |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 29 | import android.widget.TextView; |
Sunny Goyal | b713ad4 | 2015-06-24 11:45:32 -0700 | [diff] [blame] | 30 | |
Mario Bertschler | ee4ee42 | 2016-12-27 15:41:24 -0800 | [diff] [blame] | 31 | import com.android.launcher3.config.FeatureFlags; |
Sunny Goyal | 1f3f07d | 2017-02-10 16:52:16 -0800 | [diff] [blame^] | 32 | import com.android.launcher3.util.Themes; |
Mario Bertschler | ee4ee42 | 2016-12-27 15:41:24 -0800 | [diff] [blame] | 33 | |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 34 | /** |
| 35 | * The track and scrollbar that shows when you scroll the list. |
| 36 | */ |
| 37 | public class BaseRecyclerViewFastScrollBar { |
| 38 | |
| 39 | public interface FastScrollFocusableView { |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 40 | void setFastScrollFocusState(final FastBitmapDrawable.State focusState, boolean animated); |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 41 | } |
| 42 | |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 43 | private static final Property<BaseRecyclerViewFastScrollBar, Integer> TRACK_WIDTH = |
| 44 | new Property<BaseRecyclerViewFastScrollBar, Integer>(Integer.class, "width") { |
| 45 | |
| 46 | @Override |
| 47 | public Integer get(BaseRecyclerViewFastScrollBar scrollBar) { |
| 48 | return scrollBar.mWidth; |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public void set(BaseRecyclerViewFastScrollBar scrollBar, Integer value) { |
| 53 | scrollBar.setTrackWidth(value); |
| 54 | } |
| 55 | }; |
| 56 | |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 57 | private final static int MAX_TRACK_ALPHA = 30; |
| 58 | private final static int SCROLL_BAR_VIS_DURATION = 150; |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 59 | private static final float FAST_SCROLL_OVERLAY_Y_OFFSET_FACTOR = 1.5f; |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 60 | |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 61 | private final Rect mTmpRect = new Rect(); |
| 62 | private final BaseRecyclerView mRv; |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 63 | |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 64 | private final boolean mIsRtl; |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 65 | |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 66 | // The inset is the buffer around which a point will still register as a click on the scrollbar |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 67 | private final int mTouchInset; |
| 68 | |
| 69 | private final int mMinWidth; |
| 70 | private final int mMaxWidth; |
| 71 | |
| 72 | // Current width of the track |
| 73 | private int mWidth; |
| 74 | private ObjectAnimator mWidthAnimator; |
| 75 | |
| 76 | private final Path mThumbPath = new Path(); |
| 77 | private final Paint mThumbPaint; |
| 78 | private final int mThumbHeight; |
| 79 | |
| 80 | private final Paint mTrackPaint; |
| 81 | |
| 82 | private float mLastTouchY; |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 83 | private boolean mIsDragging; |
Winson | d2eb49e | 2015-08-18 17:43:02 -0700 | [diff] [blame] | 84 | private boolean mIsThumbDetached; |
| 85 | private boolean mCanThumbDetach; |
Winson | ec4845b | 2015-08-27 10:19:48 -0700 | [diff] [blame] | 86 | private boolean mIgnoreDragGesture; |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 87 | |
| 88 | // This is the offset from the top of the scrollbar when the user first starts touching. To |
| 89 | // prevent jumping, this offset is applied as the user scrolls. |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 90 | private int mTouchOffsetY; |
| 91 | private int mThumbOffsetY; |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 92 | |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 93 | // Fast scroller popup |
| 94 | private TextView mPopupView; |
| 95 | private boolean mPopupVisible; |
| 96 | private String mPopupSectionName; |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 97 | |
| 98 | public BaseRecyclerViewFastScrollBar(BaseRecyclerView rv, Resources res) { |
| 99 | mRv = rv; |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 100 | mTrackPaint = new Paint(); |
| 101 | mTrackPaint.setColor(rv.getFastScrollerTrackColor(Color.BLACK)); |
Winson | 6779595 | 2015-08-20 12:23:52 -0700 | [diff] [blame] | 102 | mTrackPaint.setAlpha(MAX_TRACK_ALPHA); |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 103 | |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 104 | mThumbPaint = new Paint(); |
Winson | 6779595 | 2015-08-20 12:23:52 -0700 | [diff] [blame] | 105 | mThumbPaint.setAntiAlias(true); |
Sunny Goyal | 1f3f07d | 2017-02-10 16:52:16 -0800 | [diff] [blame^] | 106 | mThumbPaint.setColor(Themes.getColorAccent(rv.getContext())); |
Winson | 6779595 | 2015-08-20 12:23:52 -0700 | [diff] [blame] | 107 | mThumbPaint.setStyle(Paint.Style.FILL); |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 108 | |
| 109 | mWidth = mMinWidth = res.getDimensionPixelSize(R.dimen.container_fastscroll_thumb_min_width); |
| 110 | mMaxWidth = res.getDimensionPixelSize(R.dimen.container_fastscroll_thumb_max_width); |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 111 | mThumbHeight = res.getDimensionPixelSize(R.dimen.container_fastscroll_thumb_height); |
| 112 | mTouchInset = res.getDimensionPixelSize(R.dimen.container_fastscroll_thumb_touch_inset); |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 113 | mIsRtl = Utilities.isRtl(res); |
| 114 | updateThumbPath(); |
| 115 | } |
| 116 | |
| 117 | public void setPopupView(View popup) { |
| 118 | mPopupView = (TextView) popup; |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Winson | d2eb49e | 2015-08-18 17:43:02 -0700 | [diff] [blame] | 121 | public void setDetachThumbOnFastScroll() { |
| 122 | mCanThumbDetach = true; |
| 123 | } |
| 124 | |
| 125 | public void reattachThumbToScroll() { |
| 126 | mIsThumbDetached = false; |
| 127 | } |
| 128 | |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 129 | private int getDrawLeft() { |
| 130 | return mIsRtl ? 0 : (mRv.getWidth() - mMaxWidth); |
| 131 | } |
| 132 | |
| 133 | public void setThumbOffsetY(int y) { |
| 134 | if (mThumbOffsetY == y) { |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 135 | return; |
| 136 | } |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 137 | |
| 138 | // Invalidate the previous and new thumb area |
| 139 | int drawLeft = getDrawLeft(); |
| 140 | mTmpRect.set(drawLeft, mThumbOffsetY, drawLeft + mMaxWidth, mThumbOffsetY + mThumbHeight); |
| 141 | mThumbOffsetY = y; |
| 142 | mTmpRect.union(drawLeft, mThumbOffsetY, drawLeft + mMaxWidth, mThumbOffsetY + mThumbHeight); |
| 143 | mRv.invalidate(mTmpRect); |
| 144 | } |
| 145 | |
| 146 | public int getThumbOffsetY() { |
| 147 | return mThumbOffsetY; |
| 148 | } |
| 149 | |
| 150 | private void setTrackWidth(int width) { |
| 151 | if (mWidth == width) { |
| 152 | return; |
| 153 | } |
| 154 | int left = getDrawLeft(); |
| 155 | // Invalidate the whole scroll bar area. |
Sunny Goyal | 00e1068 | 2016-10-18 14:23:46 +0100 | [diff] [blame] | 156 | mRv.invalidate(left, 0, left + mMaxWidth, mRv.getScrollbarTrackHeight()); |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 157 | |
| 158 | mWidth = width; |
Winson | 6779595 | 2015-08-20 12:23:52 -0700 | [diff] [blame] | 159 | updateThumbPath(); |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 162 | /** |
| 163 | * Updates the path for the thumb drawable. |
| 164 | */ |
| 165 | private void updateThumbPath() { |
| 166 | int smallWidth = mIsRtl ? mWidth : -mWidth; |
| 167 | int largeWidth = mIsRtl ? mMaxWidth : -mMaxWidth; |
Winson | d2eb49e | 2015-08-18 17:43:02 -0700 | [diff] [blame] | 168 | |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 169 | mThumbPath.reset(); |
| 170 | mThumbPath.moveTo(0, 0); |
| 171 | mThumbPath.lineTo(0, mThumbHeight); // Left edge |
| 172 | mThumbPath.lineTo(smallWidth, mThumbHeight); // bottom edge |
| 173 | mThumbPath.cubicTo(smallWidth, mThumbHeight, // right edge |
| 174 | largeWidth, mThumbHeight / 2, |
| 175 | smallWidth, 0); |
| 176 | mThumbPath.close(); |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | public int getThumbHeight() { |
| 180 | return mThumbHeight; |
| 181 | } |
| 182 | |
Winson | d2eb49e | 2015-08-18 17:43:02 -0700 | [diff] [blame] | 183 | public boolean isDraggingThumb() { |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 184 | return mIsDragging; |
| 185 | } |
| 186 | |
Winson | d2eb49e | 2015-08-18 17:43:02 -0700 | [diff] [blame] | 187 | public boolean isThumbDetached() { |
| 188 | return mIsThumbDetached; |
| 189 | } |
| 190 | |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 191 | /** |
| 192 | * Handles the touch event and determines whether to show the fast scroller (or updates it if |
| 193 | * it is already showing). |
| 194 | */ |
| 195 | public void handleTouchEvent(MotionEvent ev, int downX, int downY, int lastY) { |
| 196 | ViewConfiguration config = ViewConfiguration.get(mRv.getContext()); |
| 197 | |
| 198 | int action = ev.getAction(); |
| 199 | int y = (int) ev.getY(); |
| 200 | switch (action) { |
| 201 | case MotionEvent.ACTION_DOWN: |
Winson | ec4845b | 2015-08-27 10:19:48 -0700 | [diff] [blame] | 202 | if (isNearThumb(downX, downY)) { |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 203 | mTouchOffsetY = downY - mThumbOffsetY; |
Mario Bertschler | ee4ee42 | 2016-12-27 15:41:24 -0800 | [diff] [blame] | 204 | } else if (FeatureFlags.LAUNCHER3_DIRECT_SCROLL |
| 205 | && mRv.supportsFastScrolling() |
| 206 | && isNearScrollBar(downX)) { |
| 207 | calcTouchOffsetAndPrepToFastScroll(downY, lastY); |
| 208 | updateFastScrollSectionNameAndThumbOffset(lastY, y); |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 209 | } |
| 210 | break; |
| 211 | case MotionEvent.ACTION_MOVE: |
Winson | ec4845b | 2015-08-27 10:19:48 -0700 | [diff] [blame] | 212 | // Check if we should start scrolling, but ignore this fastscroll gesture if we have |
| 213 | // exceeded some fixed movement |
| 214 | mIgnoreDragGesture |= Math.abs(y - downY) > config.getScaledPagingTouchSlop(); |
Winson | 646c236 | 2015-09-03 11:46:11 -0700 | [diff] [blame] | 215 | if (!mIsDragging && !mIgnoreDragGesture && mRv.supportsFastScrolling() && |
| 216 | isNearThumb(downX, lastY) && |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 217 | Math.abs(y - downY) > config.getScaledTouchSlop()) { |
Mario Bertschler | ee4ee42 | 2016-12-27 15:41:24 -0800 | [diff] [blame] | 218 | calcTouchOffsetAndPrepToFastScroll(downY, lastY); |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 219 | } |
| 220 | if (mIsDragging) { |
Mario Bertschler | ee4ee42 | 2016-12-27 15:41:24 -0800 | [diff] [blame] | 221 | updateFastScrollSectionNameAndThumbOffset(lastY, y); |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 222 | } |
| 223 | break; |
| 224 | case MotionEvent.ACTION_UP: |
| 225 | case MotionEvent.ACTION_CANCEL: |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 226 | mTouchOffsetY = 0; |
Winson | d2eb49e | 2015-08-18 17:43:02 -0700 | [diff] [blame] | 227 | mLastTouchY = 0; |
Winson | ec4845b | 2015-08-27 10:19:48 -0700 | [diff] [blame] | 228 | mIgnoreDragGesture = false; |
Winson Chung | 4c7fc62 | 2015-06-24 16:59:31 -0700 | [diff] [blame] | 229 | if (mIsDragging) { |
| 230 | mIsDragging = false; |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 231 | animatePopupVisibility(false); |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 232 | showActiveScrollbar(false); |
Winson Chung | 4c7fc62 | 2015-06-24 16:59:31 -0700 | [diff] [blame] | 233 | } |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 234 | break; |
| 235 | } |
| 236 | } |
| 237 | |
Mario Bertschler | ee4ee42 | 2016-12-27 15:41:24 -0800 | [diff] [blame] | 238 | private void calcTouchOffsetAndPrepToFastScroll(int downY, int lastY) { |
| 239 | mRv.getParent().requestDisallowInterceptTouchEvent(true); |
| 240 | mIsDragging = true; |
| 241 | if (mCanThumbDetach) { |
| 242 | mIsThumbDetached = true; |
| 243 | } |
| 244 | mTouchOffsetY += (lastY - downY); |
| 245 | animatePopupVisibility(true); |
| 246 | showActiveScrollbar(true); |
| 247 | } |
| 248 | |
| 249 | private void updateFastScrollSectionNameAndThumbOffset(int lastY, int y) { |
| 250 | // Update the fastscroller section name at this touch position |
| 251 | int bottom = mRv.getScrollbarTrackHeight() - mThumbHeight; |
| 252 | float boundedY = (float) Math.max(0, Math.min(bottom, y - mTouchOffsetY)); |
| 253 | String sectionName = mRv.scrollToPositionAtProgress(boundedY / bottom); |
| 254 | if (!sectionName.equals(mPopupSectionName)) { |
| 255 | mPopupSectionName = sectionName; |
| 256 | mPopupView.setText(sectionName); |
| 257 | } |
| 258 | animatePopupVisibility(!sectionName.isEmpty()); |
| 259 | updatePopupY(lastY); |
| 260 | mLastTouchY = boundedY; |
| 261 | setThumbOffsetY((int) mLastTouchY); |
| 262 | } |
| 263 | |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 264 | public void draw(Canvas canvas) { |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 265 | if (mThumbOffsetY < 0) { |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 266 | return; |
| 267 | } |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 268 | int saveCount = canvas.save(Canvas.MATRIX_SAVE_FLAG); |
| 269 | if (!mIsRtl) { |
| 270 | canvas.translate(mRv.getWidth(), 0); |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 271 | } |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 272 | // Draw the track |
| 273 | int thumbWidth = mIsRtl ? mWidth : -mWidth; |
Sunny Goyal | 00e1068 | 2016-10-18 14:23:46 +0100 | [diff] [blame] | 274 | canvas.drawRect(0, 0, thumbWidth, mRv.getScrollbarTrackHeight(), mTrackPaint); |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 275 | |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 276 | canvas.translate(0, mThumbOffsetY); |
| 277 | canvas.drawPath(mThumbPath, mThumbPaint); |
| 278 | canvas.restoreToCount(saveCount); |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | /** |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 282 | * Animates the width of the scrollbar. |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 283 | */ |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 284 | private void showActiveScrollbar(boolean isScrolling) { |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 285 | if (mWidthAnimator != null) { |
| 286 | mWidthAnimator.cancel(); |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 287 | } |
Winson | 6779595 | 2015-08-20 12:23:52 -0700 | [diff] [blame] | 288 | |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 289 | mWidthAnimator = ObjectAnimator.ofInt(this, TRACK_WIDTH, |
| 290 | isScrolling ? mMaxWidth : mMinWidth); |
| 291 | mWidthAnimator.setDuration(SCROLL_BAR_VIS_DURATION); |
| 292 | mWidthAnimator.start(); |
Winson | 6779595 | 2015-08-20 12:23:52 -0700 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | /** |
Mario Bertschler | ee4ee42 | 2016-12-27 15:41:24 -0800 | [diff] [blame] | 296 | * Returns whether the specified point is inside the thumb bounds. |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 297 | */ |
Hyunyoung Song | f4cbb14 | 2016-06-10 12:00:02 -0700 | [diff] [blame] | 298 | public boolean isNearThumb(int x, int y) { |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 299 | int left = getDrawLeft(); |
| 300 | mTmpRect.set(left, mThumbOffsetY, left + mMaxWidth, mThumbOffsetY + mThumbHeight); |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 301 | mTmpRect.inset(mTouchInset, mTouchInset); |
| 302 | return mTmpRect.contains(x, y); |
| 303 | } |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 304 | |
Mario Bertschler | ee4ee42 | 2016-12-27 15:41:24 -0800 | [diff] [blame] | 305 | /** |
| 306 | * Returns whether the specified x position is near the scroll bar. |
| 307 | */ |
| 308 | public boolean isNearScrollBar(int x) { |
| 309 | int left = getDrawLeft(); |
| 310 | return x >= left && x <= left + mMaxWidth; |
| 311 | } |
| 312 | |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 313 | private void animatePopupVisibility(boolean visible) { |
| 314 | if (mPopupVisible != visible) { |
| 315 | mPopupVisible = visible; |
| 316 | mPopupView.animate().cancel(); |
| 317 | mPopupView.animate().alpha(visible ? 1f : 0f).setDuration(visible ? 200 : 150).start(); |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | private void updatePopupY(int lastTouchY) { |
| 322 | int height = mPopupView.getHeight(); |
| 323 | float top = lastTouchY - (FAST_SCROLL_OVERLAY_Y_OFFSET_FACTOR * height); |
Sunny Goyal | 00e1068 | 2016-10-18 14:23:46 +0100 | [diff] [blame] | 324 | top = Math.max(mMaxWidth, Math.min(top, mRv.getScrollbarTrackHeight() - mMaxWidth - height)); |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 325 | mPopupView.setTranslationY(top); |
| 326 | } |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 327 | } |