android.widget.DatePicker Java Examples

The following examples show how to use android.widget.DatePicker. 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: UI.java    From Android-Commons with Apache License 2.0 7 votes vote down vote up
/**
* Sets whether the year should be visible and selectable in the given `DatePicker` instance
*
* @param picker the `DatePicker` instance
* @param yearVisible whether the year should be visible or not
*/
  public static void setDatePickerYearVisible(final DatePicker picker, final boolean yearVisible) {
  	try {
   	final Field f[] = picker.getClass().getDeclaredFields();

   	for (Field field : f) {
    	if (field.getName().equals("mYearPicker") || field.getName().equals("mYearSpinner")) {
	    	field.setAccessible(true);
	    	Object yearPicker = new Object();
	    	yearPicker = field.get(picker);
	    	((View) yearPicker).setVisibility(yearVisible ? View.VISIBLE : View.GONE);
    	}
   	}
  	}
  	catch (Exception e) { }
  }
 
Example #2
Source File: MainActivity.java    From Android-Example with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);
	dp=(DatePicker)findViewById(R.id.DP1);
	bt=(Button)findViewById(R.id.button1);
	tv1=(TextView)findViewById(R.id.textView1);
	tv2=(TextView)findViewById(R.id.textView2);
	tv3=(TextView)findViewById(R.id.textView3);
	bt.setOnClickListener(new OnClickListener() 
	{
		
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			i1=dp.getDayOfMonth();
			s1=dp.getMonth();
			i2=dp.getYear();
			tv1.setText(String.valueOf(i1));
			tv2.setText(String.valueOf(s1));
			tv3.setText(String.valueOf(i2));
		}
	});

}
 
Example #3
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
 * 返回:
 * month: 格式:yyyy-MM
 */
public static void pickMonth(final 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)) {
        calendar.setTime(DateUtil.convertString2Date(date, "yyyy-MM"));
    }
    DialogUtil.pickMonth(webLoader.getPageControl().getActivity(), title, calendar, new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            calendar.set(Calendar.YEAR, year);
            calendar.set(Calendar.MONTH, monthOfYear);
            calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
            String chooseDate = DateUtil.convertDate(calendar.getTime(), "yyyy-MM");
            Map<String, Object> map = new HashMap<>();
            map.put("month", chooseDate);
            callback.applySuccess(map);
        }
    });
}
 
Example #4
Source File: StartNewSensor.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if(Sensor.isActive() == false) {
        setContentView(R.layout.activity_start_new_sensor);

        button = (Button)findViewById(R.id.startNewSensor);
        dp = (DatePicker)findViewById(R.id.datePicker);
        tp = (TimePicker)findViewById(R.id.timePicker);
        addListenerOnButton();


    } else {
        Intent intent = new Intent(this, StopSensor.class);
        startActivity(intent);
        finish();
    }
}
 
Example #5
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
 * 返回:
 * date: 格式:yyyy-MM-dd
 */
public static void pickDate(final IQuickFragment webLoader, WebView wv, JSONObject param, final Callback callback) {
    final String title = param.optString("title");
    String date = param.optString("datetime");
    final Calendar calendar = Calendar.getInstance();
    if (!TextUtils.isEmpty(date)) {
        calendar.setTime(DateUtil.convertString2Date(date, "yyyy-MM-dd"));
    }
    wv.post(new Runnable() {
        public void run() {
            DialogUtil.pickDate(webLoader.getPageControl().getActivity(), title, calendar, new DatePickerDialog.OnDateSetListener() {
                @Override
                public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                    calendar.set(Calendar.YEAR, year);
                    calendar.set(Calendar.MONTH, monthOfYear);
                    calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                    String chooseDate = DateUtil.convertDate(calendar.getTime(), "yyyy-MM-dd");
                    Map<String, Object> map = new HashMap<>();
                    map.put("date", chooseDate);
                    callback.applySuccess(map);
                }
            });
        }
    });
}
 
Example #6
Source File: EditMovieFragment.java    From Mizuu with Apache License 2.0 6 votes vote down vote up
private void showDatePickerDialog(String initialValue) {
    String[] dateArray = initialValue.split("-");
    Calendar cal = Calendar.getInstance();
    cal.set(Integer.parseInt(dateArray[0]), Integer.parseInt(dateArray[1]) - 1, Integer.parseInt(dateArray[2]));
    DatePickerDialog dialog = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            // Update the date
            mMovie.setReleaseDate(year, monthOfYear + 1, dayOfMonth);

            // Update the UI with the new value
            setupValues(false);
        }
    }, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH));
    dialog.show();
}
 
