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:com.ranglerz.tlc.tlc.com.ranglerz.tlc.tlc.Insurance.TlcInsurance.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tlc_insurance);
    checkWriteExternalPermission();//from  w ww .  jav  a 2  s. c  om
    checkReadExternalStoragePermission();
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    if (toolbar != null) {
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }
    createNetErrorDialog();
    tlcDatabase = new TlcDatabase(this);

    showDialogForGettingUserDataFromSignUp();

    setUpIds();

    DriverLicenceImageView.setVisibility(View.GONE);
    SSCardImageView.setVisibility(View.GONE);
    BaseLetterImageView.setVisibility(View.GONE);
    UtilityBillsImageView.setVisibility(View.GONE);
    MVTitleImageView.setVisibility(View.GONE);
    SixhrDrivingClassImageView.setVisibility(View.GONE);
    SHlPermitCopyImageView.setVisibility(View.GONE);
    SHLPermitReceiptImageView.setVisibility(View.GONE);
    IsPermitOwnedImageView.setVisibility(View.GONE);
    CertificateCorporationImageView.setVisibility(View.GONE);
    FillingReciptImageView.setVisibility(View.GONE);

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.spinner_item, carTypes);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    carType.setAdapter(adapter);

    //final int pos = carType.getSelectedItemPosition();
    st = carType.getSelectedItemPosition();
    carType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            switch (arg2) {
            case 0:

                einnum.setVisibility(View.GONE);
                ownername.setVisibility(View.GONE);
                SHlPermitCopy.setVisibility(View.GONE);
                SHLPermitReceipt.setVisibility(View.GONE);
                SHlPermitCopyImageView.setVisibility(View.GONE);
                SHLPermitReceiptImageView.setVisibility(View.GONE);

                break;
            case 1:

                einnum.setVisibility(View.GONE);
                ownername.setVisibility(View.GONE);
                SHlPermitCopy.setVisibility(View.GONE);
                SHLPermitReceipt.setVisibility(View.GONE);
                SHlPermitCopyImageView.setVisibility(View.GONE);
                SHLPermitReceiptImageView.setVisibility(View.GONE);

                break;
            case 2:

                einnum.setVisibility(View.GONE);
                ownername.setVisibility(View.GONE);
                SHlPermitCopy.setVisibility(View.GONE);
                SHLPermitReceipt.setVisibility(View.GONE);
                SHlPermitCopyImageView.setVisibility(View.GONE);
                SHLPermitReceiptImageView.setVisibility(View.GONE);

                break;
            case 3:

                einnum.setVisibility(View.GONE);
                ownername.setVisibility(View.GONE);
                SHlPermitCopy.setVisibility(View.GONE);
                SHLPermitReceipt.setVisibility(View.GONE);
                SHlPermitCopyImageView.setVisibility(View.GONE);
                SHLPermitReceiptImageView.setVisibility(View.GONE);

                break;
            case 4:

                einnum.setVisibility(View.GONE);
                ownername.setVisibility(View.GONE);
                SHlPermitCopy.setVisibility(View.GONE);
                SHLPermitReceipt.setVisibility(View.GONE);
                SHlPermitCopyImageView.setVisibility(View.GONE);
                SHLPermitReceiptImageView.setVisibility(View.GONE);

                break;

            case 5:
                einnum.setVisibility(View.VISIBLE);
                ownername.setVisibility(View.VISIBLE);
                SHlPermitCopy.setVisibility(View.GONE);
                SHLPermitReceipt.setVisibility(View.GONE);
                SHlPermitCopyImageView.setVisibility(View.GONE);
                SHLPermitReceiptImageView.setVisibility(View.GONE);
                break;
            default:

                break;

            }

        }

        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub

        }
    });
    DriverLicence.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            selectImage();
            btnClicked = licenseButton;
        }
    });

    SSCard.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            selectImage();
            btnClicked = ssCardButton;

        }
    });

    BaseLetter.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            selectImage();
            btnClicked = baseLetterButton;
        }
    });

    UtilityBills.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            selectImage();
            btnClicked = utilityBillsbutton;
        }
    });

    MVTitle.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            selectImage();
            btnClicked = mvTitlebutton;
        }
    });
    SixhrDrivingClass.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            selectImage();
            btnClicked = sixhrdrivingbutton;
        }
    });
    SHlPermitCopy.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            selectImage();
            btnClicked = shlPermitbutton;
        }
    });
    SHLPermitReceipt.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            selectImage();
            btnClicked = shlpermitreceiptbutton;
        }
    });
    IsPermitOwned.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            selectImage();
            btnClicked = ispermitownedbutton;
        }
    });
    CertificateCorporation.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            selectImage();
            btnClicked = certificatebutton;
        }
    });
    FillingRecipt.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            selectImage();
            btnClicked = fillingbutton;
        }
    });
    final DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {

        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            // TODO Auto-generated method stub
            myCalendar.set(Calendar.YEAR, year);
            myCalendar.set(Calendar.MONTH, monthOfYear);
            myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
            updateLabel();
        }

    };

    dob.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            new DatePickerDialog(TlcInsurance.this, date, myCalendar.get(Calendar.YEAR),
                    myCalendar.get(Calendar.MONTH), myCalendar.get(Calendar.DAY_OF_MONTH)).show();
        }
    });

    submit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            //                boolean result = tlcDatabase.insertDataInTlcInsurance(fullname.getText().toString(), address.getText().toString(), dob.getText().toString(),
            //                        driverLicense.getText().toString(), tlcLicense.getText().toString(), phoneNum.getText().toString(),
            //                        email.getText().toString(), vinnum.getText().toString(),socialSecurtiyNumber.getText().toString(),carMake.getText().toString(),
            //                        carModel.getText().toString(),carYear.getText().toString(),einnum.getText().toString(),ownername.getText().toString());
            //                if (result)
            //                    Toast.makeText(TlcInsurance.this, "Data Submited successfully", Toast.LENGTH_LONG).show();
            //                else
            //                    Toast.makeText(TlcInsurance.this, "Data not Submited successfully", Toast.LENGTH_LONG).show();

            strfullname = fullname.getText().toString();
            straddress = address.getText().toString();
            strzipcode = Zipcode.getText().toString();
            strdob = dob.getText().toString();
            strdriverLicense = driverLicense.getText().toString();
            strtlcLicense = tlcLicense.getText().toString();
            strphoneNum = phoneNum.getText().toString();
            stremail = email.getText().toString();
            strvinnum = vinnum.getText().toString();
            strsocialSecurtiyNumber = socialSecurtiyNumber.getText().toString();
            strAddComment = AddComment.getText().toString();
            strcarType = carType.getSelectedItem().toString();
            streinnum = einnum.getText().toString();
            strownername = ownername.getText().toString();
            strcarMake = carMake.getText().toString();
            strcarModel = carModel.getText().toString();
            strcarYear = carYear.getText().toString();
            intIsPermitRadioGroup = IsPermitRadioGroup.getCheckedRadioButtonId();
            PermitRadioGroup = (RadioButton) findViewById(intIsPermitRadioGroup);
            intIsCabPolicyRadioGroup = IsCabPolicyRadioGroup.getCheckedRadioButtonId();
            CabPolicyRadioGroup = (RadioButton) findViewById(intIsCabPolicyRadioGroup);
            intNeedFullCoverage = NeedFullCoverage.getCheckedRadioButtonId();
            NeedFullCoverageis = (RadioButton) findViewById(intNeedFullCoverage);
            strTaxID = TaxID.getText().toString();

            if (strfullname.equals("")) {
                fullname.setError("Please Enter Full Name");
            } else if (straddress.equals("")) {
                address.setError("Please Enter Full Address");
            } else if (strzipcode.equals("")) {
                Zipcode.setError("Please Enter Zip Code");
            } else if (strdob.equals("")) {
                dob.setError("Please Enter Date of Birth");
            } else if (strdriverLicense.equals("")) {
                driverLicense.setError("Please Enter DMV License");
            } else if (strtlcLicense.equals("")) {
                tlcLicense.setError("Please Enter TLC License");
            } else if (strphoneNum.equals("")) {
                phoneNum.setError("Please Enter Phone Number");
            } else if (stremail.equals("")) {
                email.setError("Please Enter Email Address");
            } else if (strsocialSecurtiyNumber.equals("")) {
                socialSecurtiyNumber.setError("Please Enter Social Security Number");
            } else if (strvinnum.equals("")) {
                vinnum.setError("Please Enter VIN Number");
            } else if (DriverLicenceImageView.getDrawable() == null) {
                Toast.makeText(getApplicationContext(), "Please Upload Driver License Image",
                        Toast.LENGTH_SHORT).show();
            } else if (SSCardImageView.getDrawable() == null) {
                Toast.makeText(getApplicationContext(), "Please Upload SS Card Image", Toast.LENGTH_SHORT)
                        .show();
            } else if (BaseLetterImageView.getDrawable() == null) {
                Toast.makeText(getApplicationContext(), "Please Upload Base Letter Image", Toast.LENGTH_SHORT)
                        .show();
            } else if (UtilityBillsImageView.getDrawable() == null) {
                Toast.makeText(getApplicationContext(), "Please Upload Utility Bills Image", Toast.LENGTH_SHORT)
                        .show();
            } else if (MVTitleImageView.getDrawable() == null) {
                Toast.makeText(getApplicationContext(), "Please MV50/Title Letter Image", Toast.LENGTH_SHORT)
                        .show();
            } else if (SixhrDrivingClassImageView.getDrawable() == null) {
                Toast.makeText(getApplicationContext(), "Please Upload Six HR Driving Class Image",
                        Toast.LENGTH_SHORT).show();
            } else if (strcarType.equals("Type of Car")) {
                Toast.makeText(getApplicationContext(), "Please (Select Type of) Car Drop Down Menu",
                        Toast.LENGTH_SHORT).show();
            } else if (strcarType.equals("Corporation") && streinnum.length() == 0) {
                einnum.setError("Please Enter EIN Number");

            } else if (strcarType.equals("Corporation") && strownername.length() == 0) {
                ownername.setError("Please Enter Owner Name");

            } else if (IsPermitRadioGroup.getCheckedRadioButtonId() == -1) {
                Toast.makeText(getApplicationContext(), "Please Select Is Permit Owned Radio Button",
                        Toast.LENGTH_SHORT).show();
            } else if (PermitRadioGroup.getText().equals("No")
                    && IsPermitOwnedImageView.getDrawable() == null) {
                Toast.makeText(getApplicationContext(), "Please Upload Power Attorney Image",
                        Toast.LENGTH_SHORT).show();
            } else if (IsCabPolicyRadioGroup.getCheckedRadioButtonId() == -1) {
                Toast.makeText(getApplicationContext(), "Please Select Is Cab Policy Radio Button",
                        Toast.LENGTH_SHORT).show();
            } else if (CabPolicyRadioGroup.getText().equals("Yes")
                    && CertificateCorporationImageView.getDrawable() == null) {
                Toast.makeText(getApplicationContext(), "Please Upload Certificate of Incorporation Image",
                        Toast.LENGTH_SHORT).show();

            } else if (CabPolicyRadioGroup.getText().equals("Yes")
                    && FillingReciptImageView.getDrawable() == null) {
                Toast.makeText(getApplicationContext(), "Please Upload Filling Receipt Image",
                        Toast.LENGTH_SHORT).show();
            } else if (CabPolicyRadioGroup.getText().equals("Yes") && strTaxID.equals("")) {

                TaxID.setError("Please Enter Tax ID/EIN number");
            } else if (NeedFullCoverage.getCheckedRadioButtonId() == -1) {
                Toast.makeText(getApplicationContext(), "Please Select Need Full Coverage Radio Button",
                        Toast.LENGTH_SHORT).show();
            } else {
                getTExtPermitRadioGroup = PermitRadioGroup.getText().toString();
                getTextCabPolicyRadioGroup = CabPolicyRadioGroup.getText().toString();
                getTExtNeedFullCoverageis = NeedFullCoverageis.getText().toString();

                sharedPreferences = getSharedPreferences("email", 1);
                String email = sharedPreferences.getString(emailkey, null);

                message = "User Email: " + email + "\n\nFull Name : " + strfullname + "\nAddress : "
                        + straddress + "\nAddress Zip Code: " + strzipcode + "\nData of Birth : " + strdob
                        + "\nDMV License : " + strdriverLicense + "\nTlc License : " + strtlcLicense
                        + "\nPhone Number : " + strphoneNum + "Email : " + stremail + "\nVIN Number : "
                        + strvinnum + "\nSocial Security Number : " + strsocialSecurtiyNumber
                        + "\nSelected Car Type " + strcarType + "\nEIN Number : " + streinnum
                        + "\nOwner Name : " + strownername + "\nCar Make :" + strcarMake + "\nCar Model :"
                        + strcarModel + "\nCar Year :" + strcarYear + "Tax ID: " + strTaxID
                        + "\nIs Permit Owned :" + getTExtPermitRadioGroup + "\nIs Cab Policy :"
                        + getTextCabPolicyRadioGroup + "\nNeed Full Coverage :" + getTExtNeedFullCoverageis;

                //new SendEmail().execute();
                new uploadData().execute();

            }
            //Toast.makeText(TlcInsurance.this, "aslfkafa", Toast.LENGTH_SHORT).show();

            //                UploadImage ui1 = new UploadImage();
            //                ui1.execute(bitmap1);

            //
        }
    });

    IsPermitOwned.setVisibility(View.GONE);
    //IsPermitOwnedImageView.setVisibility(View.GONE);

    IsPermitRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            if (checkedId == R.id.ispermitownedno) {
                IsPermitOwned.setVisibility(View.VISIBLE);
                //IsPermitOwnedImageView.setVisibility(View.VISIBLE);
            } else {
                IsPermitOwned.setVisibility(View.GONE);
                IsPermitOwnedImageView.setVisibility(View.GONE);

            }
        }
    });

    CertificateCorporation.setVisibility(View.GONE);
    //  CertificateCorporationImageView.setVisibility(View.GONE);
    FillingRecipt.setVisibility(View.GONE);
    // FillingReciptImageView.setVisibility(View.GONE);
    TaxID.setVisibility(View.GONE);

    IsCabPolicyRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            if (checkedId == R.id.cabpolicyyes) {
                CertificateCorporation.setVisibility(View.VISIBLE);
                // CertificateCorporationImageView.setVisibility(View.VISIBLE);
                FillingRecipt.setVisibility(View.VISIBLE);
                //FillingReciptImageView.setVisibility(View.VISIBLE);
                TaxID.setVisibility(View.VISIBLE);
            } else {
                CertificateCorporation.setVisibility(View.GONE);
                CertificateCorporationImageView.setVisibility(View.GONE);
                FillingRecipt.setVisibility(View.GONE);
                FillingReciptImageView.setVisibility(View.GONE);
                TaxID.setVisibility(View.GONE);

            }
        }
    });
}

From source file:nl.mpcjanssen.simpletask.AddTask.java

private void insertDate(final int dateType) {
    Dialog d = Util.createDeferDialog(this, dateType, false, new Util.InputDialogListener() {
        @Override//w  w w  .j a va  2s  .c  o  m
        public void onClick(@NotNull String selected) {
            if (selected.equals("pick")) {
                /* Note on some Android versions the OnDateSetListener can fire twice
                 * https://code.google.com/p/android/issues/detail?id=34860
                 * With the current implementation which replaces the dates this is not an
                 * issue. The date is just replaced twice
                 */
                final DateTime today = DateTime.today(TimeZone.getDefault());
                DatePickerDialog dialog = new DatePickerDialog(AddTask.this,
                        new DatePickerDialog.OnDateSetListener() {
                            @Override
                            public void onDateSet(DatePicker datePicker, int year, int month, int day) {
                                month++;

                                DateTime date = DateTime.forDateOnly(year, month, day);
                                insertDateAtSelection(dateType, date);
                            }
                        }, today.getYear(), today.getMonth() - 1, today.getDay());

                boolean showCalendar = m_app.showCalendar();

                dialog.getDatePicker().setCalendarViewShown(showCalendar);
                dialog.getDatePicker().setSpinnersShown(!showCalendar);
                dialog.show();
            } else {
                insertDateAtSelection(dateType,
                        Util.addInterval(DateTime.today(TimeZone.getDefault()), selected));
            }
        }
    });
    d.show();
}

From source file:org.openmrs.mobile.activities.addeditpatient.AddEditPatientFragment.java

private void addListeners() {
    gen.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        public void onCheckedChanged(RadioGroup rGroup, int checkedId) {
            gendererror.setVisibility(View.GONE);
        }//w  w w .  ja v  a  2s .c  om
    });

    edcountry.setThreshold(2);
    edcountry.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (edcountry.getText().length() >= edcountry.getThreshold()) {
                edcountry.showDropDown();
            }
            if (Arrays.asList(countries).contains(edcountry.getText().toString())) {
                edcountry.dismissDropDown();
            }
        }
    });
    edstate.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            addSuggestionsToCities();
        }
    });
    if (eddob != null) {
        eddob.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int cYear;
                int cMonth;
                int cDay;

                if (bdt == null) {
                    Calendar currentDate = Calendar.getInstance();
                    cYear = currentDate.get(Calendar.YEAR);
                    cMonth = currentDate.get(Calendar.MONTH);
                    cDay = currentDate.get(Calendar.DAY_OF_MONTH);
                } else {
                    cYear = bdt.getYear();
                    cMonth = bdt.getMonthOfYear() - 1;
                    cDay = bdt.getDayOfMonth();
                }

                edmonth.getText().clear();
                edyr.getText().clear();

                DatePickerDialog mDatePicker = new DatePickerDialog(AddEditPatientFragment.this.getActivity(),
                        new DatePickerDialog.OnDateSetListener() {
                            public void onDateSet(DatePicker datepicker, int selectedyear, int selectedmonth,
                                    int selectedday) {
                                int adjustedMonth = selectedmonth + 1;
                                eddob.setText(selectedday + "/" + adjustedMonth + "/" + selectedyear);
                                birthdate = new LocalDate(selectedyear, adjustedMonth, selectedday);
                                bdt = birthdate.toDateTimeAtStartOfDay().toDateTime();
                            }
                        }, cYear, cMonth, cDay);
                mDatePicker.getDatePicker().setMaxDate(System.currentTimeMillis());
                mDatePicker.setTitle("Select Date");
                mDatePicker.show();
            }
        });
    }

    capturePhoto.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            AddEditPatientFragmentPermissionsDispatcher.capturePhotoWithCheck(AddEditPatientFragment.this);
        }
    });

    submitConfirm.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mPresenter.confirmRegister(createPatient());
        }
    });

    patientImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (output != null) {
                Intent i = new Intent(Intent.ACTION_VIEW);
                i.setDataAndType(Uri.fromFile(output), "image/jpeg");
                startActivity(i);
            } else if (patientPhoto != null) {
                Intent intent = new Intent(getContext(), PatientPhotoActivity.class);
                ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                patientPhoto.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
                intent.putExtra("photo", byteArrayOutputStream.toByteArray());
                intent.putExtra("name", patientName);
                startActivity(intent);
            }
        }
    });

    TextWatcher textWatcher = new PatientBirthdateValidatorWatcher(eddob, edmonth, edyr);
    edmonth.addTextChangedListener(textWatcher);
    edyr.addTextChangedListener(textWatcher);
}

