Esempio n. 1
0
  void showDatePickerDialog() {
    final int tempYear = cYear;
    final int tempMonth = cMonth;
    final int tempDay = cDay;

    DatePickerDialog dialog =
        new DatePickerDialog(
            this,
            new DatePickerDialog.OnDateSetListener() {
              @Override
              public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                cYear = year;
                cMonth = monthOfYear + 1;
                cDay = dayOfMonth;
                loadDiary();
              }
            },
            cYear,
            cMonth - 1,
            cDay);

    dialog.setOnCancelListener(
        new DialogInterface.OnCancelListener() {
          @Override
          public void onCancel(DialogInterface arg0) {
            cYear = tempYear;
            cMonth = tempMonth;
            cDay = tempDay;
          }
        });

    dialog.setTitle("날짜 선택");

    dialog.show();
  }
Esempio n. 2
0
 @Override
 public void onClick(View v) {
   // TODO Auto-generated method stub
   DatePickerDialog dpd =
       new DatePickerDialog(MainActivity.this, datePickerDlgOnDateSet, mYear, mMonth, mDay);
   dpd.setTitle("Choose Date");
   dpd.setMessage("");
   dpd.setCancelable(false);
   dpd.show();
 }
Esempio n. 3
0
 @OnClick(R.id.rlDate)
 public void pickDate() {
   Calendar cal = Calendar.getInstance(TimeZone.getDefault());
   DatePickerDialog datePickerDialog =
       new DatePickerDialog(
           this,
           DatePickerDialog.THEME_HOLO_LIGHT,
           datePickerListener,
           cal.get(Calendar.YEAR),
           cal.get(Calendar.MONTH),
           cal.get(Calendar.DAY_OF_MONTH));
   datePickerDialog.setCancelable(false);
   datePickerDialog.setTitle("Select the date");
   datePickerDialog.show();
 }
  public DatePickerDialog builder() {

    Calendar newCalendar = Calendar.getInstance();

    // Data de Nascimento
    DatePickerDialog dataPickerDialog =
        new DatePickerDialog(
            this.activity,
            this,
            newCalendar.get(Calendar.YEAR),
            newCalendar.get(Calendar.MONTH),
            newCalendar.get(Calendar.DAY_OF_MONTH));
    dataPickerDialog.setTitle(getTitleDate()); // constante

    return dataPickerDialog;
  }
        @Override
        public void onClick(View v) {
          // TODO Auto-generated method stub
          mTxtResult.setText("");

          Calendar now = Calendar.getInstance();
          DatePickerDialog dataPicDlg =
              new DatePickerDialog(
                  DialogActivity.this,
                  datePicDlgOnDateSelLis,
                  now.get(Calendar.YEAR),
                  now.get(Calendar.MONTH),
                  now.get(Calendar.DAY_OF_MONTH));

          dataPicDlg.setTitle("选择日期");
          dataPicDlg.setMessage("请选择适合您的日期");
          dataPicDlg.setIcon(android.R.drawable.ic_dialog_info);
          dataPicDlg.setCancelable(false);
          dataPicDlg.show();
        }
Esempio n. 6
0
  public void showDatePickerDialog(
      int year, int month, int day, final DatePickerLister datePickerLister) {
    mYear = year;
    mMonth = month;
    mDay = day;
    if (mDateDialog == null) {
      mDateDialog = new DatePickerDialog(mContext, onDateSetListener, mYear, mMonth, mDay);
    }
    DatePicker dp = mDateDialog.getDatePicker();
    dp.setMaxDate(Calendar.getInstance().getTimeInMillis()); // 设置最大日期
    mDateDialog.setTitle(R.string.userinfo_select_birthday);
    mDateDialog.setButton(
        AlertDialog.BUTTON_NEGATIVE,
        mContext.getResources().getString(R.string.common_cancel),
        new DialogInterface.OnClickListener() {

          @Override
          public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            mDateDialog = null;
          }
        });
    mDateDialog.setButton(
        AlertDialog.BUTTON_POSITIVE,
        mContext.getResources().getString(R.string.common_sure),
        new DialogInterface.OnClickListener() {

          @Override
          public void onClick(DialogInterface dialog, int which) {
            mYear = mDateDialog.getDatePicker().getYear();
            mMonth = mDateDialog.getDatePicker().getMonth();
            mDay = mDateDialog.getDatePicker().getDayOfMonth();
            datePickerLister.onDatePicker(mYear, mMonth, mDay);
            dialog.dismiss();
            mDateDialog = null;
          }
        });
    mDateDialog.show();
  }
  @Override
  public void onClick(View v) {
    if (v.getId() == R.id.tvAction) {
      sendCreateReminderRequest();
    } else {
      final Calendar calendar = Calendar.getInstance();
      switch (v.getId()) {
        case R.id.tvStartDate:
        case R.id.tvStartTime:
          calendar.setTime(startTime);
          break;
        case R.id.tvEndDate:
        case R.id.tvEndTime:
          calendar.setTime(endTime);
          break;
        case R.id.tvRepeatEndDate:
          calendar.setTime(endDate);
          break;
      }
      int date = calendar.get(Calendar.DATE);
      int month = calendar.get(Calendar.MONTH);
      int year = calendar.get(Calendar.YEAR);
      int hour = calendar.get(Calendar.HOUR_OF_DAY);
      int minute = calendar.get(Calendar.MINUTE);
      switch (v.getId()) {
        case R.id.tvRepeatEndDate:
          {
            DatePickerDialog dialogEndDate =
                new DatePickerDialog(
                    this,
                    new OnDateSetListener() {
                      boolean fired = false;

                      @Override
                      public void onDateSet(DatePicker view, int year, int month, int day) {
                        // onDateSet call twice, so, we will check for first call
                        if (!fired) {
                          calendar.set(Calendar.DATE, day);
                          calendar.set(Calendar.MONTH, month);
                          calendar.set(Calendar.YEAR, year);
                          endDate = calendar.getTime();
                          // check if end time is less than start time, set default end time is
                          // start time
                          if (DateTimeFormater.timeServerFormat
                                  .format(endDate)
                                  .compareToIgnoreCase(
                                      DateTimeFormater.timeServerFormat.format(startTime))
                              < 0) {
                            showCenterToast(R.string.msg_err_end_time_must_greater_start_time);
                            calendar.setTime(startTime);
                            calendar.set(Calendar.HOUR_OF_DAY, 23);
                            calendar.set(Calendar.MINUTE, 59);
                            calendar.set(Calendar.SECOND, 59);
                            endDate = calendar.getTime();
                          }
                          tvRepeatEndDate.setText(
                              DateTimeFormater.dateFullFormater.format(endDate));
                          fired = true;
                        }
                      }
                    },
                    year,
                    month,
                    date);
            dialogEndDate.setTitle("Select End Date repeat");
            dialogEndDate.show();
            break;
          }
        case R.id.tvStartDate:
          {
            DatePickerDialog dialog =
                new DatePickerDialog(
                    this,
                    new OnDateSetListener() {
                      boolean fired = false;

                      @Override
                      public void onDateSet(DatePicker view, int year, int month, int day) {
                        // onDateSet call twice, so, we will check for first call
                        if (!fired) {
                          calendar.set(Calendar.DATE, day);
                          calendar.set(Calendar.MONTH, month);
                          calendar.set(Calendar.YEAR, year);
                          startTime = calendar.getTime();
                          tvStartDate.setText(DateTimeFormater.dateFullFormater.format(startTime));
                          // check if end time is less than start time, set default end time is
                          // start time + 1 hour
                          if (DateTimeFormater.timeServerFormat
                                  .format(endTime)
                                  .compareToIgnoreCase(
                                      DateTimeFormater.timeServerFormat.format(startTime))
                              < 0) {
                            calendar.setTime(startTime);
                            calendar.add(Calendar.HOUR, 1);
                            endTime = calendar.getTime();
                            tvEndDate.setText(DateTimeFormater.dateFullFormater.format(endTime));
                            tvEndTime.setText(DateTimeFormater.timeFormater.format(endTime));
                          }
                          if (DateTimeFormater.timeServerFormat
                                  .format(endDate)
                                  .compareToIgnoreCase(
                                      DateTimeFormater.timeServerFormat.format(startTime))
                              < 0) {
                            // set end date
                            calendar.setTime(startTime);
                            calendar.set(Calendar.HOUR_OF_DAY, 23);
                            calendar.set(Calendar.MINUTE, 59);
                            calendar.set(Calendar.SECOND, 59);
                            endDate = calendar.getTime();
                            tvRepeatEndDate.setText(
                                DateTimeFormater.dateFullFormater.format(endDate));
                          }
                          fired = true;
                        }
                      }
                    },
                    year,
                    month,
                    date);
            dialog.setTitle("Select Start Date");
            dialog.show();
            break;
          }
        case R.id.tvEndDate:
          {
            DatePickerDialog dialog =
                new DatePickerDialog(
                    this,
                    new OnDateSetListener() {
                      boolean fired = false;

                      @Override
                      public void onDateSet(DatePicker view, int year, int month, int day) {
                        // onDateSet call twice, so, we will check for first call
                        if (!fired) {
                          calendar.set(Calendar.DATE, day);
                          calendar.set(Calendar.MONTH, month);
                          calendar.set(Calendar.YEAR, year);
                          endTime = calendar.getTime();
                          // check if end time is less than start time, show error toast and set
                          // default end time
                          // is
                          // start time + 1 hour
                          if (DateTimeFormater.timeServerFormat
                                  .format(endTime)
                                  .compareToIgnoreCase(
                                      DateTimeFormater.timeServerFormat.format(startTime))
                              < 0) {
                            showCenterToast(R.string.msg_err_end_time_must_greater_start_time);
                            calendar.setTime(startTime);
                            calendar.add(Calendar.HOUR, 1);
                            endTime = calendar.getTime();
                          }
                          tvEndDate.setText(DateTimeFormater.dateFullFormater.format(endTime));
                          fired = true;
                        }
                      }
                    },
                    year,
                    month,
                    date);
            dialog.setTitle("Select End Date");
            dialog.show();
            break;
          }
        case R.id.tvStartTime:
          {
            TimePickerDialog dialog =
                new TimePickerDialog(
                    this,
                    new OnTimeSetListener() {

                      @Override
                      public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                        calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
                        calendar.set(Calendar.MINUTE, minute);
                        startTime = calendar.getTime();
                        tvStartTime.setText(DateTimeFormater.timeFormater.format(startTime));
                        // check if end time is less than start time, set default end time is
                        // start time + 1 hour
                        if (DateTimeFormater.timeServerFormat
                                .format(endTime)
                                .compareToIgnoreCase(
                                    DateTimeFormater.timeServerFormat.format(startTime))
                            < 0) {
                          // set end time
                          calendar.setTime(startTime);
                          calendar.add(Calendar.HOUR, 1);
                          endTime = calendar.getTime();
                          tvEndDate.setText(DateTimeFormater.dateFullFormater.format(endTime));
                          tvEndTime.setText(DateTimeFormater.timeFormater.format(endTime));
                        }
                        if (DateTimeFormater.timeServerFormat
                                .format(endDate)
                                .compareToIgnoreCase(
                                    DateTimeFormater.timeServerFormat.format(startTime))
                            < 0) {
                          // set end date
                          calendar.setTime(startTime);
                          calendar.set(Calendar.HOUR_OF_DAY, 23);
                          calendar.set(Calendar.MINUTE, 59);
                          calendar.set(Calendar.SECOND, 59);
                          endDate = calendar.getTime();
                          tvRepeatEndDate.setText(
                              DateTimeFormater.dateFullFormater.format(endDate));
                        }
                      }
                    },
                    hour,
                    minute,
                    true);
            dialog.setTitle("Select Start Time");
            dialog.show();
            break;
          }
        case R.id.tvEndTime:
          {
            TimePickerDialog dialog =
                new TimePickerDialog(
                    this,
                    new OnTimeSetListener() {

                      @Override
                      public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                        calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
                        calendar.set(Calendar.MINUTE, minute);
                        endTime = calendar.getTime();
                        // check if end time is less than start time, show error toast and set
                        // default end time is
                        // start time + 1 hour
                        if (DateTimeFormater.timeServerFormat
                                .format(endTime)
                                .compareToIgnoreCase(
                                    DateTimeFormater.timeServerFormat.format(startTime))
                            < 0) {
                          showCenterToast(R.string.msg_err_end_time_must_greater_start_time);
                          calendar.setTime(startTime);
                          calendar.add(Calendar.HOUR, 1);
                          endTime = calendar.getTime();
                        }
                        tvEndTime.setText(DateTimeFormater.timeFormater.format(endTime));
                      }
                    },
                    hour,
                    minute,
                    true);
            dialog.setTitle("Select End Time");
            dialog.show();
            break;
          }
        default:
          break;
      }
    }
  }