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 | 1a8f6fb | 2017-06-14 15:35:16 -0700 | [diff] [blame^] | 32 | import com.android.launcher3.graphics.FastScrollThumbDrawable; |
Sunny Goyal | 1f3f07d | 2017-02-10 16:52:16 -0800 | [diff] [blame] | 33 | import com.android.launcher3.util.Themes; |
Mario Bertschler | ee4ee42 | 2016-12-27 15:41:24 -0800 | [diff] [blame] | 34 | |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 35 | /** |
| 36 | * The track and scrollbar that shows when you scroll the list. |
| 37 | */ |
| 38 | public class BaseRecyclerViewFastScrollBar { |
| 39 | |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 40 | private static final Property<BaseRecyclerViewFastScrollBar, Integer> TRACK_WIDTH = |
| 41 | new Property<BaseRecyclerViewFastScrollBar, Integer>(Integer.class, "width") { |
| 42 | |
| 43 | @Override |
| 44 | public Integer get(BaseRecyclerViewFastScrollBar scrollBar) { |
| 45 | return scrollBar.mWidth; |
| 46 | } |
| 47 | |
| 48 | @Override |
| 49 | public void set(BaseRecyclerViewFastScrollBar scrollBar, Integer value) { |
| 50 | scrollBar.setTrackWidth(value); |
| 51 | } |
| 52 | }; |
| 53 | |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 54 | private final static int MAX_TRACK_ALPHA = 30; |
| 55 | private final static int SCROLL_BAR_VIS_DURATION = 150; |
Sunny Goyal | 1a8f6fb | 2017-06-14 15:35:16 -0700 | [diff] [blame^] | 56 | private static final float FAST_SCROLL_OVERLAY_Y_OFFSET_FACTOR = 0.75f; |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 57 | |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 58 | private final Rect mTmpRect = new Rect(); |
| 59 | private final BaseRecyclerView mRv; |
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 boolean mIsRtl; |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 62 | |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 63 | // 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] | 64 | private final int mTouchInset; |
| 65 | |
| 66 | private final int mMinWidth; |
| 67 | private final int mMaxWidth; |
Sunny Goyal | 1a8f6fb | 2017-06-14 15:35:16 -0700 | [diff] [blame^] | 68 | private final int mThumbPadding; |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 69 | |
| 70 | // Current width of the track |
| 71 | private int mWidth; |
| 72 | private ObjectAnimator mWidthAnimator; |
| 73 | |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 74 | private final Paint mThumbPaint; |
| 75 | private final int mThumbHeight; |
| 76 | |
| 77 | private final Paint mTrackPaint; |
| 78 | |
| 79 | private float mLastTouchY; |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 80 | private boolean mIsDragging; |
Winson | d2eb49e | 2015-08-18 17:43:02 -0700 | [diff] [blame] | 81 | private boolean mIsThumbDetached; |
| 82 | private boolean mCanThumbDetach; |
Winson | ec4845b | 2015-08-27 10:19:48 -0700 | [diff] [blame] | 83 | private boolean mIgnoreDragGesture; |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 84 | |
| 85 | // This is the offset from the top of the scrollbar when the user first starts touching. To |
| 86 | // prevent jumping, this offset is applied as the user scrolls. |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 87 | private int mTouchOffsetY; |
| 88 | private int mThumbOffsetY; |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 89 | |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 90 | // Fast scroller popup |
| 91 | private TextView mPopupView; |
| 92 | private boolean mPopupVisible; |
| 93 | private String mPopupSectionName; |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 94 | |
| 95 | public BaseRecyclerViewFastScrollBar(BaseRecyclerView rv, Resources res) { |
| 96 | mRv = rv; |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 97 | mTrackPaint = new Paint(); |
Sunny Goyal | 1a8f6fb | 2017-06-14 15:35:16 -0700 | [diff] [blame^] | 98 | mTrackPaint.setColor(Themes.getAttrColor(rv.getContext(), android.R.attr.textColorPrimary)); |
Winson | 6779595 | 2015-08-20 12:23:52 -0700 | [diff] [blame] | 99 | mTrackPaint.setAlpha(MAX_TRACK_ALPHA); |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 100 | |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 101 | mThumbPaint = new Paint(); |
Winson | 6779595 | 2015-08-20 12:23:52 -0700 | [diff] [blame] | 102 | mThumbPaint.setAntiAlias(true); |
Sunny Goyal | 1f3f07d | 2017-02-10 16:52:16 -0800 | [diff] [blame] | 103 | mThumbPaint.setColor(Themes.getColorAccent(rv.getContext())); |
Winson | 6779595 | 2015-08-20 12:23:52 -0700 | [diff] [blame] | 104 | mThumbPaint.setStyle(Paint.Style.FILL); |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 105 | |
Sunny Goyal | 1a8f6fb | 2017-06-14 15:35:16 -0700 | [diff] [blame^] | 106 | mWidth = mMinWidth = res.getDimensionPixelSize(R.dimen.fastscroll_track_min_width); |
| 107 | mMaxWidth = res.getDimensionPixelSize(R.dimen.fastscroll_track_max_width); |
| 108 | |
| 109 | mThumbPadding = res.getDimensionPixelSize(R.dimen.fastscroll_thumb_padding); |
| 110 | mThumbHeight = res.getDimensionPixelSize(R.dimen.fastscroll_thumb_height); |
| 111 | |
| 112 | mTouchInset = res.getDimensionPixelSize(R.dimen.fastscroll_thumb_touch_inset); |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 113 | mIsRtl = Utilities.isRtl(res); |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | public void setPopupView(View popup) { |
| 117 | mPopupView = (TextView) popup; |
Sunny Goyal | 1a8f6fb | 2017-06-14 15:35:16 -0700 | [diff] [blame^] | 118 | mPopupView.setBackground(new FastScrollThumbDrawable(mThumbPaint, mIsRtl)); |
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); |
Sunny Goyal | dc19a07 | 2017-05-12 08:17:35 -0700 | [diff] [blame] | 143 | mTmpRect.offset(0, mRv.getPaddingTop()); |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 144 | mRv.invalidate(mTmpRect); |
| 145 | } |
| 146 | |
| 147 | public int getThumbOffsetY() { |
| 148 | return mThumbOffsetY; |
| 149 | } |
| 150 | |
| 151 | private void setTrackWidth(int width) { |
| 152 | if (mWidth == width) { |
| 153 | return; |
| 154 | } |
| 155 | int left = getDrawLeft(); |
Sunny Goyal | dc19a07 | 2017-05-12 08:17:35 -0700 | [diff] [blame] | 156 | int top = mRv.getPaddingTop(); |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 157 | // Invalidate the whole scroll bar area. |
Sunny Goyal | dc19a07 | 2017-05-12 08:17:35 -0700 | [diff] [blame] | 158 | mRv.invalidate(left, top, left + mMaxWidth, top + mRv.getScrollbarTrackHeight()); |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 159 | |
| 160 | mWidth = width; |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | public int getThumbHeight() { |
| 164 | return mThumbHeight; |
| 165 | } |
| 166 | |
Winson | d2eb49e | 2015-08-18 17:43:02 -0700 | [diff] [blame] | 167 | public boolean isDraggingThumb() { |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 168 | return mIsDragging; |
| 169 | } |
| 170 | |
Winson | d2eb49e | 2015-08-18 17:43:02 -0700 | [diff] [blame] | 171 | public boolean isThumbDetached() { |
| 172 | return mIsThumbDetached; |
| 173 | } |
| 174 | |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 175 | /** |
| 176 | * Handles the touch event and determines whether to show the fast scroller (or updates it if |
| 177 | * it is already showing). |
| 178 | */ |
| 179 | public void handleTouchEvent(MotionEvent ev, int downX, int downY, int lastY) { |
| 180 | ViewConfiguration config = ViewConfiguration.get(mRv.getContext()); |
| 181 | |
| 182 | int action = ev.getAction(); |
| 183 | int y = (int) ev.getY(); |
| 184 | switch (action) { |
| 185 | case MotionEvent.ACTION_DOWN: |
Winson | ec4845b | 2015-08-27 10:19:48 -0700 | [diff] [blame] | 186 | if (isNearThumb(downX, downY)) { |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 187 | mTouchOffsetY = downY - mThumbOffsetY; |
Mario Bertschler | ee4ee42 | 2016-12-27 15:41:24 -0800 | [diff] [blame] | 188 | } else if (FeatureFlags.LAUNCHER3_DIRECT_SCROLL |
| 189 | && mRv.supportsFastScrolling() |
| 190 | && isNearScrollBar(downX)) { |
| 191 | calcTouchOffsetAndPrepToFastScroll(downY, lastY); |
| 192 | updateFastScrollSectionNameAndThumbOffset(lastY, y); |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 193 | } |
| 194 | break; |
| 195 | case MotionEvent.ACTION_MOVE: |
Winson | ec4845b | 2015-08-27 10:19:48 -0700 | [diff] [blame] | 196 | // Check if we should start scrolling, but ignore this fastscroll gesture if we have |
| 197 | // exceeded some fixed movement |
| 198 | mIgnoreDragGesture |= Math.abs(y - downY) > config.getScaledPagingTouchSlop(); |
Winson | 646c236 | 2015-09-03 11:46:11 -0700 | [diff] [blame] | 199 | if (!mIsDragging && !mIgnoreDragGesture && mRv.supportsFastScrolling() && |
| 200 | isNearThumb(downX, lastY) && |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 201 | Math.abs(y - downY) > config.getScaledTouchSlop()) { |
Mario Bertschler | ee4ee42 | 2016-12-27 15:41:24 -0800 | [diff] [blame] | 202 | calcTouchOffsetAndPrepToFastScroll(downY, lastY); |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 203 | } |
| 204 | if (mIsDragging) { |
Mario Bertschler | ee4ee42 | 2016-12-27 15:41:24 -0800 | [diff] [blame] | 205 | updateFastScrollSectionNameAndThumbOffset(lastY, y); |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 206 | } |
| 207 | break; |
| 208 | case MotionEvent.ACTION_UP: |
| 209 | case MotionEvent.ACTION_CANCEL: |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 210 | mTouchOffsetY = 0; |
Winson | d2eb49e | 2015-08-18 17:43:02 -0700 | [diff] [blame] | 211 | mLastTouchY = 0; |
Winson | ec4845b | 2015-08-27 10:19:48 -0700 | [diff] [blame] | 212 | mIgnoreDragGesture = false; |
Winson Chung | 4c7fc62 | 2015-06-24 16:59:31 -0700 | [diff] [blame] | 213 | if (mIsDragging) { |
| 214 | mIsDragging = false; |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 215 | animatePopupVisibility(false); |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 216 | showActiveScrollbar(false); |
Winson Chung | 4c7fc62 | 2015-06-24 16:59:31 -0700 | [diff] [blame] | 217 | } |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 218 | break; |
| 219 | } |
| 220 | } |
| 221 | |
Mario Bertschler | ee4ee42 | 2016-12-27 15:41:24 -0800 | [diff] [blame] | 222 | private void calcTouchOffsetAndPrepToFastScroll(int downY, int lastY) { |
| 223 | mRv.getParent().requestDisallowInterceptTouchEvent(true); |
| 224 | mIsDragging = true; |
| 225 | if (mCanThumbDetach) { |
| 226 | mIsThumbDetached = true; |
| 227 | } |
| 228 | mTouchOffsetY += (lastY - downY); |
| 229 | animatePopupVisibility(true); |
| 230 | showActiveScrollbar(true); |
| 231 | } |
| 232 | |
| 233 | private void updateFastScrollSectionNameAndThumbOffset(int lastY, int y) { |
| 234 | // Update the fastscroller section name at this touch position |
| 235 | int bottom = mRv.getScrollbarTrackHeight() - mThumbHeight; |
| 236 | float boundedY = (float) Math.max(0, Math.min(bottom, y - mTouchOffsetY)); |
| 237 | String sectionName = mRv.scrollToPositionAtProgress(boundedY / bottom); |
| 238 | if (!sectionName.equals(mPopupSectionName)) { |
| 239 | mPopupSectionName = sectionName; |
| 240 | mPopupView.setText(sectionName); |
| 241 | } |
| 242 | animatePopupVisibility(!sectionName.isEmpty()); |
| 243 | updatePopupY(lastY); |
| 244 | mLastTouchY = boundedY; |
| 245 | setThumbOffsetY((int) mLastTouchY); |
| 246 | } |
| 247 | |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 248 | public void draw(Canvas canvas) { |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 249 | if (mThumbOffsetY < 0) { |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 250 | return; |
| 251 | } |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 252 | int saveCount = canvas.save(Canvas.MATRIX_SAVE_FLAG); |
| 253 | if (!mIsRtl) { |
Sunny Goyal | 1a8f6fb | 2017-06-14 15:35:16 -0700 | [diff] [blame^] | 254 | canvas.translate(mRv.getWidth() - mWidth, 0); |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 255 | } |
Sunny Goyal | dc19a07 | 2017-05-12 08:17:35 -0700 | [diff] [blame] | 256 | canvas.translate(0, mRv.getPaddingTop()); |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 257 | // Draw the track |
Sunny Goyal | 1a8f6fb | 2017-06-14 15:35:16 -0700 | [diff] [blame^] | 258 | canvas.drawRoundRect(0, 0, mWidth, mRv.getScrollbarTrackHeight(), |
| 259 | mWidth, mWidth, mTrackPaint); |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 260 | |
Sunny Goyal | 1a8f6fb | 2017-06-14 15:35:16 -0700 | [diff] [blame^] | 261 | canvas.translate(-mThumbPadding, mThumbOffsetY); |
| 262 | float r = mWidth + mThumbPadding + mThumbPadding; |
| 263 | canvas.drawRoundRect(0, 0, r, mThumbHeight, r, r, mThumbPaint); |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 264 | canvas.restoreToCount(saveCount); |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | /** |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 268 | * Animates the width of the scrollbar. |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 269 | */ |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 270 | private void showActiveScrollbar(boolean isScrolling) { |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 271 | if (mWidthAnimator != null) { |
| 272 | mWidthAnimator.cancel(); |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 273 | } |
Winson | 6779595 | 2015-08-20 12:23:52 -0700 | [diff] [blame] | 274 | |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 275 | mWidthAnimator = ObjectAnimator.ofInt(this, TRACK_WIDTH, |
| 276 | isScrolling ? mMaxWidth : mMinWidth); |
| 277 | mWidthAnimator.setDuration(SCROLL_BAR_VIS_DURATION); |
| 278 | mWidthAnimator.start(); |
Winson | 6779595 | 2015-08-20 12:23:52 -0700 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | /** |
Mario Bertschler | ee4ee42 | 2016-12-27 15:41:24 -0800 | [diff] [blame] | 282 | * Returns whether the specified point is inside the thumb bounds. |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 283 | */ |
Hyunyoung Song | f4cbb14 | 2016-06-10 12:00:02 -0700 | [diff] [blame] | 284 | public boolean isNearThumb(int x, int y) { |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 285 | int left = getDrawLeft(); |
| 286 | mTmpRect.set(left, mThumbOffsetY, left + mMaxWidth, mThumbOffsetY + mThumbHeight); |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 287 | mTmpRect.inset(mTouchInset, mTouchInset); |
| 288 | return mTmpRect.contains(x, y); |
| 289 | } |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 290 | |
Mario Bertschler | ee4ee42 | 2016-12-27 15:41:24 -0800 | [diff] [blame] | 291 | /** |
| 292 | * Returns whether the specified x position is near the scroll bar. |
| 293 | */ |
| 294 | public boolean isNearScrollBar(int x) { |
| 295 | int left = getDrawLeft(); |
| 296 | return x >= left && x <= left + mMaxWidth; |
| 297 | } |
| 298 | |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 299 | private void animatePopupVisibility(boolean visible) { |
| 300 | if (mPopupVisible != visible) { |
| 301 | mPopupVisible = visible; |
| 302 | mPopupView.animate().cancel(); |
| 303 | mPopupView.animate().alpha(visible ? 1f : 0f).setDuration(visible ? 200 : 150).start(); |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | private void updatePopupY(int lastTouchY) { |
| 308 | int height = mPopupView.getHeight(); |
| 309 | float top = lastTouchY - (FAST_SCROLL_OVERLAY_Y_OFFSET_FACTOR * height); |
Sunny Goyal | 1a8f6fb | 2017-06-14 15:35:16 -0700 | [diff] [blame^] | 310 | top = Utilities.boundToRange(top, |
| 311 | mMaxWidth, mRv.getScrollbarTrackHeight() - mMaxWidth - height); |
Sunny Goyal | 5d9fb0e | 2016-10-08 17:43:48 -0700 | [diff] [blame] | 312 | mPopupView.setTranslationY(top); |
| 313 | } |
Winson Chung | b177744 | 2015-06-16 13:35:04 -0700 | [diff] [blame] | 314 | } |