Java Code Examples for android.widget.TimePicker#setCurrentHour()

The following examples show how to use android.widget.TimePicker#setCurrentHour() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimePickerPreference.java    From ploggy with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected View onCreateDialogView() {

        tp = new TimePicker(getContext());
        tp.setOnTimeChangedListener(this);

        String value = getPersistedString(this.defaultValue);
        int h = getHour(value);
        int m = getMinute(value);
        if (h >= 0 && m >= 0) {
                tp.setCurrentHour(h);
                tp.setCurrentMinute(m);
        }
        tp.setIs24HourView(DateFormat.is24HourFormat(getContext()));

        return tp;
}
 
Example 2
Source File: PickerActions.java    From android-test with Apache License 2.0 6 votes vote down vote up
/** Returns a {@link ViewAction} that sets a time on a {@link TimePicker}. */
public static ViewAction setTime(final int hours, final int minutes) {

  return new ViewAction() {

    @Override
    public void perform(UiController uiController, View view) {
      final TimePicker timePicker = (TimePicker) view;
      timePicker.setCurrentHour(hours);
      timePicker.setCurrentMinute(minutes);
    }

    @Override
    public String getDescription() {
      return "set time";
    }

    @SuppressWarnings("unchecked")
    @Override
    public Matcher<View> getConstraints() {
      return allOf(isAssignableFrom(TimePicker.class), isDisplayed());
    }
  };
}
 
Example 3
Source File: CalendarTool.java    From zidoorecorder with Apache License 2.0 6 votes vote down vote up
public void init(DatePicker datePicker, TimePicker timePicker) {
	Calendar calendar = Calendar.getInstance();
	// if (!(null == initDateTime || "".equals(initDateTime))) {
	// calendar = this.getCalendarByInintData(initDateTime);
	// } else {
	initDateTime = calendar.get(Calendar.YEAR) + "年"
			+ calendar.get(Calendar.MONTH) + "月"
			+ calendar.get(Calendar.DAY_OF_MONTH) + "日 "
			+ calendar.get(Calendar.HOUR_OF_DAY) + ":"
			+ calendar.get(Calendar.MINUTE);
	// }

	datePicker.init(calendar.get(Calendar.YEAR),
			calendar.get(Calendar.MONTH),
			calendar.get(Calendar.DAY_OF_MONTH), this);
	timePicker.setCurrentHour(calendar.get(Calendar.HOUR_OF_DAY));
	timePicker.setCurrentMinute(calendar.get(Calendar.MINUTE));

}
 
Example 4
Source File: DateTimePickDialogUtil.java    From VideoMeeting with Apache License 2.0 6 votes vote down vote up
public void init(DatePicker datePicker, TimePicker timePicker) {
    Calendar calendar = Calendar.getInstance();
    if (!(null == initDateTime || "".equals(initDateTime))) {
        calendar = this.getCalendarByInintData(initDateTime);
    } else {
        initDateTime = calendar.get(Calendar.YEAR) + "年"
                + calendar.get(Calendar.MONTH) + "月"
                + calendar.get(Calendar.DAY_OF_MONTH) + "日 "
                + calendar.get(Calendar.HOUR_OF_DAY) + ":"
                + calendar.get(Calendar.MINUTE);
    }

    datePicker.init(calendar.get(Calendar.YEAR),
            calendar.get(Calendar.MONTH),
            calendar.get(Calendar.DAY_OF_MONTH), this);
    timePicker.setCurrentHour(calendar.get(Calendar.HOUR_OF_DAY));
    timePicker.setCurrentMinute(calendar.get(Calendar.MINUTE));
}
 
Example 5
Source File: TimeMeasurementView.java    From openScale with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected View getInputView() {
    TimePicker timePicker = new TimePicker(getContext());
    timePicker.setPadding(0, 15, 0, 0);

    Calendar cal = Calendar.getInstance();
    cal.setTime(time);

    timePicker.setCurrentHour(cal.get(Calendar.HOUR_OF_DAY));
    timePicker.setCurrentMinute(cal.get(Calendar.MINUTE));
    timePicker.setIs24HourView(android.text.format.DateFormat.is24HourFormat(getContext()));

    return timePicker;
}
 
Example 6
Source File: DateTimePickerDialog.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * @param context The context the dialog is to run in.
 * @param callBack How the parent is notified that the date is set.
 * @param year The initial year of the dialog.
 * @param monthOfYear The initial month of the dialog.
 * @param dayOfMonth The initial day of the dialog.
 */
