Java Code Examples for android.widget.TimePicker#setCurrentMinute()
The following examples show how to use
android.widget.TimePicker#setCurrentMinute() .
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: TimePickerDialog.java From android_9.0.0_r45 with Apache License 2.0 | 7 votes |
/** * Creates a new time picker dialog with the specified theme. * <p> * The theme is overlaid on top of the theme of the parent {@code context}. * If {@code themeResId} is 0, the dialog will be inflated using the theme * specified by the * {@link android.R.attr#timePickerDialogTheme android:timePickerDialogTheme} * attribute on the parent {@code context}'s theme. * * @param context the parent context * @param themeResId the resource ID of the theme to apply to this dialog * @param listener the listener to call when the time is set * @param hourOfDay the initial hour * @param minute the initial minute * @param is24HourView Whether this is a 24 hour view, or AM/PM. */ public TimePickerDialog(Context context, int themeResId, OnTimeSetListener listener, int hourOfDay, int minute, boolean is24HourView) { super(context, resolveDialogTheme(context, themeResId)); mTimeSetListener = listener; mInitialHourOfDay = hourOfDay; mInitialMinute = minute; mIs24HourView = is24HourView; final Context themeContext = getContext(); final LayoutInflater inflater = LayoutInflater.from(themeContext); final View view = inflater.inflate(R.layout.time_picker_dialog, null); setView(view); setButton(BUTTON_POSITIVE, themeContext.getString(R.string.ok), this); setButton(BUTTON_NEGATIVE, themeContext.getString(R.string.cancel), this); setButtonPanelLayoutHint(LAYOUT_HINT_SIDE); mTimePicker = (TimePicker) view.findViewById(R.id.timePicker); mTimePicker.setIs24HourView(mIs24HourView); mTimePicker.setCurrentHour(mInitialHourOfDay); mTimePicker.setCurrentMinute(mInitialMinute); mTimePicker.setOnTimeChangedListener(this); }
Example 2
Source File: PickerActions.java From android-test with Apache License 2.0 | 6 votes |
/** 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 |
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: TimePickerPreference.java From ploggy with GNU General Public License v3.0 | 6 votes |
@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 5
Source File: DateTimePickDialogUtil.java From VideoMeeting with Apache License 2.0 | 6 votes |
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 6
Source File: DateWidgets2.java From codeexamples-android with Eclipse Public License 1.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.date_widgets_example_2); TimePicker timePicker = (TimePicker) findViewById(R.id.timePicker); timePicker.setCurrentHour(12); timePicker.setCurrentMinute(15); mTimeDisplay = (TextView) findViewById(R.id.dateDisplay); updateDisplay(12, 15); timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() { public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { updateDisplay(hourOfDay, minute); } }); }
Example 7
Source File: DateTimePickerDialog.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
/** * @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 8
Source File: TimeMeasurementView.java From openScale with GNU General Public License v3.0 | 5 votes |
@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 9
Source File: ClockPreference.java From heads-up with GNU General Public License v3.0 | 5 votes |
@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 10
Source File: TimePreference.java From privacy-friendly-interval-timer with GNU General Public License v3.0 | 5 votes |
protected void setMinute(TimePicker timePicker, int minute) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { timePicker.setMinute(minute); } else { timePicker.setCurrentMinute(minute); } }
Example 11
Source File: TimeEventSkillViewFragment.java From Easer with GNU General Public License v3.0 | 5 votes |
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 12
Source File: GeckoViewPrompt.java From focus-android with Mozilla Public License 2.0 | 5 votes |
@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 android with MIT License | 5 votes |
@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 14
Source File: SimpleTimeDialog.java From SimpleDialogFragments with Apache License 2.0 | 5 votes |
@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 15
Source File: TimePickerPreference.java From BatteryFu with GNU General Public License v2.0 | 5 votes |
@Override protected View onCreateDialogView() { TimePicker tp = new TimePicker(getContext()); tp.setOnTimeChangedListener(this); int h = getHour(); int m = getMinute(); if (h >= 0 && m >= 0) { tp.setCurrentHour(h); tp.setCurrentMinute(m); } return tp; }
Example 16
Source File: TimePreference.java From financisto with GNU General Public License v2.0 | 5 votes |
@Override protected View onCreateDialogView() { Context context = getContext(); TimePicker timePicker = new TimePicker(context); timePicker.setIs24HourView(is24HourFormat(context)); timePicker.setOnTimeChangedListener(this); timePicker.setCurrentHour(getHour()); timePicker.setCurrentMinute(getMinute()); return timePicker; }
Example 17
Source File: DialogUtil.java From quickhybrid-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * 时间选择对话框 * * @param con 上下文 * @param title 标题 * @param listener 选择事件 * @param cal 默认时间 */ public static void pickTime(Context con, String title, Calendar cal, final OnTimeSetListener listener) { LinearLayout ll = new LinearLayout(con); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); ll.setLayoutParams(layoutParams); ll.setOrientation(LinearLayout.VERTICAL); //添加一条线 LinearLayout line = new LinearLayout(con); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 1); line.setBackgroundColor(con.getResources().getColor(R.color.line)); line.setLayoutParams(lp); ll.addView(line); //添加选择器控件 final TimePicker timePicker = new TimePicker(con, null, themeId); timePicker.setLayoutParams(layoutParams); timePicker.setCurrentHour(cal.get(Calendar.HOUR_OF_DAY)); timePicker.setCurrentMinute(cal.get(Calendar.MINUTE)); timePicker.setIs24HourView(true); ll.addView(timePicker); QuickDialog.Builder builder = new QuickDialog.Builder(con); builder.setContentView(ll); builder.setTitle(title); builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); listener.onTimeSet(timePicker, timePicker.getCurrentHour(), timePicker.getCurrentMinute()); } }); builder.create().show(); }
Example 18
Source File: TimeFragment.java From SlideDateTimePicker with Apache License 2.0 | 4 votes |
/** * 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 |
@SuppressWarnings("deprecation") private static void setMinute(TimePicker picker, int minute) { picker.setCurrentMinute(minute); }
Example 20
Source File: TimeFragment.java From SlideDayTimePicker with Apache License 2.0 | 4 votes |
/** * 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; }