Leave transparent bar after restart
This commit is contained in:
parent
96c05f7c1b
commit
ccc15e797f
3 changed files with 39 additions and 28 deletions
|
@ -13,6 +13,7 @@ import java.util.Map.Entry;
|
|||
import net.osmand.CallbackWithObject;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.ResultMatcher;
|
||||
import net.osmand.StateChangedListener;
|
||||
import net.osmand.access.AccessibleToast;
|
||||
import net.osmand.data.AmenityType;
|
||||
import net.osmand.map.ITileSource;
|
||||
|
@ -98,9 +99,10 @@ public class MapActivityLayers {
|
|||
}
|
||||
|
||||
|
||||
public void createLayers(OsmandMapTileView mapView){
|
||||
public void createLayers(final OsmandMapTileView mapView){
|
||||
|
||||
RoutingHelper routingHelper = ((OsmandApplication) getApplication()).getRoutingHelper();
|
||||
OsmandApplication app = (OsmandApplication) getApplication();
|
||||
RoutingHelper routingHelper = app.getRoutingHelper();
|
||||
|
||||
// mapView.addLayer(underlayLayer, -0.5f);
|
||||
mapTileLayer = new MapTileLayer(true);
|
||||
|
@ -111,8 +113,6 @@ public class MapActivityLayers {
|
|||
mapVectorLayer = new MapVectorLayer(mapTileLayer);
|
||||
mapView.addLayer(mapVectorLayer, 0.5f);
|
||||
|
||||
// mapView.addLayer(overlayLayer, 0.7f);
|
||||
|
||||
// 0.9 gpx layer
|
||||
gpxLayer = new GPXLayer();
|
||||
mapView.addLayer(gpxLayer, 0.9f);
|
||||
|
@ -122,7 +122,6 @@ public class MapActivityLayers {
|
|||
mapView.addLayer(routeLayer, 1);
|
||||
|
||||
// 2. osm bugs layer
|
||||
|
||||
// 3. poi layer
|
||||
poiMapLayer = new POIMapLayer(activity);
|
||||
// 4. favorites layer
|
||||
|
@ -151,6 +150,15 @@ public class MapActivityLayers {
|
|||
mapControlsLayer = new MapControlsLayer(activity);
|
||||
mapView.addLayer(mapControlsLayer, 11);
|
||||
|
||||
app.getSettings().MAP_TRANSPARENCY.addListener(new StateChangedListener<Integer>() {
|
||||
@Override
|
||||
public void stateChanged(Integer change) {
|
||||
mapTileLayer.setAlpha(change);
|
||||
mapVectorLayer.setAlpha(change);
|
||||
mapView.refreshMap();
|
||||
}
|
||||
});
|
||||
|
||||
OsmandPlugin.createLayers(mapView, activity);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|||
import java.util.Map;
|
||||
|
||||
import net.osmand.ResultMatcher;
|
||||
import net.osmand.StateChangedListener;
|
||||
import net.osmand.map.ITileSource;
|
||||
import net.osmand.map.TileSourceManager.TileSourceTemplate;
|
||||
import net.osmand.plus.ContextMenuAdapter;
|
||||
|
@ -17,7 +18,6 @@ import net.osmand.plus.activities.DownloadTilesDialog;
|
|||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.MapActivityLayers;
|
||||
import net.osmand.plus.activities.SettingsActivity;
|
||||
import net.osmand.plus.views.BaseMapLayer;
|
||||
import net.osmand.plus.views.MapTileLayer;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
import net.osmand.plus.views.SeekBarPreference;
|
||||
|
@ -73,6 +73,12 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
|
|||
|
||||
private void createLayers() {
|
||||
underlayLayer = new MapTileLayer(false);
|
||||
settings.MAP_OVERLAY_TRANSPARENCY.addListener(new StateChangedListener<Integer>() {
|
||||
@Override
|
||||
public void stateChanged(Integer change) {
|
||||
overlayLayer.setAlpha(change);
|
||||
}
|
||||
});
|
||||
// mapView.addLayer(underlayLayer, -0.5f);
|
||||
overlayLayer = new MapTileLayer(false);
|
||||
// mapView.addLayer(overlayLayer, 0.7f);
|
||||
|
@ -111,8 +117,7 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
|
|||
|
||||
public void selectMapOverlayLayer(final OsmandMapTileView mapView,
|
||||
final CommonPreference<String> mapPref, final CommonPreference<Integer> transparencyPref,
|
||||
final MapActivity activity,
|
||||
final BaseMapLayer... transparencyToChange){
|
||||
final MapActivity activity){
|
||||
final OsmandSettings settings = app.getSettings();
|
||||
final MapActivityLayers layers = activity.getMapLayers();
|
||||
Map<String, String> entriesMap = settings.getTileSourceEntries();
|
||||
|
@ -137,10 +142,10 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
|
|||
if(object == null){
|
||||
if(count == 1){
|
||||
mapPref.set(template.getName());
|
||||
layers.getMapControlsLayer().showTransparencyBar(transparencyPref, transparencyToChange);
|
||||
layers.getMapControlsLayer().showTransparencyBar(transparencyPref);
|
||||
updateMapLayers(mapView, mapPref, layers);
|
||||
} else {
|
||||
selectMapOverlayLayer(mapView, mapPref, transparencyPref, activity, transparencyToChange);
|
||||
selectMapOverlayLayer(mapView, mapPref, transparencyPref, activity);
|
||||
}
|
||||
} else {
|
||||
count ++;
|
||||
|
@ -156,7 +161,7 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
|
|||
});
|
||||
} else {
|
||||
mapPref.set(keys.get(which));
|
||||
layers.getMapControlsLayer().showTransparencyBar(transparencyPref, transparencyToChange);
|
||||
layers.getMapControlsLayer().showTransparencyBar(transparencyPref);
|
||||
updateMapLayers(mapView, mapPref, layers);
|
||||
}
|
||||
dialog.dismiss();
|
||||
|
@ -182,8 +187,7 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
|
|||
layers.getMapControlsLayer().hideTransparencyBar(settings.MAP_OVERLAY_TRANSPARENCY);
|
||||
} else {
|
||||
dialog.dismiss();
|
||||
selectMapOverlayLayer(mapView, settings.MAP_OVERLAY, settings.MAP_OVERLAY_TRANSPARENCY, mapActivity,
|
||||
overlayLayer);
|
||||
selectMapOverlayLayer(mapView, settings.MAP_OVERLAY, settings.MAP_OVERLAY_TRANSPARENCY, mapActivity);
|
||||
}
|
||||
} else if(itemId == R.string.layer_underlay){
|
||||
if(underlayLayer.getMap() != null){
|
||||
|
@ -193,7 +197,7 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
|
|||
} else {
|
||||
dialog.dismiss();
|
||||
selectMapOverlayLayer(mapView, settings.MAP_UNDERLAY,settings.MAP_TRANSPARENCY,
|
||||
mapActivity, layers.getMapTileLayer(), layers.getMapVectorLayer());
|
||||
mapActivity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,12 +62,12 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
private Drawable rulerDrawable;
|
||||
private TextPaint rulerTextPaint;
|
||||
private final static double screenRulerPercent = 0.25;
|
||||
private CommonPreference<Integer> settingsToTransparency;
|
||||
private BaseMapLayer[] transparencyLayers;
|
||||
|
||||
private float scaleCoefficient;
|
||||
|
||||
private SeekBar transparencyBar;
|
||||
private LinearLayout transparencyBarLayout;
|
||||
private static CommonPreference<Integer> settingsToTransparency;
|
||||
|
||||
|
||||
public MapControlsLayer(MapActivity activity){
|
||||
|
@ -340,11 +340,14 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
Gravity.BOTTOM | Gravity.CENTER);
|
||||
params.setMargins(0, 0, 0, minimumHeight + 3);
|
||||
transparencyBarLayout = new LinearLayout(view.getContext());
|
||||
transparencyBarLayout.setVisibility(View.GONE);
|
||||
transparencyBarLayout.setVisibility(settingsToTransparency != null ? View.VISIBLE : View.GONE);
|
||||
parent.addView(transparencyBarLayout, params);
|
||||
|
||||
transparencyBar = new SeekBar(view.getContext());
|
||||
transparencyBar.setMax(255);
|
||||
if(settingsToTransparency != null) {
|
||||
transparencyBar.setProgress(settingsToTransparency.get());
|
||||
}
|
||||
transparencyBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
|
||||
@Override
|
||||
|
@ -357,11 +360,8 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
if (settingsToTransparency != null && transparencyLayers != null) {
|
||||
if (settingsToTransparency != null) {
|
||||
settingsToTransparency.set(progress);
|
||||
for (BaseMapLayer base : transparencyLayers) {
|
||||
base.setAlpha(progress);
|
||||
}
|
||||
MapControlsLayer.this.view.refreshMap();
|
||||
}
|
||||
}
|
||||
|
@ -376,6 +376,7 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
transparencyBarLayout.setVisibility(View.GONE);
|
||||
hideTransparencyBar(settingsToTransparency);
|
||||
}
|
||||
});
|
||||
imageButton.setContentDescription(view.getContext().getString(R.string.close));
|
||||
|
@ -383,18 +384,16 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
transparencyBarLayout.addView(imageButton, prms);
|
||||
}
|
||||
|
||||
public void showTransparencyBar(CommonPreference<Integer> transparenPreference,
|
||||
BaseMapLayer[] layerToChange) {
|
||||
public void showTransparencyBar(CommonPreference<Integer> transparenPreference) {
|
||||
MapControlsLayer.settingsToTransparency = transparenPreference;
|
||||
transparencyBarLayout.setVisibility(View.VISIBLE);
|
||||
transparencyBar.setProgress(transparenPreference.get());
|
||||
this.transparencyLayers = layerToChange;
|
||||
this.settingsToTransparency = transparenPreference;
|
||||
}
|
||||
|
||||
public void hideTransparencyBar(CommonPreference<Integer> transparenPreference) {
|
||||
if(this.settingsToTransparency == transparenPreference) {
|
||||
public void hideTransparencyBar(CommonPreference<Integer> transparentPreference) {
|
||||
if(settingsToTransparency == transparentPreference) {
|
||||
transparencyBarLayout.setVisibility(View.GONE);
|
||||
this.settingsToTransparency = null;
|
||||
settingsToTransparency = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue