Back to project page android-styled-dialogs.
The source code is released under:
Apache License
If you think the Android project android-styled-dialogs listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.avast.android.dialogs.fragment; /*from w w w . j a va2s. c o m*/ import java.util.Calendar; import java.util.Date; import java.util.TimeZone; import android.content.Context; import android.support.v4.app.FragmentManager; import android.view.LayoutInflater; import android.widget.TimePicker; import com.avast.android.dialogs.R; import com.avast.android.dialogs.core.BaseDialogFragment; /** * Dialog with a time picker. Implement {@link com.avast.android.dialogs.iface.IDateDialogListener} or {@link com.avast.android.dialogs.iface.IDateDialogCancelListener} to handle events. */ public class TimePickerDialogFragment extends DatePickerDialogFragment { TimePicker mTimePicker; Calendar mCalendar; public static SimpleDialogBuilder createBuilder(Context context, FragmentManager fragmentManager) { return new SimpleDialogBuilder(context, fragmentManager, TimePickerDialogFragment.class); } @Override protected BaseDialogFragment.Builder build(BaseDialogFragment.Builder builder) { builder = super.build(builder); mTimePicker = (TimePicker) LayoutInflater.from(getActivity()).inflate(R.layout.sdl_timepicker, null); mTimePicker.setIs24HourView(getArguments().getBoolean(ARG_24H)); builder.setView(mTimePicker); TimeZone zone = TimeZone.getTimeZone(getArguments().getString(ARG_ZONE)); mCalendar = Calendar.getInstance(zone); mCalendar.setTimeInMillis(getArguments().getLong(ARG_DATE, System.currentTimeMillis())); mTimePicker.setCurrentHour(mCalendar.get(Calendar.HOUR_OF_DAY)); mTimePicker.setCurrentMinute(mCalendar.get(Calendar.MINUTE)); return builder; } public Date getDate() { mCalendar.set(Calendar.HOUR_OF_DAY, mTimePicker.getCurrentHour()); mCalendar.set(Calendar.MINUTE, mTimePicker.getCurrentMinute()); return mCalendar.getTime(); } }