android设置默认日期,android 4.4 设置默认日期格式
private void initUI() {boolean autoTimeEnabled = getAutoState(Settings.Global.AUTO_TIME);boolean autoTimeZoneEnabled = getAutoState(Settings.Global.AUTO_TIME_ZONE);Intent intent = getActivity().getInt
private void initUI() {
boolean autoTimeEnabled = getAutoState(Settings.Global.AUTO_TIME);
boolean autoTimeZoneEnabled = getAutoState(Settings.Global.AUTO_TIME_ZONE);
Intent intent = getActivity().getIntent();
boolean isFirstRun = intent.getBooleanExtra(EXTRA_IS_FIRST_RUN, false);
mDummyDate = Calendar.getInstance();
mAutoTimePref = (CheckBoxPreference) findPreference(KEY_AUTO_TIME);
mAutoTimePref.setChecked(autoTimeEnabled);
mAutoTimeZonePref = (CheckBoxPreference) findPreference(KEY_AUTO_TIME_ZONE);
// Override auto-timezone if it's a wifi-only device or if we're still in setup wizard.
// TODO: Remove the wifiOnly test when auto-timezone is implemented based on wifi-location.
if (Utils.isWifiOnly(getActivity()) || isFirstRun) {
getPreferenceScreen().removePreference(mAutoTimeZonePref);
autoTimeZoneEnabled = false;
}
mAutoTimeZonePref.setChecked(autoTimeZoneEnabled);
mTimePref = findPreference("time");
mTime24Pref = findPreference("24 hour");
mTimeZone = findPreference("timezone");
mDatePref = findPreference("date");
mDateFormat = (ListPreference) findPreference(KEY_DATE_FORMAT);
if (isFirstRun) {
getPreferenceScreen().removePreference(mTime24Pref);
getPreferenceScreen().removePreference(mDateFormat);
}
//{{Await add
String format = getResources().getString(R.string.default_date_format);
Settings.System.putString(getContentResolver(),
Settings.System.DATE_FORMAT, format);
//}}
String [] dateFormats = getResources().getStringArray(R.array.date_format_values);
String [] formattedDates = new String[dateFormats.length];
String currentFormat = getDateFormat();
// Initialize if DATE_FORMAT is not set in the system settings
// This can happen after a factory reset (or data wipe)
if (currentFormat == null) {
currentFormat = "";
}
// Prevents duplicated values on date format selector.
mDummyDate.set(mDummyDate.get(Calendar.YEAR), mDummyDate.DECEMBER, 31, 13, 0, 0);
for (int i = 0; i < formattedDates.length; i++) {
String formatted =
DateFormat.getDateFormatForSetting(getActivity(), dateFormats[i])
.format(mDummyDate.getTime());
if (dateFormats[i].length() == 0) {
formattedDates[i] = getResources().
getString(R.string.normal_date_format, formatted);
} else {
formattedDates[i] = formatted;
}
}
mDateFormat.setEntries(formattedDates);
mDateFormat.setEntryValues(R.array.date_format_values);
mDateFormat.setValue(currentFormat);
mTimePref.setEnabled(!autoTimeEnabled);
mDatePref.setEnabled(!autoTimeEnabled);
mTimeZone.setEnabled(!autoTimeZoneEnabled);
}
更多推荐
所有评论(0)