OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.widget; | 5 package org.chromium.chrome.browser.widget; |
6 | 6 |
7 import android.content.res.ColorStateList; | 7 import android.content.res.ColorStateList; |
8 import android.content.res.Resources; | 8 import android.content.res.Resources; |
9 import android.graphics.Bitmap; | 9 import android.graphics.Bitmap; |
10 import android.graphics.BitmapFactory; | 10 import android.graphics.BitmapFactory; |
11 import android.graphics.PorterDuff; | 11 import android.graphics.PorterDuff; |
12 import android.graphics.drawable.BitmapDrawable; | 12 import android.graphics.drawable.BitmapDrawable; |
13 | 13 |
| 14 import org.chromium.base.ApiCompatibilityUtils; |
14 import org.chromium.chrome.R; | 15 import org.chromium.chrome.R; |
15 | 16 |
16 /** | 17 /** |
17 * Implementation of BitmapDrawable that allows to tint the color of the drawabl
e for all | 18 * Implementation of BitmapDrawable that allows to tint the color of the drawabl
e for all |
18 * bitmap drawable states using chrome:tint attribute in XML. | 19 * bitmap drawable states using chrome:tint attribute in XML. |
19 */ | 20 */ |
20 public class TintedDrawable extends BitmapDrawable { | 21 public class TintedDrawable extends BitmapDrawable { |
21 /** | 22 /** |
22 * The set of colors that just be used for tinting this bitmap drawable. | 23 * The set of colors that just be used for tinting this bitmap drawable. |
23 */ | 24 */ |
24 protected ColorStateList mTint; | 25 protected ColorStateList mTint; |
25 | 26 |
26 public TintedDrawable(Resources res, Bitmap bitmap) { | 27 public TintedDrawable(Resources res, Bitmap bitmap) { |
27 super(res, bitmap); | 28 super(res, bitmap); |
28 mTint = res.getColorStateList(R.color.dark_mode_tint); | 29 mTint = ApiCompatibilityUtils.getColorStateList(res, R.color.dark_mode_t
int); |
29 } | 30 } |
30 | 31 |
31 @Override | 32 @Override |
32 protected boolean onStateChange(int[] state) { | 33 protected boolean onStateChange(int[] state) { |
33 boolean ret = updateTintColor(); | 34 boolean ret = updateTintColor(); |
34 super.onStateChange(state); | 35 super.onStateChange(state); |
35 return ret; | 36 return ret; |
36 } | 37 } |
37 | 38 |
38 @Override | 39 @Override |
(...skipping 25 matching lines...) Expand all Loading... |
64 public static TintedDrawable constructTintedDrawable(Resources res, Bitmap i
con) { | 65 public static TintedDrawable constructTintedDrawable(Resources res, Bitmap i
con) { |
65 return new TintedDrawable(res, icon); | 66 return new TintedDrawable(res, icon); |
66 } | 67 } |
67 | 68 |
68 private boolean updateTintColor() { | 69 private boolean updateTintColor() { |
69 if (mTint == null) return false; | 70 if (mTint == null) return false; |
70 setColorFilter(mTint.getColorForState(getState(), 0), PorterDuff.Mode.SR
C_IN); | 71 setColorFilter(mTint.getColorForState(getState(), 0), PorterDuff.Mode.SR
C_IN); |
71 return true; | 72 return true; |
72 } | 73 } |
73 } | 74 } |
OLD | NEW |