@Override
  public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();

    switch (item.getItemId()) {
      case R.id.menu_delete:
        int position = info.position - mNumAvailableServers;
        mCustomServers.remove(position);
        Preferences.setCustomServers(mCustomServers, getActivity());
        refresh();
        return true;

      default:
        return super.onContextItemSelected(item);
    }
  }
  /**
   * Adds a new server JSONObject to Preferences
   *
   * <p>This only updates the Preferences data. You still need make sure that the screen actually
   * reflects this change.
   *
   * @param dialog
   */
  private void saveNewServer(View dialog) {
    final EditText name = (EditText) dialog.findViewById(R.id.name);
    final EditText url = (EditText) dialog.findViewById(R.id.url);
    final EditText jurisdiction = (EditText) dialog.findViewById(R.id.jurisdiction);
    final EditText api_key = (EditText) dialog.findViewById(R.id.api_key);
    final ToggleButton supports_media = (ToggleButton) dialog.findViewById(R.id.supports_media);
    final Spinner format = (Spinner) dialog.findViewById(R.id.format);

    JSONObject server = new JSONObject();
    try {
      server.put(Open311.NAME, name.getText().toString());
      server.put(Open311.URL, url.getText().toString());
      server.put(Open311.JURISDICTION, jurisdiction.getText().toString());
      server.put(Open311.API_KEY, api_key.getText().toString());
      server.put(Open311.SUPPORTS_MEDIA, supports_media.isChecked());
      server.put(Open311.FORMAT, format.getSelectedItem());

      mCustomServers.put(server);
      Preferences.setCustomServers(mCustomServers, getActivity());
    } catch (JSONException e) {
      e.printStackTrace();
    }
  }