Example usage for android.app DatePickerDialog DatePickerDialog

List of usage examples for android.app DatePickerDialog DatePickerDialog

Introduction

In this page you can find the example usage for android.app DatePickerDialog DatePickerDialog.

Prototype

public DatePickerDialog(@NonNull Context context, @Nullable OnDateSetListener listener, int year, int month,
        int dayOfMonth) 

Source Link

Document

Creates a new date picker dialog for the specified date using the parent context's default date picker dialog theme.

Usage

From source file:nl.inversion.carexpense.EditCar_Activity.java

@SuppressWarnings("deprecation")
@Override/*  w ww  .j a  va2  s.com*/
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case 1:
        // set date picker as current date
        return new DatePickerDialog(this, purDatePickerListener, purDateYear, purDateMonth, purDateDay);
    case 2:
        // set date picker as current date
        return new DatePickerDialog(this, MOTDatePickerListener, MOTDateYear, MOTDateMonth, MOTDateDay);
    case 3:
        // set date picker as current date
        return new DatePickerDialog(this, buildDatePickerListener, buildDateYear, buildDateMonth, buildDateDay);
    }
    return null;
}

From source file:uk.ac.horizon.artcodes.fragment.AvailabilityEditDialogFragment.java

private void selectDate(Long timestamp, final DateListener listener) {
    final Calendar calendar = Calendar.getInstance();
    if (timestamp != null) {
        calendar.setTimeInMillis(timestamp);
    } else {//from  w  ww . j ava2 s  .c o  m
        calendar.setTimeInMillis(System.currentTimeMillis());
    }
    int mYear = calendar.get(Calendar.YEAR);
    int mMonth = calendar.get(Calendar.MONTH);
    int mDay = calendar.get(Calendar.DAY_OF_MONTH);

    DatePickerDialog dialog = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            final Calendar calendar = Calendar.getInstance();
            calendar.set(year, monthOfYear, dayOfMonth);
            listener.dateSelected(calendar.getTimeInMillis());
        }
    }, mYear, mMonth, mDay);
    dialog.setButton(DatePickerDialog.BUTTON_NEUTRAL, getString(R.string.clear),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    listener.dateSelected(null);
                }
            });
    dialog.show();
}

