android.widget.TimePicker Java Examples

The following examples show how to use android.widget.TimePicker. 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 vote down vote up
/**
 * 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: FormAdapter.java    From SSForms with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
    mCalendarCurrentTime.set(Calendar.HOUR_OF_DAY, hourOfDay);
    mCalendarCurrentTime.set(Calendar.MINUTE, minute);

    String myFormatTime = "HH:mm a"; // custom format
    SimpleDateFormat sdfTime = new SimpleDateFormat(myFormatTime, Locale.getDefault());

    // act only if clicked position is a valid index
    if (clickedPosition >= 0) {
        ((FormElement) mDataset.get(clickedPosition)).setValue(sdfTime.format(mCalendarCurrentTime.getTime()));
        notifyItemChanged(clickedPosition);
        clickedPosition = -1;

    }
}
 
Example #3
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 #4
Source File: NewEventActivity.java    From RoomBookerMVP with MIT License 6 votes vote down vote up
private void displayTimePicker(final EditText destination) {
    TimePickerFragment timePickerFragment = new TimePickerFragment();
    timePickerFragment.setOnTimeSetListener(new TimePickerDialog.OnTimeSetListener() {
        @Override
        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
            Calendar calendar = Calendar.getInstance();
            calendar.set(calendar.HOUR_OF_DAY, hourOfDay);
            calendar.set(Calendar.MINUTE, minute);
            String displayTime = simpleTimeFormat.format(calendar.getTime());
            destination.setText(displayTime);
            switch (destination.getId()) {
                case R.id.ane_start_time:
                    newEventPresenter.setStartTime(hourOfDay, minute);
                    break;
                case R.id.ane_end_time:
                    newEventPresenter.setEndTime(hourOfDay, minute);
                    break;
            }
        }
    });
    timePickerFragment.show(getSupportFragmentManager(), TimePickerFragment.TAG);
}
 
Example #5
Source File: FormAdapter.java    From SSForms with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
    mCalendarCurrentTime.set(Calendar.HOUR_OF_DAY, hourOfDay);
    mCalendarCurrentTime.set(Calendar.MINUTE, minute);
    String myFormatTime = "HH:mm"; // custom format
    SimpleDateFormat sdfTime = new SimpleDateFormat(myFormatTime, Locale.getDefault());
    // act only if clicked position is a valid index
    if (clickedPosition >= 0) {
        FormElementDateTime fe = (FormElementDateTime) mDataset.get(clickedPosition);
        fe.setValue(mCalendarCurrentTime.getTime());
        DateTimeCallBack dateTimeCallBack = fe.getCallback();
        dateTimeCallBack.callbackDateTimeReturn(mCalendarCurrentDate.getTime(), fe, fe.getTag());
        notifyItemChanged(clickedPosition);
        clickedPosition = -1;


    }
}
 
Example #6
Source File: ActivityImportSms.java    From fingen with Apache License 2.0 6 votes vote down vote up
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
    Calendar calendar = Calendar.getInstance();
    switch (mTimeType) {
        case R.id.editTextStartTime:
            calendar.setTime(mStartDate);
            calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), hourOfDay, minute);
            mStartDate.setTime(calendar.getTimeInMillis());
            break;
        case R.id.editTextEndTime:
            calendar.setTime(mEndDate);
            calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), hourOfDay, minute);
            mEndDate.setTime(calendar.getTimeInMillis());
            break;
    }
    initDates();
}
 
Example #7
Source File: FormAdapter.java    From SSForms with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
    mCalendarCurrentTime.set(Calendar.HOUR_OF_DAY, hourOfDay);
    mCalendarCurrentTime.set(Calendar.MINUTE, minute);

    String myFormatTime = "HH:mm"; // custom format
    SimpleDateFormat sdfTime = new SimpleDateFormat(myFormatTime, Locale.getDefault());

    // act only if clicked position is a valid index
    if (clickedPosition >= 0) {
        ((FormElement) mDataset.get(clickedPosition)).setValue(sdfTime.format(mCalendarCurrentTime.getTime()));
        notifyItemChanged(clickedPosition);
        clickedPosition = -1;

    }
}
 
Example #8
Source File: AddTrip.java    From kute with Apache License 2.0 6 votes vote down vote up
private void setupTimePicker(){
    // Get Current Time
    Calendar c = Calendar.getInstance();
    int mHour = c.get(Calendar.HOUR_OF_DAY);
    int mMinute = c.get(Calendar.MINUTE);

    // Launch Time Picker Dialog
    TimePickerDialog timePickerDialog = new TimePickerDialog(this,R.style.TimePickerTheme,
            new TimePickerDialog.OnTimeSetListener() {

                @Override
                public void onTimeSet(TimePicker view, int hourOfDay,
                                      int minute) {
                    Toast.makeText(AddTrip.this,Integer.toString(hourOfDay),Toast.LENGTH_SHORT).show();
                    String time_string1=Integer.toString(hourOfDay)+":"+Integer.toString(minute);
                    time.setText(time_string1);
                    time_string=time_string1;

                }
            }, mHour, mMinute, false);
    timePickerDialog.show();
}
 
Example #9
Source File: FragmentDarkThemeViewModel.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
public void onClickFromTime(View v) {
    sharedPreferences = G.context.getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE);
    int hour = sharedPreferences.getInt(SHP_SETTING.KEY_SELECTED_HOUR_FROM, 8);
    int minute = sharedPreferences.getInt(SHP_SETTING.KEY_SELECTED_MINUTE_FROM, 0);

    TimePickerDialog mTimePicker = new TimePickerDialog(G.currentActivity, new TimePickerDialog.OnTimeSetListener() {
        @Override
        public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
            long fNow = (selectedHour * 3600000) + (selectedMinute * 60000);
            SharedPreferences.Editor editor = sharedPreferences.edit();
            editor.putInt(SHP_SETTING.KEY_SELECTED_HOUR_FROM, selectedHour);
            editor.putInt(SHP_SETTING.KEY_SELECTED_MINUTE_FROM, selectedMinute);
            editor.putLong(SHP_SETTING.KEY_SELECTED_MILISECOND_FROM, fNow);
            editor.apply();
            callbackFromTime.set("" + selectedHour + ":" + selectedMinute);
        }
    }, hour, minute, true);//Yes 24 hour time
    mTimePicker.setTitle(G.context.getResources().getString(R.string.Select_Time));
    mTimePicker.show();

}
 
Example #10
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 #11
Source File: HistoryDetailActivity.java    From ActivityDiary with GNU General Public License v3.0 6 votes vote down vote up
public void showStartTimePickerDialog(View v) {
    TimePickerFragment newFragment = new TimePickerFragment();
    newFragment.setData(new TimePickerDialog.OnTimeSetListener (){
                            @Override
                            public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                                start.set(Calendar.HOUR_OF_DAY, hourOfDay);
                                start.set(Calendar.MINUTE, minute);
                                start.set(Calendar.SECOND, 0);
                                start.set(Calendar.MILLISECOND, 0);

                                Long newStart = Long.valueOf(start.getTimeInMillis());
                                updateValues.put(ActivityDiaryContract.Diary.START, newStart);
                                updateDateTimes();
                            }
                        }
            , start.get(Calendar.HOUR_OF_DAY), start.get(Calendar.MINUTE));
    newFragment.show(getSupportFragmentManager(), "startTimePicker");
}
 
Example #12
Source File: PreferencesFragment.java    From HouSi with Apache License 2.0 6 votes vote down vote up
private void showTimePicker() {
    final Calendar calendar = Calendar.getInstance();

    String startTime = QueryPreferences.getSettingServiceStartTime(getContext());
    if (startTime != null) {
        calendar.setTimeInMillis(Long.parseLong(startTime));
    }

    TimePickerDialog timePickerDialog = new TimePickerDialog(getContext(),
            new TimePickerDialog.OnTimeSetListener() {
                @Override
                public void onTimeSet(TimePicker timePicker, int hourOfDay, int minute) {
                    calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
                    calendar.set(Calendar.MINUTE, minute);

                    QueryPreferences.setSettingServiceStartTime(getContext(), calendar.getTimeInMillis() + "");
                    mSettingServiceStartTime.setSummary(SERVICE_START_TIME_FORMAT.format(calendar.getTime()));
                }
            },
            calendar.get(Calendar.HOUR_OF_DAY),
            calendar.get(Calendar.MINUTE),
            true);
    timePickerDialog.setTitle("设置时间");
    timePickerDialog.show();
}
 
Example #13
Source File: Setter.java    From AndroidRipper with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Sets the time in a given {@link TimePicker}.
 *
 * @param timePicker the {@code TimePicker} object.
 * @param hour the hour e.g. 15
 * @param minute the minute e.g. 30
 */

