예제 #1
0
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
      // Use the current date as the default date in the picker
      int year = 0;
      int month = 0;
      int day = 0;
      /*if (userBirthdate != null) {
          year = userBirthdate.getYear();
          month = userBirthdate.getMonthOfYear() - 1;
          day = userBirthdate.getDayOfMonth();
      } else {*/
      LocalDateTime now = LocalDateTime.now();
      year = now.getYear();
      month = now.getMonthOfYear();
      day = now.getDayOfMonth();
      // }

      DatePickerDialog dateDlg = new DatePickerDialog(getActivity(), this, year, month, day);
      dateDlg.setMessage(getString(R.string.add_date_dialog_title));
      Calendar calendar = Calendar.getInstance();
      calendar.set(Calendar.MONTH, calendar.getActualMaximum(Calendar.MONTH));
      calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE));
      // dateDlg.getDatePicker().setMaxDate(calendar.getTimeInMillis());

      // Create a new instance of DatePickerDialog and return it
      return dateDlg;
    }
예제 #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();
 }
        @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();
        }
예제 #4
0
  /**
   * Called when a view has been clicked.
   *
   * @param v The view that was clicked.
   */
  @Override
  public void onClick(View v) {
    final DateFormat dateFormat =
        new SimpleDateFormat(editTaskScreen.getString(R.string.date_format));
    final DateFormat dateFormatInput =
        new SimpleDateFormat(editTaskScreen.getString(R.string.date_format_input));
    final View view = v;
    final Calendar c;

    switch (v.getId()) {
      case (R.id.button_save_task):
        // confirm task information button
        c = Calendar.getInstance();

        final String textTaskTittle = editTaskScreen.getTaskTittle().getText().toString();
        final String textTaskNotes = editTaskScreen.getTaskNote().getText().toString();

        final String textTaskDueDate = taskBundle.getString("Due Date", "");
        final String textPriority = taskBundle.getString("Parent");

        Log.v("Things.DO", "Confirm add task \"" + textTaskTittle + "\"");

        // load selected task information
        Intent resultTask = new Intent(editTaskScreen, MainScreen.class);

        resultTask.putExtra("Task ID", taskBundle.getInt("Task ID"));
        resultTask.putExtra("Google ID", taskBundle.getString("Google ID"));
        resultTask.putExtra("Tittle", textTaskTittle);
        resultTask.putExtra("Update Date", dateFormat.format(c.getTime()));
        resultTask.putExtra("Parent", textPriority);
        resultTask.putExtra("Notes", textTaskNotes);
        resultTask.putExtra("Status", "needsAction");
        resultTask.putExtra("Due Date", textTaskDueDate);
        resultTask.putExtra("Completed Date", "");
        resultTask.putExtra("Category", taskBundle.getString("Category"));

        String collaborators = "";
        for (int i = 0; i < editTaskScreen.getCollaborators().size(); i++) {
          collaborators += editTaskScreen.getCollaborators().get(i).exportForSQLite(i);
        }
        resultTask.putExtra("Collaborators", collaborators);

        if (taskBundle.getString("Old Category") != null) {
          resultTask.putExtra("Old Category", taskBundle.getString("Old Category"));
          resultTask.putExtra("Old Task Position", taskBundle.getInt("Old Task Position"));
        }

        editTaskScreen.setResult(Activity.RESULT_OK, resultTask);

        editTaskScreen.finish();
        break;

      case (R.id.button_task_due_date):
        // edit due date button
        final String oldDueDate = taskBundle.getString("Due Date");
        c = Calendar.getInstance();

        int mYear = c.get(Calendar.YEAR);
        int mMonth = c.get(Calendar.MONTH);
        int mDay = c.get(Calendar.DAY_OF_MONTH);

        // if task is not a new task and has a due date
        if (!taskBundle.getString("Due Date", "None").equals("None")) {
          try {
            Date oldDate = dateFormat.parse(taskBundle.getString("Due Date"));

            Calendar oldCalendar = Calendar.getInstance();
            oldCalendar.setTime(oldDate);

            mYear = oldCalendar.get(Calendar.YEAR);
            mMonth = oldCalendar.get(Calendar.MONTH);
            mDay = oldCalendar.get(Calendar.DAY_OF_MONTH);

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

        DatePickerDialog datePickerDialog =
            new DatePickerDialog(
                editTaskScreen,
                new DatePickerDialog.OnDateSetListener() {

                  @Override
                  public void onDateSet(
                      DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                    Date pickedDate = Calendar.getInstance().getTime();

                    try {
                      pickedDate =
                          dateFormatInput.parse(
                              year + "/" + (monthOfYear + 1) + "/" + dayOfMonth + " 00:00:00.000");
                    } catch (ParseException e) {
                      e.printStackTrace();
                    }

                    Log.v("Things.DO", "Date chosen: " + dateFormat.format(pickedDate));
                    taskBundle.putString("Due Date", dateFormat.format(pickedDate));

                    String dueDate = taskBundle.getString("Due Date");

                    if (!dueDate.equals("None")) {
                      Date date = Calendar.getInstance().getTime();

                      try {
                        date =
                            (new SimpleDateFormat(editTaskScreen.getString(R.string.date_format)))
                                .parse(dueDate);
                      } catch (ParseException e) {
                        e.printStackTrace();
                      }

                      dueDate =
                          (new SimpleDateFormat(
                                  editTaskScreen.getString(R.string.date_format_display)))
                              .format(date);
                    }

                    editTaskScreen.getSetDueDate().setText(dueDate);
                  }
                },
                mYear,
                mMonth,
                mDay);

        datePickerDialog.setOnCancelListener(
            new DialogInterface.OnCancelListener() {
              @Override
              public void onCancel(DialogInterface dialog) {
                Log.v("Things.DO", "Date picker cancel");
                taskBundle.putString("Due Date", oldDueDate);

                String date = "None";
                if (!oldDueDate.equals("None")) {
                  try {
                    date =
                        (new SimpleDateFormat(
                                editTaskScreen.getString(R.string.date_format_display)))
                            .format(
                                (new SimpleDateFormat(
                                        editTaskScreen.getString(R.string.date_format)))
                                    .parse(oldDueDate));
                  } catch (ParseException e) {
                    e.printStackTrace();
                  }
                }

                editTaskScreen.getSetDueDate().setText(date);
              }
            });

        datePickerDialog.setCancelable(true);
        datePickerDialog.setCanceledOnTouchOutside(true);
        datePickerDialog.setMessage(editTaskScreen.getString(R.string.text_date_picker_question));

        datePickerDialog.show();
        break;

      case (R.id.button_task_priority):
        // edit priority button
        // get dialog builder
        AlertDialog.Builder builder = new AlertDialog.Builder(editTaskScreen);

        // priority options
        final String[] choice = {"Urgent", "High", "Medium", "Low"};

        // try to get task priority
        final String oldPriority = taskBundle.getString("Parent", "Medium");

        int currentChoiceIndex = 0;

        // set default choice
        for (int i = 0; i < choice.length; i++) {
          if (choice[i].equals(oldPriority)) {
            currentChoiceIndex = i;
            break;
          }
        }

        // display dialog
        builder
            .setIconAttribute(android.R.attr.alertDialogIcon)
            .setTitle(editTaskScreen.getString(R.string.text_priority_tittle))
            .setSingleChoiceItems(
                choice,
                currentChoiceIndex,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int whichButton) {
                    Log.v("Things.DO", "Choice: " + choice[whichButton]);
                    taskBundle.putString("Parent", choice[whichButton]);

                    editTaskScreen.getSetTaskPriority().setText(choice[whichButton]);

                    if (choice[whichButton].equals("Urgent")) {
                      ((Button) view)
                          .setCompoundDrawablesWithIntrinsicBounds(
                              null,
                              editTaskScreen
                                  .getResources()
                                  .getDrawable(R.drawable.ic_priority_urgent),
                              null,
                              null);
                    } else {
                      ((Button) view)
                          .setCompoundDrawablesWithIntrinsicBounds(
                              null,
                              editTaskScreen.getResources().getDrawable(R.drawable.ic_priority),
                              null,
                              null);
                    }
                  }
                })
            .setPositiveButton(
                "OK",
                new DialogInterface.OnClickListener() {
                  /**
                   * This method will be invoked when a button in the dialog is clicked.
                   *
                   * @param dialog The dialog that received the click.
                   * @param which The button that was clicked (e.g. {@link
                   *     android.content.DialogInterface#BUTTON1}) or the position
                   */
                  @Override
                  public void onClick(DialogInterface dialog, int which) {}
                })
            .setNegativeButton(
                "Cancel",
                new DialogInterface.OnClickListener() {
                  /**
                   * This method will be invoked when a button in the dialog is clicked.
                   *
                   * @param dialog The dialog that received the click.
                   * @param which The button that was clicked (e.g. {@link
                   *     android.content.DialogInterface#BUTTON1}) or the position
                   */
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    taskBundle.putString("Parent", oldPriority);

                    editTaskScreen.getSetTaskPriority().setText(oldPriority);
                  }
                })
            .create();

        builder.show();
        break;

      case (R.id.button_task_category):
        // edit category
        // get dialog builder
        builder = new AlertDialog.Builder(editTaskScreen);

        // category options
        final String[] categories = taskBundle.getStringArray("Category List");

        // try to get task priority
        final String oldCategory = taskBundle.getString("Category", "Personal");

        currentChoiceIndex = 0;

        // set default choice
        for (int i = 0; i < categories.length; i++) {
          if (categories[i].equals(oldCategory)) {
            currentChoiceIndex = i;
            break;
          }
        }

        // display dialog
        builder
            .setIconAttribute(android.R.attr.alertDialogIcon)
            .setTitle(editTaskScreen.getString(R.string.text_priority_tittle))
            .setSingleChoiceItems(
                categories,
                currentChoiceIndex,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int whichButton) {
                    Log.v("Things.DO", "Choice: " + categories[whichButton]);
                    taskBundle.putString("Category", categories[whichButton]);

                    editTaskScreen.getSetTaskCategory().setText(categories[whichButton]);
                  }
                })
            .setPositiveButton(
                "OK",
                new DialogInterface.OnClickListener() {
                  /**
                   * This method will be invoked when a button in the dialog is clicked.
                   *
                   * @param dialog The dialog that received the click.
                   * @param which The button that was clicked (e.g. {@link
                   *     android.content.DialogInterface#BUTTON1}) or the position
                   */
                  @Override
                  public void onClick(DialogInterface dialog, int which) {}
                })
            .setNegativeButton(
                "Cancel",
                new DialogInterface.OnClickListener() {
                  /**
                   * This method will be invoked when a button in the dialog is clicked.
                   *
                   * @param dialog The dialog that received the click.
                   * @param which The button that was clicked (e.g. {@link
                   *     android.content.DialogInterface#BUTTON1}) or the position
                   */
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    taskBundle.putString("Category", oldCategory);

                    editTaskScreen.getSetTaskCategory().setText(oldCategory);
                  }
                })
            .create();

        builder.show();
        break;

      case (R.id.button_task_add_collaborator):
        editTaskScreen.showContactPicker();

        break;
    }
  }