Remove hud buttons by id

This commit is contained in:
Vitaliy 2020-07-27 19:53:32 +03:00
parent 7d69d47897
commit 228fde0235
3 changed files with 44 additions and 35 deletions

View file

@ -57,7 +57,6 @@ import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.routing.TransportRoutingHelper; import net.osmand.plus.routing.TransportRoutingHelper;
import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.views.MapControlsLayer; import net.osmand.plus.views.MapControlsLayer;
import net.osmand.plus.views.MapControlsLayer.MapHudButton;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.router.TransportRoutePlanner.TransportRouteResult; import net.osmand.router.TransportRoutePlanner.TransportRouteResult;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -69,10 +68,15 @@ import java.io.IOException;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Locale; 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, public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMenuFragmentListener,
RouteDetailsFragmentListener { 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 INITIAL_MENU_STATE_KEY = "initial_menu_state_key";
public static final String ADJUST_MAP_KEY = "adjust_map_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 @Nullable
private LockableViewPager viewPager; private LockableViewPager viewPager;
protected List<WeakReference<RouteDetailsFragment>> routeDetailsFragments = new ArrayList<>(); protected List<WeakReference<RouteDetailsFragment>> routeDetailsFragments = new ArrayList<>();
@ -103,10 +111,6 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe
private boolean publicTransportMode; private boolean publicTransportMode;
private boolean needAdjustMap; private boolean needAdjustMap;
private MapHudButton mapZoomIn;
private MapHudButton mapZoomOut;
private MapHudButton myLocationButton;
@Nullable @Nullable
@Override @Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 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(); MapActivity mapActivity = getMapActivity();
if (mapActivity != null) { if (mapActivity != null) {
MapControlsLayer mapControlsLayer = mapActivity.getMapLayers().getMapControlsLayer(); MapControlsLayer mapControlsLayer = mapActivity.getMapLayers().getMapControlsLayer();
mapControlsLayer.removeHudButton(mapZoomIn); mapControlsLayer.removeHudButtons(Arrays.asList(ZOOM_IN_BUTTON_ID, ZOOM_OUT_BUTTON_ID, BACK_TO_LOC_BUTTON_ID));
mapControlsLayer.removeHudButton(mapZoomOut);
mapControlsLayer.removeHudButton(myLocationButton);
} }
} }
@ -372,9 +374,9 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe
View.OnLongClickListener longClickListener = MapControlsLayer.getOnClickMagnifierListener(mapTileView); View.OnLongClickListener longClickListener = MapControlsLayer.getOnClickMagnifierListener(mapTileView);
MapControlsLayer mapControlsLayer = mapActivity.getMapLayers().getMapControlsLayer(); MapControlsLayer mapControlsLayer = mapActivity.getMapLayers().getMapControlsLayer();
mapZoomIn = mapControlsLayer.createZoomInButton(zoomInButtonView, longClickListener); mapControlsLayer.setupZoomInButton(zoomInButtonView, longClickListener, ZOOM_IN_BUTTON_ID);
mapZoomOut = mapControlsLayer.createZoomOutButton(zoomOutButtonView, longClickListener); mapControlsLayer.setupZoomOutButton(zoomOutButtonView, longClickListener, ZOOM_OUT_BUTTON_ID);
myLocationButton = mapControlsLayer.createMyLocationButton(myLocButtonView); mapControlsLayer.setupMyLocationButton(myLocButtonView, BACK_TO_LOC_BUTTON_ID);
AndroidUiHelper.updateVisibility(zoomButtonsView, true); AndroidUiHelper.updateVisibility(zoomButtonsView, true);
} }

View file