From source file:com.uoit.freeroomfinder.FreeRoom.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    // Add the root view container.
    rootView = inflater.inflate(R.layout.activity_free_room, container, false);

    // Load the shared preferences.
    sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this.getActivity().getBaseContext());

    // Get the current date and time.
    curDate = new Date();

    // Set up default values for the display elements in the fragment.

    // Default campus selection.
    Spinner campus = (Spinner) rootView.findViewById(R.id.campus);
    campus.setSelection(Integer.valueOf(sharedPrefs.getString("default_campus", "0")) - 1);

    // Default booking duration.
    Spinner duration = (Spinner) rootView.findViewById(R.id.duration);
    duration.setSelection(Integer.valueOf(sharedPrefs.getString("default_duration", "0")) - 1);

    // Default time selection.
    timeSpinner = (Spinner) rootView.findViewById(R.id.time);
    // Set the current date to show as Today.
    TextView date = (TextView) rootView.findViewById(R.id.date);
    date.setText(DateTimeUtility.formatDate(curDate) + " (Today)");

    datePicked = DateTimeUtility.formatDate(curDate);

    // Instantiate the list of available rooms.
    availableRooms = new ArrayList<Rooms>();

    // Logic for when a date is clicked on. This initiates the custom date spinner control.
    date.setOnClickListener(new OnClickListener() {
        /*/*w w w . j a v a  2s .co m*/
         * (non-Javadoc)
         * 
         * @see android.view.View.OnClickListener#onClick(android.view.View)
         */
        @Override
        public void onClick(View v) {
            // parse the date that's currently in there.
            Date d = null;
            try {
                d = DateTimeUtility.parseDate(datePicked);
            } catch (ParseException e) {
                e.printStackTrace();
            }

            Calendar c = Calendar.getInstance();
            // Grab the year, month, and day from the spinners.
            if (d != null) {
                c.setTime(d);
            }
            int yy = c.get(Calendar.YEAR);
            int mm = c.get(Calendar.MONTH);
            int dd = c.get(Calendar.DAY_OF_MONTH);

            DatePickerDialog alert = new DatePickerDialog(rootView.getContext(),

                    /**
                     * Set up the listener for when the date is set from the custom spinner alert
                     * dialog.
                     */
                    new DatePickerDialog.OnDateSetListener() {
                        @Override
                        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                            // Parse the date - year, month, day.
                            datePicked = year + "-" + (monthOfYear + 1) + "-" + dayOfMonth;
                            TextView date = (TextView) rootView.findViewById(R.id.date);

                            // If the date is today's date, set it to Today.
                            date.setText(datePicked);
                            if (datePicked.contains(DateTimeUtility.formatDate(curDate))) {
                                date.setText(datePicked + " (Today)");
                            }
                        }
                    }, yy, mm, dd);

            alert.show();
        }
    });

    // Add the search buttom.
    Button search = (Button) rootView.findViewById(R.id.search);
    search.setOnClickListener(new OnClickListener() {
        /*
         * (non-Javadoc)
         * 
         * @see android.view.View.OnClickListener#onClick(android.view.View)
         */
        @Override
        public void onClick(View v) {
            // When the search button is pressed, fetch the results.
            Date curDate = new Date();

            Spinner timeSpinner = (Spinner) rootView.findViewById(R.id.time);
            Spinner durationSpinner = (Spinner) rootView.findViewById(R.id.duration);
            Spinner campusSpinner = (Spinner) rootView.findViewById(R.id.campus);

            try {
                // Formulate a query based on the time. If we're using the current time, make
                // sure we use the actual current time rather than "Now" because that's invalid.
                if (timeSpinner.getSelectedItem().toString().compareTo("Now") == 0) {
                    timePicked = DateTimeUtility.formatFullTime(DateTimeUtility.formatTime(curDate));
                } else {
                    timePicked = DateTimeUtility.formatFullTime(timeSpinner.getSelectedItem().toString());
                }

                // Add the campus we've selected to the query.
                campusPicked = rootView.getResources().getStringArray(R.array.campus_names)[campusSpinner
                        .getSelectedItemPosition()];

                // Add the duration of the search to the query.
                durationPicked = Integer.valueOf(durationSpinner.getSelectedItem().toString());

                // Formulate the search task.
                ((MainActivity) FreeRoom.this.getActivity()).showProgress(true);
                searchTask = new SearchTask();
                searchTask
                        .setOnFinshedTaskListener((Results) MainActivity.switchTabs(MainActivity.RESULTS_TAB));
                searchTask.execute();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

    return rootView;
}

From source file:com.mattprecious.smsfix.library.FixOld.java

@Override
protected Dialog onCreateDialog(int id) {
    Dialog dialog;//  w  w w  .j a  v  a 2s.  c o m
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    switch (id) {
    case DIALOG_ID_START_DATE_PICKER:
        dialog = new DatePickerDialog(this, new OnDateSetListener() {

            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                startCalendar.set(year, monthOfYear, dayOfMonth);

                updateButtons();
            }
        }, startCalendar.get(Calendar.YEAR), startCalendar.get(Calendar.MONTH),
                startCalendar.get(Calendar.DAY_OF_MONTH));
        break;
    case DIALOG_ID_START_TIME_PICKER:
        dialog = new TimePickerDialog(this, new OnTimeSetListener() {

            @Override
            public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                startCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
                startCalendar.set(Calendar.MINUTE, minute);

                updateButtons();
            }
        }, startCalendar.get(Calendar.HOUR_OF_DAY), startCalendar.get(Calendar.MINUTE),
                DateFormat.is24HourFormat(this));
        break;
    case DIALOG_ID_END_DATE_PICKER:
        dialog = new DatePickerDialog(this, new OnDateSetListener() {

            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                endCalendar.set(year, monthOfYear, dayOfMonth);

                updateButtons();
            }
        }, endCalendar.get(Calendar.YEAR), endCalendar.get(Calendar.MONTH),
                endCalendar.get(Calendar.DAY_OF_MONTH));
        break;
    case DIALOG_ID_END_TIME_PICKER:
        dialog = new TimePickerDialog(this, new OnTimeSetListener() {

            @Override
            public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                endCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
                endCalendar.set(Calendar.MINUTE, minute);

                updateButtons();
            }
        }, endCalendar.get(Calendar.HOUR_OF_DAY), endCalendar.get(Calendar.MINUTE),
                DateFormat.is24HourFormat(this));
        break;
    case DIALOG_ID_OFFSET_PICKER:
        builder.setTitle(R.string.offset_hours);

        final EditText editText = new EditText(this);

        DecimalFormat df = new DecimalFormat("#.###");
        editText.setText(df.format(Math.abs(offset) / 3600000f));
        editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED
                | InputType.TYPE_NUMBER_FLAG_DECIMAL);

        builder.setView(editText);

        builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                offset = (long) (Double.parseDouble(editText.getText().toString()) * 3600000);
                updateButtons();
            }
        });

        builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
            }
        });

        dialog = builder.create();
        break;
    case DIALOG_ID_CONFIRM:
        builder.setTitle(R.string.fix_old_confirm_title);
        builder.setMessage(R.string.fix_old_confirm_message);
        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                fixMessages();

            }
        });

        builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();

            }
        });

        dialog = builder.create();
        break;
    default:
        dialog = null;
    }

    return dialog;
}

