Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.Context; | 7 import android.content.Context; |
| 8 import android.content.res.ColorStateList; | |
| 9 import android.graphics.PorterDuff; | |
| 10 import android.graphics.drawable.Drawable; | |
| 8 import android.support.v7.widget.SwitchCompat; | 11 import android.support.v7.widget.SwitchCompat; |
| 9 import android.util.AttributeSet; | 12 import android.util.AttributeSet; |
| 10 import android.view.accessibility.AccessibilityEvent; | 13 import android.view.accessibility.AccessibilityEvent; |
| 11 import android.view.accessibility.AccessibilityNodeInfo; | 14 import android.view.accessibility.AccessibilityNodeInfo; |
| 12 import android.widget.Switch; | 15 import android.widget.Switch; |
| 13 | 16 |
| 17 import org.chromium.chrome.R; | |
| 18 | |
| 14 /** | 19 /** |
| 15 * This class fixes the accessibility of SwitchCompat so it's read as "on switch " instead of | 20 * This class fixes the accessibility of SwitchCompat so it's read as "on switch " instead of |
| 16 * "checkbox checked". http://crbug.com/441702 | 21 * "checkbox checked". http://crbug.com/441702 |
| 17 * | 22 * |
| 18 * TalkBack doesn't recognize the SwitchCompat class, so it reads events with th at classname as | 23 * TalkBack doesn't recognize the SwitchCompat class, so it reads events with th at classname as |
| 19 * "Checkbox". This works around the bug by marking accessibility events from Sw itchCompat with the | 24 * "Checkbox". This works around the bug by marking accessibility events from Sw itchCompat with the |
| 20 * Switch class name, which TalkBack recognizes. | 25 * Switch class name, which TalkBack recognizes. |
| 21 * | 26 * |
| 27 * It also fixes the thumb drawable being too small and disappearing on certain devices | |
| 28 * and the disabled tint color being incorrect. http://crbug.com/455327 | |
| 29 * | |
| 22 * TODO(newt): Delete this class once the support library is fixed. http://b/191 10477 | 30 * TODO(newt): Delete this class once the support library is fixed. http://b/191 10477 |
| 23 */ | 31 */ |
| 24 public class ChromeSwitchCompat extends SwitchCompat { | 32 public class ChromeSwitchCompat extends SwitchCompat { |
| 33 private Drawable mThumbDrawable; | |
| 34 private ColorStateList mTint; | |
| 25 | 35 |
| 26 /** | 36 /** |
| 27 * Constructor for inflating from XML. | 37 * Constructor for inflating from XML. |
| 28 */ | 38 */ |
| 29 public ChromeSwitchCompat(Context context, AttributeSet attrs) { | 39 public ChromeSwitchCompat(Context context, AttributeSet attrs) { |
| 30 super(context, attrs); | 40 super(context, attrs); |
| 41 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.
| |
| 42 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.
| |
| 43 mTint = getResources().getColorStateList(R.color.switch_thumb_tint); | |
| 31 } | 44 } |
| 32 | 45 |
| 33 @Override | 46 @Override |
| 34 public void onInitializeAccessibilityEvent(AccessibilityEvent event) { | 47 public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
| 35 super.onInitializeAccessibilityEvent(event); | 48 super.onInitializeAccessibilityEvent(event); |
| 36 event.setClassName(Switch.class.getName()); | 49 event.setClassName(Switch.class.getName()); |
| 37 } | 50 } |
| 38 | 51 |
| 39 @Override | 52 @Override |
| 40 public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { | 53 public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { |
| 41 super.onInitializeAccessibilityNodeInfo(info); | 54 super.onInitializeAccessibilityNodeInfo(info); |
| 42 info.setClassName(Switch.class.getName()); | 55 info.setClassName(Switch.class.getName()); |
| 43 } | 56 } |
| 57 | |
| 58 @Override | |
| 59 protected void drawableStateChanged() { | |
| 60 super.drawableStateChanged(); | |
| 61 updateThumbTintColor(); | |
| 62 } | |
| 63 | |
| 64 private boolean updateThumbTintColor() { | |
| 65 if (mTint == null) return false; | |
| 66 mThumbDrawable.setColorFilter(mTint.getColorForState(mThumbDrawable.getS tate(), 0), | |
| 67 PorterDuff.Mode.SRC_IN); | |
| 68 return true; | |
| 69 } | |
| 44 } | 70 } |
| OLD | NEW |