@@ -84,8 +84,16 @@ public final class MaterialDatePicker<S> extends DialogFragment {
84
84
private static final String TITLE_TEXT_KEY = "TITLE_TEXT_KEY" ;
85
85
private static final String POSITIVE_BUTTON_TEXT_RES_ID_KEY = "POSITIVE_BUTTON_TEXT_RES_ID_KEY" ;
86
86
private static final String POSITIVE_BUTTON_TEXT_KEY = "POSITIVE_BUTTON_TEXT_KEY" ;
87
+ private static final String POSITIVE_BUTTON_CONTENT_DESCRIPTION_RES_ID_KEY =
88
+ "POSITIVE_BUTTON_CONTENT_DESCRIPTION_RES_ID_KEY" ;
89
+ private static final String POSITIVE_BUTTON_CONTENT_DESCRIPTION_KEY =
90
+ "POSITIVE_BUTTON_CONTENT_DESCRIPTION_KEY" ;
87
91
private static final String NEGATIVE_BUTTON_TEXT_RES_ID_KEY = "NEGATIVE_BUTTON_TEXT_RES_ID_KEY" ;
88
92
private static final String NEGATIVE_BUTTON_TEXT_KEY = "NEGATIVE_BUTTON_TEXT_KEY" ;
93
+ private static final String NEGATIVE_BUTTON_CONTENT_DESCRIPTION_RES_ID_KEY =
94
+ "NEGATIVE_BUTTON_CONTENT_DESCRIPTION_RES_ID_KEY" ;
95
+ private static final String NEGATIVE_BUTTON_CONTENT_DESCRIPTION_KEY =
96
+ "NEGATIVE_BUTTON_CONTENT_DESCRIPTION_KEY" ;
89
97
private static final String INPUT_MODE_KEY = "INPUT_MODE_KEY" ;
90
98
91
99
static final Object CONFIRM_BUTTON_TAG = "CONFIRM_BUTTON_TAG" ;
@@ -146,9 +154,12 @@ public String getHeaderText() {
146
154
@ InputMode private int inputMode ;
147
155
@ StringRes private int positiveButtonTextResId ;
148
156
private CharSequence positiveButtonText ;
157
+ @ StringRes private int positiveButtonContentDescriptionResId ;
158
+ private CharSequence positiveButtonContentDescription ;
149
159
@ StringRes private int negativeButtonTextResId ;
150
160
private CharSequence negativeButtonText ;
151
-
161
+ @ StringRes private int negativeButtonContentDescriptionResId ;
162
+ private CharSequence negativeButtonContentDescription ;
152
163
private TextView headerTitleTextView ;
153
164
private TextView headerSelectionText ;
154
165
private CheckableImageButton headerToggleButton ;
@@ -172,8 +183,18 @@ static <S> MaterialDatePicker<S> newInstance(@NonNull Builder<S> options) {
172
183
args .putInt (INPUT_MODE_KEY , options .inputMode );
173
184
args .putInt (POSITIVE_BUTTON_TEXT_RES_ID_KEY , options .positiveButtonTextResId );
174
185
args .putCharSequence (POSITIVE_BUTTON_TEXT_KEY , options .positiveButtonText );
186
+ args .putInt (
187
+ POSITIVE_BUTTON_CONTENT_DESCRIPTION_RES_ID_KEY ,
188
+ options .positiveButtonContentDescriptionResId );
189
+ args .putCharSequence (
190
+ POSITIVE_BUTTON_CONTENT_DESCRIPTION_KEY , options .positiveButtonContentDescription );
175
191
args .putInt (NEGATIVE_BUTTON_TEXT_RES_ID_KEY , options .negativeButtonTextResId );
176
192
args .putCharSequence (NEGATIVE_BUTTON_TEXT_KEY , options .negativeButtonText );
193
+ args .putInt (
194
+ NEGATIVE_BUTTON_CONTENT_DESCRIPTION_RES_ID_KEY ,
195
+ options .negativeButtonContentDescriptionResId );
196
+ args .putCharSequence (
197
+ NEGATIVE_BUTTON_CONTENT_DESCRIPTION_KEY , options .negativeButtonContentDescription );
177
198
materialDatePickerDialogFragment .setArguments (args );
178
199
return materialDatePickerDialogFragment ;
179
200
}
@@ -197,8 +218,16 @@ public final void onSaveInstanceState(@NonNull Bundle bundle) {
197
218
bundle .putInt (INPUT_MODE_KEY , inputMode );
198
219
bundle .putInt (POSITIVE_BUTTON_TEXT_RES_ID_KEY , positiveButtonTextResId );
199
220
bundle .putCharSequence (POSITIVE_BUTTON_TEXT_KEY , positiveButtonText );
221
+ bundle .putInt (
222
+ POSITIVE_BUTTON_CONTENT_DESCRIPTION_RES_ID_KEY , positiveButtonContentDescriptionResId );
223
+ bundle .putCharSequence (
224
+ POSITIVE_BUTTON_CONTENT_DESCRIPTION_KEY , positiveButtonContentDescription );
200
225
bundle .putInt (NEGATIVE_BUTTON_TEXT_RES_ID_KEY , negativeButtonTextResId );
201
226
bundle .putCharSequence (NEGATIVE_BUTTON_TEXT_KEY , negativeButtonText );
227
+ bundle .putInt (
228
+ NEGATIVE_BUTTON_CONTENT_DESCRIPTION_RES_ID_KEY , negativeButtonContentDescriptionResId );
229
+ bundle .putCharSequence (
230
+ NEGATIVE_BUTTON_CONTENT_DESCRIPTION_KEY , negativeButtonContentDescription );
202
231
}
203
232
204
233
@ Override
@@ -214,8 +243,16 @@ public final void onCreate(@Nullable Bundle bundle) {
214
243
inputMode = activeBundle .getInt (INPUT_MODE_KEY );
215
244
positiveButtonTextResId = activeBundle .getInt (POSITIVE_BUTTON_TEXT_RES_ID_KEY );
216
245
positiveButtonText = activeBundle .getCharSequence (POSITIVE_BUTTON_TEXT_KEY );
246
+ positiveButtonContentDescriptionResId =
247
+ activeBundle .getInt (POSITIVE_BUTTON_CONTENT_DESCRIPTION_RES_ID_KEY );
248
+ positiveButtonContentDescription =
249
+ activeBundle .getCharSequence (POSITIVE_BUTTON_CONTENT_DESCRIPTION_KEY );
217
250
negativeButtonTextResId = activeBundle .getInt (NEGATIVE_BUTTON_TEXT_RES_ID_KEY );
218
251
negativeButtonText = activeBundle .getCharSequence (NEGATIVE_BUTTON_TEXT_KEY );
252
+ negativeButtonContentDescriptionResId =
253
+ activeBundle .getInt (NEGATIVE_BUTTON_CONTENT_DESCRIPTION_RES_ID_KEY );
254
+ negativeButtonContentDescription =
255
+ activeBundle .getCharSequence (NEGATIVE_BUTTON_CONTENT_DESCRIPTION_KEY );
219
256
220
257
fullTitleText =
221
258
titleText != null ? titleText : requireContext ().getResources ().getText (titleTextResId );
@@ -302,6 +339,12 @@ public final View onCreateView(
302
339
} else if (positiveButtonTextResId != 0 ) {
303
340
confirmButton .setText (positiveButtonTextResId );
304
341
}
342
+ if (positiveButtonContentDescription != null ) {
343
+ confirmButton .setContentDescription (positiveButtonContentDescription );
344
+ } else if (positiveButtonContentDescriptionResId != 0 ) {
345
+ confirmButton .setContentDescription (
346
+ getContext ().getResources ().getText (positiveButtonContentDescriptionResId ));
347
+ }
305
348
confirmButton .setOnClickListener (
306
349
new View .OnClickListener () {
307
350
@ Override
@@ -321,6 +364,12 @@ public void onClick(View v) {
321
364
} else if (negativeButtonTextResId != 0 ) {
322
365
cancelButton .setText (negativeButtonTextResId );
323
366
}
367
+ if (negativeButtonContentDescription != null ) {
368
+ cancelButton .setContentDescription (negativeButtonContentDescription );
369
+ } else if (negativeButtonContentDescriptionResId != 0 ) {
370
+ cancelButton .setContentDescription (
371
+ getContext ().getResources ().getText (negativeButtonContentDescriptionResId ));
372
+ }
324
373
cancelButton .setOnClickListener (
325
374
new View .OnClickListener () {
326
375
@ Override
@@ -403,8 +452,7 @@ private void enableEdgeToEdgeIfNeeded(Window window) {
403
452
return ;
404
453
}
405
454
final View headerLayout = requireView ().findViewById (R .id .fullscreen_header );
406
- EdgeToEdgeUtils .applyEdgeToEdge (
407
- window , true , ViewUtils .getBackgroundColor (headerLayout ), null );
455
+ EdgeToEdgeUtils .applyEdgeToEdge (window , true , ViewUtils .getBackgroundColor (headerLayout ), null );
408
456
final int originalPaddingTop = headerLayout .getPaddingTop ();
409
457
final int originalHeaderHeight = headerLayout .getLayoutParams ().height ;
410
458
ViewCompat .setOnApplyWindowInsetsListener (
@@ -662,8 +710,12 @@ public static final class Builder<S> {
662
710
CharSequence titleText = null ;
663
711
int positiveButtonTextResId = 0 ;
664
712
CharSequence positiveButtonText = null ;
713
+ int positiveButtonContentDescriptionResId = 0 ;
714
+ CharSequence positiveButtonContentDescription = null ;
665
715
int negativeButtonTextResId = 0 ;
666
716
CharSequence negativeButtonText = null ;
717
+ int negativeButtonContentDescriptionResId = 0 ;
718
+ CharSequence negativeButtonContentDescription = null ;
667
719
@ Nullable S selection = null ;
668
720
@ InputMode int inputMode = INPUT_MODE_CALENDAR ;
669
721
@@ -797,6 +849,34 @@ public Builder<S> setPositiveButtonText(@Nullable CharSequence text) {
797
849
return this ;
798
850
}
799
851
852
+ /**
853
+ * Sets the content description used in the positive button
854
+ *
855
+ * @param contentDescriptionId resource id to be used as content description in the positive
856
+ * button
857
+ */
858
+ @ NonNull
859
+ @ CanIgnoreReturnValue
860
+ public Builder <S > setPositiveButtonContentDescription (@ StringRes int contentDescriptionId ) {
861
+ this .positiveButtonContentDescriptionResId = contentDescriptionId ;
862
+ this .positiveButtonContentDescription = null ;
863
+ return this ;
864
+ }
865
+
866
+ /**
867
+ * Sets the content description used in the positive button
868
+ *
869
+ * @param contentDescription content description used in the positive button
870
+ */
871
+ @ NonNull
872
+ @ CanIgnoreReturnValue
873
+ public Builder <S > setPositiveButtonContentDescription (
874
+ @ Nullable CharSequence contentDescription ) {
875
+ this .positiveButtonContentDescription = contentDescription ;
876
+ this .positiveButtonContentDescriptionResId = 0 ;
877
+ return this ;
878
+ }
879
+
800
880
/**
801
881
* Sets the text used in the negative button
802
882
*
@@ -823,6 +903,34 @@ public Builder<S> setNegativeButtonText(@Nullable CharSequence text) {
823
903
return this ;
824
904
}
825
905
906
+ /**
907
+ * Sets the content description used in the negative button
908
+ *
909
+ * @param contentDescriptionId resource id to be used as content description in the negative
910
+ * button
911
+ */
912
+ @ NonNull
913
+ @ CanIgnoreReturnValue
914
+ public Builder <S > setNegativeButtonContentDescription (@ StringRes int contentDescriptionId ) {
915
+ this .negativeButtonContentDescriptionResId = contentDescriptionId ;
916
+ this .negativeButtonContentDescription = null ;
917
+ return this ;
918
+ }
919
+
920
+ /**
921
+ * Sets the content description used in the negative button
922
+ *
923
+ * @param contentDescription content description used in the negative button
924
+ */
925
+ @ NonNull
926
+ @ CanIgnoreReturnValue
927
+ public Builder <S > setNegativeButtonContentDescription (
928
+ @ Nullable CharSequence contentDescription ) {
929
+ this .negativeButtonContentDescription = contentDescription ;
930
+ this .negativeButtonContentDescriptionResId = 0 ;
931
+ return this ;
932
+ }
933
+
826
934
/** Sets the input mode to start with. */
827
935
@ NonNull
828
936
@ CanIgnoreReturnValue
@@ -864,7 +972,8 @@ private Month createDefaultOpenAt() {
864
972
865
973
Month thisMonth = Month .current ();
866
974
return monthInValidRange (thisMonth , calendarConstraints )
867
- ? thisMonth : calendarConstraints .getStart ();
975
+ ? thisMonth
976
+ : calendarConstraints .getStart ();
868
977
}
869
978
870
979
private static boolean monthInValidRange (Month month , CalendarConstraints constraints ) {
0 commit comments