Example usage for android.widget DatePicker setCalendarViewShown

List of usage examples for android.widget DatePicker setCalendarViewShown

Introduction

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

Prototype

@Deprecated
public void setCalendarViewShown(boolean shown) 

Source Link

Document

Sets whether the CalendarView is shown.

Usage

From source file:com.cerema.cloud2.ui.dialog.ExpirationDatePickerDialogFragment.java

/**
 * {@inheritDoc}//  ww  w .  j a va 2 s  . co  m
 *
 * @return      A new dialog to let the user choose an expiration date that will be bound to a share link.
 */
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    // Load arguments
    mFile = getArguments().getParcelable(ARG_FILE);

    // Chosen date received as an argument must be later than tomorrow ; default to tomorrow in other case
    final Calendar chosenDate = Calendar.getInstance();
    long tomorrowInMillis = chosenDate.getTimeInMillis() + DateUtils.DAY_IN_MILLIS;
    long chosenDateInMillis = getArguments().getLong(ARG_CHOSEN_DATE_IN_MILLIS);
    if (chosenDateInMillis > tomorrowInMillis) {
        chosenDate.setTimeInMillis(chosenDateInMillis);
    } else {
        chosenDate.setTimeInMillis(tomorrowInMillis);
    }

    // Create a new instance of DatePickerDialog
    DatePickerDialog dialog = new DatePickerDialog(getActivity(), this, chosenDate.get(Calendar.YEAR),
            chosenDate.get(Calendar.MONTH), chosenDate.get(Calendar.DAY_OF_MONTH));

    // Prevent days in the past may be chosen
    DatePicker picker = dialog.getDatePicker();
    picker.setMinDate(tomorrowInMillis - 1000);

    // Enforce spinners view; ignored by MD-based theme in Android >=5, but calendar is REALLY buggy
    // in Android < 5, so let's be sure it never appears (in tablets both spinners and calendar are
    // shown by default)
    picker.setCalendarViewShown(false);

    return dialog;
}

From source file:me.tipi.kiosk.ui.fragments.IdentityFragment.java

/**
 * Style date picker./* w  ww  . ja va 2s. c o  m*/
 *
 * @param datePicker the date picker
 */
private void styleDatePicker(DatePicker datePicker) {
    datePicker.setCalendarViewShown(false);
    datePicker.setSpinnersShown(true);
    LinearLayout llFirst = (LinearLayout) datePicker.getChildAt(0);
    LinearLayout llSecond = (LinearLayout) llFirst.getChildAt(0);
    for (int i = 0; i < llSecond.getChildCount(); i++) {
        NumberPicker picker = (NumberPicker) llSecond.getChildAt(i); // NumberPickers in llSecond
        Field[] pickerFields = NumberPicker.class.getDeclaredFields();
        for (Field pf : pickerFields) {
            if (pf.getName().equals("mSelectionDivider")) {
                pf.setAccessible(true);
                try {
                    pf.set(picker, ContextCompat.getDrawable(getActivity(), R.drawable.picker_divider));
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (Resources.NotFoundException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
                break;
            }
        }
    }
}

From source file:com.owncloud.android.ui.dialog.ExpirationDatePickerDialogFragment.java

/**
 * {@inheritDoc}/*from   ww w.j  av a2  s  .  c  o m*/
 *
 * @return A new dialog to let the user choose an expiration date that will be bound to a share link.
 */
@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {

    // Chosen date received as an argument must be later than tomorrow ; default to tomorrow in other case
    final Calendar chosenDate = Calendar.getInstance();
    long tomorrowInMillis = chosenDate.getTimeInMillis() + DateUtils.DAY_IN_MILLIS;
    long chosenDateInMillis = getArguments().getLong(ARG_CHOSEN_DATE_IN_MILLIS);
    long maxDateInMillis = getArguments().getLong(ARG_MAX_DATE_IN_MILLIS);

    if (chosenDateInMillis < tomorrowInMillis) {
        chosenDateInMillis = tomorrowInMillis;
    }
    chosenDate.setTimeInMillis(chosenDateInMillis);

    // Create a new instance of DatePickerDialog
    DatePickerDialog dialog = new DatePickerDialog(getActivity(), this, chosenDate.get(Calendar.YEAR),
            chosenDate.get(Calendar.MONTH), chosenDate.get(Calendar.DAY_OF_MONTH));

    dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.share_cancel_public_link_button),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    if (which == DialogInterface.BUTTON_NEGATIVE) {
                        // Do Stuff
                        notifyDatePickerListener(null);
                    }
                }
            });

    // Prevent days in the past may be chosen
    DatePicker picker = dialog.getDatePicker();
    if (maxDateInMillis >= chosenDateInMillis) {
        // the extra second (+1000) is required to prevent a bug of DatePicker that shows
        // an extra header with the selected date if maxDateInMillis == chosenDateInMillis
        picker.setMaxDate(maxDateInMillis + 1000);
    }
    picker.setMinDate(tomorrowInMillis - 1000);

    // Enforce spinners view; ignored by MD-based theme in Android >=5, but calendar is REALLY buggy
    // in Android < 5, so let's be sure it never appears (in tablets both spinners and calendar are
    // shown by default)
    picker.setCalendarViewShown(false);

    return dialog;
}

