public LocalTime getTime() {
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
     return new LocalTime(mTimePicker.getHour(), mTimePicker.getMinute());
   } else {
     return new LocalTime(mTimePicker.getCurrentHour(), mTimePicker.getCurrentMinute());
   }
 }
Exemplo n.º 2
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_cancel) {
      Intent intent = new Intent(this, TasksList.class);
      startActivity(intent);
      return true;
    } else if (id == R.id.action_delete) {
      DBHandlerSingleton.getInstance(getApplicationContext()).deleteTask(task_id);
      Intent intent = new Intent(this, TasksList.class);
      startActivity(intent);
      return true;
    } else if (id == R.id.action_modify) {
      EditText editTextName = (EditText) findViewById(R.id.editTextTaskName);
      EditText editTextDesc = (EditText) findViewById(R.id.editTextTaskDescription);
      DatePicker datePicker = (DatePicker) findViewById(R.id.datePickerTask);
      TimePicker time = (TimePicker) findViewById(R.id.timePickerTask);
      CheckBox checkBox = (CheckBox) findViewById(R.id.checkBoxTaskDetail);
      task_name = editTextName.getText().toString();
      task_desc = editTextDesc.getText().toString();
      int currentapiVersion = android.os.Build.VERSION.SDK_INT;
      if (currentapiVersion >= Build.VERSION_CODES.M) {
        task_limitedate =
            Integer.toString(datePicker.getYear())
                + "-"
                + Integer.toString(datePicker.getMonth() + 1)
                + "-"
                + Integer.toString(datePicker.getDayOfMonth())
                + "-"
                + Integer.toString(time.getHour())
                + ":"
                + Integer.toString(time.getMinute());
      } else {
        task_limitedate =
            Integer.toString(datePicker.getYear())
                + "-"
                + Integer.toString(datePicker.getMonth() + 1)
                + "-"
                + Integer.toString(datePicker.getDayOfMonth())
                + "-"
                + Integer.toString(time.getCurrentHour())
                + ":"
                + Integer.toString(time.getCurrentMinute());
      }

      DBHandlerSingleton.getInstance(getApplicationContext())
          .updateTask(task_id, task_name, task_desc, task_limitedate);
      DBHandlerSingleton.getInstance(getApplicationContext()).setColorTask(task_id, task_color);
      DBHandlerSingleton.getInstance(getApplicationContext()).setTaskDone(task_id, task_done);
      Intent intent = new Intent(this, TasksList.class);
      startActivity(intent);
      return true;
    } else if (id == R.id.action_logout) {
      MainUserSingleton.getInstance().disconnect(getApplicationContext());
      Intent intent = new Intent(this, MainActivity.class);
      startActivity(intent);
      return true;
    }
    return super.onOptionsItemSelected(item);
  }