Change all settings layout

This commit is contained in:
Victor Shcherb 2012-08-19 17:31:39 +02:00
parent 6c8b991ae1
commit 48c479215c
8 changed files with 391 additions and 179 deletions

View file

@ -9,6 +9,8 @@
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
-->
<string name="map_widget_vector_attributes">Rendering attributes:</string>
<string name="map_widget_renderer">Rendering style</string>
<string name="live_monitoring_mode_off">Start\n live tracking</string>
<string name="live_monitoring_mode_on">Stop\n live tracking</string>
<string name="position_on_map_descr">Choose location of position marker on the map</string>

View file

@ -5,20 +5,18 @@
<PreferenceCategory android:title="@string/profile_settings" android:key="profile_dep_cat">
<ListPreference android:summary="@string/settings_preset_descr" android:title="@string/settings_preset" android:key="application_mode"></ListPreference>
<!--
<PreferenceScreen android:key="appearance_settings" android:title="@string/map_settings" android:summary="@string/map_settings_descr">
<ListPreference android:key="rotate_map" android:title="@string/rotate_map_to_bearing" android:summary="@string/rotate_map_to_bearing_descr"></ListPreference>
<ListPreference android:key="daynight_mode" android:title="@string/daynight" android:summary="@string/daynight_descr"></ListPreference>
<PreferenceCategory android:title="@string/pref_vector_map">
<ListPreference android:key="renderer" android:title="@string/renderers" android:summary="@string/renderers_descr"></ListPreference>
<ListPreference android:key="map_text_size" android:title="@string/map_text_size" android:summary="@string/map_text_size_descr"/>
</PreferenceCategory>
</PreferenceScreen>
-->
<PreferenceScreen android:key="routing_settings" android:title="@string/routing_settings" android:summary="@string/routing_settings_descr">
<ListPreference android:title="@string/router_service" android:key="router_service" android:summary="@string/router_service_descr"></ListPreference>
<CheckBoxPreference android:summary="@string/fast_route_mode_descr" android:title="@string/fast_route_mode"
android:key="fast_route_mode"></CheckBoxPreference>
<ListPreference android:title="@string/voice_provider" android:key="voice_provider" android:summary="@string/voice_provider_descr"></ListPreference>
<ListPreference android:key="daynight_mode" android:title="@string/daynight" android:summary="@string/daynight_descr"></ListPreference>
<ListPreference android:key="auto_follow_route" android:title="@string/choose_auto_follow_route"
android:summary="@string/choose_auto_follow_route_descr"></ListPreference>
<CheckBoxPreference android:title="@string/auto_zoom_map" android:summary="@string/auto_zoom_map_descr" android:key="auto_zoom_map"></CheckBoxPreference>

View file

@ -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<String, CommonPreference<String>> customRendersProps = new LinkedHashMap<String, OsmandSettings.CommonPreference<String>>();
public CommonPreference<String> 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<String, CommonPreference<Boolean>> customBooleanRendersProps = new LinkedHashMap<String, OsmandSettings.CommonPreference<Boolean>>();
public CommonPreference<Boolean> getCustomRenderBooleanProperty(String attrName){
if(!customRendersProps.containsKey(attrName)){
customBooleanRendersProps.put(attrName, new BooleanPreference("nrenderer_"+attrName, false).makeProfile());
}
return customBooleanRendersProps.get(attrName);
}
public final OsmandPreference<Boolean> VOICE_MUTE = new BooleanPreference("voice_mute", false).makeGlobal();
// for background service

View file

@ -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<entries.length; i++){
entries[i] = RouteService.values()[i].getName();
}
registerListPreference(osmandSettings.ROUTER_SERVICE, screen, entries, RouteService.values());
entries = new String[ApplicationMode.values().length];
for(int i=0; i<entries.length; i++){
entries[i] = ApplicationMode.values()[i].toHumanString(this);
}
registerListPreference(osmandSettings.APPLICATION_MODE, screen, entries, ApplicationMode.values());
Collection<String> 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<String> 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<String, Object> vals = new LinkedHashMap<String, Object>();
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;

View file

@ -1,18 +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.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;
@ -49,11 +57,47 @@ 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<Float> 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() {
@ -73,6 +117,29 @@ public class OsmandExtraSettings extends OsmandPlugin {
view.refreshMap();
}
});
final CommonPreference<Integer> 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
@ -121,19 +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));
// 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));
}
}

View file

@ -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<String> 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<Boolean> pref = prefs.getCustomRenderBooleanProperty(customProp.getAttrName());
renderingReq.setBooleanFilter(customProp, pref.get());
} else {
CommonPreference<String> 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();
}
}
}
}

View file

@ -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<Boolean> 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<MapInfoControlRegInfo> 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<ApplicationMode> 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<String> 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<String> 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<String> set, Set<MapInfoControlRegInfo> 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<String> set = new LinkedHashSet<String>();
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<String> set = new LinkedHashSet<String>();
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<MapInfoControlRegInfo> 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<ApplicationMode> defaultModes;
private EnumSet<ApplicationMode> defaultCollapsible;
private EnumSet<ApplicationMode> visibleModes;
private EnumSet<ApplicationMode> visibleCollapsible;
private CommonPreference<Boolean> 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<Boolean> blPreference) {
this.blPreference = blPreference;
this.preference = blPreference;
}

View file

@ -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<String> 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<Boolean> 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<String> 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<String> getSpecificVisibleCategories(Set<MapInfoControlRegInfo> m) {
Set<String> s = new LinkedHashSet<String>();
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<MapInfoControlRegInfo> widgets, String category, ArrayList<Object> 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<MapInfoControlRegInfo> widgets = mapInfoControls.getAppearanceWidgets();
Set<String> 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))) {