Example #7
Source File: CreditCardExpirationDatePickerView.java    From android-AutofillFramework with Apache License 2.0 6 votes vote down vote up
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    DatePickerDialog dialog = new DatePickerDialog(getActivity(),
            R.style.CustomDatePickerDialogTheme, this, mParent.mYear, mParent.mMonth, 1);

    DatePicker datePicker = dialog.getDatePicker();

    // Limit range.
    Calendar c = mParent.getCalendar();
    datePicker.setMinDate(c.getTimeInMillis());
    c.set(Calendar.YEAR, mParent.mYear + CC_EXP_YEARS_COUNT - 1);
    datePicker.setMaxDate(c.getTimeInMillis());

    // Remove day.
    datePicker.findViewById(getResources().getIdentifier("day", "id", "android"))
            .setVisibility(View.GONE);
    return dialog;
}
 
Example #8
Source File: BuilderDate.java    From SmsScheduler with GNU General Public License v2.0 6 votes vote down vote up
@Override
public DatePicker build() {
    getView().init(
        sms.getCalendar().get(GregorianCalendar.YEAR),
        sms.getCalendar().get(GregorianCalendar.MONTH),
        sms.getCalendar().get(GregorianCalendar.DAY_OF_MONTH),
        new DatePicker.OnDateChangedListener() {
            @Override
            public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                sms.getCalendar().set(GregorianCalendar.YEAR, year);
                sms.getCalendar().set(GregorianCalendar.MONTH, monthOfYear);
                sms.getCalendar().set(GregorianCalendar.DAY_OF_MONTH, dayOfMonth);
            }
        }
    );
    return getView();
}
 
Example #9
Source File: TravelTimePicker.java    From msdkui-android with Apache License 2.0 6 votes vote down vote up
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity())
            .setNegativeButton(R.string.msdkui_cancel, null)
            .setPositiveButton(R.string.msdkui_ok, null);

    final View view = View.inflate(getActivity(), R.layout.travel_time_picker, null);
    dialogBuilder.setView(view);

    mTabLayout = (TabLayout) view.findViewById(R.id.picker_tab);
    mDatePicker = (DatePicker) view.findViewById(R.id.travel_date);
    mTimePicker = (TimePicker) view.findViewById(R.id.travel_time);
    mTimePicker.setIs24HourView(DateFormat.is24HourFormat(getActivity()));

    updateDefaultValues();
    updateTab(savedInstanceState);
    updateDatePicker(savedInstanceState);
    updateTimePicker(savedInstanceState);
    updateVisibility(savedInstanceState);

    final Dialog dialog = dialogBuilder.create();
    dialog.setOnShowListener(mOnShowListener);
    return dialog;
}
 
Example #10
Source File: SearchInvoiceTabFrg.java    From Android-POS with MIT License 6 votes vote down vote up
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {

    int fromDTemp = Integer.parseInt(fromDate);//yearMonthDay
    int toDTemp = Integer.parseInt(String.valueOf(year)+String.valueOf(month)+String.valueOf(dayOfMonth));//yearMonthDay


    if (fromDTemp <= toDTemp){
        toDate = year+month+dayOfMonth+"";
        binding.toDateInBtn.setText(dayOfMonth+"."+month+"."+year);

    }else {
        Toast.makeText(getActivity(),"From date can,t be lower then to date",Toast.LENGTH_SHORT).show();
        binding.toDateInBtn.setText("Select to");
        toDate = "0";
    }

    if (!toDate.equals("0") && !fromDate.equals("0")){
        validDate =true;
    }else validDate = false;

}
 
Example #11
Source File: Setter.java    From AndroidRipper with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Sets the date in a given {@link DatePicker}.
 *
 * @param datePicker the {@code DatePicker} object.
 * @param year the year e.g. 2011
 * @param monthOfYear the month which is starting from zero e.g. 03
 * @param dayOfMonth the day e.g. 10
 */

public void setDatePicker(final DatePicker datePicker, final int year, final int monthOfYear, final int dayOfMonth) {
	if(datePicker != null){
		Activity activity = activityUtils.getCurrentActivity(false);
		if(activity != null){
			activity.runOnUiThread(new Runnable()
			{
				public void run()
				{
					try{
						datePicker.updateDate(year, monthOfYear, dayOfMonth);
					}catch (Exception ignored){}
				}
			});
		}
	}
}
 
