diff --git a/DataExtractionOSM/src/net/osmand/render/default.render.xml b/DataExtractionOSM/src/net/osmand/render/default.render.xml index d187a4a10f..64bd6bd7c0 100644 --- a/DataExtractionOSM/src/net/osmand/render/default.render.xml +++ b/DataExtractionOSM/src/net/osmand/render/default.render.xml @@ -1015,19 +1015,19 @@ - + - + - + - + @@ -1041,11 +1041,11 @@ - + - + @@ -1059,11 +1059,11 @@ - + - + @@ -1077,35 +1077,35 @@ - + - + - + - + - + - + - + - + @@ -1132,11 +1132,11 @@ - + - + diff --git a/OsmAnd/res/layout/local_openstreetmap_list_item_category.xml b/OsmAnd/res/layout/local_openstreetmap_list_item_category.xml index de2db0b9c5..3fd387b730 100644 --- a/OsmAnd/res/layout/local_openstreetmap_list_item_category.xml +++ b/OsmAnd/res/layout/local_openstreetmap_list_item_category.xml @@ -9,7 +9,7 @@ android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:paddingLeft="10dp" - android:src="@drawable/expandable_category_unpushed" /> + /> diff --git a/OsmAnd/res/values-ca/strings.xml b/OsmAnd/res/values-ca/strings.xml index e96c1ae3c3..2ca2506708 100644 --- a/OsmAnd/res/values-ca/strings.xml +++ b/OsmAnd/res/values-ca/strings.xml @@ -1,4 +1,4 @@ - + Mostra els missatges d\'avís… Rutes amb fluorescència Mostra el regle @@ -18,7 +18,7 @@ Torna a carregar la llista El punt d\'inici és massa lluny de la carretera més propera. Indica el temps límit d\'aparcament -Tria el tipus d'aparcament +Tria el tipus d\'aparcament Evita les carreteres no pavimentades Evita… Atura\n l\'enregistrament en GPX @@ -200,8 +200,8 @@ Tema transparent Miscel·lània Interval de despertament del GPS: %s -Treu el cotxe de l'aparcament -Optimització del mapa per cada Perfil d'usuari +Treu el cotxe de l\'aparcament +Optimització del mapa per cada Perfil d\'usuari Reprodueix instruccions de la veu seleccionada Desplaçament del mapa per gests a la pantalla tàctil Desplaçament natural del mapa @@ -209,6 +209,6 @@ Utilitza el ratolí de bola per controlar el zoom Utilitza els noms dels objectes {0} PDI/errors van ser penjats -PDI/errors d'OSM desats localment -Mostra i gestiona els PDI/errors d'OSM de les bases de dades locals +PDI/errors d\'OSM desats localment +Mostra i gestiona els PDI/errors d\'OSM de les bases de dades locals diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index f679067a4c..7d91166c83 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,8 +9,12 @@ 1. 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 --> + Rendering attributes: + Rendering style Start\n live tracking Stop\n live tracking + Choose location of position marker on the map + Position marker Configure screen… Show lanes Avoid unpaved roads diff --git a/OsmAnd/res/xml/settings_pref.xml b/OsmAnd/res/xml/settings_pref.xml index 1ece7a2c55..5e3fad9a37 100644 --- a/OsmAnd/res/xml/settings_pref.xml +++ b/OsmAnd/res/xml/settings_pref.xml @@ -5,20 +5,18 @@ + + diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 1942c9cf6b..5dc7a06e33 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -61,6 +61,8 @@ public class OsmandSettings { T getModeValue(ApplicationMode m); String getId(); + + void resetToDefault(); } // These settings are stored in SharedPreferences @@ -119,6 +121,11 @@ public class OsmandSettings { public void overrideDefaultValue(ApplicationMode newDefaultValue) { throw new UnsupportedOperationException(); } + + @Override + public void resetToDefault() { + set(ApplicationMode.DEFAULT); + }; @Override public boolean set(ApplicationMode val) { @@ -292,6 +299,11 @@ public class OsmandSettings { public String getId() { return id; } + + @Override + public void resetToDefault(){ + set(getDefaultValue()); + } @Override public boolean set(T obj) { @@ -1195,9 +1207,7 @@ public class OsmandSettings { } RenderingRulesStorage loaded = ctx.getRendererRegistry().getRenderer(val); if (loaded != null) { - ctx.getRendererRegistry().setCurrentSelectedRender(loaded); super.setValue(prefs, val); - ctx.getResourceManager().getRenderer().clearCache(); return true; } return false; @@ -1208,7 +1218,7 @@ public class OsmandSettings { Map> customRendersProps = new LinkedHashMap>(); public CommonPreference getCustomRenderProperty(String attrName){ if(!customRendersProps.containsKey(attrName)){ - customRendersProps.put(attrName, new StringPreference("renderer_"+attrName, "").makeProfile()); + customRendersProps.put(attrName, new StringPreference("nrenderer_"+attrName, "").makeProfile()); } return customRendersProps.get(attrName); } @@ -1219,6 +1229,14 @@ public class OsmandSettings { pref.setModeDefaultValue(ApplicationMode.BICYCLE, "bicycle"); } + Map> customBooleanRendersProps = new LinkedHashMap>(); + public CommonPreference getCustomRenderBooleanProperty(String attrName){ + if(!customRendersProps.containsKey(attrName)){ + customBooleanRendersProps.put(attrName, new BooleanPreference("nrenderer_"+attrName, false).makeProfile()); + } + return customBooleanRendersProps.get(attrName); + } + public final OsmandPreference VOICE_MUTE = new BooleanPreference("voice_mute", false).makeGlobal(); // for background service diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java index d2bac489a7..ae120d801f 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java @@ -3,7 +3,6 @@ package net.osmand.plus.activities; import java.io.File; import java.lang.reflect.Field; import java.util.ArrayList; -import java.util.Collection; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; @@ -19,7 +18,6 @@ import net.osmand.map.TileSourceManager.TileSourceTemplate; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; -import net.osmand.plus.OsmandSettings.CommonPreference; import net.osmand.plus.OsmandSettings.DayNightMode; import net.osmand.plus.OsmandSettings.MetricsConstants; import net.osmand.plus.OsmandSettings.OsmandPreference; @@ -30,12 +28,12 @@ import net.osmand.plus.activities.CustomTitleBar.CustomTitleBarView; import net.osmand.plus.render.NativeOsmandLibrary; import net.osmand.plus.routing.RouteProvider.RouteService; import net.osmand.plus.views.SeekBarPreference; -import net.osmand.render.RenderingRuleProperty; import net.osmand.render.RenderingRulesStorage; import android.app.Activity; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.app.ProgressDialog; +import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnMultiChoiceClickListener; @@ -117,12 +115,12 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference seekBarPreferences.put(b.getId(), b); } - public String getStringPropertyName(String propertyName, String defValue) { + public static String getStringPropertyName(Context ctx, String propertyName, String defValue) { try { Field f = R.string.class.getField("rendering_attr_" + propertyName + "_name"); if (f != null) { Integer in = (Integer) f.get(null); - return getString(in); + return ctx.getString(in); } } catch (Exception e) { System.err.println(e.getMessage()); @@ -298,9 +296,9 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference // List preferences - registerListPreference(osmandSettings.ROTATE_MAP, screen, - new String[]{getString(R.string.rotate_map_none_opt), getString(R.string.rotate_map_bearing_opt), getString(R.string.rotate_map_compass_opt)}, - new Integer[]{OsmandSettings.ROTATE_MAP_NONE, OsmandSettings.ROTATE_MAP_BEARING, OsmandSettings.ROTATE_MAP_COMPASS}); +// registerListPreference(osmandSettings.ROTATE_MAP, screen, +// new String[]{getString(R.string.rotate_map_none_opt), getString(R.string.rotate_map_bearing_opt), getString(R.string.rotate_map_compass_opt)}, +// new Integer[]{OsmandSettings.ROTATE_MAP_NONE, OsmandSettings.ROTATE_MAP_BEARING, OsmandSettings.ROTATE_MAP_COMPASS}); registerListPreference(osmandSettings.MAP_SCREEN_ORIENTATION, screen, new String[] {getString(R.string.map_orientation_portrait), getString(R.string.map_orientation_landscape), getString(R.string.map_orientation_default)}, @@ -344,33 +342,18 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference } registerListPreference(osmandSettings.AUTO_FOLLOW_ROUTE, screen, entries, intValues); - Float[] floatValues = new Float[] {0.6f, 0.8f, 1.0f, 1.2f, 1.5f}; - entries = new String[floatValues.length]; - for (int i = 0; i < floatValues.length; i++) { - entries[i] = (int) (floatValues[i] * 100) +" %"; - } - registerListPreference(osmandSettings.MAP_TEXT_SIZE, screen, entries, floatValues); - entries = new String[RouteService.values().length]; for(int i=0; i rendererNames = getMyApplication().getRendererRegistry().getRendererNames(); - entries = (String[]) rendererNames.toArray(new String[rendererNames.size()]); - registerListPreference(osmandSettings.RENDERER, screen, entries, entries); - - createCustomRenderingProperties(false); - applicationModePreference = (ListPreference) screen.findPreference(osmandSettings.APPLICATION_MODE.getId()); applicationModePreference.setOnPreferenceChangeListener(this); @@ -411,38 +394,6 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference } } - private void createCustomRenderingProperties(boolean update) { - RenderingRulesStorage renderer = getMyApplication().getRendererRegistry().getCurrentSelectedRenderer(); - PreferenceCategory cat = (PreferenceCategory) findPreference("custom_vector_rendering"); - if (cat != null) { - cat.removeAll(); - if (renderer != null) { - for (RenderingRuleProperty p : renderer.PROPS.getCustomRules()) { - CommonPreference custom = getMyApplication().getSettings().getCustomRenderProperty(p.getAttrName()); - ListPreference lp = new ListPreference(this); - lp.setOnPreferenceChangeListener(this); - lp.setKey(custom.getId()); - lp.setTitle(getStringPropertyName(p.getAttrName(), p.getName())); - lp.setSummary(getStringPropertyDescription(p.getAttrName(), p.getDescription())); - cat.addPreference(lp); - - LinkedHashMap vals = new LinkedHashMap(); - screenPreferences.put(custom.getId(), lp); - listPreferences.put(custom.getId(), custom); - listPrefValues.put(custom.getId(), vals); - String[] names = p.getPossibleValues(); - for (int i = 0; i < names.length; i++) { - vals.put(names[i], names[i]); - } - - } - if (update) { - updateAllSettings(); - } - } - } - - } private void reloadVoiceListPreference(PreferenceScreen screen) { String[] entries; @@ -583,14 +534,6 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference + osmandSettings.DAYNIGHT_MODE.get().toHumanString(this) + "]"); } } - if (listPref.getId().equals(osmandSettings.RENDERER.getId())) { - if (changed) { - AccessibleToast.makeText(this, R.string.renderer_load_sucess, Toast.LENGTH_SHORT).show(); - } else { - AccessibleToast.makeText(this, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show(); - } - createCustomRenderingProperties(true); - } } else if (preference == applicationDir) { warnAboutChangingStorage((String) newValue); return false; diff --git a/OsmAnd/src/net/osmand/plus/extrasettings/OsmandExtraSettings.java b/OsmAnd/src/net/osmand/plus/extrasettings/OsmandExtraSettings.java index eaeb7f6a88..6ce35b590b 100644 --- a/OsmAnd/src/net/osmand/plus/extrasettings/OsmandExtraSettings.java +++ b/OsmAnd/src/net/osmand/plus/extrasettings/OsmandExtraSettings.java @@ -1,19 +1,26 @@ package net.osmand.plus.extrasettings; +import java.util.Arrays; + import net.osmand.Version; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; +import net.osmand.plus.OsmandSettings.CommonPreference; +import net.osmand.plus.OsmandSettings.OsmandPreference; import net.osmand.plus.R; -import net.osmand.plus.activities.ApplicationMode; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.SettingsActivity; import net.osmand.plus.views.MapInfoControls; +import net.osmand.plus.views.MapInfoControls.MapInfoControlRegInfo; import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.OsmandMapTileView; -import net.osmand.plus.views.MapInfoControls.MapInfoControlRegInfo; import net.osmand.plus.voice.CommandPlayer; +import android.app.AlertDialog; +import android.app.AlertDialog.Builder; +import android.content.DialogInterface; +import android.content.DialogInterface.OnClickListener; import android.media.AudioManager; import android.preference.ListPreference; import android.preference.Preference; @@ -50,17 +57,52 @@ public class OsmandExtraSettings extends OsmandPlugin { return app.getString(R.string.extra_settings); } @Override - public void registerLayers(MapActivity activity) { + public void registerLayers(final MapActivity activity) { registerControls = true; final OsmandMapTileView view = activity.getMapView(); final MapInfoLayer mapInfoLayer = activity.getMapLayers().getMapInfoLayer(); final MapInfoControls mapInfoControls = mapInfoLayer.getMapInfoControls(); + + final OsmandPreference textSizePref = view.getSettings().MAP_TEXT_SIZE; + final MapInfoControlRegInfo textSize = mapInfoControls.registerAppearanceWidget(0, R.string.map_text_size, + "text_size", textSizePref); + textSize.setStateChangeListener(new Runnable() { + @Override + public void run() { + final Float[] floatValues = new Float[] {0.6f, 0.8f, 1.0f, 1.2f, 1.5f}; + String[] entries = new String[floatValues.length]; + for (int i = 0; i < floatValues.length; i++) { + entries[i] = (int) (floatValues[i] * 100) +" %"; + } + Builder b = new AlertDialog.Builder(view.getContext()); + int i = Arrays.binarySearch(floatValues, textSizePref.get()); + b.setSingleChoiceItems(entries, i, new OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + textSizePref.set(floatValues[which]); + app.getResourceManager().getRenderer().clearCache(); + view.refreshMap(true); + dialog.dismiss(); + } + }); + b.show(); + } + }); + final MapInfoControlRegInfo showRuler = mapInfoControls.registerAppearanceWidget(0, R.string.map_widget_show_ruler, + "showRuler", view.getSettings().SHOW_RULER); + showRuler.setStateChangeListener(new Runnable() { + @Override + public void run() { + view.getSettings().SHOW_RULER.set(!view.getSettings().SHOW_RULER.get()); + view.refreshMap(); + } + }); + final MapInfoControlRegInfo transparent = mapInfoControls.registerAppearanceWidget(0, R.string.map_widget_transparent, "transparent", view.getSettings().TRANSPARENT_MAP_THEME); transparent.setStateChangeListener(new Runnable() { @Override public void run() { - ApplicationMode am = view.getSettings().getApplicationMode(); view.getSettings().TRANSPARENT_MAP_THEME.set(!view.getSettings().TRANSPARENT_MAP_THEME.get()); mapInfoLayer.recreateControls(); } @@ -71,11 +113,33 @@ public class OsmandExtraSettings extends OsmandPlugin { fluorescent.setStateChangeListener(new Runnable() { @Override public void run() { - ApplicationMode am = view.getSettings().getApplicationMode(); view.getSettings().FLUORESCENT_OVERLAYS.set(!view.getSettings().FLUORESCENT_OVERLAYS.get()); view.refreshMap(); } }); + + final CommonPreference posPref = view.getSettings().POSITION_ON_MAP; + final MapInfoControlRegInfo posMap = mapInfoControls.registerAppearanceWidget(0, R.string.position_on_map, + "position_on_map", textSizePref); + posMap.setStateChangeListener(new Runnable() { + @Override + public void run() { + String[] entries = new String[] { activity.getString(R.string.position_on_map_center), activity.getString(R.string.position_on_map_bottom) }; + final Integer[] vals = new Integer[] { OsmandSettings.CENTER_CONSTANT, OsmandSettings.BOTTOM_CONSTANT }; + Builder b = new AlertDialog.Builder(view.getContext()); + int i = Arrays.binarySearch(vals, posPref.get()); + b.setSingleChoiceItems(entries, i, new OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + posPref.set(vals[which]); + activity.updateApplicationModeSettings(); + view.refreshMap(true); + dialog.dismiss(); + } + }); + b.show(); + } + }); } @Override @@ -124,11 +188,13 @@ public class OsmandExtraSettings extends OsmandPlugin { } - PreferenceScreen appearance = (PreferenceScreen) screen.findPreference("appearance_settings"); - PreferenceCategory vectorSettings = new PreferenceCategory(app); - vectorSettings.setTitle(R.string.pref_vector_rendering); - vectorSettings.setKey("custom_vector_rendering"); - appearance.addPreference(vectorSettings); - +// cat = new PreferenceCategory(app); +// cat.setTitle(R.string.extra_settings); +// PreferenceScreen routing = (PreferenceScreen) screen.findPreference(SettingsActivity.SCREEN_ID_NAVIGATION_SETTINGS); +// routing.addPreference(cat); +// cat.addPreference(activity.createListPreference(settings.POSITION_ON_MAP, +// new String[] { activity.getString(R.string.position_on_map_center), activity.getString(R.string.position_on_map_bottom) }, +// new Integer[] { OsmandSettings.CENTER_CONSTANT, OsmandSettings.BOTTOM_CONSTANT }, R.string.position_on_map, +// R.string.position_on_map_descr)); } } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/LocalOpenstreetmapActivity.java b/OsmAnd/src/net/osmand/plus/osmedit/LocalOpenstreetmapActivity.java index df60504555..0b9c08b14b 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/LocalOpenstreetmapActivity.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/LocalOpenstreetmapActivity.java @@ -29,7 +29,6 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import android.widget.BaseExpandableListAdapter; import android.widget.ExpandableListView; import android.widget.ExpandableListView.ExpandableListContextMenuInfo; import android.widget.TextView; @@ -170,7 +169,7 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity { switch (id) { case DIALOG_PROGRESS_UPLOAD: UploadOpenstreetmapPointAsyncTask uploadTask = new UploadOpenstreetmapPointAsyncTask((ProgressDialog) dialog, remotepoi, - remotebug, toUpload.length); + remotebug, toUpload.length); uploadTask.execute(toUpload); break; } @@ -188,10 +187,8 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity { private boolean interruptUploading = false; - public UploadOpenstreetmapPointAsyncTask(ProgressDialog progress, - OpenstreetmapRemoteUtil remotepoi, - OsmBugsRemoteUtil remotebug, - int listSize) { + public UploadOpenstreetmapPointAsyncTask(ProgressDialog progress, OpenstreetmapRemoteUtil remotepoi, OsmBugsRemoteUtil remotebug, + int listSize) { this.progress = progress; this.remotepoi = remotepoi; this.remotebug = remotebug; @@ -203,7 +200,8 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity { int uploaded = 0; for (OsmPoint point : points) { - if (interruptUploading) break; + if (interruptUploading) + break; if (point.getGroup() == OsmPoint.Group.POI) { OpenstreetmapPoint p = (OpenstreetmapPoint) point; @@ -214,10 +212,11 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity { Node n; if ((n = remotepoi.commitNodeImpl(p.getAction(), p.getEntity(), entityInfo, p.getComment())) != null) { if (point.getId() != n.getId()) { - //change all category points... + // change all category points... listAdapter.categoryIdChanged(point.getId(), n.getId()); } remotepoi.updateNodeInIndexes(LocalOpenstreetmapActivity.this, p.getAction(), n, p.getEntity()); + dbpoi.deleteOpenstreetmap(p); publishProgress(p); uploaded++; } @@ -225,10 +224,13 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity { OsmbugsPoint p = (OsmbugsPoint) point; if (p.getAction() == OsmPoint.Action.CREATE) { remotebug.createNewBug(p.getLatitude(), p.getLongitude(), p.getText(), p.getAuthor()); + dbbug.deleteOsmbugs(p); } else if (p.getAction() == OsmPoint.Action.MODIFY) { remotebug.addingComment(p.getId(), p.getText(), p.getAuthor()); + dbbug.deleteOsmbugs(p); } else if (p.getAction() == OsmPoint.Action.DELETE) { remotebug.closingBug(p.getId()); + dbbug.deleteOsmbugs(p); } publishProgress(p); uploaded++; @@ -243,11 +245,11 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity { interruptUploading = false; progress.setOnCancelListener(new DialogInterface.OnCancelListener() { - @Override - public void onCancel(DialogInterface dialog) { - UploadOpenstreetmapPointAsyncTask.this.setInterruptUploading(true); - } - }); + @Override + public void onCancel(DialogInterface dialog) { + UploadOpenstreetmapPointAsyncTask.this.setInterruptUploading(true); + } + }); progress.setIndeterminate(false); progress.setMax(listSize); progress.setProgress(0); @@ -256,8 +258,10 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity { @Override protected void onPostExecute(Integer result) { listAdapter.notifyDataSetChanged(); - if(result != null){ - AccessibleToast.makeText(LocalOpenstreetmapActivity.this, MessageFormat.format(getString(R.string.local_openstreetmap_were_uploaded), result.intValue()), Toast.LENGTH_LONG).show(); + if (result != null) { + AccessibleToast.makeText(LocalOpenstreetmapActivity.this, + MessageFormat.format(getString(R.string.local_openstreetmap_were_uploaded), result.intValue()), Toast.LENGTH_LONG) + .show(); } removeDialog(DIALOG_PROGRESS_UPLOAD); } diff --git a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java index 1384650745..d13c659f20 100644 --- a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java +++ b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java @@ -486,18 +486,23 @@ public class MapRenderRepositories { RenderingRuleSearchRequest renderingReq = new RenderingRuleSearchRequest(storage); renderingReq.setBooleanFilter(renderingReq.ALL.R_NIGHT_MODE, nightMode); for (RenderingRuleProperty customProp : storage.PROPS.getCustomRules()) { - CommonPreference settings = prefs.getCustomRenderProperty(customProp.getAttrName()); - String res = settings.get(); - if (!Algoritms.isEmpty(res)) { - if (customProp.isString()) { - renderingReq.setStringFilter(customProp, res); - } else if (customProp.isBoolean()) { - renderingReq.setBooleanFilter(customProp, "true".equalsIgnoreCase(res)); - } else { - try { - renderingReq.setIntFilter(customProp, Integer.parseInt(res)); - } catch (NumberFormatException e) { - e.printStackTrace(); + if (customProp.isBoolean()) { + CommonPreference pref = prefs.getCustomRenderBooleanProperty(customProp.getAttrName()); + renderingReq.setBooleanFilter(customProp, pref.get()); + } else { + CommonPreference settings = prefs.getCustomRenderProperty(customProp.getAttrName()); + String res = settings.get(); + if (!Algoritms.isEmpty(res)) { + if (customProp.isString()) { + renderingReq.setStringFilter(customProp, res); + } else if (customProp.isBoolean()) { + renderingReq.setBooleanFilter(customProp, "true".equalsIgnoreCase(res)); + } else { + try { + renderingReq.setIntFilter(customProp, Integer.parseInt(res)); + } catch (NumberFormatException e) { + e.printStackTrace(); + } } } } diff --git a/OsmAnd/src/net/osmand/plus/views/MapInfoControls.java b/OsmAnd/src/net/osmand/plus/views/MapInfoControls.java index d315f0a0fd..544c6fb3f4 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapInfoControls.java +++ b/OsmAnd/src/net/osmand/plus/views/MapInfoControls.java @@ -2,14 +2,17 @@ package net.osmand.plus.views; import java.util.Comparator; import java.util.EnumSet; +import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; import java.util.TreeSet; +import net.osmand.Algoritms; import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.CommonPreference; +import net.osmand.plus.OsmandSettings.OsmandPreference; import net.osmand.plus.activities.ApplicationMode; import android.view.View; import android.view.ViewGroup; @@ -68,12 +71,12 @@ public class MapInfoControls { } public MapInfoControlRegInfo registerAppearanceWidget(int drawable, int messageId, String key, - CommonPreference pref) { + OsmandPreference pref) { MapInfoControlRegInfo ii = new MapInfoControlRegInfo(); ii.defaultModes = EnumSet.noneOf(ApplicationMode.class); ii.defaultCollapsible = null; ii.key = key; - ii.blPreference = pref; + ii.preference = pref; ii.visibleModes = EnumSet.noneOf(ApplicationMode.class); ii.visibleCollapsible = null; ii.drawable = drawable; @@ -82,6 +85,32 @@ public class MapInfoControls { return ii; } + public void removeApperanceWidgets(String category) { + Iterator it = appearanceWidgets.iterator(); + while(it.hasNext()) { + if(Algoritms.objectEquals(it.next().category, category)) { + it.remove(); + } + } + } + + public MapInfoControlRegInfo registerAppearanceWidget(int drawable, String message, String key, + CommonPreference pref, String subcategory) { + MapInfoControlRegInfo ii = new MapInfoControlRegInfo(); + ii.defaultModes = EnumSet.noneOf(ApplicationMode.class); + ii.defaultCollapsible = null; + ii.key = key; + ii.category = subcategory; + ii.preference = pref; + ii.visibleModes = EnumSet.noneOf(ApplicationMode.class); + ii.visibleCollapsible = null; + ii.drawable = drawable; + ii.messageId = message.hashCode(); + ii.message = message; + this.appearanceWidgets.add(ii); + return ii; + } + public MapInfoControlRegInfo registerTopWidget(View m, int drawable, int messageId, String key, int left, EnumSet appDefaultModes, int priorityOrder) { MapInfoControlRegInfo ii = new MapInfoControlRegInfo(); @@ -93,8 +122,12 @@ public class MapInfoControls { for(ApplicationMode ms : ApplicationMode.values() ) { boolean def = appDefaultModes.contains(ms); Set set = visibleElements.get(ms); - if(set != null) { - def = set.contains(key); + if (set != null) { + if (set.contains(key)) { + def = true; + } else if (set.contains("-" + key)) { + def = false; + } } if(def){ ii.visibleModes.add(ms); @@ -124,8 +157,13 @@ public class MapInfoControls { boolean def = appDefaultModes.contains(ms); Set set = visibleElements.get(ms); if(set != null) { - def = set.contains(key); - collapse = set.contains("+"+key); + if (set.contains(key)) { + def = true; + } else if (set.contains("-" + key)) { + def = false; + } else if(set.contains("+"+key)){ + collapse = true; + } } if(def){ ii.visibleModes.add(ms); @@ -145,45 +183,58 @@ public class MapInfoControls { } private void restoreModes(Set set, Set mi, ApplicationMode mode) { - for(MapInfoControlRegInfo m : mi){ - if(m.visibleModes.contains(mode)) { - set.add(m.key) ; - } else if(m.visibleCollapsible != null && m.visibleCollapsible.contains(mode)) { - set.add("+"+m.key) ; - } + for (MapInfoControlRegInfo m : mi) { + if (m.preference == null) { + if (m.visibleModes.contains(mode)) { + set.add(m.key); + } else if (m.visibleCollapsible != null && m.visibleCollapsible.contains(mode)) { + set.add("+" + m.key); + } else { + set.add("-" + m.key); + } + } } } - public void changeVisibility(MapInfoControlRegInfo m, boolean visible, boolean collapse) { - ApplicationMode mode = settings.APPLICATION_MODE.get(); - if(this.visibleElements.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.visibleElements.get(mode).remove(m.key); - this.visibleElements.get(mode).remove("+" + m.key); - m.visibleModes.remove(mode); - if(m.visibleCollapsible != null) { - m.visibleCollapsible.remove(mode); - } - if(visible) { - if(collapse && m.visibleCollapsible != null) { - m.visibleCollapsible.add(mode); - this.visibleElements.get(mode).add("+" + m.key); + public void changeVisibility(MapInfoControlRegInfo m) { + boolean selecteable = m.selecteable(); + if (selecteable) { + ApplicationMode mode = settings.APPLICATION_MODE.get(); + boolean visible = m.visible(mode); + boolean collapseEnabled = m.collapseEnabled(mode); + boolean collapse = m.visibleCollapsed(mode); + if (this.visibleElements.get(mode) == null) { + LinkedHashSet set = new LinkedHashSet(); + restoreModes(set, left, mode); + restoreModes(set, right, mode); + restoreModes(set, top, mode); + this.visibleElements.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); + m.visibleModes.remove(mode); + if (m.visibleCollapsible != null) { + m.visibleCollapsible.remove(mode); + } + if (visible || collapse) { + if (collapseEnabled && !collapse) { + m.visibleCollapsible.add(mode); + this.visibleElements.get(mode).add("+" + m.key); + } else { + this.visibleElements.get(mode).add("-" + m.key); + } } else { m.visibleModes.add(mode); - this.visibleElements.get(mode).add(m.key); - + this.visibleElements.get(mode).add("" + m.key); } + StringBuilder bs = new StringBuilder(); + for (String ks : this.visibleElements.get(mode)) { + bs.append(ks).append(";"); + } + settings.MAP_INFO_CONTROLS.set(bs.toString()); } - StringBuilder bs = new StringBuilder(); - for(String ks : this.visibleElements.get(mode)){ - bs.append(ks).append(";"); - } - settings.MAP_INFO_CONTROLS.set(bs.toString()); if(m.stateChangeListener != null) { m.stateChangeListener.run(); } @@ -233,15 +284,19 @@ public class MapInfoControls { private void resetDefault(ApplicationMode mode, Set set ){ for(MapInfoControlRegInfo ri : set) { - if(ri.visibleCollapsible != null) { - 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(ri.preference != null) { + ri.preference.resetToDefault(); + } else { + if (ri.visibleCollapsible != null) { + 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); + } } } } @@ -251,6 +306,7 @@ public class MapInfoControls { resetDefault(appMode, left); resetDefault(appMode, right); resetDefault(appMode, top); + resetDefault(appMode, appearanceWidgets); this.visibleElements.put(appMode, null); settings.MAP_INFO_CONTROLS.set(""); } @@ -267,27 +323,41 @@ public class MapInfoControls { public View m; public int drawable; public int messageId; + public String message; private String key; private int position; + private String category; private EnumSet defaultModes; private EnumSet defaultCollapsible; private EnumSet visibleModes; private EnumSet visibleCollapsible; - private CommonPreference blPreference = null; + private OsmandPreference preference = null; private Runnable stateChangeListener = null; public int priorityOrder; public boolean visibleCollapsed(ApplicationMode mode){ - return blPreference == null && visibleCollapsible != null && visibleCollapsible.contains(mode); + return preference == null && visibleCollapsible != null && visibleCollapsible.contains(mode); } public boolean collapseEnabled(ApplicationMode mode){ - return visibleCollapsible != null && blPreference == null; + return visibleCollapsible != null && preference == null; + } + + + public String getCategory() { + return category; + } + public boolean selecteable(){ + return preference == null || (preference.get() instanceof Boolean); } public boolean visible(ApplicationMode mode){ - if(blPreference != null) { - return blPreference.getModeValue(mode); + if(preference != null) { + Object value = preference.getModeValue(mode); + if(value instanceof Boolean) { + return ((Boolean) value).booleanValue(); + } + return true; } return visibleModes.contains(mode); } @@ -300,7 +370,7 @@ public class MapInfoControls { } public void setPreference(CommonPreference blPreference) { - this.blPreference = blPreference; + this.preference = blPreference; } diff --git a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java index cf67536e69..c60c7177bb 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java @@ -2,19 +2,33 @@ package net.osmand.plus.views; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; import java.util.EnumSet; +import java.util.LinkedHashSet; +import java.util.Set; +import net.osmand.Algoritms; +import net.osmand.access.AccessibleToast; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; +import net.osmand.plus.OsmandSettings.CommonPreference; import net.osmand.plus.activities.ApplicationMode; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.activities.SettingsActivity; +import net.osmand.plus.extrasettings.OsmandExtraSettings; import net.osmand.plus.routing.RouteDirectionInfo; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.views.MapInfoControls.MapInfoControlRegInfo; +import net.osmand.render.RenderingRuleProperty; +import net.osmand.render.RenderingRulesStorage; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.content.Context; import android.content.DialogInterface; +import android.content.DialogInterface.OnClickListener; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; @@ -34,6 +48,7 @@ import android.view.WindowManager; import android.widget.ArrayAdapter; import android.widget.CheckBox; import android.widget.CompoundButton; +import android.widget.Toast; import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.FrameLayout; import android.widget.ImageView; @@ -73,6 +88,8 @@ public class MapInfoLayer extends OsmandMapLayer { private LockInfoControl lockInfoControl; + private String ADDITIONAL_VECTOR_RENDERING_CATEGORY; + public MapInfoLayer(MapActivity map, RouteLayer layer){ this.map = map; this.routeLayer = layer; @@ -86,6 +103,7 @@ public class MapInfoLayer extends OsmandMapLayer { scaleCoefficient *= 1.5f; } + ADDITIONAL_VECTOR_RENDERING_CATEGORY = map.getString(R.string.map_widget_vector_attributes); paintText = new Paint(); paintText.setStyle(Style.FILL_AND_STROKE); paintText.setColor(Color.BLACK); @@ -232,28 +250,91 @@ public class MapInfoLayer extends OsmandMapLayer { private void registerAppearanceWidgets() { - final MapInfoControlRegInfo showRuler = mapInfoControls.registerAppearanceWidget(0, R.string.map_widget_show_ruler, - "showRuler", view.getSettings().SHOW_RULER); - showRuler.setStateChangeListener(new Runnable() { + final MapInfoControlRegInfo vectorRenderer = mapInfoControls.registerAppearanceWidget(0, R.string.map_widget_renderer, + "renderer", view.getSettings().RENDERER); + final OsmandApplication app = view.getApplication(); + vectorRenderer.setStateChangeListener(new Runnable() { @Override public void run() { - ApplicationMode am = view.getSettings().getApplicationMode(); - view.getSettings().SHOW_RULER.set(!view.getSettings().SHOW_RULER.get()); - view.refreshMap(); + Builder bld = new AlertDialog.Builder(view.getContext()); + bld.setTitle(R.string.renderers); + Collection rendererNames = app.getRendererRegistry().getRendererNames(); + final String[] items = rendererNames.toArray(new String[rendererNames.size()]); + bld.setItems(items, new OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + String renderer = items[which]; + RenderingRulesStorage loaded = app.getRendererRegistry().getRenderer(renderer); + if (loaded != null) { + view.getSettings().RENDERER.set(renderer); + app.getRendererRegistry().setCurrentSelectedRender(loaded); + app.getResourceManager().getRenderer().clearCache(); + view.refreshMap(true); + } else { + AccessibleToast.makeText(app, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show(); + } + createCustomRenderingProperties(loaded); + } + }); + bld.show(); } }); + final MapInfoControlRegInfo displayViewDirections = mapInfoControls.registerAppearanceWidget(0, R.string.map_widget_view_direction, "viewDirection", view.getSettings().SHOW_VIEW_ANGLE); displayViewDirections.setStateChangeListener(new Runnable() { @Override public void run() { - ApplicationMode am = view.getSettings().getApplicationMode(); view.getSettings().SHOW_VIEW_ANGLE.set(!view.getSettings().SHOW_VIEW_ANGLE.get()); map.updateApplicationModeSettings(); } }); + createCustomRenderingProperties(app.getRendererRegistry().getCurrentSelectedRenderer()); + } + + private void createCustomRenderingProperties(RenderingRulesStorage renderer) { + String categoryName = ADDITIONAL_VECTOR_RENDERING_CATEGORY; + mapInfoControls.removeApperanceWidgets(categoryName); + final OsmandApplication app = view.getApplication(); + for (final RenderingRuleProperty p : renderer.PROPS.getCustomRules()) { + String propertyName = SettingsActivity.getStringPropertyName(view.getContext(), p.getAttrName(), p.getName()); + if(p.isBoolean()) { + final CommonPreference pref = view.getApplication().getSettings().getCustomRenderBooleanProperty(p.getAttrName()); + MapInfoControlRegInfo w = mapInfoControls.registerAppearanceWidget(0, propertyName, "rend_"+p.getAttrName(), pref, categoryName); + w.setStateChangeListener(new Runnable() { + @Override + public void run() { + pref.set(!pref.get()); + app.getResourceManager().getRenderer().clearCache(); + view.refreshMap(true); + } + }); + + } else { + final CommonPreference pref = view.getApplication().getSettings().getCustomRenderProperty(p.getAttrName()); + MapInfoControlRegInfo w = mapInfoControls.registerAppearanceWidget(0, propertyName, "rend_"+p.getAttrName(), pref, categoryName); + w.setStateChangeListener(new Runnable() { + @Override + public void run() { + Builder b = new AlertDialog.Builder(view.getContext()); + int i = Arrays.asList(p.getPossibleValues()).indexOf(pref.get()); + b.setSingleChoiceItems(p.getPossibleValues(), i, new OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + pref.set(p.getPossibleValues()[which]); + app.getResourceManager().getRenderer().clearCache(); + view.refreshMap(true); + dialog.dismiss(); + } + }); + b.show(); + } + }); + } + } } @@ -336,6 +417,27 @@ public class MapInfoLayer extends OsmandMapLayer { // update and create controls recreateControls(); } + + public Set getSpecificVisibleCategories(Set m) { + Set s = new LinkedHashSet(); + for(MapInfoControlRegInfo ms : m){ + if(ms.getCategory() != null) { + s.add(ms.getCategory()); + } + } + if(OsmandPlugin.getEnabledPlugin(OsmandExtraSettings.class) == null){ + s.remove(ADDITIONAL_VECTOR_RENDERING_CATEGORY); + } + return s; + } + + public void fillAppearanceWidgets(Set widgets, String category, ArrayList registry) { + for(MapInfoControlRegInfo w : widgets ) { + if(Algoritms.objectEquals(w.getCategory(), category)) { + registry.add(w); + } + } + } public void openViewConfigureDialog() { final OsmandSettings settings = view.getSettings(); @@ -348,8 +450,15 @@ public class MapInfoLayer extends OsmandMapLayer { list.addAll(mapInfoControls.getRight()); list.add(map.getString(R.string.map_widget_left_stack)); list.addAll(mapInfoControls.getLeft()); + + Set widgets = mapInfoControls.getAppearanceWidgets(); + Set cats = getSpecificVisibleCategories(widgets); list.add(map.getString(R.string.map_widget_appearance)); - list.addAll(mapInfoControls.getAppearanceWidgets()); + fillAppearanceWidgets(widgets, null, list); + for(String cat : cats) { + list.add(cat); + fillAppearanceWidgets(widgets, cat, list); + } // final LayerMenuListener listener = new LayerMenuListener(adapter, mapView, settings); @@ -367,8 +476,13 @@ public class MapInfoLayer extends OsmandMapLayer { Object o = list.get(position); if(o instanceof MapInfoControlRegInfo) { final MapInfoControlRegInfo mi = (MapInfoControlRegInfo) o; + String s = mi.visibleCollapsed(mode)? " - " : " "; - tv.setText(s +map.getString(mi.messageId) +s); + if(mi.message != null) { + tv.setText(s +mi.message +s); + } else { + tv.setText(s +map.getString(mi.messageId) +s); + } // Put the image on the TextView if (mi.drawable != 0) { tv.setPadding((int) (12 *scaleCoefficient), 0, 0, 0); @@ -377,29 +491,31 @@ public class MapInfoLayer extends OsmandMapLayer { tv.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); tv.setPadding((int) (30 *scaleCoefficient), 0, 0, 0); } - - boolean check = mi.visibleCollapsed(mode) || mi.visible(mode); + final boolean selecteable = mi.selecteable(); ch.setOnCheckedChangeListener(null); - ch.setChecked(check); + if(!mi.selecteable()) { + ch.setVisibility(View.INVISIBLE); + } else { + boolean check = mi.visibleCollapsed(mode) || mi.visible(mode); + ch.setChecked(check); + ch.setVisibility(View.VISIBLE); + } ch.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if(!isChecked) { - if(mi.visible(mode) && mi.collapseEnabled(mode)) { - mapInfoControls.changeVisibility(mi, true, true); - ch.setChecked(true); - } else { - mapInfoControls.changeVisibility(mi, false, false); - } - } else { - mapInfoControls.changeVisibility(mi, true, false); + mapInfoControls.changeVisibility(mi); + if (selecteable) { + ch.setChecked(mi.visible(mode) || mi.visibleCollapsed(mode)); } String s = mi.visibleCollapsed(mode) ? " - " : " "; - tv.setText(s + map.getString(mi.messageId) + s); + if(mi.message != null) { + tv.setText(s +mi.message +s); + } else { + tv.setText(s +map.getString(mi.messageId) +s); + } recreateControls(); } }); - ch.setVisibility(View.VISIBLE); } else { tv.setText(o.toString()); tv.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); @@ -417,11 +533,10 @@ public class MapInfoLayer extends OsmandMapLayer { Object o = list.get(position); if (o instanceof MapInfoControlRegInfo) { final MapInfoControlRegInfo mi = (MapInfoControlRegInfo) o; + final boolean selecteable = mi.selecteable(); boolean check = mi.visibleCollapsed(mode) || mi.visible(mode); - if (check) { - mapInfoControls.changeVisibility(mi, false, false); - } else { - mapInfoControls.changeVisibility(mi, true, false); + if (check || selecteable) { + mapInfoControls.changeVisibility(mi); } recreateControls(); } else if(o.toString().equals(map.getString(R.string.map_widget_reset))) {