Skip to content

Commit

Permalink
[MaterialTimePicker][a11y] Update accessibility className used for ho…
Browse files Browse the repository at this point in the history
…ur/minute Chips

PiperOrigin-RevId: 436207977
(cherry picked from commit a51d1dc)
  • Loading branch information
paulfthomas authored and hunterstich committed Mar 22, 2022
1 parent 6252528 commit 981129f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/java/com/google/android/material/chip/Chip.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public class Chip extends AppCompatCheckBox
@Dimension(unit = Dimension.PX)
private int minTouchTargetSize;

@Nullable private CharSequence accessibilityClassName;
private static final String BUTTON_ACCESSIBILITY_CLASS_NAME = "android.widget.Button";
private static final String COMPOUND_BUTTON_ACCESSIBILITY_CLASS_NAME =
"android.widget.CompoundButton";
Expand Down Expand Up @@ -1112,7 +1113,7 @@ public void setChipMinHeightResource(@DimenRes int id) {
/**
* Sets this chip's minimum height.
*
* @param minHeight This chip's mininum height.
* @param minHeight This chip's minimum height.
* @attr ref com.google.android.material.R.styleable#Chip_chipMinHeight
*/
public void setChipMinHeight(float minHeight) {
Expand Down Expand Up @@ -2304,10 +2305,21 @@ public boolean ensureAccessibleTouchTarget(@Dimension int minTargetPx) {
return true;
}

/**
* Sets this chip's accessibility class name.
*
* @param className This chip's accessibility class name.
*/
public void setAccessibilityClassName(@Nullable CharSequence className) {
accessibilityClassName = className;
}

@Override
@NonNull
public CharSequence getAccessibilityClassName() {
if (isCheckable()) {
if (!TextUtils.isEmpty(accessibilityClassName)) {
return accessibilityClassName;
} else if (isCheckable()) {
ViewParent parent = getParent();
if (parent instanceof ChipGroup && ((ChipGroup) parent).isSingleSelection()) {
return RADIO_BUTTON_ACCESSIBILITY_CLASS_NAME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import com.google.android.material.R;

import static com.google.android.material.timepicker.TimePickerView.GENERIC_VIEW_ACCESSIBILITY_CLASS_NAME;

import android.content.Context;
import android.content.res.Configuration;
import android.os.Build.VERSION;
Expand Down Expand Up @@ -68,6 +70,7 @@ public ChipTextInputComboView(
super(context, attrs, defStyleAttr);
LayoutInflater inflater = LayoutInflater.from(context);
chip = (Chip) inflater.inflate(R.layout.material_time_chip, this, false);
chip.setAccessibilityClassName(GENERIC_VIEW_ACCESSIBILITY_CLASS_NAME);
textInputLayout = (TextInputLayout) inflater.inflate(R.layout.material_time_input, this, false);
editText = textInputLayout.getEditText();
editText.setVisibility(INVISIBLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ interface OnDoubleTapListener {
void onDoubleTap();
}

static final String GENERIC_VIEW_ACCESSIBILITY_CLASS_NAME = "android.view.View";

private final Chip minuteView;
private final Chip hourView;

Expand Down Expand Up @@ -169,6 +171,9 @@ private void setUpDisplay() {

minuteView.setOnClickListener(selectionListener);
hourView.setOnClickListener(selectionListener);

minuteView.setAccessibilityClassName(GENERIC_VIEW_ACCESSIBILITY_CLASS_NAME);
hourView.setAccessibilityClassName(GENERIC_VIEW_ACCESSIBILITY_CLASS_NAME);
}

@Override
Expand Down

0 comments on commit 981129f

Please sign in to comment.