Example #12
Source File: AddSmsActivity.java    From SmsScheduler with GNU General Public License v2.0 6 votes vote down vote up
private void buildForm() {
    EditText formMessage = findViewById(R.id.form_input_message);
    AutoCompleteTextView formContact = findViewById(R.id.form_input_contact);
    TextWatcher watcherEmptiness = new EmptinessTextWatcher(this, formContact, formMessage);
    formContact.addTextChangedListener(watcherEmptiness);
    formMessage.addTextChangedListener(watcherEmptiness);

    new BuilderMessage().setView(formMessage).setSms(sms).build();
    new BuilderContact().setView(formContact).setSms(sms).setActivity(this).build();

    new BuilderSimCard().setActivity(this).setView(findViewById(R.id.form_sim_card)).setSms(sms).build();
    new BuilderRecurringMode()
        .setRecurringDayView((Spinner) findViewById(R.id.form_recurring_day))
        .setRecurringMonthView((Spinner) findViewById(R.id.form_recurring_month))
        .setDateView((DatePicker) findViewById(R.id.form_date))
        .setActivity(this)
        .setView(findViewById(R.id.form_recurring_mode))
        .setSms(sms)
        .build()
    ;

    new BuilderTime().setActivity(this).setView(findViewById(R.id.form_time)).setSms(sms).build();
    new BuilderDate().setActivity(this).setView(findViewById(R.id.form_date)).setSms(sms).build();

    new BuilderCancel().setView(findViewById(R.id.button_cancel)).setSms(sms).build();
}
 
Example #13
Source File: HistoryDetailActivity.java    From ActivityDiary with GNU General Public License v3.0 6 votes vote down vote up
public void showStartDatePickerDialog(View v) {
    DatePickerFragment newFragment = new DatePickerFragment();
    newFragment.setData(new DatePickerDialog.OnDateSetListener (){
                            @Override
                            public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
                                start.set(Calendar.YEAR, year);
                                start.set(Calendar.MONTH, month);
                                start.set(Calendar.DAY_OF_MONTH, dayOfMonth);

                                Long newStart = Long.valueOf(start.getTimeInMillis());
                                updateValues.put(ActivityDiaryContract.Diary.START, newStart);
                                updateDateTimes();
                            }
                        }
            , start.get(Calendar.YEAR), start.get(Calendar.MONTH), start.get(Calendar.DAY_OF_MONTH));
    newFragment.show(getSupportFragmentManager(), "startDatePicker");
}
 
Example #14
Source File: DateTimePickDialogUtil.java    From VideoMeeting with Apache License 2.0 6 votes vote down vote up
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 #15
Source File: NewEventActivity.java    From RoomBookerMVP with MIT License 6 votes vote down vote up
private void displayDatePicker(final EditText destination) {
    DatePickerFragment datePickerFragment = new DatePickerFragment();
    datePickerFragment.setOnDateSetListener(new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            Calendar calendar = Calendar.getInstance();
            calendar.set(year, monthOfYear, dayOfMonth);
            String displayDate = simpleDateFormat.format(calendar.getTime());
            destination.setText(displayDate);
            switch (destination.getId()) {
                case R.id.ane_start_date:
                    newEventPresenter.setStartDate(year, monthOfYear, dayOfMonth);
                    break;
                case R.id.ane_end_date:
                    newEventPresenter.setEndDate(year, monthOfYear, dayOfMonth);
                    break;
            }
        }
    });
    datePickerFragment.show(getSupportFragmentManager(), DatePickerFragment.TAG);
}
 
Example #16
Source File: FormAdapter.java    From SSForms with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
    mCalendarCurrentDate.set(Calendar.YEAR, year);
    mCalendarCurrentDate.set(Calendar.MONTH, monthOfYear);
    mCalendarCurrentDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);

    String myFormatDate = "dd/MM/yy"; // custom format
    SimpleDateFormat sdfDate = new SimpleDateFormat(myFormatDate, Locale.US);

    // 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());
        clickedPosition = -1;

    }
}
 
