Skip to content

Commit

Permalink
[MaterialTimePicker][a11y] Fix wrong clock item selection
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 431938695
  • Loading branch information
paulfthomas authored and hunterstich committed Mar 2, 2022
1 parent 52daa6f commit 9cdf4c9
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions lib/java/com/google/android/material/timepicker/ClockFaceView.java
Expand Up @@ -277,22 +277,26 @@ private void findIntersectingTextView() {
continue;
}
tv.getDrawingRect(textViewRect);
textViewRect.offset(tv.getPaddingLeft(), tv.getPaddingTop());
offsetDescendantRectToMyCoords(tv, textViewRect);

scratch.set(textViewRect);
if (RectF.intersects(selectorBox, scratch)) {
tv.getPaint().setShader(getGradient(selectorBox));
tv.setSelected(true);
} else {
tv.getPaint().setShader(null); // clear
tv.setSelected(false);
}
// set selection
tv.setSelected(selectorBox.contains(textViewRect.centerX(), textViewRect.centerY()));

// set gradient
RadialGradient radialGradient = getGradientForTextView(selectorBox, textViewRect, tv);
tv.getPaint().setShader(radialGradient);
tv.invalidate();
}
}

private RadialGradient getGradient(RectF selectorBox) {
@Nullable
private RadialGradient getGradientForTextView(RectF selectorBox, Rect tvBox, TextView tv) {
scratch.set(tvBox);
scratch.offset(tv.getPaddingLeft(), tv.getPaddingTop());
if (!RectF.intersects(selectorBox, scratch)) {
return null;
}

return new RadialGradient(
(selectorBox.centerX() - scratch.left),
(selectorBox.centerY() - scratch.top),
Expand Down

0 comments on commit 9cdf4c9

Please sign in to comment.