android.app.TimePickerDialog Java Examples

The following examples show how to use android.app.TimePickerDialog. 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: AEditText.java    From Stylish-Widget-for-Android with Apache License 2.0 6 votes vote down vote up
public void createTimePicker(final boolean isDateTimePicker) {
    timePicker = new TimePickerDialog(
            getContext(),
            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);

                    if (isDateTimePicker)
                        displayDateTime();
                    else
                        displayTime();
                }
            },
            calendar.get(Calendar.HOUR_OF_DAY),
            calendar.get(Calendar.MINUTE),
            is24Hours
    );
}
 
Example #2
Source File: DateTimeTableView.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void showTimePicker(View view) {
    final Calendar c = Calendar.getInstance();
    int hour = c.get(Calendar.HOUR_OF_DAY);
    int minute = c.get(Calendar.MINUTE);
    boolean is24HourFormat = android.text.format.DateFormat.is24HourFormat(getContext());

    TimePickerDialog dialog = new TimePickerDialog(getContext(), (
            timePicker, hourOfDay, minutes) -> {
        selectedCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
        selectedCalendar.set(Calendar.MINUTE, minutes);
        Date selectedDate = selectedCalendar.getTime();
        String result = DateUtils.timeFormat().format(selectedDate);
        textView.setText(result);
        listener.onDateSelected(selectedDate);
        nextFocus(view);
    },
            hour,
            minute,
            is24HourFormat);
    dialog.setTitle(label);
    dialog.show();
}
 
Example #3
Source File: FragmentOptionsSynchronize.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Bundle args = getArguments();
    boolean start = args.getBoolean("start");

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
    int minutes = prefs.getInt("schedule_" + (start ? "start" : "end"), 0);

    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, minutes / 60);
    cal.set(Calendar.MINUTE, minutes % 60);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);

    return new TimePickerDialog(getContext(), this,
            cal.get(Calendar.HOUR_OF_DAY),
            cal.get(Calendar.MINUTE),
            DateFormat.is24HourFormat(getContext()));
}
 
Example #4
Source File: FragmentRule.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Bundle args = getArguments();
    int minutes = args.getInt("minutes");

    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, minutes / 60);
    cal.set(Calendar.MINUTE, minutes % 60);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);

    return new TimePickerDialog(getContext(), this,
            cal.get(Calendar.HOUR_OF_DAY),
            cal.get(Calendar.MINUTE),
            DateFormat.is24HourFormat(getContext()));
}
 
Example #5
Source File: DateTimeView.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void showTimePicker(View view) {
    final Calendar c = Calendar.getInstance();
    int hour = c.get(Calendar.HOUR_OF_DAY);
    int minute = c.get(Calendar.MINUTE);
    boolean is24HourFormat = android.text.format.DateFormat.is24HourFormat(getContext());

    TimePickerDialog dialog = new TimePickerDialog(getContext(), (
            timePicker, hourOfDay, minutes) -> {
        selectedCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
        selectedCalendar.set(Calendar.MINUTE, minutes);
        Date selectedDate = selectedCalendar.getTime();
        String result = dateFormat.format(selectedDate);
        editText.setText(result);
        listener.onDateSelected(selectedDate);
        nextFocus(view);
        date = null;
    },
            hour,
            minute,
            is24HourFormat);
    dialog.setTitle(binding.getLabel());
    dialog.show();
}
 
Example #6
Source File: ActivityImportSms.java    From fingen with Apache License 2.0 6 votes vote down vote up
@OnClick({R.id.editTextStartTime, R.id.editTextEndTime})
public void onTimeClick(View view) {
    Calendar calendar = Calendar.getInstance();
    switch (view.getId()) {
        case R.id.editTextStartTime:
            calendar.setTime(mStartDate);
            break;
        case R.id.editTextEndTime:
            calendar.setTime(mEndDate);
            break;
    }
    new TimePickerDialog(this,
            this,
            calendar.get(Calendar.HOUR_OF_DAY),
            calendar.get(Calendar.MINUTE),
            DateTimeFormatter.is24(this)
    ).show();
    mTimeType = view.getId();
}
 