public void setTimePicker(final TimePicker timePicker, final int hour, final int minute) {
	if(timePicker != null){
		Activity activity = activityUtils.getCurrentActivity(false);
		if(activity != null){
			activity.runOnUiThread(new Runnable()
			{
				public void run()
				{
					try{
						timePicker.setCurrentHour(hour);
						timePicker.setCurrentMinute(minute);
					}catch (Exception ignored){}
				}
			});
		}
	}
}
 
Example #14
Source File: EventEditView.java    From ToDay with MIT License 6 votes vote down vote up
private void showTimePicker(final boolean startTime) {
    final Calendar dateTime = startTime ? mEvent.localStart : mEvent.localEnd;
    new TimePickerDialog(getContext(),
            new TimePickerDialog.OnTimeSetListener() {
                @Override
                public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                    dateTime.set(Calendar.HOUR_OF_DAY, hourOfDay);
                    dateTime.set(Calendar.MINUTE, minute);
                    mSwitchAllDay.setChecked(false);
                    setTime(startTime);
                }
            },
            dateTime.get(Calendar.HOUR_OF_DAY),
            dateTime.get(Calendar.MINUTE),
            false)
            .show();
}
 
Example #15
Source File: UIApi.java    From quickhybrid-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 弹出时间选择对话框
 * <p>
 * 参数:
 * title:标题
 * datetime 指定时间 yyyy-MM-dd HH:mm或者HH:mm
 * 返回:
 * time:格式:HH:mm
 */
