From 5245e116997bcd00ac677562631e7b13c7d07eee Mon Sep 17 00:00:00 2001 From: vshcherb Date: Fri, 29 Nov 2013 09:47:13 +0100 Subject: [PATCH 1/4] Add modes selection dialog --- OsmAnd/res/values/strings.xml | 2 + .../src/net/osmand/plus/ApplicationMode.java | 51 +++++++++----- .../net/osmand/plus/OsmandBackupAgent.java | 3 +- .../src/net/osmand/plus/OsmandSettings.java | 2 + .../plus/activities/SettingsBaseActivity.java | 2 +- .../activities/actions/NavigateAction.java | 67 +++++++++++-------- .../SettingsDevelopmentActivity.java | 48 +++++++++++++ .../osmand/plus/srtmplugin/SRTMPlugin.java | 2 +- .../net/osmand/plus/views/MapInfoLayer.java | 2 +- 9 files changed, 132 insertions(+), 47 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index bba636dfc8..5e36d65c15 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,8 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Choose available application modes in application + Application Modes Remaining elements: Map rendering: Hiking diff --git a/OsmAnd/src/net/osmand/plus/ApplicationMode.java b/OsmAnd/src/net/osmand/plus/ApplicationMode.java index 2e3442d05b..1d0a124164 100644 --- a/OsmAnd/src/net/osmand/plus/ApplicationMode.java +++ b/OsmAnd/src/net/osmand/plus/ApplicationMode.java @@ -6,11 +6,15 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import net.osmand.StateChangedListener; + import android.content.Context; public class ApplicationMode { private static List values = new ArrayList(); + private static List cachedFilteredValues = new ArrayList(); + private static boolean listenerRegistered = false; /* * DEFAULT("Browse map"), CAR("Car"), BICYCLE("Bicycle"), PEDESTRIAN("Pedestrian"); */ @@ -26,18 +30,18 @@ public class ApplicationMode { public static final ApplicationMode PEDESTRIAN = create(R.string.app_mode_pedestrian, "pedestrian").speed(1.5f, 5). icon(R.drawable.ic_pedestrian, R.drawable.ic_action_pedestrian_light, R.drawable.ic_action_parking_dark).reg(); -// public static final ApplicationMode AIRCRAFT = create(R.string.app_mode_aircraft, "aircraft").speed(40f, 100).carLocation(). -// icon(R.drawable.ic_aircraft, R.drawable.ic_action_aircraft_light, R.drawable.ic_action_aircraft_dark).reg(); -// -// public static final ApplicationMode BOAT = create(R.string.app_mode_boat, "boat").speed(5.5f, 20).carLocation(). -// icon(R.drawable.ic_sail_boat, R.drawable.ic_action_sail_boat_light, R.drawable.ic_action_sail_boat_dark).reg(); -// -// public static final ApplicationMode HIKING = create(R.string.app_mode_hiking, "hiking").speed(1.5f, 5).parent(PEDESTRIAN). -// icon(R.drawable.ic_trekking, R.drawable.ic_action_trekking_light, R.drawable.ic_action_trekking_dark).reg(); -// -// public static final ApplicationMode MOTORCYCLE = create(R.string.app_mode_motorcycle, "motorcycle").speed(15.3f, 40). -// carLocation().parent(CAR). -// icon(R.drawable.ic_motorcycle, R.drawable.ic_action_motorcycle_light, R.drawable.ic_action_motorcycle_dark).reg(); + public static final ApplicationMode AIRCRAFT = create(R.string.app_mode_aircraft, "aircraft").speed(40f, 100).carLocation(). + icon(R.drawable.ic_aircraft, R.drawable.ic_action_aircraft_light, R.drawable.ic_action_aircraft_dark).reg(); + + public static final ApplicationMode BOAT = create(R.string.app_mode_boat, "boat").speed(5.5f, 20).carLocation(). + icon(R.drawable.ic_sail_boat, R.drawable.ic_action_sail_boat_light, R.drawable.ic_action_sail_boat_dark).reg(); + + public static final ApplicationMode HIKING = create(R.string.app_mode_hiking, "hiking").speed(1.5f, 5).parent(PEDESTRIAN). + icon(R.drawable.ic_trekking, R.drawable.ic_action_trekking_light, R.drawable.ic_action_trekking_dark).reg(); + + public static final ApplicationMode MOTORCYCLE = create(R.string.app_mode_motorcycle, "motorcycle").speed(15.3f, 40). + carLocation().parent(CAR). + icon(R.drawable.ic_motorcycle, R.drawable.ic_action_motorcycle_light, R.drawable.ic_action_motorcycle_dark).reg(); private static class ApplicationModeBuilder { @@ -113,11 +117,28 @@ public class ApplicationMode { } public static List values(OsmandSettings settings) { - // TODO - return values; + if (cachedFilteredValues.isEmpty()) { + if (!listenerRegistered) { + settings.AVAILABLE_APP_MODES.addListener(new StateChangedListener() { + @Override + public void stateChanged(String change) { + cachedFilteredValues = new ArrayList(); + } + }); + listenerRegistered = true; + } + String available = settings.AVAILABLE_APP_MODES.get(); + cachedFilteredValues = new ArrayList(); + for (ApplicationMode v : values) { + if (available.indexOf(v.getStringKey() + ",") != -1 || v == DEFAULT) { + cachedFilteredValues.add(v); + } + } + } + return cachedFilteredValues; } - public static List allPossibleValues(ClientContext ctx) { + public static List allPossibleValues(OsmandSettings settings) { return values; } diff --git a/OsmAnd/src/net/osmand/plus/OsmandBackupAgent.java b/OsmAnd/src/net/osmand/plus/OsmandBackupAgent.java index cad5f652ce..e181892db8 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandBackupAgent.java +++ b/OsmAnd/src/net/osmand/plus/OsmandBackupAgent.java @@ -13,7 +13,8 @@ public class OsmandBackupAgent extends BackupAgentHelper { @Override public void onCreate() { - List all = ApplicationMode.allPossibleValues((OsmandApplication) getApplicationContext()); + OsmandApplication app = (OsmandApplication) getApplicationContext(); + List all = ApplicationMode.allPossibleValues(app.getSettings()); String[] prefs = new String[all.size() + 1]; prefs[0] = OsmandSettings.getSharedPreferencesName(null); int i = 1; diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index a163179890..38feb9a86a 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -570,6 +570,8 @@ public class OsmandSettings { // this value string is synchronized with settings_pref.xml preference name public final CommonPreference USE_INTERNET_TO_DOWNLOAD_TILES = new BooleanPreference("use_internet_to_download_tiles", true).makeGlobal().cache(); + public final OsmandPreference AVAILABLE_APP_MODES = new StringPreference("available_application_modes", "car,bicycle,pedestrian,").makeGlobal().cache(); + public final OsmandPreference DEFAULT_APPLICATION_MODE = new CommonPreference("default_application_mode", ApplicationMode.DEFAULT) { @Override diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsBaseActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsBaseActivity.java index b8228572e5..f7f95bf142 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsBaseActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsBaseActivity.java @@ -306,7 +306,7 @@ public abstract class SettingsBaseActivity extends SherlockPreferenceActivity im protected void profileDialog() { Builder b = new AlertDialog.Builder(this); final Set selected = new LinkedHashSet(); - View v = NavigateAction.prepareAppModeView(this, selected, false, null, + View v = NavigateAction.prepareAppModeView(this, selected, false, null, false, new View.OnClickListener() { @Override public void onClick(View v) { diff --git a/OsmAnd/src/net/osmand/plus/activities/actions/NavigateAction.java b/OsmAnd/src/net/osmand/plus/activities/actions/NavigateAction.java index 3600e47e6a..845992e274 100644 --- a/OsmAnd/src/net/osmand/plus/activities/actions/NavigateAction.java +++ b/OsmAnd/src/net/osmand/plus/activities/actions/NavigateAction.java @@ -360,52 +360,63 @@ public class NavigateAction { public static View prepareAppModeView(Activity a, final Set selected, boolean showDefault, - ViewGroup parent, final View.OnClickListener onClickListener) { - LinearLayout ll = (LinearLayout) a.getLayoutInflater().inflate(R.layout.mode_toggles, parent); + ViewGroup parent, final boolean singleSelection, final View.OnClickListener onClickListener) { OsmandSettings settings = ((OsmandApplication) a.getApplication()).getSettings(); final List values = new ArrayList(ApplicationMode.values(settings)); if(!showDefault) { values.remove(ApplicationMode.DEFAULT); } + selected.add(settings.getApplicationMode()); + return prepareAppModeView(a, values, selected, parent, singleSelection, onClickListener); + + } + + public static View prepareAppModeView(Activity a, final List values , final Set selected, + ViewGroup parent, final boolean singleSelection, final View.OnClickListener onClickListener) { + LinearLayout ll = (LinearLayout) a.getLayoutInflater().inflate(R.layout.mode_toggles, parent); final ToggleButton[] buttons = createToggles(values, ll, a); - ApplicationMode appMode = settings.getApplicationMode(); for (int i = 0; i < buttons.length; i++) { if (buttons[i] != null) { final int ind = i; ToggleButton b = buttons[i]; final ApplicationMode buttonAppMode = values.get(i); - b.setChecked(appMode == buttonAppMode); - if(appMode == buttonAppMode) { - selected.add(appMode); - } + b.setChecked(selected.contains(buttonAppMode)); b.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (isChecked) { - selected.clear(); - for (int j = 0; j < buttons.length; j++) { - if (buttons[j] != null) { - if(ind == j) { - selected.add(values.get(j)); + if (!singleSelection) { + if (isChecked) { + selected.clear(); + for (int j = 0; j < buttons.length; j++) { + if (buttons[j] != null) { + if (ind == j) { + selected.add(values.get(j)); + } + if (buttons[j].isChecked() != (ind == j)) { + buttons[j].setChecked(ind == j); + } } - if (buttons[j].isChecked() != (ind == j)) { - buttons[j].setChecked(ind == j); + } + } else { + // revert state + boolean revert = true; + for (int j = 0; j < buttons.length; j++) { + if (buttons[j] != null) { + if (buttons[j].isChecked()) { + revert = false; + break; + } } } + if (revert) { + buttons[ind].setChecked(true); + } } } else { - // revert state - boolean revert = true; - for (int j = 0; j < buttons.length; j++) { - if (buttons[j] != null) { - if (buttons[j].isChecked()) { - revert = false; - break; - } - } - } - if (revert) { - buttons[ind].setChecked(true); + if (isChecked) { + selected.add(buttonAppMode); + } else { + selected.remove(buttonAppMode); } } if(onClickListener != null) { @@ -482,7 +493,7 @@ public class NavigateAction { return mapActivity.getString(resId); } - private ApplicationMode getAppMode(ToggleButton[] buttons, OsmandSettings settings, List modes){ + private static ApplicationMode getAppMode(ToggleButton[] buttons, OsmandSettings settings, List modes){ for (int i = 0; i < buttons.length; i++) { if (buttons[i] != null && buttons[i].isChecked() && i < modes.size()) { return modes.get(i); diff --git a/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java b/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java index 70eeb8f55f..df6aa99ebf 100644 --- a/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java +++ b/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java @@ -2,10 +2,17 @@ package net.osmand.plus.development; import java.text.SimpleDateFormat; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; +import net.osmand.plus.ApplicationMode; import net.osmand.plus.R; import net.osmand.plus.activities.SettingsBaseActivity; +import net.osmand.plus.activities.actions.NavigateAction; import net.osmand.util.SunriseSunset; +import android.app.AlertDialog; +import android.app.AlertDialog.Builder; import android.content.Intent; import android.os.Bundle; import android.os.Debug; @@ -14,10 +21,12 @@ import android.preference.CheckBoxPreference; import android.preference.Preference; import android.preference.Preference.OnPreferenceClickListener; import android.preference.PreferenceScreen; +import android.view.View; public class SettingsDevelopmentActivity extends SettingsBaseActivity { + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -43,6 +52,19 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity { }); cat.addPreference(pref); + pref = new Preference(this); + pref.setTitle(R.string.app_modes_choose); + pref.setSummary(R.string.app_modes_choose_descr); + pref.setKey("available_application_modes"); + pref.setOnPreferenceClickListener(new OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + availableProfileDialog(); + return true; + } + }); + cat.addPreference(pref); + pref = new Preference(this); pref.setTitle(R.string.global_app_allocated_memory); @@ -79,6 +101,32 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity { } cat.addPreference(pref); } + + protected void availableProfileDialog() { + Builder b = new AlertDialog.Builder(this); + final List modes = ApplicationMode.allPossibleValues(settings); + modes.remove(ApplicationMode.DEFAULT); + final Set selected = new LinkedHashSet(ApplicationMode.values(settings)); + selected.remove(ApplicationMode.DEFAULT); + View v = NavigateAction.prepareAppModeView(this, modes, selected, null, false, + new View.OnClickListener() { + + @Override + public void onClick(View v) { + StringBuilder vls = new StringBuilder(); + for(ApplicationMode mode : modes) { + if(selected.contains(mode)) { + vls.append(mode.getStringKey()+","); + } + } + settings.AVAILABLE_APP_MODES.set(vls.toString()); + } + }); + b.setTitle(R.string.profile_settings); + b.setPositiveButton(R.string.default_buttons_ok, null); + b.setView(v); + b.show(); + } diff --git a/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java b/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java index 2860603ab8..c74a7c1035 100644 --- a/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java +++ b/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java @@ -32,7 +32,7 @@ public class SRTMPlugin extends OsmandPlugin { OsmandSettings settings = app.getSettings(); CommonPreference pref = settings.getCustomRenderProperty("contourLines"); if(pref.get().equals("")) { - for(ApplicationMode m : ApplicationMode.allPossibleValues(app)) { + for(ApplicationMode m : ApplicationMode.allPossibleValues(settings)) { if(pref.getModeValue(m).equals("")) { pref.setModeValue(m, "13"); } diff --git a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java index 43a59b7bb5..3df4e01dbd 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java @@ -423,7 +423,7 @@ public class MapInfoLayer extends OsmandMapLayer { View confirmDialog = view.inflate(view.getContext(), R.layout.configuration_dialog, null); final ListView lv = (ListView) confirmDialog.findViewById(android.R.id.list); NavigateAction.prepareAppModeView(map, selected, true, - (ViewGroup) confirmDialog.findViewById(R.id.TopBar), + (ViewGroup) confirmDialog.findViewById(R.id.TopBar), false, new View.OnClickListener() { @Override public void onClick(View v) { From f741c047555536f32e27a579831a4f9fe2b95daa Mon Sep 17 00:00:00 2001 From: vshcherb Date: Fri, 29 Nov 2013 23:37:19 +0100 Subject: [PATCH 2/4] Unify how widgets registry works --- .../src/net/osmand/plus/ApplicationMode.java | 77 +++++++++++++++--- .../audionotes/AudioVideoNotesPlugin.java | 4 +- .../development/OsmandDevelopmentPlugin.java | 4 +- .../DistanceCalculatorPlugin.java | 5 +- .../monitoring/OsmandMonitoringPlugin.java | 6 +- .../parkingpoint/ParkingPositionPlugin.java | 4 +- .../net/osmand/plus/views/MapInfoLayer.java | 40 +++++----- .../mapwidgets/AppearanceWidgetsFactory.java | 79 +++++++------------ .../views/mapwidgets/MapWidgetRegistry.java | 73 ++++++++--------- 9 files changed, 151 insertions(+), 141 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/ApplicationMode.java b/OsmAnd/src/net/osmand/plus/ApplicationMode.java index 1d0a124164..4029c00df6 100644 --- a/OsmAnd/src/net/osmand/plus/ApplicationMode.java +++ b/OsmAnd/src/net/osmand/plus/ApplicationMode.java @@ -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> widgets = new LinkedHashMap>(); private static List values = new ArrayList(); private static List cachedFilteredValues = new ArrayList(); 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 allOf() { - // TODO - return new HashSet(values); + + // returns modifiable ! Set to exclude non-wanted derived + public static Set regWidget(String widgetId, ApplicationMode... am) { + HashSet set = new HashSet(); + 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 noneOf() { - // TODO - return new HashSet(); + public boolean isWidgetCollapsible(String key) { + return false; } - public static Set of(ApplicationMode... modes ) { - // TODO - HashSet ts = new HashSet(); - Collections.addAll(ts, modes); - return ts; + public boolean isWidgetVisible(String key) { + Set set = widgets.get(key); + if(set == null) { + return false; + } + return set.contains(this); } + + public static List getModesDerivedFrom(ApplicationMode am) { List list = new ArrayList(); for(ApplicationMode a : values) { @@ -224,4 +275,6 @@ public class ApplicationMode { + + } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java index f4bbfb5a07..5ff1569c11 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java @@ -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(); } } diff --git a/OsmAnd/src/net/osmand/plus/development/OsmandDevelopmentPlugin.java b/OsmAnd/src/net/osmand/plus/development/OsmandDevelopmentPlugin.java index 79c37cfe29..e053a5f08c 100644 --- a/OsmAnd/src/net/osmand/plus/development/OsmandDevelopmentPlugin.java +++ b/OsmAnd/src/net/osmand/plus/development/OsmandDevelopmentPlugin.java @@ -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(); } } diff --git a/OsmAnd/src/net/osmand/plus/distancecalculator/DistanceCalculatorPlugin.java b/OsmAnd/src/net/osmand/plus/distancecalculator/DistanceCalculatorPlugin.java index db0a06ff03..3daed79fef 100644 --- a/OsmAnd/src/net/osmand/plus/distancecalculator/DistanceCalculatorPlugin.java +++ b/OsmAnd/src/net/osmand/plus/distancecalculator/DistanceCalculatorPlugin.java @@ -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(); } diff --git a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java index ace7628829..e1c1ae51de 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java @@ -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(); } diff --git a/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java b/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java index c716397860..7c7b9c5777 100644 --- a/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java +++ b/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java @@ -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(); } } diff --git a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java index 3df4e01dbd..2be5b5db4a 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java @@ -170,57 +170,54 @@ public class MapInfoLayer extends OsmandMapLayer { alarmControl = ric.createAlarmInfoControl(app, map); // register right stack - Set all = ApplicationMode.allOf(); - Set carBicycleDefault = ApplicationMode.of(ApplicationMode.CAR, ApplicationMode.DEFAULT, ApplicationMode.BICYCLE); - Set exceptCar = ApplicationMode.of(ApplicationMode.BICYCLE, ApplicationMode.PEDESTRIAN, ApplicationMode.DEFAULT); - Set 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 list = new ArrayList(); - 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()); diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/AppearanceWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/AppearanceWidgetsFactory.java index 47b45d9552..40a4f8b79f 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/AppearanceWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/AppearanceWidgetsFactory.java @@ -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 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 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 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); diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java index bbb147d94c..8db02dd5ff 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java @@ -42,7 +42,7 @@ public class MapWidgetRegistry { return cmp; } }); - private Map> visibleElements = new LinkedHashMap>(); + private Map> visibleElementsFromSettings = new LinkedHashMap>(); 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 set = new LinkedHashSet(); - 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(); 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(); 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 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(appDefaultModes); - ii.defaultCollapsible = null; ii.key = key; - ii.visibleModes = ApplicationMode.noneOf(); + ii.visibleModes = new LinkedHashSet(); ii.visibleCollapsible = null; for(ApplicationMode ms : ApplicationMode.values(settings) ) { - boolean def = appDefaultModes.contains(ms); - Set set = visibleElements.get(ms); + boolean def = ms.isWidgetVisible(key); + Set 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 appDefaultModes, Set 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(appDefaultModes); - ii.defaultCollapsible = new LinkedHashSet(defaultCollapsible); ii.key = key; - ii.visibleModes = ApplicationMode.noneOf(); - ii.visibleCollapsible = ApplicationMode.noneOf(); + ii.visibleModes = new LinkedHashSet(); + ii.visibleCollapsible = new LinkedHashSet(); for(ApplicationMode ms : ApplicationMode.values(settings) ) { - boolean collapse = defaultCollapsible.contains(ms);; - boolean def = appDefaultModes.contains(ms); - Set set = visibleElements.get(ms); + boolean collapse = ms.isWidgetCollapsible(key); + boolean def = ms.isWidgetVisible(key); + Set 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 set = new LinkedHashSet(); 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 defaultModes; - private Set defaultCollapsible; private Set visibleModes; private Set visibleCollapsible; private OsmandPreference preference = null; From 739d42581b12866ed33379f39c7a764ed53643f6 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Fri, 29 Nov 2013 23:52:40 +0100 Subject: [PATCH 3/4] Update routing providers for new application modes --- .../src/net/osmand/plus/ApplicationMode.java | 8 +++ .../osmand/plus/CurrentPositionHelper.java | 11 +++- .../osmand/plus/routing/RouteProvider.java | 65 +++++++++++++------ .../net/osmand/plus/routing/VoiceRouter.java | 16 ++++- 4 files changed, 73 insertions(+), 27 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/ApplicationMode.java b/OsmAnd/src/net/osmand/plus/ApplicationMode.java index 4029c00df6..e794ec47c3 100644 --- a/OsmAnd/src/net/osmand/plus/ApplicationMode.java +++ b/OsmAnd/src/net/osmand/plus/ApplicationMode.java @@ -256,6 +256,10 @@ public class ApplicationMode { return ctx.getString(key); } + public String toHumanStringCtx(ClientContext ctx) { + return ctx.getString(key); + } + public static ApplicationMode valueOfStringKey(String key, ApplicationMode def) { for(ApplicationMode p : values) { if(p.getStringKey().equals(key)) { @@ -274,6 +278,10 @@ public class ApplicationMode { } + public boolean isDerivedRoutingFrom(ApplicationMode mode) { + return this == mode || getParent() == mode; + } + diff --git a/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java b/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java index 3618e7e5d8..63dc37855b 100644 --- a/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java +++ b/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java @@ -27,12 +27,14 @@ public class CurrentPositionHelper { private void initCtx(ClientContext app) { am = app.getSettings().getApplicationMode(); GeneralRouterProfile p ; - if (am == ApplicationMode.BICYCLE) { + if (am.isDerivedRoutingFrom(ApplicationMode.BICYCLE)) { p = GeneralRouterProfile.BICYCLE; - } else if (am == ApplicationMode.PEDESTRIAN) { + } else if (am.isDerivedRoutingFrom(ApplicationMode.PEDESTRIAN)) { p = GeneralRouterProfile.PEDESTRIAN; - } else { + } else if (am.isDerivedRoutingFrom(ApplicationMode.CAR)) { p = GeneralRouterProfile.CAR; + } else { + return; } RoutingConfiguration cfg = RoutingConfiguration.getDefault().build(p.name().toLowerCase(), 10); ctx = new RoutingContext(cfg, null, app.getTodoAPI().getRoutingMapFiles()); @@ -43,6 +45,9 @@ public class CurrentPositionHelper { try { if(ctx == null || am != app.getSettings().getApplicationMode()) { initCtx(app); + if(ctx == null) { + return null; + } } RouteSegment sg = rp.findRouteSegment(loc.getLatitude(), loc.getLongitude(), ctx); if(sg == null) { diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java index 99d960c532..dc826b1d37 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java @@ -282,12 +282,14 @@ public class RouteProvider { uri.append("&flon=").append(params.start.getLongitude()); //$NON-NLS-1$ uri.append("&tlat=").append(params.end.getLatitude()); //$NON-NLS-1$ uri.append("&tlon=").append(params.end.getLongitude()); //$NON-NLS-1$ - if(ApplicationMode.PEDESTRIAN == params.mode){ - uri.append("&v=foot") ; //$NON-NLS-1$ - } else if(ApplicationMode.BICYCLE == params.mode){ + if (params.mode.isDerivedRoutingFrom(ApplicationMode.BICYCLE)) { uri.append("&v=bicycle") ; //$NON-NLS-1$ - } else { + } else if (params.mode.isDerivedRoutingFrom(ApplicationMode.PEDESTRIAN)) { + uri.append("&v=foot") ; //$NON-NLS-1$ + } else if(params.mode.isDerivedRoutingFrom(ApplicationMode.CAR)){ uri.append("&v=motorcar"); //$NON-NLS-1$ + } else { + return applicationModeNotSupported(params); } uri.append("&fast=").append(params.fast ? "1" : "0").append("&layer=mapnik"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ log.info("URL route " + uri); @@ -349,12 +351,14 @@ public class RouteProvider { config = RoutingConfiguration.getDefault(); } GeneralRouterProfile p ; - if (params.mode == ApplicationMode.BICYCLE) { + if (params.mode.isDerivedRoutingFrom(ApplicationMode.BICYCLE)) { p = GeneralRouterProfile.BICYCLE; - } else if (params.mode == ApplicationMode.PEDESTRIAN) { + } else if (params.mode.isDerivedRoutingFrom(ApplicationMode.PEDESTRIAN)) { p = GeneralRouterProfile.PEDESTRIAN; - } else { + } else if(params.mode.isDerivedRoutingFrom(ApplicationMode.CAR)){ p = GeneralRouterProfile.CAR; + } else { + return applicationModeNotSupported(params); } // order matters List specs = new ArrayList(); @@ -417,10 +421,10 @@ public class RouteProvider { return new RouteCalculationResult("Route can not be found from end point (" +ctx.calculationProgress.distanceFromEnd/1000f+" km)"); } if(ctx.calculationProgress.isCancelled) { - return new RouteCalculationResult("Route calculation was interrupted"); + return interrupted(); } // something really strange better to see that message on the scren - return new RouteCalculationResult("Empty result"); + return emptyResult(); } else { RouteCalculationResult res = new RouteCalculationResult(result, params.start, params.end, params.intermediates, params.ctx, params.leftSide, ctx.routingTime); @@ -429,7 +433,7 @@ public class RouteProvider { } catch (RuntimeException e) { return new RouteCalculationResult(e.getMessage() ); } catch (InterruptedException e) { - return new RouteCalculationResult("Route calculation was interrupted"); + return interrupted(); } catch (OutOfMemoryError e) { // ActivityManager activityManager = (ActivityManager)app.getSystemService(Context.ACTIVITY_SERVICE); // ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo(); @@ -441,6 +445,21 @@ public class RouteProvider { return new RouteCalculationResult("Not enough process memory "+ s); } } + + + + + private RouteCalculationResult applicationModeNotSupported(RouteCalculationParams params) { + return new RouteCalculationResult("Application mode '"+ params.mode.toHumanStringCtx(params.ctx)+ "'is not supported."); + } + + private RouteCalculationResult interrupted() { + return new RouteCalculationResult("Route calculation was interrupted"); + } + + private RouteCalculationResult emptyResult() { + return new RouteCalculationResult("Empty result"); + } protected RouteCalculationResult findCloudMadeRoute(RouteCalculationParams params) @@ -470,27 +489,27 @@ public class RouteProvider { uri.append(params.end.getLatitude() + "").append(","); //$NON-NLS-1$//$NON-NLS-2$ uri.append(params.end.getLongitude() + "").append("/"); //$NON-NLS-1$ //$NON-NLS-2$ - float speed = 1.5f; - if (ApplicationMode.PEDESTRIAN == params.mode) { + if (params.mode.isDerivedRoutingFrom(ApplicationMode.PEDESTRIAN)) { uri.append("foot.gpx"); //$NON-NLS-1$ - } else if (ApplicationMode.BICYCLE == params.mode) { - speed = 4.2f; + } else if (params.mode.isDerivedRoutingFrom(ApplicationMode.BICYCLE)) { uri.append("bicycle.gpx"); //$NON-NLS-1$ - } else { - speed = 15.3f; + } else if (params.mode.isDerivedRoutingFrom(ApplicationMode.CAR)) { if (params.fast) { uri.append("car.gpx"); //$NON-NLS-1$ } else { uri.append("car/shortest.gpx"); //$NON-NLS-1$ } + } else { + return applicationModeNotSupported(params); } + uri.append("?lang=").append(Locale.getDefault().getLanguage()); //$NON-NLS-1$ log.info("URL route " + uri); URL url = new URL(uri.toString()); URLConnection connection = url.openConnection(); connection.setRequestProperty("User-Agent", Version.getFullVersion(params.ctx)); GPXFile gpxFile = GPXUtilities.loadGPXFile(params.ctx, connection.getInputStream(), false); - directions = parseCloudmadeRoute(res, gpxFile, false, params.leftSide, speed); + directions = parseCloudmadeRoute(res, gpxFile, false, params.leftSide, params.mode.getDefaultSpeed()); return new RouteCalculationResult(res, directions, params, null); } @@ -616,9 +635,9 @@ public class RouteProvider { List res = new ArrayList(); String rpref = "Fastest"; - if (ApplicationMode.PEDESTRIAN == params.mode) { + if (params.mode.isDerivedRoutingFrom(ApplicationMode.PEDESTRIAN)) { rpref = "Pedestrian"; - } else if (ApplicationMode.BICYCLE == params.mode) { + } else if (params.mode.isDerivedRoutingFrom(ApplicationMode.BICYCLE)) { rpref = "Bicycle"; // } else if (ApplicationMode.LOWTRAFFIC == mode) { // rpref = "BicycleSafety"; @@ -628,8 +647,12 @@ public class RouteProvider { // rpref = "BicycleRoute"; // } else if (ApplicationMode.MTBIKE == mode) { // rpref = "BicycleMTB"; - } else if (!params.fast) { - rpref = "Shortest"; + } else if (params.mode.isDerivedRoutingFrom(ApplicationMode.CAR)) { + if (!params.fast) { + rpref = "Shortest"; + } + } else { + return applicationModeNotSupported(params); } StringBuilder request = new StringBuilder(); diff --git a/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java b/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java index 467a214696..fa5a917579 100644 --- a/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java +++ b/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java @@ -104,7 +104,7 @@ public class VoiceRouter { // lead time criterion only for TURN_IN and TURN PREPARE_LONG_DISTANCE = 3500; // [105 sec] - 120 km/h PREPARE_LONG_DISTANCE_END = 3000; // [ 90 sec] - 120 km/h - if(router.getAppMode() == ApplicationMode.PEDESTRIAN){ + if(router.getAppMode().isDerivedRoutingFrom(ApplicationMode.PEDESTRIAN)){ // prepare_long_distance warning not needed for pedestrian PREPARE_LONG_DISTANCE_END = PREPARE_LONG_DISTANCE + 100; // do not play // prepare distance is not needed for pedestrian @@ -116,7 +116,7 @@ public class VoiceRouter { TURN_IN_DISTANCE_END = 30; // 15 sec (was 70m, 35 sec) TURN_DISTANCE = 15; // 7,5sec (was 25m, 12 sec). Check if this works with GPS accuracy! TURN_DEFAULT_SPEED = DEFAULT_SPEED = 2f; // 7,2 km/h - } else if(router.getAppMode() == ApplicationMode.BICYCLE){ + } else if(router.getAppMode().isDerivedRoutingFrom(ApplicationMode.BICYCLE)){ PREPARE_LONG_DISTANCE = 500; // [100 sec] PREPARE_LONG_DISTANCE_END = 300; // [ 60 sec] PREPARE_DISTANCE = 200; // [ 40 sec] (was 500m, 100sec) @@ -125,7 +125,7 @@ public class VoiceRouter { TURN_IN_DISTANCE_END = 60; // 12 sec (was 80m, 16sec) TURN_DISTANCE = 30; // 6 sec (was 45m, 9sec). Check if this works with GPS accuracy! TURN_DEFAULT_SPEED = DEFAULT_SPEED = 5; // 18 km/h - } else { + } else if(router.getAppMode().isDerivedRoutingFrom(ApplicationMode.CAR)){ PREPARE_DISTANCE = 1500; // [125 sec] PREPARE_DISTANCE_END = 1200; // [100 sec] TURN_IN_DISTANCE = 390; // 30 sec @@ -133,6 +133,16 @@ public class VoiceRouter { TURN_DISTANCE = 50; // 7 sec TURN_DEFAULT_SPEED = 7f; // 25 km/h DEFAULT_SPEED = 13; // 48 km/h + } else { + DEFAULT_SPEED = router.getAppMode().getDefaultSpeed(); + TURN_DEFAULT_SPEED = DEFAULT_SPEED / 2; + PREPARE_LONG_DISTANCE = (int) (DEFAULT_SPEED * 305); + PREPARE_LONG_DISTANCE_END = (int) (DEFAULT_SPEED * 225); + PREPARE_DISTANCE = (int) (DEFAULT_SPEED * 125); + PREPARE_DISTANCE_END = (int) (DEFAULT_SPEED * 100); + TURN_IN_DISTANCE = (int) (DEFAULT_SPEED * 30); + TURN_IN_DISTANCE_END = (int) (DEFAULT_SPEED * 14); + TURN_DISTANCE = (int) (DEFAULT_SPEED * 7); } } From 6b717b48ec1b6511ff669b9d01be5c7db7265e8b Mon Sep 17 00:00:00 2001 From: vshcherb Date: Sat, 30 Nov 2013 01:22:02 +0100 Subject: [PATCH 4/4] Fix settings --- .../net/osmand/plus/activities/actions/NavigateAction.java | 2 +- .../net/osmand/plus/development/OsmandDevelopmentPlugin.java | 4 ---- .../osmand/plus/development/SettingsDevelopmentActivity.java | 2 +- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/actions/NavigateAction.java b/OsmAnd/src/net/osmand/plus/activities/actions/NavigateAction.java index 845992e274..d518b99c53 100644 --- a/OsmAnd/src/net/osmand/plus/activities/actions/NavigateAction.java +++ b/OsmAnd/src/net/osmand/plus/activities/actions/NavigateAction.java @@ -384,7 +384,7 @@ public class NavigateAction { b.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (!singleSelection) { + if (singleSelection) { if (isChecked) { selected.clear(); for (int j = 0; j < buttons.length; j++) { diff --git a/OsmAnd/src/net/osmand/plus/development/OsmandDevelopmentPlugin.java b/OsmAnd/src/net/osmand/plus/development/OsmandDevelopmentPlugin.java index e053a5f08c..0e13a2b467 100644 --- a/OsmAnd/src/net/osmand/plus/development/OsmandDevelopmentPlugin.java +++ b/OsmAnd/src/net/osmand/plus/development/OsmandDevelopmentPlugin.java @@ -1,14 +1,10 @@ package net.osmand.plus.development; -import java.util.EnumSet; - -import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.SettingsActivity; -import net.osmand.plus.audionotes.AudioNotesLayer; import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.OsmandMapLayer.DrawSettings; import net.osmand.plus.views.OsmandMapTileView; diff --git a/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java b/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java index df6aa99ebf..c43bf89975 100644 --- a/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java +++ b/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java @@ -113,7 +113,7 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity { @Override public void onClick(View v) { - StringBuilder vls = new StringBuilder(); + StringBuilder vls = new StringBuilder(ApplicationMode.DEFAULT.getStringKey()+","); for(ApplicationMode mode : modes) { if(selected.contains(mode)) { vls.append(mode.getStringKey()+",");