From source file:auribises.com.visitorbook.Activites.AdminEntryActivity.java

public void showDatePicker(View view) {

    Calendar calendar = Calendar.getInstance();
    int dd = calendar.get(Calendar.DAY_OF_MONTH);
    int mm = calendar.get(Calendar.MONTH);
    int yy = calendar.get(Calendar.YEAR);

    datePickerDialog = new DatePickerDialog(this, dateSetListener, yy, mm, dd);
    datePickerDialog.show();/* ww w.  jav  a2 s  .  c  o m*/

}

From source file:com.ushahidi.android.app.ui.phone.AddReportActivity.java

/**
 * Create various dialog/*from   w  ww . ja v a2s  . c o m*/
 */
@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_ERROR_NETWORK: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.network_error));
        dialog.setMessage(getString(R.string.network_error_msg));
        dialog.setButton2(getString(R.string.ok), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.setCancelable(false);
        return dialog;
    }
    case DIALOG_ERROR_SAVING: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.network_error));
        dialog.setMessage(getString(R.string.file_system_error_msg));
        dialog.setButton2(getString(R.string.ok), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.setCancelable(false);
        return dialog;
    }

    case DIALOG_CHOOSE_IMAGE_METHOD: {

        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.choose_method));
        dialog.setMessage(getString(R.string.how_to_select_pic));
        dialog.setButton(getString(R.string.gallery_option), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_PICK);
                intent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(intent, REQUEST_CODE_IMAGE);
                dialog.dismiss();
            }
        });
        dialog.setButton2(getString(R.string.cancel), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.setButton3(getString(R.string.camera_option), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                intent.putExtra(MediaStore.EXTRA_OUTPUT,
                        PhotoUtils.getPhotoUri(photoName, AddReportActivity.this));
                startActivityForResult(intent, REQUEST_CODE_CAMERA);
                dialog.dismiss();
            }
        });

        dialog.setCancelable(false);
        return dialog;
    }

    case DIALOG_MULTIPLE_CATEGORY: {
        if (showCategories() != null) {
            return new AlertDialog.Builder(this).setTitle(R.string.choose_categories)
                    .setMultiChoiceItems(showCategories(), setCheckedCategories(),
                            new DialogInterface.OnMultiChoiceClickListener() {
                                public void onClick(DialogInterface dialog, int whichButton,
                                        boolean isChecked) {
                                    // see if categories have previously

                                    if (isChecked) {
                                        mVectorCategories.add(mCategoriesId.get(whichButton));

                                        mError = false;
                                    } else {
                                        mVectorCategories.remove(mCategoriesId.get(whichButton));
                                    }

                                    setSelectedCategories(mVectorCategories);
                                }
                            })
                    .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {

                            /* User clicked Yes so do some stuff */
                        }
                    }).create();
        }
    }

    case TIME_DIALOG_ID:
        return new TimePickerDialog(this, mTimeSetListener, mCalendar.get(Calendar.HOUR),
                mCalendar.get(Calendar.MINUTE), false);

    case DATE_DIALOG_ID:
        return new DatePickerDialog(this, mDateSetListener, mCalendar.get(Calendar.YEAR),
                mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH));

    case DIALOG_SHOW_MESSAGE:
        AlertDialog.Builder messageBuilder = new AlertDialog.Builder(this);
        messageBuilder.setMessage(mErrorMessage).setPositiveButton(getString(R.string.ok),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });

        AlertDialog showDialog = messageBuilder.create();
        showDialog.show();
        break;

    case DIALOG_SHOW_REQUIRED:
        AlertDialog.Builder requiredBuilder = new AlertDialog.Builder(this);
        requiredBuilder.setTitle(R.string.required_fields);
        requiredBuilder.setMessage(mErrorMessage).setPositiveButton(getString(R.string.ok),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });

        AlertDialog showRequiredDialog = requiredBuilder.create();
        showRequiredDialog.show();
        break;

    // prompt for unsaved changes
    case DIALOG_SHOW_PROMPT: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.unsaved_changes));
        dialog.setMessage(getString(R.string.want_to_cancel));
        dialog.setButton(getString(R.string.no), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

                dialog.dismiss();
            }
        });
        dialog.setButton2(getString(R.string.yes), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                finish();
                dialog.dismiss();
            }
        });

        dialog.setCancelable(false);
        return dialog;
    }

    // prompt for report deletion
    case DIALOG_SHOW_DELETE_PROMPT: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.delete_report));
        dialog.setMessage(getString(R.string.want_to_delete));
        dialog.setButton(getString(R.string.no), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

                dialog.dismiss();
            }
        });
        dialog.setButton2(getString(R.string.yes), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                // delete report
                deleteReport();
                dialog.dismiss();
            }
        });

        dialog.setCancelable(false);
        return dialog;
    }

    }
    return null;
}

From source file:com.markuspage.android.atimetracker.Tasks.java

/**
 * Creates a progressDialog to change the dates for which task times are
 * shown. Offers a short selection of pre-defined defaults, and the option
 * to choose a range from a progressDialog.
 *
 * @see arrays.xml/*from  w  w  w.j a v a2  s  .c o m*/
 * @return the progressDialog to be displayed
 */
private Dialog openChangeViewDialog() {
    return new AlertDialog.Builder(Tasks.this).setItems(R.array.views, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            SharedPreferences.Editor ed = preferences.edit();
            ed.putInt(VIEW_MODE, which);
            ed.commit();
            if (which == 5) {
                Calendar calInstance = Calendar.getInstance();
                new DatePickerDialog(Tasks.this, new DatePickerDialog.OnDateSetListener() {
                    public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                        Calendar start = Calendar.getInstance();
                        start.set(Calendar.YEAR, year);
                        start.set(Calendar.MONTH, monthOfYear);
                        start.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                        start.set(Calendar.HOUR, start.getMinimum(Calendar.HOUR));
                        start.set(Calendar.MINUTE, start.getMinimum(Calendar.MINUTE));
                        start.set(Calendar.SECOND, start.getMinimum(Calendar.SECOND));
                        start.set(Calendar.MILLISECOND, start.getMinimum(Calendar.MILLISECOND));
                        SharedPreferences.Editor ed = preferences.edit();
                        ed.putLong(START_DATE, start.getTime().getTime());
                        ed.commit();

                        new DatePickerDialog(Tasks.this, new DatePickerDialog.OnDateSetListener() {
                            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                                Calendar end = Calendar.getInstance();
                                end.set(Calendar.YEAR, year);
                                end.set(Calendar.MONTH, monthOfYear);
                                end.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                                end.set(Calendar.HOUR, end.getMaximum(Calendar.HOUR));
                                end.set(Calendar.MINUTE, end.getMaximum(Calendar.MINUTE));
                                end.set(Calendar.SECOND, end.getMaximum(Calendar.SECOND));
                                end.set(Calendar.MILLISECOND, end.getMaximum(Calendar.MILLISECOND));
                                SharedPreferences.Editor ed = preferences.edit();
                                ed.putLong(END_DATE, end.getTime().getTime());
                                ed.commit();
                                Tasks.this.switchView(5); // Update the list view
                            }
                        }, year, monthOfYear, dayOfMonth).show();
                    }
                }, calInstance.get(Calendar.YEAR), calInstance.get(Calendar.MONTH),
                        calInstance.get(Calendar.DAY_OF_MONTH)).show();
            } else {
                switchView(which);
            }
        }
    }).create();
}

