From fde588081ddba9a4571bbd994abf1834f31102d9 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 29 Aug 2017 13:55:36 +0300 Subject: [PATCH 01/12] Create fragments and related things for new map markers --- .../bottom_navigation_color_selector.xml | 5 + .../layout/fragment_map_markers_dialog.xml | 38 +++++++ .../menu/map_markers_bottom_navigation.xml | 12 +++ .../mapmarkers/MapMarkersActiveFragment.java | 20 ++++ .../mapmarkers/MapMarkersDialogFragment.java | 101 ++++++++++++++++++ .../mapmarkers/MapMarkersHistoryFragment.java | 20 ++++ 6 files changed, 196 insertions(+) create mode 100644 OsmAnd/res/color/bottom_navigation_color_selector.xml create mode 100644 OsmAnd/res/layout/fragment_map_markers_dialog.xml create mode 100644 OsmAnd/res/menu/map_markers_bottom_navigation.xml create mode 100644 OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java create mode 100644 OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java create mode 100644 OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java diff --git a/OsmAnd/res/color/bottom_navigation_color_selector.xml b/OsmAnd/res/color/bottom_navigation_color_selector.xml new file mode 100644 index 0000000000..d1537744a1 --- /dev/null +++ b/OsmAnd/res/color/bottom_navigation_color_selector.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/OsmAnd/res/layout/fragment_map_markers_dialog.xml b/OsmAnd/res/layout/fragment_map_markers_dialog.xml new file mode 100644 index 0000000000..ff0494c462 --- /dev/null +++ b/OsmAnd/res/layout/fragment_map_markers_dialog.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + diff --git a/OsmAnd/res/menu/map_markers_bottom_navigation.xml b/OsmAnd/res/menu/map_markers_bottom_navigation.xml new file mode 100644 index 0000000000..5751b155b0 --- /dev/null +++ b/OsmAnd/res/menu/map_markers_bottom_navigation.xml @@ -0,0 +1,12 @@ + + + + + + diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java new file mode 100644 index 0000000000..10178b2cd7 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java @@ -0,0 +1,20 @@ +package net.osmand.plus.mapmarkers; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +public class MapMarkersActiveFragment extends Fragment { + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + TextView textView = new TextView(getContext()); + textView.setText("active fragment"); + return textView; + } +} diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java new file mode 100644 index 0000000000..5ed339b9ef --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java @@ -0,0 +1,101 @@ +package net.osmand.plus.mapmarkers; + +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.design.widget.BottomNavigationView; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentPagerAdapter; +import android.view.LayoutInflater; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; + +import net.osmand.plus.LockableViewPager; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandSettings; +import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; + +import java.util.Arrays; +import java.util.List; + +public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragment { + + public static final String TAG = "MapMarkersDialogFragment"; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + OsmandApplication app = getMyApplication(); + boolean isLightTheme = app.getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME; + int themeId = isLightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme; + setStyle(STYLE_NO_FRAME, themeId); + } + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { + View mainView = inflater.inflate(R.layout.fragment_map_markers_dialog, container); + + final LockableViewPager viewPager = mainView.findViewById(R.id.map_markers_view_pager); + viewPager.setSwipeLocked(true); + viewPager.setAdapter(new MapMarkersViewPagerAdapter(getChildFragmentManager())); + + BottomNavigationView bottomNav = mainView.findViewById(R.id.map_markers_bottom_navigation); + bottomNav.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { + @Override + public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) { + switch (menuItem.getItemId()) { + case R.id.action_active: + viewPager.setCurrentItem(0); + return true; + case R.id.action_history: + viewPager.setCurrentItem(1); + return true; + } + return false; + } + }); + + return mainView; + } + + private OsmandApplication getMyApplication() { + return (OsmandApplication) getActivity().getApplication(); + } + + public static boolean showInstance(@NonNull MapActivity mapActivity) { + try { + if (mapActivity.isActivityDestroyed()) { + return false; + } + MapMarkersDialogFragment fragment = new MapMarkersDialogFragment(); + fragment.show(mapActivity.getSupportFragmentManager(), TAG); + return true; + } catch (RuntimeException e) { + return false; + } + } + + private class MapMarkersViewPagerAdapter extends FragmentPagerAdapter { + + private final List fragments; + + MapMarkersViewPagerAdapter(FragmentManager fm) { + super(fm); + fragments = Arrays.asList(new MapMarkersActiveFragment(), new MapMarkersHistoryFragment()); + } + + @Override + public Fragment getItem(int position) { + return fragments.get(position); + } + + @Override + public int getCount() { + return fragments.size(); + } + } +} diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java new file mode 100644 index 0000000000..1667047172 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java @@ -0,0 +1,20 @@ +package net.osmand.plus.mapmarkers; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +public class MapMarkersHistoryFragment extends Fragment { + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + TextView textView = new TextView(getContext()); + textView.setText("history fragment"); + return textView; + } +} From 489e228e3ff8e4f0be199378317a29b7a47e9da9 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 29 Aug 2017 16:02:12 +0300 Subject: [PATCH 02/12] Add toolbar --- .../layout/fragment_map_markers_dialog.xml | 43 +++++++++++++++++-- .../mapmarkers/MapMarkersDialogFragment.java | 17 ++++++++ 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/OsmAnd/res/layout/fragment_map_markers_dialog.xml b/OsmAnd/res/layout/fragment_map_markers_dialog.xml index ff0494c462..eb0335a3ee 100644 --- a/OsmAnd/res/layout/fragment_map_markers_dialog.xml +++ b/OsmAnd/res/layout/fragment_map_markers_dialog.xml @@ -3,14 +3,50 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" - android:layout_height="match_parent" - android:background="?attr/bg_color"> + android:layout_height="match_parent"> + + + + + + + + + + + + android:layout_below="@+id/map_markers_toolbar"> Date: Tue, 29 Aug 2017 18:59:26 +0300 Subject: [PATCH 03/12] Move method from MapMarkerDialogHelper to MapMarkersHelper; add some code for new map markers --- OsmAnd/res/layout/map_marker_item_new.xml | 43 +++++------ .../src/net/osmand/plus/MapMarkersHelper.java | 30 ++++++++ .../plus/helpers/MapMarkerDialogHelper.java | 35 +-------- .../mapmarkers/MapMarkersActiveFragment.java | 34 +++++++-- .../adapters/MapMarkerItemViewHolder.java | 33 +++++++++ .../adapters/MapMarkersActiveAdapter.java | 72 +++++++++++++++++++ .../mapwidgets/MapMarkersWidgetsFactory.java | 5 +- 7 files changed, 192 insertions(+), 60 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java create mode 100644 OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java diff --git a/OsmAnd/res/layout/map_marker_item_new.xml b/OsmAnd/res/layout/map_marker_item_new.xml index f3531437eb..140b98c2a1 100644 --- a/OsmAnd/res/layout/map_marker_item_new.xml +++ b/OsmAnd/res/layout/map_marker_item_new.xml @@ -4,37 +4,41 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="56dp" + android:background="?attr/bg_color" android:descendantFocusability="blocksDescendants"> + android:background="?attr/selectableItemBackground"> diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index febf7a53ed..2e3c5e4a75 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -463,4 +463,34 @@ public class MapMarkersHelper { ctx.getGeocodingLookupService().cancel(latLon); } } + + public static int getMapMarkerColorId(int colorIndex) { + int colorId; + switch (colorIndex) { + case 0: + colorId = R.color.marker_blue; + break; + case 1: + colorId = R.color.marker_green; + break; + case 2: + colorId = R.color.marker_orange; + break; + case 3: + colorId = R.color.marker_red; + break; + case 4: + colorId = R.color.marker_yellow; + break; + case 5: + colorId = R.color.marker_teal; + break; + case 6: + colorId = R.color.marker_purple; + break; + default: + colorId = R.color.marker_blue; + } + return colorId; + } } diff --git a/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java b/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java index 4d8c4a35e0..f74f7c32ff 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java @@ -43,7 +43,6 @@ import net.osmand.plus.views.DirectionDrawable; import net.osmand.plus.views.controls.DynamicListView; import net.osmand.plus.views.controls.ListDividerShape; import net.osmand.plus.views.controls.StableArrayAdapter; -import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; import java.io.File; @@ -784,37 +783,7 @@ public class MapMarkerDialogHelper { } public static Drawable getMapMarkerIcon(OsmandApplication app, int colorIndex) { - return app.getIconsCache().getIcon(R.drawable.ic_action_flag_dark, getMapMarkerColorId(colorIndex)); - } - - public static int getMapMarkerColorId(int colorIndex) { - int colorId; - switch (colorIndex) { - case 0: - colorId = R.color.marker_blue; - break; - case 1: - colorId = R.color.marker_green; - break; - case 2: - colorId = R.color.marker_orange; - break; - case 3: - colorId = R.color.marker_red; - break; - case 4: - colorId = R.color.marker_yellow; - break; - case 5: - colorId = R.color.marker_teal; - break; - case 6: - colorId = R.color.marker_purple; - break; - default: - colorId = R.color.marker_blue; - } - return colorId; + return app.getIconsCache().getIcon(R.drawable.ic_action_flag_dark, MapMarkersHelper.getMapMarkerColorId(colorIndex)); } public void updateLocation(ListView listView, boolean compassChanged) { @@ -896,7 +865,7 @@ public class MapMarkerDialogHelper { WptPt wpt = new WptPt(); wpt.lat = marker.getLatitude(); wpt.lon = marker.getLongitude(); - wpt.setColor(mapActivity.getResources().getColor(getMapMarkerColorId(marker.colorIndex))); + wpt.setColor(mapActivity.getResources().getColor(MapMarkersHelper.getMapMarkerColorId(marker.colorIndex))); wpt.name = marker.getOnlyName(); //wpt.link = r.getFileName(); //wpt.time = r.getFile().lastModified(); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java index 10178b2cd7..a3268f01c6 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java @@ -1,20 +1,46 @@ package net.osmand.plus.mapmarkers; +import android.app.Activity; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.TextView; +import android.widget.Toast; + +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.mapmarkers.adapters.MapMarkersActiveAdapter; +import net.osmand.plus.mapmarkers.adapters.MapMarkersActiveAdapter.MapMarkersActiveAdapterListener; public class MapMarkersActiveFragment extends Fragment { @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - TextView textView = new TextView(getContext()); - textView.setText("active fragment"); - return textView; + final RecyclerView recyclerView = new RecyclerView(getContext()); + recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); + OsmandApplication app = getMyApplication(); + if (app != null) { + MapMarkersActiveAdapter adapter = new MapMarkersActiveAdapter(app); + adapter.setAdapterListener(new MapMarkersActiveAdapterListener() { + @Override + public void onItemClick(View view) { + Toast.makeText(getContext(), recyclerView.indexOfChild(view) + "", Toast.LENGTH_SHORT).show(); + } + }); + recyclerView.setAdapter(adapter); + } + return recyclerView; + } + + private OsmandApplication getMyApplication() { + Activity activity = getActivity(); + if (activity != null) { + return (OsmandApplication) activity.getApplication(); + } + return null; } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java new file mode 100644 index 0000000000..8775a599f9 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java @@ -0,0 +1,33 @@ +package net.osmand.plus.mapmarkers.adapters; + +import android.support.v7.widget.RecyclerView; +import android.view.View; +import android.widget.ImageButton; +import android.widget.ImageView; +import android.widget.TextView; + +import net.osmand.plus.R; + +public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder { + + final ImageView iconDirection; + final ImageView iconReorder; + final ImageView icon; + final TextView title; + final TextView distance; + final TextView point; + final TextView description; + final ImageButton options; + + public MapMarkerItemViewHolder(View view) { + super(view); + iconDirection = (ImageView) view.findViewById(R.id.map_marker_direction_icon); + iconReorder = (ImageView) view.findViewById(R.id.map_marker_reorder_icon); + icon = (ImageView) view.findViewById(R.id.map_marker_icon); + title = (TextView) view.findViewById(R.id.map_marker_title); + distance = (TextView) view.findViewById(R.id.map_marker_distance); + point = (TextView) view.findViewById(R.id.map_marker_point_text_view); + description = (TextView) view.findViewById(R.id.map_marker_description); + options = (ImageButton) view.findViewById(R.id.map_marker_options_button); + } +} diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java new file mode 100644 index 0000000000..4ca0f41e25 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -0,0 +1,72 @@ +package net.osmand.plus.mapmarkers.adapters; + +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.MotionEvent; +import android.view.View; +import android.view.ViewGroup; + +import net.osmand.plus.IconsCache; +import net.osmand.plus.MapMarkersHelper; +import net.osmand.plus.MapMarkersHelper.MapMarker; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; + +import java.util.List; + +public class MapMarkersActiveAdapter extends RecyclerView.Adapter { + + private OsmandApplication application; + private List markers; + private MapMarkersActiveAdapterListener listener; + + public MapMarkersActiveAdapter(OsmandApplication application) { + this.application = application; + markers = application.getMapMarkersHelper().getMapMarkers(); + } + + public void setAdapterListener(MapMarkersActiveAdapterListener listener) { + this.listener = listener; + } + + @Override + public MapMarkerItemViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { + View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.map_marker_item_new, viewGroup, false); + view.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + listener.onItemClick(view); + } + }); + return new MapMarkerItemViewHolder(view); + } + + @Override + public void onBindViewHolder(MapMarkerItemViewHolder holder, int pos) { + IconsCache iconsCache = application.getIconsCache(); + MapMarker marker = markers.get(pos); + + holder.iconReorder.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_reorder)); + holder.iconReorder.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View view, MotionEvent motionEvent) { + return false; + } + }); + + int color = MapMarkersHelper.getMapMarkerColorId(marker.colorIndex); + holder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_flag_dark, color)); + + holder.title.setText(marker.getName(application)); + } + + @Override + public int getItemCount() { + return markers.size(); + } + + public interface MapMarkersActiveAdapterListener { + + void onItemClick(View view); + } +} diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java index 78dc836f2f..da924a42dc 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java @@ -17,7 +17,6 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.dashboard.DashLocationFragment; import net.osmand.plus.dashboard.DashboardOnMap; import net.osmand.plus.helpers.AndroidUiHelper; -import net.osmand.plus.helpers.MapMarkerDialogHelper; import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu; import net.osmand.plus.views.AnimateDraggingMapThread; import net.osmand.plus.views.DirectionDrawable; @@ -251,7 +250,7 @@ public class MapMarkersWidgetsFactory { } else { dd = (DirectionDrawable) arrowImg.getDrawable(); } - dd.setImage(R.drawable.ic_arrow_marker_diretion, MapMarkerDialogHelper.getMapMarkerColorId(marker.colorIndex)); + dd.setImage(R.drawable.ic_arrow_marker_diretion, MapMarkersHelper.getMapMarkerColorId(marker.colorIndex)); if (heading != null && loc != null) { dd.setAngle(mes[1] - heading + 180 + screenOrientation); } @@ -365,7 +364,7 @@ public class MapMarkersWidgetsFactory { setImageDrawable(map.getMyApplication().getIconsCache() .getIcon(isNight() ? R.drawable.widget_marker_night : R.drawable.widget_marker_day, R.drawable.widget_marker_triangle, - MapMarkerDialogHelper.getMapMarkerColorId(marker.colorIndex))); + MapMarkersHelper.getMapMarkerColorId(marker.colorIndex))); cachedMarkerColorIndex = marker.colorIndex; cachedNightMode = isNight(); res = true; From 46da397593d05690fef4f3b314172d9190fc17c1 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 29 Aug 2017 21:22:11 +0300 Subject: [PATCH 04/12] Add some code --- .../mapmarkers/MapMarkersActiveFragment.java | 17 ++---- .../adapters/MapMarkersActiveAdapter.java | 56 ++++++++++++++++--- 2 files changed, 53 insertions(+), 20 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java index a3268f01c6..3f49ffb01d 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java @@ -1,6 +1,5 @@ package net.osmand.plus.mapmarkers; -import android.app.Activity; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; @@ -11,7 +10,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.Toast; -import net.osmand.plus.OsmandApplication; +import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapmarkers.adapters.MapMarkersActiveAdapter; import net.osmand.plus.mapmarkers.adapters.MapMarkersActiveAdapter.MapMarkersActiveAdapterListener; @@ -22,9 +21,9 @@ public class MapMarkersActiveFragment extends Fragment { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { final RecyclerView recyclerView = new RecyclerView(getContext()); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - OsmandApplication app = getMyApplication(); - if (app != null) { - MapMarkersActiveAdapter adapter = new MapMarkersActiveAdapter(app); + MapActivity mapActivity = (MapActivity) getActivity(); + if (mapActivity != null) { + MapMarkersActiveAdapter adapter = new MapMarkersActiveAdapter(mapActivity); adapter.setAdapterListener(new MapMarkersActiveAdapterListener() { @Override public void onItemClick(View view) { @@ -35,12 +34,4 @@ public class MapMarkersActiveFragment extends Fragment { } return recyclerView; } - - private OsmandApplication getMyApplication() { - Activity activity = getActivity(); - if (activity != null) { - return (OsmandApplication) activity.getApplication(); - } - return null; - } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java index 4ca0f41e25..18d491543c 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -6,23 +6,32 @@ import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; +import net.osmand.Location; +import net.osmand.data.LatLon; import net.osmand.plus.IconsCache; import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper.MapMarker; -import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.dashboard.DashLocationFragment; +import net.osmand.plus.dashboard.DashboardOnMap; +import net.osmand.plus.views.DirectionDrawable; import java.util.List; public class MapMarkersActiveAdapter extends RecyclerView.Adapter { - private OsmandApplication application; + private MapActivity mapActivity; private List markers; private MapMarkersActiveAdapterListener listener; - public MapMarkersActiveAdapter(OsmandApplication application) { - this.application = application; - markers = application.getMapMarkersHelper().getMapMarkers(); + private LatLon location; + private Float heading; + + public MapMarkersActiveAdapter(MapActivity mapActivity) { + this.mapActivity = mapActivity; + markers = mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkers(); } public void setAdapterListener(MapMarkersActiveAdapterListener listener) { @@ -43,7 +52,7 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter Date: Wed, 30 Aug 2017 12:10:27 +0300 Subject: [PATCH 05/12] Add "New map markers" item to drawer; move method --- .../src/net/osmand/plus/MapMarkersHelper.java | 60 +++++++++---------- .../plus/activities/MapActivityActions.java | 13 ++++ .../plus/helpers/MapMarkerDialogHelper.java | 4 +- .../adapters/MapMarkersActiveAdapter.java | 3 +- .../mapwidgets/MapMarkersWidgetsFactory.java | 4 +- 5 files changed, 48 insertions(+), 36 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 2e3c5e4a75..b727621a62 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -105,6 +105,36 @@ public class MapMarkersHelper { result = 31 * result + colorIndex; return result; } + + public static int getColorId(int colorIndex) { + int colorId; + switch (colorIndex) { + case 0: + colorId = R.color.marker_blue; + break; + case 1: + colorId = R.color.marker_green; + break; + case 2: + colorId = R.color.marker_orange; + break; + case 3: + colorId = R.color.marker_red; + break; + case 4: + colorId = R.color.marker_yellow; + break; + case 5: + colorId = R.color.marker_teal; + break; + case 6: + colorId = R.color.marker_purple; + break; + default: + colorId = R.color.marker_blue; + } + return colorId; + } } public MapMarkersHelper(OsmandApplication ctx) { @@ -463,34 +493,4 @@ public class MapMarkersHelper { ctx.getGeocodingLookupService().cancel(latLon); } } - - public static int getMapMarkerColorId(int colorIndex) { - int colorId; - switch (colorIndex) { - case 0: - colorId = R.color.marker_blue; - break; - case 1: - colorId = R.color.marker_green; - break; - case 2: - colorId = R.color.marker_orange; - break; - case 3: - colorId = R.color.marker_red; - break; - case 4: - colorId = R.color.marker_yellow; - break; - case 5: - colorId = R.color.marker_teal; - break; - case 6: - colorId = R.color.marker_purple; - break; - default: - colorId = R.color.marker_blue; - } - return colorId; - } } diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index cebfc913d3..8187f17f61 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -48,6 +48,7 @@ import net.osmand.plus.dashboard.DashboardOnMap.DashboardType; import net.osmand.plus.dialogs.FavoriteDialogs; import net.osmand.plus.download.IndexItem; import net.osmand.plus.liveupdates.OsmLiveActivity; +import net.osmand.plus.mapmarkers.MapMarkersDialogFragment; import net.osmand.plus.measurementtool.MeasurementToolFragment; import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder; @@ -623,6 +624,18 @@ public class MapActivityActions implements DialogProvider { return false; } }).createItem()); + + optionsMenuHelper.addItem(new ItemBuilder().setTitle("New map markers") + .setIcon(R.drawable.ic_action_flag_dark) + .setListener(new ContextMenuAdapter.ItemClickListener() { + @Override + public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { + app.logEvent(mapActivity, "drawer_markers_open"); + MapActivity.clearPrevActivityIntent(); + MapMarkersDialogFragment.showInstance(mapActivity); + return true; + } + }).createItem()); } else { optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.waypoints, mapActivity) .setIcon(R.drawable.ic_action_intermediate) diff --git a/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java b/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java index f74f7c32ff..35823dfcba 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java @@ -783,7 +783,7 @@ public class MapMarkerDialogHelper { } public static Drawable getMapMarkerIcon(OsmandApplication app, int colorIndex) { - return app.getIconsCache().getIcon(R.drawable.ic_action_flag_dark, MapMarkersHelper.getMapMarkerColorId(colorIndex)); + return app.getIconsCache().getIcon(R.drawable.ic_action_flag_dark, MapMarker.getColorId(colorIndex)); } public void updateLocation(ListView listView, boolean compassChanged) { @@ -865,7 +865,7 @@ public class MapMarkerDialogHelper { WptPt wpt = new WptPt(); wpt.lat = marker.getLatitude(); wpt.lon = marker.getLongitude(); - wpt.setColor(mapActivity.getResources().getColor(MapMarkersHelper.getMapMarkerColorId(marker.colorIndex))); + wpt.setColor(mapActivity.getResources().getColor(MapMarker.getColorId(marker.colorIndex))); wpt.name = marker.getOnlyName(); //wpt.link = r.getFileName(); //wpt.time = r.getFile().lastModified(); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java index 18d491543c..e3dbc3f318 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -9,7 +9,6 @@ import android.view.ViewGroup; import net.osmand.Location; import net.osmand.data.LatLon; import net.osmand.plus.IconsCache; -import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.R; @@ -63,7 +62,7 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter Date: Wed, 30 Aug 2017 12:51:51 +0300 Subject: [PATCH 06/12] Fix layout and getting location data --- OsmAnd/res/layout/map_marker_item_new.xml | 8 +++-- .../adapters/MapMarkersActiveAdapter.java | 32 +++++++++---------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/OsmAnd/res/layout/map_marker_item_new.xml b/OsmAnd/res/layout/map_marker_item_new.xml index 140b98c2a1..829b01b1c7 100644 --- a/OsmAnd/res/layout/map_marker_item_new.xml +++ b/OsmAnd/res/layout/map_marker_item_new.xml @@ -78,16 +78,17 @@ android:id="@+id/map_marker_direction_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_gravity="center_vertical" tools:src="@drawable/ic_direction_arrow"/> @@ -95,14 +96,17 @@ android:id="@+id/map_marker_point_text_view" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_gravity="center_vertical" android:text="•" android:textColor="?android:textColorSecondary" - android:textSize="@dimen/default_sub_text_size"/> + android:textSize="@dimen/default_sub_text_size" + android:visibility="gone"/> Date: Wed, 30 Aug 2017 13:11:59 +0300 Subject: [PATCH 07/12] Move to marker on map on list item click --- .../plus/mapmarkers/MapMarkersActiveFragment.java | 14 ++++++++++---- .../adapters/MapMarkersActiveAdapter.java | 4 ++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java index 3f49ffb01d..bdee74d340 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java @@ -2,14 +2,15 @@ package net.osmand.plus.mapmarkers; import android.os.Bundle; import android.support.annotation.Nullable; +import android.support.v4.app.DialogFragment; import android.support.v4.app.Fragment; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.Toast; +import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapmarkers.adapters.MapMarkersActiveAdapter; import net.osmand.plus.mapmarkers.adapters.MapMarkersActiveAdapter.MapMarkersActiveAdapterListener; @@ -21,13 +22,18 @@ public class MapMarkersActiveFragment extends Fragment { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { final RecyclerView recyclerView = new RecyclerView(getContext()); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - MapActivity mapActivity = (MapActivity) getActivity(); + final MapActivity mapActivity = (MapActivity) getActivity(); if (mapActivity != null) { - MapMarkersActiveAdapter adapter = new MapMarkersActiveAdapter(mapActivity); + final MapMarkersActiveAdapter adapter = new MapMarkersActiveAdapter(mapActivity); adapter.setAdapterListener(new MapMarkersActiveAdapterListener() { @Override public void onItemClick(View view) { - Toast.makeText(getContext(), recyclerView.indexOfChild(view) + "", Toast.LENGTH_SHORT).show(); + int pos = recyclerView.indexOfChild(view); + MapMarker marker = adapter.getItem(pos); + mapActivity.getMyApplication().getSettings().setMapLocationToShow(marker.getLatitude(), marker.getLongitude(), + 15, marker.getPointDescription(mapActivity), true, marker); + MapActivity.launchMapActivityMoveToTop(mapActivity); + ((DialogFragment) getParentFragment()).dismiss(); } }); recyclerView.setAdapter(adapter); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java index 5c84a06f4d..fc2a6b64d9 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -92,6 +92,10 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter Date: Wed, 30 Aug 2017 15:21:03 +0300 Subject: [PATCH 08/12] Add improvements --- .../mapmarkers/MapMarkersActiveFragment.java | 110 +++++++++++++++--- .../adapters/MapMarkersActiveAdapter.java | 56 ++++----- 2 files changed, 115 insertions(+), 51 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java index bdee74d340..cf217eb582 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java @@ -10,12 +10,23 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import net.osmand.Location; +import net.osmand.data.LatLon; import net.osmand.plus.MapMarkersHelper.MapMarker; +import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener; +import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; +import net.osmand.plus.OsmandApplication; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.base.MapViewTrackingUtilities; +import net.osmand.plus.dashboard.DashLocationFragment; import net.osmand.plus.mapmarkers.adapters.MapMarkersActiveAdapter; import net.osmand.plus.mapmarkers.adapters.MapMarkersActiveAdapter.MapMarkersActiveAdapterListener; -public class MapMarkersActiveFragment extends Fragment { +public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassListener, OsmAndLocationListener { + + private MapMarkersActiveAdapter adapter; + private Location location; + private float heading; @Nullable @Override @@ -23,21 +34,88 @@ public class MapMarkersActiveFragment extends Fragment { final RecyclerView recyclerView = new RecyclerView(getContext()); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); final MapActivity mapActivity = (MapActivity) getActivity(); - if (mapActivity != null) { - final MapMarkersActiveAdapter adapter = new MapMarkersActiveAdapter(mapActivity); - adapter.setAdapterListener(new MapMarkersActiveAdapterListener() { - @Override - public void onItemClick(View view) { - int pos = recyclerView.indexOfChild(view); - MapMarker marker = adapter.getItem(pos); - mapActivity.getMyApplication().getSettings().setMapLocationToShow(marker.getLatitude(), marker.getLongitude(), - 15, marker.getPointDescription(mapActivity), true, marker); - MapActivity.launchMapActivityMoveToTop(mapActivity); - ((DialogFragment) getParentFragment()).dismiss(); - } - }); - recyclerView.setAdapter(adapter); - } + + adapter = new MapMarkersActiveAdapter(mapActivity); + adapter.setAdapterListener(new MapMarkersActiveAdapterListener() { + @Override + public void onItemClick(View view) { + int pos = recyclerView.indexOfChild(view); + MapMarker marker = adapter.getItem(pos); + mapActivity.getMyApplication().getSettings().setMapLocationToShow(marker.getLatitude(), marker.getLongitude(), + 15, marker.getPointDescription(mapActivity), true, marker); + MapActivity.launchMapActivityMoveToTop(mapActivity); + ((DialogFragment) getParentFragment()).dismiss(); + } + }); + recyclerView.setAdapter(adapter); + return recyclerView; } + + @Override + public void onResume() { + super.onResume(); + adapter.setScreenOrientation(DashLocationFragment.getScreenOrientation(getActivity())); + startLocationUpdate(); + } + + @Override + public void onPause() { + super.onPause(); + stopLocationUpdate(); + } + + @Override + public void updateLocation(Location location) { + this.location = location; + updateLocation(); + } + + @Override + public void updateCompassValue(float heading) { + this.heading = heading; + updateLocation(); + } + + private OsmandApplication getMyApplication() { + if (getActivity() != null) { + return ((MapActivity) getActivity()).getMyApplication(); + } + return null; + } + + private void updateLocation() { + MapActivity mapActivity = (MapActivity) getActivity(); + if (mapActivity != null) { + if (location == null) { + location = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation(); + } + MapViewTrackingUtilities utilities = mapActivity.getMapViewTrackingUtilities(); + boolean useCenter = !(utilities.isMapLinkedToLocation() && location != null); + + adapter.setUseCenter(useCenter); + adapter.setLocation(useCenter ? mapActivity.getMapLocation() : new LatLon(location.getLatitude(), location.getLongitude())); + adapter.setHeading(useCenter ? -mapActivity.getMapRotate() : heading); + adapter.notifyDataSetChanged(); + } + } + + private void startLocationUpdate() { + OsmandApplication app = getMyApplication(); + if (app != null) { + app.getLocationProvider().removeCompassListener(app.getLocationProvider().getNavigationInfo()); + app.getLocationProvider().addCompassListener(this); + app.getLocationProvider().addLocationListener(this); + updateLocation(); + } + } + + private void stopLocationUpdate() { + OsmandApplication app = getMyApplication(); + if (app != null) { + app.getLocationProvider().removeLocationListener(this); + app.getLocationProvider().removeCompassListener(this); + app.getLocationProvider().addCompassListener(app.getLocationProvider().getNavigationInfo()); + } + } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java index fc2a6b64d9..c188105548 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -1,22 +1,17 @@ package net.osmand.plus.mapmarkers.adapters; -import android.support.v4.content.ContextCompat; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; -import net.osmand.Location; import net.osmand.data.LatLon; import net.osmand.plus.IconsCache; import net.osmand.plus.MapMarkersHelper.MapMarker; -import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.base.MapViewTrackingUtilities; import net.osmand.plus.dashboard.DashLocationFragment; -import net.osmand.plus.views.DirectionDrawable; import java.util.List; @@ -29,6 +24,7 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter Date: Wed, 30 Aug 2017 18:35:10 +0300 Subject: [PATCH 09/12] Fix updating UI --- .../mapmarkers/MapMarkersActiveFragment.java | 55 +++++++++++++------ 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java index cf217eb582..53ac0c78e4 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java @@ -21,12 +21,13 @@ import net.osmand.plus.base.MapViewTrackingUtilities; import net.osmand.plus.dashboard.DashLocationFragment; import net.osmand.plus.mapmarkers.adapters.MapMarkersActiveAdapter; import net.osmand.plus.mapmarkers.adapters.MapMarkersActiveAdapter.MapMarkersActiveAdapterListener; +import net.osmand.util.MapUtils; public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassListener, OsmAndLocationListener { private MapMarkersActiveAdapter adapter; private Location location; - private float heading; + private Float heading; @Nullable @Override @@ -67,14 +68,27 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL @Override public void updateLocation(Location location) { - this.location = location; - updateLocation(); + boolean newLocation = this.location == null && location != null; + boolean locationChanged = this.location != null && location != null + && this.location.getLatitude() != location.getLatitude() + && this.location.getLongitude() != location.getLongitude(); + if (newLocation || locationChanged) { + this.location = location; + updateLocationUi(); + } } @Override - public void updateCompassValue(float heading) { - this.heading = heading; - updateLocation(); + public void updateCompassValue(float value) { + // 99 in next line used to one-time initialize arrows (with reference vs. fixed-north direction) + // on non-compass devices + float lastHeading = heading != null ? heading : 99; + heading = value; + if (Math.abs(MapUtils.degreesDiff(lastHeading, heading)) > 5) { + updateLocationUi(); + } else { + heading = lastHeading; + } } private OsmandApplication getMyApplication() { @@ -84,19 +98,24 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL return null; } - private void updateLocation() { - MapActivity mapActivity = (MapActivity) getActivity(); + private void updateLocationUi() { + final MapActivity mapActivity = (MapActivity) getActivity(); if (mapActivity != null) { - if (location == null) { - location = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation(); - } - MapViewTrackingUtilities utilities = mapActivity.getMapViewTrackingUtilities(); - boolean useCenter = !(utilities.isMapLinkedToLocation() && location != null); + mapActivity.getMyApplication().runInUIThread(new Runnable() { + @Override + public void run() { + if (location == null) { + location = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation(); + } + MapViewTrackingUtilities utilities = mapActivity.getMapViewTrackingUtilities(); + boolean useCenter = !(utilities.isMapLinkedToLocation() && location != null); - adapter.setUseCenter(useCenter); - adapter.setLocation(useCenter ? mapActivity.getMapLocation() : new LatLon(location.getLatitude(), location.getLongitude())); - adapter.setHeading(useCenter ? -mapActivity.getMapRotate() : heading); - adapter.notifyDataSetChanged(); + adapter.setUseCenter(useCenter); + adapter.setLocation(useCenter ? mapActivity.getMapLocation() : new LatLon(location.getLatitude(), location.getLongitude())); + adapter.setHeading(useCenter ? -mapActivity.getMapRotate() : heading); + adapter.notifyDataSetChanged(); + } + }); } } @@ -106,7 +125,7 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL app.getLocationProvider().removeCompassListener(app.getLocationProvider().getNavigationInfo()); app.getLocationProvider().addCompassListener(this); app.getLocationProvider().addLocationListener(this); - updateLocation(); + updateLocationUi(); } } From 1fa4d3c835316fb9dd2ed66b0bfa501620c49dae Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 30 Aug 2017 19:05:44 +0300 Subject: [PATCH 10/12] Improve some stuff --- .../plus/mapmarkers/MapMarkersActiveFragment.java | 11 +++++++---- .../plus/mapmarkers/MapMarkersDialogFragment.java | 5 ++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java index 53ac0c78e4..e8263c6cb9 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java @@ -28,6 +28,7 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL private MapMarkersActiveAdapter adapter; private Location location; private Float heading; + private boolean locationUpdateStarted; @Nullable @Override @@ -119,9 +120,10 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL } } - private void startLocationUpdate() { + void startLocationUpdate() { OsmandApplication app = getMyApplication(); - if (app != null) { + if (app != null && !locationUpdateStarted) { + locationUpdateStarted = true; app.getLocationProvider().removeCompassListener(app.getLocationProvider().getNavigationInfo()); app.getLocationProvider().addCompassListener(this); app.getLocationProvider().addLocationListener(this); @@ -129,9 +131,10 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL } } - private void stopLocationUpdate() { + void stopLocationUpdate() { OsmandApplication app = getMyApplication(); - if (app != null) { + if (app != null && locationUpdateStarted) { + locationUpdateStarted = false; app.getLocationProvider().removeLocationListener(this); app.getLocationProvider().removeCompassListener(this); app.getLocationProvider().addCompassListener(app.getLocationProvider().getNavigationInfo()); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java index 90109cbeb8..4b689e261b 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java @@ -58,7 +58,8 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm final LockableViewPager viewPager = mainView.findViewById(R.id.map_markers_view_pager); viewPager.setSwipeLocked(true); - viewPager.setAdapter(new MapMarkersViewPagerAdapter(getChildFragmentManager())); + final MapMarkersViewPagerAdapter adapter = new MapMarkersViewPagerAdapter(getChildFragmentManager()); + viewPager.setAdapter(adapter); BottomNavigationView bottomNav = mainView.findViewById(R.id.map_markers_bottom_navigation); bottomNav.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { @@ -66,9 +67,11 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.action_active: + ((MapMarkersActiveFragment) adapter.getItem(0)).startLocationUpdate(); viewPager.setCurrentItem(0); return true; case R.id.action_history: + ((MapMarkersActiveFragment) adapter.getItem(0)).stopLocationUpdate(); viewPager.setCurrentItem(1); return true; } From 6162fd4feb41f5e658eddec5ef665da18f2992c2 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Thu, 31 Aug 2017 13:49:08 +0300 Subject: [PATCH 11/12] Replace relative layout with linear layout --- OsmAnd/res/layout/map_marker_item_new.xml | 65 ++++++++++------------- 1 file changed, 29 insertions(+), 36 deletions(-) diff --git a/OsmAnd/res/layout/map_marker_item_new.xml b/OsmAnd/res/layout/map_marker_item_new.xml index 829b01b1c7..db101331d0 100644 --- a/OsmAnd/res/layout/map_marker_item_new.xml +++ b/OsmAnd/res/layout/map_marker_item_new.xml @@ -7,7 +7,7 @@ android:background="?attr/bg_color" android:descendantFocusability="blocksDescendants"> - @@ -16,9 +16,7 @@ android:id="@+id/map_marker_reorder_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_alignParentLeft="true" - android:layout_alignParentStart="true" - android:layout_centerVertical="true" + android:layout_gravity="center_vertical" android:paddingBottom="16dp" android:paddingLeft="16dp" android:paddingStart="16dp" @@ -30,36 +28,16 @@ android:id="@+id/map_marker_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_centerVertical="true" + android:layout_gravity="center_vertical" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" - android:layout_toEndOf="@id/map_marker_reorder_icon" - android:layout_toRightOf="@id/map_marker_reorder_icon" tools:src="@drawable/ic_action_flag_dark"/> - - - - + android:layout_height="wrap_content" + android:layout_gravity="center_vertical|end" + android:layout_marginBottom="16dp" + android:layout_marginLeft="14dp" + android:layout_marginRight="14dp" + android:layout_marginTop="16dp" + android:background="?attr/selectableItemBackground" + android:focusableInTouchMode="true" + tools:src="@drawable/ic_overflow_menu_white"/> - \ No newline at end of file + + + + + From d5b2704a61ab09878c47aea17126fb3d48b217aa Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Thu, 31 Aug 2017 14:04:19 +0300 Subject: [PATCH 12/12] Replace relative layout with linear layout --- OsmAnd/res/layout/fragment_map_markers_dialog.xml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/OsmAnd/res/layout/fragment_map_markers_dialog.xml b/OsmAnd/res/layout/fragment_map_markers_dialog.xml index eb0335a3ee..f07f3a3c15 100644 --- a/OsmAnd/res/layout/fragment_map_markers_dialog.xml +++ b/OsmAnd/res/layout/fragment_map_markers_dialog.xml @@ -1,15 +1,15 @@ - + android:layout_height="match_parent" + android:orientation="vertical"> + android:layout_height="0dp" + android:layout_weight="1"> - +