Improving accessibility feedback for two state widgets.

1. Added population of sensible text for the state of the
   two state controls such as CheckBox, Switch, etc. This
   is important since if they are in a layout manager which
   fires an accessibility event there should be a description
   of the widget.

bug:5092552

Change-Id: Ie3ca955653563496b84db379ae23a23fe88089a8
diff --git a/core/java/android/widget/Switch.java b/core/java/android/widget/Switch.java
index 0c80a11..57f73ac 100644
--- a/core/java/android/widget/Switch.java
+++ b/core/java/android/widget/Switch.java
@@ -364,8 +364,19 @@
     @Override
     public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
         super.onPopulateAccessibilityEvent(event);
-        Layout switchText = getTargetCheckedState() ? mOnLayout : mOffLayout;
-        event.getText().add(switchText.getText());
+        if (isChecked()) {
+            CharSequence text = mOnLayout.getText();
+            if (TextUtils.isEmpty(text)) {
+                text = mContext.getString(R.string.switch_on);
+            }
+            event.getText().add(text);
+        } else {
+            CharSequence text = mOffLayout.getText();
+            if (TextUtils.isEmpty(text)) {
+                text = mContext.getString(R.string.switch_off);
+            }
+            event.getText().add(text);
+        }
     }
 
     private Layout makeLayout(CharSequence text) {