Example usage for android.app TimePickerDialog updateTime

List of usage examples for android.app TimePickerDialog updateTime

Introduction

In this page you can find the example usage for android.app TimePickerDialog updateTime.

Prototype

public void updateTime(int hourOfDay, int minuteOfHour) 

Source Link

Document

Sets the current time.

Usage

From source file:github.popeen.dsub.fragments.NowPlayingFragment.java

protected void startCustomTimerDialog() {
    // Retrieve previous custom time
    final SharedPreferences prefs = Util.getPreferences(context);
    String lengthString = prefs.getString(Constants.PREFERENCES_KEY_SLEEP_TIMER_DURATION, "5");
    int length = Integer.parseInt(lengthString);

    // Create TimePicker dialog
    TimePickerDialog timePicker = new TimePickerDialog(context, new TimePickerDialog.OnTimeSetListener() {
        @Override//from  w  ww .j  a v  a2 s .  co  m
        public void onTimeSet(TimePicker timePicker, int i, int i1) {
            // Parse length from dialog
            int length = (timePicker.getCurrentHour() * 60) + timePicker.getCurrentMinute();

            // Store custom length preference
            SharedPreferences.Editor editor = prefs.edit();
            editor.putString(Constants.PREFERENCES_KEY_SLEEP_TIMER_DURATION, Integer.toString(length));
            editor.commit();

            // Start timer
            // length is in milliseconds so multiply (minutes * 60 seconds * 1000 milliseconds)
            startTimer(length * 60000);
        }
    }, 0, 5, true);

    timePicker.setTitle(R.string.menu_set_timer);
    timePicker.updateTime((length / 60), (length % 60));
    timePicker.show();
}