static Dialog createDialog( Bundle args, Context activityContext, @Nullable OnTimeSetListener onTimeSetListener ) { final Calendar now = Calendar.getInstance(); int hour = now.get(Calendar.HOUR_OF_DAY); int minute = now.get(Calendar.MINUTE); boolean is24hour = DateFormat.is24HourFormat(activityContext); if (args != null) { hour = args.getInt(TimePickerDialogModule.ARG_HOUR, now.get(Calendar.HOUR_OF_DAY)); minute = args.getInt(TimePickerDialogModule.ARG_MINUTE, now.get(Calendar.MINUTE)); is24hour = args.getBoolean( TimePickerDialogModule.ARG_IS24HOUR, DateFormat.is24HourFormat(activityContext)); } return new DismissableTimePickerDialog( activityContext, onTimeSetListener, hour, minute, is24hour); }
NumberPadTimePickerDialogViewDelegate(@NonNull DialogInterface delegator, @NonNull Context context, @NonNull NumberPadTimePicker timePicker, @Nullable View okButton, @Nullable OnTimeSetListener listener, boolean is24HourMode) { mDelegator = checkNotNull(delegator); mTimePicker = checkNotNull(timePicker); mOkButton = okButton; mTimeSetListener = listener; mDummy = new TimePicker(context); // TODO: If this model is needed by other classes, make it a singleton. final LocaleModel localeModel = new LocaleModel(context); mPresenter = new NumberPadTimePickerDialogPresenter(this, localeModel, is24HourMode); final OnBackspaceClickHandler backspaceClickHandler = new OnBackspaceClickHandler(mPresenter); mTimePicker.setOnBackspaceClickListener(backspaceClickHandler); mTimePicker.setOnBackspaceLongClickListener(backspaceClickHandler); mTimePicker.setOnNumberKeyClickListener(new OnNumberKeyClickListener(mPresenter)); mTimePicker.setOnAltKeyClickListener(new OnAltKeyClickListener(mPresenter)); }
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { // Find the TaskEditFragment that created this dialog. We'll // use that fragment as the edit callback, so that when the user // chooses a new date in our datepicker dialog, // the dialog will call back into the edit fragment to set the // new date. OnTimeSetListener listener = (OnTimeSetListener) getFragmentManager() .findFragmentByTag( TaskEditFragment .DEFAULT_FRAGMENT_TAG); // Construct a new TimePicker Dialog that will be hosted by // this fragment. Set its Hour and Minutes to the values // specified in the args bundle Bundle args = getArguments(); return new TimePickerDialog(getActivity(), listener, args.getInt(HOUR), args.getInt(MINS), false); }
/** * show timepicker * * @param mContext * @param mTextView formar of the time * @return show timepicker */ public static void showTimePickerDialog(final Context mContext, final TextView mTextView) { new TimePickerDialog(mContext, new OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { SimpleDateFormat timeFormatter = new SimpleDateFormat("hh:mm a"); dateTime.set(Calendar.HOUR_OF_DAY, hourOfDay); dateTime.set(Calendar.MINUTE, minute); mTextView.setText(timeFormatter.format(dateTime.getTime())); } }, dateTime.get(Calendar.HOUR_OF_DAY), dateTime.get(Calendar.MINUTE), false).show(); }
private void setEventListeners() { saveAlert.setOnClickListener(onAlertSave()); alertEventSpinner.setOnItemSelectedListener(spinnerItemSelected()); editStartTime.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { TimePickerDialog tp1 = new TimePickerDialog(activity, new OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { editStartTime.setText(hourOfDay + ":" + minute); } }, 00, 00, true); tp1.show(); } }); }
public void showTimeDialog() { final Calendar cal = Calendar.getInstance(); // load preferences SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity()); int hourOfDay = cal.get(Calendar.HOUR_OF_DAY); int minute = cal.get(Calendar.MINUTE); try { hourOfDay = sharedPref.getInt("alarm_hour_of_day", Calendar.HOUR_OF_DAY); minute = sharedPref.getInt("alarm_minute", Calendar.MINUTE); } catch (Exception e) { e.printStackTrace(); } OnTimeSetListener timeSetListener = (OnTimeSetListener) this; new TimePickerDialog(getActivity(), 0, timeSetListener, hourOfDay, minute, true).show(); }
/** * 日期和时间选择对话框,选选择日期后选择时间 * * @param con 上下文 * @param title1 日期选择标题 * @param title2 事件选择标题 * @param calendar 默认日期 * @param listener 时间选择事件 */ public static void pickDateTime(final Context con, String title1, final String title2, final Calendar calendar, final OnTimeSetListener listener) { // 增加判断,解决4.X系统可能存在的弹出多个时间选择器的问题 final boolean[] isShowTime = {false}; pickDate(con, title1, calendar, new OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) { calendar.set(year, month, dayOfMonth); if (!isShowTime[0]) { isShowTime[0] = true; pickTime(con, title2, calendar, listener); } } }); }
/** * 时间选择对话框 * * @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(); }
public static NumberPadTimePickerDialogFragment newInstance(OnTimeSetListener listener, @DialogMode int dialogMode, @StyleRes int themeResId, boolean customTheme) { NumberPadTimePickerDialogFragment f = new NumberPadTimePickerDialogFragment(); Bundle args = new Bundle(); args.putInt(KEY_THEME_RES_ID, themeResId); args.putInt(KEY_DIALOG_MODE, dialogMode); args.putBoolean(KEY_CUSTOM_THEME, customTheme); f.setArguments(args); f.listener = listener; return f; }
static void setupDialogView(@NonNull DialogView dialogView, @NonNull final Context context, @NonNull final NumberPadTimePicker timePicker, @NonNull View okButton, @Nullable final OnTimeSetListener listener, boolean is24HourMode) { DialogPresenter presenter = new NumberPadTimePickerDialogPresenter(dialogView, timePicker.getPresenter()); setupDialogView(dialogView, presenter, context, timePicker, okButton, listener, is24HourMode); }
public NumberPadTimePickerDialog(@NonNull Context context, @StyleRes int themeResId, @Nullable OnTimeSetListener listener, boolean is24HourMode) { super(context, resolveDialogTheme(context, themeResId)); final View root = getLayoutInflater().inflate( R.layout.nptp_alert_numberpad_time_picker_dialog, null); final NumberPadTimePicker timePicker = (NumberPadTimePicker) root.findViewById(R.id.nptp_time_picker); final NumberPadTimePickerAlertComponent timePickerComponent = (NumberPadTimePickerAlertComponent) timePicker.getComponent(); final DialogPresenter presenter = new NumberPadTimePickerDialogPresenter( this, timePicker.getPresenter()); DialogViewInitializer.setupDialogView(this, presenter, getContext(), timePicker, timePickerComponent.getOkButton(), listener, is24HourMode); timePickerComponent.getCancelButton().setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { presenter.onCancelClick(); } }); mThemer = new NumberPadTimePickerDialogThemer(timePickerComponent); mIs24HourMode = is24HourMode; // Must be requested before adding content, or get an AndroidRuntimeException! supportRequestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(root); }
public Bug34833WorkaroundTimePickerDialog(Context context, OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) throws NoSuchFieldException, IllegalAccessException, IllegalArgumentException { super(context, null, hourOfDay, minute, is24HourView); this.callBack = callBack; //É obrigado a obter o timePicker desta forma porque o TimePickerDialog não possui um "getTimePicker" (ao contrário do DatePickerDialog). Field field = TimePickerDialog.class.getDeclaredField("mTimePicker"); field.setAccessible(true); timePicker = (TimePicker) field.get(this); }
@Override public Dialog onCreateDialog(Bundle savedInstanceState){ OnTimeSetListener listener = (OnTimeSetListener) getFragmentManager().findFragmentByTag(TaskEditFragment.DEFAULT_FRAGMENT_TAG); Bundle args = getArguments(); return new TimePickerDialog(getActivity(),listener,args.getInt(HOUR),args.getInt(MINS),false); }
private void showTimeDlg(final TextView textView) { TimePickerDialog pickdialog = new TimePickerDialog(mContext, new OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { textView.setText(String.format("%02d:%02d", hourOfDay, minute)); } }, 0, 0, true); pickdialog.show(); }
/** * Show date and time pickers */ protected void showDateTimeSelectors(long reminder) { // Sets actual time or previously saved in note final Calendar now = DateHelper.getCalendar(reminder); DatePickerDialog mCalendarDatePickerDialog = DatePickerDialog.newInstance( new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePickerDialog dialog, int year, int monthOfYear, int dayOfMonth) { reminderYear = year; reminderMonth = monthOfYear; reminderDay = dayOfMonth; TimePickerDialog mRadialTimePickerDialog = TimePickerDialog.newInstance( new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(RadialPickerLayout radialPickerLayout, int hour, int minute) { hourOfDay = hour; minutes = minute; showRecurrencePickerDialog(recurrenceRule); } }, now.get(Calendar.HOUR_OF_DAY), now.get(Calendar.MINUTE), DateHelper.is24HourMode(mActivity)); mRadialTimePickerDialog.show(mActivity.getSupportFragmentManager(), Constants.TAG); } }, now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH)); mCalendarDatePickerDialog.show(mActivity.getSupportFragmentManager(), Constants.TAG); }
@Override public void onAttach(Activity activity) { super.onAttach(activity); mActivity = activity; if (getArguments().containsKey(DEFAULT_TIME)) { this.defaultTime = getArguments().getLong(DEFAULT_TIME); } try { mListener = (OnTimeSetListener) mActivity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement OnTimeSetListener"); } }
private void selectTime(final boolean isWindowStart) { int defaultMinutes = isWindowStart ? mMaintenanceStart : mMaintenanceEnd; TimePickerDialog timePicker = new TimePickerDialog(getActivity(), new OnTimeSetListener() { @Override public void onTimeSet(TimePicker arg0, int hour, int minutes) { if (isWindowStart) { mMaintenanceStart = hour * 60 + minutes; } else { mMaintenanceEnd = hour * 60 + minutes; } updateMaintenanceWindowDisplay(); } }, defaultMinutes / 60, defaultMinutes % 60, true); timePicker.show(); }
public void showTimePicker(OnTimeSetListener timeSetListener, int hourOfDay, int minute) { if (mActivity.isFinishing()) { return; } close(); dlgTime = new TimePickerDialog(mActivity, timeSetListener, hourOfDay, minute, true); dlgTime.show(); // try { // DialogFragment timePicker = new TimePickerFragment(timeSetListener, hourOfDay, minute); // timePicker.show(mActivity.getSupportFragmentManager(), "timePicker"); // } catch (Exception e) { // Log.e(TAG, "showTimePicker " + e.getMessage()); // } }
private Dialog createTimePicker() { OnTimeSetListener timeSetListener = new TimePickerDialog.OnTimeSetListener() { public void onTimeSet(TimePicker view, int hour, int minute) { setTime(hour, minute); Log.d(TAG, "Setting time to: " + hour + ":" + minute); } }; return new TimePickerDialog(getContext(), timeSetListener, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), true) { }; }
@Override public void onAttach(Activity activity) { super.onAttach(activity); mActivity = (Activity) activity; if (getArguments().containsKey(DEFAULT_TIME)) { this.defaultTime = getArguments().getLong(DEFAULT_TIME); } try { mListener = (OnTimeSetListener) mActivity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement OnTimeSetListener"); } }
@Override protected AlertDialog createDialog(final Calendar cal) { OnTimeSetListener callback = new OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { cal.set(Calendar.HOUR_OF_DAY, hourOfDay); cal.set(Calendar.MINUTE, minute); listener.onValuePicked(String.valueOf(cal.getTimeInMillis())); } }; TimePickerDialog dialog = new TimePickerDialog(activity, callback, cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), android.text.format.DateFormat.is24HourFormat(activity)); return dialog; }
public static void pickDateTime(Context con, Calendar calendar, OnTimeSetListener listener) { pickDateTime(con, con.getString(R.string.pick_date), con.getString(R.string.pick_time), calendar, listener); }
public static void pickTime(Context con, String title, OnTimeSetListener listener) { final Calendar cal = Calendar.getInstance(); pickTime(con, title, cal, listener); }
public static void pickTime(Context con, OnTimeSetListener listener) { final Calendar cal = Calendar.getInstance(); pickTime(con, con.getString(R.string.pick_time), cal, listener); }
public BottomSheetNumberPadTimePickerDialog(@NonNull Context context, @Nullable OnTimeSetListener listener, boolean is24HourMode) { this(context, 0, listener, is24HourMode); }
public NumberPadTimePickerDialog(@NonNull Context context, @Nullable OnTimeSetListener listener, boolean is24HourMode) { this(context, 0, listener, is24HourMode); }
public void setOnTimeSetListener(@Nullable OnTimeSetListener onTimeSetListener) { mOnTimeSetListener = onTimeSetListener; }