From source file:com.karthikb351.vitinfo2.fragment.LoginFragment.java

private void showDatePicker(View view) {
    new DatePickerDialog(getActivity(), onDateSetListener, calendar.get(Calendar.YEAR),
            calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)).show();
}

From source file:com.adarshahd.indianrailinfo.donate.TrainEnquiry.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.id_btn_date:
        DatePickerDialog datePickerDialog = new DatePickerDialog(this, this, mCal.get(Calendar.YEAR),
                mCal.get(Calendar.MONTH), mCal.get(Calendar.DAY_OF_MONTH));
        datePickerDialog.show();//from  w w w  .j  a  v  a2s .c o m
        break;
    case R.id.id_btn_details:
        if (!mUtil.isConnected()) {
            mUtil.showAlert("Alert", "Network unavailable, Please check your network connection.");
            return;
        }
        if (isFormOK()) {
            ((Button) v).setText("Getting details, please wait . . .");
            v.setEnabled(false);
            if (!searchUsingTrnNumber) {
                mSrc = mACTFrom.getText().toString().split("- ", 0)[1];
                mDst = mACTTo.getText().toString().split("- ", 0)[1];
            }
            new GetTrainDetails().execute();
        } else {
            break;
        }
        break;
    default:
        return;
    }
}

From source file:com.anyonavinfo.commonuserregister.MainActivity.java

/**
 * //from  ww w .ja  va2  s.c o  m
 *
 * @param view
 */
@OnClick(R.id.birth_day)
public void showDate(View view) {
    if (!NoDoubleClick.isDoubleClick()) {
        new DatePickerDialog(MainActivity.this, new DatePickerDialog.OnDateSetListener() {
            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                String data = String.format("%d-%d-%d", year, (monthOfYear + 1), dayOfMonth);
                System.out.println(data);
                edittext_birth.setText(data);
            }
        }, 1992, 6, 2).show();
    } else {

    }
}

From source file:ca.marcmeszaros.papyrus.browser.BooksBrowser.java

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        switch (requestCode) {
        // LOAN A BOOK
        case 1001:

            // there are sufficient copies of the book to lend
            if (canLoanBook()) {
                loanData = data;//from   ww w . j a  v a  2 s .  co m

                // set default due date
                final Calendar c = Calendar.getInstance();
                c.setTimeInMillis(System.currentTimeMillis() + (1000 * 60 * 60 * 24 * 14));
                int mYear = c.get(Calendar.YEAR);
                int mMonth = c.get(Calendar.MONTH);
                int mDay = c.get(Calendar.DAY_OF_MONTH);

                // create the custom dialog title view block
                LinearLayout linearLayout = (LinearLayout) getLayoutInflater()
                        .inflate(R.layout.datepickerdialog_customtitle_twoline, null);
                TextView title = (TextView) linearLayout
                        .findViewById(R.id.DatePickerDialog_customTitle_twoline_title);
                TextView titleDescription = (TextView) linearLayout
                        .findViewById(R.id.DatePickerDialog_customTitle_twoline_description);

                // set the text
                title.setText(R.string.AlertDialog_LoanReturnDateDialog_title);
                titleDescription.setText(R.string.AlertDialog_LoanReturnDateDialog_titleDescription);

                // create the dialog with the custom header and display it
                DatePickerDialog dialog = new DatePickerDialog(this, mDateSetListener, mYear, mMonth, mDay);
                dialog.setCustomTitle(linearLayout);
                dialog.show();
            } else {
                // there are no more copies left in the library
                Toast.makeText(this, getString(R.string.BooksBrowser_toast_allCopiesLentOut), Toast.LENGTH_LONG)
                        .show();
            }

            break;
        }

    } else {
        // gracefully handle failure
        // Log.w(DEBUG_TAG, "resultWarning: activity result not ok");
    }
}

