Loading src/com/android/deskclock/ClockFragment.java +11 −1 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.view.View.OnTouchListener; import android.view.ViewConfiguration; import android.view.ViewGroup; import android.widget.ListView; import android.widget.TextClock; import com.android.deskclock.alarms.AlarmNotifications; import com.android.deskclock.worldclock.WorldClockAdapter; Loading Loading @@ -73,8 +74,15 @@ public class ClockFragment extends DeskClockFragment implements OnSharedPreferen } else { mAdapter.notifyDataSetChanged(); } // Reloading the cities list with new localized names // Locale change: update digital clock format and // reload the cities list with new localized names if (action.equals(Intent.ACTION_LOCALE_CHANGED)) { if (mDigitalClock != null) { Utils.setTimeFormat( (TextClock)(mDigitalClock.findViewById(R.id.digital_clock)), (int)context.getResources(). getDimension(R.dimen.bottom_text_size)); } mAdapter.loadCitiesDb(context); mAdapter.notifyDataSetChanged(); } Loading Loading @@ -182,6 +190,8 @@ public class ClockFragment extends DeskClockFragment implements OnSharedPreferen mDigitalClock = mClockFrame.findViewById(R.id.digital_clock); mAnalogClock = mClockFrame.findViewById(R.id.analog_clock); Utils.setTimeFormat((TextClock)(mDigitalClock.findViewById(R.id.digital_clock)), (int)getResources().getDimension(R.dimen.bottom_text_size)); View footerView = inflater.inflate(R.layout.blank_footer_view, mList, false); footerView.setBackgroundResource(R.color.blackish); mList.addFooterView(footerView); Loading src/com/android/deskclock/Utils.java +36 −0 Original line number Diff line number Diff line Loading @@ -38,14 +38,20 @@ import android.os.Handler; import android.os.SystemClock; import android.preference.PreferenceManager; import android.provider.Settings; import android.text.Spannable; import android.text.SpannableString; import android.text.TextUtils; import android.text.format.DateFormat; import android.text.format.DateUtils; import android.text.format.Time; import android.text.style.AbsoluteSizeSpan; import android.text.style.StyleSpan; import android.text.style.TypefaceSpan; import android.view.MenuItem; import android.view.View; import android.view.animation.AccelerateInterpolator; import android.view.animation.DecelerateInterpolator; import android.widget.TextClock; import android.widget.TextView; import com.android.deskclock.stopwatch.Stopwatches; Loading Loading @@ -477,6 +483,36 @@ public class Utils { } } /*** * Formats the 12 hour time in the TextClock according to the Locale with a special * formatting treatment for the am/pm label. * @param clock - TextClock to format * @param amPmFormat - a format string to set a specific font for the am/pm */ public static void setTimeFormat(TextClock clock, int amPmFontSize) { if (clock != null) { // Get the best format for h:mm am/pm according to the locale String skeleton = "hma"; String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton); // Replace spaces with "Hair Space" pattern = pattern.replaceAll(" ", "\u200A"); // Build a spannable so that the am/pm will be formatted int amPmPos = pattern.indexOf('a'); if (amPmPos == -1) { clock.setFormat12Hour(pattern); } else { Spannable sp = new SpannableString(pattern); sp.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), amPmPos, amPmPos + 1, Spannable.SPAN_POINT_MARK); sp.setSpan(new AbsoluteSizeSpan(amPmFontSize), amPmPos, amPmPos + 1, Spannable.SPAN_POINT_MARK); sp.setSpan(new TypefaceSpan("sans-serif-condensed"), amPmPos, amPmPos + 1, Spannable.SPAN_POINT_MARK); clock.setFormat12Hour(sp); } } } public static CityObj[] loadCitiesFromXml(Context c) { Resources r = c.getResources(); // Read strings array of name,timezone, id Loading Loading
src/com/android/deskclock/ClockFragment.java +11 −1 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.view.View.OnTouchListener; import android.view.ViewConfiguration; import android.view.ViewGroup; import android.widget.ListView; import android.widget.TextClock; import com.android.deskclock.alarms.AlarmNotifications; import com.android.deskclock.worldclock.WorldClockAdapter; Loading Loading @@ -73,8 +74,15 @@ public class ClockFragment extends DeskClockFragment implements OnSharedPreferen } else { mAdapter.notifyDataSetChanged(); } // Reloading the cities list with new localized names // Locale change: update digital clock format and // reload the cities list with new localized names if (action.equals(Intent.ACTION_LOCALE_CHANGED)) { if (mDigitalClock != null) { Utils.setTimeFormat( (TextClock)(mDigitalClock.findViewById(R.id.digital_clock)), (int)context.getResources(). getDimension(R.dimen.bottom_text_size)); } mAdapter.loadCitiesDb(context); mAdapter.notifyDataSetChanged(); } Loading Loading @@ -182,6 +190,8 @@ public class ClockFragment extends DeskClockFragment implements OnSharedPreferen mDigitalClock = mClockFrame.findViewById(R.id.digital_clock); mAnalogClock = mClockFrame.findViewById(R.id.analog_clock); Utils.setTimeFormat((TextClock)(mDigitalClock.findViewById(R.id.digital_clock)), (int)getResources().getDimension(R.dimen.bottom_text_size)); View footerView = inflater.inflate(R.layout.blank_footer_view, mList, false); footerView.setBackgroundResource(R.color.blackish); mList.addFooterView(footerView); Loading
src/com/android/deskclock/Utils.java +36 −0 Original line number Diff line number Diff line Loading @@ -38,14 +38,20 @@ import android.os.Handler; import android.os.SystemClock; import android.preference.PreferenceManager; import android.provider.Settings; import android.text.Spannable; import android.text.SpannableString; import android.text.TextUtils; import android.text.format.DateFormat; import android.text.format.DateUtils; import android.text.format.Time; import android.text.style.AbsoluteSizeSpan; import android.text.style.StyleSpan; import android.text.style.TypefaceSpan; import android.view.MenuItem; import android.view.View; import android.view.animation.AccelerateInterpolator; import android.view.animation.DecelerateInterpolator; import android.widget.TextClock; import android.widget.TextView; import com.android.deskclock.stopwatch.Stopwatches; Loading Loading @@ -477,6 +483,36 @@ public class Utils { } } /*** * Formats the 12 hour time in the TextClock according to the Locale with a special * formatting treatment for the am/pm label. * @param clock - TextClock to format * @param amPmFormat - a format string to set a specific font for the am/pm */ public static void setTimeFormat(TextClock clock, int amPmFontSize) { if (clock != null) { // Get the best format for h:mm am/pm according to the locale String skeleton = "hma"; String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton); // Replace spaces with "Hair Space" pattern = pattern.replaceAll(" ", "\u200A"); // Build a spannable so that the am/pm will be formatted int amPmPos = pattern.indexOf('a'); if (amPmPos == -1) { clock.setFormat12Hour(pattern); } else { Spannable sp = new SpannableString(pattern); sp.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), amPmPos, amPmPos + 1, Spannable.SPAN_POINT_MARK); sp.setSpan(new AbsoluteSizeSpan(amPmFontSize), amPmPos, amPmPos + 1, Spannable.SPAN_POINT_MARK); sp.setSpan(new TypefaceSpan("sans-serif-condensed"), amPmPos, amPmPos + 1, Spannable.SPAN_POINT_MARK); clock.setFormat12Hour(sp); } } } public static CityObj[] loadCitiesFromXml(Context c) { Resources r = c.getResources(); // Read strings array of name,timezone, id Loading