Skip to content
Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
66 lines (57 sloc) 2.13 KB
package net.cmikavac.autowol.partials;
import android.app.Activity;
import android.app.Dialog;
import android.app.DialogFragment;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.widget.TimePicker;
/**
* This class is used so values from TimePickerFragment could be
* returned back to the activity from which it was called.
*/
public class TimePickerFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener {
OnTimePickedListener mCallback;
Integer mLayoutId = null;
/**
* An interface containing onTimePicked() method signature.
* Container Activity must implement this interface.
*/
public interface OnTimePickedListener {
public void onTimePicked(int textId, int hour, int minute);
}
/* (non-Javadoc)
* @see android.app.DialogFragment#onAttach(android.app.Activity)
*/
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
mCallback = (OnTimePickedListener)activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString() + " must implement OnTimePickedListener.");
}
}
/* (non-Javadoc)
* @see android.app.DialogFragment#onCreateDialog(android.os.Bundle)
*/
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
mCallback = (OnTimePickedListener)getActivity();
Bundle bundle = this.getArguments();
mLayoutId = bundle.getInt("layoutId");
int hour = bundle.getInt("hour");
int minute = bundle.getInt("minute");
// Create a new instance of TimePickerDialog and return it
return new TimePickerDialog(getActivity(), this, hour, minute, DateFormat.is24HourFormat(getActivity()));
}
/* (non-Javadoc)
* @see android.app.TimePickerDialog.OnTimeSetListener#onTimeSet(android.widget.TimePicker, int, int)
*/
public void onTimeSet(TimePicker view, int hour, int minute) {
if(mCallback != null)
{
mCallback.onTimePicked(mLayoutId, hour, minute);
}
}
}
You can’t perform that action at this time.