Example #17
Source File: SelectDateFragment.java    From Expense-Tracker-App with MIT License 6 votes vote down vote up
private void showDateDialog(final int id) {
    final Calendar calendar = Calendar.getInstance();
    calendar.setTime(id == R.id.btn_date_from ? DateManager.getInstance().getDateFrom() : DateManager.getInstance().getDateTo());
    DialogManager.getInstance()
            .showDatePicker(
                    getContext(),
                    new DatePickerDialog.OnDateSetListener() {
                        @Override
                        public void onDateSet(DatePicker datePicker, int year, int month, int day) {
                            calendar.set(year, month, day);
                            DateUtils.setDateStartOfDay(calendar);
                            if (id == R.id.btn_date_from) {
                                DateManager.getInstance().setDateFrom(calendar.getTime());
                                updateDate(btnDateFrom, DateManager.getInstance().getDateFrom());
                            } else {
                                DateManager.getInstance().setDateTo(calendar.getTime());
                                updateDate(btnDateTo, DateManager.getInstance().getDateTo());
                            }
                            iSelectDateFragment.updateData();
                        }
                    },
                    calendar,
                    (R.id.btn_date_from == id) ? null : DateManager.getInstance().getDateFrom(),
                    (R.id.btn_date_from == id) ? DateManager.getInstance().getDateTo() : null);
}
 
Example #18
Source File: BasicActivity.java    From DynamicCalendar with Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(View v) {
    mCurrentDate = Calendar.getInstance();
    int mYear = mCurrentDate.get(Calendar.YEAR);
    int mMonth = mCurrentDate.get(Calendar.MONTH);
    int mDay = mCurrentDate.get(Calendar.DAY_OF_MONTH);

    DatePickerDialog mDatePicker = new DatePickerDialog(BasicActivity.this, new DatePickerDialog.OnDateSetListener() {
        public void onDateSet(DatePicker datepicker, int selectedYear, int selectedMonth, int selectedDay) {
            // Update the editText to display the selected date
            mDateEditText.setText(selectedDay + "-" + (selectedMonth + 1) + "-" + selectedYear);

            // Set the mCurrentDate to the selected date-month-year
            mCurrentDate.set(selectedYear, selectedMonth, selectedDay);
            mGeneratedDateIcon = mImageGenerator.generateDateImage(mCurrentDate, R.drawable.empty_calendar);
            mDisplayGeneratedImage.setImageBitmap(mGeneratedDateIcon);

        }
    }, mYear, mMonth, mDay);
    mDatePicker.show();
}
 
Example #19
Source File: DateTableView.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void showCustomCalendar() {
    DatePickerUtils.getDatePickerDialog(getContext(), label, date, allowFutureDates,
            new DatePickerUtils.OnDatePickerClickListener() {
                @Override
                public void onNegativeClick() {
                    editText.setText(null);
                    listener.onDateSelected(null);
                }

                @Override
                public void onPositiveClick(DatePicker datePicker) {
                    selectedCalendar.set(Calendar.YEAR, datePicker.getYear());
                    selectedCalendar.set(Calendar.MONTH, datePicker.getMonth());
                    selectedCalendar.set(Calendar.DAY_OF_MONTH, datePicker.getDayOfMonth());
                    selectedCalendar.set(Calendar.HOUR_OF_DAY, 0);
                    selectedCalendar.set(Calendar.MINUTE, 0);
                    Date selectedDate = selectedCalendar.getTime();
                    String result = DateUtils.uiDateFormat().format(selectedDate);
                    editText.setText(result);
                    listener.onDateSelected(selectedDate);
                    nextFocus(DateTableView.this);
                }
            }).show();
}
 
Example #20
Source File: CreateNewUserActivity.java    From platform-friends-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void displayDatePicker() {
    final Calendar myCalendar = Calendar.getInstance();

    DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear,
                              int dayOfMonth) {
            myCalendar.set(Calendar.YEAR, year);
            myCalendar.set(Calendar.MONTH, monthOfYear);
            myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
            updateLabel();
        }

        private void updateLabel() {

            DateFormat dateFormat = getDateFormat();

            birthDay.setText(dateFormat.format(myCalendar.getTime()));
        }
    };

    new DatePickerDialog(CreateNewUserActivity.this, date, myCalendar
            .get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
            myCalendar.get(Calendar.DAY_OF_MONTH)).show();
}
 
Example #21
Source File: SettingInfoActivity.java    From WifiChat with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void initViews() {

    mIvAvater = (ImageView) findViewById(R.id.setting_my_avater_img);
    mEtNickname = (EditText) findViewById(R.id.setting_my_nickname);
    mRgGender = (RadioGroup) findViewById(R.id.setting_baseinfo_rg_gender);
    mHtvConstellation = (TextView) findViewById(R.id.setting_birthday_htv_constellation);
    mHtvAge = (TextView) findViewById(R.id.setting_birthday_htv_age);
    mDpBirthday = (DatePicker) findViewById(R.id.setting_birthday_dp_birthday);

    mRbBoy = (RadioButton) findViewById(R.id.setting_baseinfo_rb_male);
    mRbGirl = (RadioButton) findViewById(R.id.setting_baseinfo_rb_female);

    mBtnBack = (Button) findViewById(R.id.setting_btn_back);
    mBtnNext = (Button) findViewById(R.id.setting_btn_next);

}
 
