Code example for Time

Methods: format, set, setToNow, toMillis

0
     * Get the string of the alarm ring time 
     * @param napDuration 
     * @return 
     */ 
    private String formatAlarmTime(int napDuration) {
        Time t = new Time();
        t.setToNow();
        t.set(t.toMillis(false) +napDuration);
        return t.format("%H:%M");
    } 
 
    /** 
     * Save the configured nap duration in shared preferences 
     * @param appWidgetId The widget id 
     * @param napDuration The duration in minutes 
     */ 
    static void setNapDuration(Context context, int appWidgetId, int napDuration) {
        SharedPreferences.Editor prefs = context.getSharedPreferences(PREFS_NAME, 0).edit();
        prefs.putInt(PREF_DURATION_PREFIX + appWidgetId, napDuration);
        prefs.commit();
    }