|
@@ -0,0 +1,703 @@
|
|
|
+package com.tofly.route.util.AmapUtils;
|
|
|
+
|
|
|
+
|
|
|
+ * 测量工具:长度、面积、角度的测量
|
|
|
+ * Created by li on 2016/8/25.
|
|
|
+ */
|
|
|
+
|
|
|
+import android.annotation.SuppressLint;
|
|
|
+import android.content.Context;
|
|
|
+import android.graphics.Color;
|
|
|
+import android.util.Log;
|
|
|
+import android.view.Menu;
|
|
|
+import android.view.MenuItem;
|
|
|
+import android.view.MotionEvent;
|
|
|
+import android.view.View;
|
|
|
+import android.view.ViewGroup;
|
|
|
+import android.widget.BaseAdapter;
|
|
|
+import android.widget.ImageView;
|
|
|
+import android.widget.LinearLayout;
|
|
|
+import android.widget.RadioButton;
|
|
|
+import android.widget.RadioGroup;
|
|
|
+import android.widget.Spinner;
|
|
|
+import android.widget.TextView;
|
|
|
+import android.widget.RadioGroup.OnCheckedChangeListener;
|
|
|
+
|
|
|
+import androidx.appcompat.view.ActionMode;
|
|
|
+import androidx.core.view.ActionProvider;
|
|
|
+import androidx.core.view.MenuItemCompat;
|
|
|
+
|
|
|
+import com.esri.arcgisruntime.geometry.AngularUnit;
|
|
|
+import com.esri.arcgisruntime.geometry.AreaUnit;
|
|
|
+import com.esri.arcgisruntime.geometry.GeodeticCurveType;
|
|
|
+import com.esri.arcgisruntime.geometry.Geometry;
|
|
|
+import com.esri.arcgisruntime.geometry.GeometryEngine;
|
|
|
+import com.esri.arcgisruntime.geometry.LinearUnit;
|
|
|
+import com.esri.arcgisruntime.geometry.Point;
|
|
|
+import com.esri.arcgisruntime.geometry.PointCollection;
|
|
|
+import com.esri.arcgisruntime.geometry.Polygon;
|
|
|
+import com.esri.arcgisruntime.geometry.Polyline;
|
|
|
+import com.esri.arcgisruntime.geometry.Unit;
|
|
|
+import com.esri.arcgisruntime.mapping.view.Callout;
|
|
|
+import com.esri.arcgisruntime.mapping.view.DefaultMapViewOnTouchListener;
|
|
|
+import com.esri.arcgisruntime.mapping.view.Graphic;
|
|
|
+import com.esri.arcgisruntime.mapping.view.GraphicsOverlay;
|
|
|
+import com.esri.arcgisruntime.mapping.view.MapView;
|
|
|
+import com.esri.arcgisruntime.symbology.FillSymbol;
|
|
|
+import com.esri.arcgisruntime.symbology.LineSymbol;
|
|
|
+import com.esri.arcgisruntime.symbology.MarkerSymbol;
|
|
|
+import com.esri.arcgisruntime.symbology.SimpleFillSymbol;
|
|
|
+import com.esri.arcgisruntime.symbology.SimpleLineSymbol;
|
|
|
+import com.esri.arcgisruntime.symbology.SimpleMarkerSymbol;
|
|
|
+import com.esri.arcgisruntime.util.ListenableList;
|
|
|
+import com.tofly.route.util.pupwindow.PopWindowUtils;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Iterator;
|
|
|
+
|
|
|
+@SuppressWarnings("ResourceType")
|
|
|
+public class MeasuringTool implements android.view.ActionMode.Callback {
|
|
|
+ private static final long serialVersionUID = 1L;
|
|
|
+ private static final int MENU_DELETE = 0;
|
|
|
+ private static final int MENU_PREF = 1;
|
|
|
+ private static final int MENU_UNDO = 2;
|
|
|
+ private MapView mMap;
|
|
|
+ private GraphicsOverlay mLayer;
|
|
|
+ private View.OnTouchListener mOldOnSingleTapListener;
|
|
|
+ private MarkerSymbol mMarkerSymbol;
|
|
|
+ private LineSymbol mLineSymbol;
|
|
|
+ private double mResult;
|
|
|
+ private TextView mText;
|
|
|
+ private MeasureType mMeasureMode;
|
|
|
+ private int mCurrentLinearUnit;
|
|
|
+ private Unit[] mLinearUnits;
|
|
|
+ private Unit[] mDefaultLinearUnits;
|
|
|
+ private int mCurrentAreaUnit;
|
|
|
+ private Unit[] mAreaUnits;
|
|
|
+ private Unit[] mDefaultAreaUnits;
|
|
|
+ private int mCurrentAngularUnit;
|
|
|
+ private Unit[] mAngularUnit;
|
|
|
+ private Unit[] mDefaultAngularUnit;
|
|
|
+ private Context mContext;
|
|
|
+ private ArrayList<Point> mPoints;
|
|
|
+ private FillSymbol mFillSymbol;
|
|
|
+ private Callout mCallout;
|
|
|
+ private android.view.ActionMode mMode;
|
|
|
+ private Polyline mLine;
|
|
|
+ private Polygon mPolygon;
|
|
|
+
|
|
|
+
|
|
|
+ public MeasuringTool(MapView map) {
|
|
|
+ this.mMeasureMode = MeasureType.LINEAR;
|
|
|
+ this.mMap = map;
|
|
|
+ this.mContext = this.mMap.getContext();
|
|
|
+ this.mMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, -65536, 10);
|
|
|
+ this.mLineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, -16777216, 3.0F);
|
|
|
+ this.mDefaultLinearUnits = new Unit[] {Unit.fromUnitId(9001), Unit.fromUnitId(9036), Unit.fromUnitId(9002), Unit.fromUnitId(9093)};
|
|
|
+ this.mDefaultAreaUnits = new Unit[]{Unit.fromUnitId(109404), Unit.fromUnitId(109414), Unit.fromUnitId(109405), Unit.fromUnitId(109439)};
|
|
|
+ this.mDefaultAngularUnit = new Unit[]{Unit.fromUnitId(9102), Unit.fromUnitId(9101)};
|
|
|
+ this.mFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID,
|
|
|
+ Color.argb(100, 225, 225, 0), null);
|
|
|
+ this.mFillSymbol.setOutline(new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID ,0, 0.0F));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void init() {
|
|
|
+ this.mOldOnSingleTapListener = this.mMap.getOnTouchListener();
|
|
|
+ this.mMap.setOnTouchListener(new DefaultMapViewOnTouchListener(mContext, mMap){
|
|
|
+ @Override
|
|
|
+ public boolean onSingleTapConfirmed(MotionEvent e) {
|
|
|
+ onSingleTap(e.getX(), e.getY());
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ this.mLayer = new GraphicsOverlay();
|
|
|
+ this.mMap.getGraphicsOverlays().add(this.mLayer);
|
|
|
+ this.mPoints = new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public void deleteAll() {
|
|
|
+ this.mLayer.getGraphics().clear();
|
|
|
+ this.mResult = 0.0D;
|
|
|
+ this.mPoints.clear();
|
|
|
+ this.showResult();
|
|
|
+ this.updateMenu();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public void onDestroyActionMode(ActionMode mode) {
|
|
|
+ this.hideCallout();
|
|
|
+ this.mMap.getGraphicsOverlays().remove(this.mLayer);
|
|
|
+ this.mLayer = null;
|
|
|
+ this.mMap.setOnTouchListener(this.mOldOnSingleTapListener);
|
|
|
+ this.mPoints = null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void hideCallout() {
|
|
|
+ if (this.mCallout != null && this.mCallout.isShowing()) {
|
|
|
+ this.mCallout.dismiss();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public void onSingleTap(float x, float y) {
|
|
|
+ this.addPoint(x, y);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void addPoint(float x, float y) {
|
|
|
+ android.graphics.Point screenPoint =
|
|
|
+ new android.graphics.Point(Math.round(x), Math.round(y));
|
|
|
+ Point point = this.mMap.screenToLocation(screenPoint);
|
|
|
+ this.mPoints.add(point);
|
|
|
+ this.clearAndDraw();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void undo() {
|
|
|
+ this.mPoints.remove(this.mPoints.size() - 1);
|
|
|
+ this.clearAndDraw();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void clearAndDraw() {
|
|
|
+ ListenableList oldGraphics = this.mLayer.getGraphics();
|
|
|
+ this.mLayer.getGraphics().removeAll(oldGraphics);
|
|
|
+ this.draw();
|
|
|
+ this.updateMenu();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 在地图上描点
|
|
|
+ */
|
|
|
+ private void draw() {
|
|
|
+ if (this.mPoints.size() != 0) {
|
|
|
+ int index = 0;
|
|
|
+ this.mResult = 0.0D;
|
|
|
+
|
|
|
+
|
|
|
+ PointCollection collection = new PointCollection(mMap.getSpatialReference());
|
|
|
+ Point screenPoint;
|
|
|
+ for (Iterator labelPointForPolygon = this.mPoints.iterator(); labelPointForPolygon.hasNext(); ++index) {
|
|
|
+ screenPoint = (Point) labelPointForPolygon.next();
|
|
|
+ this.mLayer.getGraphics().add(new Graphic(screenPoint, this.mMarkerSymbol));
|
|
|
+ if (index == 0) {
|
|
|
+ collection.add(screenPoint);
|
|
|
+
|
|
|
+ if (this.mMeasureMode == MeasureType.AREA) {
|
|
|
+
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ collection.add(screenPoint);
|
|
|
+
|
|
|
+ if (this.mMeasureMode == MeasureType.AREA) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ this.mLine = new Polyline(collection);
|
|
|
+ this.mLayer.getGraphics().add(new Graphic(this.mLine, this.mLineSymbol));
|
|
|
+ }
|
|
|
+
|
|
|
+ Point var4;
|
|
|
+ if (this.mMeasureMode == MeasureType.LINEAR) {
|
|
|
+
|
|
|
+ this.mResult += GeometryEngine.lengthGeodetic(this.mLine
|
|
|
+ , (LinearUnit) this.getLinearUnit(this.mCurrentLinearUnit)
|
|
|
+ , GeodeticCurveType.GEODESIC);
|
|
|
+ android.graphics.Point screen = this.mMap.locationToScreen(this.mPoints.get(index - 1));
|
|
|
+ var4 = new Point(screen.x, screen.y);
|
|
|
+ this.showResult((float) var4.getX(), (float) var4.getY());
|
|
|
+ } else if (this.mMeasureMode == MeasureType.AREA) {
|
|
|
+ collection.add(this.mPoints.get(0));
|
|
|
+ this.mLine = new Polyline(collection);
|
|
|
+
|
|
|
+ this.mLayer.getGraphics().add(new Graphic(this.mLine, this.mLineSymbol));
|
|
|
+ this.mPolygon = new Polygon(collection);
|
|
|
+
|
|
|
+ this.mLayer.getGraphics().add(new Graphic(this.mPolygon, this.mFillSymbol));
|
|
|
+
|
|
|
+ this.mResult = GeometryEngine.areaGeodetic(this.mPolygon
|
|
|
+ , (AreaUnit) this.getAreaUnit(this.mCurrentAreaUnit),
|
|
|
+ GeodeticCurveType.GEODESIC);
|
|
|
+ var4 = GeometryEngine.labelPoint(this.mPolygon);
|
|
|
+
|
|
|
+ , this.mMap.getSpatialReference());*/
|
|
|
+ android.graphics.Point screen = this.mMap.locationToScreen(var4);
|
|
|
+ this.showResult((float) screen.x, (float) screen.y);
|
|
|
+ } else if (this.mMeasureMode == MeasureType.ANGULAR) {
|
|
|
+ int i = index - 1;
|
|
|
+
|
|
|
+ if (i >= 2) {
|
|
|
+ this.mResult = DegreeUtil.MeasuringDegree(mPoints.get(i - 2)
|
|
|
+ , mPoints.get(i - 1)
|
|
|
+ , mPoints.get(i)
|
|
|
+ , (AngularUnit) this.getAngularUnite(this.mCurrentAngularUnit));
|
|
|
+
|
|
|
+ android.graphics.Point screen = this.mMap.locationToScreen(this.mPoints.get(index - 2));
|
|
|
+ var4 = new Point(screen.x, screen.y);
|
|
|
+ this.showResult((float) var4.getX(), (float) var4.getY());
|
|
|
+ } else {
|
|
|
+ hideCallout();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void updateMenu() {
|
|
|
+ this.mMode.getMenu().findItem(0).setVisible(this.mPoints.size() > 0);
|
|
|
+ this.mMode.getMenu().findItem(2).setVisible(this.mPoints.size() > 0);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 显示结果到地图上
|
|
|
+ *
|
|
|
+ * @param x ,y callout的坐标
|
|
|
+ */
|
|
|
+ private void showResult(float x, float y) {
|
|
|
+ if (this.mResult > 0.0D) {
|
|
|
+ if (this.mCallout == null) {
|
|
|
+ this.mText = new TextView(this.mContext);
|
|
|
+ this.mCallout = this.mMap.getCallout();
|
|
|
+ }
|
|
|
+ this.mText.setText(this.getResultString());
|
|
|
+ android.graphics.Point screenPoint =
|
|
|
+ new android.graphics.Point(Math.round(x), Math.round(y));
|
|
|
+ Point mapPoint = this.mMap.screenToLocation(screenPoint);
|
|
|
+ this.mCallout.show(mText, mapPoint);
|
|
|
+ } else if (this.mCallout != null && this.mCallout.isShowing()) {
|
|
|
+ this.mCallout.dismiss();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void showResult() {
|
|
|
+ if (this.mResult > 0.0D) {
|
|
|
+ this.mText.setText(this.getResultString());
|
|
|
+ this.mCallout.show();
|
|
|
+ } else if (this.mCallout != null && this.mCallout.isShowing()) {
|
|
|
+ this.mCallout.dismiss();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 设置测量长度的工具
|
|
|
+ *
|
|
|
+ * @param linearUnits 工具单位数组
|
|
|
+ */
|
|
|
+ public void setLinearUnits(Unit[] linearUnits) {
|
|
|
+ this.mLinearUnits = linearUnits;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Unit getLinearUnit(int position) {
|
|
|
+ return this.mLinearUnits == null ?
|
|
|
+ this.mDefaultLinearUnits[position % mDefaultLinearUnits.length] :
|
|
|
+ this.mLinearUnits[position % mLinearUnits.length];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ int getLinearUnitSize() {
|
|
|
+ return this.mLinearUnits == null ? this.mDefaultLinearUnits.length : this.mLinearUnits.length;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 设置测量面积的单位集合
|
|
|
+ *
|
|
|
+ * @param areaUnits 面积单位数组
|
|
|
+ */
|
|
|
+ public void setAreaUnits(Unit[] areaUnits) {
|
|
|
+ this.mAreaUnits = areaUnits;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private Unit getAreaUnit(int position) {
|
|
|
+ return this.mAreaUnits == null ?
|
|
|
+ this.mDefaultAreaUnits[position % mDefaultAreaUnits.length] :
|
|
|
+ this.mAreaUnits[position % mAreaUnits.length];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private int getAreaUnitSize() {
|
|
|
+ return this.mAreaUnits == null ? this.mDefaultAreaUnits.length : this.mAreaUnits.length;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 设置测量角度的单位集合
|
|
|
+ *
|
|
|
+ * @param angularUnits 角度单位数组
|
|
|
+ */
|
|
|
+ private void setAngularUnits(Unit[] angularUnits) {
|
|
|
+ this.mAngularUnit = angularUnits;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private Unit getAngularUnite(int position) {
|
|
|
+ return this.mAngularUnit == null ?
|
|
|
+ this.mDefaultAngularUnit[position % mDefaultAngularUnit.length] :
|
|
|
+ this.mAngularUnit[position % mAngularUnit.length];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private int getAngularUnitSize() {
|
|
|
+ return this.mAngularUnit == null ? this.mDefaultAngularUnit.length : this.mAngularUnit.length;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private int getUnitSize() {
|
|
|
+ return this.mMeasureMode == MeasureType.LINEAR ?
|
|
|
+ this.getLinearUnitSize() : this.mMeasureMode == MeasureType.AREA ?
|
|
|
+ this.getAreaUnitSize() : this.getAngularUnitSize();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private Unit getUnit(int position) {
|
|
|
+ return this.mMeasureMode == MeasureType.LINEAR ?
|
|
|
+ this.getLinearUnit(position) : this.mMeasureMode == MeasureType.AREA ?
|
|
|
+ this.getAreaUnit(position) : this.getAngularUnite(position);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private Unit getCurrentUnit() {
|
|
|
+ return this.getUnit(this.mMeasureMode == MeasureType.LINEAR ?
|
|
|
+ this.mCurrentLinearUnit : this.mMeasureMode == MeasureType.AREA ?
|
|
|
+ this.mCurrentAreaUnit : this.mCurrentAngularUnit);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getUnitDisplayNameCn(Unit unit){
|
|
|
+ String nameCn = unit.getDisplayName();
|
|
|
+ switch (unit.getUnitId()){
|
|
|
+ case 9001:
|
|
|
+ nameCn = "米";
|
|
|
+ break;
|
|
|
+ case 9036:
|
|
|
+ nameCn = "千米";
|
|
|
+ break;
|
|
|
+ case 9002:
|
|
|
+ nameCn = "英尺";
|
|
|
+ break;
|
|
|
+ case 9093:
|
|
|
+ nameCn = "英里";
|
|
|
+ break;
|
|
|
+ case 109404:
|
|
|
+ nameCn = "平方米";
|
|
|
+ break;
|
|
|
+ case 109414:
|
|
|
+ nameCn = "平方千米";
|
|
|
+ break;
|
|
|
+ case 109405:
|
|
|
+ nameCn = "平方英尺";
|
|
|
+ break;
|
|
|
+ case 109439:
|
|
|
+ nameCn = "平方英里";
|
|
|
+ break;
|
|
|
+ case 9102:
|
|
|
+ nameCn = "度";
|
|
|
+ break;
|
|
|
+ case 9101:
|
|
|
+ nameCn = "弧度";
|
|
|
+ break;
|
|
|
+
|
|
|
+ }
|
|
|
+ return nameCn;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 设置绘制的线的样式
|
|
|
+ *
|
|
|
+ * @param symbol 线样式
|
|
|
+ */
|
|
|
+ public void setLineSymbol(LineSymbol symbol) {
|
|
|
+ this.mLineSymbol = symbol;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 设置标记点的样式
|
|
|
+ *
|
|
|
+ * @param symbol 标记点样式
|
|
|
+ */
|
|
|
+ public void setMarkerSymbol(MarkerSymbol symbol) {
|
|
|
+ this.mMarkerSymbol = symbol;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 设置面积图形的样式
|
|
|
+ *
|
|
|
+ * @param symbol 样式
|
|
|
+ */
|
|
|
+ public void setFillSymbol(FillSymbol symbol) {
|
|
|
+ this.mFillSymbol = symbol;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Geometry getGeometry() {
|
|
|
+ return (this.mMeasureMode == MeasureType.AREA ? this.mPolygon : this.mLine);
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressLint("DefaultLocale")
|
|
|
+ private String getResultString() {
|
|
|
+ return this.mResult > 0.0D ?
|
|
|
+ String.format("%.2f", new Object[]{Double.valueOf(this.mResult)})
|
|
|
+ + " "
|
|
|
+ + getUnitDisplayNameCn(this.getCurrentUnit())
|
|
|
+ : "";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean onCreateActionMode(android.view.ActionMode mode, Menu menu) {
|
|
|
+ this.mMode = mode;
|
|
|
+ this.init();
|
|
|
+ MenuItem item = menu.add(0, 2, 1, "返回");
|
|
|
+ item.setIcon(android.R.drawable.ic_menu_revert);
|
|
|
+ item.setVisible(false);
|
|
|
+ item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
|
|
+ item = menu.add(0, 0, 2, "清理全部");
|
|
|
+ item.setIcon(android.R.drawable.ic_menu_delete);
|
|
|
+ item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
|
|
+ item.setVisible(false);
|
|
|
+ item = menu.add(0, 1, 3, "参数选择");
|
|
|
+ item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
|
|
+ item.setIcon(android.R.drawable.ic_menu_manage);
|
|
|
+
|
|
|
+ MenuItemCompat.setActionProvider(item, new Preferences(this.mContext));
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean onPrepareActionMode(android.view.ActionMode mode, Menu menu) {
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean onActionItemClicked(android.view.ActionMode mode, MenuItem item) {
|
|
|
+ switch (item.getItemId()) {
|
|
|
+ case 0:
|
|
|
+ this.deleteAll();
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ this.undo();
|
|
|
+
|
|
|
+ case 1:
|
|
|
+
|
|
|
+
|
|
|
+ Log.e("TAG", "onActionItemClicked: =============" );
|
|
|
+
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onDestroyActionMode(android.view.ActionMode mode) {
|
|
|
+ this.hideCallout();
|
|
|
+ this.mMap.getGraphicsOverlays().remove(this.mLayer);
|
|
|
+ this.mLayer = null;
|
|
|
+ this.mMap.setOnTouchListener(this.mOldOnSingleTapListener);
|
|
|
+ this.mPoints = null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 设置单位选项的ActionProvider
|
|
|
+ */
|
|
|
+ class Preferences extends ActionProvider {
|
|
|
+ private ImageView imageView;
|
|
|
+
|
|
|
+ public Preferences(Context context) {
|
|
|
+ super(context);
|
|
|
+ this.imageView = new ImageView(MeasuringTool.this.mContext);
|
|
|
+ this.imageView.setImageDrawable(context.getResources().getDrawable(
|
|
|
+ android.R.drawable.ic_menu_manage));
|
|
|
+ }
|
|
|
+
|
|
|
+ public View onCreateActionView() {
|
|
|
+ Spinner spinner = new Spinner(MeasuringTool.this.mContext);
|
|
|
+ spinner.setAdapter(new BaseAdapter() {
|
|
|
+
|
|
|
+ public View getView(int position, View convertView, ViewGroup parent) {
|
|
|
+ return Preferences.this.imageView;
|
|
|
+ }
|
|
|
+
|
|
|
+ public View getDropDownView(int position, View convertView, ViewGroup parent) {
|
|
|
+ LinearLayout layout;
|
|
|
+ TextView text;
|
|
|
+
|
|
|
+ if (position == 0) {
|
|
|
+ layout = new LinearLayout(MeasuringTool.this.mContext);
|
|
|
+ layout.setOrientation(LinearLayout.VERTICAL);
|
|
|
+ text = new TextView(MeasuringTool.this.mContext);
|
|
|
+ text.setText("选择测量类型");
|
|
|
+ text.setTextColor(MeasuringTool.this.mContext.getResources().getColor(android.R.color.holo_blue_light));
|
|
|
+ text.setTextSize(16.0F);
|
|
|
+ layout.addView(text);
|
|
|
+ RadioButton varLen = new RadioButton(MeasuringTool.this.mContext);
|
|
|
+ varLen.setText("长度");
|
|
|
+ RadioButton varArea = new RadioButton(MeasuringTool.this.mContext);
|
|
|
+ varArea.setText("面积");
|
|
|
+ RadioButton varAngu = new RadioButton(MeasuringTool.this.mContext);
|
|
|
+ varAngu.setText("角度");
|
|
|
+ RadioGroup geoType = new RadioGroup(MeasuringTool.this.mContext);
|
|
|
+ geoType.addView(varLen);
|
|
|
+ geoType.addView(varArea);
|
|
|
+ geoType.addView(varAngu);
|
|
|
+
|
|
|
+ geoType.check(MeasuringTool.this.mMeasureMode == MeasureType.LINEAR ?
|
|
|
+ varLen.getId() : MeasuringTool.this.mMeasureMode == MeasureType.AREA ?
|
|
|
+ varArea.getId() : varAngu.getId());
|
|
|
+ layout.addView(geoType);
|
|
|
+ layout.setPadding(10, 10, 10, 10);
|
|
|
+ geoType.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
|
|
+ public void onCheckedChanged(RadioGroup rGroup, int checkedId) {
|
|
|
+ for (int i = 0; i < rGroup.getChildCount(); ++i) {
|
|
|
+ if (rGroup.getChildAt(i).getId() == checkedId) {
|
|
|
+ MeasuringTool.this.mMeasureMode = MeasureType.getType(i);
|
|
|
+ notifyDataSetChanged();
|
|
|
+ MeasuringTool.this.clearAndDraw();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return layout;
|
|
|
+ } else {
|
|
|
+ layout = new LinearLayout(MeasuringTool.this.mContext);
|
|
|
+ layout.setOrientation(LinearLayout.VERTICAL);
|
|
|
+ text = new TextView(MeasuringTool.this.mContext);
|
|
|
+ text.setText("选择单位");
|
|
|
+ text.setTextColor(MeasuringTool.this.mContext.getResources().getColor(android.R.color.holo_blue_light));
|
|
|
+ text.setTextSize(16.0F);
|
|
|
+ layout.addView(text);
|
|
|
+ RadioGroup group = new RadioGroup(MeasuringTool.this.mContext);
|
|
|
+ for (int i = 0; i < MeasuringTool.this.getUnitSize(); ++i) {
|
|
|
+ RadioButton r = new RadioButton(MeasuringTool.this.mContext);
|
|
|
+ r.setText(getUnitDisplayNameCn(MeasuringTool.this.getUnit(i)));
|
|
|
+ group.addView(r);
|
|
|
+
|
|
|
+ if (i == (MeasuringTool.this.mMeasureMode == MeasureType.LINEAR ?
|
|
|
+ MeasuringTool.this.mCurrentLinearUnit : MeasuringTool.this.mMeasureMode == MeasureType.AREA ?
|
|
|
+ MeasuringTool.this.mCurrentAreaUnit : MeasuringTool.this.mCurrentAngularUnit)) {
|
|
|
+ group.check(r.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ group.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
|
|
+ public void onCheckedChanged(RadioGroup rGroup, int checkedId) {
|
|
|
+ for (int i = 0; i < rGroup.getChildCount(); ++i) {
|
|
|
+ if (rGroup.getChildAt(i).getId() == checkedId) {
|
|
|
+ if (MeasuringTool.this.mMeasureMode == MeasureType.LINEAR) {
|
|
|
+ if (MeasuringTool.this.mResult > 0.0D) {
|
|
|
+ LinearUnit lineUnit = (LinearUnit) MeasuringTool.this.getLinearUnit(MeasuringTool.this.mCurrentLinearUnit);
|
|
|
+ MeasuringTool.this.mResult = lineUnit.convertTo((LinearUnit) MeasuringTool.this.getLinearUnit(i), MeasuringTool.this.mResult);
|
|
|
+
|
|
|
+ MeasuringTool.this.mCurrentLinearUnit = i;
|
|
|
+ MeasuringTool.this.showResult();
|
|
|
+ } else {
|
|
|
+ MeasuringTool.this.mCurrentLinearUnit = i;
|
|
|
+ }
|
|
|
+ } else if (MeasuringTool.this.mMeasureMode == MeasureType.AREA) {
|
|
|
+ if (MeasuringTool.this.mResult > 0.0D) {
|
|
|
+ AreaUnit areaUnit = (AreaUnit) MeasuringTool.this.getAreaUnit(MeasuringTool.this.mCurrentAreaUnit);
|
|
|
+ MeasuringTool.this.mResult = areaUnit.convertTo((AreaUnit) MeasuringTool.this.getAreaUnit(i), MeasuringTool.this.mResult);
|
|
|
+
|
|
|
+ MeasuringTool.this.mCurrentAreaUnit = i;
|
|
|
+ MeasuringTool.this.showResult();
|
|
|
+ } else {
|
|
|
+ MeasuringTool.this.mCurrentAreaUnit = i;
|
|
|
+ }
|
|
|
+ } else if (MeasuringTool.this.mMeasureMode == MeasureType.ANGULAR) {
|
|
|
+ if (MeasuringTool.this.mResult > 0.0D) {
|
|
|
+ AngularUnit angularUnit = (AngularUnit) MeasuringTool.this.getAngularUnite(MeasuringTool.this.mCurrentAngularUnit);
|
|
|
+ MeasuringTool.this.mResult = angularUnit.convertTo((AngularUnit) MeasuringTool.this.getAngularUnite(i), MeasuringTool.this.mResult);
|
|
|
+
|
|
|
+ MeasuringTool.this.mCurrentAngularUnit = i;
|
|
|
+ MeasuringTool.this.showResult();
|
|
|
+ } else {
|
|
|
+ MeasuringTool.this.mCurrentAngularUnit = i;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ layout.addView(group);
|
|
|
+ layout.setPadding(10, 10, 10, 10);
|
|
|
+ return layout;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public long getItemId(int position) {
|
|
|
+ return (long) position;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Object getItem(int position) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public int getCount() {
|
|
|
+ return 2;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return spinner;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public enum MeasureType {
|
|
|
+ LINEAR,
|
|
|
+ AREA,
|
|
|
+ ANGULAR;
|
|
|
+
|
|
|
+
|
|
|
+ * 提供静态方法,供外部获取枚举类型
|
|
|
+ *
|
|
|
+ * @param i 0表示LINEAR长度 1表示AREA面积 2表示角度
|
|
|
+ */
|
|
|
+ public static MeasureType getType(int i) {
|
|
|
+ switch (i) {
|
|
|
+ case 0:
|
|
|
+ return LINEAR;
|
|
|
+ case 1:
|
|
|
+ return AREA;
|
|
|
+ case 2:
|
|
|
+ return ANGULAR;
|
|
|
+ default:
|
|
|
+ return LINEAR;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|