public static void pickTime(IQuickFragment webLoader, WebView wv, JSONObject param, final Callback callback) {
    String title = param.optString("title");
    String date = param.optString("datetime");
    final Calendar calendar = Calendar.getInstance();
    if (!TextUtils.isEmpty(date)) {
        if (date.contains(" ")) {
            calendar.setTime(DateUtil.convertString2Date(date, "yyyy-MM-dd HH:mm"));
        } else {
            calendar.setTime(DateUtil.convertString2Date(date, "HH:mm"));
        }
    }
    DialogUtil.pickTime(webLoader.getPageControl().getActivity(), title, calendar, new TimePickerDialog.OnTimeSetListener() {
        @Override
        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
            calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
            calendar.set(Calendar.MINUTE, minute);
            String chooseTime = DateUtil.convertDate(calendar.getTime(), "HH:mm");
            Map<String, Object> map = new HashMap<>();
            map.put("time", chooseTime);
            callback.applySuccess(map);
        }
    });
}
 
Example #16
Source File: SettingsActivity.java    From SendBird-Android with MIT License 5 votes vote down vote up
private void setDoNotDisturbTime(final boolean from, final TextView textView) {
    long timeMillis = System.currentTimeMillis();
    if (from) {
        String doNotDisturbFrom = PreferenceUtils.getNotificationsDoNotDisturbFrom();
        if (doNotDisturbFrom.length() > 0) {
            timeMillis = Long.valueOf(doNotDisturbFrom);
        }
    } else {
        String doNotDisturbTo = PreferenceUtils.getNotificationsDoNotDisturbTo();
        if (doNotDisturbTo.length() > 0) {
            timeMillis = Long.valueOf(doNotDisturbTo);
        }
    }

    new TimePickerDialog(SettingsActivity.this, new TimePickerDialog.OnTimeSetListener() {
        @Override
        public void onTimeSet(TimePicker timePicker, int hour, int min) {
            mCalendar.clear();
            mCalendar.set(Calendar.HOUR_OF_DAY, hour);
            mCalendar.set(Calendar.MINUTE, min);
            long millis = mCalendar.getTimeInMillis();

            if (from) {
                if (!String.valueOf(millis).equals(PreferenceUtils.getNotificationsDoNotDisturbFrom())) {
                    PreferenceUtils.setNotificationsDoNotDisturbFrom(String.valueOf(millis));
                    saveDoNotDisturb(true);
                }
            } else {
                if (!String.valueOf(millis).equals(PreferenceUtils.getNotificationsDoNotDisturbTo())) {
                    PreferenceUtils.setNotificationsDoNotDisturbTo(String.valueOf(millis));
                    saveDoNotDisturb(true);
                }
            }
            textView.setText(DateUtils.formatTimeWithMarker(millis));
        }
    }, DateUtils.getHourOfDay(timeMillis), DateUtils.getMinute(timeMillis), true).show();
}
 
