Code example for GregorianCalendar

Methods: getTimeInMillis, set, setTimeInMillis

0
        super.onDialogClosed(positiveResult);
        Log.v(TAG,"onDialogClosed()");
 
        if (positiveResult) {
        	Log.v(TAG,"onDialogClosed() + Result:" + positiveResult != null ? "positiv":"negative");
            calendar.setTimeInMillis(System.currentTimeMillis());
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MINUTE,0);
            calendar.set(Calendar.MILLISECOND, 0);
            calendar.set(Calendar.HOUR_OF_DAY, picker.getCurrentHour());
            calendar.set(Calendar.MINUTE, picker.getCurrentMinute());
             
            Log.v(TAG, "Setting Calendar "+ picker.getCurrentHour() + " : " + picker.getCurrentMinute());
            Log.v(TAG, "Setting Calendar to " + new SimpleDateFormat("yyy-MM-dd HH:mm").format(new Date(calendar.getTimeInMillis())));
 
            setSummary(getSummary());
            if (callChangeListener(calendar.getTimeInMillis())) {
            	Log.v(TAG, "persitLong() " + calendar.getTimeInMillis());
                persistLong(calendar.getTimeInMillis());
                notifyChanged(); 
            } 
        } 
    } 
 
    @Override 
    protected Object onGetDefaultValue(TypedArray a, int index) {
    	Log.v(TAG, "onGetDefaultValue :  " + a.getString(index));
        return (a.getString(index));
    } 
 
    @Override 
    protected void onSetInitialValue(boolean restoreValue, Object defaultValue) {
    	Log.v(TAG,"onSetInitialValue()");
    	Log.v(TAG, "restoreValue "+ Boolean.toString(restoreValue));
    	Log.v(TAG, "defaultValue " + defaultValue!=null ? "Not Null":"null");
        if (restoreValue) {
            if (defaultValue == null) {
                calendar.setTimeInMillis(getPersistedLong(System.currentTimeMillis()));
            } else { 
                calendar.setTimeInMillis(getPersistedLong((Long) defaultValue));
            } 
        } else { 
            if (defaultValue == null) {
                calendar.setTimeInMillis(System.currentTimeMillis());
            } else { 
                calendar.setTimeInMillis(Long.parseLong((String)defaultValue));
            } 
        } 
        setSummary(getSummary());
    } 
 
    @Override 
    public CharSequence getSummary() {
        if (calendar == null) {
            return null; 
        } 
        return DateFormat.getTimeFormat(getContext()).format(new Date(calendar.getTimeInMillis()));
    } 
}