Unify how widgets registry works
This commit is contained in:
parent
5245e11699
commit
f741c04755
9 changed files with 151 additions and 141 deletions
|
@ -3,15 +3,17 @@ package net.osmand.plus;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.osmand.StateChangedListener;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
|
||||
public class ApplicationMode {
|
||||
private static Map<String, Set<ApplicationMode>> widgets = new LinkedHashMap<String, Set<ApplicationMode>>();
|
||||
private static List<ApplicationMode> values = new ArrayList<ApplicationMode>();
|
||||
private static List<ApplicationMode> cachedFilteredValues = new ArrayList<ApplicationMode>();
|
||||
private static boolean listenerRegistered = false;
|
||||
|
@ -43,6 +45,39 @@ public class ApplicationMode {
|
|||
carLocation().parent(CAR).
|
||||
icon(R.drawable.ic_motorcycle, R.drawable.ic_action_motorcycle_light, R.drawable.ic_action_motorcycle_dark).reg();
|
||||
|
||||
static {
|
||||
ApplicationMode[] exceptPedestrian = new ApplicationMode[] { DEFAULT, CAR, BICYCLE, BOAT, AIRCRAFT };
|
||||
ApplicationMode[] exceptAirBoat = new ApplicationMode[] { DEFAULT, CAR, BICYCLE};
|
||||
ApplicationMode[] exceptCarBoatAir = new ApplicationMode[] { DEFAULT, BICYCLE, PEDESTRIAN };
|
||||
ApplicationMode[] pedestrian = new ApplicationMode[] { PEDESTRIAN };
|
||||
|
||||
ApplicationMode[] all = null;
|
||||
ApplicationMode[] none = new ApplicationMode[] {};
|
||||
|
||||
// left
|
||||
regWidget("next_turn", exceptPedestrian);
|
||||
regWidget("next_turn_small", pedestrian);
|
||||
regWidget("next_next_turn", exceptPedestrian);
|
||||
|
||||
// right
|
||||
regWidget("intermediate_distance", all);
|
||||
regWidget("distance", all);
|
||||
regWidget("time", all);
|
||||
regWidget("speed", exceptPedestrian);
|
||||
regWidget("max_speed", exceptAirBoat);
|
||||
regWidget("gps_info", exceptCarBoatAir);
|
||||
regWidget("altitude", exceptCarBoatAir);
|
||||
|
||||
// top
|
||||
regWidget("compass", all);
|
||||
regWidget("config", all);
|
||||
regWidget("street_name", exceptAirBoat);
|
||||
regWidget("back_to_location", all);
|
||||
regWidget("monitoring_services", exceptCarBoatAir);
|
||||
regWidget("bgService", none);
|
||||
regWidget("layers", none);
|
||||
}
|
||||
|
||||
|
||||
private static class ApplicationModeBuilder {
|
||||
|
||||
|
@ -142,23 +177,39 @@ public class ApplicationMode {
|
|||
return values;
|
||||
}
|
||||
|
||||
public static Set<ApplicationMode> allOf() {
|
||||
// TODO
|
||||
return new HashSet<ApplicationMode>(values);
|
||||
|
||||
// returns modifiable ! Set<ApplicationMode> to exclude non-wanted derived
|
||||
public static Set<ApplicationMode> regWidget(String widgetId, ApplicationMode... am) {
|
||||
HashSet<ApplicationMode> set = new HashSet<ApplicationMode>();
|
||||
if(am == null) {
|
||||
set.addAll(values);
|
||||
} else {
|
||||
Collections.addAll(set, am);
|
||||
}
|
||||
for(ApplicationMode m : values) {
|
||||
// add derived modes
|
||||
if(set.contains(m.getParent())) {
|
||||
set.add(m);
|
||||
}
|
||||
}
|
||||
widgets.put(widgetId, set);
|
||||
return set;
|
||||
}
|
||||
|
||||
public static Set<ApplicationMode> noneOf() {
|
||||
// TODO
|
||||
return new HashSet<ApplicationMode>();
|
||||
public boolean isWidgetCollapsible(String key) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Set<ApplicationMode> of(ApplicationMode... modes ) {
|
||||
// TODO
|
||||
HashSet<ApplicationMode> ts = new HashSet<ApplicationMode>();
|
||||
Collections.addAll(ts, modes);
|
||||
return ts;
|
||||
public boolean isWidgetVisible(String key) {
|
||||
Set<ApplicationMode> set = widgets.get(key);
|
||||
if(set == null) {
|
||||
return false;
|
||||
}
|
||||
return set.contains(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static List<ApplicationMode> getModesDerivedFrom(ApplicationMode am) {
|
||||
List<ApplicationMode> list = new ArrayList<ApplicationMode>();
|
||||
for(ApplicationMode a : values) {
|
||||
|
@ -224,4 +275,6 @@ public class ApplicationMode {
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -334,6 +334,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
|
|||
public AudioVideoNotesPlugin(OsmandApplication app) {
|
||||
this.app = app;
|
||||
OsmandSettings settings = app.getSettings();
|
||||
ApplicationMode.regWidget("audionotes", (ApplicationMode[])null);
|
||||
AV_EXTERNAL_RECORDER = settings.registerBooleanPreference("av_external_recorder", false).makeGlobal();
|
||||
AV_EXTERNAL_PHOTO_CAM = settings.registerBooleanPreference("av_external_cam", true).makeGlobal();
|
||||
AV_VIDEO_FORMAT = settings.registerIntPreference("av_video_format", VIDEO_OUTPUT_MP4).makeGlobal();
|
||||
|
@ -467,8 +468,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
|
|||
recordControl.setImageDrawable(activity.getResources().getDrawable(R.drawable.monitoring_rec_inactive));
|
||||
setRecordListener(recordControl, activity);
|
||||
mapInfoLayer.getMapInfoControls().registerSideWidget(recordControl, R.drawable.widget_icon_av_inactive,
|
||||
R.string.map_widget_av_notes, "audionotes", false, ApplicationMode.allOf(),
|
||||
ApplicationMode.noneOf(), 22);
|
||||
R.string.map_widget_av_notes, "audionotes", false, 22);
|
||||
mapInfoLayer.recreateControls();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ public class OsmandDevelopmentPlugin extends OsmandPlugin {
|
|||
|
||||
public OsmandDevelopmentPlugin(OsmandApplication app) {
|
||||
this.app = app;
|
||||
//ApplicationMode.regWidget("fps", new ApplicationMode[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -68,8 +69,7 @@ public class OsmandDevelopmentPlugin extends OsmandPlugin {
|
|||
}
|
||||
};
|
||||
mapInfoLayer.getMapInfoControls().registerSideWidget(fps, 0,
|
||||
R.string.map_widget_fps_info, "fps", false, ApplicationMode.noneOf(),
|
||||
ApplicationMode.noneOf(), 30);
|
||||
R.string.map_widget_fps_info, "fps", false, 30);
|
||||
mapInfoLayer.recreateControls();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,6 +74,7 @@ public class DistanceCalculatorPlugin extends OsmandPlugin {
|
|||
|
||||
public DistanceCalculatorPlugin(OsmandApplication app) {
|
||||
this.app = app;
|
||||
ApplicationMode.regWidget("distance.measurement", ApplicationMode.PEDESTRIAN, ApplicationMode.DEFAULT);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -113,9 +114,7 @@ public class DistanceCalculatorPlugin extends OsmandPlugin {
|
|||
if (mapInfoLayer != null ) {
|
||||
distanceControl = createDistanceControl(activity, mapInfoLayer.getPaintText(), mapInfoLayer.getPaintSubText());
|
||||
mapInfoLayer.getMapInfoControls().registerSideWidget(distanceControl,
|
||||
R.drawable.widget_distance, R.string.map_widget_distancemeasurement, "distance.measurement", false,
|
||||
ApplicationMode.of(ApplicationMode.DEFAULT, ApplicationMode.PEDESTRIAN),
|
||||
ApplicationMode.noneOf(), 21);
|
||||
R.drawable.widget_distance, R.string.map_widget_distancemeasurement, "distance.measurement", false, 21);
|
||||
mapInfoLayer.recreateControls();
|
||||
updateText();
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package net.osmand.plus.monitoring;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.ContextMenuAdapter;
|
||||
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
|
||||
|
@ -41,6 +39,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin implements MonitoringIn
|
|||
|
||||
public OsmandMonitoringPlugin(OsmandApplication app) {
|
||||
this.app = app;
|
||||
ApplicationMode.regWidget("monitoring", ApplicationMode.DEFAULT, ApplicationMode.BICYCLE, ApplicationMode.PEDESTRIAN);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -70,8 +69,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin implements MonitoringIn
|
|||
monitoringControl = createMonitoringControl(activity, layer.getPaintText(), layer.getPaintSubText());
|
||||
|
||||
layer.getMapInfoControls().registerSideWidget(monitoringControl,
|
||||
R.drawable.monitoring_rec_big, R.string.map_widget_monitoring, "monitoring", false,
|
||||
ApplicationMode.of(ApplicationMode.BICYCLE, ApplicationMode.PEDESTRIAN), ApplicationMode.noneOf(), 18);
|
||||
R.drawable.monitoring_rec_big, R.string.map_widget_monitoring, "monitoring", false, 18);
|
||||
layer.recreateControls();
|
||||
}
|
||||
|
||||
|
|
|
@ -65,6 +65,7 @@ public class ParkingPositionPlugin extends OsmandPlugin {
|
|||
public ParkingPositionPlugin(OsmandApplication app) {
|
||||
this.app = app;
|
||||
OsmandSettings set = app.getSettings();
|
||||
ApplicationMode. regWidget("parking", (ApplicationMode[]) null);
|
||||
parkingLat = set.registerFloatPreference(PARKING_POINT_LAT, 0f).makeGlobal();
|
||||
parkingLon = set.registerFloatPreference(PARKING_POINT_LON, 0f).makeGlobal();
|
||||
parkingType = set.registerBooleanPreference(PARKING_TYPE, false).makeGlobal();
|
||||
|
@ -190,8 +191,7 @@ public class ParkingPositionPlugin extends OsmandPlugin {
|
|||
if (mapInfoLayer != null) {
|
||||
parkingPlaceControl = createParkingPlaceInfoControl(activity, mapInfoLayer.getPaintText(), mapInfoLayer.getPaintSubText());
|
||||
mapInfoLayer.getMapInfoControls().registerSideWidget(parkingPlaceControl,
|
||||
R.drawable.widget_parking, R.string.map_widget_parking, "parking", false,
|
||||
ApplicationMode.allOf(), ApplicationMode.noneOf(), 8);
|
||||
R.drawable.widget_parking, R.string.map_widget_parking, "parking", false, 8);
|
||||
mapInfoLayer.recreateControls();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -170,57 +170,54 @@ public class MapInfoLayer extends OsmandMapLayer {
|
|||
|
||||
alarmControl = ric.createAlarmInfoControl(app, map);
|
||||
// register right stack
|
||||
Set<ApplicationMode> all = ApplicationMode.allOf();
|
||||
Set<ApplicationMode> carBicycleDefault = ApplicationMode.of(ApplicationMode.CAR, ApplicationMode.DEFAULT, ApplicationMode.BICYCLE);
|
||||
Set<ApplicationMode> exceptCar = ApplicationMode.of(ApplicationMode.BICYCLE, ApplicationMode.PEDESTRIAN, ApplicationMode.DEFAULT);
|
||||
Set<ApplicationMode> none = ApplicationMode.noneOf();
|
||||
|
||||
RoutingHelper routingHelper = app.getRoutingHelper();
|
||||
NextTurnInfoWidget bigInfoControl = ric.createNextInfoControl(routingHelper, app, view.getSettings(), paintText,
|
||||
paintSubText, false);
|
||||
mapInfoControls.registerSideWidget(bigInfoControl, R.drawable.widget_next_turn, R.string.map_widget_next_turn,"next_turn", true, carBicycleDefault, none, 5);
|
||||
mapInfoControls.registerSideWidget(bigInfoControl, R.drawable.widget_next_turn, R.string.map_widget_next_turn,"next_turn", true, 5);
|
||||
NextTurnInfoWidget smallInfoControl = ric.createNextInfoControl(routingHelper, app, view.getSettings(),
|
||||
paintSmallText, paintSmallSubText, true);
|
||||
mapInfoControls.registerSideWidget(smallInfoControl, R.drawable.widget_next_turn, R.string.map_widget_next_turn_small, "next_turn_small", true,
|
||||
ApplicationMode.of(ApplicationMode.PEDESTRIAN), none, 10);
|
||||
10);
|
||||
NextTurnInfoWidget nextNextInfoControl = ric.createNextNextInfoControl(routingHelper, app, view.getSettings(),
|
||||
paintSmallText, paintSmallSubText, true);
|
||||
mapInfoControls.registerSideWidget(nextNextInfoControl, R.drawable.widget_next_turn, R.string.map_widget_next_next_turn, "next_next_turn",true, carBicycleDefault, none, 15);
|
||||
mapInfoControls.registerSideWidget(nextNextInfoControl, R.drawable.widget_next_turn, R.string.map_widget_next_next_turn, "next_next_turn",true, 15);
|
||||
//MiniMapControl miniMap = ric.createMiniMapControl(routingHelper, view);
|
||||
//mapInfoControls.registerSideWidget(miniMap, R.drawable.widget_next_turn, R.string.map_widget_mini_route, "mini_route", true, none, none, 20);
|
||||
// right stack
|
||||
TextInfoWidget intermediateDist = ric.createIntermediateDistanceControl(map, paintText, paintSubText);
|
||||
mapInfoControls.registerSideWidget(intermediateDist, R.drawable.widget_intermediate, R.string.map_widget_intermediate_distance, "intermediate_distance", false, all, none, 3);
|
||||
mapInfoControls.registerSideWidget(intermediateDist, R.drawable.widget_intermediate, R.string.map_widget_intermediate_distance, "intermediate_distance", false, 3);
|
||||
TextInfoWidget dist = ric.createDistanceControl(map, paintText, paintSubText);
|
||||
mapInfoControls.registerSideWidget(dist, R.drawable.widget_target, R.string.map_widget_distance, "distance", false, all, none, 5);
|
||||
mapInfoControls.registerSideWidget(dist, R.drawable.widget_target, R.string.map_widget_distance, "distance", false, 5);
|
||||
TextInfoWidget time = ric.createTimeControl(map, paintText, paintSubText);
|
||||
mapInfoControls.registerSideWidget(time, R.drawable.widget_time, R.string.map_widget_time, "time",false, all, none, 10);
|
||||
mapInfoControls.registerSideWidget(time, R.drawable.widget_time, R.string.map_widget_time, "time",false, 10);
|
||||
TextInfoWidget speed = ric.createSpeedControl(map, paintText, paintSubText);
|
||||
mapInfoControls.registerSideWidget(speed, R.drawable.widget_speed, R.string.map_widget_speed, "speed", false, carBicycleDefault, none, 15);
|
||||
mapInfoControls.registerSideWidget(speed, R.drawable.widget_speed, R.string.map_widget_speed, "speed", false, 15);
|
||||
TextInfoWidget gpsInfo = mic.createGPSInfoControl(map, paintText, paintSubText);
|
||||
mapInfoControls.registerSideWidget(gpsInfo, R.drawable.widget_gps_info, R.string.map_widget_gps_info, "gps_info", false, exceptCar, none, 17);
|
||||
mapInfoControls.registerSideWidget(gpsInfo, R.drawable.widget_gps_info, R.string.map_widget_gps_info, "gps_info", false, 17);
|
||||
TextInfoWidget maxspeed = ric.createMaxSpeedControl(map, paintText, paintSubText);
|
||||
mapInfoControls.registerSideWidget(maxspeed, R.drawable.widget_max_speed, R.string.map_widget_max_speed, "max_speed", false, carBicycleDefault, none, 18);
|
||||
mapInfoControls.registerSideWidget(maxspeed, R.drawable.widget_max_speed, R.string.map_widget_max_speed, "max_speed", false, 18);
|
||||
TextInfoWidget alt = mic.createAltitudeControl(map, paintText, paintSubText);
|
||||
mapInfoControls.registerSideWidget(alt, R.drawable.widget_altitude, R.string.map_widget_altitude, "altitude", false, exceptCar, none, 20);
|
||||
mapInfoControls.registerSideWidget(alt, R.drawable.widget_altitude, R.string.map_widget_altitude, "altitude", false, 20);
|
||||
|
||||
// Top widgets
|
||||
ImageViewWidget compassView = mic.createCompassView(map);
|
||||
mapInfoControls.registerTopWidget(compassView, R.drawable.widget_compass, R.string.map_widget_compass, "compass", MapWidgetRegistry.LEFT_CONTROL, all, 5);
|
||||
mapInfoControls.registerTopWidget(compassView, R.drawable.widget_compass, R.string.map_widget_compass, "compass", MapWidgetRegistry.LEFT_CONTROL, 5);
|
||||
View config = createConfiguration();
|
||||
mapInfoControls.registerTopWidget(config, R.drawable.widget_config, R.string.map_widget_config, "config", MapWidgetRegistry.RIGHT_CONTROL, all, 10).required(ApplicationMode.DEFAULT);
|
||||
mapInfoControls.registerTopWidget(config, R.drawable.widget_config, R.string.map_widget_config, "config", MapWidgetRegistry.RIGHT_CONTROL, 10).required(ApplicationMode.DEFAULT);
|
||||
mapInfoControls.registerTopWidget(monitoringServices.createMonitoringWidget(view, map), R.drawable.widget_monitoring, R.string.map_widget_monitoring_services,
|
||||
"monitoring_services", MapWidgetRegistry.LEFT_CONTROL, exceptCar, 12);
|
||||
"monitoring_services", MapWidgetRegistry.LEFT_CONTROL, 12);
|
||||
mapInfoControls.registerTopWidget(mic.createLockInfo(map), R.drawable.widget_lock_screen, R.string.bg_service_screen_lock, "bgService",
|
||||
MapWidgetRegistry.LEFT_CONTROL, none, 15);
|
||||
MapWidgetRegistry.LEFT_CONTROL, 15);
|
||||
backToLocation = mic.createBackToLocation(map);
|
||||
mapInfoControls.registerTopWidget(backToLocation, R.drawable.widget_backtolocation, R.string.map_widget_back_to_loc, "back_to_location", MapWidgetRegistry.RIGHT_CONTROL, all, 5);
|
||||
mapInfoControls.registerTopWidget(backToLocation, R.drawable.widget_backtolocation, R.string.map_widget_back_to_loc, "back_to_location", MapWidgetRegistry.RIGHT_CONTROL, 5);
|
||||
|
||||
View globus = createLayer();
|
||||
mapInfoControls.registerTopWidget(globus, R.drawable.widget_layer, R.string.menu_layers, "progress", MapWidgetRegistry.RIGHT_CONTROL, none, 15);
|
||||
mapInfoControls.registerTopWidget(globus, R.drawable.widget_layer, R.string.menu_layers, "layers", MapWidgetRegistry.RIGHT_CONTROL, 15);
|
||||
|
||||
topText = mic.createStreetView(app, map, paintText);
|
||||
mapInfoControls.registerTopWidget(topText, R.drawable.street_name, R.string.map_widget_top_text,
|
||||
"street_name", MapWidgetRegistry.MAIN_CONTROL, all, 100);
|
||||
"street_name", MapWidgetRegistry.MAIN_CONTROL, 100);
|
||||
|
||||
// Register appearance widgets
|
||||
AppearanceWidgetsFactory.INSTANCE.registerAppearanceWidgets(map, this, mapInfoControls);
|
||||
|
@ -330,7 +327,6 @@ public class MapInfoLayer extends OsmandMapLayer {
|
|||
final OsmandSettings settings = view.getSettings();
|
||||
|
||||
final ArrayList<Object> list = new ArrayList<Object>();
|
||||
String appMode = settings.getApplicationMode().toHumanString(view.getApplication());
|
||||
list.add(map.getString(R.string.map_widget_reset));
|
||||
list.add(map.getString(R.string.map_widget_top_stack));
|
||||
list.addAll(mapInfoControls.getTop());
|
||||
|
|
|
@ -24,6 +24,7 @@ public class AppearanceWidgetsFactory {
|
|||
public static AppearanceWidgetsFactory INSTANCE = new AppearanceWidgetsFactory();
|
||||
private String ADDITIONAL_VECTOR_RENDERING_CATEGORY;
|
||||
public static boolean EXTRA_SETTINGS = true;
|
||||
public static boolean POSITION_ON_THE_MAP = false;
|
||||
|
||||
|
||||
public void registerAppearanceWidgets(final MapActivity map, final MapInfoLayer mapInfoLayer,
|
||||
|
@ -42,8 +43,6 @@ public class AppearanceWidgetsFactory {
|
|||
});
|
||||
|
||||
if (EXTRA_SETTINGS) {
|
||||
// previous extra settings
|
||||
|
||||
final MapWidgetRegistry.MapWidgetRegInfo showRuler = mapInfoControls.registerAppearanceWidget(R.drawable.widget_ruler, R.string.map_widget_show_ruler,
|
||||
"showRuler", view.getSettings().SHOW_RULER);
|
||||
showRuler.setStateChangeListener(new Runnable() {
|
||||
|
@ -74,28 +73,32 @@ public class AppearanceWidgetsFactory {
|
|||
}
|
||||
});
|
||||
|
||||
// final OsmandSettings.OsmandPreference<Integer> posPref = view.getSettings().POSITION_ON_MAP;
|
||||
// final MapWidgetRegistry.MapWidgetRegInfo posMap = mapInfoControls.registerAppearanceWidget(R.drawable.widget_position_marker, R.string.position_on_map,
|
||||
// "position_on_map", textSizePref);
|
||||
// posMap.setStateChangeListener(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// String[] entries = new String[] {map.getString(R.string.position_on_map_center), map.getString(R.string.position_on_map_bottom) };
|
||||
// final Integer[] vals = new Integer[] { OsmandSettings.CENTER_CONSTANT, OsmandSettings.BOTTOM_CONSTANT };
|
||||
// AlertDialog.Builder b = new AlertDialog.Builder(view.getContext());
|
||||
// int i = Arrays.binarySearch(vals, posPref.get());
|
||||
// b.setSingleChoiceItems(entries, i, new DialogInterface.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(DialogInterface dialog, int which) {
|
||||
// posPref.set(vals[which]);
|
||||
// map.updateApplicationModeSettings();
|
||||
// view.refreshMap(true);
|
||||
// dialog.dismiss();
|
||||
// }
|
||||
// });
|
||||
// b.show();
|
||||
// }
|
||||
// });
|
||||
if (POSITION_ON_THE_MAP) {
|
||||
final OsmandSettings.OsmandPreference<Integer> posPref = view.getSettings().POSITION_ON_MAP;
|
||||
final MapWidgetRegistry.MapWidgetRegInfo posMap = mapInfoControls.registerAppearanceWidget(
|
||||
R.drawable.widget_position_marker, R.string.position_on_map, "position_on_map", posPref);
|
||||
posMap.setStateChangeListener(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String[] entries = new String[] { map.getString(R.string.position_on_map_center),
|
||||
map.getString(R.string.position_on_map_bottom) };
|
||||
final Integer[] vals = new Integer[] { OsmandSettings.CENTER_CONSTANT,
|
||||
OsmandSettings.BOTTOM_CONSTANT };
|
||||
AlertDialog.Builder b = new AlertDialog.Builder(view.getContext());
|
||||
int i = Arrays.binarySearch(vals, posPref.get());
|
||||
b.setSingleChoiceItems(entries, i, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
posPref.set(vals[which]);
|
||||
map.updateApplicationModeSettings();
|
||||
view.refreshMap(true);
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
b.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -164,34 +167,6 @@ public class AppearanceWidgetsFactory {
|
|||
bld.show();
|
||||
}
|
||||
});
|
||||
|
||||
/*final OsmandSettings.OsmandPreference<Float> textSizePref = view.getSettings().MAP_TEXT_SIZE;
|
||||
final MapWidgetRegistry.MapWidgetRegInfo textSize = mapInfoControls.registerAppearanceWidget(R.drawable.widget_text_size, R.string.map_text_size,
|
||||
"text_size", textSizePref, map.getString(R.string.map_widget_map_rendering));
|
||||
textSize.setStateChangeListener(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final Float[] floatValues = new Float[] {0.6f, 0.8f, 1.0f, 1.2f, 1.5f, 1.75f, 2f};
|
||||
String[] entries = new String[floatValues.length];
|
||||
for (int i = 0; i < floatValues.length; i++) {
|
||||
entries[i] = (int) (floatValues[i] * 100) +" %";
|
||||
}
|
||||
AlertDialog.Builder b = new AlertDialog.Builder(view.getContext());
|
||||
b.setTitle(R.string.map_text_size);
|
||||
int i = Arrays.binarySearch(floatValues, textSizePref.get());
|
||||
b.setSingleChoiceItems(entries, i, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
textSizePref.set(floatValues[which]);
|
||||
app.getResourceManager().getRenderer().clearCache();
|
||||
view.refreshMap(true);
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
b.show();
|
||||
}
|
||||
});*/
|
||||
|
||||
RenderingRulesStorage renderer = app.getRendererRegistry().getCurrentSelectedRenderer();
|
||||
if(renderer != null && EXTRA_SETTINGS) {
|
||||
createCustomRenderingProperties(renderer, map, mapInfoLayer, mapInfoControls);
|
||||
|
|
|
@ -42,7 +42,7 @@ public class MapWidgetRegistry {
|
|||
return cmp;
|
||||
}
|
||||
});
|
||||
private Map<ApplicationMode, Set<String>> visibleElements = new LinkedHashMap<ApplicationMode, Set<String>>();
|
||||
private Map<ApplicationMode, Set<String>> visibleElementsFromSettings = new LinkedHashMap<ApplicationMode, Set<String>>();
|
||||
private final OsmandSettings settings;
|
||||
|
||||
|
||||
|
@ -52,10 +52,10 @@ public class MapWidgetRegistry {
|
|||
for(ApplicationMode ms : ApplicationMode.values(settings) ) {
|
||||
String mpf = settings.MAP_INFO_CONTROLS.getModeValue(ms);
|
||||
if(mpf.equals("")) {
|
||||
visibleElements.put(ms, null);
|
||||
visibleElementsFromSettings.put(ms, null);
|
||||
} else {
|
||||
LinkedHashSet<String> set = new LinkedHashSet<String>();
|
||||
visibleElements.put(ms, set);
|
||||
visibleElementsFromSettings.put(ms, set);
|
||||
Collections.addAll(set, mpf.split(";"));
|
||||
}
|
||||
}
|
||||
|
@ -65,11 +65,9 @@ public class MapWidgetRegistry {
|
|||
public MapWidgetRegInfo registerAppearanceWidget(int drawable, int messageId, String key,
|
||||
OsmandPreference<?> pref) {
|
||||
MapWidgetRegInfo ii = new MapWidgetRegInfo();
|
||||
ii.defaultModes = ApplicationMode.noneOf();
|
||||
ii.defaultCollapsible = null;
|
||||
ii.key = key;
|
||||
ii.preference = pref;
|
||||
ii.visibleModes = ApplicationMode.noneOf();
|
||||
ii.visibleModes = new LinkedHashSet<ApplicationMode>();
|
||||
ii.visibleCollapsible = null;
|
||||
ii.drawable = drawable;
|
||||
ii.messageId = messageId;
|
||||
|
@ -89,12 +87,10 @@ public class MapWidgetRegistry {
|
|||
public MapWidgetRegInfo registerAppearanceWidget(int drawable, String message, String key,
|
||||
CommonPreference<?> pref, String subcategory) {
|
||||
MapWidgetRegInfo ii = new MapWidgetRegInfo();
|
||||
ii.defaultModes = ApplicationMode.noneOf();
|
||||
ii.defaultCollapsible = null;
|
||||
ii.key = key;
|
||||
ii.category = subcategory;
|
||||
ii.preference = pref;
|
||||
ii.visibleModes = ApplicationMode.noneOf();
|
||||
ii.visibleModes = new LinkedHashSet<ApplicationMode>();
|
||||
ii.visibleCollapsible = null;
|
||||
ii.drawable = drawable;
|
||||
ii.messageId = message.hashCode();
|
||||
|
@ -103,17 +99,14 @@ public class MapWidgetRegistry {
|
|||
return ii;
|
||||
}
|
||||
|
||||
public MapWidgetRegInfo registerTopWidget(View m, int drawable, int messageId, String key, int left,
|
||||
Set<ApplicationMode> appDefaultModes, int priorityOrder) {
|
||||
public MapWidgetRegInfo registerTopWidget(View m, int drawable, int messageId, String key, int left, int priorityOrder) {
|
||||
MapWidgetRegInfo ii = new MapWidgetRegInfo();
|
||||
ii.defaultModes = new LinkedHashSet<ApplicationMode>(appDefaultModes);
|
||||
ii.defaultCollapsible = null;
|
||||
ii.key = key;
|
||||
ii.visibleModes = ApplicationMode.noneOf();
|
||||
ii.visibleModes = new LinkedHashSet<ApplicationMode>();
|
||||
ii.visibleCollapsible = null;
|
||||
for(ApplicationMode ms : ApplicationMode.values(settings) ) {
|
||||
boolean def = appDefaultModes.contains(ms);
|
||||
Set<String> set = visibleElements.get(ms);
|
||||
boolean def = ms.isWidgetVisible(key);
|
||||
Set<String> set = visibleElementsFromSettings.get(ms);
|
||||
if (set != null) {
|
||||
if (set.contains(key)) {
|
||||
def = true;
|
||||
|
@ -138,18 +131,15 @@ public class MapWidgetRegistry {
|
|||
|
||||
|
||||
|
||||
public void registerSideWidget(BaseMapWidget m, int drawable, int messageId, String key, boolean left,
|
||||
Set<ApplicationMode> appDefaultModes, Set<ApplicationMode> defaultCollapsible, int priorityOrder) {
|
||||
public void registerSideWidget(BaseMapWidget m, int drawable, int messageId, String key, boolean left, int priorityOrder) {
|
||||
MapWidgetRegInfo ii = new MapWidgetRegInfo();
|
||||
ii.defaultModes = new LinkedHashSet<ApplicationMode>(appDefaultModes);
|
||||
ii.defaultCollapsible = new LinkedHashSet<ApplicationMode>(defaultCollapsible);
|
||||
ii.key = key;
|
||||
ii.visibleModes = ApplicationMode.noneOf();
|
||||
ii.visibleCollapsible = ApplicationMode.noneOf();
|
||||
ii.visibleModes = new LinkedHashSet<ApplicationMode>();
|
||||
ii.visibleCollapsible = new LinkedHashSet<ApplicationMode>();
|
||||
for(ApplicationMode ms : ApplicationMode.values(settings) ) {
|
||||
boolean collapse = defaultCollapsible.contains(ms);;
|
||||
boolean def = appDefaultModes.contains(ms);
|
||||
Set<String> set = visibleElements.get(ms);
|
||||
boolean collapse = ms.isWidgetCollapsible(key);
|
||||
boolean def = ms.isWidgetVisible(key);
|
||||
Set<String> set = visibleElementsFromSettings.get(ms);
|
||||
if(set != null) {
|
||||
if (set.contains(key)) {
|
||||
def = true;
|
||||
|
@ -202,17 +192,17 @@ public class MapWidgetRegistry {
|
|||
boolean visible = m.visible(mode);
|
||||
boolean collapseEnabled = m.collapseEnabled(mode);
|
||||
boolean collapse = m.visibleCollapsed(mode);
|
||||
if (this.visibleElements.get(mode) == null) {
|
||||
if (this.visibleElementsFromSettings.get(mode) == null) {
|
||||
LinkedHashSet<String> set = new LinkedHashSet<String>();
|
||||
restoreModes(set, left, mode);
|
||||
restoreModes(set, right, mode);
|
||||
restoreModes(set, top, mode);
|
||||
this.visibleElements.put(mode, set);
|
||||
this.visibleElementsFromSettings.put(mode, set);
|
||||
}
|
||||
// clear everything
|
||||
this.visibleElements.get(mode).remove(m.key);
|
||||
this.visibleElements.get(mode).remove("+" + m.key);
|
||||
this.visibleElements.get(mode).remove("-" + m.key);
|
||||
this.visibleElementsFromSettings.get(mode).remove(m.key);
|
||||
this.visibleElementsFromSettings.get(mode).remove("+" + m.key);
|
||||
this.visibleElementsFromSettings.get(mode).remove("-" + m.key);
|
||||
m.visibleModes.remove(mode);
|
||||
if (m.visibleCollapsible != null) {
|
||||
m.visibleCollapsible.remove(mode);
|
||||
|
@ -220,16 +210,16 @@ public class MapWidgetRegistry {
|
|||
if (visible || collapse) {
|
||||
if (collapseEnabled && !collapse) {
|
||||
m.visibleCollapsible.add(mode);
|
||||
this.visibleElements.get(mode).add("+" + m.key);
|
||||
this.visibleElementsFromSettings.get(mode).add("+" + m.key);
|
||||
} else {
|
||||
this.visibleElements.get(mode).add("-" + m.key);
|
||||
this.visibleElementsFromSettings.get(mode).add("-" + m.key);
|
||||
}
|
||||
} else {
|
||||
m.visibleModes.add(mode);
|
||||
this.visibleElements.get(mode).add("" + m.key);
|
||||
this.visibleElementsFromSettings.get(mode).add("" + m.key);
|
||||
}
|
||||
StringBuilder bs = new StringBuilder();
|
||||
for (String ks : this.visibleElements.get(mode)) {
|
||||
for (String ks : this.visibleElementsFromSettings.get(mode)) {
|
||||
bs.append(ks).append(";");
|
||||
}
|
||||
settings.MAP_INFO_CONTROLS.set(bs.toString());
|
||||
|
@ -290,11 +280,12 @@ public class MapWidgetRegistry {
|
|||
ri.visibleCollapsible.remove(mode);
|
||||
}
|
||||
ri.visibleModes.remove(mode);
|
||||
if (ri.defaultCollapsible != null && ri.defaultCollapsible.contains(mode)) {
|
||||
ri.visibleCollapsible.add(mode);
|
||||
}
|
||||
if (ri.defaultModes.contains(mode)) {
|
||||
ri.visibleModes.add(mode);
|
||||
if (mode.isWidgetVisible(ri.key)) {
|
||||
if (mode.isWidgetCollapsible(ri.key)) {
|
||||
ri.visibleCollapsible.add(mode);
|
||||
} else {
|
||||
ri.visibleModes.add(mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -306,7 +297,7 @@ public class MapWidgetRegistry {
|
|||
resetDefault(appMode, right);
|
||||
resetDefault(appMode, top);
|
||||
resetDefault(appMode, appearanceWidgets);
|
||||
this.visibleElements.put(appMode, null);
|
||||
this.visibleElementsFromSettings.put(appMode, null);
|
||||
settings.MAP_INFO_CONTROLS.set("");
|
||||
}
|
||||
|
||||
|
@ -326,8 +317,6 @@ public class MapWidgetRegistry {
|
|||
private String key;
|
||||
private int position;
|
||||
private String category;
|
||||
private Set<ApplicationMode> defaultModes;
|
||||
private Set<ApplicationMode> defaultCollapsible;
|
||||
private Set<ApplicationMode> visibleModes;
|
||||
private Set<ApplicationMode> visibleCollapsible;
|
||||
private OsmandPreference<?> preference = null;
|
||||
|
|
Loading…
Reference in a new issue