Example #7
Source File: AddVoiceSettingActivity.java    From your-local-weather with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    Long storedHourMinute = voiceSettingParametersDbHelper.getLongParam(
            voiceSettingId,
            VoiceSettingParamType.VOICE_SETTING_TIME_TO_START.getVoiceSettingParamTypeId());

    int hour;
    int minute;
    if (storedHourMinute == null) {
        final Calendar c = Calendar.getInstance();
        hour = c.get(Calendar.HOUR_OF_DAY);
        minute = c.get(Calendar.MINUTE);
    } else {
        int hourMinute = storedHourMinute.intValue();
        hour = hourMinute / 100;
        minute = hourMinute - (hour * 100);
    }
    return new TimePickerDialog(getActivity(), this, hour, minute,
            DateFormat.is24HourFormat(getActivity()));
}
 
Example #8
Source File: ActivityEditTransaction.java    From fingen with Apache License 2.0 6 votes vote down vote up
public void onTimeClick(View view) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(transaction.getDateTime());
    new TimePickerDialog(this,
            (timePicker, hourOfDay, minute) -> {
                Calendar calendar1 = Calendar.getInstance();
                calendar1.setTime(transaction.getDateTime());
                calendar1.set(calendar1.get(Calendar.YEAR), calendar1.get(Calendar.MONTH), calendar1.get(Calendar.DAY_OF_MONTH), hourOfDay, minute);
                transaction.setDateTime(calendar1.getTime());
                initDateTimeButtons();
            },
            calendar.get(Calendar.HOUR_OF_DAY),
            calendar.get(Calendar.MINUTE),
            DateTimeFormatter.is24(this)
    ).show();
}
 
Example #9
Source File: CVDatePreference.java    From callmeter with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onDialogClosed(final boolean positiveResult) {
    if (positiveResult) {
        v.set(dp.getYear(), dp.getMonth(), dp.getDayOfMonth());
        cv.put(getKey(), v.getTimeInMillis());
        if (ul != null) {
            ul.onUpdateValue(this);
        }
        if (dt) {
            TimePickerDialog tpd = new TimePickerDialog(getContext(), this,
                    v.get(Calendar.HOUR_OF_DAY), v.get(Calendar.MINUTE), true);
            tpd.setTitle(getTitle());
            tpd.setCancelable(true);
            tpd.show();
        }
    }
}
 
Example #10
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 #11
Source File: HistoryDetailActivity.java    From ActivityDiary with GNU General Public License v3.0 6 votes vote down vote up
public void showEndTimePickerDialog(View v) {
    TimePickerFragment newFragment = new TimePickerFragment();
    newFragment.setData(new TimePickerDialog.OnTimeSetListener (){
                            @Override
                            public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                                end.set(Calendar.HOUR_OF_DAY, hourOfDay);
                                end.set(Calendar.MINUTE, minute);
                                end.set(Calendar.SECOND, 0);
                                end.set(Calendar.MILLISECOND, 0);

                                Long newEnd = Long.valueOf(end.getTimeInMillis());
                                updateValues.put(ActivityDiaryContract.Diary.END, newEnd);
                                updateDateTimes();
                            }
                        }
            , end.get(Calendar.HOUR_OF_DAY), end.get(Calendar.MINUTE));
    newFragment.show(getSupportFragmentManager(), "endTimePicker");
}
 
Example #12
Source File: OCM_ChildMenu.java    From GLEXP-Team-onebillion with Apache License 2.0 6 votes vote down vote up
void showPickTimeDialog (final TimePickerDialog.OnTimeSetListener listener)
{
    final DatePickerDialog.OnDateSetListener dateListener = (DatePickerDialog.OnDateSetListener) listener;
    final Calendar calendar = Calendar.getInstance();
    TimePickerDialog d = new TimePickerDialog(MainActivity.mainActivity, listener, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), DateFormat.is24HourFormat(MainActivity.mainActivity));
    //
    d.setCancelable(false);
    d.setCanceledOnTouchOutside(false);
    //
    d.setButton(DatePickerDialog.BUTTON_NEGATIVE, "Back", new DialogInterface.OnClickListener()
    {
        @Override
        public void onClick (DialogInterface dialog, int which)
        {
            showPickDateDialog(dateListener, null);
        }
    });
    //
    LinearLayout linearLayout = new LinearLayout(MainActivity.mainActivity.getApplicationContext());
    d.requestWindowFeature(Window.FEATURE_NO_TITLE);
    d.setCustomTitle(linearLayout);
    //
    d.show();
}
 
