@Override
  public boolean onOptionsItemSelected(MenuItem item) {
    if ((mPopupContainer == null) || (mPopupContainer.getPopupCount() <= 0)) return true;

    Popup popup = mPopupContainer.getCurrentPopup();
    switch (item.getItemId()) {
      case R.id.menu_camera:
        startActivityForResult(
            new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI), 1);
        break;
      case R.id.menu_delete:
        deleteFeature(popup);
        break;
      case R.id.menu_edit:
        ViewGroup view = popup.getLayout().getLayout();
        LinearLayout ll = (LinearLayout) view.findViewById(R.id.second_inner_linearlayout);
        if (ll != null) ll.setVisibility(View.GONE);
        editFeature(popup);
        break;
      case R.id.menu_save:
        saveFeature(popup);
        break;
    }

    return true;
  }
  @Override
  public void onPrepareOptionsMenu(Menu menu) {

    // Turn on/off menu items based on popup's edit capabilities
    for (int i = 0; i < menu.size(); i++) {
      MenuItem item = menu.getItem(i);
      if (mPopupContainer != null) {
        Popup popup = mPopupContainer.getCurrentPopup();
        if (popup != null) {
          if (popup.isEditMode()) {
            if ((item.getItemId() == R.id.menu_save) || (item.getItemId() == R.id.menu_camera)) {
              item.setVisible(true);
              item.setEnabled(true);
            } else {
              item.setVisible(false);
              item.setEnabled(false);
            }
          } else {
            if (((item.getItemId() == R.id.menu_edit) && (popup.isEditable()))
                || ((item.getItemId() == R.id.menu_delete) && (popup.isDeletable()))) {
              item.setVisible(true);
              item.setEnabled(true);
            } else {
              item.setVisible(false);
              item.setEnabled(false);
            }
          }
        } else {
          item.setVisible(false);
          item.setEnabled(false);
        }
      } else {
        item.setVisible(false);
        item.setEnabled(false);
      }
    }
  }
  // Get the feature layer which is associated with the current popup
  private ArcGISFeatureLayer getFeatureLayer(Popup popup) {
    ArcGISFeatureLayer featureLayer = null;

    if ((mMapView == null) || (popup == null)) return null;
    PopupInfo popupInfo = popup.getPopupInfo();
    if (popupInfo instanceof ArcGISPopupInfo) {
      ArcGISPopupInfo agsPopupInfo = (ArcGISPopupInfo) popupInfo;
      Layer[] layers = mMapView.getLayers();
      for (Layer layer : layers) {
        if ((layer instanceof ArcGISFeatureLayer)
            && (layer.getUrl().compareToIgnoreCase(agsPopupInfo.getLayerUrl()) == 0)) {
          featureLayer = (ArcGISFeatureLayer) layer;
          return featureLayer;
        }
      }
    }

    return featureLayer;
  }