From 83c7a57cf30fff26487866ddfb7b91daa8ddae67 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Wed, 1 Jun 2011 13:56:00 +0200 Subject: [PATCH] Implement transparency bar over map --- .../plus/activities/MapActivityLayers.java | 29 +++++--- .../activities/search/GeoIntentActivity.java | 1 - .../search/SearchAddressActivity.java | 1 - .../search/SearchBuildingByNameActivity.java | 1 - .../activities/search/SearchPOIActivity.java | 1 - .../search/SearchStreetByNameActivity.java | 1 - .../search/SearchTransportActivity.java | 1 - .../osmand/plus/render/MapVectorLayer.java | 11 ++- .../net/osmand/plus/views/BaseMapLayer.java | 9 +++ .../osmand/plus/views/MapControlsLayer.java | 69 +++++++++++++++++++ .../net/osmand/plus/views/MapTileLayer.java | 10 +-- .../osmand/plus/views/SeekBarPreference.java | 1 + .../osmand/plus/views/TransportInfoLayer.java | 1 - .../plus/views/TransportStopsLayer.java | 1 - 14 files changed, 106 insertions(+), 31 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java index 9418e6bbfb..4b865beb6b 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java @@ -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 mapPref){ + private void selectMapOverlayLayer(final OsmandMapTileView mapView, + final CommonPreference mapPref, final CommonPreference transparencyPref, + final BaseMapLayer... transparencyToChange){ final OsmandSettings settings = getApplication().getSettings(); Map entriesMap = settings.getTileSourceEntries(); final ArrayList keys = new ArrayList(entriesMap.keySet()); @@ -539,6 +549,7 @@ public class MapActivityLayers { }); } else { mapPref.set(keys.get(which)); + mapControlsLayer.showAndHideTransparencyBar(transparencyPref, transparencyToChange); updateMapSource(mapView); } diff --git a/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java index 366abefb98..8395db3b78 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java @@ -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; diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressActivity.java index 21879fedea..3c50b6c629 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressActivity.java @@ -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; diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchBuildingByNameActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchBuildingByNameActivity.java index 5d5ea2ab67..cf8195bfc5 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchBuildingByNameActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchBuildingByNameActivity.java @@ -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; diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java index 8be3991cf8..e52cd5df4f 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java @@ -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; diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchStreetByNameActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchStreetByNameActivity.java index 87a1b6ff80..a347bcce95 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchStreetByNameActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchStreetByNameActivity.java @@ -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; diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchTransportActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchTransportActivity.java index df0b4ea371..82ee554c36 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchTransportActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchTransportActivity.java @@ -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; diff --git a/OsmAnd/src/net/osmand/plus/render/MapVectorLayer.java b/OsmAnd/src/net/osmand/plus/render/MapVectorLayer.java index af0239f94a..265e109c5b 100644 --- a/OsmAnd/src/net/osmand/plus/render/MapVectorLayer.java +++ b/OsmAnd/src/net/osmand/plus/render/MapVectorLayer.java @@ -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) { diff --git a/OsmAnd/src/net/osmand/plus/views/BaseMapLayer.java b/OsmAnd/src/net/osmand/plus/views/BaseMapLayer.java index a00a13f6ba..c8557d4bb0 100644 --- a/OsmAnd/src/net/osmand/plus/views/BaseMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/BaseMapLayer.java @@ -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; + } + } diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index d6547f11bb..200714b8a3 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -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 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 transparenPreference, + BaseMapLayer[] layerToChange) { + showAndHideTransparencyBar(transparenPreference, layerToChange, SHOW_SEEKBAR_DELAY); + } + private void showAndHideTransparencyBar(CommonPreference 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 diff --git a/OsmAnd/src/net/osmand/plus/views/MapTileLayer.java b/OsmAnd/src/net/osmand/plus/views/MapTileLayer.java index f4b770e4ff..499ec4b595 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapTileLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapTileLayer.java @@ -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) { diff --git a/OsmAnd/src/net/osmand/plus/views/SeekBarPreference.java b/OsmAnd/src/net/osmand/plus/views/SeekBarPreference.java index a446cb8dd2..63acbc259b 100644 --- a/OsmAnd/src/net/osmand/plus/views/SeekBarPreference.java +++ b/OsmAnd/src/net/osmand/plus/views/SeekBarPreference.java @@ -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); } diff --git a/OsmAnd/src/net/osmand/plus/views/TransportInfoLayer.java b/OsmAnd/src/net/osmand/plus/views/TransportInfoLayer.java index 39d27df8e7..d4497ad205 100644 --- a/OsmAnd/src/net/osmand/plus/views/TransportInfoLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/TransportInfoLayer.java @@ -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; diff --git a/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java b/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java index 0557c1861c..bfea4ed992 100644 --- a/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java @@ -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;