Skip to content

Commit

Permalink
[Date Picker] ContentDescription for "DayName" is not properly gettin…
Browse files Browse the repository at this point in the history
…g read by talkback for the German language

Resolves #3051

GIT_ORIGIN_REV_ID=91b350bf4830f5903d4809a1c3b097bbec2c2b27
PiperOrigin-RevId: 524068644
  • Loading branch information
kavitamp authored and drchen committed Apr 17, 2023
1 parent 3029ff0 commit 35bd1fc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
Expand Up @@ -90,7 +90,7 @@ static String getMonthDayOfWeekDay(long timeInMillis) {

static String getMonthDayOfWeekDay(long timeInMillis, Locale locale) {
if (VERSION.SDK_INT >= VERSION_CODES.N) {
return UtcDates.getAbbrMonthWeekdayDayFormat(locale).format(new Date(timeInMillis));
return UtcDates.getMonthWeekdayDayFormat(locale).format(new Date(timeInMillis));
}
return UtcDates.getFullFormat(locale).format(new Date(timeInMillis));
}
Expand All @@ -101,7 +101,7 @@ static String getYearMonthDayOfWeekDay(long timeInMillis) {

static String getYearMonthDayOfWeekDay(long timeInMillis, Locale locale) {
if (VERSION.SDK_INT >= VERSION_CODES.N) {
return UtcDates.getYearAbbrMonthWeekdayDayFormat(locale).format(new Date(timeInMillis));
return UtcDates.getYearMonthWeekdayDayFormat(locale).format(new Date(timeInMillis));
}
return UtcDates.getFullFormat(locale).format(new Date(timeInMillis));
}
Expand Down
8 changes: 4 additions & 4 deletions lib/java/com/google/android/material/datepicker/UtcDates.java
Expand Up @@ -212,13 +212,13 @@ static android.icu.text.DateFormat getAbbrMonthDayFormat(Locale locale) {
}

@TargetApi(VERSION_CODES.N)
static android.icu.text.DateFormat getAbbrMonthWeekdayDayFormat(Locale locale) {
return getAndroidFormat(android.icu.text.DateFormat.ABBR_MONTH_WEEKDAY_DAY, locale);
static android.icu.text.DateFormat getMonthWeekdayDayFormat(Locale locale) {
return getAndroidFormat(android.icu.text.DateFormat.MONTH_WEEKDAY_DAY, locale);
}

@TargetApi(VERSION_CODES.N)
static android.icu.text.DateFormat getYearAbbrMonthWeekdayDayFormat(Locale locale) {
return getAndroidFormat(android.icu.text.DateFormat.YEAR_ABBR_MONTH_WEEKDAY_DAY, locale);
static android.icu.text.DateFormat getYearMonthWeekdayDayFormat(Locale locale) {
return getAndroidFormat(android.icu.text.DateFormat.YEAR_MONTH_WEEKDAY_DAY, locale);
}

static DateFormat getMediumFormat() {
Expand Down
Expand Up @@ -310,7 +310,7 @@ public void getDayContentDescription_notToday() {
/* isStartOfRange= */ false,
/* isEndOfRange= */ false);

assertThat(contentDescription, is("Mon, Nov 30, 2020"));
assertThat(contentDescription, is("Monday, November 30, 2020"));
}

@Test
Expand All @@ -324,7 +324,7 @@ public void getDayContentDescription_notToday_startOfRange() {
/* isStartOfRange= */ true,
/* isEndOfRange= */ false);

assertThat(contentDescription, is("Start date Mon, Nov 30, 2020"));
assertThat(contentDescription, is("Start date Monday, November 30, 2020"));
}

@Test
Expand All @@ -338,7 +338,7 @@ public void getDayContentDescription_notToday_endOfRange() {
/* isStartOfRange= */ false,
/* isEndOfRange= */ true);

assertThat(contentDescription, is("End date Mon, Nov 30, 2020"));
assertThat(contentDescription, is("End date Monday, November 30, 2020"));
}

@Test
Expand All @@ -352,7 +352,7 @@ public void getDayContentDescription_notToday_startAndEndOfRange() {
/* isStartOfRange= */ true,
/* isEndOfRange= */ true);

assertThat(contentDescription, is("Start date Mon, Nov 30, 2020"));
assertThat(contentDescription, is("Start date Monday, November 30, 2020"));
}

@Test
Expand All @@ -366,7 +366,7 @@ public void getDayContentDescription_today() {
/* isStartOfRange= */ false,
/* isEndOfRange= */ false);

assertThat(contentDescription, is("Today Mon, Nov 30, 2020"));
assertThat(contentDescription, is("Today Monday, November 30, 2020"));
}

@Test
Expand All @@ -380,7 +380,7 @@ public void getDayContentDescription_today_startOfRange() {
/* isStartOfRange= */ true,
/* isEndOfRange= */ false);

assertThat(contentDescription, is("Start date Today Mon, Nov 30, 2020"));
assertThat(contentDescription, is("Start date Today Monday, November 30, 2020"));
}

@Test
Expand All @@ -394,7 +394,7 @@ public void getDayContentDescription_today_endOfRange() {
/* isStartOfRange= */ false,
/* isEndOfRange= */ true);

assertThat(contentDescription, is("End date Today Mon, Nov 30, 2020"));
assertThat(contentDescription, is("End date Today Monday, November 30, 2020"));
}

@Test
Expand All @@ -408,7 +408,21 @@ public void getDayContentDescription_today_startAndEndOfRange() {
/* isStartOfRange= */ true,
/* isEndOfRange= */ true);

assertThat(contentDescription, is("Start date Today Mon, Nov 30, 2020"));
assertThat(contentDescription, is("Start date Today Monday, November 30, 2020"));
}

@Test
public void getLocalizedDayContentDescription_german() {
startDate = setupLocalizedCalendar(Locale.GERMAN, 2020, 10, 30);
String contentDescription =
DateStrings.getDayContentDescription(
ApplicationProvider.getApplicationContext(),
startDate.getTimeInMillis(),
/* isToday= */ false,
/* isStartOfRange= */ false,
/* isEndOfRange= */ false);

assertThat(contentDescription, is("Montag, 30. November 2020"));
}

@Test
Expand Down

0 comments on commit 35bd1fc

Please sign in to comment.