Example #13
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 #14
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 #15
Source File: OBSystemsManager.java    From GLEXP-Team-onebillion with Apache License 2.0 6 votes vote down vote up
public Dialog createTimeSetDialog(OBUtils.RunLambda completionBlock, final OBUtils.RunLambda cancelCompletionBlock)
{
    timeSetCompletionBlock = completionBlock;
    final Calendar calendar = Calendar.getInstance();
    TimePickerDialog d = new TimePickerDialog(MainActivity.mainActivity, this, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), DateFormat.is24HourFormat(MainActivity.mainActivity));
    d.setCancelable(false);
    d.setCanceledOnTouchOutside(false);
    d.setButton(DatePickerDialog.BUTTON_NEGATIVE, "Back", new DialogInterface.OnClickListener()
    {
        @Override
        public void onClick(DialogInterface dialog, int which)
        {
            OBUtils.runOnMainThread(cancelCompletionBlock);
        }
    });
    d.setMessage("Please set the current time.\n");
    return d;
}
 
Example #16
Source File: Picker_Fragment.java    From ui with Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(View v) {

    if (v == btn_date) {//date picker
        new DatePickerDialog(getActivity(), d,
            dateAndTime.get(Calendar.YEAR),
            dateAndTime.get(Calendar.MONTH),
            dateAndTime.get(Calendar.DAY_OF_MONTH)
        ).show();
    } else { //time picker
        Log.v("Time", "Should show the picker!");
        new TimePickerDialog(getActivity(), t,
            dateAndTime.get(Calendar.HOUR),
            dateAndTime.get(Calendar.MINUTE),
            false
        ).show();
    }
}
 
Example #17
Source File: SelfRouteDetailActivity.java    From kute with Apache License 2.0 6 votes vote down vote up
/********************** Custom Functions *********************/
//Creates the dialog for time picking
public void setupTimePickerDialog(){
    // 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(SelfRouteDetailActivity.this,Integer.toString(hourOfDay),Toast.LENGTH_SHORT).show();
                    String time_string=Integer.toString(hourOfDay)+":"+Integer.toString(minute);
                    time.setText(time_string);

                }
            }, mHour, mMinute, false);
    timePickerDialog.show();
}
 
Example #18
Source File: AddRouteActivity.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(AddRouteActivity.this,Integer.toString(hourOfDay),Toast.LENGTH_SHORT).show();
                    String time_string=Integer.toString(hourOfDay)+":"+Integer.toString(minute);
                    time.setText(time_string);

                }
            }, mHour, mMinute, false);
    timePickerDialog.show();
}
 
Example #19
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 #20
Source File: FragmentDarkThemeViewModel.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
public void onClickToTime(View v) {

        sharedPreferences = G.context.getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE);
        int hour = sharedPreferences.getInt(SHP_SETTING.KEY_SELECTED_HOUR_TO, 8);
        int minute = sharedPreferences.getInt(SHP_SETTING.KEY_SELECTED_MINUTE_TO, 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_TO, selectedHour);
                editor.putInt(SHP_SETTING.KEY_SELECTED_MINUTE_TO, selectedMinute);
                editor.putLong(SHP_SETTING.KEY_SELECTED_MILISECOND_TO, fNow);
                editor.apply();
                callbackToTime.set("" + selectedHour + ":" + selectedMinute);
            }
        }, hour, minute, true);//Yes 24 hour time
        mTimePicker.setTitle(G.context.getResources().getString(R.string.Select_Time));
        mTimePicker.show();

    }
 
Example #21
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 #22
Source File: ScheduleShoppingList.java    From ShoppingList with MIT License 6 votes vote down vote up
@Override
public void onClick(View v) {
	switch (v.getId()) {
	case R.id.schedule_notificatin_display_time:
		new TimePickerDialog(getContext(), timePickerListener, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), true).show();
		break;

	case R.id.schedule_notificatin_display_date:
		new DatePickerDialog(getContext(), datePickerListener, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)).show();
		break;
	case R.id.schedule_notificatin_cancel:
		dismiss();
		break;

	case R.id.schedule_notificatin_schedule:
		AlarmeNotificationShoppingList.initAlarme(getContext(), idShoppingList, calendar);
		Toast.makeText(getContext(), getContext().getResources().getString(R.string.new_notification_seted) + " " + CustomDateFormat.getFormatedCompletedDate(new Date(calendar.getTimeInMillis())), Toast.LENGTH_LONG).show();
		dismiss();
		break;
	}
}
 
Example #23
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 #24
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 #25
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
 * 返回:
 * datetime:格式:yyyy-MM-dd HH:mm
 */
