Skip to content

Commit

Permalink
[TimePicker][a11y] Fix Switch Access can't reach clock items
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 425684600
  • Loading branch information
paulfthomas authored and pekingme committed Feb 1, 2022
1 parent dff1e4e commit f9914da
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
20 changes: 20 additions & 0 deletions lib/java/com/google/android/material/timepicker/ClockFaceView.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Shader.TileMode;
import android.os.Bundle;
import android.os.SystemClock;
import androidx.appcompat.content.res.AppCompatResources;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewTreeObserver.OnPreDrawListener;
import android.view.accessibility.AccessibilityNodeInfo;
Expand All @@ -47,6 +50,7 @@
import androidx.core.view.AccessibilityDelegateCompat;
import androidx.core.view.ViewCompat;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat.AccessibilityActionCompat;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat.CollectionInfoCompat;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat.CollectionItemInfoCompat;
import com.google.android.material.resources.MaterialResources;
Expand Down Expand Up @@ -166,6 +170,22 @@ public void onInitializeAccessibilityNodeInfo(
/* selected= */ host.isSelected()));

info.setClickable(true);
info.addAction(AccessibilityActionCompat.ACTION_CLICK);
}

@Override
public boolean performAccessibilityAction(View host, int action, Bundle args) {
if (action == AccessibilityNodeInfoCompat.ACTION_CLICK) {
long eventTime = SystemClock.uptimeMillis();
float x = host.getX() + host.getWidth() / 2f;
float y = host.getY() + host.getHeight() / 2f;
clockHandView.onTouchEvent(
MotionEvent.obtain(eventTime, eventTime, MotionEvent.ACTION_DOWN, x, y, 0));
clockHandView.onTouchEvent(
MotionEvent.obtain(eventTime, eventTime, MotionEvent.ACTION_UP, x, y, 0));
return true;
}
return super.performAccessibilityAction(host, action, args);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?attr/colorOnSurface"
android:padding="16dp"
android:padding="@dimen/material_clock_number_text_padding"
android:textSize="@dimen/material_clock_number_text_size"
android:visibility="gone"
tools:ignore="SpUsage" />
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<dimen name="material_clock_hand_center_dot_radius">4dp</dimen>
<!-- TODO(b/158490859) revisit number scaling -->
<dimen name="material_clock_number_text_size">15dp</dimen>
<dimen name="material_clock_number_text_padding">20dp</dimen>

<!-- cursor dimens -->
<dimen name="material_cursor_inset_bottom">-6dp</dimen>
Expand Down

0 comments on commit f9914da

Please sign in to comment.