diff --git a/OsmAnd/res/values-ru/strings.xml b/OsmAnd/res/values-ru/strings.xml index 2e2bc9eb2e..6df13de7d3 100644 --- a/OsmAnd/res/values-ru/strings.xml +++ b/OsmAnd/res/values-ru/strings.xml @@ -1,5 +1,10 @@ + Изменить прозрачность карты покрытия + Прозрачность покрытия + Изменить прозрачность основной карты + Прозрачность карты + Изменить прозрачность Карта подложки... Карта подложки Выберите слой подложки для основной карты diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 7aecfd4568..678cc139fe 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -1,5 +1,10 @@ + Modify overlay transparency + Overlay transparency + Modify base map transparency + Map transparency + Modify transparency Underlay map... Underlay map Choose underlay map diff --git a/OsmAnd/res/xml/settings_pref.xml b/OsmAnd/res/xml/settings_pref.xml index 426638cc97..1f98050fb4 100644 --- a/OsmAnd/res/xml/settings_pref.xml +++ b/OsmAnd/res/xml/settings_pref.xml @@ -16,6 +16,11 @@ + + + diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index efcb05b217..91815146d3 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -520,6 +520,14 @@ public class OsmandSettings { public final CommonPreference MAP_UNDERLAY = new StringPreference("map_underlay", null, true); + // this value string is synchronized with settings_pref.xml preference name + public final CommonPreference MAP_OVERLAY_TRANSPARENCY = new IntPreference("overlay_transparency", + 200, true); + + // this value string is synchronized with settings_pref.xml preference name + public final CommonPreference MAP_TRANSPARENCY = new IntPreference("map_transparency", + 255, true); + // this value string is synchronized with settings_pref.xml preference name public final CommonPreference MAP_TILE_SOURCES = new StringPreference("map_tile_sources", TileSourceManager.getMapnikSource().getName(), true); diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java index dfb61a8511..9418e6bbfb 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java @@ -219,6 +219,11 @@ public class MapActivityLayers { } else { mapView.setMainLayer(mapTileLayer); } + // update transparency + overlayLayer.setAlpha(settings.MAP_OVERLAY_TRANSPARENCY.get()); + int mapTransparency = settings.MAP_UNDERLAY.get() == null ? 255 : settings.MAP_TRANSPARENCY.get(); + mapTileLayer.setAlpha(mapTransparency); + mapVectorLayer.setAlpha(mapTransparency); diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java index 8a0284f006..5dcfb7b45e 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java @@ -22,6 +22,7 @@ import net.osmand.plus.OsmandSettings.MetricsConstants; import net.osmand.plus.OsmandSettings.OsmandPreference; import net.osmand.plus.activities.RouteProvider.RouteService; import net.osmand.plus.render.MapRenderRepositories; +import net.osmand.plus.views.SeekBarPreference; import android.app.Activity; import android.app.AlertDialog; import android.app.ProgressDialog; @@ -69,6 +70,8 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference private Map> booleanPreferences = new LinkedHashMap>(); private Map> listPreferences = new LinkedHashMap>(); private Map> editTextPreferences = new LinkedHashMap>(); + private Map> seekBarPreferences = new LinkedHashMap>(); + private Map> listPrefValues = new LinkedHashMap>(); @@ -80,6 +83,13 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference booleanPreferences.put(b.getId(), b); } + private void registerSeekBarPreference(OsmandPreference b, PreferenceScreen screen){ + SeekBarPreference p = (SeekBarPreference) screen.findPreference(b.getId()); + p.setOnPreferenceChangeListener(this); + screenPreferences.put(b.getId(), p); + seekBarPreferences.put(b.getId(), b); + } + private void registerListPreference(OsmandPreference b, PreferenceScreen screen, String[] names, T[] values){ ListPreference p = (ListPreference) screen.findPreference(b.getId()); p.setOnPreferenceChangeListener(this); @@ -156,6 +166,8 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference registerEditTextPreference(osmandSettings.USER_PASSWORD, screen); + registerSeekBarPreference(osmandSettings.MAP_OVERLAY_TRANSPARENCY, screen); + registerSeekBarPreference(osmandSettings.MAP_TRANSPARENCY, screen); // List preferences registerListPreference(osmandSettings.ROTATE_MAP, screen, @@ -306,6 +318,11 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference pref.setChecked(b.get()); } + for(OsmandPreference b : seekBarPreferences.values()){ + SeekBarPreference pref = (SeekBarPreference) screenPreferences.get(b.getId()); + pref.setValue(b.get()); + } + for(OsmandPreference p : listPreferences.values()){ ListPreference listPref = (ListPreference) screenPreferences.get(p.getId()); Map prefValues = listPrefValues.get(p.getId()); @@ -386,6 +403,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference public boolean onPreferenceChange(Preference preference, Object newValue) { // handle boolean prefences OsmandPreference boolPref = booleanPreferences.get(preference.getKey()); + OsmandPreference seekPref = seekBarPreferences.get(preference.getKey()); OsmandPreference listPref = (OsmandPreference) listPreferences.get(preference.getKey()); OsmandPreference editPref = editTextPreferences.get(preference.getKey()); if(boolPref != null){ @@ -397,6 +415,8 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference return false; } } + } else if (seekPref != null) { + seekPref.set((Integer) newValue); } else if (editPref != null) { editPref.set((String) newValue); } else if (listPref != null) { diff --git a/OsmAnd/src/net/osmand/plus/render/MapVectorLayer.java b/OsmAnd/src/net/osmand/plus/render/MapVectorLayer.java index 0b3eaf38d9..af0239f94a 100644 --- a/OsmAnd/src/net/osmand/plus/render/MapVectorLayer.java +++ b/OsmAnd/src/net/osmand/plus/render/MapVectorLayer.java @@ -24,6 +24,7 @@ public class MapVectorLayer extends BaseMapLayer { private RectF destImage = new RectF(); private final MapTileLayer tileLayer; private boolean visible = false; + private int alpha; public MapVectorLayer(MapTileLayer tileLayer){ this.tileLayer = tileLayer; @@ -128,6 +129,18 @@ public class MapVectorLayer extends BaseMapLayer { } } + + public void setAlpha(int alpha) { + this.alpha = alpha; + if (paintImg != null) { + paintImg.setAlpha(alpha); + } + } + + public int getAlpha() { + return alpha; + } + @Override public boolean onLongPressEvent(PointF point) { return false; diff --git a/OsmAnd/src/net/osmand/plus/views/SeekBarPreference.java b/OsmAnd/src/net/osmand/plus/views/SeekBarPreference.java new file mode 100644 index 0000000000..a446cb8dd2 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/views/SeekBarPreference.java @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2010 Jordan Frank, HumanSense Project, McGill University + * Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php + * See LICENSE for more information + */ +package net.osmand.plus.views; + +import net.osmand.plus.R; +import android.content.Context; +import android.preference.DialogPreference; +import android.util.AttributeSet; +import android.view.Gravity; +import android.view.View; +import android.widget.LinearLayout; +import android.widget.SeekBar; +import android.widget.TextView; + +/** + * A preference item that uses a seek-bar, or slider to set the value. + * + * @author Jordan Frank + * + */ +public class SeekBarPreference extends DialogPreference implements + SeekBar.OnSeekBarChangeListener { + + private static final String MAX_VALUE_ID = "max"; + private static final String DEFAULT_VALUE_ID = "defaultValue"; + private static final String DIALOG_TEXT_ID = "text"; + private static final String DIALOG_MESSAGE_ID = "dialogMessage"; + private static final String ANDROID_NS = "http://schemas.android.com/apk/res/android"; + + private SeekBar seekBar; + private TextView dialogTextView, valueTextView; + private final Context context; + + private final String dialogText, valueText; + private final int defaultValue; + + private int maxValue, value, valueToSave = 0; + + /** + * Default constructor. + * + * @param context + * The application context. + * @param attrs + * The attribute set, containing the text, title, values, and + * range for the slider dialog. + */ + public SeekBarPreference(final Context context, final AttributeSet attrs) { + super(context, attrs); + this.context = context; + + dialogText = context.getResources().getString( + attrs.getAttributeResourceValue(ANDROID_NS, DIALOG_MESSAGE_ID, + R.string.app_name)); + valueText = attrs.getAttributeValue(ANDROID_NS, DIALOG_TEXT_ID); + defaultValue = attrs.getAttributeIntValue(ANDROID_NS, DEFAULT_VALUE_ID, + 0); + maxValue = attrs.getAttributeIntValue(ANDROID_NS, MAX_VALUE_ID, 100); + + } + + public int getMax() { + return maxValue; + } + + public int getValue() { + return value; + } + + @Override + protected void onBindDialogView(final View v) { + super.onBindDialogView(v); + seekBar.setMax(maxValue); + seekBar.setProgress(value); + } + + @Override + protected View onCreateDialogView() { + LinearLayout.LayoutParams params; + final LinearLayout layout = new LinearLayout(context); + layout.setOrientation(LinearLayout.VERTICAL); + layout.setPadding(6, 6, 6, 6); + + dialogTextView = new TextView(context); + if (dialogText != null) { + dialogTextView.setText(dialogText); + } + layout.addView(dialogTextView); + + valueTextView = new TextView(context); + valueTextView.setGravity(Gravity.CENTER_HORIZONTAL); + valueTextView.setTextSize(32); + params = new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.FILL_PARENT, + LinearLayout.LayoutParams.WRAP_CONTENT); + layout.addView(valueTextView, params); + + seekBar = new SeekBar(context); + seekBar.setOnSeekBarChangeListener(this); + layout.addView(seekBar, new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.FILL_PARENT, + LinearLayout.LayoutParams.WRAP_CONTENT)); + + if (shouldPersist()) { + value = getPersistedInt(defaultValue); + } + + seekBar.setMax(maxValue); + seekBar.setProgress(value); + return layout; + } + + @Override + protected void onDialogClosed(boolean positiveResult) { + super.onDialogClosed(positiveResult); + if(positiveResult){ + if (shouldPersist()) { + persistInt(valueToSave); + } + callChangeListener(new Integer(valueToSave)); + } else { + this.valueToSave = value; + } + } + + @Override + public void onProgressChanged(final SeekBar seek, final int value, + final boolean fromTouch) { + final String t = String.valueOf(value); + valueTextView.setText(valueText == null ? t : t.concat(valueText)); + valueToSave = value; + } + + @Override + protected void onSetInitialValue(final boolean restore, + final Object defaultValue) { + super.onSetInitialValue(restore, defaultValue); + if (restore) { + value = shouldPersist() ? getPersistedInt(this.defaultValue) : 0; + } else { + value = (Integer) defaultValue; + } + valueToSave = value; + } + + @Override + public void onStartTrackingTouch(final SeekBar seek) { + } + + @Override + public void onStopTrackingTouch(final SeekBar seek) { + } + + public void setMax(final int max) { + maxValue = max; + } + + public void setValue(final int value) { + this.value = value; + this.valueToSave = value; + if (seekBar != null) { + seekBar.setProgress(value); + } + } + +} \ No newline at end of file