From source file:com.alivenet.dmv.driverapplication.fragment.MyAccount.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    view = inflater.inflate(R.layout.myaccount, container, false);
    getActivity().setTitle("      MY ACCOUNT");
    spincabname = (Spinner) view.findViewById(R.id.cabspinner);
    profile_image = (ImageView) view.findViewById(R.id.img_prifile_show);
    fname = (EditText) view.findViewById(R.id.edit_firname);
    lname = (EditText) view.findViewById(R.id.edit_lname);
    pass = (EditText) view.findViewById(R.id.edit_pass);
    dctc = (EditText) view.findViewById(R.id.edit_dctc);
    experdate = (TextView) view.findViewById(R.id.edit_exprdate);
    cell = (TextView) view.findViewById(R.id.edit_cell);
    email = (TextView) view.findViewById(R.id.edit_email);
    licenid = (EditText) view.findViewById(R.id.edit_licenid);
    proofincu = (EditText) view.findViewById(R.id.edit_proofinsu);
    nameinsu = (EditText) view.findViewById(R.id.edit_nameinsu);
    vehicle = (EditText) view.findViewById(R.id.edit_vehicle);
    tabsate = (EditText) view.findViewById(R.id.edit_tabstate);
    et_pvin = (EditText) view.findViewById(R.id.edit_pvin);
    btndriver = (Button) view.findViewById(R.id.btndriver);

    mPref = getActivity().getSharedPreferences(MYPREF, Context.MODE_PRIVATE);

    mTypeface = Typeface.createFromAsset(getActivity().getAssets(), "System San Francisco Display Regular.ttf");
    getFontFamily();/*www .jav a  2  s  .c  o m*/

    if (CommonMethod.isOnline(getActivity())) {

        Myaccountdata myacc = new Myaccountdata();
        myacc.execute();

        GetCablistAsync cablist = new GetCablistAsync();
        cablist.execute();

    } else {
        CommonMethodUtil.showAlert("Please connect internet", getActivity());
    }

    profile_image.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            showActionSheet();

        }
    });

    experdate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            final Calendar c = Calendar.getInstance();
            mYear = c.get(Calendar.YEAR);
            mMonth = c.get(Calendar.MONTH);
            mDay = c.get(Calendar.DAY_OF_MONTH);
            // Launch Date Picker Dialog
            DatePickerDialog dpd = new DatePickerDialog(getActivity(),
                    new DatePickerDialog.OnDateSetListener() {
                        @Override
                        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                            // Display Selected date in textbox
                            MyApplication.dataupdateflag = true;
                            try {
                                expiration_date = String.format("%02d", dayOfMonth) + "-"
                                        + String.format("%02d", (monthOfYear + 1)) + "-" + year;

                                SharedPreferences.Editor editor = mPref.edit();
                                editor.putString("dateformat1", expiration_date);
                                editor.apply();
                                Log.e("monthe", "" + monthOfYear);
                                if (monthOfYear == 0) {
                                    monthd = "Jan";
                                } else if (monthOfYear == 1) {
                                    monthd = "Feb";
                                } else if (monthOfYear == 2) {
                                    monthd = "Mar";
                                } else if (monthOfYear == 3) {
                                    monthd = "Apr";
                                } else if (monthOfYear == 4) {
                                    monthd = "May";
                                } else if (monthOfYear == 5) {
                                    monthd = "Jun";
                                } else if (monthOfYear == 6) {
                                    monthd = "Jul";
                                } else if (monthOfYear == 7) {
                                    monthd = "Aug";
                                } else if (monthOfYear == 8) {
                                    monthd = "Sept";
                                } else if (monthOfYear == 9) {
                                    monthd = "Oct";
                                } else if (monthOfYear == 10) {
                                    monthd = "Nov";
                                } else if (monthOfYear == 11) {
                                    monthd = "Dec";
                                }
                                getdate = monthd + "  " + String.valueOf(dayOfMonth) + ","
                                        + String.valueOf(year);
                                System.out.println("dateprntln>>>>>>>>>>" + getdate);

                                // Display Selected date in textbox
                                experdate.setText(getdate);

                            } catch (Exception e) {
                                e.printStackTrace();
                            }

                            //experdate.setText(String.format("%02d", dayOfMonth) + "-" + String.format("%02d", (monthOfYear + 1)) + "-" + year);
                        }
                    }, mYear, mMonth, mDay);
            dpd.getDatePicker();
            dpd.show();

        }
    });

    spincabname.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

            if (position > 0) {
                if (cabtypeList != null) {
                    cabId = cabtypeList.get(position - 1).getCabId();
                }

            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

    btndriver.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            if (CommonMethod.isOnline(getActivity())) {
                if (checkValidationUpdateProfile()) {
                    UPdateProfile update = new UPdateProfile();
                    update.execute();
                    /*  if(CommonMethod.getprofileupdate(getActivity()))
                      {
                    CommonMethodUtil.showAlert("You cant update profile after accepting ride .", getActivity());
                      }else {
                            
                      }*/
                }

            } else {
                CommonMethodUtil.showAlert("Please connect internet", getActivity());
            }

        }
    });

    return view;
}

