Android Open Source - android-styled-dialogs Time Picker Dialog Fragment






From Project

Back to project page android-styled-dialogs.

License

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.

Java Source Code

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();
    }
}




Java Source Code List

com.avast.android.dialogs.core.BaseDialogBuilder.java
com.avast.android.dialogs.core.BaseDialogFragment.java
com.avast.android.dialogs.fragment.DatePickerDialogFragment.java
com.avast.android.dialogs.fragment.ListDialogFragment.java
com.avast.android.dialogs.fragment.ProgressDialogFragment.java
com.avast.android.dialogs.fragment.SimpleDialogFragment.java
com.avast.android.dialogs.fragment.TimePickerDialogFragment.java
com.avast.android.dialogs.iface.IDateDialogCancelListener.java
com.avast.android.dialogs.iface.IDateDialogListener.java
com.avast.android.dialogs.iface.IListDialogListener.java
com.avast.android.dialogs.iface.ISimpleDialogCancelListener.java
com.avast.android.dialogs.iface.ISimpleDialogListener.java
com.avast.android.dialogs.util.TypefaceHelper.java
com.avast.dialogs.DemoActivity.java
com.avast.dialogs.JayneHatDialogFragment.java