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

Commit 164fba7c authored by Matt Garnes's avatar Matt Garnes
Browse files

Determine default 12/24 hour time format setting from locale.

We allow the user to override the 12/24 hour format based on their
preference. Previously, the default was set to 24 hour format for all
users out of the box. Instead, initialize the default value from the
user's locale. It can always be changed later.

Change-Id: I9e4c5e9f2ebcb50321dd9d9438efc9b1a5ce6cdc
parent 5bf7e675
Loading
Loading
Loading
Loading
+34 −22
Original line number Diff line number Diff line
@@ -183,6 +183,21 @@ public class DateFormat {
                Settings.System.TIME_12_24, userHandle);

        if (value == null) {
            return is24HourFormatLocale(context);
        }

        return value.equals("24");
    }

    /**
     * Returns true if the time should be formatted in 24 hour format, based on the device locale.
     * @param context The context to use to get Resources.
     * @return true if 24 hour time format should be used, false otherwise.
     *
     * @hide
     */
    public static boolean is24HourFormatLocale(Context context) {
        String value = null;
        Locale locale = context.getResources().getConfiguration().locale;

        synchronized (sLocaleLock) {
@@ -215,9 +230,6 @@ public class DateFormat {
        return sIs24Hour;
    }

        return value.equals("24");
    }

    /**
     * Returns the best possible localized form of the given skeleton for the given
     * locale. A skeleton is similar to, and uses the same format characters as, a Unicode
+0 −3
Original line number Diff line number Diff line
@@ -83,9 +83,6 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    <!-- Voice Call earpiece Volume,its value is from 0 to 5,default value is 4 -->
    <integer name="def_voice_call_earpiece_volume" translatable="false">4</integer>

    <!-- Time format,default vlaue is 24 : 24 format,other value is 12 format -->
    <string name="def_time_format" translatable="false">24</string>

    <!-- Date format,yyyy-MM-dd: 2013/07/30; MM-dd-yyyy:07/30/2013; dd-MM-yyyy:30/07/2013 -->
    <string name="def_date_format" translatable="false">MM-dd-yyyy</string>

+4 −2
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import android.provider.Settings.Global;
import android.provider.Settings.Secure;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.text.format.DateFormat;
import android.util.Log;

import com.android.internal.content.PackageHelper;
@@ -2603,8 +2604,9 @@ public class DatabaseHelper extends SQLiteOpenHelper {
            loadIntegerSetting(stmt, Settings.System.POINTER_SPEED,
                    R.integer.def_pointer_speed);

            loadStringSetting(stmt, Settings.System.TIME_12_24,
                    R.string.def_time_format);
            boolean is24Hour = DateFormat.is24HourFormatLocale(mContext);
            String defaultTimeFormat = is24Hour ? "24" : "12";
            loadSetting(stmt, Settings.System.TIME_12_24, defaultTimeFormat);

            loadStringSetting(stmt, Settings.System.DATE_FORMAT,
                    R.string.def_date_format);