Add seek bar to modify layer transparency

This commit is contained in:
Victor Shcherb 2011-06-01 00:18:34 +02:00
parent 276edaa1e1
commit 53da4a210b
8 changed files with 230 additions and 0 deletions

View file

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="overlay_transparency_descr">Изменить прозрачность карты покрытия</string>
<string name="overlay_transparency">Прозрачность покрытия</string>
<string name="map_transparency_descr">Изменить прозрачность основной карты</string>
<string name="map_transparency">Прозрачность карты</string>
<string name="modify_transparency">Изменить прозрачность</string>
<string name="layer_underlay">Карта подложки...</string>
<string name="map_underlay">Карта подложки</string>
<string name="map_underlay_descr">Выберите слой подложки для основной карты </string>

View file

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<resources>
<string name="overlay_transparency_descr">Modify overlay transparency</string>
<string name="overlay_transparency">Overlay transparency</string>
<string name="map_transparency_descr">Modify base map transparency</string>
<string name="map_transparency">Map transparency</string>
<string name="modify_transparency">Modify transparency</string>
<string name="layer_underlay">Underlay map...</string>
<string name="map_underlay">Underlay map</string>
<string name="map_underlay_descr">Choose underlay map</string>

View file

@ -16,6 +16,11 @@
<CheckBoxPreference android:summary="@string/continuous_rendering_descr" android:title="@string/continuous_rendering"
android:key="use_step_by_step_rendering" />
<CheckBoxPreference android:key="use_high_res_maps" android:title="@string/use_high_res_maps" android:summary="@string/use_high_res_maps_descr"></CheckBoxPreference>
<net.osmand.plus.views.SeekBarPreference android:key="map_transparency" android:defaultValue="0" android:max="255"
android:dialogMessage="@string/modify_transparency" android:title="@string/map_transparency" android:summary="@string/map_transparency_descr"/>
<net.osmand.plus.views.SeekBarPreference android:key="overlay_transparency" android:defaultValue="0" android:max="255"
android:dialogMessage="@string/modify_transparency" android:title="@string/overlay_transparency" android:summary="@string/overlay_transparency_descr"/>
<CheckBoxPreference android:summary="@string/trace_rendering_descr" android:title="@string/trace_rendering"
android:key="debug_rendering"></CheckBoxPreference>

View file

@ -520,6 +520,14 @@ public class OsmandSettings {
public final CommonPreference<String> MAP_UNDERLAY = new StringPreference("map_underlay",
null, true);
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<Integer> MAP_OVERLAY_TRANSPARENCY = new IntPreference("overlay_transparency",
200, true);
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<Integer> MAP_TRANSPARENCY = new IntPreference("map_transparency",
255, true);
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<String> MAP_TILE_SOURCES = new StringPreference("map_tile_sources",
TileSourceManager.getMapnikSource().getName(), true);

View file

@ -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);

View file

@ -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<String, OsmandPreference<Boolean>> booleanPreferences = new LinkedHashMap<String, OsmandPreference<Boolean>>();
private Map<String, OsmandPreference<?>> listPreferences = new LinkedHashMap<String, OsmandPreference<?>>();
private Map<String, OsmandPreference<String>> editTextPreferences = new LinkedHashMap<String, OsmandPreference<String>>();
private Map<String, OsmandPreference<Integer>> seekBarPreferences = new LinkedHashMap<String, OsmandPreference<Integer>>();
private Map<String, Map<String, ?>> listPrefValues = new LinkedHashMap<String, Map<String, ?>>();
@ -80,6 +83,13 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
booleanPreferences.put(b.getId(), b);
}
private void registerSeekBarPreference(OsmandPreference<Integer> b, PreferenceScreen screen){
SeekBarPreference p = (SeekBarPreference) screen.findPreference(b.getId());
p.setOnPreferenceChangeListener(this);
screenPreferences.put(b.getId(), p);
seekBarPreferences.put(b.getId(), b);
}
private <T> void registerListPreference(OsmandPreference<T> 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<Integer> 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<String, ?> 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<Boolean> boolPref = booleanPreferences.get(preference.getKey());
OsmandPreference<Integer> seekPref = seekBarPreferences.get(preference.getKey());
OsmandPreference<Object> listPref = (OsmandPreference<Object>) listPreferences.get(preference.getKey());
OsmandPreference<String> 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) {

View file

@ -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;

View file

@ -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 <jordan.frank@cs.mcgill.ca>
*
*/
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);
}
}
}