Example usage for android.widget DatePicker getMonth

List of usage examples for android.widget DatePicker getMonth

Introduction

In this page you can find the example usage for android.widget DatePicker getMonth.

Prototype

public int getMonth() 

Source Link

Usage

From source file:com.propelforwardmedia.app.DatePickerDialogFragment.java

@TargetApi(11)
@Override//from   w w w.  j  a va2  s.c  om
public Dialog onCreateDialog(Bundle savedInstanceState) {
    int year = mCalendar.get(Calendar.YEAR);
    int month = mCalendar.get(Calendar.MONTH);
    int day = mCalendar.get(Calendar.DAY_OF_MONTH);

    // 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(), year, month,
            day);

    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:com.app.afridge.ui.fragments.DatePickerDialogFragment.java

@TargetApi(11)
@Override//  w ww.ja va 2s.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:com.dycody.android.idealnote.utils.date.DatePickerDialogFragment.java

@NonNull
@Override/*from ww w  . j  a  v  a 2  s .  co  m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    // Use the current date as the default date in the picker
    Calendar cal = DateUtils.getCalendar(defaultDate);
    int y = cal.get(Calendar.YEAR);
    int m = cal.get(Calendar.MONTH);
    int d = cal.get(Calendar.DAY_OF_MONTH);

    // 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(), DatePickerDialog.THEME_HOLO_LIGHT,
            getConstructorListener(), y, m, d);
    picker.setTitle("");

    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();// w ww .jav a 2s .c o m
}

From source file:br.com.heitorcolangelo.mobilereport.DatePickerDialogFragment.java

@TargetApi(11)
@Override//w  w  w.  j  av a2  s .  co m
public Dialog onCreateDialog(Bundle savedInstanceState) {

    // 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(), year, month,
            day);

    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) {
                        // Quando cancela no retorna nenhuma data.
                        DatePicker dp = picker.getDatePicker();
                        mListener.onDateSet(dp, 0, 0, 0);
                    }
                });
    }
    return picker;
}

From source file:com.gatesnfc.existing.DatePicker_Fix.java

@TargetApi(11)
@Override/*w  w  w .  java  2s .  c  o  m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {

    // 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(), year, month,
            day);

    if (hasJellyBeanAndAbove()) {
        /*
         * Restriction of Date from 1980 Jan 1st to Current Date
         */
        Calendar c = Calendar.getInstance();
        picker.getDatePicker().setMaxDate(c.getTimeInMillis());
        c.set(Calendar.YEAR, 1980);
        c.set(Calendar.MONTH, c.getMinimum(Calendar.MONTH));
        c.set(Calendar.DATE, c.getMinimum(Calendar.DATE));
        c.set(Calendar.HOUR_OF_DAY, c.getMinimum(Calendar.HOUR_OF_DAY));
        c.set(Calendar.MINUTE, c.getMinimum(Calendar.MINUTE));
        c.set(Calendar.SECOND, c.getMinimum(Calendar.SECOND));
        c.set(Calendar.MILLISECOND, c.getMinimum(Calendar.MILLISECOND));
        picker.getDatePicker().setMinDate(c.getTimeInMillis());
        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.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();//www.ja  v a2s . c  o  m
    }
}

From source file:com.facebook.react.tests.DatePickerDialogTestCase.java

public void testPresetDate() {
    final WritableMap options = new WritableNativeMap();
    options.putDouble("date", getDateInMillis(2020, 5, 6));

    final DialogFragment datePickerFragment = showDialog(options);
    final DatePicker datePicker = ((DatePickerDialog) datePickerFragment.getDialog()).getDatePicker();

    assertEquals(2020, datePicker.getYear());
    assertEquals(5, datePicker.getMonth());
    assertEquals(6, datePicker.getDayOfMonth());
}

From source file:com.flowzr.activity.DateFilterActivity.java

private void setDialogResult(Dialog d, Calendar c) {
    DatePicker dp = (DatePicker) 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 = (TimePicker) d.findViewById(R.id.time);
    c.set(Calendar.HOUR_OF_DAY, tp.getCurrentHour());
    c.set(Calendar.MINUTE, tp.getCurrentMinute());
    updateDate();// www . j a  v  a2 s  .  c  o  m
}

From source file:at.florian_lentsch.expirysync.AddProductActivity.java

/**
 * Creates a {@link ProductEntry} from the form data
 * //  w  ww.  j  a v  a 2  s .  c  o  m
 * @param article
 *            the article associated with the entry
 * @return the requested {@link ProductEntry}
 */
private ProductEntry createProductEntryFromFormData(Article article) {
    final ProductEntry productEntry = new ProductEntry();
    productEntry.article = article;

    EditText amountField = ((EditText) findViewById(R.id.amount_field));
    String amountStr = amountField.getText().toString();
    if (amountStr.trim().equals("")) {
        amountStr = DEFAULT_AMOUNT;
    }
    productEntry.amount = Integer.parseInt(amountStr);
    productEntry.created_at = new DateTime();
    productEntry.updated_at = new DateTime();
    productEntry.description = ((EditText) findViewById(R.id.product_description_field)).getText().toString();

    DatePicker datePicker = (DatePicker) findViewById(R.id.expiration_date_field);
    productEntry.expiration_date = (new GregorianCalendar(datePicker.getYear(), datePicker.getMonth(),
            datePicker.getDayOfMonth())).getTime();
    productEntry.location = ProductListActivity.currentLocation;

    productEntry.inSync = false;

    return productEntry;
}