public class PrefAutoRefreshStartTime extends DialogPreference implements TimePicker.OnTimeChangedListener {
/** * The validation expression for this preference */ private static final String VALIDATION_EXPRESSION = "[0-2]*[0-9]:[0-5]*[0-9]"; /** * The default value for this preference */ private String defaultValue; /** * @param context * @param attrs */ public PrefAutoRefreshStartTime(Context context, AttributeSet attrs) {super(context, attrs);initialize(context); } /** * @param context * @param attrs * @param defStyle */public PrefAutoRefreshStartTime(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle);initialize(context); } /** * Initialize this preference */private void initialize(Context context) {setPersistent(true);SharedPreferences sp = getPreferenceManager().getDefaultSharedPreferences(getContext());String timeTemp = sp.getString(IConfigsParameters.KEY_P_AUTOFRESH_START, "");if(null != timeTemp){setSummary(packageTimeInfo(timeTemp)); }else{setSummary(packageTimeInfo(context.getText(R.string.time_default_auto_update_start).toString())); } } /* * (non-Javadoc) * * @see android.preference.DialogPreference#onCreateDialogView() */@Override protected View onCreateDialogView() {TimePicker tp = new TimePicker(getContext());tp.setOnTimeChangedListener(this); /** */SharedPreferences sp = getPreferenceManager().getDefaultSharedPreferences(getContext());String timeTemp = sp.getString("p_autofresh_strart", "");String time = timeTemp.split(":");if((time != null) && (time.length == 2)){Integer hour = Integer.decode(time[0]);Integer min = Integer.decode(time);tp.setCurrentHour(hour);tp.setCurrentMinute(min); }else{ /** */int h = getHour();int m = getMinute();if (h >= 0 && m >= 0) {tp.setCurrentHour(h);tp.setCurrentMinute(m); } } return tp; } /* * (non-Javadoc) * * @see * android.widget.TimePicker.OnTimeChangedListener#onTimeChanged(android * .widget.TimePicker, int, int) */@Override public void onTimeChanged(TimePicker view, int hour, int minute) {setSummary(packageTimeInfo((""+hour+":"+minute)));persistString(hour + ":" + minute); } /* * (non-Javadoc) * * @see android.preference.Preference#setDefaultValue(java.lang.Object) */@Override public void setDefaultValue(Object defaultValue) {// BUG this method is never called if you use the ''android:defaultValue'' // attribute in your XML preference file, not sure why it isn''t super.setDefaultValue(defaultValue);if (!(defaultValue instanceof String)) {return; } if (!((String) defaultValue).matches(VALIDATION_EXPRESSION)) {return; } this.defaultValue = (String) defaultValue; } /** * Get the hour value (in 24 hour time) * * @return The hour value, will be 0 to 23 (inclusive) */private int get