Bug 1400164 - Part 2: Tint close button manually when checked status is changed. r=nechen draft
authorJing-wei Wu <topwu.tw@gmail.com>
Mon, 18 Sep 2017 11:19:22 +0800
changeset 666153 a98bf72df25a85f0e9fec32a0d0d4277580e3784
parent 666152 202335949ad30ee05b60b54b3d0db9df710dc19f
child 731991 8435983ce3e920dc961314d4380021c69b82fa78
push id80290
push userbmo:topwu.tw@gmail.com
push dateMon, 18 Sep 2017 03:23:53 +0000
reviewersnechen
bugs1400164
milestone57.0a1
Bug 1400164 - Part 2: Tint close button manually when checked status is changed. r=nechen Because without implementing 'Checkable' interface, ThemedImageButton doesn't refresh its drawable when the 'checked' status is changed. We have to tint the drawable and set into the view manually. MozReview-Commit-ID: CDYUxOZkn60
mobile/android/base/java/org/mozilla/gecko/tabs/TabStripItemView.java
--- a/mobile/android/base/java/org/mozilla/gecko/tabs/TabStripItemView.java
+++ b/mobile/android/base/java/org/mozilla/gecko/tabs/TabStripItemView.java
@@ -10,18 +10,22 @@ import org.mozilla.gecko.R;
 import org.mozilla.gecko.Tab;
 import org.mozilla.gecko.Tabs;
 import org.mozilla.gecko.annotation.RobocopTarget;
 import org.mozilla.gecko.widget.themed.ThemedImageButton;
 import org.mozilla.gecko.widget.themed.ThemedLinearLayout;
 import org.mozilla.gecko.widget.themed.ThemedTextView;
 
 import android.content.Context;
+import android.content.res.ColorStateList;
 import android.content.res.Resources;
 import android.graphics.Bitmap;
+import android.graphics.Color;
+import android.graphics.drawable.Drawable;
+import android.support.v4.graphics.drawable.DrawableCompat;
 import android.support.v4.widget.TextViewCompat;
 import android.util.AttributeSet;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.widget.Checkable;
 import android.widget.ImageView;
 
 public class TabStripItemView extends ThemedLinearLayout
@@ -107,16 +111,23 @@ public class TabStripItemView extends Th
     @Override
     public void setChecked(boolean checked) {
         if (this.checked == checked) {
             return;
         }
 
         this.checked = checked;
         refreshDrawableState();
+
+        // Tint the close view based on current checked status.
+        final ColorStateList colorStateList = closeView.getDrawableColors();
+        final int tintColor = colorStateList.getColorForState(getDrawableState(), Color.TRANSPARENT);
+        final Drawable drawable = DrawableCompat.wrap(closeView.getDrawable());
+        DrawableCompat.setTint(drawable, tintColor);
+        closeView.setImageDrawable(drawable);
     }
 
     @Override
     public void toggle() {
         setChecked(!checked);
     }
 
     @Override