|
30 | 30 | import android.content.res.TypedArray; |
31 | 31 | import android.os.Bundle; |
32 | 32 | import androidx.fragment.app.DialogFragment; |
| 33 | +import androidx.appcompat.widget.TooltipCompat; |
33 | 34 | import android.text.TextUtils; |
34 | | -import android.util.Pair; |
35 | 35 | import android.util.TypedValue; |
36 | 36 | import android.view.LayoutInflater; |
37 | 37 | import android.view.View; |
@@ -398,9 +398,12 @@ private void updateInputMode(MaterialButton modeButton) { |
398 | 398 | initializeOrRetrieveActivePresenterForMode(inputMode, timePickerView, textInputStub); |
399 | 399 | activePresenter.show(); |
400 | 400 | activePresenter.invalidate(); |
401 | | - Pair<Integer, Integer> buttonData = dataForMode(inputMode); |
402 | | - modeButton.setIconResource(buttonData.first); |
403 | | - modeButton.setContentDescription(getResources().getString(buttonData.second)); |
| 401 | + ModeButtonData modeButtonData = getModeButtonData(inputMode); |
| 402 | + modeButton.setIconResource(modeButtonData.iconResId); |
| 403 | + modeButton.setContentDescription( |
| 404 | + getResources().getString(modeButtonData.contentDescriptionResId)); |
| 405 | + TooltipCompat.setTooltipText( |
| 406 | + modeButton, getResources().getString(modeButtonData.tooltipTextResId)); |
404 | 407 | modeButton.sendAccessibilityEvent( |
405 | 408 | AccessibilityEventCompat.CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION); |
406 | 409 | } |
@@ -432,15 +435,21 @@ private TimePickerPresenter initializeOrRetrieveActivePresenterForMode( |
432 | 435 | return timePickerTextInputPresenter; |
433 | 436 | } |
434 | 437 |
|
435 | | - private Pair<Integer, Integer> dataForMode(@InputMode int mode) { |
| 438 | + private ModeButtonData getModeButtonData(@InputMode int mode) { |
436 | 439 | switch (mode) { |
437 | 440 | case INPUT_MODE_KEYBOARD: |
438 | | - return new Pair<>(clockIcon, R.string.material_timepicker_clock_mode_description); |
| 441 | + return new ModeButtonData( |
| 442 | + clockIcon, |
| 443 | + R.string.material_timepicker_clock_mode_description, |
| 444 | + R.string.material_timepicker_clock_mode_tooltip); |
439 | 445 | case INPUT_MODE_CLOCK: |
440 | | - return new Pair<>(keyboardIcon, R.string.material_timepicker_text_input_mode_description); |
| 446 | + return new ModeButtonData( |
| 447 | + keyboardIcon, |
| 448 | + R.string.material_timepicker_text_input_mode_description, |
| 449 | + R.string.material_timepicker_text_input_mode_tooltip); |
| 450 | + default: |
| 451 | + throw new IllegalArgumentException("no button data for mode: " + mode); |
441 | 452 | } |
442 | | - |
443 | | - throw new IllegalArgumentException("no icon for mode: " + mode); |
444 | 453 | } |
445 | 454 |
|
446 | 455 | @Nullable |
@@ -677,4 +686,19 @@ public MaterialTimePicker build() { |
677 | 686 | return MaterialTimePicker.newInstance(this); |
678 | 687 | } |
679 | 688 | } |
| 689 | + |
| 690 | + private static final class ModeButtonData { |
| 691 | + @DrawableRes final int iconResId; |
| 692 | + @StringRes final int contentDescriptionResId; |
| 693 | + @StringRes final int tooltipTextResId; |
| 694 | + |
| 695 | + ModeButtonData( |
| 696 | + @DrawableRes int iconResId, |
| 697 | + @StringRes int contentDescriptionResId, |
| 698 | + @StringRes int tooltipTextResId) { |
| 699 | + this.iconResId = iconResId; |
| 700 | + this.contentDescriptionResId = contentDescriptionResId; |
| 701 | + this.tooltipTextResId = tooltipTextResId; |
| 702 | + } |
| 703 | + } |
680 | 704 | } |
0 commit comments