List of usage examples for android.widget DatePicker getDayOfMonth
public int getDayOfMonth()
From source file:Main.java
public static java.util.Date getDateFromDatePicker(DatePicker datePicker) { int day = datePicker.getDayOfMonth(); int month = datePicker.getMonth(); int year = datePicker.getYear(); Calendar calendar = Calendar.getInstance(); calendar.set(year, month, day);/* w w w . j av a 2 s .c o m*/ return calendar.getTime(); }
From source file:Main.java
/** * @param datePicker//ww w .j a v a 2 s .co m * @return date with the hours/minutes/seconds/milliseconds stripped off */ public static long getDate(DatePicker datePicker) { return getDate(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth()); }
From source file:com.facebook.appevents.codeless.internal.ViewHierarchy.java
public static String getTextOfView(View view) { Object textObj = null;/* w w w . j av a2s . c o m*/ if (view instanceof TextView) { textObj = ((TextView) view).getText(); if (view instanceof Switch) { boolean isOn = ((Switch) view).isChecked(); textObj = isOn ? "1" : "0"; } } else if (view instanceof Spinner) { Object selectedItem = ((Spinner) view).getSelectedItem(); if (selectedItem != null) { textObj = selectedItem.toString(); } } else if (view instanceof DatePicker) { DatePicker picker = (DatePicker) view; int y = picker.getYear(); int m = picker.getMonth(); int d = picker.getDayOfMonth(); textObj = String.format("%04d-%02d-%02d", y, m, d); } else if (view instanceof TimePicker) { TimePicker picker = (TimePicker) view; int h = picker.getCurrentHour(); int m = picker.getCurrentMinute(); textObj = String.format("%02d:%02d", h, m); } else if (view instanceof RadioGroup) { RadioGroup radioGroup = (RadioGroup) view; int checkedId = radioGroup.getCheckedRadioButtonId(); int childCount = radioGroup.getChildCount(); for (int i = 0; i < childCount; i++) { View child = radioGroup.getChildAt(i); if (child.getId() == checkedId && child instanceof RadioButton) { textObj = ((RadioButton) child).getText(); break; } } } else if (view instanceof RatingBar) { RatingBar bar = (RatingBar) view; float rating = bar.getRating(); textObj = String.valueOf(rating); } return textObj == null ? "" : textObj.toString(); }
From source file:org.akop.crosswords.fragment.DatePickerFragment.java
private void notifyListener(DatePicker picker) { int year = picker.getYear(); int month = picker.getMonth() + 1; int day = picker.getDayOfMonth(); Activity activity = getActivity();/*from ww w . j a va2 s . c o m*/ if (activity instanceof OnDateSelectedListener) { OnDateSelectedListener listener = (OnDateSelectedListener) activity; listener.onDateSelected(new DateTime(year, month, day, 0, 0, 0)); } }
From source file:com.itcorea.coreonwallet.DatePickerDialogFragment.java
@TargetApi(11) @Override//from w w w . j av a2s.co m public Dialog onCreateDialog(Bundle savedInstanceState) { Bundle b = getArguments(); int y = b.getInt(YEAR); int m = b.getInt(MONTH); int d = b.getInt(DATE); final DatePickerDialog picker = new DatePickerDialog(getActivity(), getConstructorListener(), y, m, d); if (hasJellyBeanAndAbove()) { picker.setButton(DialogInterface.BUTTON_POSITIVE, getActivity().getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { DatePicker dp = picker.getDatePicker(); mListener.onDateSet(dp, dp.getYear(), dp.getMonth(), dp.getDayOfMonth()); } }); picker.setButton(DialogInterface.BUTTON_NEGATIVE, getActivity().getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); } return picker; }
From source file:org.uab.deic.uabdroid.solutions.unit5.FormAppActivity.java
private void storeCurrentState() { SharedPreferences preferences = getPreferences(Context.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.putBoolean(STATE_NOT_SAVED, true); EditText editText = (EditText) findViewById(R.id.edittext_form_name); editor.putString(FORM_FIELD_NAME, editText.getText().toString()); editText = (EditText) findViewById(R.id.edittext_form_developer); editor.putString(FORM_FIELD_DEVELOPER, editText.getText().toString()); DatePicker datePicker = (DatePicker) findViewById(R.id.datepicker_form_date); editor.putInt(FORM_FIELD_DAY, datePicker.getDayOfMonth()); editor.putInt(FORM_FIELD_MONTH, datePicker.getMonth()); editor.putInt(FORM_FIELD_YEAR, datePicker.getYear()); editText = (EditText) findViewById(R.id.edittext_form_url); editor.putString(FORM_FIELD_URL, editText.getText().toString()); editor.commit();//from w w w. ja va 2 s . c o m }
From source file:at.jclehner.rxdroid.DatePickerFragment.java
@Override public void onShow(DialogInterface dialogInterface) { if (Version.SDK_IS_JELLYBEAN_OR_NEWER) { final DatePickerDialog dialog = (DatePickerDialog) dialogInterface; dialog.getButton(Dialog.BUTTON_POSITIVE).setOnClickListener(new OnClickListener() { @TargetApi(11)/* ww w . j av a 2 s. co m*/ @Override public void onClick(View v) { final DatePicker picker = dialog.getDatePicker(); mListener.onDateSet(picker, picker.getYear(), picker.getMonth(), picker.getDayOfMonth()); dialog.dismiss(); } }); } }
From source file:org.uab.deic.uabdroid.solutions.unit3.FormAppActivity.java
private void storeCurrentState() { // As the fragment is loaded dynamically, we souldn't suppose that it's going to be // the FormFragment. In this case where we don't have any other, we could avoid // the conditional, but it's a good practice either way EditText editText = (EditText) findViewById(R.id.edittext_form_name); if (editText != null) { // Obtain a reference to the preferences SharedPreferences preferences = getPreferences(Context.MODE_PRIVATE); // And then a reference to the editor to store the preferences SharedPreferences.Editor editor = preferences.edit(); // Make clear that the state of the form is not saved editor.putBoolean(STATE_NOT_SAVED, true); // Store the values of the form editor.putString(FORM_FIELD_NAME, editText.getText().toString()); editText = (EditText) findViewById(R.id.edittext_form_developer); editor.putString(FORM_FIELD_DEVELOPER, editText.getText().toString()); DatePicker datePicker = (DatePicker) findViewById(R.id.datepicker_form_date); editor.putInt(FORM_FIELD_DAY, datePicker.getDayOfMonth()); editor.putInt(FORM_FIELD_MONTH, datePicker.getMonth()); editor.putInt(FORM_FIELD_YEAR, datePicker.getYear()); editText = (EditText) findViewById(R.id.edittext_form_url); editor.putString(FORM_FIELD_URL, editText.getText().toString()); // In order to really store the values, we must perform a commit() operation editor.commit();//from ww w .j a v a 2s .c o m } }
From source file:com.example.reminder.alarm.DatePickerFragment.java
@TargetApi(11) @Override/*w ww .j a va 2 s . c o m*/ public Dialog onCreateDialog(Bundle savedInstanceState) { Bundle b = getArguments(); int y = b.getInt(YEAR); int m = b.getInt(MONTH); int d = b.getInt(DATE); // Jelly Bean introduced a bug in DatePickerDialog (and possibly // TimePickerDialog as well), and one of the possible solutions is // to postpone the creation of both the listener and the BUTTON_* . // // Passing a null here won't harm because DatePickerDialog checks for a null // whenever it reads the listener that was passed here. >>> This seems to be // true down to 1.5 / API 3, up to 4.1.1 / API 16. <<< No worries. For now. // // See my own question and answer, and details I included for the issue: // // http://stackoverflow.com/a/11493752/489607 // http://code.google.com/p/android/issues/detail?id=34833 // // Of course, suggestions welcome. final DatePickerDialog picker = new DatePickerDialog(getActivity(), getConstructorListener(), y, m, d); if (hasJellyBeanAndAbove()) { picker.setButton(DialogInterface.BUTTON_POSITIVE, getActivity().getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { DatePicker dp = picker.getDatePicker(); mListener.onDateSet(dp, dp.getYear(), dp.getMonth(), dp.getDayOfMonth()); } }); picker.setButton(DialogInterface.BUTTON_NEGATIVE, getActivity().getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); } return picker; }
From source file:net.davidcesarino.android.common.ui.DatePickerDialogFragment.java
@TargetApi(11) @Override/*from w ww .j a va2 s. co m*/ public Dialog onCreateDialog(Bundle savedInstanceState) { Bundle b = getArguments(); int y = b.getInt(YEAR); int m = b.getInt(MONTH); int d = b.getInt(DATE); // Jelly Bean introduced a bug in DatePickerDialog (and possibly // TimePickerDialog as well), and one of the possible solutions is // to postpone the creation of both the listener and the BUTTON_* . // // Passing a null here won't harm because DatePickerDialog checks for a null // whenever it reads the listener that was passed here. >>> This seems to be // true down to 1.5 / API 3, up to 4.1.1 / API 16. <<< No worries. For now. // // See my own question and answer, and details I included for the issue: // // http://stackoverflow.com/a/11493752/489607 // http://code.google.com/p/android/issues/detail?id=34833 // // Of course, suggestions welcome. final DatePickerDialog picker = new DatePickerDialog(getActivity(), getConstructorListener(), y, m, d); if (isAffectedVersion()) { picker.setButton(DialogInterface.BUTTON_POSITIVE, getActivity().getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { DatePicker dp = picker.getDatePicker(); mListener.onDateSet(dp, dp.getYear(), dp.getMonth(), dp.getDayOfMonth()); } }); picker.setButton(DialogInterface.BUTTON_NEGATIVE, getActivity().getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); } return picker; }