From source file:com.vanisty.ui.MenuActivity.java

/** Create a new dialog for date picker */
@Override/*from w w w .  ja  va 2  s .c o  m*/
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DATE_DIALOG_ID:
        return new DatePickerDialog(this, pDateSetListener, pYear, pMonth, pDay);
    }
    return null;
}

From source file:foam.littlej.android.app.ui.phone.AddReportActivity.java

/**
 * Create various dialog/*from ww w .ja v  a  2 s  .co m*/
 */
@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_ERROR_NETWORK: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.network_error));
        dialog.setMessage(getString(R.string.network_error_msg));
        dialog.setButton2(getString(R.string.ok), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.setCancelable(false);
        return dialog;
    }
    case DIALOG_ERROR_SAVING: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.network_error));
        dialog.setMessage(getString(R.string.file_system_error_msg));
        dialog.setButton2(getString(R.string.ok), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.setCancelable(false);
        return dialog;
    }

    case DIALOG_CHOOSE_IMAGE_METHOD: {

        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.choose_method));
        dialog.setMessage(getString(R.string.how_to_select_pic));
        dialog.setButton(getString(R.string.gallery_option), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_PICK);
                intent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(intent, REQUEST_CODE_IMAGE);
                dialog.dismiss();
            }
        });
        dialog.setButton2(getString(R.string.cancel), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.setButton3(getString(R.string.camera_option), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                intent.putExtra(MediaStore.EXTRA_OUTPUT,
                        PhotoUtils.getPhotoUri(photoName, AddReportActivity.this));
                startActivityForResult(intent, REQUEST_CODE_CAMERA);
                dialog.dismiss();
            }
        });

        dialog.setCancelable(false);
        return dialog;
    }

    case DIALOG_MULTIPLE_CATEGORY: {
        if (showCategories() != null) {
            return new AlertDialog.Builder(this).setTitle(R.string.choose_categories)
                    .setMultiChoiceItems(showCategories(), setCheckedCategories(),
                            new DialogInterface.OnMultiChoiceClickListener() {
                                public void onClick(DialogInterface dialog, int whichButton,
                                        boolean isChecked) {
                                    // see if categories have previously

                                    if (isChecked) {
                                        mVectorCategories.add(mCategoriesId.get(whichButton));

                                        mError = false;
                                    } else {
                                        mVectorCategories.remove(mCategoriesId.get(whichButton));
                                    }

                                    setSelectedCategories(mVectorCategories);
                                }
                            })
                    .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {

                            /* User clicked Yes so do some stuff */
                        }
                    }).create();
        }
    }

    case TIME_DIALOG_ID:
        return new TimePickerDialog(this, mTimeSetListener, mCalendar.get(Calendar.HOUR),
                mCalendar.get(Calendar.MINUTE), false);

    case DATE_DIALOG_ID:
        return new DatePickerDialog(this, mDateSetListener, mCalendar.get(Calendar.YEAR),
                mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH));

    case DIALOG_SHOW_MESSAGE:
        AlertDialog.Builder messageBuilder = new AlertDialog.Builder(this);
        messageBuilder.setMessage(mErrorMessage).setPositiveButton(getString(R.string.ok),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });

        AlertDialog showDialog = messageBuilder.create();
        showDialog.show();
        break;

    case DIALOG_SHOW_REQUIRED:
        AlertDialog.Builder requiredBuilder = new AlertDialog.Builder(this);
        requiredBuilder.setTitle(R.string.required_fields);
        requiredBuilder.setMessage(mErrorMessage).setPositiveButton(getString(R.string.ok),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });

        AlertDialog showRequiredDialog = requiredBuilder.create();
        showRequiredDialog.show();
        break;

    // prompt for unsaved changes
    case DIALOG_SHOW_PROMPT: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.unsaved_changes));
        dialog.setMessage(getString(R.string.want_to_cancel));
        dialog.setButton(getString(R.string.no), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

                dialog.dismiss();
            }
        });
        dialog.setButton2(getString(R.string.yes), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                new DiscardTask(AddReportActivity.this).execute((String) null);
                finish();
                dialog.dismiss();
            }
        });

        dialog.setCancelable(false);
        return dialog;
    }

    // prompt for report deletion
    case DIALOG_SHOW_DELETE_PROMPT: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.delete_report));
        dialog.setMessage(getString(R.string.want_to_delete));
        dialog.setButton(getString(R.string.no), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

                dialog.dismiss();
            }
        });
        dialog.setButton2(getString(R.string.yes), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                // delete report
                deleteReport();
                dialog.dismiss();
            }
        });

        dialog.setCancelable(false);
        return dialog;
    }

    }
    return null;
}

From source file:pl.bcichecki.rms.client.android.activities.EditEventActivity.java

private void showEndsOnDateDialog() {
    Calendar endDateCalendar = Calendar.getInstance();
    endDateCalendar.setTime(endDate);//  w w w. jav a  2s  .c om

    OnDateSetListener onDateSetListener = new DatePickerDialog.OnDateSetListener() {

        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            endDate = DateUtils.setYears(endDate, year);
            endDate = DateUtils.setMonths(endDate, monthOfYear);
            endDate = DateUtils.setDays(endDate, dayOfMonth);
            updateEndDateButtons();
        }
    };

    DatePickerDialog datePickerDialog = new DatePickerDialog(context, onDateSetListener,
            endDateCalendar.get(Calendar.YEAR), endDateCalendar.get(Calendar.MONTH),
            endDateCalendar.get(Calendar.DAY_OF_MONTH));
    datePickerDialog.setTitle(R.string.activity_edit_event_pick_end_date);
    datePickerDialog.show();
}

From source file:com.speed.traquer.app.TraqComplaintTaxi.java

public void dateOnClick(View view) {
    new DatePickerDialog(TraqComplaintTaxi.this, date, c.get(Calendar.YEAR), c.get(Calendar.MONTH),
            c.get(Calendar.DAY_OF_MONTH)).show();
}