Example #22
Source File: FormAdapter.java    From SSForms with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
    mCalendarCurrentDate.set(Calendar.YEAR, year);
    mCalendarCurrentDate.set(Calendar.MONTH, monthOfYear);
    mCalendarCurrentDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);

    String myFormatDate = "dd/MM/yy"; // custom format
    SimpleDateFormat sdfDate = new SimpleDateFormat(myFormatDate, Locale.US);

    // 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 #23
Source File: OCM_ChildMenu.java    From GLEXP-Team-onebillion with Apache License 2.0 5 votes vote down vote up
void showPickDateDialog (final DatePickerDialog.OnDateSetListener listener, Date startDate)
{
    Calendar currentCalendar = Calendar.getInstance();
    if (startDate != null)
    {
        currentCalendar.setTime(startDate);
    }
    final Calendar calendar = currentCalendar;
    DatePickerDialog d = new DatePickerDialog(MainActivity.mainActivity, listener, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
    //
    d.setCancelable(false);
    d.setCanceledOnTouchOutside(false);
    //
    LinearLayout linearLayout = new LinearLayout(MainActivity.mainActivity.getApplicationContext());
    d.requestWindowFeature(Window.FEATURE_NO_TITLE);
    d.getWindow().clearFlags(Window.FEATURE_ACTION_BAR);
    d.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    d.setCustomTitle(linearLayout);
    //
    d.setButton(DatePickerDialog.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener()
    {
        @Override
        public void onClick (DialogInterface dialog, int which)
        {
            // do nothing
        }
    });
    //
    DatePicker datePicker = d.getDatePicker();
    calendar.clear();
    calendar.set(2017, Calendar.JANUARY, 1);
    datePicker.setMinDate(calendar.getTimeInMillis());
    calendar.clear();
    calendar.set(2025, Calendar.DECEMBER, 31);
    datePicker.setMaxDate(calendar.getTimeInMillis());
    //
    d.show();
}
 
Example #24
Source File: DatePickerFragment.java    From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
    OrderActivity activity = (OrderActivity) getActivity();
    if (activity != null) {
        activity.processDatePickerResult(year, month, dayOfMonth);
    }
}
 
Example #25
Source File: DateTimePickerDialog.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void onDateChanged(DatePicker view, int year,
        int month, int day) {
    // Signal a time change so the max/min checks can be applied.
    if (mTimePicker != null) {
        onTimeChanged(mTimePicker, mTimePicker.getCurrentHour(),
                mTimePicker.getCurrentMinute());
    }
}
 
Example #26
Source File: DateMeasurementView.java    From openScale with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected boolean validateAndSetInput(View view) {
    DatePicker datePicker = (DatePicker) view;

    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth());
    setValue(cal.getTime(), true);

    return true;
}
 
Example #27
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 #28
Source File: DateFilterActivity.java    From financisto with GNU General Public License v2.0 5 votes vote down vote up
private void setDialogResult(Dialog d, Calendar c) {
	DatePicker dp = d.findViewById(R.id.date);
	c.set(Calendar.YEAR, dp.getYear());
	c.set(Calendar.MONTH, dp.getMonth());
	c.set(Calendar.DAY_OF_MONTH, dp.getDayOfMonth());
	TimePicker tp = d.findViewById(R.id.time);
	c.set(Calendar.HOUR_OF_DAY, tp.getCurrentHour());
	c.set(Calendar.MINUTE, tp.getCurrentMinute());
	updateDate();
}
 
Example #29
Source File: DateWidgets1.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
public void onDateSet(DatePicker view, int year, int monthOfYear,
        int dayOfMonth) {
    mYear = year;
    mMonth = monthOfYear;
    mDay = dayOfMonth;
    updateDisplay();
}
 
Example #30
Source File: MainActivity.java    From three-things-today with Apache License 2.0 5 votes vote down vote up
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
    mSelectedYear = year;
    mSelectedMonth = month;
    mSelectedDayOfMonth = dayOfMonth;

    updateDateText();
    updateThreeThingsText();
}