gt:             if (isInDeletePreview) {
context: /*
   * Geopaparazzi - Digital field mapping on Android based devices
   * Copyright (C) 2010  HydroloGIS (www.hydrologis.com)
   *
   * This program is free software: you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
   */
  package eu.hydrologis.geopaparazzi.maptools.tools;
  
  import android.content.Context;
  import android.content.Intent;
  import android.graphics.Canvas;
  import android.graphics.Color;
  import android.graphics.Paint;
  import android.graphics.Point;
  import android.graphics.PorterDuff.Mode;
  import android.os.Parcelable;
  import android.view.MotionEvent;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.view.View.OnTouchListener;
  import android.view.ViewGroup.LayoutParams;
  import android.widget.ImageButton;
  import android.widget.LinearLayout;
  
  import com.vividsolutions.jts.android.PointTransformation;
  import com.vividsolutions.jts.android.ShapeWriter;
  import com.vividsolutions.jts.geom.Geometry;
  import com.vividsolutions.jts.io.WKBReader;
  
  import org.mapsforge.android.maps.MapView;
  import org.mapsforge.android.maps.MapViewPosition;
  import org.mapsforge.android.maps.Projection;
  
  import java.util.ArrayList;
  import java.util.List;
  
  import eu.geopaparazzi.library.database.GPLog;
  import eu.geopaparazzi.library.features.EditManager;
  import eu.geopaparazzi.library.features.EditingView;
  import eu.geopaparazzi.library.features.Feature;
  import eu.geopaparazzi.library.features.ILayer;
  import eu.geopaparazzi.library.features.Tool;
  import eu.geopaparazzi.library.features.ToolGroup;
  import eu.geopaparazzi.library.util.ColorUtilities;
  import eu.geopaparazzi.spatialite.database.spatial.core.daos.DaoSpatialite;
  import eu.hydrologis.geopaparazzi.R;
  import eu.hydrologis.geopaparazzi.maps.MapsSupportService;
  import eu.hydrologis.geopaparazzi.maps.overlays.MapsforgePointTransformation;
  import eu.hydrologis.geopaparazzi.maps.overlays.SliderDrawProjection;
  import eu.hydrologis.geopaparazzi.maptools.CopyToLayersListActivity;
  import eu.hydrologis.geopaparazzi.maptools.FeaturePagerActivity;
  import eu.hydrologis.geopaparazzi.maptools.FeatureUtilities;
  
  /**
   * The group of tools active when a selection has been done.
   * 
   * @author Andrea Antonello (www.hydrologis.com)
   */
  public class OnSelectionToolGroup implements ToolGroup, OnClickListener, OnTouchListener {
  
      private MapView mapView;
  
      private int buttonSelectionColor;
      private List<Feature> selectedFeatures = new ArrayList<Feature>();
      private ImageButton deleteFeatureButton;
      private SliderDrawProjection editingViewProjection;
  
      private Paint geometryPaintStroke = new Paint();
      private Paint geometryPaintFill = new Paint();
  
      private final Paint selectedGeometryPaintStroke = new Paint();
      private final Paint selectedGeometryPaintFill = new Paint();
      private final Paint selectedPreviewGeometryPaintStroke = new Paint();
      private final Paint selectedPreviewGeometryPaintFill = new Paint();
  
      private WKBReader wkbReader = new WKBReader();
  
      /**
       * Stores the top-left map position at which the redraw should happen.
       */
      private final Point point;
  
      /**
       * Stores the map position after drawing is finished.
       */
      private Point positionBeforeDraw;
      private ImageButton editAttributesButton;
  
      private boolean isInDeletePreview;
  
      private ImageButton commitButton;
  
      private ImageButton undoButton;
      private ImageButton copyFeatureButton;
  
      /**
       * Constructor.
       * 
       * @param mapView the map view.
       * @param selectedFeatures the set of selected features.
       */
      public OnSelectionToolGroup( MapView mapView, List<Feature> selectedFeatures ) {
          this.mapView = mapView;
          this.selectedFeatures.addAll(selectedFeatures);
  
          EditingView editingView = EditManager.INSTANCE.getEditingView();
          editingViewProjection = new SliderDrawProjection(mapView, editingView);
          buttonSelectionColor = editingView.getContext().getResources().getColor(R.color.main_selection);
  
  
          int stroke = ColorUtilities.getColor(ColorUtilities.selection_stroke);
          int fill = ColorUtilities.getColor(ColorUtilities.selection_fill);
          selectedGeometryPaintFill.setAntiAlias(true);
          selectedGeometryPaintFill.setColor(fill);
          selectedGeometryPaintFill.setAlpha(180);
          selectedGeometryPaintFill.setStyle(Paint.Style.FILL);
          selectedGeometryPaintStroke.setAntiAlias(true);
          selectedGeometryPaintStroke.setStrokeWidth(5f);
          selectedGeometryPaintStroke.setColor(stroke);
          selectedGeometryPaintStroke.setStyle(Paint.Style.STROKE);
  
          stroke = ColorUtilities.getColor(ColorUtilities.preview_stroke);
          fill = ColorUtilities.getColor(ColorUtilities.preview_fill);
          selectedPreviewGeometryPaintFill.setAntiAlias(true);
          selectedPreviewGeometryPaintFill.setColor(fill);
          selectedPreviewGeometryPaintFill.setAlpha(180);
          selectedPreviewGeometryPaintFill.setStyle(Paint.Style.FILL);
          selectedPreviewGeometryPaintStroke.setAntiAlias(true);
          selectedPreviewGeometryPaintStroke.setStrokeWidth(5f);
          selectedPreviewGeometryPaintStroke.setColor(stroke);
          selectedPreviewGeometryPaintStroke.setStyle(Paint.Style.STROKE);
  
          geometryPaintFill = selectedGeometryPaintFill;
          geometryPaintStroke = selectedGeometryPaintStroke;
  
          point = new Point();
          positionBeforeDraw = new Point();
      }
  
      public void activate() {
          if (mapView != null)
              mapView.setClickable(true);
      }
  
      public void initUI() {
          LinearLayout parent = EditManager.INSTANCE.getToolsLayout();
          parent.removeAllViews();
  
          Context context = parent.getContext();
          ILayer editLayer = EditManager.INSTANCE.getEditLayer();
          int padding = 2;
  
          if (editLayer != null) {
              deleteFeatureButton = new ImageButton(context);
              deleteFeatureButton.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                      LayoutParams.WRAP_CONTENT));
              deleteFeatureButton.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.ic_editing_delete_feature));
              deleteFeatureButton.setPadding(0, padding, 0, padding);
              deleteFeatureButton.setOnTouchListener(this);
              deleteFeatureButton.setOnClickListener(this);
              parent.addView(deleteFeatureButton);
  
              copyFeatureButton = new ImageButton(context);
              copyFeatureButton.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                      LayoutParams.WRAP_CONTENT));
              copyFeatureButton.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.ic_editing_copy_geoms));
              copyFeatureButton.setPadding(0, padding, 0, padding);
              copyFeatureButton.setOnTouchListener(this);
              copyFeatureButton.setOnClickListener(this);
              parent.addView(copyFeatureButton);
  
              editAttributesButton = new ImageButton(context);
              editAttributesButton.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                      LayoutParams.WRAP_CONTENT));
              editAttributesButton.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.ic_editing_view_attributes));
              editAttributesButton.setPadding(0, padding, 0, padding);
              editAttributesButton.setOnTouchListener(this);
              editAttributesButton.setOnClickListener(this);
              parent.addView(editAttributesButton);
  
              undoButton = new ImageButton(context);
              undoButton.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
              undoButton.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.ic_editing_undo));
              undoButton.setPadding(0, padding, 0, padding);
              undoButton.setOnTouchListener(this);
              undoButton.setOnClickListener(this);
              parent.addView(undoButton);
  
              commitButton = new ImageButton(context);
              commitButton.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
              commitButton.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.ic_editing_commit));
              commitButton.setPadding(0, padding, 0, padding);
              commitButton.setOnTouchListener(this);
              commitButton.setOnClickListener(this);
              parent.addView(commitButton);
              commitButton.setVisibility(View.GONE);
          }
      }
  
      public void disable() {
          LinearLayout parent = EditManager.INSTANCE.getToolsLayout();
          if (parent != null)
              parent.removeAllViews();
          parent = null;
      }
  
      public void onClick( View v ) {
          if (v == editAttributesButton) {
              if (selectedFeatures.size() > 0) {
                  Context context = v.getContext();
                  Intent intent = new Intent(context, FeaturePagerActivity.class);
                  intent.putParcelableArrayListExtra(FeatureUtilities.KEY_FEATURESLIST,
                          (ArrayList< ? extends Parcelable>) selectedFeatures);
                  intent.putExtra(FeatureUtilities.KEY_READONLY, false);
                  context.startActivity(intent);
              }
          } else if (v == deleteFeatureButton) {
              if (!isInDeletePreview) {
                  isInDeletePreview = true;
                  geometryPaintFill = selectedPreviewGeometryPaintFill;
                  geometryPaintStroke = selectedPreviewGeometryPaintStroke;
                  commitButton.setVisibility(View.VISIBLE);
                  EditManager.INSTANCE.invalidateEditingView();
              }
          } else if (v == copyFeatureButton) {
              if (selectedFeatures.size() > 0) {
                  List<Feature> copySelectedFeatures = new ArrayList<Feature>(selectedFeatures);
                  Context context = v.getContext();
                  Intent intent = new Intent(context, CopyToLayersListActivity.class);
                  intent.putParcelableArrayListExtra(FeatureUtilities.KEY_FEATURESLIST,
                          (ArrayList< ? extends Parcelable>) copySelectedFeatures);
                  context.startActivity(intent);
  
                  selectedFeatures.clear();
                  EditManager.INSTANCE.setActiveToolGroup(new MainEditingToolGroup(mapView));
                  EditManager.INSTANCE.setActiveTool(null);
  
              }
          } else if (v == undoButton) {
  