Add packages for map widgets

This commit is contained in:
Vitaliy 2020-07-27 20:35:42 +03:00
parent 790f4dbab3
commit 2966d87dd5
25 changed files with 481 additions and 453 deletions

View file

@ -21,7 +21,7 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.AidlMapLayer; import net.osmand.plus.views.AidlMapLayer;
import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.OsmandMapLayer; import net.osmand.plus.views.OsmandMapLayer;
import net.osmand.plus.views.mapwidgets.TextInfoWidget; import net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import java.util.Map; import java.util.Map;

View file

@ -80,7 +80,7 @@ import net.osmand.plus.views.AidlMapLayer;
import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.OsmandMapLayer; import net.osmand.plus.views.OsmandMapLayer;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.mapwidgets.TextInfoWidget; import net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget;
import net.osmand.router.TurnType; import net.osmand.router.TurnType;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;

View file

@ -70,8 +70,8 @@ import net.osmand.plus.settings.fragments.BaseSettingsFragment;
import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings; import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.mapwidgets.MapWidgetRegistry; import net.osmand.plus.views.mapwidgets.widgetstates.WidgetState;
import net.osmand.plus.views.mapwidgets.TextInfoWidget; import net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import net.osmand.util.GeoPointParserUtil.GeoParsedPoint; import net.osmand.util.GeoPointParserUtil.GeoParsedPoint;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
@ -2128,7 +2128,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
return DashAudioVideoNotesFragment.FRAGMENT_DATA; return DashAudioVideoNotesFragment.FRAGMENT_DATA;
} }
public class AudioVideoNotesWidgetState extends MapWidgetRegistry.WidgetState { public class AudioVideoNotesWidgetState extends WidgetState {
private static final int AV_WIDGET_STATE_ASK = R.id.av_notes_widget_state_ask; private static final int AV_WIDGET_STATE_ASK = R.id.av_notes_widget_state_ask;
private static final int AV_WIDGET_STATE_AUDIO = R.id.av_notes_widget_state_audio; private static final int AV_WIDGET_STATE_AUDIO = R.id.av_notes_widget_state_audio;

View file

@ -18,7 +18,7 @@ import net.osmand.plus.settings.fragments.BaseSettingsFragment;
import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings; import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.mapwidgets.TextInfoWidget; import net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_BUILDS_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_BUILDS_ID;

View file

@ -35,7 +35,7 @@ import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.MapTileLayer; import net.osmand.plus.views.MapTileLayer;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.mapwidgets.MapWidgetRegistry.MapWidgetRegInfo; import net.osmand.plus.views.mapwidgets.MapWidgetRegistry.MapWidgetRegInfo;
import net.osmand.plus.views.mapwidgets.TextInfoWidget; import net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import java.text.MessageFormat; import java.text.MessageFormat;

View file

@ -46,7 +46,7 @@ import net.osmand.plus.settings.fragments.BaseSettingsFragment;
import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings; import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.mapwidgets.TextInfoWidget; import net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;

View file

@ -28,7 +28,7 @@ import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo;
import net.osmand.plus.routing.RouteDirectionInfo; import net.osmand.plus.routing.RouteDirectionInfo;
import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.TurnPathHelper; import net.osmand.plus.views.TurnPathHelper;
import net.osmand.plus.views.mapwidgets.NextTurnInfoWidget.TurnDrawable; import net.osmand.plus.views.mapwidgets.TurnDrawable;
import net.osmand.router.TurnType; import net.osmand.router.TurnType;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;

View file

@ -40,7 +40,7 @@ import net.osmand.plus.views.AnimateDraggingMapThread;
import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings; import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.mapwidgets.TextInfoWidget; import net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;

View file

@ -19,7 +19,7 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.mapcontextmenu.other.TrackChartPoints; import net.osmand.plus.mapcontextmenu.other.TrackChartPoints;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.CompassRulerControlWidgetState; import net.osmand.plus.views.mapwidgets.widgetstates.CompassRulerWidgetState;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopCoordinatesView; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopCoordinatesView;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopTextView; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopTextView;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController;
@ -28,15 +28,15 @@ import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarView;
import net.osmand.plus.views.mapwidgets.MapMarkersWidgetsFactory; import net.osmand.plus.views.mapwidgets.MapMarkersWidgetsFactory;
import net.osmand.plus.views.mapwidgets.MapWidgetRegistry; import net.osmand.plus.views.mapwidgets.MapWidgetRegistry;
import net.osmand.plus.views.mapwidgets.MapWidgetRegistry.MapWidgetRegInfo; import net.osmand.plus.views.mapwidgets.MapWidgetRegistry.MapWidgetRegInfo;
import net.osmand.plus.views.mapwidgets.MapWidgetRegistry.WidgetState; import net.osmand.plus.views.mapwidgets.widgetstates.WidgetState;
import net.osmand.plus.views.mapwidgets.NextTurnInfoWidget; import net.osmand.plus.views.mapwidgets.widgets.NextTurnWidget;
import net.osmand.plus.views.mapwidgets.RouteInfoWidgetsFactory; import net.osmand.plus.views.mapwidgets.RouteInfoWidgetsFactory;
import net.osmand.plus.views.mapwidgets.AlarmWidget; import net.osmand.plus.views.mapwidgets.widgets.AlarmWidget;
import net.osmand.plus.views.mapwidgets.BearingWidgetState; import net.osmand.plus.views.mapwidgets.widgetstates.BearingWidgetState;
import net.osmand.plus.views.mapwidgets.LanesControl; import net.osmand.plus.views.mapwidgets.LanesControl;
import net.osmand.plus.views.mapwidgets.RulerWidget; import net.osmand.plus.views.mapwidgets.widgets.RulerWidget;
import net.osmand.plus.views.mapwidgets.TimeControlWidgetState; import net.osmand.plus.views.mapwidgets.widgetstates.TimeWidgetState;
import net.osmand.plus.views.mapwidgets.TextInfoWidget; import net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget;
import static net.osmand.plus.views.mapwidgets.MapWidgetRegistry.WIDGET_ALTITUDE; import static net.osmand.plus.views.mapwidgets.MapWidgetRegistry.WIDGET_ALTITUDE;
import static net.osmand.plus.views.mapwidgets.MapWidgetRegistry.WIDGET_BATTERY; import static net.osmand.plus.views.mapwidgets.MapWidgetRegistry.WIDGET_BATTERY;
@ -184,11 +184,11 @@ public class MapInfoLayer extends OsmandMapLayer {
// register left stack // register left stack
registerSideWidget(null, R.drawable.ic_action_compass, R.string.map_widget_compass, WIDGET_COMPASS, true, 4); registerSideWidget(null, R.drawable.ic_action_compass, R.string.map_widget_compass, WIDGET_COMPASS, true, 4);
NextTurnInfoWidget bigInfoControl = ric.createNextInfoControl(map, app, false); NextTurnWidget bigInfoControl = ric.createNextInfoControl(map, app, false);
registerSideWidget(bigInfoControl, R.drawable.ic_action_next_turn, R.string.map_widget_next_turn, WIDGET_NEXT_TURN, true, 5); registerSideWidget(bigInfoControl, R.drawable.ic_action_next_turn, R.string.map_widget_next_turn, WIDGET_NEXT_TURN, true, 5);
NextTurnInfoWidget smallInfoControl = ric.createNextInfoControl(map, app, true); NextTurnWidget smallInfoControl = ric.createNextInfoControl(map, app, true);
registerSideWidget(smallInfoControl, R.drawable.ic_action_next_turn, R.string.map_widget_next_turn_small, WIDGET_NEXT_TURN_SMALL, true, 6); registerSideWidget(smallInfoControl, R.drawable.ic_action_next_turn, R.string.map_widget_next_turn_small, WIDGET_NEXT_TURN_SMALL, true, 6);
NextTurnInfoWidget nextNextInfoControl = ric.createNextNextInfoControl(map, app, true); NextTurnWidget nextNextInfoControl = ric.createNextNextInfoControl(map, app, true);
registerSideWidget(nextNextInfoControl, R.drawable.ic_action_next_turn, R.string.map_widget_next_next_turn, WIDGET_NEXT_NEXT_TURN,true, 7); registerSideWidget(nextNextInfoControl, R.drawable.ic_action_next_turn, R.string.map_widget_next_next_turn, WIDGET_NEXT_NEXT_TURN,true, 7);
// register right stack // register right stack
@ -196,11 +196,11 @@ public class MapInfoLayer extends OsmandMapLayer {
TextInfoWidget intermediateDist = ric.createIntermediateDistanceControl(map); TextInfoWidget intermediateDist = ric.createIntermediateDistanceControl(map);
registerSideWidget(intermediateDist, R.drawable.ic_action_intermediate, R.string.map_widget_intermediate_distance, WIDGET_INTERMEDIATE_DISTANCE, false, 13); registerSideWidget(intermediateDist, R.drawable.ic_action_intermediate, R.string.map_widget_intermediate_distance, WIDGET_INTERMEDIATE_DISTANCE, false, 13);
TextInfoWidget intermediateTime = ric.createTimeControl(map, true); TextInfoWidget intermediateTime = ric.createTimeControl(map, true);
registerSideWidget(intermediateTime, new TimeControlWidgetState(app, true), WIDGET_INTERMEDIATE_TIME, false, 14); registerSideWidget(intermediateTime, new TimeWidgetState(app, true), WIDGET_INTERMEDIATE_TIME, false, 14);
TextInfoWidget dist = ric.createDistanceControl(map); TextInfoWidget dist = ric.createDistanceControl(map);
registerSideWidget(dist, R.drawable.ic_action_target, R.string.map_widget_distance, WIDGET_DISTANCE, false, 15); registerSideWidget(dist, R.drawable.ic_action_target, R.string.map_widget_distance, WIDGET_DISTANCE, false, 15);
TextInfoWidget time = ric.createTimeControl(map, false); TextInfoWidget time = ric.createTimeControl(map, false);
registerSideWidget(time, new TimeControlWidgetState(app, false), WIDGET_TIME, false, 16); registerSideWidget(time, new TimeWidgetState(app, false), WIDGET_TIME, false, 16);
TextInfoWidget marker = mwf.createMapMarkerControl(map, true); TextInfoWidget marker = mwf.createMapMarkerControl(map, true);
@ -224,7 +224,7 @@ public class MapInfoLayer extends OsmandMapLayer {
TextInfoWidget battery = ric.createBatteryControl(map); TextInfoWidget battery = ric.createBatteryControl(map);
registerSideWidget(battery, R.drawable.ic_action_battery, R.string.map_widget_battery, WIDGET_BATTERY, false, 42); registerSideWidget(battery, R.drawable.ic_action_battery, R.string.map_widget_battery, WIDGET_BATTERY, false, 42);
TextInfoWidget ruler = mic.createRulerControl(map); TextInfoWidget ruler = mic.createRulerControl(map);
registerSideWidget(ruler, new CompassRulerControlWidgetState(app), WIDGET_RULER, false, 43); registerSideWidget(ruler, new CompassRulerWidgetState(app), WIDGET_RULER, false, 43);
} }
public void recreateControls() { public void recreateControls() {

View file

@ -20,11 +20,13 @@ import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.views.OsmandMapLayer; import net.osmand.plus.views.OsmandMapLayer;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget;
import net.osmand.router.RouteResultPreparation; import net.osmand.router.RouteResultPreparation;
import java.util.Arrays; import java.util.Arrays;
public class LanesControl { public class LanesControl {
private MapViewTrackingUtilities trackingUtilities; private MapViewTrackingUtilities trackingUtilities;
private OsmAndLocationProvider locationProvider; private OsmAndLocationProvider locationProvider;
private MapRouteInfoMenu mapRouteInfoMenu; private MapRouteInfoMenu mapRouteInfoMenu;
@ -39,19 +41,19 @@ public class LanesControl {
private View centerInfo; private View centerInfo;
private int shadowRadius; private int shadowRadius;
public LanesControl(final MapActivity map, final OsmandMapTileView view) { public LanesControl(MapActivity mapActivity, OsmandMapTileView view) {
lanesView = (ImageView) map.findViewById(R.id.map_lanes); lanesView = mapActivity.findViewById(R.id.map_lanes);
lanesText = (TextView) map.findViewById(R.id.map_lanes_dist_text); lanesText = mapActivity.findViewById(R.id.map_lanes_dist_text);
lanesShadowText = (TextView) map.findViewById(R.id.map_lanes_dist_text_shadow); lanesShadowText = mapActivity.findViewById(R.id.map_lanes_dist_text_shadow);
centerInfo = (View) map.findViewById(R.id.map_center_info); centerInfo = mapActivity.findViewById(R.id.map_center_info);
lanesDrawable = new LanesDrawable(map, map.getMapView().getScaleCoefficient()); lanesDrawable = new LanesDrawable(mapActivity, mapActivity.getMapView().getScaleCoefficient());
lanesView.setImageDrawable(lanesDrawable); lanesView.setImageDrawable(lanesDrawable);
trackingUtilities = map.getMapViewTrackingUtilities(); trackingUtilities = mapActivity.getMapViewTrackingUtilities();
locationProvider = map.getMyApplication().getLocationProvider(); locationProvider = mapActivity.getMyApplication().getLocationProvider();
settings = map.getMyApplication().getSettings(); settings = mapActivity.getMyApplication().getSettings();
mapRouteInfoMenu = map.getMapRouteInfoMenu(); mapRouteInfoMenu = mapActivity.getMapRouteInfoMenu();
rh = map.getMyApplication().getRoutingHelper(); rh = mapActivity.getMyApplication().getRoutingHelper();
app = map.getMyApplication(); app = mapActivity.getMyApplication();
} }
public void updateTextSize(boolean isNight, int textColor, int textShadowColor, boolean textBold, int shadowRadius) { public void updateTextSize(boolean isNight, int textColor, int textShadowColor, boolean textBold, int shadowRadius) {
@ -134,4 +136,4 @@ public class LanesControl {
AndroidUiHelper.updateVisibility(centerInfo, visible); AndroidUiHelper.updateVisibility(centerInfo, visible);
return true; return true;
} }
} }

View file

@ -68,8 +68,7 @@ import net.osmand.plus.settings.backend.OsmandSettings.RulerMode;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings; import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.RulerControlLayer; import net.osmand.plus.views.RulerControlLayer;
import net.osmand.plus.views.mapwidgets.MapWidgetRegistry.WidgetState; import net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget;
import net.osmand.plus.views.mapwidgets.NextTurnInfoWidget.TurnDrawable;
import net.osmand.render.RenderingRuleSearchRequest; import net.osmand.render.RenderingRuleSearchRequest;
import net.osmand.render.RenderingRulesStorage; import net.osmand.render.RenderingRulesStorage;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -160,54 +159,6 @@ public class MapInfoWidgetsFactory {
return gpsInfoControl; return gpsInfoControl;
} }
public static class CompassRulerControlWidgetState extends WidgetState {
public static final int COMPASS_CONTROL_WIDGET_STATE_SHOW = R.id.compass_ruler_control_widget_state_show;
public static final int COMPASS_CONTROL_WIDGET_STATE_HIDE = R.id.compass_ruler_control_widget_state_hide;
private final OsmandSettings.OsmandPreference<Boolean> showCompass;
public CompassRulerControlWidgetState(OsmandApplication ctx) {
super(ctx);
showCompass = ctx.getSettings().SHOW_COMPASS_CONTROL_RULER;
}
@Override
public int getMenuTitleId() {
return R.string.map_widget_ruler_control;
}
@Override
public int getMenuIconId() {
return R.drawable.ic_action_ruler_circle;
}
@Override
public int getMenuItemId() {
return showCompass.get() ? COMPASS_CONTROL_WIDGET_STATE_SHOW : COMPASS_CONTROL_WIDGET_STATE_HIDE;
}
@Override
public int[] getMenuTitleIds() {
return new int[]{R.string.show_compass_ruler, R.string.hide_compass_ruler};
}
@Override
public int[] getMenuIconIds() {
return new int[]{R.drawable.ic_action_compass_widget, R.drawable.ic_action_compass_widget_hide};
}
@Override
public int[] getMenuItemIds() {
return new int[]{COMPASS_CONTROL_WIDGET_STATE_SHOW, COMPASS_CONTROL_WIDGET_STATE_HIDE};
}
@Override
public void changeState(int stateId) {
showCompass.set(stateId == COMPASS_CONTROL_WIDGET_STATE_SHOW);
}
}
public TextInfoWidget createRulerControl(final MapActivity map) { public TextInfoWidget createRulerControl(final MapActivity map) {
final String title = ""; final String title = "";
final TextInfoWidget rulerControl = new TextInfoWidget(map) { final TextInfoWidget rulerControl = new TextInfoWidget(map) {
@ -936,7 +887,7 @@ public class MapInfoWidgetsFactory {
private boolean showMarker; private boolean showMarker;
public TopTextView(OsmandApplication app, MapActivity map) { public TopTextView(OsmandApplication app, MapActivity map) {
turnDrawable = new NextTurnInfoWidget.TurnDrawable(map, true); turnDrawable = new TurnDrawable(map, true);
topBar = map.findViewById(R.id.map_top_bar); topBar = map.findViewById(R.id.map_top_bar);
addressText = (TextView) map.findViewById(R.id.map_address_text); addressText = (TextView) map.findViewById(R.id.map_address_text);
addressTextShadow = (TextView) map.findViewById(R.id.map_address_text_shadow); addressTextShadow = (TextView) map.findViewById(R.id.map_address_text_shadow);

View file

@ -20,6 +20,7 @@ import net.osmand.plus.views.AnimateDraggingMapThread;
import net.osmand.plus.views.DirectionDrawable; import net.osmand.plus.views.DirectionDrawable;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings; import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;

View file

@ -27,6 +27,8 @@ import net.osmand.plus.quickaction.QuickActionListFragment;
import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.MapQuickActionLayer; import net.osmand.plus.views.MapQuickActionLayer;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings; import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget;
import net.osmand.plus.views.mapwidgets.widgetstates.WidgetState;
import net.osmand.plus.widgets.IconPopupMenu; import net.osmand.plus.widgets.IconPopupMenu;
import java.util.Collections; import java.util.Collections;
@ -362,7 +364,7 @@ public class MapWidgetRegistry {
cm.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.coordinates_widget, map) cm.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.coordinates_widget, map)
.setIcon(R.drawable.ic_action_coordinates_widget) .setIcon(R.drawable.ic_action_coordinates_widget)
.setSelected(settings.SHOW_COORDINATES_WIDGET.get()) .setSelected(settings.SHOW_COORDINATES_WIDGET.get())
.setListener(new ApearanceItemClickListener(settings.SHOW_COORDINATES_WIDGET, map)) .setListener(new AppearanceItemClickListener(settings.SHOW_COORDINATES_WIDGET, map))
.setLayout(R.layout.list_item_icon_and_switch).createItem()); .setLayout(R.layout.list_item_icon_and_switch).createItem());
cm.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_markers, map) cm.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_markers, map)
.setDescription(settings.MAP_MARKERS_MODE.get().toHumanString(map)) .setDescription(settings.MAP_MARKERS_MODE.get().toHumanString(map))
@ -408,14 +410,13 @@ public class MapWidgetRegistry {
@StringRes int stringId, OsmandPreference<Boolean> pref) { @StringRes int stringId, OsmandPreference<Boolean> pref) {
cm.addItem(new ContextMenuItem.ItemBuilder().setTitleId(stringId, map) cm.addItem(new ContextMenuItem.ItemBuilder().setTitleId(stringId, map)
.setSelected(pref.get()) .setSelected(pref.get())
.setListener(new ApearanceItemClickListener(pref, map)).createItem()); .setListener(new AppearanceItemClickListener(pref, map)).createItem());
} }
public static boolean distChanged(int oldDist, int dist) { public static boolean distChanged(int oldDist, int dist) {
return !(oldDist != 0 && oldDist - dist < 100 && Math.abs(((float) dist - oldDist) / oldDist) < 0.01); return !(oldDist != 0 && oldDist - dist < 100 && Math.abs(((float) dist - oldDist) / oldDist) < 0.01);
} }
public void addControls(MapActivity map, ContextMenuAdapter cm, ApplicationMode mode) { public void addControls(MapActivity map, ContextMenuAdapter cm, ApplicationMode mode) {
addQuickActionControl(map, cm, mode); addQuickActionControl(map, cm, mode);
// Right panel // Right panel
@ -819,49 +820,23 @@ public class MapWidgetRegistry {
return cm; return cm;
} }
class ApearanceItemClickListener implements ContextMenuAdapter.ItemClickListener { static class AppearanceItemClickListener implements ContextMenuAdapter.ItemClickListener {
private MapActivity map;
private MapActivity mapActivity;
private OsmandPreference<Boolean> pref; private OsmandPreference<Boolean> pref;
public ApearanceItemClickListener(OsmandPreference<Boolean> pref, MapActivity map) { public AppearanceItemClickListener(OsmandPreference<Boolean> pref, MapActivity mapActivity) {
this.pref = pref; this.pref = pref;
this.map = map; this.mapActivity = mapActivity;
} }
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> a, public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> a,
int itemId, int pos, boolean isChecked, int[] viewCoordinates) { int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
pref.set(!pref.get()); pref.set(!pref.get());
map.updateApplicationModeSettings(); mapActivity.updateApplicationModeSettings();
a.notifyDataSetChanged(); a.notifyDataSetChanged();
return false; return false;
} }
} }
}
public static abstract class WidgetState {
private OsmandApplication ctx;
public OsmandApplication getCtx() {
return ctx;
}
public WidgetState(OsmandApplication ctx) {
this.ctx = ctx;
}
public abstract int getMenuTitleId();
public abstract int getMenuIconId();
public abstract int getMenuItemId();
public abstract int[] getMenuTitleIds();
public abstract int[] getMenuIconIds();
public abstract int[] getMenuItemIds();
public abstract void changeState(int stateId);
}
}

View file

@ -1,236 +0,0 @@
package net.osmand.plus.views.mapwidgets;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.text.TextPaint;
import androidx.annotation.ColorRes;
import androidx.annotation.NonNull;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.TurnPathHelper;
import net.osmand.router.TurnType;
public class NextTurnInfoWidget extends TextInfoWidget {
protected boolean horisontalMini;
protected int deviatedPath = 0;
protected int nextTurnDistance = 0;
private TurnDrawable turnDrawable;
private OsmandApplication app;
public NextTurnInfoWidget(Activity activity, OsmandApplication app, boolean horisontalMini) {
super(activity);
this.app = app;
this.horisontalMini = horisontalMini;
turnDrawable = new TurnDrawable(activity, horisontalMini);
if(horisontalMini) {
setImageDrawable(turnDrawable, false);
setTopImageDrawable(null, null);
} else {
setImageDrawable(null, true);
setTopImageDrawable(turnDrawable, "");
}
}
public TurnType getTurnType() {
return turnDrawable.turnType;
}
public void setTurnType(TurnType turnType) {
boolean vis = updateVisibility(turnType != null);
if (turnDrawable.setTurnType(turnType) || vis) {
turnDrawable.setTextPaint(topTextView.getPaint());
if(horisontalMini) {
setImageDrawable(turnDrawable, false);
} else {
setTopImageDrawable(turnDrawable, "");
// setTopImageDrawable(turnDrawable, turnType == null || turnType.getExitOut() == 0 ? "" :
// turnType.getExitOut() + "");
}
}
}
public void setTurnImminent(int turnImminent, boolean deviatedFromRoute) {
if(turnDrawable.turnImminent != turnImminent || turnDrawable.deviatedFromRoute != deviatedFromRoute) {
turnDrawable.setTurnImminent(turnImminent, deviatedFromRoute);
}
}
public void setDeviatePath(int deviatePath) {
if (RouteInfoWidgetsFactory.distChanged(deviatePath, this.deviatedPath)) {
this.deviatedPath = deviatePath;
updateDistance();
}
}
public void setTurnDistance(int nextTurnDistance) {
if (RouteInfoWidgetsFactory.distChanged(nextTurnDistance, this.nextTurnDistance)) {
this.nextTurnDistance = nextTurnDistance;
updateDistance();
}
}
private void updateDistance() {
int deviatePath = turnDrawable.deviatedFromRoute ? deviatedPath : nextTurnDistance;
String ds = OsmAndFormatter.getFormattedDistance(deviatePath, app);
if (ds != null) {
TurnType turnType = getTurnType();
RoutingHelper routingHelper = app.getRoutingHelper();
if ((turnType != null) && (routingHelper != null)) {
setContentDescription(ds + " " + routingHelper.getRoute().toString(turnType, app, false));
} else {
setContentDescription(ds);
}
}
int ls = ds.lastIndexOf(' ');
if (ls == -1) {
setTextNoUpdateVisibility(ds, null);
} else {
setTextNoUpdateVisibility(ds.substring(0, ls), ds.substring(ls + 1));
}
}
@Override
public boolean updateInfo(DrawSettings drawSettings) {
return false;
}
public static class TurnDrawable extends Drawable {
protected Paint paintBlack;
protected Paint paintRouteDirection;
protected Path pathForTurn = new Path();
protected Path pathForTurnOutlay = new Path();
protected TurnType turnType = null;
protected int turnImminent;
protected boolean deviatedFromRoute;
private Context ctx;
private boolean mini;
private PointF centerText;
private TextPaint textPaint;
private int clr;
public TurnDrawable(Context ctx, boolean mini) {
this.ctx = ctx;
this.mini = mini;
centerText = new PointF();
paintBlack = new Paint();
paintBlack.setStyle(Style.STROKE);
paintBlack.setColor(Color.BLACK);
paintBlack.setAntiAlias(true);
paintBlack.setStrokeWidth(2.5f);
paintRouteDirection = new Paint();
paintRouteDirection.setStyle(Style.FILL);
paintRouteDirection.setAntiAlias(true);
setColor(R.color.nav_arrow);
}
@ColorRes
public void setColor(int clr) {
if(clr != this.clr) {
this.clr = clr;
paintRouteDirection.setColor(ctx.getResources().getColor(clr));
}
}
@Override
protected void onBoundsChange(Rect bounds) {
Matrix m = new Matrix();
float scaleX = bounds.width() / 72f;
float scaleY = bounds.height() / 72f;
m.setScale(scaleX, scaleY);
pathForTurn.transform(m, pathForTurn);
centerText.x = scaleX * centerText.x;
centerText.y = scaleY * centerText.y;
pathForTurnOutlay.transform(m, pathForTurnOutlay);
}
public void setTurnImminent(int turnImminent, boolean deviatedFromRoute) {
//if user deviates from route that we should draw grey arrow
this.turnImminent = turnImminent;
this.deviatedFromRoute = deviatedFromRoute;
if (deviatedFromRoute){
paintRouteDirection.setColor(ctx.getResources().getColor(R.color.nav_arrow_distant));
} else if (turnImminent > 0) {
paintRouteDirection.setColor(ctx.getResources().getColor(R.color.nav_arrow));
} else if (turnImminent == 0) {
paintRouteDirection.setColor(ctx.getResources().getColor(R.color.nav_arrow_imminent));
} else {
paintRouteDirection.setColor(ctx.getResources().getColor(R.color.nav_arrow_distant));
}
invalidateSelf();
}
@Override
public void draw(@NonNull Canvas canvas) {
/// small indent
// canvas.translate(0, 3 * scaleCoefficient);
canvas.drawPath(pathForTurnOutlay, paintBlack);
canvas.drawPath(pathForTurn, paintRouteDirection);
canvas.drawPath(pathForTurn, paintBlack);
if(textPaint != null ) {
if (turnType != null && !mini && turnType.getExitOut() > 0) {
canvas.drawText(turnType.getExitOut() + "", centerText.x,
centerText.y - (textPaint.descent() + textPaint.ascent()) / 2, textPaint);
}
}
}
public void setTextPaint(TextPaint textPaint) {
this.textPaint = textPaint;
this.textPaint.setTextAlign(Align.CENTER);
}
@Override
public void setAlpha(int alpha) {
paintRouteDirection.setAlpha(alpha);
}
@Override
public void setColorFilter(ColorFilter cf) {
paintRouteDirection.setColorFilter(cf);
}
@Override
public int getOpacity() {
return 0;
}
public boolean setTurnType(TurnType turnType) {
if(turnType != this.turnType) {
this.turnType = turnType;
TurnPathHelper.calcTurnPath(pathForTurn, pathForTurnOutlay, turnType, null,
centerText, mini, false, true, false);
onBoundsChange(getBounds());
return true;
}
return false;
}
}
}

View file

@ -27,17 +27,22 @@ import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference; import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings; import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.mapwidgets.widgets.AlarmWidget;
import net.osmand.plus.views.mapwidgets.widgets.DistanceToPointWidget;
import net.osmand.plus.views.mapwidgets.widgets.NextTurnWidget;
import net.osmand.plus.views.mapwidgets.widgets.RulerWidget;
import net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget;
import net.osmand.router.TurnType; import net.osmand.router.TurnType;
import java.util.List; import java.util.List;
public class RouteInfoWidgetsFactory { public class RouteInfoWidgetsFactory {
public NextTurnInfoWidget createNextInfoControl(final Activity activity, public NextTurnWidget createNextInfoControl(final Activity activity,
final OsmandApplication app, boolean horisontalMini) { final OsmandApplication app, boolean horisontalMini) {
final OsmandSettings settings = app.getSettings(); final OsmandSettings settings = app.getSettings();
final RoutingHelper routingHelper = app.getRoutingHelper(); final RoutingHelper routingHelper = app.getRoutingHelper();
final NextTurnInfoWidget nextTurnInfo = new NextTurnInfoWidget(activity, app, horisontalMini) { final NextTurnWidget nextTurnInfo = new NextTurnWidget(activity, app, horisontalMini) {
NextDirectionInfo calc1 = new NextDirectionInfo(); NextDirectionInfo calc1 = new NextDirectionInfo();
@Override @Override
@ -99,10 +104,10 @@ public class RouteInfoWidgetsFactory {
return nextTurnInfo; return nextTurnInfo;
} }
public NextTurnInfoWidget createNextNextInfoControl(final Activity activity, public NextTurnWidget createNextNextInfoControl(final Activity activity,
final OsmandApplication app, boolean horisontalMini) { final OsmandApplication app, boolean horisontalMini) {
final RoutingHelper routingHelper = app.getRoutingHelper(); final RoutingHelper routingHelper = app.getRoutingHelper();
final NextTurnInfoWidget nextTurnInfo = new NextTurnInfoWidget(activity, app, horisontalMini) { final NextTurnWidget nextTurnInfo = new NextTurnWidget(activity, app, horisontalMini) {
NextDirectionInfo calc1 = new NextDirectionInfo(); NextDirectionInfo calc1 = new NextDirectionInfo();
@Override @Override
public boolean updateInfo(DrawSettings drawSettings) { public boolean updateInfo(DrawSettings drawSettings) {
@ -395,7 +400,7 @@ public class RouteInfoWidgetsFactory {
} }
public TextInfoWidget createDistanceControl(final MapActivity map) { public TextInfoWidget createDistanceControl(final MapActivity map) {
DistanceToPointInfoControl distanceControl = new DistanceToPointInfoControl(map, R.drawable.widget_target_day, DistanceToPointWidget distanceControl = new DistanceToPointWidget(map, R.drawable.widget_target_day,
R.drawable.widget_target_night) { R.drawable.widget_target_night) {
@Override @Override
public LatLon getPointToNavigate() { public LatLon getPointToNavigate() {
@ -416,7 +421,7 @@ public class RouteInfoWidgetsFactory {
public TextInfoWidget createIntermediateDistanceControl(final MapActivity map) { public TextInfoWidget createIntermediateDistanceControl(final MapActivity map) {
final TargetPointsHelper targets = map.getMyApplication().getTargetPointsHelper(); final TargetPointsHelper targets = map.getMyApplication().getTargetPointsHelper();
DistanceToPointInfoControl distanceControl = new DistanceToPointInfoControl(map, R.drawable.widget_intermediate_day, DistanceToPointWidget distanceControl = new DistanceToPointWidget(map, R.drawable.widget_intermediate_day,
R.drawable.widget_intermediate_night) { R.drawable.widget_intermediate_night) {
@Override @Override
@ -458,7 +463,7 @@ public class RouteInfoWidgetsFactory {
private float MIN_SPEED_FOR_HEADING = 1f; private float MIN_SPEED_FOR_HEADING = 1f;
private LatLon getNextTargetPoint() { private LatLon getNextTargetPoint() {
List<TargetPoint> points = getOsmandApplication().getTargetPointsHelper().getIntermediatePointsWithTarget(); List<TargetPoint> points = getApplication().getTargetPointsHelper().getIntermediatePointsWithTarget();
return points.isEmpty() ? null : points.get(0).point; return points.isEmpty() ? null : points.get(0).point;
} }
@ -471,7 +476,7 @@ public class RouteInfoWidgetsFactory {
if (isUpdateNeeded() || degreesChanged(cachedDegrees, b) || modeChanged) { if (isUpdateNeeded() || degreesChanged(cachedDegrees, b) || modeChanged) {
cachedDegrees = b; cachedDegrees = b;
if (b != -1000) { if (b != -1000) {
setText(OsmAndFormatter.getFormattedAzimuth(b, getOsmandApplication()) + (relative ? "" : " M"), null); setText(OsmAndFormatter.getFormattedAzimuth(b, getApplication()) + (relative ? "" : " M"), null);
} else { } else {
setText(null, null); setText(null, null);
} }
@ -487,10 +492,10 @@ public class RouteInfoWidgetsFactory {
public int getBearing(boolean relative) { public int getBearing(boolean relative) {
int d = -1000; int d = -1000;
Location myLocation = getOsmandApplication().getLocationProvider().getLastKnownLocation(); Location myLocation = getApplication().getLocationProvider().getLastKnownLocation();
LatLon l = getNextTargetPoint(); LatLon l = getNextTargetPoint();
if (l == null) { if (l == null) {
List<MapMarker> markers = getOsmandApplication().getMapMarkersHelper().getMapMarkers(); List<MapMarker> markers = getApplication().getMapMarkersHelper().getMapMarkers();
if (markers.size() > 0) { if (markers.size() > 0) {
l = markers.get(0).point; l = markers.get(0).point;
} }
@ -505,7 +510,7 @@ public class RouteInfoWidgetsFactory {
float bearingToDest = dest.getBearing() - destGf.getDeclination(); float bearingToDest = dest.getBearing() - destGf.getDeclination();
if (relative) { if (relative) {
float b = -1000; float b = -1000;
Float heading = getOsmandApplication().getLocationProvider().getHeading(); Float heading = getApplication().getLocationProvider().getHeading();
if ((myLocation.getSpeed() < MIN_SPEED_FOR_HEADING || !myLocation.hasBearing()) if ((myLocation.getSpeed() < MIN_SPEED_FOR_HEADING || !myLocation.hasBearing())
&& heading != null) { && heading != null) {
b = heading; b = heading;

View file

@ -0,0 +1,146 @@
package net.osmand.plus.views.mapwidgets;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.text.TextPaint;
import androidx.annotation.ColorRes;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import net.osmand.plus.R;
import net.osmand.plus.views.TurnPathHelper;
import net.osmand.router.TurnType;
public class TurnDrawable extends Drawable {
protected Paint paintBlack;
protected Paint paintRouteDirection;
protected Path pathForTurn = new Path();
protected Path pathForTurnOutlay = new Path();
protected TurnType turnType = null;
protected int turnImminent;
protected boolean deviatedFromRoute;
private Context ctx;
private boolean mini;
private PointF centerText;
private TextPaint textPaint;
private int clr;
public TurnDrawable(Context ctx, boolean mini) {
this.ctx = ctx;
this.mini = mini;
centerText = new PointF();
paintBlack = new Paint();
paintBlack.setStyle(Paint.Style.STROKE);
paintBlack.setColor(Color.BLACK);
paintBlack.setAntiAlias(true);
paintBlack.setStrokeWidth(2.5f);
paintRouteDirection = new Paint();
paintRouteDirection.setStyle(Paint.Style.FILL);
paintRouteDirection.setAntiAlias(true);
setColor(R.color.nav_arrow);
}
public void setColor(@ColorRes int clr) {
if (clr != this.clr) {
this.clr = clr;
paintRouteDirection.setColor(ContextCompat.getColor(ctx, clr));
}
}
@Override
protected void onBoundsChange(Rect bounds) {
Matrix m = new Matrix();
float scaleX = bounds.width() / 72f;
float scaleY = bounds.height() / 72f;
m.setScale(scaleX, scaleY);
pathForTurn.transform(m, pathForTurn);
centerText.x = scaleX * centerText.x;
centerText.y = scaleY * centerText.y;
pathForTurnOutlay.transform(m, pathForTurnOutlay);
}
public int getTurnImminent() {
return turnImminent;
}
public boolean isDeviatedFromRoute() {
return deviatedFromRoute;
}
public void setTurnImminent(int turnImminent, boolean deviatedFromRoute) {
//if user deviates from route that we should draw grey arrow
this.turnImminent = turnImminent;
this.deviatedFromRoute = deviatedFromRoute;
if (deviatedFromRoute) {
paintRouteDirection.setColor(ctx.getResources().getColor(R.color.nav_arrow_distant));
} else if (turnImminent > 0) {
paintRouteDirection.setColor(ctx.getResources().getColor(R.color.nav_arrow));
} else if (turnImminent == 0) {
paintRouteDirection.setColor(ctx.getResources().getColor(R.color.nav_arrow_imminent));
} else {
paintRouteDirection.setColor(ctx.getResources().getColor(R.color.nav_arrow_distant));
}
invalidateSelf();
}
@Override
public void draw(@NonNull Canvas canvas) {
/// small indent
// canvas.translate(0, 3 * scaleCoefficient);
canvas.drawPath(pathForTurnOutlay, paintBlack);
canvas.drawPath(pathForTurn, paintRouteDirection);
canvas.drawPath(pathForTurn, paintBlack);
if (textPaint != null) {
if (turnType != null && !mini && turnType.getExitOut() > 0) {
canvas.drawText(turnType.getExitOut() + "", centerText.x,
centerText.y - (textPaint.descent() + textPaint.ascent()) / 2, textPaint);
}
}
}
public void setTextPaint(TextPaint textPaint) {
this.textPaint = textPaint;
this.textPaint.setTextAlign(Paint.Align.CENTER);
}
@Override
public void setAlpha(int alpha) {
paintRouteDirection.setAlpha(alpha);
}
@Override
public void setColorFilter(ColorFilter cf) {
paintRouteDirection.setColorFilter(cf);
}
@Override
public int getOpacity() {
return 0;
}
public TurnType getTurnType() {
return turnType;
}
public boolean setTurnType(TurnType turnType) {
if (turnType != this.turnType) {
this.turnType = turnType;
TurnPathHelper.calcTurnPath(pathForTurn, pathForTurnOutlay, turnType, null,
centerText, mini, false, true, false);
onBoundsChange(getBounds());
return true;
}
return false;
}
}

View file

@ -1,4 +1,4 @@
package net.osmand.plus.views.mapwidgets; package net.osmand.plus.views.mapwidgets.widgets;
import android.content.res.Resources; import android.content.res.Resources;
import android.view.View; import android.view.View;
@ -33,7 +33,7 @@ public class AlarmWidget {
private TextView widgetText; private TextView widgetText;
private TextView widgetBottomText; private TextView widgetBottomText;
private OsmandSettings settings; private OsmandSettings settings;
private RoutingHelper rh; private RoutingHelper routingHelper;
private MapViewTrackingUtilities trackingUtilities; private MapViewTrackingUtilities trackingUtilities;
private OsmAndLocationProvider locationProvider; private OsmAndLocationProvider locationProvider;
private WaypointHelper wh; private WaypointHelper wh;
@ -44,11 +44,11 @@ public class AlarmWidget {
public AlarmWidget(final OsmandApplication app, MapActivity ma) { public AlarmWidget(final OsmandApplication app, MapActivity ma) {
layout = ma.findViewById(R.id.map_alarm_warning); layout = ma.findViewById(R.id.map_alarm_warning);
icon = (ImageView) ma.findViewById(R.id.map_alarm_warning_icon); icon = ma.findViewById(R.id.map_alarm_warning_icon);
widgetText = (TextView) ma.findViewById(R.id.map_alarm_warning_text); widgetText = ma.findViewById(R.id.map_alarm_warning_text);
widgetBottomText = (TextView) ma.findViewById(R.id.map_alarm_warning_text_bottom); widgetBottomText = ma.findViewById(R.id.map_alarm_warning_text_bottom);
settings = app.getSettings(); settings = app.getSettings();
rh = ma.getRoutingHelper(); routingHelper = ma.getRoutingHelper();
trackingUtilities = ma.getMapViewTrackingUtilities(); trackingUtilities = ma.getMapViewTrackingUtilities();
locationProvider = app.getLocationProvider(); locationProvider = app.getLocationProvider();
wh = app.getWaypointHelper(); wh = app.getWaypointHelper();
@ -62,10 +62,10 @@ public class AlarmWidget {
boolean tunnels = settings.SHOW_TUNNELS.get(); boolean tunnels = settings.SHOW_TUNNELS.get();
boolean browseMap = settings.APPLICATION_MODE.get() == ApplicationMode.DEFAULT; boolean browseMap = settings.APPLICATION_MODE.get() == ApplicationMode.DEFAULT;
boolean visible = false; boolean visible = false;
if ((rh.isFollowingMode() || trackingUtilities.isMapLinkedToLocation() && !browseMap) if ((routingHelper.isFollowingMode() || trackingUtilities.isMapLinkedToLocation() && !browseMap)
&& showRoutingAlarms && (trafficWarnings || cams)) { && showRoutingAlarms && (trafficWarnings || cams)) {
AlarmInfo alarm; AlarmInfo alarm;
if (rh.isFollowingMode() && !rh.isDeviatedFromRoute() && (rh.getCurrentGPXRoute() == null || rh.isCurrentGPXRouteV2())) { if (routingHelper.isFollowingMode() && !routingHelper.isDeviatedFromRoute() && (routingHelper.getCurrentGPXRoute() == null || routingHelper.isCurrentGPXRouteV2())) {
alarm = wh.getMostImportantAlarm(settings.SPEED_SYSTEM.get(), cams); alarm = wh.getMostImportantAlarm(settings.SPEED_SYSTEM.get(), cams);
} else { } else {
RouteDataObject ro = locationProvider.getLastKnownRouteSegment(); RouteDataObject ro = locationProvider.getLastKnownRouteSegment();
@ -188,6 +188,6 @@ public class AlarmWidget {
} }
public void setVisibility(boolean visibility) { public void setVisibility(boolean visibility) {
layout.setVisibility(visibility ? View.VISIBLE : View.GONE); AndroidUiHelper.updateVisibility(layout, visibility);
} }
} }

View file

@ -1,4 +1,4 @@
package net.osmand.plus.views.mapwidgets; package net.osmand.plus.views.mapwidgets.widgets;
import android.view.View; import android.view.View;
@ -9,14 +9,15 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.AnimateDraggingMapThread; import net.osmand.plus.views.AnimateDraggingMapThread;
import net.osmand.plus.views.OsmandMapLayer; import net.osmand.plus.views.OsmandMapLayer;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.mapwidgets.RouteInfoWidgetsFactory;
public abstract class DistanceToPointInfoControl extends TextInfoWidget { public abstract class DistanceToPointWidget extends TextInfoWidget {
private final OsmandMapTileView view; private final OsmandMapTileView view;
private float[] calculations = new float[1]; private float[] calculations = new float[1];
private int cachedMeters; private int cachedMeters;
public DistanceToPointInfoControl(MapActivity ma, int res, int resNight) { public DistanceToPointWidget(MapActivity ma, int res, int resNight) {
super(ma); super(ma);
this.view = ma.getMapView(); this.view = ma.getMapView();
if (res != 0 && resNight != 0) { if (res != 0 && resNight != 0) {
@ -36,7 +37,7 @@ public abstract class DistanceToPointInfoControl extends TextInfoWidget {
AnimateDraggingMapThread thread = view.getAnimatedDraggingThread(); AnimateDraggingMapThread thread = view.getAnimatedDraggingThread();
LatLon pointToNavigate = getPointToNavigate(); LatLon pointToNavigate = getPointToNavigate();
if (pointToNavigate != null) { if (pointToNavigate != null) {
int fZoom = view.getZoom() < 15 ? 15 : view.getZoom(); int fZoom = Math.max(view.getZoom(), 15);
thread.startMoving(pointToNavigate.getLatitude(), pointToNavigate.getLongitude(), fZoom, true); thread.startMoving(pointToNavigate.getLatitude(), pointToNavigate.getLongitude(), fZoom, true);
} }
} }
@ -79,4 +80,4 @@ public abstract class DistanceToPointInfoControl extends TextInfoWidget {
} }
return d; return d;
} }
} }

View file

@ -0,0 +1,100 @@
package net.osmand.plus.views.mapwidgets.widgets;
import android.app.Activity;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.routing.RouteCalculationResult;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.mapwidgets.RouteInfoWidgetsFactory;
import net.osmand.plus.views.mapwidgets.TurnDrawable;
import net.osmand.router.TurnType;
public class NextTurnWidget extends TextInfoWidget {
protected boolean horizontalMini;
protected int deviatedPath = 0;
protected int nextTurnDistance = 0;
private TurnDrawable turnDrawable;
private OsmandApplication app;
public NextTurnWidget(Activity activity, OsmandApplication app, boolean horizontalMini) {
super(activity);
this.app = app;
this.horizontalMini = horizontalMini;
turnDrawable = new TurnDrawable(activity, horizontalMini);
if (horizontalMini) {
setImageDrawable(turnDrawable, false);
setTopImageDrawable(null, null);
} else {
setImageDrawable(null, true);
setTopImageDrawable(turnDrawable, "");
}
}
public TurnType getTurnType() {
return turnDrawable.getTurnType();
}
public void setTurnType(TurnType turnType) {
boolean vis = updateVisibility(turnType != null);
if (turnDrawable.setTurnType(turnType) || vis) {
turnDrawable.setTextPaint(topTextView.getPaint());
if (horizontalMini) {
setImageDrawable(turnDrawable, false);
} else {
setTopImageDrawable(turnDrawable, "");
// setTopImageDrawable(turnDrawable, turnType == null || turnType.getExitOut() == 0 ? "" :
// turnType.getExitOut() + "");
}
}
}
public void setTurnImminent(int turnImminent, boolean deviatedFromRoute) {
if (turnDrawable.getTurnImminent() != turnImminent || turnDrawable.isDeviatedFromRoute() != deviatedFromRoute) {
turnDrawable.setTurnImminent(turnImminent, deviatedFromRoute);
}
}
public void setDeviatePath(int deviatePath) {
if (RouteInfoWidgetsFactory.distChanged(deviatePath, this.deviatedPath)) {
this.deviatedPath = deviatePath;
updateDistance();
}
}
public void setTurnDistance(int nextTurnDistance) {
if (RouteInfoWidgetsFactory.distChanged(nextTurnDistance, this.nextTurnDistance)) {
this.nextTurnDistance = nextTurnDistance;
updateDistance();
}
}
private void updateDistance() {
int deviatePath = turnDrawable.isDeviatedFromRoute() ? deviatedPath : nextTurnDistance;
String ds = OsmAndFormatter.getFormattedDistance(deviatePath, app);
TurnType turnType = getTurnType();
RoutingHelper routingHelper = app.getRoutingHelper();
if ((turnType != null) && (routingHelper != null)) {
setContentDescription(ds + " " + RouteCalculationResult.toString(turnType, app, false));
} else {
setContentDescription(ds);
}
int ls = ds.lastIndexOf(' ');
if (ls == -1) {
setTextNoUpdateVisibility(ds, null);
} else {
setTextNoUpdateVisibility(ds.substring(0, ls), ds.substring(ls + 1));
}
}
@Override
public boolean updateInfo(DrawSettings drawSettings) {
return false;
}
}

View file

@ -1,4 +1,4 @@
package net.osmand.plus.views.mapwidgets; package net.osmand.plus.views.mapwidgets.widgets;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -12,7 +12,7 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.views.OsmandMapLayer; import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
public class RulerWidget { public class RulerWidget {
@ -21,7 +21,7 @@ public class RulerWidget {
private ImageView icon; private ImageView icon;
private TextView text; private TextView text;
private TextView textShadow; private TextView textShadow;
private MapActivity ma; private MapActivity mapActivity;
private String cacheRulerText; private String cacheRulerText;
private int maxWidth; private int maxWidth;
private float cacheMapDensity; private float cacheMapDensity;
@ -31,15 +31,15 @@ public class RulerWidget {
private double cacheRulerTileY; private double cacheRulerTileY;
private boolean orientationPortrait; private boolean orientationPortrait;
public RulerWidget(final OsmandApplication app, MapActivity ma) { public RulerWidget(OsmandApplication app, MapActivity mapActivity) {
this.ma = ma; this.mapActivity = mapActivity;
layout = ma.findViewById(R.id.map_ruler_layout); layout = mapActivity.findViewById(R.id.map_ruler_layout);
icon = (ImageView) ma.findViewById(R.id.map_ruler_image); icon = mapActivity.findViewById(R.id.map_ruler_image);
text = (TextView) ma.findViewById(R.id.map_ruler_text); text = mapActivity.findViewById(R.id.map_ruler_text);
textShadow = (TextView) ma.findViewById(R.id.map_ruler_text_shadow); textShadow = mapActivity.findViewById(R.id.map_ruler_text_shadow);
maxWidth = ma.getResources().getDimensionPixelSize(R.dimen.map_ruler_width); maxWidth = mapActivity.getResources().getDimensionPixelSize(R.dimen.map_ruler_width);
orientationPortrait = AndroidUiHelper.isOrientationPortrait(ma); orientationPortrait = AndroidUiHelper.isOrientationPortrait(mapActivity);
mapDensity = ma.getMyApplication().getSettings().MAP_DENSITY; mapDensity = mapActivity.getMyApplication().getSettings().MAP_DENSITY;
cacheMapDensity = mapDensity.get(); cacheMapDensity = mapDensity.get();
} }
@ -48,9 +48,9 @@ public class RulerWidget {
icon.setBackgroundResource(isNight ? R.drawable.ruler_night : R.drawable.ruler); icon.setBackgroundResource(isNight ? R.drawable.ruler_night : R.drawable.ruler);
} }
public boolean updateInfo(RotatedTileBox tb, OsmandMapLayer.DrawSettings nightMode) { public boolean updateInfo(RotatedTileBox tb, DrawSettings nightMode) {
boolean visible = true; boolean visible = true;
OsmandMapTileView view = ma.getMapView(); OsmandMapTileView view = mapActivity.getMapView();
// update cache // update cache
if (view.isZooming()) { if (view.isZooming()) {
visible = false; visible = false;
@ -79,6 +79,6 @@ public class RulerWidget {
} }
public void setVisibility(boolean visibility) { public void setVisibility(boolean visibility) {
layout.setVisibility(visibility ? View.VISIBLE : View.GONE); AndroidUiHelper.updateVisibility(layout, visibility);
} }
} }

View file

@ -1,4 +1,4 @@
package net.osmand.plus.views.mapwidgets; package net.osmand.plus.views.mapwidgets.widgets;
import android.app.Activity; import android.app.Activity;
import android.graphics.Paint.Style; import android.graphics.Paint.Style;
@ -19,7 +19,9 @@ import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings; import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
public class TextInfoWidget { public class TextInfoWidget {
private OsmandApplication app;
private String contentTitle; private String contentTitle;
private View view; private View view;
@ -31,7 +33,6 @@ public class TextInfoWidget {
private ImageView topImageView; private ImageView topImageView;
protected TextView topTextView; protected TextView topTextView;
private boolean explicitlyVisible; private boolean explicitlyVisible;
private OsmandApplication app;
private int dayIcon; private int dayIcon;
private int nightIcon; private int nightIcon;
@ -44,35 +45,34 @@ public class TextInfoWidget {
public TextInfoWidget(Activity activity) { public TextInfoWidget(Activity activity) {
app = (OsmandApplication) activity.getApplication(); app = (OsmandApplication) activity.getApplication();
view = UiUtilities.getInflater(activity, isNight).inflate(R.layout.map_hud_widget, null); view = UiUtilities.getInflater(activity, isNight).inflate(R.layout.map_hud_widget, null);
bottomLayout = (ViewGroup) view.findViewById(R.id.widget_bottom_layout); bottomLayout = view.findViewById(R.id.widget_bottom_layout);
topImageView = (ImageView) view.findViewById(R.id.widget_top_icon); topImageView = view.findViewById(R.id.widget_top_icon);
topTextView = (TextView) view.findViewById(R.id.widget_top_icon_text); topTextView = view.findViewById(R.id.widget_top_icon_text);
imageView = (ImageView) view.findViewById(R.id.widget_icon); imageView = view.findViewById(R.id.widget_icon);
textView = (TextView) view.findViewById(R.id.widget_text); textView = view.findViewById(R.id.widget_text);
textViewShadow = (TextView) view.findViewById(R.id.widget_text_shadow); textViewShadow = view.findViewById(R.id.widget_text_shadow);
smallTextViewShadow = (TextView) view.findViewById(R.id.widget_text_small_shadow); smallTextViewShadow = view.findViewById(R.id.widget_text_small_shadow);
smallTextView = (TextView) view.findViewById(R.id.widget_text_small); smallTextView = view.findViewById(R.id.widget_text_small);
} }
public OsmandApplication getOsmandApplication() { public OsmandApplication getApplication() {
return app; return app;
} }
public View getView() { public View getView() {
return view; return view;
} }
public void setImageDrawable(Drawable imageDrawable) { public void setImageDrawable(Drawable imageDrawable) {
setImageDrawable(imageDrawable, false); setImageDrawable(imageDrawable, false);
} }
public void setImageDrawable(int res) { public void setImageDrawable(int res) {
setImageDrawable(app.getUIUtilities().getIcon(res, 0), false); setImageDrawable(app.getUIUtilities().getIcon(res, 0), false);
} }
public void setImageDrawable(Drawable imageDrawable, boolean gone) { public void setImageDrawable(Drawable imageDrawable, boolean gone) {
if(imageDrawable != null) { if (imageDrawable != null) {
imageView.setImageDrawable(imageDrawable); imageView.setImageDrawable(imageDrawable);
Object anim = imageView.getDrawable(); Object anim = imageView.getDrawable();
if (anim instanceof AnimationDrawable) { if (anim instanceof AnimationDrawable) {
@ -84,9 +84,9 @@ public class TextInfoWidget {
} }
imageView.invalidate(); imageView.invalidate();
} }
public void setTopImageDrawable(Drawable imageDrawable, String topText) { public void setTopImageDrawable(Drawable imageDrawable, String topText) {
if(imageDrawable != null) { if (imageDrawable != null) {
topImageView.setImageDrawable(imageDrawable); topImageView.setImageDrawable(imageDrawable);
topImageView.setVisibility(View.VISIBLE); topImageView.setVisibility(View.VISIBLE);
LinearLayout.LayoutParams lp = (android.widget.LinearLayout.LayoutParams) bottomLayout.getLayoutParams(); LinearLayout.LayoutParams lp = (android.widget.LinearLayout.LayoutParams) bottomLayout.getLayoutParams();
@ -96,17 +96,17 @@ public class TextInfoWidget {
topTextView.setVisibility(View.VISIBLE); topTextView.setVisibility(View.VISIBLE);
topTextView.setText(topText == null ? "" : topText); topTextView.setText(topText == null ? "" : topText);
} else { } else {
topImageView.setVisibility(View.GONE ); topImageView.setVisibility(View.GONE);
topTextView.setVisibility(View.GONE ); topTextView.setVisibility(View.GONE);
LinearLayout.LayoutParams lp = (android.widget.LinearLayout.LayoutParams) bottomLayout.getLayoutParams(); LinearLayout.LayoutParams lp = (android.widget.LinearLayout.LayoutParams) bottomLayout.getLayoutParams();
lp.gravity = Gravity.NO_GRAVITY; lp.gravity = Gravity.NO_GRAVITY;
bottomLayout.setLayoutParams(lp); bottomLayout.setLayoutParams(lp);
} }
topTextView.invalidate(); topTextView.invalidate();
topImageView.invalidate(); topImageView.invalidate();
} }
public boolean setIcons(int widgetDayIcon, int widgetNightIcon) { public boolean setIcons(int widgetDayIcon, int widgetNightIcon) {
if (dayIcon != widgetDayIcon || nightIcon != widgetNightIcon) { if (dayIcon != widgetDayIcon || nightIcon != widgetNightIcon) {
dayIcon = widgetDayIcon; dayIcon = widgetDayIcon;
@ -134,7 +134,7 @@ public class TextInfoWidget {
public void setContentDescription(CharSequence text) { public void setContentDescription(CharSequence text) {
view.setContentDescription(combine(contentTitle, text)); view.setContentDescription(combine(contentTitle, text));
} }
public void setContentTitle(int messageId) { public void setContentTitle(int messageId) {
setContentTitle(view.getContext().getString(messageId)); setContentTitle(view.getContext().getString(messageId));
} }
@ -143,7 +143,7 @@ public class TextInfoWidget {
contentTitle = text; contentTitle = text;
setContentDescription(combine(textView.getText(), smallTextView.getText())); setContentDescription(combine(textView.getText(), smallTextView.getText()));
} }
public void setText(String text, String subtext) { public void setText(String text, String subtext) {
setTextNoUpdateVisibility(text, subtext); setTextNoUpdateVisibility(text, subtext);
updateVisibility(text != null); updateVisibility(text != null);
@ -154,14 +154,14 @@ public class TextInfoWidget {
// if(this.text != null && this.text.length() > 7) { // if(this.text != null && this.text.length() > 7) {
// this.text = this.text.substring(0, 6) +".."; // this.text = this.text.substring(0, 6) +"..";
// } // }
if(text == null) { if (text == null) {
textView.setText(""); textView.setText("");
textViewShadow.setText(""); textViewShadow.setText("");
} else { } else {
textView.setText(text); textView.setText(text);
textViewShadow.setText(text); textViewShadow.setText(text);
} }
if(subtext == null) { if (subtext == null) {
smallTextView.setText(""); smallTextView.setText("");
smallTextViewShadow.setText(""); smallTextViewShadow.setText("");
} else { } else {
@ -169,7 +169,7 @@ public class TextInfoWidget {
smallTextViewShadow.setText(subtext); smallTextViewShadow.setText(subtext);
} }
} }
protected boolean updateVisibility(boolean visible) { protected boolean updateVisibility(boolean visible) {
if (visible != (view.getVisibility() == View.VISIBLE)) { if (visible != (view.getVisibility() == View.VISIBLE)) {
if (visible) { if (visible) {
@ -184,7 +184,7 @@ public class TextInfoWidget {
} }
return false; return false;
} }
public boolean isVisible() { public boolean isVisible() {
return view.getVisibility() == View.VISIBLE && view.getParent() != null; return view.getVisibility() == View.VISIBLE && view.getParent() != null;
} }
@ -223,15 +223,15 @@ public class TextInfoWidget {
public void setExplicitlyVisible(boolean explicitlyVisible) { public void setExplicitlyVisible(boolean explicitlyVisible) {
this.explicitlyVisible = explicitlyVisible; this.explicitlyVisible = explicitlyVisible;
} }
public boolean isExplicitlyVisible() { public boolean isExplicitlyVisible() {
return explicitlyVisible; return explicitlyVisible;
} }
public void updateIconMode(boolean night) { public void updateIconMode(boolean night) {
isNight = night; isNight = night;
if(dayIcon != 0) { if (dayIcon != 0) {
setImageDrawable(!night? dayIcon : nightIcon); setImageDrawable(!night ? dayIcon : nightIcon);
} }
} }
@ -240,10 +240,10 @@ public class TextInfoWidget {
updateTextColor(textView, textViewShadow, textColor, textShadowColor, bold, rad); updateTextColor(textView, textViewShadow, textColor, textShadowColor, bold, rad);
updateTextColor(topTextView, null, textColor, textShadowColor, bold, rad); updateTextColor(topTextView, null, textColor, textShadowColor, bold, rad);
} }
public static void updateTextColor(TextView tv, TextView shadow, int textColor, int textShadowColor, boolean textBold, int rad) { public static void updateTextColor(TextView tv, TextView shadow, int textColor, int textShadowColor, boolean textBold, int rad) {
if(shadow != null) { if (shadow != null) {
if(rad > 0) { if (rad > 0) {
shadow.setVisibility(View.VISIBLE); shadow.setVisibility(View.VISIBLE);
shadow.setTypeface(Typeface.DEFAULT, textBold ? Typeface.BOLD : Typeface.NORMAL); shadow.setTypeface(Typeface.DEFAULT, textBold ? Typeface.BOLD : Typeface.NORMAL);
shadow.getPaint().setStrokeWidth(rad); shadow.getPaint().setStrokeWidth(rad);
@ -258,4 +258,4 @@ public class TextInfoWidget {
tv.setTextColor(textColor); tv.setTextColor(textColor);
tv.setTypeface(Typeface.DEFAULT, textBold ? Typeface.BOLD : Typeface.NORMAL); tv.setTypeface(Typeface.DEFAULT, textBold ? Typeface.BOLD : Typeface.NORMAL);
} }
} }

View file

@ -1,10 +1,10 @@
package net.osmand.plus.views.mapwidgets; package net.osmand.plus.views.mapwidgets.widgetstates;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.backend.OsmandSettings;
public class BearingWidgetState extends MapWidgetRegistry.WidgetState { public class BearingWidgetState extends WidgetState {
public static final int BEARING_WIDGET_STATE_RELATIVE_BEARING = R.id.bearing_widget_state_relative_bearing; public static final int BEARING_WIDGET_STATE_RELATIVE_BEARING = R.id.bearing_widget_state_relative_bearing;
public static final int BEARING_WIDGET_STATE_MAGNETIC_BEARING = R.id.bearing_widget_state_magnetic_bearing; public static final int BEARING_WIDGET_STATE_MAGNETIC_BEARING = R.id.bearing_widget_state_magnetic_bearing;
@ -50,4 +50,4 @@ public class BearingWidgetState extends MapWidgetRegistry.WidgetState {
public void changeState(int stateId) { public void changeState(int stateId) {
showRelativeBearing.set(stateId == BEARING_WIDGET_STATE_RELATIVE_BEARING); showRelativeBearing.set(stateId == BEARING_WIDGET_STATE_RELATIVE_BEARING);
} }
} }

View file

@ -0,0 +1,53 @@
package net.osmand.plus.views.mapwidgets.widgetstates;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
public class CompassRulerWidgetState extends WidgetState {
public static final int COMPASS_CONTROL_WIDGET_STATE_SHOW = R.id.compass_ruler_control_widget_state_show;
public static final int COMPASS_CONTROL_WIDGET_STATE_HIDE = R.id.compass_ruler_control_widget_state_hide;
private final OsmandPreference<Boolean> showCompass;
public CompassRulerWidgetState(OsmandApplication app) {
super(app);
showCompass = app.getSettings().SHOW_COMPASS_CONTROL_RULER;
}
@Override
public int getMenuTitleId() {
return R.string.map_widget_ruler_control;
}
@Override
public int getMenuIconId() {
return R.drawable.ic_action_ruler_circle;
}
@Override
public int getMenuItemId() {
return showCompass.get() ? COMPASS_CONTROL_WIDGET_STATE_SHOW : COMPASS_CONTROL_WIDGET_STATE_HIDE;
}
@Override
public int[] getMenuTitleIds() {
return new int[] {R.string.show_compass_ruler, R.string.hide_compass_ruler};
}
@Override
public int[] getMenuIconIds() {
return new int[] {R.drawable.ic_action_compass_widget, R.drawable.ic_action_compass_widget_hide};
}
@Override
public int[] getMenuItemIds() {
return new int[] {COMPASS_CONTROL_WIDGET_STATE_SHOW, COMPASS_CONTROL_WIDGET_STATE_HIDE};
}
@Override
public void changeState(int stateId) {
showCompass.set(stateId == COMPASS_CONTROL_WIDGET_STATE_SHOW);
}
}

View file

@ -1,24 +1,24 @@
package net.osmand.plus.views.mapwidgets; package net.osmand.plus.views.mapwidgets.widgetstates;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
public class TimeControlWidgetState extends MapWidgetRegistry.WidgetState { public class TimeWidgetState extends WidgetState {
public static final int TIME_CONTROL_WIDGET_STATE_ARRIVAL_TIME = R.id.time_control_widget_state_arrival_time; public static final int TIME_CONTROL_WIDGET_STATE_ARRIVAL_TIME = R.id.time_control_widget_state_arrival_time;
public static final int TIME_CONTROL_WIDGET_STATE_TIME_TO_GO = R.id.time_control_widget_state_time_to_go; public static final int TIME_CONTROL_WIDGET_STATE_TIME_TO_GO = R.id.time_control_widget_state_time_to_go;
private final OsmandSettings.OsmandPreference<Boolean> showArrival; private final OsmandPreference<Boolean> showArrival;
private final boolean intermediate; private final boolean intermediate;
public TimeControlWidgetState(OsmandApplication ctx, boolean intermediate) { public TimeWidgetState(OsmandApplication app, boolean intermediate) {
super(ctx); super(app);
this.intermediate = intermediate; this.intermediate = intermediate;
if (intermediate) { if (intermediate) {
showArrival = ctx.getSettings().SHOW_INTERMEDIATE_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME; showArrival = app.getSettings().SHOW_INTERMEDIATE_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME;
} else { } else {
showArrival = ctx.getSettings().SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME; showArrival = app.getSettings().SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME;
} }
} }
@ -68,4 +68,4 @@ public class TimeControlWidgetState extends MapWidgetRegistry.WidgetState {
public void changeState(int stateId) { public void changeState(int stateId) {
showArrival.set(stateId == TIME_CONTROL_WIDGET_STATE_ARRIVAL_TIME); showArrival.set(stateId == TIME_CONTROL_WIDGET_STATE_ARRIVAL_TIME);
} }
} }

View file

@ -0,0 +1,30 @@
package net.osmand.plus.views.mapwidgets.widgetstates;
import net.osmand.plus.OsmandApplication;
public abstract class WidgetState {
private OsmandApplication ctx;
public OsmandApplication getCtx() {
return ctx;
}
public WidgetState(OsmandApplication ctx) {
this.ctx = ctx;
}
public abstract int getMenuTitleId();
public abstract int getMenuIconId();
public abstract int getMenuItemId();
public abstract int[] getMenuTitleIds();
public abstract int[] getMenuIconIds();
public abstract int[] getMenuItemIds();
public abstract void changeState(int stateId);
}