From 9321434c74eea60e4147ed53e285955768498a6e Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 4 Aug 2017 18:59:48 +0300 Subject: [PATCH 01/10] Add displaying of the points --- .../res/layout/fragment_measurement_tool.xml | 2 +- .../res/layout/measure_points_list_item.xml | 68 ++++++++++++++++ .../MeasurementToolAdapter.java | 81 +++++++++++++++++++ .../MeasurementToolFragment.java | 6 ++ 4 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 OsmAnd/res/layout/measure_points_list_item.xml create mode 100644 OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolAdapter.java diff --git a/OsmAnd/res/layout/fragment_measurement_tool.xml b/OsmAnd/res/layout/fragment_measurement_tool.xml index 9b2d999161..3b1093abcc 100644 --- a/OsmAnd/res/layout/fragment_measurement_tool.xml +++ b/OsmAnd/res/layout/fragment_measurement_tool.xml @@ -92,7 +92,7 @@ diff --git a/OsmAnd/res/layout/measure_points_list_item.xml b/OsmAnd/res/layout/measure_points_list_item.xml new file mode 100644 index 0000000000..0c06b7e645 --- /dev/null +++ b/OsmAnd/res/layout/measure_points_list_item.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolAdapter.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolAdapter.java new file mode 100644 index 0000000000..8d4d1817bf --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolAdapter.java @@ -0,0 +1,81 @@ +package net.osmand.plus.measurementtool; + +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageButton; +import android.widget.ImageView; +import android.widget.TextView; +import android.widget.Toast; + +import net.osmand.plus.GPXUtilities.WptPt; +import net.osmand.plus.IconsCache; +import net.osmand.plus.OsmAndFormatter; +import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; +import net.osmand.util.MapUtils; + +import java.util.List; + +class MeasurementToolAdapter extends RecyclerView.Adapter { + + private MapActivity mapActivity; + private List points; + + public MeasurementToolAdapter(MapActivity mapActivity, List points) { + this.mapActivity = mapActivity; + this.points = points; + } + + @Override + public Holder onCreateViewHolder(ViewGroup viewGroup, int i) { + View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.measure_points_list_item, viewGroup, false); + return new Holder(view); + } + + @Override + public void onBindViewHolder(final Holder holder, int pos) { + IconsCache iconsCache = mapActivity.getMyApplication().getIconsCache(); + holder.icon.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_measure_point)); + holder.title.setText(mapActivity.getString(R.string.plugin_distance_point) + " - " + (pos + 1)); + if (pos < 1) { + holder.descr.setText(mapActivity.getString(R.string.shared_string_control_start)); + } else { + float dist = 0; + for (int i = 1; i <= pos; i++) { + dist += MapUtils.getDistance(points.get(i - 1).lat, points.get(i - 1).lon, + points.get(i).lat, points.get(i).lon); + } + holder.descr.setText(OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication())); + } + holder.deleteBtn.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_remove_dark)); + holder.deleteBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Toast.makeText(mapActivity, "Remove: " + holder.getAdapterPosition(), Toast.LENGTH_SHORT).show(); + } + }); + } + + @Override + public int getItemCount() { + return points.size(); + } + + static class Holder extends RecyclerView.ViewHolder { + + final ImageView icon; + final TextView title; + final TextView descr; + final ImageButton deleteBtn; + + public Holder(View view) { + super(view); + icon = (ImageView) view.findViewById(R.id.measure_point_icon); + title = (TextView) view.findViewById(R.id.measure_point_title); + descr = (TextView) view.findViewById(R.id.measure_point_descr); + deleteBtn = (ImageButton) view.findViewById(R.id.measure_point_remove_image_button); + } + } +} diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index 52b63cc52b..ecc11e895c 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -10,6 +10,8 @@ import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.content.ContextCompat; import android.support.v7.app.AlertDialog; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; import android.support.v7.widget.SwitchCompat; import android.text.Editable; import android.text.TextWatcher; @@ -188,6 +190,10 @@ public class MeasurementToolFragment extends Fragment { mapActivity.showTopToolbar(toolBarController); } + RecyclerView rv = mainView.findViewById(R.id.measure_points_recycler_view); + rv.setLayoutManager(new LinearLayoutManager(getContext())); + rv.setAdapter(new MeasurementToolAdapter(getMapActivity(), measurementLayer.getMeasurementPoints())); + return view; } From cda30a29571108e4e168bf21adab96f697744da1 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Mon, 7 Aug 2017 13:05:11 +0300 Subject: [PATCH 02/10] Add the ability to delete points from the list; add small changes --- .../MeasurementToolAdapter.java | 17 ++++++++--- .../MeasurementToolFragment.java | 29 +++++++++++++++++-- .../measurementtool/MeasurementToolLayer.java | 10 +++++-- 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolAdapter.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolAdapter.java index 8d4d1817bf..8304957b3b 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolAdapter.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolAdapter.java @@ -7,7 +7,6 @@ import android.view.ViewGroup; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.TextView; -import android.widget.Toast; import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.IconsCache; @@ -22,12 +21,17 @@ class MeasurementToolAdapter extends RecyclerView.Adapter points; + private RemovePointListener listener; - public MeasurementToolAdapter(MapActivity mapActivity, List points) { + MeasurementToolAdapter(MapActivity mapActivity, List points) { this.mapActivity = mapActivity; this.points = points; } + public void setListener(RemovePointListener listener) { + this.listener = listener; + } + @Override public Holder onCreateViewHolder(ViewGroup viewGroup, int i) { View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.measure_points_list_item, viewGroup, false); @@ -53,7 +57,8 @@ class MeasurementToolAdapter extends RecyclerView.Adapter getMeasurementPoints() { + LinkedList getMeasurementPoints() { return measurementPoints; } @@ -141,6 +141,10 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL canvas.rotate(tb.getRotate(), center.x, center.y); } + void resetCachePoints() { + cacheMeasurementPoints = new LinkedList<>(measurementPoints); + } + void addPointOnClick() { RotatedTileBox tb = view.getCurrentRotatedTileBox(); LatLon l = tb.getLatLonFromPixel(tb.getCenterPixelX(), tb.getCenterPixelY()); @@ -154,7 +158,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL } else { measurementPoints.add(pt); } - cacheMeasurementPoints = new LinkedList<>(measurementPoints); + resetCachePoints(); view.refreshMap(); } From 3066ba2ee0f7aa8115415457b5f0e0388ba676a9 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Mon, 7 Aug 2017 14:59:18 +0300 Subject: [PATCH 03/10] Fix layouts --- OsmAnd/res/layout/fragment_measurement_tool.xml | 10 +++++----- OsmAnd/res/layout/measure_points_list_item.xml | 7 +++++-- .../plus/measurementtool/MeasurementToolAdapter.java | 4 ++++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/OsmAnd/res/layout/fragment_measurement_tool.xml b/OsmAnd/res/layout/fragment_measurement_tool.xml index 3b1093abcc..79ae72fa65 100644 --- a/OsmAnd/res/layout/fragment_measurement_tool.xml +++ b/OsmAnd/res/layout/fragment_measurement_tool.xml @@ -81,12 +81,11 @@ android:layout_height="1dp" android:background="?attr/dashboard_divider"/> - @@ -94,14 +93,15 @@ + android:layout_height="match_parent"/> - + Date: Mon, 7 Aug 2017 17:05:57 +0300 Subject: [PATCH 04/10] Replace RecyclerView with ListView --- .../res/layout/fragment_measurement_tool.xml | 6 +-- .../MeasurementToolAdapter.java | 54 ++++++++++--------- .../MeasurementToolFragment.java | 15 +++--- 3 files changed, 40 insertions(+), 35 deletions(-) diff --git a/OsmAnd/res/layout/fragment_measurement_tool.xml b/OsmAnd/res/layout/fragment_measurement_tool.xml index 79ae72fa65..6b684dfd9b 100644 --- a/OsmAnd/res/layout/fragment_measurement_tool.xml +++ b/OsmAnd/res/layout/fragment_measurement_tool.xml @@ -84,14 +84,14 @@ - diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolAdapter.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolAdapter.java index 8eb26781fa..7c9346334a 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolAdapter.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolAdapter.java @@ -1,9 +1,13 @@ package net.osmand.plus.measurementtool; -import android.support.v7.widget.RecyclerView; +import android.content.Context; +import android.support.annotation.LayoutRes; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ArrayAdapter; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.TextView; @@ -17,33 +21,39 @@ import net.osmand.util.MapUtils; import java.util.List; -class MeasurementToolAdapter extends RecyclerView.Adapter { +class MeasurementToolAdapter extends ArrayAdapter { private MapActivity mapActivity; private List points; private RemovePointListener listener; - MeasurementToolAdapter(MapActivity mapActivity, List points) { - this.mapActivity = mapActivity; + MeasurementToolAdapter(@NonNull Context context, @LayoutRes int resource, List points) { + super(context, resource, points); + this.mapActivity = (MapActivity) context; this.points = points; } - public void setListener(RemovePointListener listener) { + void setRemovePointListener(RemovePointListener listener) { this.listener = listener; } + @NonNull @Override - public Holder onCreateViewHolder(ViewGroup viewGroup, int i) { - View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.measure_points_list_item, viewGroup, false); - final boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls(); - if (!nightMode) { - view.findViewById(R.id.points_divider).setBackgroundResource(R.drawable.divider); - } - return new Holder(view); - } + public View getView(final int pos, @Nullable View view, @NonNull ViewGroup parent) { + ViewHolder holder; + + if (view == null) { + view = LayoutInflater.from(parent.getContext()).inflate(R.layout.measure_points_list_item, parent, false); + final boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls(); + if (!nightMode) { + view.findViewById(R.id.points_divider).setBackgroundResource(R.drawable.divider); + } + holder = new ViewHolder(view); + view.setTag(holder); + } else { + holder = (ViewHolder) view.getTag(); + } - @Override - public void onBindViewHolder(final Holder holder, int pos) { IconsCache iconsCache = mapActivity.getMyApplication().getIconsCache(); holder.icon.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_measure_point)); holder.title.setText(mapActivity.getString(R.string.plugin_distance_point) + " - " + (pos + 1)); @@ -61,26 +71,22 @@ class MeasurementToolAdapter extends RecyclerView.Adapter Date: Mon, 7 Aug 2017 17:28:58 +0300 Subject: [PATCH 05/10] Add ability to move map to the selected point --- OsmAnd/res/layout/measure_points_list_item.xml | 4 +++- .../plus/measurementtool/MeasurementToolFragment.java | 7 +++++++ .../osmand/plus/measurementtool/MeasurementToolLayer.java | 5 +++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/OsmAnd/res/layout/measure_points_list_item.xml b/OsmAnd/res/layout/measure_points_list_item.xml index a24901c3c1..7932721f15 100644 --- a/OsmAnd/res/layout/measure_points_list_item.xml +++ b/OsmAnd/res/layout/measure_points_list_item.xml @@ -3,7 +3,8 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:layout_height="48dp"> + android:layout_height="48dp" + android:descendantFocusability="blocksDescendants"> adapterView, View view, int pos, long l) { + measurementLayer.moveMapToPoint(pos); + } + }); return view; } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java index 6399e949ba..d699016cf4 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java @@ -178,6 +178,11 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL return cacheMeasurementPoints.size() > measurementPoints.size(); } + void moveMapToPoint(int pos) { + WptPt pt = measurementPoints.get(pos); + view.getAnimatedDraggingThread().startMoving(pt.getLatitude(), pt.getLongitude(), view.getZoom(), true); + } + @Override public void destroyLayer() { From cade8b05f2865eb0d1f5e67a74360a597cd13006 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Mon, 7 Aug 2017 17:52:15 +0300 Subject: [PATCH 06/10] Add final modifiers --- .../plus/measurementtool/MeasurementToolAdapter.java | 4 ++-- .../plus/measurementtool/MeasurementToolLayer.java | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolAdapter.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolAdapter.java index 7c9346334a..5062915c27 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolAdapter.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolAdapter.java @@ -23,8 +23,8 @@ import java.util.List; class MeasurementToolAdapter extends ArrayAdapter { - private MapActivity mapActivity; - private List points; + private final MapActivity mapActivity; + private final List points; private RemovePointListener listener; MeasurementToolAdapter(@NonNull Context context, @LayoutRes int resource, List points) { diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java index d699016cf4..722b59b5b2 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java @@ -28,18 +28,18 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL private OsmandMapTileView view; private boolean inMeasurementMode; - private LinkedList measurementPoints = new LinkedList<>(); + private final LinkedList measurementPoints = new LinkedList<>(); private LinkedList cacheMeasurementPoints = new LinkedList<>(); private Bitmap centerIconDay; private Bitmap centerIconNight; private Bitmap pointIcon; private Paint bitmapPaint; - private RenderingLineAttributes lineAttrs = new RenderingLineAttributes("measureDistanceLine"); - private Path path = new Path(); + private final RenderingLineAttributes lineAttrs = new RenderingLineAttributes("measureDistanceLine"); + private final Path path = new Path(); private int marginX; private int marginY; - private TIntArrayList tx = new TIntArrayList(); - private TIntArrayList ty = new TIntArrayList(); + private final TIntArrayList tx = new TIntArrayList(); + private final TIntArrayList ty = new TIntArrayList(); @Override public void initLayer(OsmandMapTileView view) { From 8921d283f6df50593d06d13b545b7d0db528840a Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Mon, 7 Aug 2017 18:07:46 +0300 Subject: [PATCH 07/10] Set alpha for shadow --- OsmAnd/res/layout/fragment_measurement_tool.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/OsmAnd/res/layout/fragment_measurement_tool.xml b/OsmAnd/res/layout/fragment_measurement_tool.xml index 6b684dfd9b..c655043bbd 100644 --- a/OsmAnd/res/layout/fragment_measurement_tool.xml +++ b/OsmAnd/res/layout/fragment_measurement_tool.xml @@ -99,6 +99,7 @@ android:layout_width="match_parent" android:layout_height="5dp" android:layout_gravity="bottom" + android:alpha="0.5" android:scaleType="fitXY" android:src="@drawable/bg_shadow_onmap"/> From e7bc8e4140dcd89020a25e19af4bef9b6dff51e7 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Mon, 7 Aug 2017 18:39:13 +0300 Subject: [PATCH 08/10] Add an upper position for the center of the map --- .../res/layout/fragment_measurement_tool.xml | 2 +- .../src/net/osmand/plus/OsmandSettings.java | 3 ++- .../cards/dialogs/ContextMenuCardDialog.java | 7 ++---- .../MeasurementToolFragment.java | 22 +++++++++++++++++++ .../plus/views/MapQuickActionLayer.java | 2 +- .../osmand/plus/views/OsmandMapTileView.java | 4 +++- 6 files changed, 31 insertions(+), 9 deletions(-) diff --git a/OsmAnd/res/layout/fragment_measurement_tool.xml b/OsmAnd/res/layout/fragment_measurement_tool.xml index c655043bbd..b146c796ca 100644 --- a/OsmAnd/res/layout/fragment_measurement_tool.xml +++ b/OsmAnd/res/layout/fragment_measurement_tool.xml @@ -84,7 +84,7 @@ diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 93b7f97da9..03147d4e8b 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -1244,7 +1244,8 @@ public class OsmandSettings { // this value string is synchronized with settings_pref.xml preference name public static final int CENTER_CONSTANT = 0; public static final int BOTTOM_CONSTANT = 1; - public static final int MIDDLE_CONSTANT = 2; + public static final int MIDDLE_BOTTOM_CONSTANT = 2; + public static final int MIDDLE_TOP_CONSTANT = 3; public final CommonPreference CENTER_POSITION_ON_MAP = new BooleanPreference("center_position_on_map", false).makeProfile(); // this value string is synchronized with settings_pref.xml preference name diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/dialogs/ContextMenuCardDialog.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/dialogs/ContextMenuCardDialog.java index 29fc6b6395..1474b371d7 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/dialogs/ContextMenuCardDialog.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/dialogs/ContextMenuCardDialog.java @@ -3,7 +3,6 @@ package net.osmand.plus.mapcontextmenu.builders.cards.dialogs; import android.os.Bundle; import android.support.annotation.NonNull; import android.view.Menu; -import android.view.MenuItem; import android.view.View; import net.osmand.plus.OsmandSettings; @@ -12,8 +11,6 @@ import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.mapillary.MapillaryImageDialog; import net.osmand.plus.views.OsmandMapTileView; -import java.util.List; - public abstract class ContextMenuCardDialog { private MapActivity mapActivity; @@ -109,9 +106,9 @@ public abstract class ContextMenuCardDialog { private void shiftMapPosition() { OsmandMapTileView mapView = mapActivity.getMapView(); if (AndroidUiHelper.isOrientationPortrait(mapActivity)) { - if (mapView.getMapPosition() != OsmandSettings.MIDDLE_CONSTANT) { + if (mapView.getMapPosition() != OsmandSettings.MIDDLE_BOTTOM_CONSTANT) { prevMapPosition = mapView.getMapPosition(); - mapView.setMapPosition(OsmandSettings.MIDDLE_CONSTANT); + mapView.setMapPosition(OsmandSettings.MIDDLE_BOTTOM_CONSTANT); } } else { mapView.setMapPositionX(1); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index 050a8331f0..d5d49242aa 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -36,6 +36,7 @@ import net.osmand.plus.IconsCache; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.AndroidUiHelper; +import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; import net.osmand.plus.widgets.IconPopupMenu; @@ -48,6 +49,7 @@ import java.util.LinkedList; import java.util.Locale; import static net.osmand.plus.GPXUtilities.GPXFile; +import static net.osmand.plus.OsmandSettings.MIDDLE_TOP_CONSTANT; import static net.osmand.plus.helpers.GpxImportHelper.GPX_SUFFIX; public class MeasurementToolFragment extends Fragment { @@ -62,6 +64,7 @@ public class MeasurementToolFragment extends Fragment { private boolean wasCollapseButtonVisible; private boolean pointsDetailsOpened; + private int previousMapPosition; @Nullable @Override @@ -229,12 +232,28 @@ public class MeasurementToolFragment extends Fragment { pointsDetailsOpened = true; view.findViewById(R.id.points_list_container).setVisibility(View.VISIBLE); ((ImageButton) view.findViewById(R.id.up_down_button)).setImageDrawable(icon); + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + OsmandMapTileView tileView = mapActivity.getMapView(); + previousMapPosition = tileView.getMapPosition(); + tileView.setMapPosition(MIDDLE_TOP_CONSTANT); + mapActivity.refreshMap(); + } } private void downBtnOnClick(View view, Drawable icon) { pointsDetailsOpened = false; view.findViewById(R.id.points_list_container).setVisibility(View.GONE); ((ImageButton) view.findViewById(R.id.up_down_button)).setImageDrawable(icon); + setPreviousMapPosition(); + } + + private void setPreviousMapPosition() { + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + mapActivity.getMapView().setMapPosition(previousMapPosition); + mapActivity.refreshMap(); + } } private void saveAsGpxOnClick(MapActivity mapActivity) { @@ -371,6 +390,9 @@ public class MeasurementToolFragment extends Fragment { super.onDestroyView(); exitMeasurementMode(); adapter.setRemovePointListener(null); + if (pointsDetailsOpened) { + setPreviousMapPosition(); + } } private MapActivity getMapActivity() { diff --git a/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java b/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java index c5365d41ff..f5129c680a 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java @@ -218,7 +218,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe private void enterMovingMode(RotatedTileBox tileBox) { previousMapPosition = view.getMapPosition(); - view.setMapPosition(OsmandSettings.MIDDLE_CONSTANT); + view.setMapPosition(OsmandSettings.MIDDLE_BOTTOM_CONSTANT); MapContextMenu menu = mapActivity.getContextMenu(); LatLon ll = menu.isActive() && tileBox.containsLatLon(menu.getLatLon()) ? menu.getLatLon() : tileBox.getCenterLatLon(); diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java index 2553ffaaad..4ddb967c7d 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java @@ -578,8 +578,10 @@ public class OsmandMapTileView implements IMapDownloaderCallback { final float ratioy; if (mapPosition == OsmandSettings.BOTTOM_CONSTANT) { ratioy = 0.85f; - } else if (mapPosition == OsmandSettings.MIDDLE_CONSTANT) { + } else if (mapPosition == OsmandSettings.MIDDLE_BOTTOM_CONSTANT) { ratioy = 0.70f; + } else if (mapPosition == OsmandSettings.MIDDLE_TOP_CONSTANT) { + ratioy = 0.25f; } else { ratioy = 0.5f; } From 3dcc410fd7a1600e429e69e424372e64f36862d4 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Tue, 8 Aug 2017 12:49:47 +0300 Subject: [PATCH 09/10] Replace ListView with RecyclerView --- .../res/layout/fragment_measurement_tool.xml | 4 +- .../MeasurementToolAdapter.java | 77 +++++++++++-------- .../MeasurementToolFragment.java | 17 ++-- 3 files changed, 54 insertions(+), 44 deletions(-) diff --git a/OsmAnd/res/layout/fragment_measurement_tool.xml b/OsmAnd/res/layout/fragment_measurement_tool.xml index b146c796ca..6e2250ea2e 100644 --- a/OsmAnd/res/layout/fragment_measurement_tool.xml +++ b/OsmAnd/res/layout/fragment_measurement_tool.xml @@ -90,8 +90,8 @@ - diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolAdapter.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolAdapter.java index 5062915c27..57ae8e9b63 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolAdapter.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolAdapter.java @@ -1,13 +1,9 @@ package net.osmand.plus.measurementtool; -import android.content.Context; -import android.support.annotation.LayoutRes; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; +import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ArrayAdapter; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.TextView; @@ -21,39 +17,44 @@ import net.osmand.util.MapUtils; import java.util.List; -class MeasurementToolAdapter extends ArrayAdapter { +class MeasurementToolAdapter extends RecyclerView.Adapter { - private final MapActivity mapActivity; - private final List points; - private RemovePointListener listener; + private MapActivity mapActivity; + private List points; + private RemovePointListener removePointListener; + private ItemClickListener itemClickListener; - MeasurementToolAdapter(@NonNull Context context, @LayoutRes int resource, List points) { - super(context, resource, points); - this.mapActivity = (MapActivity) context; + MeasurementToolAdapter(MapActivity mapActivity, List points) { + this.mapActivity = mapActivity; this.points = points; } void setRemovePointListener(RemovePointListener listener) { - this.listener = listener; + this.removePointListener = listener; + } + + public void setItemClickListener(ItemClickListener itemClickListener) { + this.itemClickListener = itemClickListener; } - @NonNull @Override - public View getView(final int pos, @Nullable View view, @NonNull ViewGroup parent) { - ViewHolder holder; - - if (view == null) { - view = LayoutInflater.from(parent.getContext()).inflate(R.layout.measure_points_list_item, parent, false); - final boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls(); - if (!nightMode) { - view.findViewById(R.id.points_divider).setBackgroundResource(R.drawable.divider); - } - holder = new ViewHolder(view); - view.setTag(holder); - } else { - holder = (ViewHolder) view.getTag(); + public Holder onCreateViewHolder(ViewGroup viewGroup, int i) { + View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.measure_points_list_item, viewGroup, false); + final boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls(); + if (!nightMode) { + view.findViewById(R.id.points_divider).setBackgroundResource(R.drawable.divider); } + view.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + itemClickListener.onItemClick(view); + } + }); + return new Holder(view); + } + @Override + public void onBindViewHolder(final Holder holder, int pos) { IconsCache iconsCache = mapActivity.getMyApplication().getIconsCache(); holder.icon.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_measure_point)); holder.title.setText(mapActivity.getString(R.string.plugin_distance_point) + " - " + (pos + 1)); @@ -71,22 +72,26 @@ class MeasurementToolAdapter extends ArrayAdapter { holder.deleteBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - points.remove(pos); - listener.onPointRemove(); + points.remove(holder.getAdapterPosition()); + removePointListener.onPointRemove(); } }); - - return view; } - private static class ViewHolder { + @Override + public int getItemCount() { + return points.size(); + } + + static class Holder extends RecyclerView.ViewHolder { final ImageView icon; final TextView title; final TextView descr; final ImageButton deleteBtn; - ViewHolder(View view) { + Holder(View view) { + super(view); icon = (ImageView) view.findViewById(R.id.measure_point_icon); title = (TextView) view.findViewById(R.id.measure_point_title); descr = (TextView) view.findViewById(R.id.measure_point_descr); @@ -97,4 +102,8 @@ class MeasurementToolAdapter extends ArrayAdapter { interface RemovePointListener { void onPointRemove(); } -} + + interface ItemClickListener { + void onItemClick(View view); + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index d5d49242aa..9279ba54a2 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -10,6 +10,8 @@ import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.content.ContextCompat; import android.support.v7.app.AlertDialog; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; import android.support.v7.widget.SwitchCompat; import android.text.Editable; import android.text.TextWatcher; @@ -19,11 +21,9 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import android.widget.AdapterView; import android.widget.EditText; import android.widget.ImageButton; import android.widget.ImageView; -import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; @@ -200,7 +200,7 @@ public class MeasurementToolFragment extends Fragment { mapActivity.showTopToolbar(toolBarController); } - adapter = new MeasurementToolAdapter(getMapActivity(), R.layout.measure_points_list_item, measurementLayer.getMeasurementPoints()); + adapter = new MeasurementToolAdapter(getMapActivity(), measurementLayer.getMeasurementPoints()); adapter.setRemovePointListener(new MeasurementToolAdapter.RemovePointListener() { @Override public void onPointRemove() { @@ -215,12 +215,13 @@ public class MeasurementToolFragment extends Fragment { } } }); - ListView lv = mainView.findViewById(R.id.measure_points_list_view); - lv.setDivider(null); - lv.setAdapter(adapter); - lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { + final RecyclerView rv = mainView.findViewById(R.id.measure_points_recycler_view); + rv.setLayoutManager(new LinearLayoutManager(getContext())); + rv.setAdapter(adapter); + adapter.setItemClickListener(new MeasurementToolAdapter.ItemClickListener() { @Override - public void onItemClick(AdapterView adapterView, View view, int pos, long l) { + public void onItemClick(View view) { + int pos = rv.indexOfChild(view); measurementLayer.moveMapToPoint(pos); } }); From 8f00527bd77c3d79502d4b679e90ce752de674c2 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Tue, 8 Aug 2017 12:54:13 +0300 Subject: [PATCH 10/10] Add small changes --- .../plus/measurementtool/MeasurementToolAdapter.java | 4 ++-- .../plus/measurementtool/MeasurementToolFragment.java | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolAdapter.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolAdapter.java index 57ae8e9b63..a2c4e79f69 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolAdapter.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolAdapter.java @@ -19,8 +19,8 @@ import java.util.List; class MeasurementToolAdapter extends RecyclerView.Adapter { - private MapActivity mapActivity; - private List points; + private final MapActivity mapActivity; + private final List points; private RemovePointListener removePointListener; private ItemClickListener itemClickListener; diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index 9279ba54a2..82d4440e6b 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -201,6 +201,7 @@ public class MeasurementToolFragment extends Fragment { } adapter = new MeasurementToolAdapter(getMapActivity(), measurementLayer.getMeasurementPoints()); + final RecyclerView rv = mainView.findViewById(R.id.measure_points_recycler_view); adapter.setRemovePointListener(new MeasurementToolAdapter.RemovePointListener() { @Override public void onPointRemove() { @@ -215,9 +216,6 @@ public class MeasurementToolFragment extends Fragment { } } }); - final RecyclerView rv = mainView.findViewById(R.id.measure_points_recycler_view); - rv.setLayoutManager(new LinearLayoutManager(getContext())); - rv.setAdapter(adapter); adapter.setItemClickListener(new MeasurementToolAdapter.ItemClickListener() { @Override public void onItemClick(View view) { @@ -225,6 +223,8 @@ public class MeasurementToolFragment extends Fragment { measurementLayer.moveMapToPoint(pos); } }); + rv.setLayoutManager(new LinearLayoutManager(getContext())); + rv.setAdapter(adapter); return view; } @@ -391,6 +391,7 @@ public class MeasurementToolFragment extends Fragment { super.onDestroyView(); exitMeasurementMode(); adapter.setRemovePointListener(null); + adapter.setItemClickListener(null); if (pointsDetailsOpened) { setPreviousMapPosition(); }