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 | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 19 | import android.animation.ObjectAnimator; |
| 20 | import android.animation.TimeInterpolator; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 21 | import android.graphics.Bitmap; |
| 22 | import android.graphics.Canvas; |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 23 | import android.graphics.Color; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 24 | import android.graphics.ColorFilter; |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 25 | import android.graphics.ColorMatrix; |
| 26 | import android.graphics.ColorMatrixColorFilter; |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 27 | import android.graphics.Paint; |
| 28 | import android.graphics.PixelFormat; |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 29 | import android.graphics.PorterDuff; |
| 30 | import android.graphics.PorterDuffColorFilter; |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 31 | import android.graphics.drawable.Drawable; |
Tony Wickham | 1e61849 | 2017-02-02 12:57:18 -0800 | [diff] [blame] | 32 | import android.util.Property; |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 33 | import android.util.SparseArray; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 34 | |
Tony Wickham | 010d255 | 2017-01-20 08:15:28 -0800 | [diff] [blame] | 35 | import com.android.launcher3.graphics.IconPalette; |
Tony Wickham | 9a8d11f | 2017-01-11 09:53:12 -0800 | [diff] [blame] | 36 | |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 37 | public class FastBitmapDrawable extends Drawable { |
Sunny Goyal | 2a76e3f | 2017-02-16 13:33:15 -0800 | [diff] [blame] | 38 | |
Sunny Goyal | 2a76e3f | 2017-02-16 13:33:15 -0800 | [diff] [blame] | 39 | private static final float PRESSED_BRIGHTNESS = 100f / 255f; |
Tony Wickham | 6b910a2 | 2016-11-08 10:40:34 -0800 | [diff] [blame] | 40 | private static final float DISABLED_DESATURATION = 1f; |
| 41 | private static final float DISABLED_BRIGHTNESS = 0.5f; |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 42 | |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 43 | public static final TimeInterpolator CLICK_FEEDBACK_INTERPOLATOR = new TimeInterpolator() { |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 44 | |
| 45 | @Override |
| 46 | public float getInterpolation(float input) { |
| 47 | if (input < 0.05f) { |
| 48 | return input / 0.05f; |
| 49 | } else if (input < 0.3f){ |
| 50 | return 1; |
| 51 | } else { |
| 52 | return (1 - input) / 0.7f; |
| 53 | } |
| 54 | } |
| 55 | }; |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 56 | public static final int CLICK_FEEDBACK_DURATION = 2000; |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 57 | |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 58 | // Since we don't need 256^2 values for combinations of both the brightness and saturation, we |
| 59 | // reduce the value space to a smaller value V, which reduces the number of cached |
| 60 | // ColorMatrixColorFilters that we need to keep to V^2 |
| 61 | private static final int REDUCED_FILTER_VALUE_SPACE = 48; |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 62 | |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 63 | // A cache of ColorFilters for optimizing brightness and saturation animations |
| 64 | private static final SparseArray<ColorFilter> sCachedFilter = new SparseArray<>(); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 65 | |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 66 | // Temporary matrices used for calculation |
| 67 | private static final ColorMatrix sTempBrightnessMatrix = new ColorMatrix(); |
| 68 | private static final ColorMatrix sTempFilterMatrix = new ColorMatrix(); |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 69 | |
Sunny Goyal | 55cb70b | 2016-11-12 09:58:29 -0800 | [diff] [blame] | 70 | protected final Paint mPaint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 71 | private final Bitmap mBitmap; |
Sunny Goyal | 2a76e3f | 2017-02-16 13:33:15 -0800 | [diff] [blame] | 72 | |
| 73 | private boolean mIsPressed; |
Tony Wickham | 6b910a2 | 2016-11-08 10:40:34 -0800 | [diff] [blame] | 74 | private boolean mIsDisabled; |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 75 | |
Tony Wickham | 9a8d11f | 2017-01-11 09:53:12 -0800 | [diff] [blame] | 76 | private IconPalette mIconPalette; |
| 77 | |
Sunny Goyal | 2a76e3f | 2017-02-16 13:33:15 -0800 | [diff] [blame] | 78 | private static final Property<FastBitmapDrawable, Float> BRIGHTNESS |
| 79 | = new Property<FastBitmapDrawable, Float>(Float.TYPE, "brightness") { |
| 80 | @Override |
| 81 | public Float get(FastBitmapDrawable fastBitmapDrawable) { |
| 82 | return fastBitmapDrawable.getBrightness(); |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public void set(FastBitmapDrawable fastBitmapDrawable, Float value) { |
| 87 | fastBitmapDrawable.setBrightness(value); |
| 88 | } |
| 89 | }; |
| 90 | |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 91 | // The saturation and brightness are values that are mapped to REDUCED_FILTER_VALUE_SPACE and |
| 92 | // as a result, can be used to compose the key for the cached ColorMatrixColorFilters |
| 93 | private int mDesaturation = 0; |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 94 | private int mBrightness = 0; |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 95 | private int mAlpha = 255; |
| 96 | private int mPrevUpdateKey = Integer.MAX_VALUE; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 97 | |
Sunny Goyal | 2a76e3f | 2017-02-16 13:33:15 -0800 | [diff] [blame] | 98 | // Animators for the fast bitmap drawable's brightness |
| 99 | private ObjectAnimator mBrightnessAnimator; |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 100 | |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 101 | public FastBitmapDrawable(Bitmap b) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 102 | mBitmap = b; |
Sunny Goyal | 96ac68a | 2017-02-02 16:37:21 -0800 | [diff] [blame] | 103 | setFilterBitmap(true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | @Override |
| 107 | public void draw(Canvas canvas) { |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 108 | canvas.drawBitmap(mBitmap, null, getBounds(), mPaint); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 109 | } |
| 110 | |
Tony Wickham | ce44516 | 2017-04-10 14:05:34 -0700 | [diff] [blame] | 111 | public IconPalette getIconPalette() { |
Tony Wickham | 9438ed4 | 2017-01-20 09:38:25 -0800 | [diff] [blame] | 112 | if (mIconPalette == null) { |
| 113 | mIconPalette = IconPalette.fromDominantColor(Utilities |
Tony Wickham | 7092db0 | 2017-06-07 14:32:23 -0700 | [diff] [blame] | 114 | .findDominantColorByHue(mBitmap, 20), true /* desaturateBackground */); |
Tony Wickham | 9438ed4 | 2017-01-20 09:38:25 -0800 | [diff] [blame] | 115 | } |
| 116 | return mIconPalette; |
| 117 | } |
| 118 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 119 | @Override |
Adam Cohen | badf71e | 2011-05-26 19:08:29 -0700 | [diff] [blame] | 120 | public void setColorFilter(ColorFilter cf) { |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 121 | // No op |
Adam Cohen | badf71e | 2011-05-26 19:08:29 -0700 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 125 | public int getOpacity() { |
| 126 | return PixelFormat.TRANSLUCENT; |
| 127 | } |
| 128 | |
| 129 | @Override |
| 130 | public void setAlpha(int alpha) { |
Winson Chung | 29d6fea | 2010-12-01 15:47:31 -0800 | [diff] [blame] | 131 | mAlpha = alpha; |
Winson Chung | b3347bb | 2010-08-19 14:51:28 -0700 | [diff] [blame] | 132 | mPaint.setAlpha(alpha); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 133 | } |
| 134 | |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 135 | @Override |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 136 | public void setFilterBitmap(boolean filterBitmap) { |
| 137 | mPaint.setFilterBitmap(filterBitmap); |
Winson Chung | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 138 | mPaint.setAntiAlias(filterBitmap); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Winson Chung | 29d6fea | 2010-12-01 15:47:31 -0800 | [diff] [blame] | 141 | public int getAlpha() { |
| 142 | return mAlpha; |
| 143 | } |
| 144 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 145 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 146 | public int getIntrinsicWidth() { |
Sunny Goyal | c424f22 | 2014-09-05 07:04:59 -0700 | [diff] [blame] | 147 | return mBitmap.getWidth(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | @Override |
| 151 | public int getIntrinsicHeight() { |
Sunny Goyal | c424f22 | 2014-09-05 07:04:59 -0700 | [diff] [blame] | 152 | return mBitmap.getHeight(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | @Override |
| 156 | public int getMinimumWidth() { |
Winson Chung | eeb5bbc | 2013-11-13 15:47:05 -0800 | [diff] [blame] | 157 | return getBounds().width(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | @Override |
| 161 | public int getMinimumHeight() { |
Winson Chung | eeb5bbc | 2013-11-13 15:47:05 -0800 | [diff] [blame] | 162 | return getBounds().height(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 163 | } |
| 164 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 165 | public Bitmap getBitmap() { |
| 166 | return mBitmap; |
| 167 | } |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 168 | |
Sunny Goyal | 2a76e3f | 2017-02-16 13:33:15 -0800 | [diff] [blame] | 169 | @Override |
| 170 | public boolean isStateful() { |
| 171 | return true; |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Sunny Goyal | 2a76e3f | 2017-02-16 13:33:15 -0800 | [diff] [blame] | 174 | @Override |
Sunny Goyal | 2814112 | 2017-06-21 17:28:23 -0700 | [diff] [blame] | 175 | public ColorFilter getColorFilter() { |
| 176 | return mPaint.getColorFilter(); |
| 177 | } |
| 178 | |
| 179 | @Override |
Sunny Goyal | 2a76e3f | 2017-02-16 13:33:15 -0800 | [diff] [blame] | 180 | protected boolean onStateChange(int[] state) { |
| 181 | boolean isPressed = false; |
| 182 | for (int s : state) { |
| 183 | if (s == android.R.attr.state_pressed) { |
| 184 | isPressed = true; |
| 185 | break; |
| 186 | } |
| 187 | } |
| 188 | if (mIsPressed != isPressed) { |
| 189 | mIsPressed = isPressed; |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 190 | |
Sunny Goyal | 2a76e3f | 2017-02-16 13:33:15 -0800 | [diff] [blame] | 191 | if (mBrightnessAnimator != null) { |
| 192 | mBrightnessAnimator.cancel(); |
| 193 | } |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 194 | |
Sunny Goyal | 2a76e3f | 2017-02-16 13:33:15 -0800 | [diff] [blame] | 195 | if (mIsPressed) { |
| 196 | // Animate when going to pressed state |
| 197 | mBrightnessAnimator = ObjectAnimator.ofFloat( |
| 198 | this, BRIGHTNESS, getExpectedBrightness()); |
| 199 | mBrightnessAnimator.setDuration(CLICK_FEEDBACK_DURATION); |
| 200 | mBrightnessAnimator.setInterpolator(CLICK_FEEDBACK_INTERPOLATOR); |
| 201 | mBrightnessAnimator.start(); |
| 202 | } else { |
| 203 | setBrightness(getExpectedBrightness()); |
| 204 | } |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 205 | return true; |
| 206 | } |
| 207 | return false; |
| 208 | } |
| 209 | |
Tony Wickham | 6b910a2 | 2016-11-08 10:40:34 -0800 | [diff] [blame] | 210 | private void invalidateDesaturationAndBrightness() { |
Sunny Goyal | 2a76e3f | 2017-02-16 13:33:15 -0800 | [diff] [blame] | 211 | setDesaturation(mIsDisabled ? DISABLED_DESATURATION : 0); |
| 212 | setBrightness(getExpectedBrightness()); |
Tony Wickham | 6b910a2 | 2016-11-08 10:40:34 -0800 | [diff] [blame] | 213 | } |
| 214 | |
Sunny Goyal | 2a76e3f | 2017-02-16 13:33:15 -0800 | [diff] [blame] | 215 | private float getExpectedBrightness() { |
| 216 | return mIsDisabled ? DISABLED_BRIGHTNESS : |
| 217 | (mIsPressed ? PRESSED_BRIGHTNESS : 0); |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Tony Wickham | 6b910a2 | 2016-11-08 10:40:34 -0800 | [diff] [blame] | 220 | public void setIsDisabled(boolean isDisabled) { |
| 221 | if (mIsDisabled != isDisabled) { |
| 222 | mIsDisabled = isDisabled; |
| 223 | invalidateDesaturationAndBrightness(); |
| 224 | } |
| 225 | } |
| 226 | |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 227 | /** |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 228 | * Sets the saturation of this icon, 0 [full color] -> 1 [desaturated] |
| 229 | */ |
Sunny Goyal | 55cb70b | 2016-11-12 09:58:29 -0800 | [diff] [blame] | 230 | private void setDesaturation(float desaturation) { |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 231 | int newDesaturation = (int) Math.floor(desaturation * REDUCED_FILTER_VALUE_SPACE); |
| 232 | if (mDesaturation != newDesaturation) { |
| 233 | mDesaturation = newDesaturation; |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 234 | updateFilter(); |
| 235 | } |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 236 | } |
| 237 | |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 238 | public float getDesaturation() { |
| 239 | return (float) mDesaturation / REDUCED_FILTER_VALUE_SPACE; |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 242 | /** |
| 243 | * Sets the brightness of this icon, 0 [no add. brightness] -> 1 [2bright2furious] |
| 244 | */ |
Sunny Goyal | 55cb70b | 2016-11-12 09:58:29 -0800 | [diff] [blame] | 245 | private void setBrightness(float brightness) { |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 246 | int newBrightness = (int) Math.floor(brightness * REDUCED_FILTER_VALUE_SPACE); |
| 247 | if (mBrightness != newBrightness) { |
| 248 | mBrightness = newBrightness; |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 249 | updateFilter(); |
| 250 | } |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 251 | } |
| 252 | |
Sunny Goyal | 55cb70b | 2016-11-12 09:58:29 -0800 | [diff] [blame] | 253 | private float getBrightness() { |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 254 | return (float) mBrightness / REDUCED_FILTER_VALUE_SPACE; |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * Updates the paint to reflect the current brightness and saturation. |
| 259 | */ |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 260 | private void updateFilter() { |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 261 | boolean usePorterDuffFilter = false; |
| 262 | int key = -1; |
| 263 | if (mDesaturation > 0) { |
| 264 | key = (mDesaturation << 16) | mBrightness; |
| 265 | } else if (mBrightness > 0) { |
| 266 | // Compose a key with a fully saturated icon if we are just animating brightness |
| 267 | key = (1 << 16) | mBrightness; |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 268 | |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 269 | // We found that in L, ColorFilters cause drawing artifacts with shadows baked into |
| 270 | // icons, so just use a PorterDuff filter when we aren't animating saturation |
| 271 | usePorterDuffFilter = true; |
| 272 | } |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 273 | |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 274 | // Debounce multiple updates on the same frame |
| 275 | if (key == mPrevUpdateKey) { |
| 276 | return; |
| 277 | } |
| 278 | mPrevUpdateKey = key; |
| 279 | |
| 280 | if (key != -1) { |
| 281 | ColorFilter filter = sCachedFilter.get(key); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 282 | if (filter == null) { |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 283 | float brightnessF = getBrightness(); |
| 284 | int brightnessI = (int) (255 * brightnessF); |
| 285 | if (usePorterDuffFilter) { |
| 286 | filter = new PorterDuffColorFilter(Color.argb(brightnessI, 255, 255, 255), |
| 287 | PorterDuff.Mode.SRC_ATOP); |
| 288 | } else { |
| 289 | float saturationF = 1f - getDesaturation(); |
| 290 | sTempFilterMatrix.setSaturation(saturationF); |
| 291 | if (mBrightness > 0) { |
| 292 | // Brightness: C-new = C-old*(1-amount) + amount |
| 293 | float scale = 1f - brightnessF; |
| 294 | float[] mat = sTempBrightnessMatrix.getArray(); |
| 295 | mat[0] = scale; |
| 296 | mat[6] = scale; |
| 297 | mat[12] = scale; |
| 298 | mat[4] = brightnessI; |
| 299 | mat[9] = brightnessI; |
| 300 | mat[14] = brightnessI; |
| 301 | sTempFilterMatrix.preConcat(sTempBrightnessMatrix); |
| 302 | } |
| 303 | filter = new ColorMatrixColorFilter(sTempFilterMatrix); |
| 304 | } |
| 305 | sCachedFilter.append(key, filter); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 306 | } |
| 307 | mPaint.setColorFilter(filter); |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 308 | } else { |
| 309 | mPaint.setColorFilter(null); |
| 310 | } |
Winson | c088049 | 2015-08-21 11:16:27 -0700 | [diff] [blame] | 311 | invalidateSelf(); |
Sunny Goyal | c5c60ad | 2014-07-14 12:02:01 -0700 | [diff] [blame] | 312 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 313 | } |