Example usage for android.app TimePickerDialog setTitle

List of usage examples for android.app TimePickerDialog setTitle

Introduction

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

Prototype

@Override
    public void setTitle(CharSequence title) 

Source Link

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/*w  w w.java 2s  .c o  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();
}