Java Code Examples for android.widget.DatePicker#getDayOfMonth()
The following examples show how to use
android.widget.DatePicker#getDayOfMonth() .
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: DateDialogNormalizer.java From android-chromium with BSD 2-Clause "Simplified" License | 6 votes |
private static void setLimits(DatePicker picker, long min, long max) { // DatePicker intervals are non inclusive, the DatePicker will throw an // exception when setting the min/max attribute to the current date // so make sure this never happens if (max <= min) { return; } Calendar minCal = trimToDate(min); Calendar maxCal = trimToDate(max); int currentYear = picker.getYear(); int currentMonth = picker.getMonth(); int currentDayOfMonth = picker.getDayOfMonth(); picker.updateDate(maxCal.get(Calendar.YEAR), maxCal.get(Calendar.MONTH), maxCal.get(Calendar.DAY_OF_MONTH)); picker.setMinDate(minCal.getTimeInMillis()); picker.updateDate(minCal.get(Calendar.YEAR), minCal.get(Calendar.MONTH), minCal.get(Calendar.DAY_OF_MONTH)); picker.setMaxDate(maxCal.getTimeInMillis()); // Restore the current date, this will keep the min/max settings // previously set into account. picker.updateDate(currentYear, currentMonth, currentDayOfMonth); }
Example 2
Source File: DateDialogNormalizer.java From android-chromium with BSD 2-Clause "Simplified" License | 6 votes |
private static void setLimits(DatePicker picker, long min, long max) { // DatePicker intervals are non inclusive, the DatePicker will throw an // exception when setting the min/max attribute to the current date // so make sure this never happens if (max <= min) { return; } Calendar minCal = trimToDate(min); Calendar maxCal = trimToDate(max); int currentYear = picker.getYear(); int currentMonth = picker.getMonth(); int currentDayOfMonth = picker.getDayOfMonth(); picker.updateDate(maxCal.get(Calendar.YEAR), maxCal.get(Calendar.MONTH), maxCal.get(Calendar.DAY_OF_MONTH)); picker.setMinDate(minCal.getTimeInMillis()); picker.updateDate(minCal.get(Calendar.YEAR), minCal.get(Calendar.MONTH), minCal.get(Calendar.DAY_OF_MONTH)); picker.setMaxDate(maxCal.getTimeInMillis()); // Restore the current date, this will keep the min/max settings // previously set into account. picker.updateDate(currentYear, currentMonth, currentDayOfMonth); }
Example 3
Source File: SignupFragment.java From Android with MIT License | 5 votes |
public void onDateSet(DatePicker view, int year, int month, int day) { Date_of_Birth.setText(view.getDayOfMonth() + " / " + (view.getMonth() + 1) + " / " + view.getYear()); age = view.getDayOfMonth() + " / " + (view.getMonth() + 1) + " / " + view.getYear(); age_year = view.getYear(); if (age_year <= 2002) { Date_of_Birth.setTextColor(Color.BLACK); animation_view_birth_signup.setAnimation(R.raw.success); animation_view_birth_signup.playAnimation(); } else { Date_of_Birth.setTextColor(Color.RED); animation_view_birth_signup.setProgress(0); } }
Example 4
Source File: EditProfile_Fragment.java From Android with MIT License | 4 votes |
public void onDateSet(DatePicker view, int year, int month, int day) { Date_of_Birth.setText(view.getDayOfMonth() + " / " + (view.getMonth() + 1) + " / " + view.getYear()); age = view.getDayOfMonth() + " / " + (view.getMonth() + 1) + " / " + view.getYear(); animation_view_birth.setAnimation(R.raw.success); animation_view_birth.playAnimation(); }
Example 5
Source File: ProfileActivity.java From medical-data-android with GNU General Public License v3.0 | 4 votes |
/** * To update the user's personal information. It checks that that the PIN is correct and, in * that case, saves the data in the database and the app and finishes. A {@link Toast} message * is used to inform the user if the data has been successfully updated or there has been any * problem while connecting with the database. * * @param view the clicked {@link View}. * @see #finish() * @see TextView#setError(CharSequence) * @see EditText#setError(CharSequence) */ public void btnFinish(View view) { boolean error = false; // check name correction EditText name = (EditText) findViewById(R.id.name_answer); String name_text = name.getText().toString(); if (name_text.equals("")) { name.setError(getString(R.string.name_blank)); focusFirstError(name, R.id.name); error = true; } // check email correction EditText email = (EditText) findViewById(R.id.email_answer); String email_text = email.getText().toString(); if (email_text.equals("")) { email.setError(getString(R.string.email_blank)); if (!error) { focusFirstError(email, R.id.email); error = true; } } else if (!email_text.matches(Variables.emailPattern)) { email.setError(getString(R.string.email_format)); if (!error) { focusFirstError(email, R.id.email); error = true; } } // check PIN correction EditText pin = (EditText) findViewById(R.id.pin_answer); String pin_text = pin.getText().toString(); int pin_number = settings.getInt("pin", -1); String original_pin = String.valueOf(pin_number); if (!pin_text.equals(original_pin)) { pin.setError(getString(R.string.incorrect_pin)); if (!error) { focusFirstError(pin, R.id.pin); error = true; } } // ¿Everything correct? if (!error) { String user_id = settings.getString("user_id", ""); DatePicker birthDate = (DatePicker) findViewById(R.id.age_answer); // gender = false => male, gender = true => female RadioGroup radioGroup = (RadioGroup) findViewById(R.id.gender_answer); boolean gender = radioGroup.getCheckedRadioButtonId() == R.id.radio_female; User user = new User( email_text, name_text, pin_number, birthDate.getDayOfMonth(), birthDate.getMonth(), birthDate.getYear(), gender, user_id); //Save changes in the server database try { UpdateRegistration runner = new UpdateRegistration(); runner.execute(user); int option = runner.get(); if (option == 0) { // Save register in the app user.save(this); // Feedback: update profile has been completed Toast.makeText(this, R.string.changes_saved, Toast.LENGTH_LONG).show(); } else if (option == 1) { Toast.makeText(this, R.string.repeated_email2, Toast.LENGTH_LONG).show(); } else { Toast.makeText(this, R.string.update_error, Toast.LENGTH_LONG).show(); } } catch (Exception e) { Toast.makeText(this, R.string.update_error, Toast.LENGTH_LONG).show(); } Variables.hideKeyboard(this); finish(); } }
Example 6
Source File: DateTimeWidget.java From commcare-android with Apache License 2.0 | 4 votes |
public DateTimeWidget(Context context, FormEntryPrompt prompt) { super(context, prompt); mDatePicker = new DatePicker(getContext()); mDatePicker.setFocusable(!prompt.isReadOnly()); mDatePicker.setEnabled(!prompt.isReadOnly()); mTimePicker = new TimePicker(getContext()); mTimePicker.setFocusable(!prompt.isReadOnly()); mTimePicker.setEnabled(!prompt.isReadOnly()); mTimePicker.setPadding(0, 20, 0, 0); mTimePicker.setOnTimeChangedListener(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { mTimePicker.setSaveFromParentEnabled(false); mTimePicker.setSaveEnabled(true); } String clockType = android.provider.Settings.System.getString(context.getContentResolver(), android.provider.Settings.System.TIME_12_24); if (clockType == null || clockType.equalsIgnoreCase("24")) { mTimePicker.setIs24HourView(true); } mDateListener = (view, year, month, day) -> { if (mPrompt.isReadOnly()) { setAnswer(); } else { // handle leap years and number of days in month // TODO // http://code.google.com/p/android/issues/detail?id=2081 Calendar c = Calendar.getInstance(); c.set(year, month, 1); int max = c.getActualMaximum(Calendar.DAY_OF_MONTH); if (day > max) { //If the day has fallen out of spec, set it to the correct max mDatePicker.updateDate(year, month, max); } else { if (!(mDatePicker.getDayOfMonth() == day && mDatePicker.getMonth() == month && mDatePicker.getYear() == year)) { //CTS: No reason to change the day if it's already correct? mDatePicker.updateDate(year, month, day); } } } widgetEntryChanged(); }; // If there's an answer, use it. setAnswer(); setGravity(Gravity.LEFT); addView(mDatePicker); addView(mTimePicker); }