diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java index 7a934ffa79..057340ef95 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java @@ -57,7 +57,6 @@ import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.TransportRoutingHelper; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.views.MapControlsLayer; -import net.osmand.plus.views.MapControlsLayer.MapHudButton; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.router.TransportRoutePlanner.TransportRouteResult; import net.osmand.util.Algorithms; @@ -69,10 +68,15 @@ import java.io.IOException; import java.lang.ref.WeakReference; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.Locale; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.BACK_TO_LOC_HUD_ID; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.ZOOM_IN_HUD_ID; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.ZOOM_OUT_HUD_ID; + public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMenuFragmentListener, RouteDetailsFragmentListener { @@ -82,6 +86,10 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe public static final String INITIAL_MENU_STATE_KEY = "initial_menu_state_key"; public static final String ADJUST_MAP_KEY = "adjust_map_key"; + private static final String ZOOM_IN_BUTTON_ID = ZOOM_IN_HUD_ID + TAG; + private static final String ZOOM_OUT_BUTTON_ID = ZOOM_OUT_HUD_ID + TAG; + private static final String BACK_TO_LOC_BUTTON_ID = BACK_TO_LOC_HUD_ID + TAG; + @Nullable private LockableViewPager viewPager; protected List> routeDetailsFragments = new ArrayList<>(); @@ -103,10 +111,6 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe private boolean publicTransportMode; private boolean needAdjustMap; - private MapHudButton mapZoomIn; - private MapHudButton mapZoomOut; - private MapHudButton myLocationButton; - @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { @@ -246,9 +250,7 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { MapControlsLayer mapControlsLayer = mapActivity.getMapLayers().getMapControlsLayer(); - mapControlsLayer.removeHudButton(mapZoomIn); - mapControlsLayer.removeHudButton(mapZoomOut); - mapControlsLayer.removeHudButton(myLocationButton); + mapControlsLayer.removeHudButtons(Arrays.asList(ZOOM_IN_BUTTON_ID, ZOOM_OUT_BUTTON_ID, BACK_TO_LOC_BUTTON_ID)); } } @@ -372,9 +374,9 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe View.OnLongClickListener longClickListener = MapControlsLayer.getOnClickMagnifierListener(mapTileView); MapControlsLayer mapControlsLayer = mapActivity.getMapLayers().getMapControlsLayer(); - mapZoomIn = mapControlsLayer.createZoomInButton(zoomInButtonView, longClickListener); - mapZoomOut = mapControlsLayer.createZoomOutButton(zoomOutButtonView, longClickListener); - myLocationButton = mapControlsLayer.createMyLocationButton(myLocButtonView); + mapControlsLayer.setupZoomInButton(zoomInButtonView, longClickListener, ZOOM_IN_BUTTON_ID); + mapControlsLayer.setupZoomOutButton(zoomOutButtonView, longClickListener, ZOOM_OUT_BUTTON_ID); + mapControlsLayer.setupMyLocationButton(myLocButtonView, BACK_TO_LOC_BUTTON_ID); AndroidUiHelper.updateVisibility(zoomButtonsView, true); } diff --git a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java index 77a8c06371..164b95e700 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java @@ -42,7 +42,6 @@ import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.track.SplitTrackAsyncTask.SplitTrackListener; import net.osmand.plus.views.MapControlsLayer; -import net.osmand.plus.views.MapControlsLayer.MapHudButton; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.render.RenderingRulesStorage; import net.osmand.util.Algorithms; @@ -51,8 +50,12 @@ import org.apache.commons.logging.Log; import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.BACK_TO_LOC_HUD_ID; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.ZOOM_IN_HUD_ID; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.ZOOM_OUT_HUD_ID; import static net.osmand.plus.dialogs.ConfigureMapMenu.CURRENT_TRACK_COLOR_ATTR; import static net.osmand.plus.dialogs.GpxAppearanceAdapter.TRACK_WIDTH_BOLD; import static net.osmand.plus.dialogs.GpxAppearanceAdapter.TRACK_WIDTH_MEDIUM; @@ -60,10 +63,14 @@ import static net.osmand.plus.track.TrackDrawInfo.TRACK_FILE_PATH; public class TrackAppearanceFragment extends ContextMenuFragment implements CardListener, ContextMenuFragmentListener { - public static final String TAG = TrackAppearanceFragment.class.getName(); + public static final String TAG = TrackAppearanceFragment.class.getSimpleName(); private static final Log log = PlatformUtil.getLog(TrackAppearanceFragment.class); + private static final String ZOOM_IN_BUTTON_ID = ZOOM_IN_HUD_ID + TAG; + private static final String ZOOM_OUT_BUTTON_ID = ZOOM_OUT_HUD_ID + TAG; + private static final String BACK_TO_LOC_BUTTON_ID = BACK_TO_LOC_HUD_ID + TAG; + private OsmandApplication app; private GpxDataItem gpxDataItem; @@ -80,10 +87,6 @@ public class TrackAppearanceFragment extends ContextMenuFragment implements Card private ImageView appearanceIcon; private View zoomButtonsView; - private MapHudButton mapZoomIn; - private MapHudButton mapZoomOut; - private MapHudButton myLocationButton; - @Override public int getMainLayoutId() { return R.layout.track_appearance; @@ -244,9 +247,7 @@ public class TrackAppearanceFragment extends ContextMenuFragment implements Card MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { MapControlsLayer mapControlsLayer = mapActivity.getMapLayers().getMapControlsLayer(); - mapControlsLayer.removeHudButton(mapZoomIn); - mapControlsLayer.removeHudButton(mapZoomOut); - mapControlsLayer.removeHudButton(myLocationButton); + mapControlsLayer.removeHudButtons(Arrays.asList(ZOOM_IN_BUTTON_ID, ZOOM_OUT_BUTTON_ID, BACK_TO_LOC_BUTTON_ID)); } } @@ -354,9 +355,9 @@ public class TrackAppearanceFragment extends ContextMenuFragment implements Card View.OnLongClickListener longClickListener = MapControlsLayer.getOnClickMagnifierListener(mapTileView); MapControlsLayer mapControlsLayer = mapActivity.getMapLayers().getMapControlsLayer(); - mapZoomIn = mapControlsLayer.createZoomInButton(zoomInButtonView, longClickListener); - mapZoomOut = mapControlsLayer.createZoomOutButton(zoomOutButtonView, longClickListener); - myLocationButton = mapControlsLayer.createMyLocationButton(myLocButtonView); + mapControlsLayer.setupZoomInButton(zoomInButtonView, longClickListener, ZOOM_IN_BUTTON_ID); + mapControlsLayer.setupZoomOutButton(zoomOutButtonView, longClickListener, ZOOM_OUT_BUTTON_ID); + mapControlsLayer.setupMyLocationButton(myLocButtonView, BACK_TO_LOC_BUTTON_ID); } public void updateZoomButtonsPos(@NonNull ContextMenuFragment fragment, int y, boolean animated) { diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index ca8f240708..a9e45bf324 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -66,6 +66,7 @@ import net.osmand.plus.settings.backend.OsmandSettings.LayerTransparencySeekbarM import net.osmand.plus.views.corenative.NativeCoreContext; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import gnu.trove.list.array.TIntArrayList; @@ -354,7 +355,7 @@ public class MapControlsLayer extends OsmandMapLayer { private void initControls() { View backToLocation = mapActivity.findViewById(R.id.map_my_location_button); - backToLocationControl = createMyLocationButton(backToLocation); + backToLocationControl = setupMyLocationButton(backToLocation, BACK_TO_LOC_HUD_ID); View backToMenuButton = mapActivity.findViewById(R.id.map_menu_button); @@ -392,8 +393,8 @@ public class MapControlsLayer extends OsmandMapLayer { }); } - public MapHudButton createMyLocationButton(View backToLocation) { - MapHudButton backToLocationButton = createHudButton(backToLocation, R.drawable.ic_my_location, BACK_TO_LOC_HUD_ID) + public MapHudButton setupMyLocationButton(View backToLocation, String buttonId) { + MapHudButton backToLocationButton = createHudButton(backToLocation, R.drawable.ic_my_location, buttonId) .setIconColorId(R.color.map_button_icon_color_light, R.color.map_button_icon_color_dark) .setBg(R.drawable.btn_circle_blue); @@ -600,12 +601,12 @@ public class MapControlsLayer extends OsmandMapLayer { View zoomInButton = mapActivity.findViewById(R.id.map_zoom_in_button); View zoomOutButton = mapActivity.findViewById(R.id.map_zoom_out_button); - mapZoomIn = createZoomInButton(zoomInButton, longClickListener); - mapZoomOut = createZoomOutButton(zoomOutButton, longClickListener); + mapZoomIn = setupZoomInButton(zoomInButton, longClickListener, ZOOM_IN_HUD_ID); + mapZoomOut = setupZoomOutButton(zoomOutButton, longClickListener, ZOOM_OUT_HUD_ID); } - public MapHudButton createZoomOutButton(View zoomOutButton, View.OnLongClickListener longClickListener) { - MapHudButton mapZoomOutButton = createHudButton(zoomOutButton, R.drawable.ic_zoom_out, ZOOM_OUT_HUD_ID); + public MapHudButton setupZoomOutButton(View zoomOutButton, View.OnLongClickListener longClickListener, String buttonId) { + MapHudButton mapZoomOutButton = createHudButton(zoomOutButton, R.drawable.ic_zoom_out, buttonId); mapZoomOutButton.setRoundTransparent(); zoomOutButton.setOnLongClickListener(longClickListener); @@ -624,8 +625,8 @@ public class MapControlsLayer extends OsmandMapLayer { return mapZoomOutButton; } - public MapHudButton createZoomInButton(View zoomInButton, View.OnLongClickListener longClickListener) { - MapHudButton mapZoomInButton = createHudButton(zoomInButton, R.drawable.ic_zoom_in, ZOOM_IN_HUD_ID); + public MapHudButton setupZoomInButton(View zoomInButton, View.OnLongClickListener longClickListener, String buttonId) { + MapHudButton mapZoomInButton = createHudButton(zoomInButton, R.drawable.ic_zoom_in, buttonId); mapZoomInButton.setRoundTransparent(); zoomInButton.setOnLongClickListener(longClickListener); @@ -648,8 +649,13 @@ public class MapControlsLayer extends OsmandMapLayer { return mapZoomInButton; } - public void removeHudButton(MapHudButton hudButton) { - controls.remove(hudButton); + public void removeHudButtons(List buttonIds) { + for (Iterator iterator = controls.iterator(); iterator.hasNext(); ) { + MapHudButton mapHudButton = iterator.next(); + if (buttonIds.contains(mapHudButton.id)) { + iterator.remove(); + } + } } public void showMapControlsIfHidden() { @@ -874,7 +880,7 @@ public class MapControlsLayer extends OsmandMapLayer { } for (MapHudButton mc : controls) { - if (BACK_TO_LOC_HUD_ID.equals(mc.id)) { + if (mc.id.startsWith(BACK_TO_LOC_HUD_ID)) { updateMyLocation(mc); } mc.update(mapActivity.getMyApplication(), isNight);