From source file:com.kunze.androidlocaltodo.TaskListActivity.java

private void ShowDueDateDialog(Calendar dueDate, OnClickListener okListener) {
    LayoutInflater inflater = this.getLayoutInflater();
    View dlgView = inflater.inflate(R.layout.dialog_due_date, null);
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(dlgView);/* w ww  . j  a v a 2s.c om*/
    builder.setTitle("Due Date");
    builder.setNegativeButton("Cancel", null);
    builder.setPositiveButton("OK", okListener);

    final TextView dateText = (TextView) dlgView.findViewById(R.id.due_date_text);
    SetFriendlyDueDateText(dateText, dueDate);

    final DatePicker datePicker = (DatePicker) dlgView.findViewById(R.id.due_date_calendar);
    //datePicker.setMinDate(Math.min(now.getTimeInMillis(), dueDate.getTimeInMillis()));
    datePicker.init(dueDate.get(Calendar.YEAR), dueDate.get(Calendar.MONTH), dueDate.get(Calendar.DAY_OF_MONTH),
            new DatePicker.OnDateChangedListener() {
                @Override
                public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                    Calendar calendar = Calendar.getInstance();
                    calendar.set(year, monthOfYear, dayOfMonth, 0, 0, 0);
                    SetFriendlyDueDateText(dateText, calendar);

                }
            });
    datePicker.setCalendarViewShown(false);

    Button todayButton = (Button) dlgView.findViewById(R.id.today_button);
    todayButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Calendar now = Calendar.getInstance();
            datePicker.updateDate(now.get(Calendar.YEAR), now.get(Calendar.MONTH),
                    now.get(Calendar.DAY_OF_MONTH));
            SetFriendlyDueDateText(dateText, now);
        }
    });
    Button plusDayButton = (Button) dlgView.findViewById(R.id.plus_day_button);
    plusDayButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Calendar calendar = Calendar.getInstance();
            calendar.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth());
            calendar.add(Calendar.DATE, 1);
            datePicker.updateDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
                    calendar.get(Calendar.DAY_OF_MONTH));
            SetFriendlyDueDateText(dateText, calendar);
        }
    });
    Button thisWeekendButton = (Button) dlgView.findViewById(R.id.this_weekend_button);
    thisWeekendButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Calendar weekend = Calendar.getInstance();
            while (weekend.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY) {
                weekend.add(Calendar.DATE, 1);
            }
            datePicker.updateDate(weekend.get(Calendar.YEAR), weekend.get(Calendar.MONTH),
                    weekend.get(Calendar.DAY_OF_MONTH));
            SetFriendlyDueDateText(dateText, weekend);
        }
    });
    Button plusWeekButton = (Button) dlgView.findViewById(R.id.plus_week_button);
    plusWeekButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Calendar calendar = Calendar.getInstance();
            calendar.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth());
            calendar.add(Calendar.DATE, 7);
            datePicker.updateDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
                    calendar.get(Calendar.DAY_OF_MONTH));
            SetFriendlyDueDateText(dateText, calendar);
        }
    });

    builder.show();
}