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); } }
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); }