Loading src/com/android/alarmclock/DigitalAppWidgetProvider.java +3 −1 Original line number Diff line number Diff line Loading @@ -94,6 +94,7 @@ public class DigitalAppWidgetProvider extends AppWidgetProvider { RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget); float ratio = WidgetUtils.getScaleRatio(context, null, appWidgetId); WidgetUtils.setTimeFormat(widget, 0/*no am/pm*/, R.id.the_clock); WidgetUtils.setClockSize(context, widget, ratio); refreshAlarm(context, widget); appWidgetManager.partiallyUpdateAppWidget(appWidgetId, widget); Loading Loading @@ -165,8 +166,9 @@ public class DigitalAppWidgetProvider extends AppWidgetProvider { PendingIntent.getActivity(context, 0, new Intent(context, DeskClock.class), 0)); } // Setup alarm text and font sizes // Setup alarm text clock's format and font sizes refreshAlarm(context, widget); WidgetUtils.setTimeFormat(widget, 0/*no am/pm*/, R.id.the_clock); WidgetUtils.setClockSize(context, widget, ratio); // Set today's date format Loading src/com/android/alarmclock/DigitalWidgetViewsFactory.java +5 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.alarmclock; import android.appwidget.AppWidgetManager; import android.content.Context; import android.content.Intent; import android.content.res.Resources; import android.text.format.DateFormat; import android.util.Log; import android.util.TypedValue; Loading @@ -39,6 +40,7 @@ public class DigitalWidgetViewsFactory implements RemoteViewsFactory { private static final String TAG = "DigitalWidgetViewsFactory"; private Context mContext; private Resources mResources; private int mId = AppWidgetManager.INVALID_APPWIDGET_ID; private RemoteWorldClockAdapter mAdapter; private float mFontScale = 1; Loading Loading @@ -99,6 +101,8 @@ public class DigitalWidgetViewsFactory implements RemoteViewsFactory { now.setTimeZone(TimeZone.getTimeZone(cityTZ)); int cityDayOfWeek = now.get(Calendar.DAY_OF_WEEK); WidgetUtils.setTimeFormat(clock, (int)mResources.getDimension(R.dimen.widget_label_font_size), clockId); float fontSize = mFontScale * (DateFormat.is24HourFormat(mContext) ? mFont24Size : mFontSize); clock.setTextViewTextSize(clockId, TypedValue.COMPLEX_UNIT_PX, fontSize * mFontScale); Loading Loading @@ -130,6 +134,7 @@ public class DigitalWidgetViewsFactory implements RemoteViewsFactory { public DigitalWidgetViewsFactory(Context context, Intent intent) { mContext = context; mResources = mContext.getResources(); mId = intent.getIntExtra( AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); mAdapter = new RemoteWorldClockAdapter(context); Loading src/com/android/alarmclock/WidgetUtils.java +18 −0 Original line number Diff line number Diff line Loading @@ -24,8 +24,11 @@ import android.os.Bundle; import android.util.Log; import android.util.TypedValue; import android.widget.RemoteViews; import android.widget.RemoteViews.RemoteView; import android.widget.TextClock; import com.android.deskclock.R; import com.android.deskclock.Utils; public class WidgetUtils { static final String TAG = "WidgetUtils"; Loading Loading @@ -128,5 +131,20 @@ public class WidgetUtils { scale * res.getDimension(R.dimen.digital_widget_list_min_scaled_height); return ((density * height) > neededSize); } /*** * Set the format of the time on the clock accrding to the locale * @param clock - view to format * @param amPmFontSize - size of am/pm label, zero size means no am/om label * @param clockId - id of TextClock view as defined in the clock's layout. */ public static void setTimeFormat(RemoteViews clock, int amPmFontSize, int clockId) { if (clock != null) { // Set the best format for 12 hours mode according to the locale clock.setCharSequence(clockId, "setFormat12Hour", Utils.get12ModeFormat(amPmFontSize)); // Set the best format for 24 hours mode according to the locale clock.setCharSequence(clockId, "setFormat24Hour", Utils.get24ModeFormat()); } } } src/com/android/deskclock/Utils.java +9 −6 Original line number Diff line number Diff line Loading @@ -493,14 +493,17 @@ public class Utils { public static void setTimeFormat(TextClock clock, int amPmFontSize) { if (clock != null) { // Get the best format for 12 hours mode according to the locale clock.setFormat12Hour(get12ModeFormet(amPmFontSize)); clock.setFormat12Hour(get12ModeFormat(amPmFontSize)); // Get the best format for 24 hours mode according to the locale clock.setFormat24Hour(get24ModeFormet()); clock.setFormat24Hour(get24ModeFormat()); } } public static CharSequence get12ModeFormet(int amPmFontSize) { String skeleton = "hma"; /*** * @param amPmFontSize - size of am/pm label (label removed is size is 0). * @return format string for 12 hours mode time */ public static CharSequence get12ModeFormat(int amPmFontSize) { String skeleton = (amPmFontSize > 0) ? "hma" : "hm"; String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton); // Replace spaces with "Hair Space" pattern = pattern.replaceAll(" ", "\u200A"); Loading @@ -519,7 +522,7 @@ public class Utils { return sp; } public static CharSequence get24ModeFormet() { public static CharSequence get24ModeFormat() { String skeleton = "Hm"; return DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton); } Loading src/com/android/deskclock/widget/TextTime.java +3 −3 Original line number Diff line number Diff line Loading @@ -139,8 +139,8 @@ public class TextTime extends TextView { } public void setFormat(int amPmFontSize) { setFormat12Hour(Utils.get12ModeFormet(amPmFontSize)); setFormat24Hour(Utils.get24ModeFormet()); setFormat12Hour(Utils.get12ModeFormat(amPmFontSize)); setFormat24Hour(Utils.get24ModeFormat()); } public void setTime(int hour, int minute) { Loading Loading
src/com/android/alarmclock/DigitalAppWidgetProvider.java +3 −1 Original line number Diff line number Diff line Loading @@ -94,6 +94,7 @@ public class DigitalAppWidgetProvider extends AppWidgetProvider { RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget); float ratio = WidgetUtils.getScaleRatio(context, null, appWidgetId); WidgetUtils.setTimeFormat(widget, 0/*no am/pm*/, R.id.the_clock); WidgetUtils.setClockSize(context, widget, ratio); refreshAlarm(context, widget); appWidgetManager.partiallyUpdateAppWidget(appWidgetId, widget); Loading Loading @@ -165,8 +166,9 @@ public class DigitalAppWidgetProvider extends AppWidgetProvider { PendingIntent.getActivity(context, 0, new Intent(context, DeskClock.class), 0)); } // Setup alarm text and font sizes // Setup alarm text clock's format and font sizes refreshAlarm(context, widget); WidgetUtils.setTimeFormat(widget, 0/*no am/pm*/, R.id.the_clock); WidgetUtils.setClockSize(context, widget, ratio); // Set today's date format Loading
src/com/android/alarmclock/DigitalWidgetViewsFactory.java +5 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.alarmclock; import android.appwidget.AppWidgetManager; import android.content.Context; import android.content.Intent; import android.content.res.Resources; import android.text.format.DateFormat; import android.util.Log; import android.util.TypedValue; Loading @@ -39,6 +40,7 @@ public class DigitalWidgetViewsFactory implements RemoteViewsFactory { private static final String TAG = "DigitalWidgetViewsFactory"; private Context mContext; private Resources mResources; private int mId = AppWidgetManager.INVALID_APPWIDGET_ID; private RemoteWorldClockAdapter mAdapter; private float mFontScale = 1; Loading Loading @@ -99,6 +101,8 @@ public class DigitalWidgetViewsFactory implements RemoteViewsFactory { now.setTimeZone(TimeZone.getTimeZone(cityTZ)); int cityDayOfWeek = now.get(Calendar.DAY_OF_WEEK); WidgetUtils.setTimeFormat(clock, (int)mResources.getDimension(R.dimen.widget_label_font_size), clockId); float fontSize = mFontScale * (DateFormat.is24HourFormat(mContext) ? mFont24Size : mFontSize); clock.setTextViewTextSize(clockId, TypedValue.COMPLEX_UNIT_PX, fontSize * mFontScale); Loading Loading @@ -130,6 +134,7 @@ public class DigitalWidgetViewsFactory implements RemoteViewsFactory { public DigitalWidgetViewsFactory(Context context, Intent intent) { mContext = context; mResources = mContext.getResources(); mId = intent.getIntExtra( AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); mAdapter = new RemoteWorldClockAdapter(context); Loading
src/com/android/alarmclock/WidgetUtils.java +18 −0 Original line number Diff line number Diff line Loading @@ -24,8 +24,11 @@ import android.os.Bundle; import android.util.Log; import android.util.TypedValue; import android.widget.RemoteViews; import android.widget.RemoteViews.RemoteView; import android.widget.TextClock; import com.android.deskclock.R; import com.android.deskclock.Utils; public class WidgetUtils { static final String TAG = "WidgetUtils"; Loading Loading @@ -128,5 +131,20 @@ public class WidgetUtils { scale * res.getDimension(R.dimen.digital_widget_list_min_scaled_height); return ((density * height) > neededSize); } /*** * Set the format of the time on the clock accrding to the locale * @param clock - view to format * @param amPmFontSize - size of am/pm label, zero size means no am/om label * @param clockId - id of TextClock view as defined in the clock's layout. */ public static void setTimeFormat(RemoteViews clock, int amPmFontSize, int clockId) { if (clock != null) { // Set the best format for 12 hours mode according to the locale clock.setCharSequence(clockId, "setFormat12Hour", Utils.get12ModeFormat(amPmFontSize)); // Set the best format for 24 hours mode according to the locale clock.setCharSequence(clockId, "setFormat24Hour", Utils.get24ModeFormat()); } } }
src/com/android/deskclock/Utils.java +9 −6 Original line number Diff line number Diff line Loading @@ -493,14 +493,17 @@ public class Utils { public static void setTimeFormat(TextClock clock, int amPmFontSize) { if (clock != null) { // Get the best format for 12 hours mode according to the locale clock.setFormat12Hour(get12ModeFormet(amPmFontSize)); clock.setFormat12Hour(get12ModeFormat(amPmFontSize)); // Get the best format for 24 hours mode according to the locale clock.setFormat24Hour(get24ModeFormet()); clock.setFormat24Hour(get24ModeFormat()); } } public static CharSequence get12ModeFormet(int amPmFontSize) { String skeleton = "hma"; /*** * @param amPmFontSize - size of am/pm label (label removed is size is 0). * @return format string for 12 hours mode time */ public static CharSequence get12ModeFormat(int amPmFontSize) { String skeleton = (amPmFontSize > 0) ? "hma" : "hm"; String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton); // Replace spaces with "Hair Space" pattern = pattern.replaceAll(" ", "\u200A"); Loading @@ -519,7 +522,7 @@ public class Utils { return sp; } public static CharSequence get24ModeFormet() { public static CharSequence get24ModeFormat() { String skeleton = "Hm"; return DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton); } Loading
src/com/android/deskclock/widget/TextTime.java +3 −3 Original line number Diff line number Diff line Loading @@ -139,8 +139,8 @@ public class TextTime extends TextView { } public void setFormat(int amPmFontSize) { setFormat12Hour(Utils.get12ModeFormet(amPmFontSize)); setFormat24Hour(Utils.get24ModeFormet()); setFormat12Hour(Utils.get12ModeFormat(amPmFontSize)); setFormat24Hour(Utils.get24ModeFormat()); } public void setTime(int hour, int minute) { Loading