public DateTimePickerDialog(Context context,
        OnDateTimeSetListener callBack,
        int year,
        int monthOfYear,
        int dayOfMonth,
        int hourOfDay, int minute, boolean is24HourView,
        long min, long max) {
    super(context, 0);

    mMinTimeMillis = min;
    mMaxTimeMillis = max;

    mCallBack = callBack;

    setButton(BUTTON_POSITIVE, context.getText(
            R.string.date_picker_dialog_set), this);
    setButton(BUTTON_NEGATIVE, context.getText(android.R.string.cancel),
            (OnClickListener) null);
    setIcon(0);
    setTitle(context.getText(R.string.date_time_picker_dialog_title));

    LayoutInflater inflater =
            (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.date_time_picker_dialog, null);
    setView(view);
    mDatePicker = (DatePicker) view.findViewById(R.id.date_picker);
    DateDialogNormalizer.normalize(mDatePicker, this,
            year, monthOfYear, dayOfMonth, hourOfDay, minute, min, max);

    mTimePicker = (TimePicker) view.findViewById(R.id.time_picker);
    mTimePicker.setIs24HourView(is24HourView);
    mTimePicker.setCurrentHour(hourOfDay);
    mTimePicker.setCurrentMinute(minute);
    mTimePicker.setOnTimeChangedListener(this);
    onTimeChanged(mTimePicker, mTimePicker.getCurrentHour(),
            mTimePicker.getCurrentMinute());
}
 
Example 7
Source File: ClockPreference.java    From heads-up with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected View onCreateDialogView() {
    int defaultValue = getKey().equals("night_mode_start") ? 1320 : 420;
    int value = getPersistedInt(defaultValue);

    mTimePicker = new TimePicker(getContext());

    mTimePicker.setCurrentHour((int) Math.floor(value / 60));
    mTimePicker.setCurrentMinute((int) Math.floor(value % 60));
    mTimePicker.setIs24HourView(DateFormat.is24HourFormat(getContext().getApplicationContext()));

    return mTimePicker;
}
 
Example 8
Source File: TimePreference.java    From privacy-friendly-interval-timer with GNU General Public License v3.0 5 votes vote down vote up
protected void setHour(TimePicker timePicker, int hour) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        timePicker.setHour(hour);
    } else {
        timePicker.setCurrentHour(hour);
    }
}
 
Example 9
Source File: TimePickerDialogFragment.java    From android-styled-dialogs with Apache License 2.0 5 votes vote down vote up
@Override
protected BaseDialogFragment.Builder build(BaseDialogFragment.Builder builder) {
    builder = super.build(builder);
    mTimePicker = (TimePicker) builder.getLayoutInflater().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;
}
 
Example 10
Source File: TimeEventSkillViewFragment.java    From Easer with GNU General Public License v3.0 5 votes vote down vote up
private static void setTimePicker(TimePicker timePicker, Calendar calendar) {
    int hour, minute;
    hour = calendar.get(Calendar.HOUR_OF_DAY);
    minute = calendar.get(Calendar.MINUTE);
    if (Build.VERSION.SDK_INT >= 23) {
        timePicker.setHour(hour);
        timePicker.setMinute(minute);
    } else {
        timePicker.setCurrentHour(hour);
        timePicker.setCurrentMinute(minute);
    }
}
 
Example 11
Source File: SimpleTimeDialog.java    From SimpleDialogFragments with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
protected View onCreateContentView(Bundle savedInstanceState) {

    picker = new TimePicker(getContext());

    if (savedInstanceState != null){
        picker.setCurrentHour(savedInstanceState.getInt(HOUR));
        picker.setCurrentMinute(savedInstanceState.getInt(MINUTE));

    } else {
        if (getArguments().containsKey(HOUR)) {
            picker.setCurrentHour(getArguments().getInt(HOUR));
        }
        if (getArguments().containsKey(MINUTE)) {
            picker.setCurrentMinute(getArguments().getInt(MINUTE));
        }
    }

    if (getArguments().containsKey(VIEW_24_HOUR)) {
        picker.setIs24HourView(getArguments().getBoolean(VIEW_24_HOUR));
    } else {
        picker.setIs24HourView(DateFormat.is24HourFormat(getContext())); // system default
    }
    picker.setOnTimeChangedListener(this);

    return picker;
}
 
Example 12
Source File: GeckoViewPrompt.java    From focus-android with Mozilla Public License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
private static void setTimePickerTime(final TimePicker picker, final Calendar cal) {
    if (Build.VERSION.SDK_INT >= 23) {
        picker.setHour(cal.get(Calendar.HOUR_OF_DAY));
        picker.setMinute(cal.get(Calendar.MINUTE));
    } else {
        picker.setCurrentHour(cal.get(Calendar.HOUR_OF_DAY));
        picker.setCurrentMinute(cal.get(Calendar.MINUTE));
    }
}
 
