Skip to content

Commit

Permalink
[MaterialDatePicker] Capitalize standalone date
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 495627493
  • Loading branch information
paulfthomas authored and imhappi committed Dec 16, 2022
1 parent 169bbca commit d4c16e8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class DateStrings {
private DateStrings() {}

static String getYearMonth(long timeInMillis) {
if (VERSION.SDK_INT >= VERSION_CODES.N) {
return UtcDates.getYearMonthFormat(Locale.getDefault()).format(new Date(timeInMillis));
}
int flags = DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_NO_MONTH_DAY | DateUtils.FORMAT_UTC;
return DateUtils.formatDateTime(null, timeInMillis, flags);
}
Expand Down
7 changes: 7 additions & 0 deletions lib/java/com/google/android/material/datepicker/UtcDates.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import android.annotation.TargetApi;
import android.content.res.Resources;
import android.icu.text.DisplayContext;
import android.os.Build.VERSION_CODES;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -138,6 +139,7 @@ private static android.icu.text.DateFormat getAndroidFormat(String pattern, Loca
android.icu.text.DateFormat format =
android.icu.text.DateFormat.getInstanceForSkeleton(pattern, locale);
format.setTimeZone(getUtcAndroidTimeZone());
format.setContext(DisplayContext.CAPITALIZATION_FOR_STANDALONE);
return format;
}

Expand Down Expand Up @@ -183,6 +185,11 @@ private static SimpleDateFormat getSimpleFormat(String pattern, Locale locale) {
return format;
}

@TargetApi(VERSION_CODES.N)
static android.icu.text.DateFormat getYearMonthFormat(Locale locale) {
return getAndroidFormat(android.icu.text.DateFormat.YEAR_MONTH, locale);
}

@TargetApi(VERSION_CODES.N)
static android.icu.text.DateFormat getYearAbbrMonthDayFormat(Locale locale) {
return getAndroidFormat(android.icu.text.DateFormat.YEAR_ABBR_MONTH_DAY, locale);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<LinearLayout
android:id="@+id/mtrl_picker_header"
style="?attr/materialCalendarHeaderLayout"
android:layout_width="match_parent"
android:layout_height="@dimen/mtrl_calendar_header_height"
android:layout_gravity="top"
android:paddingStart="@dimen/mtrl_calendar_header_content_padding"
android:paddingEnd="@dimen/mtrl_calendar_header_content_padding"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
<LinearLayout
android:id="@+id/fullscreen_header"
style="?attr/materialCalendarHeaderLayout"
android:layout_width="match_parent"
android:layout_height="@dimen/mtrl_calendar_header_height_fullscreen"
android:layout_gravity="top|center_horizontal"
android:orientation="horizontal"
android:paddingStart="@dimen/mtrl_calendar_header_content_padding_fullscreen"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/mtrl_picker_header_selection_text"
style="?attr/materialCalendarHeaderSelection"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="start|bottom"
app:firstBaselineToTopHeight="@dimen/mtrl_calendar_selection_text_baseline_to_top"
app:lineHeight="@dimen/mtrl_calendar_header_selection_line_height"
Expand Down

0 comments on commit d4c16e8

Please sign in to comment.