Skip to content

Commit 1fd35bc

Browse files
Material Design Teamdsn5ft
authored andcommitted
[DatePicker] Add tooltips to icon buttons
Adds tooltips to the month navigation buttons in MaterialCalendar and the header toggle button in MaterialDatePicker PiperOrigin-RevId: 853333712
1 parent 67bd159 commit 1fd35bc

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

lib/java/com/google/android/material/datepicker/MaterialCalendar.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import androidx.recyclerview.widget.RecyclerView.ItemDecoration;
2929
import androidx.recyclerview.widget.RecyclerView.OnScrollListener;
3030
import androidx.recyclerview.widget.RecyclerView.State;
31+
import androidx.appcompat.widget.TooltipCompat;
3132
import android.view.ContextThemeWrapper;
3233
import android.view.LayoutInflater;
3334
import android.view.View;
@@ -534,8 +535,10 @@ public void onInitializeAccessibilityNodeInfo(
534535

535536
monthPrev = root.findViewById(R.id.month_navigation_previous);
536537
monthPrev.setTag(NAVIGATION_PREV_TAG);
538+
TooltipCompat.setTooltipText(monthPrev, getString(R.string.mtrl_picker_prev_month_tooltip));
537539
monthNext = root.findViewById(R.id.month_navigation_next);
538540
monthNext.setTag(NAVIGATION_NEXT_TAG);
541+
TooltipCompat.setTooltipText(monthNext, getString(R.string.mtrl_picker_next_month_tooltip));
539542

540543
yearFrame = root.findViewById(R.id.mtrl_calendar_year_selector_frame);
541544
dayFrame = root.findViewById(R.id.mtrl_calendar_day_selector_frame);

lib/java/com/google/android/material/datepicker/MaterialDatePicker.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import androidx.fragment.app.DialogFragment;
3636
import androidx.fragment.app.Fragment;
3737
import androidx.appcompat.content.res.AppCompatResources;
38+
import androidx.appcompat.widget.TooltipCompat;
3839
import android.text.TextUtils;
3940
import android.view.LayoutInflater;
4041
import android.view.View;
@@ -557,6 +558,7 @@ private void initHeaderToggle(Context context) {
557558
// This information is not useful; we remove the delegate and use custom content descriptions.
558559
ViewCompat.setAccessibilityDelegate(headerToggleButton, null);
559560
updateToggleContentDescription(headerToggleButton);
561+
updateToggleTooltip(headerToggleButton);
560562
headerToggleButton.setOnClickListener(
561563
v -> {
562564
// Update confirm button in case in progress selection has been reset
@@ -565,6 +567,7 @@ private void initHeaderToggle(Context context) {
565567
headerToggleButton.toggle();
566568
inputMode = (inputMode == INPUT_MODE_TEXT) ? INPUT_MODE_CALENDAR : INPUT_MODE_TEXT;
567569
updateToggleContentDescription(headerToggleButton);
570+
updateToggleTooltip(headerToggleButton);
568571
startPickerFragment();
569572
});
570573
}
@@ -577,6 +580,16 @@ private void updateToggleContentDescription(@NonNull CheckableImageButton toggle
577580
headerToggleButton.setContentDescription(contentDescription);
578581
}
579582

583+
private void updateToggleTooltip(@NonNull CheckableImageButton toggle) {
584+
String tooltipText =
585+
inputMode == INPUT_MODE_TEXT
586+
? toggle
587+
.getContext()
588+
.getString(R.string.mtrl_picker_toggle_to_calendar_input_mode_tooltip)
589+
: toggle.getContext().getString(R.string.mtrl_picker_toggle_to_text_input_mode_tooltip);
590+
TooltipCompat.setTooltipText(headerToggleButton, tooltipText);
591+
}
592+
580593
private DateSelector<S> getDateSelector() {
581594
if (dateSelector == null) {
582595
dateSelector = getArguments().getParcelable(DATE_SELECTOR_KEY);

lib/java/com/google/android/material/datepicker/res/values/strings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,13 @@
4141
<string name="mtrl_picker_invalid_format_example" description="Tells a user what an example valid entry looks like. [CHAR_LIMIT=18]">Example: %1$s</string>
4242

4343
<string name="mtrl_picker_toggle_to_calendar_input_mode" description="a11y string to indicate this button changes the input mode to a calendar [CHAR_LIMIT=NONE]">Switch to calendar input mode</string>
44+
<string name="mtrl_picker_toggle_to_calendar_input_mode_tooltip" description="Tooltip for button to switch to calendar input mode [CHAR_LIMIT=60]">Switch to calendar</string>
4445
<string name="mtrl_picker_toggle_to_text_input_mode" description="a11y string to indicate this button changes the input mode to a text field [CHAR_LIMIT=NONE]">Switch to text input mode</string>
46+
<string name="mtrl_picker_toggle_to_text_input_mode_tooltip" description="Tooltip for button to switch to text input mode [CHAR_LIMIT=60]">Switch to text input</string>
4547
<string name="mtrl_picker_a11y_prev_month" description="a11y string to indicate this button moves the calendar to the previous month [CHAR_LIMIT=NONE]">Change to previous month</string>
48+
<string name="mtrl_picker_prev_month_tooltip" description="Tooltip for button to navigate to the previous month [CHAR_LIMIT=60]">Previous month</string>
4649
<string name="mtrl_picker_a11y_next_month" description="a11y string to indicate this button moves the calendar to the next month [CHAR_LIMIT=NONE]">Change to next month</string>
50+
<string name="mtrl_picker_next_month_tooltip" description="Tooltip for button to navigate to the next month [CHAR_LIMIT=60]">Next month</string>
4751
<string name="mtrl_picker_toggle_to_year_selection" description="a11y string to indicate this button switches the user to choosing a year [CHAR_LIMIT=NONE]">Switch to year view</string>
4852
<string name="mtrl_picker_pane_title_year_view" description="a11y string to announce the title of the date picker pane when it displays a list of selectable years [CHAR_LIMIT=NONE]">Year view</string>
4953
<string name="mtrl_picker_toggle_to_day_selection" description="a11y string to indicate this button switches the user to choosing a day [CHAR_LIMIT=NONE]">Switch to Calendar view</string>

0 commit comments

Comments
 (0)