android.app.TimePickerDialog.OnTimeSetListener Java Examples

The following examples show how to use android.app.TimePickerDialog.OnTimeSetListener. 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: NumberPadTimePickerDialogViewDelegate.java    From BottomSheetPickers with Apache License 2.0 6 votes vote down vote up
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));
}
 
Example #2
Source File: DialogUtil.java    From quickhybrid-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 日期和时间选择对话框,选选择日期后选择时间
 *
 * @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);
            }
        }
    });
}
 
Example #3
Source File: DialogUtil.java    From quickhybrid-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 时间选择对话框
 *
 * @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 #4
Source File: TimeView.java    From Viewer with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #5
Source File: NumberPadTimePickerDialogFragment.java    From NumberPadTimePicker with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #6
Source File: DialogViewInitializer.java    From NumberPadTimePicker with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #7
Source File: NumberPadTimePickerDialog.java    From NumberPadTimePicker with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #8
Source File: TimePickerFragmentActivity.java    From coursera-android with MIT License 4 votes vote down vote up
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
    ((OnTimeSetListener) getActivity()).onTimeSet(view, hourOfDay,
            minute);
}
 
Example #9
Source File: SupportTimePickerDialogFragment.java    From react-native-GPay with MIT License 4 votes vote down vote up
public void setOnTimeSetListener(@Nullable OnTimeSetListener onTimeSetListener) {
  mOnTimeSetListener = onTimeSetListener;
}
 
Example #10
Source File: TimePickerFragmentActivity.java    From coursera-android with MIT License 4 votes vote down vote up
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
	((OnTimeSetListener) getActivity()).onTimeSet(view, hourOfDay,
			minute);

}
 
Example #11
Source File: BottomSheetNumberPadTimePickerDialog.java    From BottomSheetPickers with Apache License 2.0 4 votes vote down vote up
public BottomSheetNumberPadTimePickerDialog(@NonNull Context context,
        @Nullable OnTimeSetListener listener, boolean is24HourMode) {
    this(context, 0, listener, is24HourMode);
}
 
Example #12
Source File: NumberPadTimePickerDialog.java    From NumberPadTimePicker with Apache License 2.0 4 votes vote down vote up
public NumberPadTimePickerDialog(@NonNull Context context,
        @Nullable OnTimeSetListener listener, boolean is24HourMode) {
    this(context, 0, listener, is24HourMode);
}
 
Example #13
Source File: BottomSheetNumberPadTimePickerDialog.java    From NumberPadTimePicker with Apache License 2.0 4 votes vote down vote up
public BottomSheetNumberPadTimePickerDialog(@NonNull Context context,
        @Nullable OnTimeSetListener listener, boolean is24HourMode) {
    this(context, 0, listener, is24HourMode);
}
 
Example #14
Source File: DialogUtil.java    From quickhybrid-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static void pickTime(Context con, OnTimeSetListener listener) {
    final Calendar cal = Calendar.getInstance();
    pickTime(con, con.getString(R.string.pick_time), cal, listener);
}
 
Example #15
Source File: DialogUtil.java    From quickhybrid-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static void pickTime(Context con, String title, OnTimeSetListener listener) {
    final Calendar cal = Calendar.getInstance();
    pickTime(con, title, cal, listener);
}
 
Example #16
Source File: DialogUtil.java    From quickhybrid-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
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);
}
 
Example #17
Source File: TimePickerDialogFragment.java    From react-native-GPay with MIT License 4 votes vote down vote up
public void setOnTimeSetListener(@Nullable OnTimeSetListener onTimeSetListener) {
  mOnTimeSetListener = onTimeSetListener;
}
 
Example #18
Source File: TimePickerDialogFragment.java    From react-native-GPay with MIT License 4 votes vote down vote up
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);

  TimePickerMode mode = TimePickerMode.DEFAULT;
  if (args != null && args.getString(TimePickerDialogModule.ARG_MODE, null) != null) {
    mode = TimePickerMode.valueOf(args.getString(TimePickerDialogModule.ARG_MODE).toUpperCase(Locale.US));
  }

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

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    if (mode == TimePickerMode.CLOCK) {
      return new DismissableTimePickerDialog(
        activityContext,
        activityContext.getResources().getIdentifier(
          "ClockTimePickerDialog",
          "style",
          activityContext.getPackageName()
        ),
        onTimeSetListener,
        hour,
        minute,
        is24hour
      );
    } else if (mode == TimePickerMode.SPINNER) {
      return new DismissableTimePickerDialog(
        activityContext,
        activityContext.getResources().getIdentifier(
          "SpinnerTimePickerDialog",
          "style",
          activityContext.getPackageName()
        ),
        onTimeSetListener,
        hour,
        minute,
        is24hour
      );
    }
  }
  return new DismissableTimePickerDialog(
          activityContext,
          onTimeSetListener,
          hour,
          minute,
          is24hour
  );
}