The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 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 | |
| 17 | package android.widget; |
| 18 | |
Alan Viverette | f6d87ec | 2016-03-11 10:09:14 -0500 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Nader Jawad | 93aeba8 | 2019-02-04 16:42:26 -0800 | [diff] [blame] | 20 | import android.annotation.Nullable; |
Artur Satayev | ed5a6ae | 2019-12-10 17:47:54 +0000 | [diff] [blame] | 21 | import android.compat.annotation.UnsupportedAppUsage; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.graphics.Canvas; |
| 23 | import android.graphics.ColorFilter; |
| 24 | import android.graphics.PixelFormat; |
| 25 | import android.graphics.Rect; |
| 26 | import android.graphics.drawable.Drawable; |
Nader Jawad | 93aeba8 | 2019-02-04 16:42:26 -0800 | [diff] [blame] | 27 | import android.os.Build; |
| 28 | import android.view.View; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | |
Aurimas Liutikas | 99441c5 | 2016-10-11 16:48:32 -0700 | [diff] [blame] | 30 | import com.android.internal.widget.ScrollBarUtils; |
| 31 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | /** |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 33 | * This is only used by View for displaying its scroll bars. It should probably |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | * be moved in to the view package since it is used in that lower-level layer. |
| 35 | * For now, we'll hide it so it can be cleaned up later. |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 36 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | * {@hide} |
| 38 | */ |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 39 | public class ScrollBarDrawable extends Drawable implements Drawable.Callback { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | private Drawable mVerticalTrack; |
| 41 | private Drawable mHorizontalTrack; |
Nader Jawad | 93aeba8 | 2019-02-04 16:42:26 -0800 | [diff] [blame] | 42 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 123768422) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | private Drawable mVerticalThumb; |
| 44 | private Drawable mHorizontalThumb; |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 45 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | private int mRange; |
| 47 | private int mOffset; |
| 48 | private int mExtent; |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 49 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | private boolean mVertical; |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 51 | private boolean mBoundsChanged; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | private boolean mRangeChanged; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | private boolean mAlwaysDrawHorizontalTrack; |
| 54 | private boolean mAlwaysDrawVerticalTrack; |
Alan Viverette | f8512ce | 2015-02-05 15:58:56 -0800 | [diff] [blame] | 55 | private boolean mMutated; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 57 | private int mAlpha = 255; |
| 58 | private boolean mHasSetAlpha; |
| 59 | |
| 60 | private ColorFilter mColorFilter; |
| 61 | private boolean mHasSetColorFilter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | |
Artur Satayev | 751e551 | 2019-11-15 19:12:49 +0000 | [diff] [blame] | 63 | @UnsupportedAppUsage |
| 64 | public ScrollBarDrawable() { |
| 65 | } |
| 66 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | /** |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 68 | * Indicate whether the horizontal scrollbar track should always be drawn |
| 69 | * regardless of the extent. Defaults to false. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | * |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 71 | * @param alwaysDrawTrack Whether the track should always be drawn |
| 72 | * |
| 73 | * @see #getAlwaysDrawHorizontalTrack() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | */ |
| 75 | public void setAlwaysDrawHorizontalTrack(boolean alwaysDrawTrack) { |
| 76 | mAlwaysDrawHorizontalTrack = alwaysDrawTrack; |
| 77 | } |
| 78 | |
| 79 | /** |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 80 | * Indicate whether the vertical scrollbar track should always be drawn |
| 81 | * regardless of the extent. Defaults to false. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | * |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 83 | * @param alwaysDrawTrack Whether the track should always be drawn |
| 84 | * |
| 85 | * @see #getAlwaysDrawVerticalTrack() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | */ |
| 87 | public void setAlwaysDrawVerticalTrack(boolean alwaysDrawTrack) { |
| 88 | mAlwaysDrawVerticalTrack = alwaysDrawTrack; |
| 89 | } |
| 90 | |
| 91 | /** |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 92 | * @return whether the vertical scrollbar track should always be drawn |
| 93 | * regardless of the extent. |
| 94 | * |
| 95 | * @see #setAlwaysDrawVerticalTrack(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | */ |
| 97 | public boolean getAlwaysDrawVerticalTrack() { |
| 98 | return mAlwaysDrawVerticalTrack; |
| 99 | } |
| 100 | |
| 101 | /** |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 102 | * @return whether the horizontal scrollbar track should always be drawn |
| 103 | * regardless of the extent. |
| 104 | * |
| 105 | * @see #setAlwaysDrawHorizontalTrack(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | */ |
| 107 | public boolean getAlwaysDrawHorizontalTrack() { |
| 108 | return mAlwaysDrawHorizontalTrack; |
| 109 | } |
| 110 | |
| 111 | public void setParameters(int range, int offset, int extent, boolean vertical) { |
| 112 | if (mVertical != vertical) { |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 113 | mVertical = vertical; |
| 114 | |
| 115 | mBoundsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | if (mRange != range || mOffset != offset || mExtent != extent) { |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 119 | mRange = range; |
| 120 | mOffset = offset; |
| 121 | mExtent = extent; |
| 122 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | mRangeChanged = true; |
| 124 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | @Override |
| 128 | public void draw(Canvas canvas) { |
| 129 | final boolean vertical = mVertical; |
| 130 | final int extent = mExtent; |
| 131 | final int range = mRange; |
| 132 | |
| 133 | boolean drawTrack = true; |
| 134 | boolean drawThumb = true; |
| 135 | if (extent <= 0 || range <= extent) { |
| 136 | drawTrack = vertical ? mAlwaysDrawVerticalTrack : mAlwaysDrawHorizontalTrack; |
| 137 | drawThumb = false; |
| 138 | } |
| 139 | |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 140 | final Rect r = getBounds(); |
Romain Guy | 8fb9542 | 2010-08-17 18:38:51 -0700 | [diff] [blame] | 141 | if (canvas.quickReject(r.left, r.top, r.right, r.bottom, Canvas.EdgeType.AA)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | return; |
| 143 | } |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 144 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | if (drawTrack) { |
| 146 | drawTrack(canvas, r, vertical); |
| 147 | } |
| 148 | |
| 149 | if (drawThumb) { |
Keisuke Kuroyanagi | d85bc50 | 2016-01-21 14:50:38 +0900 | [diff] [blame] | 150 | final int scrollBarLength = vertical ? r.height() : r.width(); |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 151 | final int thickness = vertical ? r.width() : r.height(); |
Keisuke Kuroyanagi | d85bc50 | 2016-01-21 14:50:38 +0900 | [diff] [blame] | 152 | final int thumbLength = |
| 153 | ScrollBarUtils.getThumbLength(scrollBarLength, thickness, extent, range); |
| 154 | final int thumbOffset = |
| 155 | ScrollBarUtils.getThumbOffset(scrollBarLength, thumbLength, extent, range, |
| 156 | mOffset); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | |
Keisuke Kuroyanagi | d85bc50 | 2016-01-21 14:50:38 +0900 | [diff] [blame] | 158 | drawThumb(canvas, r, thumbOffset, thumbLength, vertical); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | } |
| 160 | } |
| 161 | |
| 162 | @Override |
| 163 | protected void onBoundsChange(Rect bounds) { |
| 164 | super.onBoundsChange(bounds); |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 165 | mBoundsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | } |
| 167 | |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 168 | @Override |
| 169 | public boolean isStateful() { |
| 170 | return (mVerticalTrack != null && mVerticalTrack.isStateful()) |
| 171 | || (mVerticalThumb != null && mVerticalThumb.isStateful()) |
| 172 | || (mHorizontalTrack != null && mHorizontalTrack.isStateful()) |
| 173 | || (mHorizontalThumb != null && mHorizontalThumb.isStateful()) |
| 174 | || super.isStateful(); |
| 175 | } |
| 176 | |
| 177 | @Override |
| 178 | protected boolean onStateChange(int[] state) { |
| 179 | boolean changed = super.onStateChange(state); |
| 180 | if (mVerticalTrack != null) { |
| 181 | changed |= mVerticalTrack.setState(state); |
| 182 | } |
| 183 | if (mVerticalThumb != null) { |
| 184 | changed |= mVerticalThumb.setState(state); |
| 185 | } |
| 186 | if (mHorizontalTrack != null) { |
| 187 | changed |= mHorizontalTrack.setState(state); |
| 188 | } |
| 189 | if (mHorizontalThumb != null) { |
| 190 | changed |= mHorizontalThumb.setState(state); |
| 191 | } |
| 192 | return changed; |
| 193 | } |
| 194 | |
| 195 | private void drawTrack(Canvas canvas, Rect bounds, boolean vertical) { |
| 196 | final Drawable track; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 197 | if (vertical) { |
| 198 | track = mVerticalTrack; |
| 199 | } else { |
| 200 | track = mHorizontalTrack; |
| 201 | } |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 202 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 203 | if (track != null) { |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 204 | if (mBoundsChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 205 | track.setBounds(bounds); |
| 206 | } |
| 207 | track.draw(canvas); |
| 208 | } |
| 209 | } |
| 210 | |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 211 | private void drawThumb(Canvas canvas, Rect bounds, int offset, int length, boolean vertical) { |
| 212 | final boolean changed = mRangeChanged || mBoundsChanged; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 213 | if (vertical) { |
Chet Haase | 6c8fef7 | 2014-06-27 16:49:05 -0700 | [diff] [blame] | 214 | if (mVerticalThumb != null) { |
| 215 | final Drawable thumb = mVerticalThumb; |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 216 | if (changed) { |
| 217 | thumb.setBounds(bounds.left, bounds.top + offset, |
| 218 | bounds.right, bounds.top + offset + length); |
| 219 | } |
| 220 | |
Chet Haase | 6c8fef7 | 2014-06-27 16:49:05 -0700 | [diff] [blame] | 221 | thumb.draw(canvas); |
| 222 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 223 | } else { |
Chet Haase | 6c8fef7 | 2014-06-27 16:49:05 -0700 | [diff] [blame] | 224 | if (mHorizontalThumb != null) { |
| 225 | final Drawable thumb = mHorizontalThumb; |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 226 | if (changed) { |
| 227 | thumb.setBounds(bounds.left + offset, bounds.top, |
| 228 | bounds.left + offset + length, bounds.bottom); |
| 229 | } |
| 230 | |
Chet Haase | 6c8fef7 | 2014-06-27 16:49:05 -0700 | [diff] [blame] | 231 | thumb.draw(canvas); |
| 232 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | |
Nader Jawad | 93aeba8 | 2019-02-04 16:42:26 -0800 | [diff] [blame] | 236 | /** |
| 237 | * @see android.view.View#setVerticalThumbDrawable(Drawable) |
| 238 | */ |
| 239 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 240 | public void setVerticalThumbDrawable(Drawable thumb) { |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 241 | if (mVerticalThumb != null) { |
| 242 | mVerticalThumb.setCallback(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | } |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 244 | |
| 245 | propagateCurrentState(thumb); |
| 246 | mVerticalThumb = thumb; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 247 | } |
| 248 | |
Nader Jawad | 93aeba8 | 2019-02-04 16:42:26 -0800 | [diff] [blame] | 249 | /** |
| 250 | * @see View#getVerticalTrackDrawable() |
| 251 | */ |
| 252 | public @Nullable Drawable getVerticalTrackDrawable() { |
| 253 | return mVerticalTrack; |
| 254 | } |
| 255 | |
| 256 | /** |
| 257 | * @see View#getVerticalThumbDrawable() |
| 258 | */ |
| 259 | public @Nullable Drawable getVerticalThumbDrawable() { |
| 260 | return mVerticalThumb; |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * @see View#getHorizontalTrackDrawable() |
| 265 | */ |
| 266 | public @Nullable Drawable getHorizontalTrackDrawable() { |
| 267 | return mHorizontalTrack; |
| 268 | } |
| 269 | |
| 270 | /** |
| 271 | * @see View#getHorizontalThumbDrawable() |
| 272 | */ |
| 273 | public @Nullable Drawable getHorizontalThumbDrawable() { |
| 274 | return mHorizontalThumb; |
| 275 | } |
| 276 | |
| 277 | /** |
| 278 | * @see android.view.View#setVerticalTrackDrawable(Drawable) |
| 279 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 280 | public void setVerticalTrackDrawable(Drawable track) { |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 281 | if (mVerticalTrack != null) { |
| 282 | mVerticalTrack.setCallback(null); |
Alan Viverette | 03748a5 | 2015-01-15 13:00:21 -0800 | [diff] [blame] | 283 | } |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 284 | |
| 285 | propagateCurrentState(track); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 286 | mVerticalTrack = track; |
| 287 | } |
| 288 | |
Nader Jawad | 93aeba8 | 2019-02-04 16:42:26 -0800 | [diff] [blame] | 289 | /** |
| 290 | * @see android.view.View#setHorizontalThumbDrawable(Drawable) |
| 291 | */ |
| 292 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 293 | public void setHorizontalThumbDrawable(Drawable thumb) { |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 294 | if (mHorizontalThumb != null) { |
| 295 | mHorizontalThumb.setCallback(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 296 | } |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 297 | |
| 298 | propagateCurrentState(thumb); |
| 299 | mHorizontalThumb = thumb; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | public void setHorizontalTrackDrawable(Drawable track) { |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 303 | if (mHorizontalTrack != null) { |
| 304 | mHorizontalTrack.setCallback(null); |
Alan Viverette | 03748a5 | 2015-01-15 13:00:21 -0800 | [diff] [blame] | 305 | } |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 306 | |
| 307 | propagateCurrentState(track); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 308 | mHorizontalTrack = track; |
| 309 | } |
| 310 | |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 311 | private void propagateCurrentState(Drawable d) { |
| 312 | if (d != null) { |
Alan Viverette | b989c55 | 2015-02-05 17:10:47 -0800 | [diff] [blame] | 313 | if (mMutated) { |
| 314 | d.mutate(); |
| 315 | } |
| 316 | |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 317 | d.setState(getState()); |
| 318 | d.setCallback(this); |
| 319 | |
| 320 | if (mHasSetAlpha) { |
| 321 | d.setAlpha(mAlpha); |
| 322 | } |
| 323 | |
| 324 | if (mHasSetColorFilter) { |
| 325 | d.setColorFilter(mColorFilter); |
| 326 | } |
| 327 | } |
| 328 | } |
| 329 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 330 | public int getSize(boolean vertical) { |
| 331 | if (vertical) { |
Chet Haase | 6c8fef7 | 2014-06-27 16:49:05 -0700 | [diff] [blame] | 332 | return mVerticalTrack != null ? mVerticalTrack.getIntrinsicWidth() : |
| 333 | mVerticalThumb != null ? mVerticalThumb.getIntrinsicWidth() : 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 334 | } else { |
Chet Haase | 6c8fef7 | 2014-06-27 16:49:05 -0700 | [diff] [blame] | 335 | return mHorizontalTrack != null ? mHorizontalTrack.getIntrinsicHeight() : |
| 336 | mHorizontalThumb != null ? mHorizontalThumb.getIntrinsicHeight() : 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 337 | } |
| 338 | } |
| 339 | |
| 340 | @Override |
Alan Viverette | f8512ce | 2015-02-05 15:58:56 -0800 | [diff] [blame] | 341 | public ScrollBarDrawable mutate() { |
| 342 | if (!mMutated && super.mutate() == this) { |
| 343 | if (mVerticalTrack != null) { |
| 344 | mVerticalTrack.mutate(); |
| 345 | } |
| 346 | if (mVerticalThumb != null) { |
| 347 | mVerticalThumb.mutate(); |
| 348 | } |
| 349 | if (mHorizontalTrack != null) { |
| 350 | mHorizontalTrack.mutate(); |
| 351 | } |
| 352 | if (mHorizontalThumb != null) { |
| 353 | mHorizontalThumb.mutate(); |
| 354 | } |
| 355 | mMutated = true; |
| 356 | } |
| 357 | return this; |
| 358 | } |
| 359 | |
| 360 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 361 | public void setAlpha(int alpha) { |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 362 | mAlpha = alpha; |
| 363 | mHasSetAlpha = true; |
| 364 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 365 | if (mVerticalTrack != null) { |
| 366 | mVerticalTrack.setAlpha(alpha); |
| 367 | } |
Chet Haase | 6c8fef7 | 2014-06-27 16:49:05 -0700 | [diff] [blame] | 368 | if (mVerticalThumb != null) { |
| 369 | mVerticalThumb.setAlpha(alpha); |
| 370 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 371 | if (mHorizontalTrack != null) { |
| 372 | mHorizontalTrack.setAlpha(alpha); |
| 373 | } |
Chet Haase | 6c8fef7 | 2014-06-27 16:49:05 -0700 | [diff] [blame] | 374 | if (mHorizontalThumb != null) { |
| 375 | mHorizontalThumb.setAlpha(alpha); |
| 376 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | @Override |
Chet Haase | b1af7f3 | 2013-03-08 14:02:04 -0800 | [diff] [blame] | 380 | public int getAlpha() { |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 381 | return mAlpha; |
Chet Haase | b1af7f3 | 2013-03-08 14:02:04 -0800 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | @Override |
Chris Craik | bd3bfc5 | 2015-03-02 10:43:29 -0800 | [diff] [blame] | 385 | public void setColorFilter(ColorFilter colorFilter) { |
| 386 | mColorFilter = colorFilter; |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 387 | mHasSetColorFilter = true; |
| 388 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 389 | if (mVerticalTrack != null) { |
Chris Craik | bd3bfc5 | 2015-03-02 10:43:29 -0800 | [diff] [blame] | 390 | mVerticalTrack.setColorFilter(colorFilter); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 391 | } |
Chet Haase | 6c8fef7 | 2014-06-27 16:49:05 -0700 | [diff] [blame] | 392 | if (mVerticalThumb != null) { |
Chris Craik | bd3bfc5 | 2015-03-02 10:43:29 -0800 | [diff] [blame] | 393 | mVerticalThumb.setColorFilter(colorFilter); |
Chet Haase | 6c8fef7 | 2014-06-27 16:49:05 -0700 | [diff] [blame] | 394 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 395 | if (mHorizontalTrack != null) { |
Chris Craik | bd3bfc5 | 2015-03-02 10:43:29 -0800 | [diff] [blame] | 396 | mHorizontalTrack.setColorFilter(colorFilter); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 397 | } |
Chet Haase | 6c8fef7 | 2014-06-27 16:49:05 -0700 | [diff] [blame] | 398 | if (mHorizontalThumb != null) { |
Chris Craik | bd3bfc5 | 2015-03-02 10:43:29 -0800 | [diff] [blame] | 399 | mHorizontalThumb.setColorFilter(colorFilter); |
Chet Haase | 6c8fef7 | 2014-06-27 16:49:05 -0700 | [diff] [blame] | 400 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | @Override |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 404 | public ColorFilter getColorFilter() { |
| 405 | return mColorFilter; |
| 406 | } |
| 407 | |
| 408 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 409 | public int getOpacity() { |
| 410 | return PixelFormat.TRANSLUCENT; |
| 411 | } |
| 412 | |
| 413 | @Override |
Alan Viverette | f6d87ec | 2016-03-11 10:09:14 -0500 | [diff] [blame] | 414 | public void invalidateDrawable(@NonNull Drawable who) { |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 415 | invalidateSelf(); |
| 416 | } |
| 417 | |
| 418 | @Override |
Alan Viverette | f6d87ec | 2016-03-11 10:09:14 -0500 | [diff] [blame] | 419 | public void scheduleDrawable(@NonNull Drawable who, @NonNull Runnable what, long when) { |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 420 | scheduleSelf(what, when); |
| 421 | } |
| 422 | |
| 423 | @Override |
Alan Viverette | f6d87ec | 2016-03-11 10:09:14 -0500 | [diff] [blame] | 424 | public void unscheduleDrawable(@NonNull Drawable who, @NonNull Runnable what) { |
Alan Viverette | 029d039 | 2015-01-21 15:41:53 -0800 | [diff] [blame] | 425 | unscheduleSelf(what); |
| 426 | } |
| 427 | |
| 428 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 429 | public String toString() { |
| 430 | return "ScrollBarDrawable: range=" + mRange + " offset=" + mOffset + |
| 431 | " extent=" + mExtent + (mVertical ? " V" : " H"); |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | |