@Override
  public boolean onContextItemSelected(MenuItem item) {
    final SipProfile account = profileFromContextMenuInfo(item.getMenuInfo());
    if (account == null) {
      // For some reason the requested item isn't available, do nothing
      return super.onContextItemSelected(item);
    }

    switch (item.getItemId()) {
      case MENU_ITEM_DELETE:
        {
          getActivity()
              .getContentResolver()
              .delete(
                  ContentUris.withAppendedId(SipProfile.ACCOUNT_ID_URI_BASE, account.id),
                  null,
                  null);
          return true;
        }
      case MENU_ITEM_MODIFY:
        {
          showDetails(account.id, account.wizard);
          return true;
        }
      case MENU_ITEM_ACTIVATE:
        {
          ContentValues cv = new ContentValues();
          cv.put(SipProfile.FIELD_ACTIVE, !account.active);
          getActivity()
              .getContentResolver()
              .update(
                  ContentUris.withAppendedId(SipProfile.ACCOUNT_ID_URI_BASE, account.id),
                  cv,
                  null,
                  null);
          return true;
        }
      case MENU_ITEM_WIZARD:
        {
          Intent it = new Intent(getActivity(), WizardChooser.class);
          it.putExtra(Intent.EXTRA_UID, account.id);
          startActivityForResult(it, CHANGE_WIZARD);
          return true;
        }
    }
    return super.onContextItemSelected(item);
  }
Esempio n. 2
0
  @Override
  public boolean onOptionsItemSelected(final MenuItem item) {
    Intent intent;
    long itemId;

    if (!isCurrentTaskListFragment()) return false;

    // handle my own menus
    if (handleOptionsMenuItemSelected(item.getItemId(), item.getIntent())) return true;

    switch (item.getItemId()) {
        // --- context menu items

      case CONTEXT_MENU_BROADCAST_INTENT_ID:
        {
          intent = item.getIntent();
          getActivity().sendBroadcast(intent);
          return true;
        }
      case CONTEXT_MENU_EDIT_TASK_ID:
        {
          itemId = item.getGroupId();
          mListener.onTaskListItemClicked(itemId);
          return true;
        }
      case CONTEXT_MENU_COPY_TASK_ID:
        {
          itemId = item.getGroupId();
          duplicateTask(itemId);
          return true;
        }
      case CONTEXT_MENU_DELETE_TASK_ID:
        {
          itemId = item.getGroupId();
          Task task = new Task();
          task.setId(itemId);
          deleteTask(task);
          return true;
        }
      case CONTEXT_MENU_UNDELETE_TASK_ID:
        {
          itemId = item.getGroupId();
          Task task = new Task();
          task.setId(itemId);
          task.setValue(Task.DELETION_DATE, 0L);
          taskService.save(task);
          loadTaskListContent(true);
          return true;
        }
      case CONTEXT_MENU_PURGE_TASK_ID:
        {
          itemId = item.getGroupId();
          Task task = new Task();
          task.setId(itemId);
          TimerPlugin.updateTimer(getActivity(), task, false);
          taskService.purge(itemId);
          loadTaskListContent(true);
          return true;
        }
      default:
        {
          if (item.getItemId() < CONTEXT_MENU_PLUGIN_ID_FIRST) return false;
          if (item.getItemId() - CONTEXT_MENU_PLUGIN_ID_FIRST >= contextItemExposers.length)
            return false;

          AdapterContextMenuInfo adapterInfo = (AdapterContextMenuInfo) item.getMenuInfo();
          Task task = ((ViewHolder) adapterInfo.targetView.getTag()).task;
          contextItemExposers[item.getItemId() - CONTEXT_MENU_PLUGIN_ID_FIRST].invoke(task);

          return true;
        }
    }
  }