public void initUI() {

    LinearLayout parent = EditManager.INSTANCE.getToolsLayout();
    Context context = parent.getContext();
    ILayer editLayer = EditManager.INSTANCE.getEditLayer();
    int padding = 2;

    if (editLayer != null) {
      createFeatureButton = new ImageButton(context);
      createFeatureButton.setLayoutParams(
          new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
      createFeatureButton.setBackground(
          Compat.getDrawable(context, R.drawable.editing_create_line));
      createFeatureButton.setPadding(0, padding, 0, padding);
      createFeatureButton.setOnClickListener(this);
      createFeatureButton.setOnTouchListener(this);
      parent.addView(createFeatureButton);

      selectEditableButton = new ImageButton(context);
      selectEditableButton.setLayoutParams(
          new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
      selectEditableButton.setBackground(
          Compat.getDrawable(context, R.drawable.editing_select_editable));
      selectEditableButton.setPadding(0, padding, 0, padding);
      selectEditableButton.setOnClickListener(this);
      selectEditableButton.setOnTouchListener(this);
      parent.addView(selectEditableButton);
    }

    selectAllButton = new ImageButton(context);
    selectAllButton.setLayoutParams(
        new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    selectAllButton.setBackground(Compat.getDrawable(context, R.drawable.editing_select_all));
    selectAllButton.setPadding(0, padding, 0, padding);
    selectAllButton.setOnClickListener(this);
    selectAllButton.setOnTouchListener(this);
    parent.addView(selectAllButton);

    if (editLayer != null) {
      undoButton = new ImageButton(context);
      undoButton.setLayoutParams(
          new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
      undoButton.setBackground(Compat.getDrawable(context, R.drawable.editing_undo));
      undoButton.setPadding(0, padding, 0, padding);
      undoButton.setOnTouchListener(this);
      undoButton.setOnClickListener(this);
      parent.addView(undoButton);
      undoButton.setVisibility(View.GONE);

      commitButton = new ImageButton(context);
      commitButton.setLayoutParams(
          new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
      commitButton.setBackground(Compat.getDrawable(context, R.drawable.editing_commit));
      commitButton.setPadding(0, padding, 0, padding);
      commitButton.setOnTouchListener(this);
      commitButton.setOnClickListener(this);
      parent.addView(commitButton);
      commitButton.setVisibility(View.GONE);
    }
  }
  /**
   * Constructor.
   *
   * @param mapView the mapview reference.
   * @param doCut if <code>true</code>, do cut as opposed to extend.
   */
  public CutExtendTool(MapView mapView, boolean doCut) {
    super(mapView);
    this.doCut = doCut;
    editingViewProjection =
        new SliderDrawProjection(mapView, EditManager.INSTANCE.getEditingView());

    point = new Point();
    positionBeforeDraw = new Point();

    // Context context = GeopaparazziApplication.getInstance().getApplicationContext();
    // SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    drawingPaintFill.setAntiAlias(true);
    drawingPaintFill.setColor(Color.RED);
    // drawingPaintFill.setAlpha(80);
    drawingPaintFill.setStyle(Paint.Style.FILL);
    drawingPaintStroke.setAntiAlias(true);
    drawingPaintStroke.setStrokeWidth(5f);
    drawingPaintStroke.setColor(Color.RED);
    drawingPaintStroke.setStyle(Paint.Style.STROKE);

    int previewStroke = ColorUtilities.getColor(ColorUtilities.preview_stroke);
    int previewFill = ColorUtilities.getColor(ColorUtilities.preview_fill);
    selectedPreviewGeometryPaintFill.setAntiAlias(true);
    selectedPreviewGeometryPaintFill.setColor(previewFill);
    selectedPreviewGeometryPaintFill.setAlpha(180);
    selectedPreviewGeometryPaintFill.setStyle(Paint.Style.FILL);
    selectedPreviewGeometryPaintStroke.setAntiAlias(true);
    selectedPreviewGeometryPaintStroke.setStrokeWidth(5f);
    selectedPreviewGeometryPaintStroke.setColor(previewStroke);
    selectedPreviewGeometryPaintStroke.setStyle(Paint.Style.STROKE);
  }
  public void onClick(View v) {
    if (v == selectAllButton) {
      Tool currentTool = EditManager.INSTANCE.getActiveTool();
      if (currentTool != null && currentTool instanceof InfoTool) {
        // if the same tool is re-selected, it is disabled
        EditManager.INSTANCE.setActiveTool(null);
      } else {
        // check maps enablement
        try {
          final Collection<SpatialVectorTable> spatialTables =
              SpatialiteSourcesManager.INSTANCE.getSpatialiteMaps2TablesMap().values();
          boolean atLeastOneEnabled = false;
          for (SpatialVectorTable spatialVectorTable : spatialTables) {
            if (spatialVectorTable.getStyle().enabled == 1) {
              atLeastOneEnabled = true;
              break;
            }
          }
          if (!atLeastOneEnabled) {
            LinearLayout parent = EditManager.INSTANCE.getToolsLayout();
            if (parent != null) {
              Context context = parent.getContext();
              GPDialogs.warningDialog(
                  context, context.getString(R.string.no_queriable_layer_is_visible), null);
            }
            return;
          }
        } catch (Exception e) {
          GPLog.error(this, null, e);
        }

        Tool activeTool = new InfoTool(this, mapView);
        EditManager.INSTANCE.setActiveTool(activeTool);
      }
    } else if (v == selectEditableButton) {
      Tool currentTool = EditManager.INSTANCE.getActiveTool();
      if (currentTool != null && currentTool instanceof SelectionTool) {
        // if the same tool is re-selected, it is disabled
        EditManager.INSTANCE.setActiveTool(null);
      } else {
        Tool activeTool = new SelectionTool(mapView);
        EditManager.INSTANCE.setActiveTool(activeTool);
      }
    } else if (v == createFeatureButton) {
      ToolGroup createFeatureToolGroup = new LineCreateFeatureToolGroup(mapView, null);
      EditManager.INSTANCE.setActiveToolGroup(createFeatureToolGroup);
    } else if (v == undoButton) {
      //            if (cutExtendProcessedFeature != null) {
      //                EditManager.INSTANCE.setActiveTool(null);
      //                commitButton.setVisibility(View.GONE);
      //                undoButton.setVisibility(View.GONE);
      //                EditManager.INSTANCE.invalidateEditingView();
      //            }
    }

    handleToolIcons(v);
  }
 @Override
 public void onViewChanged() {
   EditingView editingView = EditManager.INSTANCE.getEditingView();
   try {
     readData(editingView);
   } catch (IOException e) {
     GPLog.error(this, null, e);
   }
 }
  public boolean onToolTouchEvent(MotionEvent event) {
    if (mapView == null || mapView.isClickable()) {
      return false;
    }
    Projection pj = editingViewProjection;

    // handle drawing
    currentX = event.getX();
    currentY = event.getY();

    int action = event.getAction();
    switch (action) {
      case MotionEvent.ACTION_DOWN:
        startGeoPoint = pj.fromPixels(round(currentX), round(currentY));
        pj.toPixels(startGeoPoint, startP);
        endP.set(startP.x, startP.y);

        drawingPath.reset();
        drawingPath.moveTo(startP.x, startP.y);

        lastX = currentX;
        lastY = currentY;
        break;
      case MotionEvent.ACTION_MOVE:
        float dx = currentX - lastX;
        float dy = currentY - lastY;
        if (abs(dx) < 1 && abs(dy) < 1) {
          lastX = currentX;
          lastY = currentY;
          return true;
        }
        GeoPoint currentGeoPoint = pj.fromPixels(round(currentX), round(currentY));
        pj.toPixels(currentGeoPoint, tmpP);
        drawingPath.lineTo(tmpP.x, tmpP.y);
        endP.set(tmpP.x, tmpP.y);

        EditManager.INSTANCE.invalidateEditingView();
        break;
      case MotionEvent.ACTION_UP:
        GeoPoint endGeoPoint = pj.fromPixels(round(currentX), round(currentY));
        GeometryFactory gf = new GeometryFactory();
        Coordinate startCoord =
            new Coordinate(startGeoPoint.getLongitude(), startGeoPoint.getLatitude());
        com.vividsolutions.jts.geom.Point startPoint = gf.createPoint(startCoord);
        Coordinate endCoord = new Coordinate(endGeoPoint.getLongitude(), endGeoPoint.getLatitude());
        com.vividsolutions.jts.geom.Point endPoint = gf.createPoint(endCoord);
        Envelope env = new Envelope(startCoord, endCoord);
        select(env.getMaxY(), env.getMinX(), env.getMinY(), env.getMaxX(), startPoint, endPoint);
        //            EditManager.INSTANCE.invalidateEditingView();
        break;
    }

    return true;
  }
  public boolean onToolTouchEvent(MotionEvent event) {
    if (mapView == null || mapView.isClickable()) {
      return false;
    }
    Projection pj = editingViewProjection;

    // handle drawing
    float currentX = event.getX();
    float currentY = event.getY();

    int action = event.getAction();
    switch (action) {
      case MotionEvent.ACTION_DOWN:
        GeoPoint startGeoPoint = pj.fromPixels(round(currentX), round(currentY));
        pj.toPixels(startGeoPoint, startP);

        lastX = currentX;
        lastY = currentY;
        break;
      case MotionEvent.ACTION_MOVE:
        float dx = currentX - lastX;
        float dy = currentY - lastY;
        if (abs(dx) < 1 && abs(dy) < 1) {
          lastX = currentX;
          lastY = currentY;
          return true;
        }
        GeoPoint currentGeoPoint = pj.fromPixels(round(currentX), round(currentY));
        pj.toPixels(currentGeoPoint, tmpP);

        left = Math.min(tmpP.x, startP.x);
        right = Math.max(tmpP.x, startP.x);
        bottom = Math.max(tmpP.y, startP.y);
        top = Math.min(tmpP.y, startP.y);
        rect.set((int) left, (int) top, (int) right, (int) bottom);

        EditManager.INSTANCE.invalidateEditingView();
        break;
      case MotionEvent.ACTION_UP:
        float deltaY = abs(top - bottom);
        float deltaX = abs(right - left);
        if (deltaX > TOUCH_BOX_THRES && deltaY > TOUCH_BOX_THRES) {
          GeoPoint ul = pj.fromPixels((int) left, (int) top);
          GeoPoint lr = pj.fromPixels((int) right, (int) bottom);

          select(ul.getLatitude(), ul.getLongitude(), lr.getLatitude(), lr.getLongitude());
        }

        break;
    }

    return true;
  }
  public boolean onToolTouchEvent(MotionEvent event) {
    if (mapView == null || mapView.isClickable()) {
      return false;
    }

    Projection pj = mapView.getProjection();
    // handle drawing
    float currentX = event.getX();
    float currentY = event.getY();
    int deltaPixels = 100;

    int action = event.getAction();
    switch (action) {
      case MotionEvent.ACTION_DOWN:
      case MotionEvent.ACTION_MOVE:
        GeoPoint currentGeoPoint = pj.fromPixels(round(currentX), round(currentY));
        GeoPoint plusPoint =
            pj.fromPixels(round(currentX + deltaPixels), round(currentY + deltaPixels));

        double touchLon = currentGeoPoint.getLongitude();
        double touchLat = currentGeoPoint.getLatitude();
        double lonPlus = plusPoint.getLongitude();
        double latPlus = plusPoint.getLatitude();
        double deltaX = Math.abs(touchLon - lonPlus);
        double deltaY = Math.abs(touchLat - latPlus);
        Coordinate touchCoord = new Coordinate(touchLon, touchLat);
        Envelope queryEnvelope = new Envelope(touchCoord);
        queryEnvelope.expandBy(deltaX, deltaY);

        List<GpsLogInfo> result = gpsLogInfoTree.query(queryEnvelope);
        if (result.size() == 0) {
          return true;
        } else {
          GpsLogInfo nearest = null;
          double minDist = Double.POSITIVE_INFINITY;
          for (GpsLogInfo info : result) {
            double dist = touchCoord.distance(info.pointXYZ);
            if (dist < minDist) {
              minDist = dist;
              nearest = info;
            }
          }
          gpsLogInfo = nearest;
        }
        break;
      case MotionEvent.ACTION_UP:
        gpsLogInfo = null;
        break;
    }
    EditManager.INSTANCE.invalidateEditingView();
    return true;
  }
  /**
   * Constructor.
   *
   * @param mapView the mapview reference.
   */
  public SelectionTool(MapView mapView) {
    super(mapView);
    editingViewProjection =
        new SliderDrawProjection(mapView, EditManager.INSTANCE.getEditingView());

    int stroke = ColorUtilities.toColor(ToolColors.selection_stroke.getHex());
    int fill = ColorUtilities.toColor(ToolColors.selection_fill.getHex());
    selectRectPaintFill.setAntiAlias(true);
    selectRectPaintFill.setColor(fill);
    selectRectPaintFill.setAlpha(80);
    selectRectPaintFill.setStyle(Paint.Style.FILL);
    selectRectPaintStroke.setAntiAlias(true);
    selectRectPaintStroke.setStrokeWidth(1.5f);
    selectRectPaintStroke.setColor(stroke);
    selectRectPaintStroke.setStyle(Paint.Style.STROKE);
  }
 @SuppressWarnings("deprecation")
 private void handleToolIcons(View activeToolButton) {
   Context context = activeToolButton.getContext();
   Tool currentTool = EditManager.INSTANCE.getActiveTool();
   if (selectEditableButton != null) {
     if (currentTool != null && activeToolButton == selectEditableButton) {
       selectEditableButton.setBackground(
           Compat.getDrawable(context, R.drawable.editing_select_editable_active));
     } else {
       selectEditableButton.setBackground(
           Compat.getDrawable(context, R.drawable.editing_select_editable));
     }
   }
   if (selectAllButton != null)
     if (currentTool != null && activeToolButton == selectAllButton) {
       selectAllButton.setBackground(
           Compat.getDrawable(context, R.drawable.editing_select_all_active));
     } else {
       selectAllButton.setBackground(Compat.getDrawable(context, R.drawable.editing_select_all));
     }
 }
  /**
   * Constructor.
   *
   * @param mapView the mapview reference.
   */
  public GpsLogInfoTool(MapView mapView) throws IOException {
    super(mapView);

    Context context = GeopaparazziApplication.getInstance().getApplicationContext();
    pixel =
        (int)
            TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, 16, context.getResources().getDisplayMetrics());

    timeString = context.getString(R.string.utctime);
    lonString = context.getString(R.string.lon);
    latString = context.getString(R.string.lat);
    altimString = context.getString(R.string.altim);

    EditingView editingView = EditManager.INSTANCE.getEditingView();
    projection = new SliderDrawProjection(mapView, editingView);

    readData(editingView);

    whiteBoxPaint.setAntiAlias(false);
    whiteBoxPaint.setColor(Color.argb(160, 255, 255, 255));
    whiteBoxPaint.setStyle(Paint.Style.FILL);
  }
Beispiel #11
0
  private void select(final double n, final double w, final double s, final double e) {

    ILayer editLayer = EditManager.INSTANCE.getEditLayer();
    SpatialVectorTableLayer layer = (SpatialVectorTableLayer) editLayer;
    final SpatialVectorTable spatialVectorTable = layer.getSpatialVectorTable();

    final Context context = EditManager.INSTANCE.getEditingView().getContext();
    infoProgressDialog = new ProgressDialog(context);
    infoProgressDialog.setCancelable(true);
    infoProgressDialog.setTitle("SELECT");
    infoProgressDialog.setMessage("Selecting features...");
    infoProgressDialog.setCancelable(false);
    infoProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    infoProgressDialog.setIndeterminate(true);
    infoProgressDialog.show();

    // TODO fix this asynctask
    new AsyncTask<String, Integer, String>() {
      private List<Feature> features = new ArrayList<>();

      protected String doInBackground(String... params) {
        try {
          features.clear();
          double north = n;
          double south = s;
          if (n - s == 0) {
            south = n - 1;
          }
          double west = w;
          double east = e;
          if (e - w == 0) {
            west = e - 1;
          }

          String query =
              SpatialiteUtilities.getBboxIntersectingFeaturesQuery(
                  LibraryConstants.SRID_WGS84_4326, spatialVectorTable, north, south, east, west);
          features = FeatureUtilities.buildFeatures(query, spatialVectorTable);

          return "";
        } catch (Exception e) {
          GPLog.error(this, null, e); // $NON-NLS-1$
          return "ERROR: " + e.getLocalizedMessage();
        }
      }

      protected void onProgressUpdate(Integer... progress) { // on UI thread!
        if (infoProgressDialog != null && infoProgressDialog.isShowing())
          infoProgressDialog.incrementProgressBy(progress[0]);
      }

      protected void onPostExecute(String response) { // on UI thread!
        GPDialogs.dismissProgressDialog(infoProgressDialog);
        if (response.startsWith("ERROR")) {
          GPDialogs.warningDialog(context, response, null);
        } else if (response.startsWith("CANCEL")) {
          return;
        } else {
          if (features.size() > 0) {
            try {
              int geomsCount = 0;
              for (Feature feature : features) {
                Geometry geometry = FeatureUtilities.getGeometry(feature);
                if (geometry != null) geomsCount = geomsCount + geometry.getNumGeometries();
              }
              if (spatialVectorTable.isPolygon()) {
                GPDialogs.toast(
                    context,
                    String.format(
                        context.getString(R.string.selected_features_in_layer),
                        features.size(),
                        geomsCount),
                    Toast.LENGTH_SHORT);
                PolygonOnSelectionToolGroup selectionGroup =
                    new PolygonOnSelectionToolGroup(mapView, features);
                EditManager.INSTANCE.setActiveToolGroup(selectionGroup);
              } else if (spatialVectorTable.isLine()) {
                GPDialogs.toast(
                    context,
                    String.format(
                        context.getString(R.string.selected_line_features_in_layer),
                        features.size(),
                        geomsCount),
                    Toast.LENGTH_SHORT);
                LineOnSelectionToolGroup selectionGroup =
                    new LineOnSelectionToolGroup(mapView, features);
                EditManager.INSTANCE.setActiveToolGroup(selectionGroup);
              }
            } catch (java.lang.Exception e) {
              GPLog.error(this, null, e); // $NON-NLS-1$
            }

          } else {
            rect.setEmpty();
            EditManager.INSTANCE.invalidateEditingView();
          }
        }
      }
    }.execute((String) null);
  }
  private void select(
      final double n,
      final double w,
      final double s,
      final double e, //
      final com.vividsolutions.jts.geom.Point startPoint,
      final com.vividsolutions.jts.geom.Point endPoint) {

    ILayer editLayer = EditManager.INSTANCE.getEditLayer();
    SpatialVectorTableLayer layer = (SpatialVectorTableLayer) editLayer;
    final SpatialVectorTable spatialVectorTable = layer.getSpatialVectorTable();

    final Context context = EditManager.INSTANCE.getEditingView().getContext();
    final ProgressDialog infoProgressDialog = new ProgressDialog(context);
    infoProgressDialog.setCancelable(true);
    infoProgressDialog.setTitle("SELECT");
    infoProgressDialog.setMessage("Selecting features...");
    infoProgressDialog.setCancelable(false);
    infoProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    infoProgressDialog.setIndeterminate(true);
    infoProgressDialog.show();

    new AsyncTask<String, Integer, String>() {

      protected String doInBackground(String... params) {
        try {
          double north = n;
          double south = s;
          if (n - s == 0) {
            south = n - 1;
          }
          double west = w;
          double east = e;
          if (e - w == 0) {
            west = e - 1;
          }

          String query =
              SpatialiteUtilities.getBboxIntersectingFeaturesQuery(
                  LibraryConstants.SRID_WGS84_4326, spatialVectorTable, north, south, east, west);
          List<Feature> features = FeatureUtilities.buildFeatures(query, spatialVectorTable);
          Geometry startGeometry = null;
          Geometry endGeometry = null;
          for (Feature feature : features) {
            if (startGeometry != null && endGeometry != null) break;
            Geometry geometry = FeatureUtilities.getGeometry(feature);
            if (startGeometry == null && geometry.intersects(startPoint)) {
              startGeometry = geometry;
              startFeature = feature;
            } else if (endGeometry == null && geometry.intersects(endPoint)) {
              endGeometry = geometry;
              endFeature = feature;
            }
          }

          if (!doCut) {
            previewGeometry = startGeometry.union(endGeometry);
          } else {
            previewGeometry = startGeometry.difference(endGeometry);
          }
          return "";
        } catch (Exception e) {
          GPLog.error(this, null, e); // $NON-NLS-1$
          return "ERROR: " + e.getLocalizedMessage();
        }
      }

      protected void onProgressUpdate(Integer... progress) { // on UI thread!
        if (infoProgressDialog != null && infoProgressDialog.isShowing())
          infoProgressDialog.incrementProgressBy(progress[0]);
      }

      protected void onPostExecute(String response) { // on UI thread!
        Utilities.dismissProgressDialog(infoProgressDialog);
        if (response.startsWith("ERROR")) {
          Utilities.messageDialog(context, response, null);
        } else {
          Utilities.toast(
              context, context.getString(R.string.preview_mode_save_warning), Toast.LENGTH_SHORT);

          EditManager.INSTANCE.invalidateEditingView();

          ToolGroup activeToolGroup = EditManager.INSTANCE.getActiveToolGroup();
          if (activeToolGroup != null) {
            activeToolGroup.onToolFinished(CutExtendTool.this);
          }
        }
      }
    }.execute((String) null);
  }
  /**
   * Constructor.
   *
   * @param mapView the map view.
   */
  public LineMainEditingToolGroup(MapView mapView) {
    this.mapView = mapView;

    LinearLayout parent = EditManager.INSTANCE.getToolsLayout();
    selectionColor = Compat.getColor(parent.getContext(), R.color.main_selection);
  }
 public void disable() {
   EditManager.INSTANCE.setActiveTool(null);
   LinearLayout parent = EditManager.INSTANCE.getToolsLayout();
   if (parent != null) parent.removeAllViews();
 }