FileDocCategorySizeDatePackage
TimePickerDialog.javaAPI DocAndroid 1.5 API5836Wed May 06 22:41:54 BST 2009android.app

TimePickerDialog

public class TimePickerDialog extends AlertDialog implements android.widget.TimePicker.OnTimeChangedListener, android.content.DialogInterface.OnClickListener
A dialog that prompts the user for the time of day using a {@link TimePicker}.

Fields Summary
private static final String
HOUR
private static final String
MINUTE
private static final String
IS_24_HOUR
private final android.widget.TimePicker
mTimePicker
private final OnTimeSetListener
mCallback
private final Calendar
mCalendar
private final DateFormat
mDateFormat
int
mInitialHourOfDay
int
mInitialMinute
boolean
mIs24HourView
Constructors Summary
public TimePickerDialog(android.content.Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView)

param
context Parent.
param
callBack How parent is notified.
param
hourOfDay The initial hour.
param
minute The initial minute.
param
is24HourView Whether this is a 24 hour view, or AM/PM.


                                       
      
             
                  
        this(context, com.android.internal.R.style.Theme_Dialog_Alert,
                callBack, hourOfDay, minute, is24HourView);
    
public TimePickerDialog(android.content.Context context, int theme, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView)

param
context Parent.
param
theme the theme to apply to this dialog
param
callBack How parent is notified.
param
hourOfDay The initial hour.
param
minute The initial minute.
param
is24HourView Whether this is a 24 hour view, or AM/PM.

        super(context, theme);
        mCallback = callBack;
        mInitialHourOfDay = hourOfDay;
        mInitialMinute = minute;
        mIs24HourView = is24HourView;

        mDateFormat = DateFormat.getTimeFormat(context);
        mCalendar = Calendar.getInstance();
        updateTitle(mInitialHourOfDay, mInitialMinute);
        
        setButton(context.getText(R.string.date_time_set), this);
        setButton2(context.getText(R.string.cancel), (OnClickListener) null);
        setIcon(R.drawable.ic_dialog_time);
        
        LayoutInflater inflater = 
                (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.time_picker_dialog, null);
        setView(view);
        mTimePicker = (TimePicker) view.findViewById(R.id.timePicker);

        // initialize state
        mTimePicker.setCurrentHour(mInitialHourOfDay);
        mTimePicker.setCurrentMinute(mInitialMinute);
        mTimePicker.setIs24HourView(mIs24HourView);
        mTimePicker.setOnTimeChangedListener(this);
    
Methods Summary
public voidonClick(android.content.DialogInterface dialog, int which)

        if (mCallback != null) {
            mTimePicker.clearFocus();
            mCallback.onTimeSet(mTimePicker, mTimePicker.getCurrentHour(), 
                    mTimePicker.getCurrentMinute());
        }
    
public voidonRestoreInstanceState(android.os.Bundle savedInstanceState)

        super.onRestoreInstanceState(savedInstanceState);
        int hour = savedInstanceState.getInt(HOUR);
        int minute = savedInstanceState.getInt(MINUTE);
        mTimePicker.setCurrentHour(hour);
        mTimePicker.setCurrentMinute(minute);
        mTimePicker.setIs24HourView(savedInstanceState.getBoolean(IS_24_HOUR));
        mTimePicker.setOnTimeChangedListener(this);
        updateTitle(hour, minute);
    
public android.os.BundleonSaveInstanceState()

        Bundle state = super.onSaveInstanceState();
        state.putInt(HOUR, mTimePicker.getCurrentHour());
        state.putInt(MINUTE, mTimePicker.getCurrentMinute());
        state.putBoolean(IS_24_HOUR, mTimePicker.is24HourView());
        return state;
    
public voidonTimeChanged(android.widget.TimePicker view, int hourOfDay, int minute)

        updateTitle(hourOfDay, minute);
    
public voidupdateTime(int hourOfDay, int minutOfHour)

        mTimePicker.setCurrentHour(hourOfDay);
        mTimePicker.setCurrentMinute(minutOfHour);
    
private voidupdateTitle(int hour, int minute)

        mCalendar.set(Calendar.HOUR_OF_DAY, hour);
        mCalendar.set(Calendar.MINUTE, minute);
        setTitle(mDateFormat.format(mCalendar.getTime()));