 |
3.0 인데 wifi 사용모델이구요 cdma는 안되구요
인터넷 시계설정말고요 수동으로 시계설정후 . 껏다 키면. 자기멋대로 바뀝니다.
쓰레기 값이 들어가는거 같은데. 어딜수정을 해야 할지 감이 안옵니다.
이것저것 주석 처리도 해봐도 . 같네요.. 소스 올릴테니 보시고 수정할곳이라도.. 힌트좀 주세요..
저장을 못하는건지 지워지는건지 . 아님 쓰레기 값이 덮어 쓰는건지.. 모가 문제인지 도 모르겟네요..
public void onCreate(Bundle icicle) { super.onCreate(icicle);
addPreferencesFromResource(R.xml.date_time_prefs);
initUI(); }
private boolean isApqModel() { if (TargetConfig.isApqTarget()) return true; return false; } private void initUI() { boolean autoTimeEnabled = getAutoState(Settings.System.AUTO_TIME); boolean autoTimeZoneEnabled = getAutoState(Settings.System.AUTO_TIME_ZONE);
Intent intent = getActivity().getIntent(); boolean isFirstRun = intent.getBooleanExtra(EXTRA_IS_FIRST_RUN, false);
if (isApqModel()) { if (isFirstRun) { autoTimeEnabled = true; Settings.System.putInt(getContentResolver(), Settings.System.AUTO_TIME, 1); } } mDummyDate = Calendar.getInstance(); mDummyDate.set(mDummyDate.get(Calendar.YEAR), 11, 31, 13, 0, 0);
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() || 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); // }
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 = ""; } 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); if (isApqModel()) { mTimeZone.setEnabled(true); } else mTimeZone.setEnabled(!autoTimeZoneEnabled); }
@Override public void onResume() { super.onResume();
getPreferenceScreen().getSharedPreferences() .registerOnSharedPreferenceChangeListener(this);
int activePhoneType = TelephonyManager.getDefault().getPhoneType(); // If phone type is CDMA disable the manual time mode & force // auto time mode if (TelephonyManager.PHONE_TYPE_CDMA == activePhoneType && !isTimeDaemonEnabled) { setAutoState(false, true); } ((CheckBoxPreference)mTime24Pref).setChecked(is24Hour());
// Register for time ticks and other reasons for time change IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_TIME_TICK); filter.addAction(Intent.ACTION_TIME_CHANGED); filter.addAction(Intent.ACTION_TIMEZONE_CHANGED); getActivity().registerReceiver(mIntentReceiver, filter, null, null);
updateTimeAndDateDisplay(getActivity()); }
@Override public void onPause() { super.onPause(); getActivity().unregisterReceiver(mIntentReceiver); getPreferenceScreen().getSharedPreferences() .unregisterOnSharedPreferenceChangeListener(this); }
public void updateTimeAndDateDisplay(Context context) { java.text.DateFormat shortDateFormat = DateFormat.getDateFormat(context); final Calendar now = Calendar.getInstance(); Date dummyDate = mDummyDate.getTime(); mTimePref.setSummary(DateFormat.getTimeFormat(getActivity()).format(now.getTime())); mTimeZone.setSummary(getTimeZoneText(now.getTimeZone())); mDatePref.setSummary(shortDateFormat.format(now.getTime())); mDateFormat.setSummary(shortDateFormat.format(dummyDate)); }
@Override public void onDateSet(DatePicker view, int year, int month, int day) { setDate(year, month, day); final Activity activity = getActivity(); if (activity != null) { updateTimeAndDateDisplay(activity); } }
@Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { setTime(hourOfDay, minute); final Activity activity = getActivity(); if (activity != null) { updateTimeAndDateDisplay(activity); }
// We don't need to call timeUpdated() here because the TIME_CHANGED // broadcast is sent by the AlarmManager as a side effect of setting the // SystemClock time. }
@Override public void onSharedPreferenceChanged(SharedPreferences preferences, String key) { if (key.equals(KEY_DATE_FORMAT)) { String format = preferences.getString(key, getResources().getString(R.string.default_date_format)); Settings.System.putString(getContentResolver(), Settings.System.DATE_FORMAT, format); updateTimeAndDateDisplay(getActivity()); } else if (key.equals(KEY_AUTO_TIME)) { boolean autoEnabled = preferences.getBoolean(key, true); setAutoState(true, autoEnabled); } else if (key.equals(KEY_AUTO_TIME_ZONE)) { boolean autoZoneEnabled = preferences.getBoolean(key, true); Settings.System.putInt( getContentResolver(), Settings.System.AUTO_TIME_ZONE, autoZoneEnabled ? 1 : 0); mTimeZone.setEnabled(!autoZoneEnabled); } }
@Override public Dialog onCreateDialog(int id) { Dialog d;
switch (id) { case DIALOG_DATEPICKER: { final Calendar calendar = Calendar.getInstance(); d = new DatePickerDialog( getActivity(), this, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)); break; } case DIALOG_TIMEPICKER: { final Calendar calendar = Calendar.getInstance(); d = new TimePickerDialog( getActivity(), this, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), DateFormat.is24HourFormat(getActivity())); break; } default: d = null; break; }
return d; }
/* @Override public void onPrepareDialog(int id, Dialog d) { switch (id) { case DIALOG_DATEPICKER: { DatePickerDialog datePicker = (DatePickerDialog)d; final Calendar calendar = Calendar.getInstance(); datePicker.updateDate( calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)); break; } case DIALOG_TIMEPICKER: { TimePickerDialog timePicker = (TimePickerDialog)d; final Calendar calendar = Calendar.getInstance(); timePicker.updateTime( calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE)); break; } default: break; } } */ @Override public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { if (preference == mDatePref) { showDialog(DIALOG_DATEPICKER); } else if (preference == mTimePref) { // The 24-hour mode may have changed, so recreate the dialog removeDialog(DIALOG_TIMEPICKER); showDialog(DIALOG_TIMEPICKER); } else if (preference == mTime24Pref) { set24Hour(((CheckBoxPreference)mTime24Pref).isChecked()); updateTimeAndDateDisplay(getActivity()); timeUpdated(); } return super.onPreferenceTreeClick(preferenceScreen, preference); }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { updateTimeAndDateDisplay(getActivity()); }
/* sets the auto_time preference to true if isEnabled flag is set true otherwise * sets the auto_time preference based on the user selection(autotimeStatus) * passed as argument. */ private void setAutoState(boolean isEnabled, boolean autotimeStatus) { if (isEnabled == false) { mAutoTimePref.setChecked(autotimeStatus); mAutoTimePref.setEnabled(isEnabled); } else { Settings.System.putInt(getContentResolver(), Settings.System.AUTO_TIME, autotimeStatus ? 1 : 0); } mTimePref.setEnabled(!autotimeStatus); mDatePref.setEnabled(!autotimeStatus); if (isApqModel()) { mTimeZone.setEnabled(true); } else mTimeZone.setEnabled(!autotimeStatus); }
private void timeUpdated() { Intent timeChanged = new Intent(Intent.ACTION_TIME_CHANGED); getActivity().sendBroadcast(timeChanged); }
/* Get & Set values from the system settings */
private boolean is24Hour() { return DateFormat.is24HourFormat(getActivity()); }
private void set24Hour(boolean is24Hour) { Settings.System.putString(getContentResolver(), Settings.System.TIME_12_24, is24Hour? HOURS_24 : HOURS_12); }
private String getDateFormat() { return Settings.System.getString(getContentResolver(), Settings.System.DATE_FORMAT); }
private boolean getAutoState(String name) { try { return Settings.System.getInt(getContentResolver(), name) > 0; } catch (SettingNotFoundException snfe) { return false; } }
/* Helper routines to format timezone */
/* package */ static void setDate(int year, int month, int day) { Calendar c = Calendar.getInstance();
c.set(Calendar.YEAR, year); c.set(Calendar.MONTH, month); c.set(Calendar.DAY_OF_MONTH, day); long when = c.getTimeInMillis();
if (when / 1000 < Integer.MAX_VALUE) { SystemClock.setCurrentTimeMillis(when); } }
/* package */ static void setTime(int hourOfDay, int minute) { Calendar c = Calendar.getInstance();
c.set(Calendar.HOUR_OF_DAY, hourOfDay); c.set(Calendar.MINUTE, minute); long when = c.getTimeInMillis();
if (when / 1000 < Integer.MAX_VALUE) { SystemClock.setCurrentTimeMillis(when); } }
/* package */ static String getTimeZoneText(TimeZone tz) { boolean daylight = tz.inDaylightTime(new Date()); StringBuilder sb = new StringBuilder();
sb.append(formatOffset(tz.getRawOffset() + (daylight ? tz.getDSTSavings() : 0))). append(", "). append(tz.getDisplayName(daylight, TimeZone.LONG));
return sb.toString(); }
private static char[] formatOffset(int off) { off = off / 1000 / 60;
char[] buf = new char[9]; buf[0] = 'G'; buf[1] = 'M'; buf[2] = 'T';
if (off < 0) { buf[3] = '-'; off = -off; } else { buf[3] = '+'; }
int hours = off / 60; int minutes = off % 60;
buf[4] = (char) ('0' + hours / 10); buf[5] = (char) ('0' + hours % 10);
buf[6] = ':';
buf[7] = (char) ('0' + minutes / 10); buf[8] = (char) ('0' + minutes % 10);
return buf; }
private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { final Activity activity = getActivity(); if (activity != null) { updateTimeAndDateDisplay(activity); } } }; } |
※ 회원등급 레벨 0 이상 읽기가 가능한 게시판입니다.
16
|