The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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 | |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 17 | package com.android.launcher3; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 18 | |
Sunny Goyal | 726bee7 | 2018-03-05 12:54:24 -0800 | [diff] [blame] | 19 | import static com.android.launcher3.anim.Interpolators.ACCEL; |
Hyunyoung Song | ef468d8 | 2019-01-03 01:02:43 -0800 | [diff] [blame] | 20 | import static com.android.launcher3.anim.Interpolators.DEACCEL; |
Sunny Goyal | 726bee7 | 2018-03-05 12:54:24 -0800 | [diff] [blame] | 21 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 22 | import android.animation.ObjectAnimator; |
Sunny Goyal | 1416843 | 2019-10-24 15:59:49 -0700 | [diff] [blame] | 23 | import android.content.Context; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 24 | import android.graphics.Bitmap; |
| 25 | import android.graphics.Canvas; |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 26 | import android.graphics.Color; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 27 | import android.graphics.ColorFilter; |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 28 | import android.graphics.ColorMatrix; |
| 29 | import android.graphics.ColorMatrixColorFilter; |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 30 | import android.graphics.Paint; |
| 31 | import android.graphics.PixelFormat; |
Sunny Goyal | 726bee7 | 2018-03-05 12:54:24 -0800 | [diff] [blame] | 32 | import android.graphics.Rect; |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 33 | import android.graphics.drawable.Drawable; |
Tony Wickham | 1e61849 | 2017-02-02 12:57:18 -0800 | [diff] [blame] | 34 | import android.util.Property; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 35 | |
Sunny Goyal | 1416843 | 2019-10-24 15:59:49 -0700 | [diff] [blame] | 36 | import com.android.launcher3.graphics.PlaceHolderIconDrawable; |
Hyunyoung Song | 48cb7bc | 2018-09-25 17:03:34 -0700 | [diff] [blame] | 37 | import com.android.launcher3.icons.BitmapInfo; |
Tony Wickham | 9a8d11f | 2017-01-11 09:53:12 -0800 | [diff] [blame] | 38 | |
Samuel Fufa | 61d3964 | 2020-01-23 12:42:06 -0800 | [diff] [blame] | 39 | |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 40 | public class FastBitmapDrawable extends Drawable { |
Sunny Goyal | 2a76e3f | 2017-02-16 13:33:15 -0800 | [diff] [blame] | 41 | |
Sunny Goyal | 726bee7 | 2018-03-05 12:54:24 -0800 | [diff] [blame] | 42 | private static final float PRESSED_SCALE = 1.1f; |
| 43 | |
Tony Wickham | 6b910a2 | 2016-11-08 10:40:34 -0800 | [diff] [blame] | 44 | private static final float DISABLED_DESATURATION = 1f; |
| 45 | private static final float DISABLED_BRIGHTNESS = 0.5f; |
Samuel Fufa | 61d3964 | 2020-01-23 12:42:06 -0800 | [diff] [blame] | 46 | private static final float DISABLED_ALPHA = 0.54f; |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 47 | |
Sunny Goyal | 726bee7 | 2018-03-05 12:54:24 -0800 | [diff] [blame] | 48 | public static final int CLICK_FEEDBACK_DURATION = 200; |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 49 | |
Samuel Fufa | 61d3964 | 2020-01-23 12:42:06 -0800 | [diff] [blame] | 50 | private static ColorFilter sDisabledFColorFilter; |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 51 | |
Sunny Goyal | 55cb70b | 2016-11-12 09:58:29 -0800 | [diff] [blame] | 52 | protected final Paint mPaint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG); |
Sunny Goyal | 61e0846 | 2018-03-02 17:25:59 -0800 | [diff] [blame] | 53 | protected Bitmap mBitmap; |
Sunny Goyal | 179249d | 2017-12-19 16:49:24 -0800 | [diff] [blame] | 54 | protected final int mIconColor; |
Sunny Goyal | 2a76e3f | 2017-02-16 13:33:15 -0800 | [diff] [blame] | 55 | |
| 56 | private boolean mIsPressed; |
Tony Wickham | 6b910a2 | 2016-11-08 10:40:34 -0800 | [diff] [blame] | 57 | private boolean mIsDisabled; |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 58 | |
Sunny Goyal | 726bee7 | 2018-03-05 12:54:24 -0800 | [diff] [blame] | 59 | // Animator and properties for the fast bitmap drawable's scale |
| 60 | private static final Property<FastBitmapDrawable, Float> SCALE |
| 61 | = new Property<FastBitmapDrawable, Float>(Float.TYPE, "scale") { |
Sunny Goyal | 2a76e3f | 2017-02-16 13:33:15 -0800 | [diff] [blame] | 62 | @Override |
| 63 | public Float get(FastBitmapDrawable fastBitmapDrawable) { |
Sunny Goyal | 726bee7 | 2018-03-05 12:54:24 -0800 | [diff] [blame] | 64 | return fastBitmapDrawable.mScale; |
Sunny Goyal | 2a76e3f | 2017-02-16 13:33:15 -0800 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public void set(FastBitmapDrawable fastBitmapDrawable, Float value) { |
Sunny Goyal | 726bee7 | 2018-03-05 12:54:24 -0800 | [diff] [blame] | 69 | fastBitmapDrawable.mScale = value; |
| 70 | fastBitmapDrawable.invalidateSelf(); |
Sunny Goyal | 2a76e3f | 2017-02-16 13:33:15 -0800 | [diff] [blame] | 71 | } |
| 72 | }; |
Sunny Goyal | 726bee7 | 2018-03-05 12:54:24 -0800 | [diff] [blame] | 73 | private ObjectAnimator mScaleAnimation; |
| 74 | private float mScale = 1; |
| 75 | |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 76 | private int mAlpha = 255; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 77 | |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 78 | public FastBitmapDrawable(Bitmap b) { |
Sunny Goyal | 179249d | 2017-12-19 16:49:24 -0800 | [diff] [blame] | 79 | this(b, Color.TRANSPARENT); |
| 80 | } |
| 81 | |
| 82 | public FastBitmapDrawable(BitmapInfo info) { |
| 83 | this(info.icon, info.color); |
| 84 | } |
| 85 | |
Sunny Goyal | 179249d | 2017-12-19 16:49:24 -0800 | [diff] [blame] | 86 | protected FastBitmapDrawable(Bitmap b, int iconColor) { |
Jon Miranda | b6d686d | 2019-03-29 10:49:43 -0700 | [diff] [blame] | 87 | this(b, iconColor, false); |
| 88 | } |
| 89 | |
| 90 | protected FastBitmapDrawable(Bitmap b, int iconColor, boolean isDisabled) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 91 | mBitmap = b; |
Sunny Goyal | 179249d | 2017-12-19 16:49:24 -0800 | [diff] [blame] | 92 | mIconColor = iconColor; |
Sunny Goyal | 96ac68a | 2017-02-02 16:37:21 -0800 | [diff] [blame] | 93 | setFilterBitmap(true); |
Jon Miranda | b6d686d | 2019-03-29 10:49:43 -0700 | [diff] [blame] | 94 | setIsDisabled(isDisabled); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | @Override |
Sunny Goyal | 726bee7 | 2018-03-05 12:54:24 -0800 | [diff] [blame] | 98 | public final void draw(Canvas canvas) { |
Matthew Ng | eb9cc9d | 2018-06-25 15:32:24 -0700 | [diff] [blame] | 99 | if (mScale != 1f) { |
Sunny Goyal | 726bee7 | 2018-03-05 12:54:24 -0800 | [diff] [blame] | 100 | int count = canvas.save(); |
| 101 | Rect bounds = getBounds(); |
| 102 | canvas.scale(mScale, mScale, bounds.exactCenterX(), bounds.exactCenterY()); |
| 103 | drawInternal(canvas, bounds); |
| 104 | canvas.restoreToCount(count); |
| 105 | } else { |
| 106 | drawInternal(canvas, getBounds()); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | protected void drawInternal(Canvas canvas, Rect bounds) { |
| 111 | canvas.drawBitmap(mBitmap, null, bounds, mPaint); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | @Override |
Adam Cohen | badf71e | 2011-05-26 19:08:29 -0700 | [diff] [blame] | 115 | public void setColorFilter(ColorFilter cf) { |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 116 | // No op |
Adam Cohen | badf71e | 2011-05-26 19:08:29 -0700 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 120 | public int getOpacity() { |
| 121 | return PixelFormat.TRANSLUCENT; |
| 122 | } |
| 123 | |
| 124 | @Override |
| 125 | public void setAlpha(int alpha) { |
Jon Miranda | dff0de4 | 2019-08-30 18:42:01 -0700 | [diff] [blame] | 126 | if (mAlpha != alpha) { |
| 127 | mAlpha = alpha; |
| 128 | mPaint.setAlpha(alpha); |
| 129 | invalidateSelf(); |
| 130 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 131 | } |
| 132 | |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 133 | @Override |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 134 | public void setFilterBitmap(boolean filterBitmap) { |
| 135 | mPaint.setFilterBitmap(filterBitmap); |
Winson Chung | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 136 | mPaint.setAntiAlias(filterBitmap); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Winson Chung | 29d6fea | 2010-12-01 15:47:31 -0800 | [diff] [blame] | 139 | public int getAlpha() { |
| 140 | return mAlpha; |
| 141 | } |
| 142 | |
Matthew Ng | eb9cc9d | 2018-06-25 15:32:24 -0700 | [diff] [blame] | 143 | public void setScale(float scale) { |
| 144 | if (mScaleAnimation != null) { |
| 145 | mScaleAnimation.cancel(); |
| 146 | mScaleAnimation = null; |
| 147 | } |
| 148 | mScale = scale; |
| 149 | invalidateSelf(); |
| 150 | } |
| 151 | |
Sunny Goyal | 726bee7 | 2018-03-05 12:54:24 -0800 | [diff] [blame] | 152 | public float getAnimatedScale() { |
| 153 | return mScaleAnimation == null ? 1 : mScale; |
| 154 | } |
| 155 | |
Matthew Ng | eb9cc9d | 2018-06-25 15:32:24 -0700 | [diff] [blame] | 156 | public float getScale() { |
| 157 | return mScale; |
| 158 | } |
| 159 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 160 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 161 | public int getIntrinsicWidth() { |
Sunny Goyal | c424f22 | 2014-09-05 07:04:59 -0700 | [diff] [blame] | 162 | return mBitmap.getWidth(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | @Override |
| 166 | public int getIntrinsicHeight() { |
Sunny Goyal | c424f22 | 2014-09-05 07:04:59 -0700 | [diff] [blame] | 167 | return mBitmap.getHeight(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | @Override |
| 171 | public int getMinimumWidth() { |
Winson Chung | eeb5bbc | 2013-11-13 15:47:05 -0800 | [diff] [blame] | 172 | return getBounds().width(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | @Override |
| 176 | public int getMinimumHeight() { |
Winson Chung | eeb5bbc | 2013-11-13 15:47:05 -0800 | [diff] [blame] | 177 | return getBounds().height(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 178 | } |
| 179 | |
Sunny Goyal | 2a76e3f | 2017-02-16 13:33:15 -0800 | [diff] [blame] | 180 | @Override |
| 181 | public boolean isStateful() { |
| 182 | return true; |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 183 | } |
| 184 | |
Sunny Goyal | 2a76e3f | 2017-02-16 13:33:15 -0800 | [diff] [blame] | 185 | @Override |
Sunny Goyal | 2814112 | 2017-06-21 17:28:23 -0700 | [diff] [blame] | 186 | public ColorFilter getColorFilter() { |
| 187 | return mPaint.getColorFilter(); |
| 188 | } |
| 189 | |
| 190 | @Override |
Sunny Goyal | 2a76e3f | 2017-02-16 13:33:15 -0800 | [diff] [blame] | 191 | protected boolean onStateChange(int[] state) { |
| 192 | boolean isPressed = false; |
| 193 | for (int s : state) { |
| 194 | if (s == android.R.attr.state_pressed) { |
| 195 | isPressed = true; |
| 196 | break; |
| 197 | } |
| 198 | } |
| 199 | if (mIsPressed != isPressed) { |
| 200 | mIsPressed = isPressed; |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 201 | |
Sunny Goyal | 726bee7 | 2018-03-05 12:54:24 -0800 | [diff] [blame] | 202 | if (mScaleAnimation != null) { |
| 203 | mScaleAnimation.cancel(); |
| 204 | mScaleAnimation = null; |
Sunny Goyal | 2a76e3f | 2017-02-16 13:33:15 -0800 | [diff] [blame] | 205 | } |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 206 | |
Sunny Goyal | 2a76e3f | 2017-02-16 13:33:15 -0800 | [diff] [blame] | 207 | if (mIsPressed) { |
| 208 | // Animate when going to pressed state |
Sunny Goyal | 726bee7 | 2018-03-05 12:54:24 -0800 | [diff] [blame] | 209 | mScaleAnimation = ObjectAnimator.ofFloat(this, SCALE, PRESSED_SCALE); |
| 210 | mScaleAnimation.setDuration(CLICK_FEEDBACK_DURATION); |
| 211 | mScaleAnimation.setInterpolator(ACCEL); |
| 212 | mScaleAnimation.start(); |
Sunny Goyal | 2a76e3f | 2017-02-16 13:33:15 -0800 | [diff] [blame] | 213 | } else { |
Hyunyoung Song | ef468d8 | 2019-01-03 01:02:43 -0800 | [diff] [blame] | 214 | if (isVisible()) { |
| 215 | mScaleAnimation = ObjectAnimator.ofFloat(this, SCALE, 1f); |
| 216 | mScaleAnimation.setDuration(CLICK_FEEDBACK_DURATION); |
| 217 | mScaleAnimation.setInterpolator(DEACCEL); |
| 218 | mScaleAnimation.start(); |
| 219 | } else { |
| 220 | mScale = 1f; |
| 221 | invalidateSelf(); |
| 222 | } |
Sunny Goyal | 2a76e3f | 2017-02-16 13:33:15 -0800 | [diff] [blame] | 223 | } |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 224 | return true; |
| 225 | } |
| 226 | return false; |
| 227 | } |
| 228 | |
Tony Wickham | 6b910a2 | 2016-11-08 10:40:34 -0800 | [diff] [blame] | 229 | public void setIsDisabled(boolean isDisabled) { |
| 230 | if (mIsDisabled != isDisabled) { |
| 231 | mIsDisabled = isDisabled; |
Samuel Fufa | 61d3964 | 2020-01-23 12:42:06 -0800 | [diff] [blame] | 232 | updateFilter(); |
Tony Wickham | 6b910a2 | 2016-11-08 10:40:34 -0800 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | |
Jon Miranda | b6d686d | 2019-03-29 10:49:43 -0700 | [diff] [blame] | 236 | protected boolean isDisabled() { |
| 237 | return mIsDisabled; |
| 238 | } |
| 239 | |
Samuel Fufa | 61d3964 | 2020-01-23 12:42:06 -0800 | [diff] [blame] | 240 | private ColorFilter getDisabledColorFilter() { |
| 241 | if (sDisabledFColorFilter == null) { |
| 242 | ColorMatrix tempBrightnessMatrix = new ColorMatrix(); |
| 243 | ColorMatrix tempFilterMatrix = new ColorMatrix(); |
| 244 | |
| 245 | tempFilterMatrix.setSaturation(1f - DISABLED_DESATURATION); |
| 246 | float scale = 1 - DISABLED_BRIGHTNESS; |
| 247 | int brightnessI = (int) (255 * DISABLED_BRIGHTNESS); |
| 248 | float[] mat = tempBrightnessMatrix.getArray(); |
| 249 | mat[0] = scale; |
| 250 | mat[6] = scale; |
| 251 | mat[12] = scale; |
| 252 | mat[4] = brightnessI; |
| 253 | mat[9] = brightnessI; |
| 254 | mat[14] = brightnessI; |
| 255 | mat[18] = DISABLED_ALPHA; |
| 256 | tempFilterMatrix.preConcat(tempBrightnessMatrix); |
| 257 | sDisabledFColorFilter = new ColorMatrixColorFilter(tempFilterMatrix); |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 258 | } |
Samuel Fufa | 61d3964 | 2020-01-23 12:42:06 -0800 | [diff] [blame] | 259 | return sDisabledFColorFilter; |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | /** |
| 263 | * Updates the paint to reflect the current brightness and saturation. |
| 264 | */ |
Sunny Goyal | 0ffab44 | 2018-06-07 17:31:48 -0700 | [diff] [blame] | 265 | protected void updateFilter() { |
Samuel Fufa | 61d3964 | 2020-01-23 12:42:06 -0800 | [diff] [blame] | 266 | mPaint.setColorFilter(mIsDisabled ? getDisabledColorFilter() : null); |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 267 | invalidateSelf(); |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 268 | } |
Sunny Goyal | 338d15d | 2018-02-23 12:19:44 -0800 | [diff] [blame] | 269 | |
| 270 | @Override |
| 271 | public ConstantState getConstantState() { |
Jon Miranda | b6d686d | 2019-03-29 10:49:43 -0700 | [diff] [blame] | 272 | return new MyConstantState(mBitmap, mIconColor, mIsDisabled); |
Sunny Goyal | 338d15d | 2018-02-23 12:19:44 -0800 | [diff] [blame] | 273 | } |
| 274 | |
Sunny Goyal | 61e0846 | 2018-03-02 17:25:59 -0800 | [diff] [blame] | 275 | protected static class MyConstantState extends ConstantState { |
| 276 | protected final Bitmap mBitmap; |
| 277 | protected final int mIconColor; |
Jon Miranda | b6d686d | 2019-03-29 10:49:43 -0700 | [diff] [blame] | 278 | protected final boolean mIsDisabled; |
Sunny Goyal | 338d15d | 2018-02-23 12:19:44 -0800 | [diff] [blame] | 279 | |
Jon Miranda | b6d686d | 2019-03-29 10:49:43 -0700 | [diff] [blame] | 280 | public MyConstantState(Bitmap bitmap, int color, boolean isDisabled) { |
Sunny Goyal | 338d15d | 2018-02-23 12:19:44 -0800 | [diff] [blame] | 281 | mBitmap = bitmap; |
| 282 | mIconColor = color; |
Jon Miranda | b6d686d | 2019-03-29 10:49:43 -0700 | [diff] [blame] | 283 | mIsDisabled = isDisabled; |
Sunny Goyal | 338d15d | 2018-02-23 12:19:44 -0800 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | @Override |
Sunny Goyal | 1416843 | 2019-10-24 15:59:49 -0700 | [diff] [blame] | 287 | public FastBitmapDrawable newDrawable() { |
Jon Miranda | b6d686d | 2019-03-29 10:49:43 -0700 | [diff] [blame] | 288 | return new FastBitmapDrawable(mBitmap, mIconColor, mIsDisabled); |
Sunny Goyal | 338d15d | 2018-02-23 12:19:44 -0800 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | @Override |
| 292 | public int getChangingConfigurations() { |
| 293 | return 0; |
| 294 | } |
| 295 | } |
Sunny Goyal | 1416843 | 2019-10-24 15:59:49 -0700 | [diff] [blame] | 296 | |
| 297 | /** |
| 298 | * Interface to be implemented by custom {@link BitmapInfo} to handle drawable construction |
| 299 | */ |
| 300 | public interface Factory { |
| 301 | |
| 302 | /** |
| 303 | * Called to create a new drawable |
| 304 | */ |
| 305 | FastBitmapDrawable newDrawable(); |
| 306 | } |
| 307 | |
| 308 | /** |
| 309 | * Returns a FastBitmapDrawable with the icon. |
| 310 | */ |
| 311 | public static FastBitmapDrawable newIcon(Context context, ItemInfoWithIcon info) { |
| 312 | FastBitmapDrawable drawable = newIcon(context, info.bitmap); |
| 313 | drawable.setIsDisabled(info.isDisabled()); |
| 314 | return drawable; |
| 315 | } |
| 316 | |
| 317 | /** |
| 318 | * Creates a drawable for the provided BitmapInfo |
| 319 | */ |
| 320 | public static FastBitmapDrawable newIcon(Context context, BitmapInfo info) { |
| 321 | if (info instanceof Factory) { |
| 322 | return ((Factory) info).newDrawable(); |
| 323 | } else if (info.isLowRes()) { |
| 324 | return new PlaceHolderIconDrawable(info, context); |
| 325 | } else { |
| 326 | return new FastBitmapDrawable(info); |
| 327 | } |
| 328 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 329 | } |