@Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
      if (requestCode == PLACE_PICKER_REQUEST_CODE) {
        UserPlace place = data.getParcelableExtra(PlacePickerActivity.PLACE_RESULT_KEY);
        Log.d(TAG, place.toString());
        // If a place wasn't selected this is a new place, so save it.
        if (mCurrentPlace == null) {
          place.getPlace().setName(mName.getText().toString().trim());

          // Write the place to the database
          PlaceTableHandler handler = new PlaceTableHandler(this);
          handler.savePlace(place);
          handler.close();

          mAdapter.addPlace(place);
        }
        // Otherwise, this place was edited, so update both, the place and the adapter
        else {
          mCurrentPlace.setLatitude(place.getLatitude());
          mCurrentPlace.setLongitude(place.getLongitude());

          PlaceTableHandler handler = new PlaceTableHandler(this);
          // If the place is primary and not set it won't be in the database, so save
          if (mCurrentPlace.isPrimary() && !mCurrentPlace.isSet()) {
            handler.savePlace(mCurrentPlace);
          }
          // Otherwise it will, so update
          else {
            handler.updatePlace(mCurrentPlace);
          }
          handler.close();

          mCurrentPlace.getPlace().setSet(true);
          mAdapter.notifyDataSetChanged();
        }

        // Once a place is saved, start the location notification service to
        //  update its internal lists of places
        // LocationNotificationService.updateDataSet(this);
      }
    }
  }
  @Override
  public void onClick(View view) {
    String name = mName.getText().toString().trim();

    // If the user didn't input a name, don't let him continue
    if (name.equals("")) {
      Toast.makeText(this, R.string.places_name_dialog_empty, Toast.LENGTH_SHORT).show();
    } else {
      // Check if the name is already set
      boolean duplicate = false;
      for (UserPlace userPlace : mAdapter.getPlaces()) {
        if (userPlace.getName().equals(name)) {
          duplicate = true;
          break;
        }
      }
      // If the name exists, don't let the user continue
      if (duplicate) {
        Toast.makeText(this, R.string.places_name_dialog_chosen, Toast.LENGTH_SHORT).show();
      } else {
        // If everything checks out, dismiss the dialog
        mNameDialog.dismiss();
        // If we are editing the name, then save it
        if (mEdition) {
          mCurrentPlace.getPlace().setName(mName.getText().toString().trim());
          mAdapter.notifyDataSetChanged();
          HttpRequest.put(
              null, API.URL.postPutPlace(mCurrentPlace), API.BODY.postPutPlace(mCurrentPlace));

          // Update the place in the database
          PlaceTableHandler handler = new PlaceTableHandler(this);
          handler.updatePlace(mCurrentPlace);
          handler.close();
        }
        // Otherwise this is a new place request, fire the place picker
        else {
          Intent add = new Intent(this, PlacePickerActivity.class);
          add.putExtra(PlacePickerActivity.PLACE_KEY, new UserPlace(name));
          startActivityForResult(add, PLACE_PICKER_REQUEST_CODE);
        }
      }
    }
  }