Example #17
Source File: TimePickerListener.java    From sensordatacollector with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minutes)
{
    String[] time = new String[2];

    time[0] = (hourOfDay < 10) ? "0" + hourOfDay : "" + hourOfDay;
    time[1] = (minutes < 10) ? "0" + minutes : "" + minutes;

    edittext.setText(time[0] + ":" + time[1]);
}
 
Example #18
Source File: TimePickerDialogFragment.java    From geopaparazzi with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onTimeSet(TimePicker arg0, int hourOfDay, int minute) {
    DecimalFormat decimalFormatter = new DecimalFormat("00"); //$NON-NLS-1$

    StringBuilder sb = new StringBuilder();
    sb.append(decimalFormatter.format(hourOfDay));
    sb.append(":"); //$NON-NLS-1$
    sb.append(decimalFormatter.format(minute));
    String dateStr = sb.toString();
    timeView.setText(dateStr);
}
 
Example #19
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 #20
Source File: Picker_Fragment.java    From ui with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View myView = inflater.inflate(R.layout.picker_fragment, container, false);
    tv_date = myView.findViewById(R.id.tv_date);
    tv_time = myView.findViewById(R.id.tv_time);
    btn_date = myView.findViewById(R.id.btn_date);
    btn_date.setOnClickListener(this);
    btn_time = myView.findViewById(R.id.btn_time);
    btn_time.setOnClickListener(this);

    //create the date picker listener, which is used later when the picker is called.
    d = new DatePickerDialog.OnDateSetListener() {
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            dateAndTime.set(Calendar.YEAR, year);
            dateAndTime.set(Calendar.MONTH, monthOfYear);
            dateAndTime.set(Calendar.DAY_OF_MONTH, dayOfMonth);
            tv_date.setText(fmtDate.format(dateAndTime.getTime()));
        }
    };
    //create the time picker listener
    t = new TimePickerDialog.OnTimeSetListener() {
        public void onTimeSet(TimePicker view, int selectedHour, int selectedMinute) {
            dateAndTime.set(Calendar.HOUR, selectedHour);
            dateAndTime.set(Calendar.MINUTE, selectedMinute);
            // set current time into textview
            tv_time.setText(fmtTime.format(dateAndTime.getTime()));
        }
    };
    return myView;
}
 
Example #21
Source File: InputDialogContainer.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void onDateTimeSet(DatePicker dateView, TimePicker timeView,
        int year, int month, int monthDay,
        int hourOfDay, int minute) {
    if (!mDialogAlreadyDismissed) {
        setFieldDateTimeValue(mDialogType, year, month, monthDay,
                hourOfDay, minute, WEEK_DEFAULT,
                mLocal ? HTML_DATE_TIME_LOCAL_FORMAT : HTML_DATE_TIME_FORMAT);
    }
}
 
Example #22
Source File: TimePreference.java    From privacy-friendly-interval-timer with GNU General Public License v3.0 5 votes vote down vote up
protected int getHour(TimePicker timePicker) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        return timePicker.getHour();
    } else {
        return timePicker.getCurrentHour();
    }
}
 
Example #23
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 #24
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 #25
Source File: TimePickerFragment.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {

        if (timeobj != null) {
            timeobj = (hourOfDay * 60) + minute;
        }
        if (callback != null) {
            callback.onTimeUpdated((hourOfDay * 60) + minute);
        }
    }
 
Example #26
Source File: SystemTimePickerDialog.java    From ClockPlus with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
    // http://stackoverflow.com/q/19452993/5055032
    // BUG PRE-LOLLIPOP! This is also called when the dialog is dismissed, so clicking
    // the 'Done' button will end up calling this twice!
    if (view.isShown() && mListener != null) {
        mListener.onTimeSet(view, hourOfDay, minute);
    }
}
 
Example #27
Source File: TimeSetterDialog.java    From GeometricWeather with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void initWidget(View view) {
    Button done = view.findViewById(R.id.dialog_time_setter_done);
    done.setOnClickListener(this);

    Button cancel = view.findViewById(R.id.dialog_time_setter_cancel);
    cancel.setOnClickListener(this);

    TimePicker timePicker = view.findViewById(R.id.dialog_time_setter_time_picker);
    timePicker.setIs24HourView(true);
    timePicker.setOnTimeChangedListener(this);
}
 
Example #28
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 #29
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 #30
Source File: TimingActivity.java    From Lamp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void showEndTimePickerDialog() {
    Calendar calendar = Calendar.getInstance();
    new TimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() {
        @Override
        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {


            setEndTimeTv(hourOfDay, minute);
        }
    }, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), true).show();

}