Index: chrome/android/java/src/org/chromium/chrome/browser/widget/TintedImageButton.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/widget/TintedImageButton.java b/chrome/android/java/src/org/chromium/chrome/browser/widget/TintedImageButton.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..878f41d6accf7c3f0173689d2756a5e787b861f2 |
--- /dev/null |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/widget/TintedImageButton.java |
@@ -0,0 +1,58 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+package org.chromium.chrome.browser.widget; |
+ |
+import android.content.Context; |
+import android.content.res.ColorStateList; |
+import android.content.res.TypedArray; |
+import android.util.AttributeSet; |
+import android.widget.ImageButton; |
+ |
+import org.chromium.chrome.R; |
+ |
+/** |
+ * Implementation of ImageButton that allows to tint the color of the image button for all |
+ * image button states using chrome:tint attribute in XML. |
+ */ |
+public class TintedImageButton extends ImageButton { |
David Trainor- moved to gerrit
2014/10/27 23:58:59
It looks like Android supports this by default wit
aurimas (slooooooooow)
2014/10/28 18:11:16
They do not have an appcompat version. This is ess
|
+ private ColorStateList mTint; |
+ |
+ public TintedImageButton(Context context) { |
+ super(context); |
+ } |
+ |
+ public TintedImageButton(Context context, AttributeSet attrs) { |
+ super(context, attrs); |
+ init(context, attrs, 0); |
+ } |
+ |
+ public TintedImageButton(Context context, AttributeSet attrs, int defStyle) { |
+ super(context, attrs, defStyle); |
+ init(context, attrs, defStyle); |
+ } |
+ |
+ private void init(Context context, AttributeSet attrs, int defStyle) { |
+ TypedArray a = context.obtainStyledAttributes( |
+ attrs, R.styleable.TintedImageButton, defStyle, 0); |
+ mTint = a.getColorStateList(R.styleable.TintedImageButton_tint); |
+ a.recycle(); |
+ } |
+ |
+ @Override |
+ protected void drawableStateChanged() { |
+ super.drawableStateChanged(); |
+ if (mTint != null && mTint.isStateful()) updateTintColor(); |
+ } |
+ |
+ public void setColorFilter(ColorStateList tint) { |
+ this.mTint = tint; |
David Trainor- moved to gerrit
2014/10/27 23:58:59
remove "this."
aurimas (slooooooooow)
2014/10/28 18:11:16
Done.
|
+ super.setColorFilter(tint.getColorForState(getDrawableState(), 0)); |
David Trainor- moved to gerrit
2014/10/27 23:58:59
call updateTintColor() here?
aurimas (slooooooooow)
2014/10/28 18:11:16
Done.
|
+ } |
+ |
+ private void updateTintColor() { |
+ int color = mTint.getColorForState(getDrawableState(), 0); |
David Trainor- moved to gerrit
2014/10/27 23:58:59
Remove temporary variable
aurimas (slooooooooow)
2014/10/28 18:11:16
Done.
|
+ setColorFilter(color); |
+ } |
+} |