@ -42,7 +42,6 @@ import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener;
import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.track.SplitTrackAsyncTask.SplitTrackListener; import net.osmand.plus.track.SplitTrackAsyncTask.SplitTrackListener;
import net.osmand.plus.views.MapControlsLayer; import net.osmand.plus.views.MapControlsLayer;
import net.osmand.plus.views.MapControlsLayer.MapHudButton;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.render.RenderingRulesStorage; import net.osmand.render.RenderingRulesStorage;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -51,8 +50,12 @@ import org.apache.commons.logging.Log;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; 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.ConfigureMapMenu.CURRENT_TRACK_COLOR_ATTR;
import static net.osmand.plus.dialogs.GpxAppearanceAdapter.TRACK_WIDTH_BOLD; import static net.osmand.plus.dialogs.GpxAppearanceAdapter.TRACK_WIDTH_BOLD;
import static net.osmand.plus.dialogs.GpxAppearanceAdapter.TRACK_WIDTH_MEDIUM; 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 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 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 OsmandApplication app;
private GpxDataItem gpxDataItem; private GpxDataItem gpxDataItem;
@ -80,10 +87,6 @@ public class TrackAppearanceFragment extends ContextMenuFragment implements Card
private ImageView appearanceIcon; private ImageView appearanceIcon;
private View zoomButtonsView; private View zoomButtonsView;
private MapHudButton mapZoomIn;
private MapHudButton mapZoomOut;
private MapHudButton myLocationButton;
@Override @Override
public int getMainLayoutId() { public int getMainLayoutId() {
return R.layout.track_appearance; return R.layout.track_appearance;
@ -244,9 +247,7 @@ public class TrackAppearanceFragment extends ContextMenuFragment implements Card
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
if (mapActivity != null) { if (mapActivity != null) {
MapControlsLayer mapControlsLayer = mapActivity.getMapLayers().getMapControlsLayer(); MapControlsLayer mapControlsLayer = mapActivity.getMapLayers().getMapControlsLayer();
mapControlsLayer.removeHudButton(mapZoomIn); mapControlsLayer.removeHudButtons(Arrays.asList(ZOOM_IN_BUTTON_ID, ZOOM_OUT_BUTTON_ID, BACK_TO_LOC_BUTTON_ID));
mapControlsLayer.removeHudButton(mapZoomOut);
mapControlsLayer.removeHudButton(myLocationButton);
} }
} }
@ -354,9 +355,9 @@ public class TrackAppearanceFragment extends ContextMenuFragment implements Card
View.OnLongClickListener longClickListener = MapControlsLayer.getOnClickMagnifierListener(mapTileView); View.OnLongClickListener longClickListener = MapControlsLayer.getOnClickMagnifierListener(mapTileView);
MapControlsLayer mapControlsLayer = mapActivity.getMapLayers().getMapControlsLayer(); MapControlsLayer mapControlsLayer = mapActivity.getMapLayers().getMapControlsLayer();
mapZoomIn = mapControlsLayer.createZoomInButton(zoomInButtonView, longClickListener); mapControlsLayer.setupZoomInButton(zoomInButtonView, longClickListener, ZOOM_IN_BUTTON_ID);
mapZoomOut = mapControlsLayer.createZoomOutButton(zoomOutButtonView, longClickListener); mapControlsLayer.setupZoomOutButton(zoomOutButtonView, longClickListener, ZOOM_OUT_BUTTON_ID);
myLocationButton = mapControlsLayer.createMyLocationButton(myLocButtonView); mapControlsLayer.setupMyLocationButton(myLocButtonView, BACK_TO_LOC_BUTTON_ID);
} }
public void updateZoomButtonsPos(@NonNull ContextMenuFragment fragment, int y, boolean animated) { public void updateZoomButtonsPos(@NonNull ContextMenuFragment fragment, int y, boolean animated) {

View file

@ -66,6 +66,7 @@ import net.osmand.plus.settings.backend.OsmandSettings.LayerTransparencySeekbarM
import net.osmand.plus.views.corenative.NativeCoreContext; import net.osmand.plus.views.corenative.NativeCoreContext;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import gnu.trove.list.array.TIntArrayList; import gnu.trove.list.array.TIntArrayList;
@ -354,7 +355,7 @@ public class MapControlsLayer extends OsmandMapLayer {
private void initControls() { private void initControls() {
View backToLocation = mapActivity.findViewById(R.id.map_my_location_button); 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); View backToMenuButton = mapActivity.findViewById(R.id.map_menu_button);
@ -392,8 +393,8 @@ public class MapControlsLayer extends OsmandMapLayer {
}); });
} }
public MapHudButton createMyLocationButton(View backToLocation) { public MapHudButton setupMyLocationButton(View backToLocation, String buttonId) {
MapHudButton backToLocationButton = createHudButton(backToLocation, R.drawable.ic_my_location, BACK_TO_LOC_HUD_ID) 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) .setIconColorId(R.color.map_button_icon_color_light, R.color.map_button_icon_color_dark)
.setBg(R.drawable.btn_circle_blue); .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 zoomInButton = mapActivity.findViewById(R.id.map_zoom_in_button);
View zoomOutButton = mapActivity.findViewById(R.id.map_zoom_out_button); View zoomOutButton = mapActivity.findViewById(R.id.map_zoom_out_button);
mapZoomIn = createZoomInButton(zoomInButton, longClickListener); mapZoomIn = setupZoomInButton(zoomInButton, longClickListener, ZOOM_IN_HUD_ID);
mapZoomOut = createZoomOutButton(zoomOutButton, longClickListener); mapZoomOut = setupZoomOutButton(zoomOutButton, longClickListener, ZOOM_OUT_HUD_ID);
} }
public MapHudButton createZoomOutButton(View zoomOutButton, View.OnLongClickListener longClickListener) { public MapHudButton setupZoomOutButton(View zoomOutButton, View.OnLongClickListener longClickListener, String buttonId) {
MapHudButton mapZoomOutButton = createHudButton(zoomOutButton, R.drawable.ic_zoom_out, ZOOM_OUT_HUD_ID); MapHudButton mapZoomOutButton = createHudButton(zoomOutButton, R.drawable.ic_zoom_out, buttonId);
mapZoomOutButton.setRoundTransparent(); mapZoomOutButton.setRoundTransparent();
zoomOutButton.setOnLongClickListener(longClickListener); zoomOutButton.setOnLongClickListener(longClickListener);
@ -624,8 +625,8 @@ public class MapControlsLayer extends OsmandMapLayer {
return mapZoomOutButton; return mapZoomOutButton;
} }
public MapHudButton createZoomInButton(View zoomInButton, View.OnLongClickListener longClickListener) { public MapHudButton setupZoomInButton(View zoomInButton, View.OnLongClickListener longClickListener, String buttonId) {
MapHudButton mapZoomInButton = createHudButton(zoomInButton, R.drawable.ic_zoom_in, ZOOM_IN_HUD_ID); MapHudButton mapZoomInButton = createHudButton(zoomInButton, R.drawable.ic_zoom_in, buttonId);
mapZoomInButton.setRoundTransparent(); mapZoomInButton.setRoundTransparent();
zoomInButton.setOnLongClickListener(longClickListener); zoomInButton.setOnLongClickListener(longClickListener);
@ -648,8 +649,13 @@ public class MapControlsLayer extends OsmandMapLayer {
return mapZoomInButton; return mapZoomInButton;
} }
public void removeHudButton(MapHudButton hudButton) { public void removeHudButtons(List<String> buttonIds) {
controls.remove(hudButton); for (Iterator<MapHudButton> iterator = controls.iterator(); iterator.hasNext(); ) {
MapHudButton mapHudButton = iterator.next();
if (buttonIds.contains(mapHudButton.id)) {
iterator.remove();
}
}
} }
public void showMapControlsIfHidden() { public void showMapControlsIfHidden() {
@ -874,7 +880,7 @@ public class MapControlsLayer extends OsmandMapLayer {
} }
for (MapHudButton mc : controls) { for (MapHudButton mc : controls) {
if (BACK_TO_LOC_HUD_ID.equals(mc.id)) { if (mc.id.startsWith(BACK_TO_LOC_HUD_ID)) {
updateMyLocation(mc); updateMyLocation(mc);
} }
mc.update(mapActivity.getMyApplication(), isNight); mc.update(mapActivity.getMyApplication(), isNight);