| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.widget; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.content.Context; |
| 21 |
import android.util.AttributeSet; |
| 22 |
import android.view.accessibility.AccessibilityNodeInfo; |
| 23 |
import android.widget.RemoteViews.RemoteView; |
| 24 |
|
| 25 |
import com.android.internal.R; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
@RemoteView |
| 54 |
public class RadioButton extends CompoundButton { |
| 55 |
|
| 56 |
public RadioButton(Context context) { |
| 57 |
this(context, null); |
| 58 |
} |
| 59 |
|
| 60 |
public RadioButton(Context context, AttributeSet attrs) { |
| 61 |
this(context, attrs, com.android.internal.R.attr.radioButtonStyle); |
| 62 |
} |
| 63 |
|
| 64 |
public RadioButton(Context context, AttributeSet attrs, int defStyleAttr) { |
| 65 |
this(context, attrs, defStyleAttr, 0); |
| 66 |
} |
| 67 |
|
| 68 |
public RadioButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { |
| 69 |
super(context, attrs, defStyleAttr, defStyleRes); |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
@Override |
| 78 |
public void toggle() { |
| 79 |
|
| 80 |
|
| 81 |
if (!isChecked()) { |
| 82 |
super.toggle(); |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
@Override |
| 87 |
public CharSequence getAccessibilityClassName() { |
| 88 |
return RadioButton.class.getName(); |
| 89 |
} |
| 90 |
|
| 91 |
@Override |
| 92 |
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { |
| 93 |
super.onInitializeAccessibilityNodeInfo(info); |
| 94 |
if (getParent() instanceof RadioGroup) { |
| 95 |
RadioGroup radioGroup = (RadioGroup) getParent(); |
| 96 |
if (radioGroup.getOrientation() == LinearLayout.HORIZONTAL) { |
| 97 |
info.setCollectionItemInfo(AccessibilityNodeInfo.CollectionItemInfo.obtain(0, 1, |
| 98 |
radioGroup.getIndexWithinVisibleButtons(this), 1, false, isChecked())); |
| 99 |
} else { |
| 100 |
info.setCollectionItemInfo(AccessibilityNodeInfo.CollectionItemInfo.obtain( |
| 101 |
radioGroup.getIndexWithinVisibleButtons(this), 1, 0, 1, |
| 102 |
false, isChecked())); |
| 103 |
} |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
@Override |
| 109 |
@NonNull |
| 110 |
protected CharSequence getButtonStateDescription() { |
| 111 |
if (isChecked()) { |
| 112 |
return getResources().getString(R.string.selected); |
| 113 |
} else { |
| 114 |
return getResources().getString(R.string.not_selected); |
| 115 |
} |
| 116 |
} |
| 117 |
} |