Example 13
Source File: TimePreference.java    From privacy-friendly-pedometer with GNU General Public License v3.0 5 votes vote down vote up
protected void setHour(TimePicker timePicker, int hour) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        timePicker.setHour(hour);
    } else {
        timePicker.setCurrentHour(hour);
    }
}
 
Example 14
Source File: TimePreference.java    From android with MIT License 5 votes vote down vote up
@Override
protected void onBindDialogView(View view) {
    super.onBindDialogView(view);
    mTimePicker = (TimePicker) view.findViewById(R.id.time_picker);
    mTimePicker.setIs24HourView(mIs24HourView);
    mTimePicker.setCurrentHour(mHour);
    mTimePicker.setCurrentMinute(mMinute);
}
 
Example 15
Source File: SimpleTimeDialog.java    From SimpleDialogFragments with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
protected View onCreateContentView(Bundle savedInstanceState) {

    picker = new TimePicker(getContext());

    if (savedInstanceState != null){
        picker.setCurrentHour(savedInstanceState.getInt(HOUR));
        picker.setCurrentMinute(savedInstanceState.getInt(MINUTE));

    } else {
        if (getArguments().containsKey(HOUR)) {
            picker.setCurrentHour(getArguments().getInt(HOUR));
        }
        if (getArguments().containsKey(MINUTE)) {
            picker.setCurrentMinute(getArguments().getInt(MINUTE));
        }
    }

    if (getArguments().containsKey(VIEW_24_HOUR)) {
        picker.setIs24HourView(getArguments().getBoolean(VIEW_24_HOUR));
    } else {
        picker.setIs24HourView(DateFormat.is24HourFormat(getContext())); // system default
    }
    picker.setOnTimeChangedListener(this);

    return picker;
}
 
Example 16
Source File: DateFilterActivity.java    From financisto with GNU General Public License v2.0 5 votes vote down vote up
private void prepareDialog(Dialog dialog, Calendar c) {
	DatePicker dp = dialog.findViewById(R.id.date);
	dp.init(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), null);
	TimePicker tp = dialog.findViewById(R.id.time);
       tp.setIs24HourView(is24HourFormat(this));
       tp.setCurrentHour(c.get(Calendar.HOUR_OF_DAY));
	tp.setCurrentMinute(c.get(Calendar.MINUTE));
}
 
Example 17
Source File: DateTimePickerDialog.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * @param context The context the dialog is to run in.
 * @param callBack How the parent is notified that the date is set.
 * @param year The initial year of the dialog.
 * @param monthOfYear The initial month of the dialog.
 * @param dayOfMonth The initial day of the dialog.
 */
public DateTimePickerDialog(Context context,
        OnDateTimeSetListener callBack,
        int year,
        int monthOfYear,
        int dayOfMonth,
        int hourOfDay, int minute, boolean is24HourView,
        long min, long max) {
    super(context, 0);

    mMinTimeMillis = min;
    mMaxTimeMillis = max;

    mCallBack = callBack;

    setButton(BUTTON_POSITIVE, context.getText(
            R.string.date_picker_dialog_set), this);
    setButton(BUTTON_NEGATIVE, context.getText(android.R.string.cancel),
            (OnClickListener) null);
    setIcon(0);
    setTitle(context.getText(R.string.date_time_picker_dialog_title));

    LayoutInflater inflater =
            (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.date_time_picker_dialog, null);
    setView(view);
    mDatePicker = (DatePicker) view.findViewById(R.id.date_picker);
    DateDialogNormalizer.normalize(mDatePicker, this,
            year, monthOfYear, dayOfMonth, hourOfDay, minute, min, max);

    mTimePicker = (TimePicker) view.findViewById(R.id.time_picker);
    mTimePicker.setIs24HourView(is24HourView);
    mTimePicker.setCurrentHour(hourOfDay);
    mTimePicker.setCurrentMinute(minute);
    mTimePicker.setOnTimeChangedListener(this);
    onTimeChanged(mTimePicker, mTimePicker.getCurrentHour(),
            mTimePicker.getCurrentMinute());
}
 
