Implement transparency bar over map

This commit is contained in:
Victor Shcherb 2011-06-01 13:56:00 +02:00
parent 53da4a210b
commit 83c7a57cf3
14 changed files with 106 additions and 31 deletions

View file

@ -25,6 +25,7 @@ import net.osmand.plus.SQLiteTileSource;
import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.render.MapRenderRepositories;
import net.osmand.plus.render.MapVectorLayer;
import net.osmand.plus.views.BaseMapLayer;
import net.osmand.plus.views.ContextMenuLayer;
import net.osmand.plus.views.FavoritesLayer;
import net.osmand.plus.views.GPXLayer;
@ -75,6 +76,7 @@ public class MapActivityLayers {
private MapInfoLayer mapInfoLayer;
private ContextMenuLayer contextMenuLayer;
private RouteInfoLayer routeInfoLayer;
private MapControlsLayer mapControlsLayer;
public MapActivityLayers(MapActivity activity) {
@ -144,7 +146,7 @@ public class MapActivityLayers {
mapView.addLayer(routeInfoLayer, 10);
// 11. route info layer
MapControlsLayer mapControlsLayer = new MapControlsLayer(activity);
mapControlsLayer = new MapControlsLayer(activity);
mapView.addLayer(mapControlsLayer, 11);
}
@ -187,6 +189,14 @@ public class MapActivityLayers {
public void updateMapSource(OsmandMapTileView mapView){
OsmandSettings settings = getApplication().getSettings();
// 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);
boolean showTiles = !settings.MAP_VECTOR_DATA.get();
// update overlay layer
updateLayer(mapView, settings, overlayLayer, settings.MAP_OVERLAY, 0.7f);
@ -219,11 +229,7 @@ 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);
@ -315,7 +321,8 @@ public class MapActivityLayers {
updateMapSource(mapView);
} else {
dialog.dismiss();
selectMapOverlayLayer(mapView, settings.MAP_OVERLAY);
selectMapOverlayLayer(mapView, settings.MAP_OVERLAY, settings.MAP_OVERLAY_TRANSPARENCY,
overlayLayer);
}
} else if(item == 7){
if(underlayLayer.getMap() != null){
@ -323,7 +330,8 @@ public class MapActivityLayers {
updateMapSource(mapView);
} else {
dialog.dismiss();
selectMapOverlayLayer(mapView, settings.MAP_UNDERLAY);
selectMapOverlayLayer(mapView, settings.MAP_UNDERLAY,settings.MAP_TRANSPARENCY,
mapTileLayer, mapVectorLayer);
}
} else if(item == routeInfoInd){
routeInfoLayer.setVisible(isChecked);
@ -515,7 +523,9 @@ public class MapActivityLayers {
}
private void selectMapOverlayLayer(final OsmandMapTileView mapView, final CommonPreference<String> mapPref){
private void selectMapOverlayLayer(final OsmandMapTileView mapView,
final CommonPreference<String> mapPref, final CommonPreference<Integer> transparencyPref,
final BaseMapLayer... transparencyToChange){
final OsmandSettings settings = getApplication().getSettings();
Map<String, String> entriesMap = settings.getTileSourceEntries();
final ArrayList<String> keys = new ArrayList<String>(entriesMap.keySet());
@ -539,6 +549,7 @@ public class MapActivityLayers {
});
} else {
mapPref.set(keys.get(which));
mapControlsLayer.showAndHideTransparencyBar(transparencyPref, transparencyToChange);
updateMapSource(mapView);
}

View file

@ -18,7 +18,6 @@ import net.osmand.data.Street;
import net.osmand.osm.LatLon;
import net.osmand.osm.MapUtils;
import net.osmand.osm.Node;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.RegionAddressRepository;
import net.osmand.plus.ResourceManager;

View file

@ -17,7 +17,6 @@ import net.osmand.plus.activities.OsmandApplication;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.Window;

View file

@ -11,7 +11,6 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.RegionAddressRepository;
import net.osmand.plus.activities.OsmandApplication;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.TextView;

View file

@ -25,7 +25,6 @@ import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.graphics.Canvas;
import android.graphics.Color;

View file

@ -10,7 +10,6 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.RegionAddressRepository;
import net.osmand.plus.activities.OsmandApplication;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.TextView;

View file

@ -23,7 +23,6 @@ import android.app.AlertDialog;
import android.app.ListActivity;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.LayoutInflater;

View file

@ -24,7 +24,6 @@ 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;
@ -46,6 +45,7 @@ public class MapVectorLayer extends BaseMapLayer {
resourceManager = view.getApplication().getResourceManager();
paintImg = new Paint();
paintImg.setFilterBitmap(true);
paintImg.setAlpha(getAlpha());
}
private void updateRotatedTileBox(){
@ -130,16 +130,13 @@ public class MapVectorLayer extends BaseMapLayer {
}
@Override
public void setAlpha(int alpha) {
this.alpha = alpha;
super.setAlpha(alpha);
if (paintImg != null) {
paintImg.setAlpha(alpha);
}
}
public int getAlpha() {
return alpha;
}
}
@Override
public boolean onLongPressEvent(PointF point) {

View file

@ -2,6 +2,7 @@ package net.osmand.plus.views;
public abstract class BaseMapLayer implements OsmandMapLayer {
private int alpha = 255;
public int getMaximumShownMapZoom(){
return 21;
@ -11,5 +12,13 @@ public abstract class BaseMapLayer implements OsmandMapLayer {
return 1;
}
public void setAlpha(int alpha) {
this.alpha = alpha;
}
public int getAlpha() {
return alpha;
}
}

View file

@ -1,11 +1,14 @@
package net.osmand.plus.views;
import net.osmand.plus.R;
import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.activities.MapActivity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.PointF;
import android.graphics.RectF;
import android.os.Handler;
import android.os.Message;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
@ -13,9 +16,15 @@ import android.view.WindowManager;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.SeekBar;
public class MapControlsLayer implements OsmandMapLayer {
private static final int SHOW_SEEKBAR_MSG_ID = 2;
private static final int SHOW_SEEKBAR_DELAY = 7000;
private static final int SHOW_SEEKBAR_SECOND_DELAY = 25000;
private OsmandMapTileView view;
private DisplayMetrics dm;
private Button zoomInButton;
@ -23,6 +32,10 @@ public class MapControlsLayer implements OsmandMapLayer {
private Button backToMenuButton;
private final MapActivity activity;
private SeekBar transparencyBar;
private Handler showBarHandler;
private CommonPreference<Integer> settingsToTransparency;
private BaseMapLayer[] transparencyLayers;
public MapControlsLayer(MapActivity activity){
this.activity = activity;
@ -57,6 +70,7 @@ public class MapControlsLayer implements OsmandMapLayer {
params = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
Gravity.BOTTOM | Gravity.RIGHT);
int minimumWidth = view.getResources().getDrawable(R.drawable.map_zoom_in).getMinimumWidth();
int minimumHeight = view.getResources().getDrawable(R.drawable.map_zoom_in).getMinimumHeight();
params.setMargins(0, 0, minimumWidth , 0);
parent.addView(zoomOutButton, params);
@ -67,6 +81,14 @@ public class MapControlsLayer implements OsmandMapLayer {
parent.addView(backToMenuButton, params);
backToMenuButton.setEnabled(true);
transparencyBar = new SeekBar(view.getContext());
transparencyBar.setVisibility(View.GONE);
transparencyBar.setMax(255);
params = new FrameLayout.LayoutParams((int) (dm.density * 100), LayoutParams.WRAP_CONTENT,
Gravity.BOTTOM | Gravity.CENTER);
params.setMargins(0, 0, 0, minimumHeight + 3);
parent.addView(transparencyBar, params);
zoomInButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -88,6 +110,53 @@ public class MapControlsLayer implements OsmandMapLayer {
}
});
transparencyBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if(settingsToTransparency != null && transparencyLayers != null){
settingsToTransparency.set(progress);
for(BaseMapLayer base : transparencyLayers){
base.setAlpha(progress);
}
MapControlsLayer.this.view.refreshMap();
showAndHideTransparencyBar(settingsToTransparency, transparencyLayers, SHOW_SEEKBAR_SECOND_DELAY);
}
}
});
}
public void showAndHideTransparencyBar(CommonPreference<Integer> transparenPreference,
BaseMapLayer[] layerToChange) {
showAndHideTransparencyBar(transparenPreference, layerToChange, SHOW_SEEKBAR_DELAY);
}
private void showAndHideTransparencyBar(CommonPreference<Integer> transparenPreference,
BaseMapLayer[] layerToChange, int delay) {
transparencyBar.setVisibility(View.VISIBLE);
transparencyBar.setProgress(transparenPreference.get());
this.transparencyLayers = layerToChange;
this.settingsToTransparency = transparenPreference;
if (showBarHandler == null) {
showBarHandler = new Handler();
}
Message msg = Message.obtain(showBarHandler, new Runnable() {
@Override
public void run() {
transparencyBar.setVisibility(View.GONE);
}
});
msg.what = SHOW_SEEKBAR_MSG_ID;
showBarHandler.removeMessages(SHOW_SEEKBAR_MSG_ID);
showBarHandler.sendMessageDelayed(msg, delay);
}
@Override

View file

@ -30,7 +30,6 @@ public class MapTileLayer extends BaseMapLayer {
protected ResourceManager resourceManager;
private OsmandSettings settings;
private boolean visible = true;
private int alpha = 255;
@Override
public boolean drawInScreenPixels() {
@ -45,20 +44,17 @@ public class MapTileLayer extends BaseMapLayer {
paintBitmap = new Paint();
paintBitmap.setFilterBitmap(true);
paintBitmap.setAlpha(alpha);
paintBitmap.setAlpha(getAlpha());
}
@Override
public void setAlpha(int alpha) {
this.alpha = alpha;
super.setAlpha(alpha);
if (paintBitmap != null) {
paintBitmap.setAlpha(alpha);
}
}
public int getAlpha() {
return alpha;
}
@Override
public void onDraw(Canvas canvas, RectF latlonRect, RectF tilesRect, boolean nightMode) {

View file

@ -161,6 +161,7 @@ public class SeekBarPreference extends DialogPreference implements
public void setValue(final int value) {
this.value = value;
this.valueToSave = value;
persistInt(value);
if (seekBar != null) {
seekBar.setProgress(value);
}

View file

@ -5,7 +5,6 @@ import java.util.List;
import net.osmand.data.TransportRoute;
import net.osmand.data.TransportStop;
import net.osmand.osm.LatLon;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.TransportIndexRepository.RouteInfoLocation;
import net.osmand.plus.activities.TransportRouteHelper;
import android.content.Context;

View file

@ -5,7 +5,6 @@ import java.util.List;
import net.osmand.data.TransportStop;
import net.osmand.osm.LatLon;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.TransportIndexRepository;
import android.content.Context;