diff options
| author | yingleiw <yingleiw@google.com> | 2019-10-11 15:10:55 -0700 |
|---|---|---|
| committer | yingleiw <yingleiw@google.com> | 2019-11-19 12:13:56 -0800 |
| commit | 473fc125fa2d2ebebac797d01eeee6c15cc05a56 (patch) | |
| tree | 88ac953cef574205e4a287e9e0b7f6a470b9df1a /core/java/android/widget/ToggleButton.java | |
| parent | 0d9dd2b0f330538a7a48e1b66991483f78fca6a7 (diff) | |
change CompoundButton button to use the accessibility state API
Test: tested with updated talkback (see CL/274237446). It works as
before.
Change-Id: I928350c8bc9112252e8b8a703c465489f03fde11
Diffstat (limited to 'core/java/android/widget/ToggleButton.java')
| -rw-r--r-- | core/java/android/widget/ToggleButton.java | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/core/java/android/widget/ToggleButton.java b/core/java/android/widget/ToggleButton.java index 9255ccb5cda7..d47405b3b11e 100644 --- a/core/java/android/widget/ToggleButton.java +++ b/core/java/android/widget/ToggleButton.java @@ -17,6 +17,7 @@ package android.widget; import android.annotation.FloatRange; +import android.annotation.NonNull; import android.content.Context; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; @@ -24,6 +25,8 @@ import android.graphics.drawable.LayerDrawable; import android.util.AttributeSet; import android.view.inspector.InspectableProperty; +import com.android.internal.R; + /** * Displays checked/unchecked states as a button * with a "light" indicator and by default accompanied with the text "ON" or "OFF". @@ -103,6 +106,9 @@ public class ToggleButton extends CompoundButton { */ public void setTextOn(CharSequence textOn) { mTextOn = textOn; + // Default state is derived from on/off-text, so state has to be updated when on/off-text + // are updated. + setDefaultStateDescritption(); } /** @@ -122,6 +128,9 @@ public class ToggleButton extends CompoundButton { */ public void setTextOff(CharSequence textOff) { mTextOff = textOff; + // Default state is derived from on/off-text, so state has to be updated when on/off-text + // are updated. + setDefaultStateDescritption(); } /** @@ -172,4 +181,15 @@ public class ToggleButton extends CompoundButton { public CharSequence getAccessibilityClassName() { return ToggleButton.class.getName(); } + + /** @hide **/ + @Override + @NonNull + protected CharSequence getButtonStateDescription() { + if (isChecked()) { + return mTextOn == null ? getResources().getString(R.string.capital_on) : mTextOn; + } else { + return mTextOff == null ? getResources().getString(R.string.capital_off) : mTextOff; + } + } } |
