Add functionality
This commit is contained in:
parent
16804410f2
commit
0f69f594c7
4 changed files with 148 additions and 13 deletions
|
@ -51,31 +51,31 @@
|
|||
tools:src="@drawable/ic_action_arrow_down"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/distance_text_view"
|
||||
android:id="@+id/measurement_distance_text_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginEnd="4dp"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginRight="4dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_toEndOf="@id/ruler_icon"
|
||||
android:layout_toRightOf="@id/ruler_icon"
|
||||
android:text="724 m, "
|
||||
android:textAppearance="@style/TextAppearance.ListItemTitle"
|
||||
tools:text="724 m, "/>
|
||||
tools:text="724 m,"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dots_text_view"
|
||||
android:id="@+id/measurement_points_text_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toEndOf="@id/distance_text_view"
|
||||
android:layout_toEndOf="@id/measurement_distance_text_view"
|
||||
android:layout_toLeftOf="@id/up_down_icon"
|
||||
android:layout_toRightOf="@id/distance_text_view"
|
||||
android:layout_toRightOf="@id/measurement_distance_text_view"
|
||||
android:layout_toStartOf="@id/up_down_icon"
|
||||
android:text="3 dots"
|
||||
android:textColor="?android:textColorSecondary"
|
||||
android:textSize="@dimen/default_list_text_size"
|
||||
tools:text="3 dots"/>
|
||||
tools:text="points: 3"/>
|
||||
</RelativeLayout>
|
||||
|
||||
<View
|
||||
|
@ -114,7 +114,7 @@
|
|||
tools:src="@drawable/ic_action_redo_dark"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/add_dot_button"
|
||||
android:id="@+id/add_point_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
||||
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
||||
-->
|
||||
<string name="measurement_points">points: %o</string>
|
||||
<string name="measurement_distance">%s,</string>
|
||||
<string name="measurement_tool">Measurement tool</string>
|
||||
<string name="quick_action_resume_pause_navigation">Resume/Pause Navigation</string>
|
||||
<string name="quick_action_resume_pause_navigation_descr">Press this button to pause the navigation, or to resume it if it was already paused.</string>
|
||||
|
|
|
@ -8,6 +8,7 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.plus.IconsCache;
|
||||
|
@ -20,6 +21,12 @@ public class MeasurementToolFragment extends Fragment {
|
|||
|
||||
private MapActivity mapActivity;
|
||||
private MeasurementToolLayer measurementLayer;
|
||||
|
||||
private TextView distanceTv;
|
||||
private TextView pointsTv;
|
||||
private String distanceSt;
|
||||
private String pointsSt;
|
||||
|
||||
private boolean wasCollapseButtonVisible;
|
||||
|
||||
@Nullable
|
||||
|
@ -31,11 +38,17 @@ public class MeasurementToolFragment extends Fragment {
|
|||
final boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
|
||||
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
|
||||
|
||||
distanceSt = mapActivity.getString(R.string.measurement_distance);
|
||||
pointsSt = mapActivity.getString(R.string.measurement_points);
|
||||
|
||||
View view = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_measurement_tool, null);
|
||||
|
||||
final View mainView = view.findViewById(R.id.main_view);
|
||||
AndroidUtils.setBackground(mapActivity, mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
|
||||
|
||||
distanceTv = (TextView) mainView.findViewById(R.id.measurement_distance_text_view);
|
||||
pointsTv = (TextView) mainView.findViewById(R.id.measurement_points_text_view);
|
||||
|
||||
((ImageView) mainView.findViewById(R.id.ruler_icon))
|
||||
.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_ruler, R.color.color_myloc_distance));
|
||||
((ImageView) mainView.findViewById(R.id.up_down_icon))
|
||||
|
@ -45,6 +58,14 @@ public class MeasurementToolFragment extends Fragment {
|
|||
((ImageView) mainView.findViewById(R.id.next_dot_icon))
|
||||
.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_redo_dark));
|
||||
|
||||
mainView.findViewById(R.id.add_point_button).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
measurementLayer.addPointOnClick();
|
||||
updateText();
|
||||
}
|
||||
});
|
||||
|
||||
enterMeasurementMode();
|
||||
|
||||
return view;
|
||||
|
@ -56,8 +77,14 @@ public class MeasurementToolFragment extends Fragment {
|
|||
exitMeasurementMode();
|
||||
}
|
||||
|
||||
private void updateText() {
|
||||
distanceTv.setText(String.format(distanceSt, measurementLayer.getDistanceSt()));
|
||||
pointsTv.setText(String.format(pointsSt, measurementLayer.getPointsCount()));
|
||||
}
|
||||
|
||||
private void enterMeasurementMode() {
|
||||
measurementLayer.setInMeasurementMode(true);
|
||||
mapActivity.refreshMap();
|
||||
mapActivity.disableDrawer();
|
||||
mark(View.INVISIBLE, R.id.map_left_widgets_panel, R.id.map_right_widgets_panel, R.id.map_center_info);
|
||||
mark(View.GONE, R.id.map_route_info_button, R.id.map_menu_button, R.id.map_compass_button, R.id.map_layers_button,
|
||||
|
@ -70,10 +97,13 @@ public class MeasurementToolFragment extends Fragment {
|
|||
} else {
|
||||
wasCollapseButtonVisible = false;
|
||||
}
|
||||
|
||||
updateText();
|
||||
}
|
||||
|
||||
private void exitMeasurementMode() {
|
||||
measurementLayer.setInMeasurementMode(false);
|
||||
mapActivity.refreshMap();
|
||||
mapActivity.enableDrawer();
|
||||
mark(View.VISIBLE, R.id.map_left_widgets_panel, R.id.map_right_widgets_panel, R.id.map_center_info,
|
||||
R.id.map_route_info_button, R.id.map_menu_button, R.id.map_compass_button, R.id.map_layers_button,
|
||||
|
@ -83,6 +113,8 @@ public class MeasurementToolFragment extends Fragment {
|
|||
if (collapseButton != null && wasCollapseButtonVisible) {
|
||||
collapseButton.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
measurementLayer.clearPoints();
|
||||
}
|
||||
|
||||
private void mark(int status, int... widgets) {
|
||||
|
|
|
@ -1,31 +1,132 @@
|
|||
package net.osmand.plus.measurementtool;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Path;
|
||||
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.QuadPoint;
|
||||
import net.osmand.data.RotatedTileBox;
|
||||
import net.osmand.plus.GPXUtilities.WptPt;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.views.OsmandMapLayer;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class MeasurementToolLayer extends OsmandMapLayer {
|
||||
|
||||
private OsmandMapTileView view;
|
||||
private boolean inMeasurementMode;
|
||||
private LinkedList<WptPt> measurementPoints = new LinkedList<>();
|
||||
private Bitmap centerIconDay;
|
||||
private Bitmap centerIconNight;
|
||||
private Bitmap pointIcon;
|
||||
private Paint bitmapPaint;
|
||||
private RenderingLineAttributes lineAttrs;
|
||||
private Path path;
|
||||
private int marginX;
|
||||
private int marginY;
|
||||
|
||||
@Override
|
||||
public void initLayer(OsmandMapTileView view) {
|
||||
this.view = view;
|
||||
|
||||
centerIconDay = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_ruler_center_day);
|
||||
centerIconNight = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_ruler_center_night);
|
||||
pointIcon = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_pedestrian_location);
|
||||
|
||||
bitmapPaint = new Paint();
|
||||
bitmapPaint.setAntiAlias(true);
|
||||
bitmapPaint.setDither(true);
|
||||
bitmapPaint.setFilterBitmap(true);
|
||||
|
||||
lineAttrs = new RenderingLineAttributes("rulerLine");
|
||||
|
||||
path = new Path();
|
||||
marginY = pointIcon.getHeight() / 2;
|
||||
marginX = pointIcon.getWidth() / 2;
|
||||
}
|
||||
|
||||
public boolean isInMeasurementMode() {
|
||||
return inMeasurementMode;
|
||||
}
|
||||
|
||||
public void setInMeasurementMode(boolean inMeasurementMode) {
|
||||
void setInMeasurementMode(boolean inMeasurementMode) {
|
||||
this.inMeasurementMode = inMeasurementMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initLayer(OsmandMapTileView view) {
|
||||
int getPointsCount() {
|
||||
return measurementPoints.size();
|
||||
}
|
||||
|
||||
String getDistanceSt() {
|
||||
float dist = 0;
|
||||
if (measurementPoints.size() > 0) {
|
||||
for (int i = 1; i < measurementPoints.size(); i++) {
|
||||
dist += MapUtils.getDistance(measurementPoints.get(i - 1).lat, measurementPoints.get(i - 1).lon,
|
||||
measurementPoints.get(i).lat, measurementPoints.get(i).lon);
|
||||
}
|
||||
}
|
||||
return OsmAndFormatter.getFormattedDistance(dist, view.getApplication());
|
||||
}
|
||||
|
||||
void clearPoints() {
|
||||
measurementPoints.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
|
||||
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings settings) {
|
||||
if (inMeasurementMode) {
|
||||
lineAttrs.updatePaints(view, settings, tb);
|
||||
drawCenterIcon(canvas, tb, tb.getCenterPixelPoint(), settings.isNightMode());
|
||||
|
||||
if (measurementPoints.size() > 0) {
|
||||
path.reset();
|
||||
for (int i = 0; i < measurementPoints.size(); i++) {
|
||||
WptPt pt = measurementPoints.get(i);
|
||||
int locX = tb.getPixXFromLonNoRot(pt.lon);
|
||||
int locY = tb.getPixYFromLatNoRot(pt.lat);
|
||||
if (i == 0) {
|
||||
path.moveTo(locX, locY);
|
||||
} else {
|
||||
path.lineTo(locX, locY);
|
||||
}
|
||||
|
||||
if (tb.containsLatLon(pt.lat, pt.lon)) {
|
||||
canvas.drawBitmap(pointIcon, locX - marginX, locY - marginY, bitmapPaint);
|
||||
}
|
||||
}
|
||||
path.lineTo(tb.getCenterPixelX(), tb.getCenterPixelY());
|
||||
canvas.drawPath(path, lineAttrs.paint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void drawCenterIcon(Canvas canvas, RotatedTileBox tb, QuadPoint center, boolean nightMode) {
|
||||
canvas.rotate(-tb.getRotate(), center.x, center.y);
|
||||
if (nightMode) {
|
||||
canvas.drawBitmap(centerIconNight, center.x - centerIconNight.getWidth() / 2,
|
||||
center.y - centerIconNight.getHeight() / 2, bitmapPaint);
|
||||
} else {
|
||||
canvas.drawBitmap(centerIconDay, center.x - centerIconDay.getWidth() / 2,
|
||||
center.y - centerIconDay.getHeight() / 2, bitmapPaint);
|
||||
}
|
||||
canvas.rotate(tb.getRotate(), center.x, center.y);
|
||||
}
|
||||
|
||||
void addPointOnClick() {
|
||||
RotatedTileBox tb = view.getCurrentRotatedTileBox();
|
||||
LatLon l = tb.getLatLonFromPixel(tb.getCenterPixelX(), tb.getCenterPixelY());
|
||||
WptPt pt = new WptPt();
|
||||
pt.lat = l.getLatitude();
|
||||
pt.lon = l.getLongitude();
|
||||
measurementPoints.add(pt);
|
||||
view.refreshMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue