Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cad0b1d4 authored by Elliott Hughes's avatar Elliott Hughes
Browse files

Correctly localize the "next alarm" formatting.

Also fix the time formatting in the world clock list of cities.

Bug: https://code.google.com/p/android/issues/detail?id=59297
Change-Id: I2febfc7c62caa15e21259df4d6fb21f5292f190a
parent 13872972
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -28,18 +28,18 @@ import com.android.deskclock.provider.Alarm;
import com.android.deskclock.provider.AlarmInstance;

import java.util.Calendar;
import java.util.Locale;

/**
 * Static utility methods for Alarms.
 */
public class AlarmUtils {
    public static final String FRAG_TAG_TIME_PICKER = "time_dialog";
    private final static String DM12 = "E h:mm aa";
    private final static String DM24 = "E kk:mm";

    public static String getFormattedTime(Context context, Calendar time) {
        String format = DateFormat.is24HourFormat(context) ? DM24 : DM12;
        return (String) DateFormat.format(format, time);
        String skeleton = DateFormat.is24HourFormat(context) ? "EHm" : "Ehma";
        String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton);
        return (String) DateFormat.format(pattern, time);
    }

    public static String getAlarmText(Context context, AlarmInstance instance) {
+16 −16
Original line number Diff line number Diff line
@@ -106,12 +106,6 @@ public class CitiesActivity extends Activity implements OnCheckedChangeListener,
        private static final int VIEW_TYPE_CITY = 0;
        private static final int VIEW_TYPE_HEADER = 1;

        private static final String FORMAT_24_HOUR = "k:mm";
        private static final String FORMAT_12_HOUR = "h:mm aa";

        private static final String FORMAT_24_HOUR_RTL = "kk:mm";
        private static final String FORMAT_12_HOUR_RTL = "hh:mm aa";

        private static final String DELETED_ENTRY = "C0";

        private List<CityObj> mDisplayedCitiesList;
@@ -119,7 +113,7 @@ public class CitiesActivity extends Activity implements OnCheckedChangeListener,
        private CityObj[] mCities;
        private CityObj[] mSelectedCities;

        private int mLayoutDirection;
        private final int mLayoutDirection;

        // A map that caches names of cities in local memory.  The names in this map are
        // preferred over the names of the selected cities stored in SharedPreferences, which could
@@ -136,6 +130,9 @@ public class CitiesActivity extends Activity implements OnCheckedChangeListener,
        private final LayoutInflater mInflater;
        private boolean mIs24HoursMode; // AM/PM or 24 hours mode

        private final String mPattern12;
        private final String mPattern24;

        private int mSelectedEndPosition = 0;

        private Filter mFilter = new Filter() {
@@ -263,6 +260,17 @@ public class CitiesActivity extends Activity implements OnCheckedChangeListener,
                }
            }

            mPattern24 = DateFormat.getBestDateTimePattern(Locale.getDefault(), "Hm");

            // There's an RTL layout bug that causes jank when fast-scrolling through
            // the list in 12-hour mode in an RTL locale. We can work around this by
            // ensuring the strings are the same length by using "hh" instead of "h".
            String pattern12 = DateFormat.getBestDateTimePattern(Locale.getDefault(), "hma");
            if (mLayoutDirection == View.LAYOUT_DIRECTION_RTL) {
                pattern12 = pattern12.replaceAll("h", "hh");
            }
            mPattern12 = pattern12;

            sortCities(mSortType);
            set24HoursMode(context);
        }
@@ -378,17 +386,9 @@ public class CitiesActivity extends Activity implements OnCheckedChangeListener,
            return view;
        }

        // We need to ensure that hours are adjusted to be two digits in RTL due to issue involving
        // layout weights and text views with different lengths in a list view.
        private CharSequence getTimeCharSequence(String timeZone) {
            mCalendar.setTimeZone(TimeZone.getTimeZone(timeZone));
            String format;
            if (mLayoutDirection == View.LAYOUT_DIRECTION_RTL) {
                format = mIs24HoursMode ? FORMAT_24_HOUR_RTL : FORMAT_12_HOUR_RTL;
            } else {
                format = mIs24HoursMode ? FORMAT_24_HOUR : FORMAT_12_HOUR;
            }
            return DateFormat.format(format, mCalendar);
            return DateFormat.format(mIs24HoursMode ? mPattern24 : mPattern12, mCalendar);
        }

        @Override