Example 18
Source File: TimeFragment.java    From SlideDateTimePicker with Apache License 2.0 4 votes vote down vote up
/**
 * Create and return the user interface view for this fragment.
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState)
{
    int theme = getArguments().getInt("theme");
    int initialHour = getArguments().getInt("hour");
    int initialMinute = getArguments().getInt("minute");
    boolean isClientSpecified24HourTime = getArguments().getBoolean("isClientSpecified24HourTime");
    boolean is24HourTime = getArguments().getBoolean("is24HourTime");

    // Unless we inflate using a cloned inflater with a Holo theme,
    // on Lollipop devices the TimePicker will be the new-style
    // radial TimePicker, which is not what we want. So we will
    // clone the inflater that we're given but with our specified
    // theme, then inflate the layout with this new inflater.

    Context contextThemeWrapper = new ContextThemeWrapper(
            getActivity(),
            theme == SlideDateTimePicker.HOLO_DARK ?
                     android.R.style.Theme_Holo :
                     android.R.style.Theme_Holo_Light);

    LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper);

    View v = localInflater.inflate(R.layout.fragment_time, container, false);

    mTimePicker = (TimePicker) v.findViewById(R.id.timePicker);
    // block keyboard popping up on touch
    mTimePicker.setDescendantFocusability(DatePicker.FOCUS_BLOCK_DESCENDANTS);
    mTimePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {

        @Override
        public void onTimeChanged(TimePicker view, int hourOfDay, int minute)
        {
            mCallback.onTimeChanged(hourOfDay, minute);
        }
    });

    // If the client specifies a 24-hour time format, set it on
    // the TimePicker.
    if (isClientSpecified24HourTime)
    {
        mTimePicker.setIs24HourView(is24HourTime);
    }
    else
    {
        // If the client does not specify a 24-hour time format, use the
        // device default.
        mTimePicker.setIs24HourView(DateFormat.is24HourFormat(
            getTargetFragment().getActivity()));
    }

    mTimePicker.setCurrentHour(initialHour);
    mTimePicker.setCurrentMinute(initialMinute);

    // Fix for the bug where a TimePicker's onTimeChanged() is not called when
    // the user toggles the AM/PM button. Only applies to 4.0.0 and 4.0.3.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH &&
        Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
    {
        fixTimePickerBug18982();
    }

    return v;
}
 
Example 19
Source File: DateTimePickerDialog.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
private static void setHour(TimePicker picker, int hour) {
    picker.setCurrentHour(hour);
}
 
Example 20
Source File: TimeFragment.java    From SlideDayTimePicker with Apache License 2.0 4 votes vote down vote up
/**
 * Create and return the user interface view for this fragment.
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState)
{
    int theme = getArguments().getInt("theme");
    int initialHour = getArguments().getInt("hour");
    int initialMinute = getArguments().getInt("minute");
    boolean isClientSpecified24HourTime = getArguments().getBoolean("isClientSpecified24HourTime");
    boolean is24HourTime = getArguments().getBoolean("is24HourTime");

    // Unless we inflate using a cloned inflater with a Holo theme,
    // on Lollipop devices the TimePicker will be the new-style
    // radial TimePicker, which is not what we want. So we will
    // clone the inflater that we're given but with our specified
    // theme, then inflate the layout with this new inflater.

    Context contextThemeWrapper = new ContextThemeWrapper(
            getActivity(),
            theme == SlideDayTimePicker.HOLO_DARK ?
                    android.R.style.Theme_Holo : android.R.style.Theme_Holo_Light);
    LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper);
    View v = localInflater.inflate(R.layout.fragment_time, container, false);

    mTimePicker = (TimePicker) v.findViewById(R.id.timePicker);
    // block keyboard popping up on touch
    mTimePicker.setDescendantFocusability(DatePicker.FOCUS_BLOCK_DESCENDANTS);
    mTimePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {

        @Override
        public void onTimeChanged(TimePicker view, int hourOfDay, int minute)
        {
            mCallback.onTimeChanged(hourOfDay, minute);
        }
    });

    // If the client specifies a 24-hour time format, set it on
    // the TimePicker.
    if (isClientSpecified24HourTime)
    {
        mTimePicker.setIs24HourView(is24HourTime);
    }
    else
    {
        // If the client does not specify a 24-hour time format, use the
        // device default.
        mTimePicker.setIs24HourView(DateFormat.is24HourFormat(
            getTargetFragment().getActivity()));
    }

    mTimePicker.setCurrentHour(initialHour);
    mTimePicker.setCurrentMinute(initialMinute);

    // Fix for the bug where a TimePicker's onTimeChanged() is not called when
    // the user toggles the AM/PM button. Only applies to 4.0.0 and 4.0.3.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH &&
        Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
    {
        fixTimePickerBug18982();
    }

    return v;
}