public static void pickDateTime(final IQuickFragment webLoader, WebView wv, JSONObject param, final Callback callback) {
    String title1 = param.optString("title1");
    String title2 = param.optString("title2");
    String date = param.optString("datetime");
    final Calendar calendar = Calendar.getInstance();
    if (!TextUtils.isEmpty(date)) {
        calendar.setTime(DateUtil.convertString2Date(date, "yyyy-MM-dd HH:mm"));
    }
    DialogUtil.pickDateTime(webLoader.getPageControl().getActivity(), title1, title2, 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 chooseDate = DateUtil.convertDate(calendar.getTime(), "yyyy-MM-dd HH:mm");
            Map<String, Object> map = new HashMap<>();
            map.put("datetime", chooseDate);
            callback.applySuccess(map);
        }
    });
}
 
Example #26
Source File: MainActivity.java    From music_player with Open Software License 3.0 6 votes vote down vote up
private void sleeper() {
        final java.util.Calendar c = java.util.Calendar.getInstance();
        final int hourNow = c.get(java.util.Calendar.HOUR_OF_DAY);
        final int minuteNow = c.get(Calendar.MINUTE);
        final int secondNow = c.get(Calendar.SECOND);
        new TimePickerDialog(MainActivity.this, new TimePickerDialog.OnTimeSetListener() {
            @Override
            public void onTimeSet(TimePicker view, int hourPicked, int minutePicked) {
                int duration = (hourPicked - hourNow) * 3600 + (minutePicked - minuteNow)*60+(60-secondNow);
                if (hourPicked >= hourNow && duration > 0 && duration < 21600) {
                    EventBus.getDefault().post(new ServiceEvent(MyConstant.deleteAction,duration));
//                    playService.deleteService(duration);
                    Toast.makeText(MainActivity.this, "已经定时为" + (duration/60) + "分钟后关闭", Toast.LENGTH_SHORT).show();
//                    Snackbar.make(mLayout, "已经定时为" + duration + "分钟后关闭", Snackbar.LENGTH_LONG).show();
                } else {
                    Toast.makeText(MainActivity.this, "所选时间须为当天,且距当前时间6小时内", Toast.LENGTH_SHORT).show();
//                    Snackbar.make(mLayout, "所选时间须为当天,且距当前时间6小时内", Snackbar.LENGTH_SHORT).show();
                }
            }
        }, hourNow, minuteNow, true).show();
    }
 
Example #27
Source File: ChecklistNoteActivity.java    From privacy-friendly-notes with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
    this.dayOfMonth = dayOfMonth;
    this.monthOfYear = monthOfYear;
    this.year = year;
    final Calendar c = Calendar.getInstance();
    if (hasAlarm) {
        c.setTimeInMillis(notificationCursor.getLong(notificationCursor.getColumnIndexOrThrow(DbContract.NotificationEntry.COLUMN_TIME)));
    }
    TimePickerDialog tpd = new TimePickerDialog(ChecklistNoteActivity.this, this, c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), true);
    tpd.show();
}
 
Example #28
Source File: InputHandlers.java    From Android-Shortify with Apache License 2.0 5 votes vote down vote up
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    // Use the current time as the default values for the picker
    final Calendar c = Calendar.getInstance();
    int hour = c.get(Calendar.HOUR_OF_DAY);
    int minute = c.get(Calendar.MINUTE);

    // Create a new instance of TimePickerDialog and return it
    return new TimePickerDialog(getActivity(), this, hour, minute,
            DateFormat.is24HourFormat(getActivity()));
}
 
Example #29
Source File: AudioNoteActivity.java    From privacy-friendly-notes with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
    this.dayOfMonth = dayOfMonth;
    this.monthOfYear = monthOfYear;
    this.year = year;
    final Calendar c = Calendar.getInstance();
    if (hasAlarm) {
        c.setTimeInMillis(notificationCursor.getLong(notificationCursor.getColumnIndexOrThrow(DbContract.NotificationEntry.COLUMN_TIME)));
    }
    TimePickerDialog tpd = new TimePickerDialog(AudioNoteActivity.this, this, c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), true);
    tpd.show();
}
 
Example #30
Source File: DateTimePicker.java    From framework with GNU Affero General Public License v3.0 5 votes vote down vote up
public TimePicker(Context context, Calendar time) {

            final Calendar c = (time != null) ? time : Calendar.getInstance();
            int hour = c.get(Calendar.HOUR_OF_DAY);
            int minute = c.get(Calendar.MINUTE);
            mDialog = new TimePickerDialog(context, this, hour, minute, false);
            mDialog.setOnCancelListener(this);
        }