diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/BaseMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/BaseMenuController.java index 5ea9bf997f..536a333198 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/BaseMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/BaseMenuController.java @@ -65,7 +65,6 @@ public abstract class BaseMenuController { protected Drawable getIcon(int iconId, int colorLightId, int colorDarkId) { IconsCache iconsCache = getMapActivity().getMyApplication().getIconsCache(); - return iconsCache.getIcon(iconId, - isLight() ? colorLightId : colorDarkId); + return iconsCache.getIcon(iconId, isLight() ? colorLightId : colorDarkId); } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index 1e2801438f..46193bac7e 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -125,7 +125,7 @@ public class MapContextMenu extends MenuTitleController { initTitle(); if (menuController != null) { - menuController.addPlainMenuItems(typeStr, this.pointDescription); + menuController.addPlainMenuItems(typeStr, this.pointDescription, this.latLon); } if (mapPosition != 0) { @@ -190,7 +190,7 @@ public class MapContextMenu extends MenuTitleController { } private void acquireMenuController() { - menuController = MenuController.getMenuController(mapActivity, latLon, pointDescription, object); + menuController = MenuController.getMenuController(mapActivity, pointDescription, object); } public void onSingleTapOnMap() { @@ -313,7 +313,7 @@ public class MapContextMenu extends MenuTitleController { acquireIcons(); if (menuController != null) { - menuController.addPlainMenuItems(typeStr, this.pointDescription); + menuController.addPlainMenuItems(typeStr, pointDescription, latLon); } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index 9a4013848a..aa1cc77a0d 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -23,7 +23,7 @@ import java.util.LinkedList; import static android.util.TypedValue.COMPLEX_UNIT_DIP; -public abstract class MenuBuilder { +public class MenuBuilder { public static final float SHADOW_HEIGHT_TOP_DP = 16f; public static final float SHADOW_HEIGHT_BOTTOM_DP = 6f; @@ -59,6 +59,19 @@ public abstract class MenuBuilder { public void build(View view) { firstRow = true; + if (needBuildPlainMenuItems()) { + buildPlainMenuItems(view); + } + } + + protected void buildPlainMenuItems(View view) { + for (PlainMenuItem item : plainMenuItems) { + buildRow(view, item.getIconId(), item.getText(), 0); + } + } + + protected boolean needBuildPlainMenuItems() { + return true; } protected boolean isFirstRow() { @@ -69,6 +82,10 @@ public abstract class MenuBuilder { firstRow = false; } + private void buildRow(View view, int iconId, String text, int textColor) { + buildRow(view, getRowIcon(iconId), text, textColor); + } + protected void buildRow(final View view, Drawable icon, String text, int textColor) { LinearLayout ll = new LinearLayout(view.getContext()); ll.setOrientation(LinearLayout.HORIZONTAL); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java index 58cc1b433d..c8de77e6c7 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java @@ -8,7 +8,6 @@ import net.osmand.data.Amenity; import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; -import net.osmand.plus.IconsCache; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; @@ -41,7 +40,7 @@ public abstract class MenuController extends BaseMenuController { } public static MenuController getMenuController(MapActivity mapActivity, - LatLon latLon, PointDescription pointDescription, Object object) { + PointDescription pointDescription, Object object) { OsmandApplication app = mapActivity.getMyApplication(); MenuController menuController = null; if (object != null) { @@ -57,7 +56,7 @@ public abstract class MenuController extends BaseMenuController { } } } else { - menuController = new PointDescriptionMenuController(app, mapActivity, pointDescription, latLon); + menuController = new PointDescriptionMenuController(app, mapActivity, pointDescription); } return menuController; } @@ -66,7 +65,15 @@ public abstract class MenuController extends BaseMenuController { builder.addPlainMenuItem(iconId, text); } - public void addPlainMenuItems(String typeStr, PointDescription pointDescription) { + public void addPlainMenuItems(String typeStr, PointDescription pointDescription, LatLon latLon) { + addMyLocationToPlainItems(pointDescription, latLon); + } + + protected void addMyLocationToPlainItems(PointDescription pointDescription, LatLon latLon) { + if (pointDescription != null) { + addPlainMenuItem(R.drawable.map_my_location, PointDescription.getLocationName(getMapActivity(), + latLon.getLatitude(), latLon.getLongitude(), true).replaceAll("\n", "")); + } } public int getInitialMenuState() { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/AmenityMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/AmenityMenuBuilder.java index 8b98946497..65bfdf7532 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/AmenityMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/AmenityMenuBuilder.java @@ -119,14 +119,9 @@ public class AmenityMenuBuilder extends MenuBuilder { super.build(view); boolean hasWiki = false; - - for (PlainMenuItem item : plainMenuItems) { - buildRow(view, item.getIconId(), item.getText(), 0, false); - } - MapPoiTypes poiTypes = app.getPoiTypes(); for (Map.Entry e : amenity.getAdditionalInfo().entrySet()) { - int iconId = 0; + int iconId; Drawable icon = null; int textColor = 0; boolean isWiki = false; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/AmenityMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/AmenityMenuController.java index bed82d1dab..451491444d 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/AmenityMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/AmenityMenuController.java @@ -3,6 +3,7 @@ package net.osmand.plus.mapcontextmenu.details; import android.os.Bundle; import net.osmand.data.Amenity; +import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.osm.PoiCategory; import net.osmand.osm.PoiType; @@ -74,14 +75,11 @@ public class AmenityMenuController extends MenuController { } @Override - public void addPlainMenuItems(String typeStr, PointDescription pointDescription) { + public void addPlainMenuItems(String typeStr, PointDescription pointDescription, LatLon latLon) { if (!Algorithms.isEmpty(typeStr)) { addPlainMenuItem(R.drawable.ic_action_info_dark, typeStr); } - if (pointDescription != null) { - addPlainMenuItem(R.drawable.map_my_location, PointDescription.getLocationName(getMapActivity(), - amenity.getLocation().getLatitude(), amenity.getLocation().getLongitude(), true).replaceAll("\n", "")); - } + addMyLocationToPlainItems(pointDescription, amenity.getLocation()); } @Override diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/FavouritePointMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/FavouritePointMenuBuilder.java index 5b2ac02cb3..5c0c6cfdd5 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/FavouritePointMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/FavouritePointMenuBuilder.java @@ -21,6 +21,11 @@ public class FavouritePointMenuBuilder extends MenuBuilder { buildRow(view, getRowIcon(iconId), text, textColor); } + @Override + protected boolean needBuildPlainMenuItems() { + return false; + } + @Override public void build(View view) { super.build(view); @@ -29,8 +34,6 @@ public class FavouritePointMenuBuilder extends MenuBuilder { buildRow(view, R.drawable.ic_action_note_dark, fav.getDescription(), 0); } - for (PlainMenuItem item : plainMenuItems) { - buildRow(view, item.getIconId(), item.getText(), 0); - } + buildPlainMenuItems(view); } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/FavouritePointMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/FavouritePointMenuController.java index e4d6f284be..b7f7862865 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/FavouritePointMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/FavouritePointMenuController.java @@ -5,7 +5,6 @@ import android.os.Bundle; import android.support.v4.app.Fragment; import net.osmand.data.FavouritePoint; -import net.osmand.data.PointDescription; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; @@ -79,14 +78,6 @@ public class FavouritePointMenuController extends MenuController { return fav.getName(); } - @Override - public void addPlainMenuItems(String typeStr, PointDescription pointDescription) { - if (pointDescription != null) { - addPlainMenuItem(R.drawable.map_my_location, PointDescription.getLocationName(getMapActivity(), - fav.getLatitude(), fav.getLongitude(), true).replaceAll("\n", "")); - } - } - @Override public void saveEntityState(Bundle bundle, String key) { bundle.putSerializable(key, fav); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/HistoryMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/HistoryMenuBuilder.java deleted file mode 100644 index 1d96351211..0000000000 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/HistoryMenuBuilder.java +++ /dev/null @@ -1,29 +0,0 @@ -package net.osmand.plus.mapcontextmenu.details; - -import android.view.View; - -import net.osmand.plus.OsmandApplication; -import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry; -import net.osmand.plus.mapcontextmenu.MenuBuilder; - -public class HistoryMenuBuilder extends MenuBuilder { - private final HistoryEntry entry; - - public HistoryMenuBuilder(OsmandApplication app, final HistoryEntry entry) { - super(app); - this.entry = entry; - } - - private void buildRow(View view, int iconId, String text, int textColor) { - buildRow(view, getRowIcon(iconId), text, textColor); - } - - @Override - public void build(View view) { - super.build(view); - - for (PlainMenuItem item : plainMenuItems) { - buildRow(view, item.getIconId(), item.getText(), 0); - } - } -} diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/HistoryMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/HistoryMenuController.java index 24b1edf6f6..1376c5d110 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/HistoryMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/HistoryMenuController.java @@ -3,12 +3,12 @@ package net.osmand.plus.mapcontextmenu.details; import android.graphics.drawable.Drawable; import android.os.Bundle; -import net.osmand.data.PointDescription; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.search.SearchHistoryFragment; import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry; +import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.mapcontextmenu.MenuController; public class HistoryMenuController extends MenuController { @@ -16,7 +16,7 @@ public class HistoryMenuController extends MenuController { private HistoryEntry entry; public HistoryMenuController(OsmandApplication app, MapActivity mapActivity, final HistoryEntry entry) { - super(new HistoryMenuBuilder(app, entry), mapActivity); + super(new MenuBuilder(app), mapActivity); this.entry = entry; } @@ -69,14 +69,6 @@ public class HistoryMenuController extends MenuController { return !entry.getName().isAddress(); } - @Override - public void addPlainMenuItems(String typeStr, PointDescription pointDescription) { - if (pointDescription != null) { - addPlainMenuItem(R.drawable.map_my_location, PointDescription.getLocationName(getMapActivity(), - entry.getLat(), entry.getLon(), true).replaceAll("\n", "")); - } - } - @Override public void saveEntityState(Bundle bundle, String key) { bundle.putSerializable(key, entry); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/MyLocationMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/MyLocationMenuController.java new file mode 100644 index 0000000000..89cab3ae0a --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/MyLocationMenuController.java @@ -0,0 +1,47 @@ +package net.osmand.plus.mapcontextmenu.details; + +import android.graphics.drawable.Drawable; +import android.os.Bundle; + +import net.osmand.data.LatLon; +import net.osmand.data.PointDescription; +import net.osmand.plus.ApplicationMode; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandSettings; +import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.activities.search.SearchHistoryFragment; +import net.osmand.plus.mapcontextmenu.MenuBuilder; +import net.osmand.plus.mapcontextmenu.MenuController; + +public class MyLocationMenuController extends MenuController { + + public MyLocationMenuController(OsmandApplication app, MapActivity mapActivity) { + super(new MenuBuilder(app), mapActivity); + } + + @Override + protected int getInitialMenuStatePortrait() { + return MenuState.HEADER_ONLY; + } + + @Override + protected int getSupportedMenuStatesPortrait() { + return MenuState.HEADER_ONLY | MenuState.HALF_SCREEN; + } + + @Override + public Drawable getLeftIcon() { + ApplicationMode appMode = getMapActivity().getMyApplication().getSettings().getApplicationMode(); + return getMapActivity().getResources().getDrawable(appMode.getResourceLocation()); + } + + @Override + public String getNameStr() { + return getMapActivity().getString(R.string.shared_string_my_location); + } + + @Override + public void saveEntityState(Bundle bundle, String key) { + } +} diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/ParkingPositionBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/ParkingPositionBuilder.java deleted file mode 100644 index 76bcf121c6..0000000000 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/ParkingPositionBuilder.java +++ /dev/null @@ -1,26 +0,0 @@ -package net.osmand.plus.mapcontextmenu.details; - -import android.view.View; - -import net.osmand.plus.OsmandApplication; -import net.osmand.plus.mapcontextmenu.MenuBuilder; - -public class ParkingPositionBuilder extends MenuBuilder { - - public ParkingPositionBuilder(OsmandApplication app) { - super(app); - } - - private void buildRow(View view, int iconId, String text, int textColor) { - buildRow(view, getRowIcon(iconId), text, textColor); - } - - @Override - public void build(View view) { - super.build(view); - - for (PlainMenuItem item : plainMenuItems) { - buildRow(view, item.getIconId(), item.getText(), 0); - } - } -} diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/ParkingPositionController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/ParkingPositionController.java index 92f79b33df..8ef8e891e5 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/ParkingPositionController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/ParkingPositionController.java @@ -9,6 +9,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.mapcontextmenu.MenuController; import net.osmand.plus.parkingpoint.ParkingPositionPlugin; import net.osmand.util.Algorithms; @@ -21,7 +22,7 @@ public class ParkingPositionController extends MenuController { String parkingDescription = ""; public ParkingPositionController(OsmandApplication app, MapActivity mapActivity, final PointDescription pointDescription, LatLon latLon) { - super(new ParkingPositionBuilder(app), mapActivity); + super(new MenuBuilder(app), mapActivity); this.pointDescription = pointDescription; this.latLon = latLon; plugin = OsmandPlugin.getPlugin(ParkingPositionPlugin.class); @@ -88,14 +89,6 @@ public class ParkingPositionController extends MenuController { return false; } - @Override - public void addPlainMenuItems(String typeStr, PointDescription pointDescription) { - if (pointDescription != null) { - addPlainMenuItem(R.drawable.map_my_location, PointDescription.getLocationName(getMapActivity(), - latLon.getLatitude(), latLon.getLongitude(), true).replaceAll("\n", "")); - } - } - @Override public void saveEntityState(Bundle bundle, String key) { bundle.putSerializable(key, latLon); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/PointDescriptionMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/PointDescriptionMenuBuilder.java deleted file mode 100644 index e20af03aa6..0000000000 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/PointDescriptionMenuBuilder.java +++ /dev/null @@ -1,29 +0,0 @@ -package net.osmand.plus.mapcontextmenu.details; - -import android.view.View; - -import net.osmand.data.PointDescription; -import net.osmand.plus.OsmandApplication; -import net.osmand.plus.mapcontextmenu.MenuBuilder; - -public class PointDescriptionMenuBuilder extends MenuBuilder { - private final PointDescription pointDescription; - - public PointDescriptionMenuBuilder(OsmandApplication app, final PointDescription pointDescription) { - super(app); - this.pointDescription = pointDescription; - } - - private void buildRow(View view, int iconId, String text, int textColor) { - buildRow(view, getRowIcon(iconId), text, textColor); - } - - @Override - public void build(View view) { - super.build(view); - - for (MenuBuilder.PlainMenuItem item : plainMenuItems) { - buildRow(view, item.getIconId(), item.getText(), 0); - } - } -} diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/PointDescriptionMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/PointDescriptionMenuController.java index d9993b6561..370625ebcb 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/PointDescriptionMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/PointDescriptionMenuController.java @@ -3,23 +3,21 @@ package net.osmand.plus.mapcontextmenu.details; import android.graphics.drawable.Drawable; import android.os.Bundle; -import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.search.SearchHistoryFragment; +import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.mapcontextmenu.MenuController; public class PointDescriptionMenuController extends MenuController { private PointDescription pointDescription; - private LatLon latLon; - public PointDescriptionMenuController(OsmandApplication app, MapActivity mapActivity, final PointDescription pointDescription, LatLon latLon) { - super(new PointDescriptionMenuBuilder(app, pointDescription), mapActivity); + public PointDescriptionMenuController(OsmandApplication app, MapActivity mapActivity, final PointDescription pointDescription) { + super(new MenuBuilder(app), mapActivity); this.pointDescription = pointDescription; - this.latLon = latLon; } @Override @@ -71,14 +69,6 @@ public class PointDescriptionMenuController extends MenuController { return !pointDescription.isAddress(); } - @Override - public void addPlainMenuItems(String typeStr, PointDescription pointDescription) { - if (pointDescription != null) { - addPlainMenuItem(R.drawable.map_my_location, PointDescription.getLocationName(getMapActivity(), - latLon.getLatitude(), latLon.getLongitude(), true).replaceAll("\n", "")); - } - } - @Override public void saveEntityState(Bundle bundle, String key) { } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ObjectSelectionMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ObjectSelectionMenu.java index 016bb76c71..5866f7f1b1 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ObjectSelectionMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ObjectSelectionMenu.java @@ -47,7 +47,7 @@ public class ObjectSelectionMenu extends BaseMenuController { } protected void init() { - controller = MenuController.getMenuController(mapActivity, latLon, pointDescription, object); + controller = MenuController.getMenuController(mapActivity, pointDescription, object); initTitle(); }