Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/widget/ChromeSwitchCompat.java

Issue 912533003: Fix ChromeSwitchCompat thumb drawable and tint color (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/widget/ChromeSwitchCompat.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/widget/ChromeSwitchCompat.java b/chrome/android/java/src/org/chromium/chrome/browser/widget/ChromeSwitchCompat.java
index fe6526b7b71aa5014a6ef3043398018f04b4a295..969869eec679856541c037319be77c3d2cde3768 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/widget/ChromeSwitchCompat.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/widget/ChromeSwitchCompat.java
@@ -5,12 +5,17 @@
package org.chromium.chrome.browser.widget;
import android.content.Context;
+import android.content.res.ColorStateList;
+import android.graphics.PorterDuff;
+import android.graphics.drawable.Drawable;
import android.support.v7.widget.SwitchCompat;
import android.util.AttributeSet;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.Switch;
+import org.chromium.chrome.R;
+
/**
* This class fixes the accessibility of SwitchCompat so it's read as "on switch" instead of
* "checkbox checked". http://crbug.com/441702
@@ -19,15 +24,23 @@ import android.widget.Switch;
* "Checkbox". This works around the bug by marking accessibility events from SwitchCompat with the
* Switch class name, which TalkBack recognizes.
*
+ * It also fixes the thumb drawable being too small and disappearing on certain devices
+ * and the disabled tint color being incorrect. http://crbug.com/455327
+ *
* TODO(newt): Delete this class once the support library is fixed. http://b/19110477
*/
public class ChromeSwitchCompat extends SwitchCompat {
+ private Drawable mThumbDrawable;
+ private ColorStateList mTint;
/**
* Constructor for inflating from XML.
*/
public ChromeSwitchCompat(Context context, AttributeSet attrs) {
super(context, attrs);
+ super.setThumbResource(R.drawable.switch_thumb);
newt (away) 2015/02/09 21:38:05 don't need "super."
Theresa 2015/02/09 23:01:15 Done.
+ mThumbDrawable = getThumbDrawable();
newt (away) 2015/02/09 21:38:05 Call mutate() on mThumbDrawable since you're chang
Theresa 2015/02/09 23:01:15 Done.
+ mTint = getResources().getColorStateList(R.color.switch_thumb_tint);
}
@Override
@@ -41,4 +54,17 @@ public class ChromeSwitchCompat extends SwitchCompat {
super.onInitializeAccessibilityNodeInfo(info);
info.setClassName(Switch.class.getName());
}
+
+ @Override
+ protected void drawableStateChanged() {
+ super.drawableStateChanged();
+ updateThumbTintColor();
+ }
+
+ private boolean updateThumbTintColor() {
+ if (mTint == null) return false;
+ mThumbDrawable.setColorFilter(mTint.getColorForState(mThumbDrawable.getState(), 0),
+ PorterDuff.Mode.SRC_IN);
+ return true;
+ }
}

Powered by Google App Engine
This is Rietveld 408576698