1 package com.android.car.carlauncher; 2 3 import android.content.Context; 4 import android.text.format.DateFormat; 5 import android.util.AttributeSet; 6 import android.widget.TextClock; 7 8 import java.util.Locale; 9 10 /** 11 * {@link TextClock} implementation which expects a date format skeleton for 12 * {@link android.R.styleable#TextClock_format12Hour} and 13 * {@link android.R.styleable#TextClock_format24Hour} and applies the best format as determined by 14 * {@link DateFormat#getBestDateTimePattern(java.util.Locale, String)}. 15 */ 16 public class LocalizedTextClock extends TextClock { 17 LocalizedTextClock(Context context)18 public LocalizedTextClock(Context context) { 19 super(context); 20 } 21 LocalizedTextClock(Context context, AttributeSet attrs)22 public LocalizedTextClock(Context context, AttributeSet attrs) { 23 super(context, attrs, 0); 24 } 25 LocalizedTextClock(Context context, AttributeSet attrs, int defStyleAttr)26 public LocalizedTextClock(Context context, AttributeSet attrs, int defStyleAttr) { 27 this(context, attrs, defStyleAttr, 0); 28 } 29 LocalizedTextClock(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)30 public LocalizedTextClock(Context context, AttributeSet attrs, int defStyleAttr, 31 int defStyleRes) { 32 super(context, attrs, defStyleAttr, defStyleRes); 33 } 34 35 @Override onFinishInflate()36 protected void onFinishInflate() { 37 super.onFinishInflate(); 38 setFormat12Hour(DateFormat.getBestDateTimePattern(Locale.getDefault(), 39 getFormat12Hour().toString())); 40 setFormat24Hour(DateFormat.getBestDateTimePattern(Locale.getDefault(), 41 getFormat24Hour().toString())); 42 } 43 } 44