From source file:com.mobilesolutionworks.android.managedview.test.DemoInFragment.java

@Override
public void onClick(View v) {
    Activity activity = getActivity();//from  w w w  .  j  a va2 s .  co  m

    switch (v.getId()) {
    case R.id.info_list: {
        ManagedDropDown dropDown = (ManagedDropDown) getView().findViewById(R.id.info_list);
        List<KeyValueObject> list = dropDown.getList();

        new AlertDialog.Builder(activity).setSingleChoiceItems(
                new ArrayAdapter<KeyValueObject>(activity, android.R.layout.simple_list_item_1, list), -1,
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        ManagedDropDown dropDown = (ManagedDropDown) getView().findViewById(R.id.info_list);
                        List<KeyValueObject> list = dropDown.getList();

                        dropDown.setText(list.get(which).name);
                        dialog.dismiss();
                    }
                }).create().show();
        break;
    }

    case R.id.info_listResource: {
        new AlertDialog.Builder(activity).setSingleChoiceItems(
                new ArrayAdapter<String>(activity, android.R.layout.simple_list_item_1,
                        getResources().getStringArray(R.array.listResources)),
                -1, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        String[] array = getResources().getStringArray(R.array.listResources);
                        ManagedDropDown dropDown = (ManagedDropDown) getView()
                                .findViewById(R.id.info_listResource);
                        dropDown.setText(array[which]);

                        dialog.dismiss();
                    }
                }).create().show();
        break;
    }

    case R.id.info_date: {
        Calendar cal = Calendar.getInstance(Locale.ENGLISH);
        cal.setTime(mInfo.date);

        mPickerDialog = new DatePickerDialog(activity, new DatePickerDialog.OnDateSetListener() {
            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                Calendar cal = Calendar.getInstance(Locale.ENGLISH);
                cal.set(Calendar.YEAR, year);
                cal.set(Calendar.MONTH, monthOfYear);
                cal.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                cal.set(Calendar.HOUR, 0);
                cal.set(Calendar.MINUTE, 0);
                cal.set(Calendar.SECOND, 0);

                SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy", Locale.ENGLISH);
                String date = sdf.format(cal.getTime());

                ManagedButton button = (ManagedButton) getView().findViewById(R.id.info_date);
                button.setText(date);

                mPickerDialog.dismiss();
            }
        }, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH));
        mPickerDialog.show();
        break;
    }

    case R.id.btn_print: {
        TextView textView = (TextView) getView().findViewById(R.id.log);
        textView.setText(mInfo.toString());
        break;
    }
    }
}