Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
736f153776
7 changed files with 361 additions and 100 deletions
|
@ -9,6 +9,9 @@
|
|||
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
||||
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
||||
-->
|
||||
<string name="hillshade_menu_download_descr">For view hillshade on the map, you need to download special map of this region.</string>
|
||||
<string name="hillshade_purchase_header">To see hillshade on the map, you need to buy and install plugin</string>
|
||||
<string name="hide_from_zoom_level">Hide from zoom level</string>
|
||||
<string name="srtm_menu_download_descr">For view contour lines on the map, you need to download contour line map of this region.</string>
|
||||
<string name="shared_string_plugin">Plugin</string>
|
||||
<string name="srtm_purchase_header">To see contour lines on the map, you need to buy and install plugin</string>
|
||||
|
|
|
@ -78,6 +78,8 @@ import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
|
|||
import net.osmand.plus.routing.RoutingHelper;
|
||||
import net.osmand.plus.routing.RoutingHelper.IRouteInformationListener;
|
||||
import net.osmand.plus.srtmplugin.ContourLinesMenu;
|
||||
import net.osmand.plus.srtmplugin.HillshadeMenu;
|
||||
import net.osmand.plus.srtmplugin.SRTMPlugin;
|
||||
import net.osmand.plus.views.DownloadedRegionsLayer;
|
||||
import net.osmand.plus.views.MapInfoLayer;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
|
@ -186,6 +188,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
|
|||
OVERLAY_MAP,
|
||||
UNDERLAY_MAP,
|
||||
CONTOUR_LINES,
|
||||
HILLSHADE,
|
||||
MAP_MARKERS,
|
||||
MAP_MARKERS_SELECTION
|
||||
}
|
||||
|
@ -460,6 +463,8 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
|
|||
tv.setText(R.string.select_map_markers);
|
||||
} else if (visibleType == DashboardType.CONTOUR_LINES) {
|
||||
tv.setText(R.string.srtm_plugin_name);
|
||||
} else if (visibleType == DashboardType.HILLSHADE) {
|
||||
tv.setText(R.string.layer_hillshade);
|
||||
}
|
||||
ImageView edit = (ImageView) dashboardView.findViewById(R.id.toolbar_edit);
|
||||
edit.setVisibility(View.GONE);
|
||||
|
@ -890,7 +895,8 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
|
|||
&& visibleType != DashboardType.MAP_MARKERS_SELECTION
|
||||
&& visibleType != DashboardType.CONFIGURE_SCREEN
|
||||
&& visibleType != DashboardType.CONFIGURE_MAP
|
||||
&& visibleType != DashboardType.CONTOUR_LINES) {
|
||||
&& visibleType != DashboardType.CONTOUR_LINES
|
||||
&& visibleType != DashboardType.HILLSHADE) {
|
||||
listView.setDivider(dividerDrawable);
|
||||
listView.setDividerHeight(dpToPx(1f));
|
||||
} else {
|
||||
|
@ -968,6 +974,8 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
|
|||
cm = RasterMapMenu.createListAdapter(mapActivity, OsmandRasterMapsPlugin.RasterMapType.OVERLAY);
|
||||
} else if (visibleType == DashboardType.CONTOUR_LINES) {
|
||||
cm = ContourLinesMenu.createListAdapter(mapActivity);
|
||||
} else if (visibleType == DashboardType.HILLSHADE) {
|
||||
cm = HillshadeMenu.createListAdapter(mapActivity);
|
||||
}
|
||||
if (cm != null) {
|
||||
updateListAdapter(cm);
|
||||
|
@ -987,14 +995,14 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
|
|||
}
|
||||
|
||||
public void onNewDownloadIndexes() {
|
||||
if (visibleType == DashboardType.CONTOUR_LINES) {
|
||||
if (visibleType == DashboardType.CONTOUR_LINES || visibleType == DashboardType.HILLSHADE) {
|
||||
refreshContent(true);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void onDownloadInProgress() {
|
||||
if (visibleType == DashboardType.CONTOUR_LINES) {
|
||||
if (visibleType == DashboardType.CONTOUR_LINES || visibleType == DashboardType.HILLSHADE) {
|
||||
DownloadIndexesThread downloadThread = getMyApplication().getDownloadThread();
|
||||
IndexItem downloadIndexItem = downloadThread.getCurrentDownloadingItem();
|
||||
if (downloadIndexItem != null) {
|
||||
|
@ -1012,8 +1020,15 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
|
|||
}
|
||||
|
||||
public void onDownloadHasFinished() {
|
||||
if (visibleType == DashboardType.CONTOUR_LINES) {
|
||||
if (visibleType == DashboardType.CONTOUR_LINES || visibleType == DashboardType.HILLSHADE) {
|
||||
refreshContent(true);
|
||||
if (visibleType == DashboardType.HILLSHADE) {
|
||||
SRTMPlugin plugin = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class);
|
||||
if (plugin != null && plugin.isHillShadeLayerEnabled()) {
|
||||
plugin.registerLayers(mapActivity);
|
||||
}
|
||||
}
|
||||
SRTMPlugin.refreshMapComplete(mapActivity);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
package net.osmand.plus.download;
|
||||
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.binary.BinaryMapDataObject;
|
||||
import net.osmand.binary.BinaryMapIndexReader;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.map.OsmandRegions;
|
||||
import net.osmand.map.WorldRegion;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.download.DownloadOsmandIndexesHelper.AssetIndexItem;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
|
@ -12,6 +16,7 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
@ -360,5 +365,52 @@ public class DownloadResources extends DownloadResourceGroup {
|
|||
return true;
|
||||
}
|
||||
|
||||
public static List<IndexItem> findIndexItemsAt(OsmandApplication app, LatLon latLon, DownloadActivityType type) throws IOException {
|
||||
|
||||
List<IndexItem> res = new ArrayList<>();
|
||||
OsmandRegions regions = app.getRegions();
|
||||
DownloadIndexesThread downloadThread = app.getDownloadThread();
|
||||
|
||||
int point31x = MapUtils.get31TileNumberX(latLon.getLongitude());
|
||||
int point31y = MapUtils.get31TileNumberY(latLon.getLatitude());
|
||||
|
||||
List<BinaryMapDataObject> mapDataObjects;
|
||||
try {
|
||||
mapDataObjects = regions.queryBbox(point31x, point31x, point31y, point31y);
|
||||
} catch (IOException e) {
|
||||
throw new IOException("Error while calling queryBbox");
|
||||
}
|
||||
if (mapDataObjects != null) {
|
||||
Iterator<BinaryMapDataObject> it = mapDataObjects.iterator();
|
||||
while (it.hasNext()) {
|
||||
BinaryMapDataObject o = it.next();
|
||||
if (o.getTypes() != null) {
|
||||
boolean isRegion = true;
|
||||
for (int i = 0; i < o.getTypes().length; i++) {
|
||||
BinaryMapIndexReader.TagValuePair tp = o.getMapIndex().decodeType(o.getTypes()[i]);
|
||||
if ("boundary".equals(tp.value)) {
|
||||
isRegion = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
WorldRegion downloadRegion = regions.getRegionData(regions.getFullName(o));
|
||||
if (downloadRegion == null || !isRegion || !regions.contain(o, point31x, point31y)) {
|
||||
it.remove();
|
||||
}
|
||||
List<IndexItem> otherIndexItems = new ArrayList<>(downloadThread.getIndexes().getIndexItems(downloadRegion));
|
||||
for (IndexItem indexItem : otherIndexItems) {
|
||||
if (indexItem.getType() == type
|
||||
&& !res.contains(indexItem)) {
|
||||
if (indexItem.isDownloaded()) {
|
||||
res.clear();
|
||||
return res;
|
||||
}
|
||||
res.add(indexItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
|
@ -4,11 +4,6 @@ import android.content.Intent;
|
|||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
|
||||
import net.osmand.binary.BinaryMapDataObject;
|
||||
import net.osmand.binary.BinaryMapIndexReader;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.map.OsmandRegions;
|
||||
import net.osmand.map.WorldRegion;
|
||||
import net.osmand.plus.ContextMenuAdapter;
|
||||
import net.osmand.plus.ContextMenuItem;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
|
@ -20,16 +15,12 @@ import net.osmand.plus.activities.PluginActivity;
|
|||
import net.osmand.plus.activities.SettingsActivity;
|
||||
import net.osmand.plus.download.DownloadActivityType;
|
||||
import net.osmand.plus.download.DownloadIndexesThread;
|
||||
import net.osmand.plus.download.DownloadResources;
|
||||
import net.osmand.plus.download.DownloadValidationManager;
|
||||
import net.osmand.plus.download.IndexItem;
|
||||
import net.osmand.plus.views.GPXLayer;
|
||||
import net.osmand.plus.views.RouteLayer;
|
||||
import net.osmand.render.RenderingRuleProperty;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import static net.osmand.plus.srtmplugin.SRTMPlugin.CONTOUR_DENSITY_ATTR;
|
||||
|
@ -100,13 +91,6 @@ public class ContourLinesMenu {
|
|||
@Override
|
||||
public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter,
|
||||
View view, int itemId, int pos) {
|
||||
/*
|
||||
if (itemId == showZoomLevelStringId) {
|
||||
if (selected) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
return super.onRowItemClick(adapter, view, itemId, pos);
|
||||
}
|
||||
|
||||
|
@ -121,7 +105,7 @@ public class ContourLinesMenu {
|
|||
@Override
|
||||
public void run() {
|
||||
mapActivity.getDashboard().refreshContent(true);
|
||||
refreshMapComplete(mapActivity);
|
||||
SRTMPlugin.refreshMapComplete(mapActivity);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -135,7 +119,7 @@ public class ContourLinesMenu {
|
|||
item.setDescription(plugin.getPrefDescription(app, contourLinesProp, pref));
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
refreshMapComplete(mapActivity);
|
||||
SRTMPlugin.refreshMapComplete(mapActivity);
|
||||
}
|
||||
});
|
||||
} else if (itemId == colorSchemeStringId) {
|
||||
|
@ -147,7 +131,7 @@ public class ContourLinesMenu {
|
|||
item.setDescription(plugin.getPrefDescription(app, colorSchemeProp, colorPref));
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
refreshMapComplete(mapActivity);
|
||||
SRTMPlugin.refreshMapComplete(mapActivity);
|
||||
}
|
||||
});
|
||||
} else if (itemId == R.string.srtm_plugin_name) {
|
||||
|
@ -164,7 +148,7 @@ public class ContourLinesMenu {
|
|||
item.setDescription(plugin.getPrefDescription(app, contourWidthProp, widthPref));
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
refreshMapComplete(mapActivity);
|
||||
SRTMPlugin.refreshMapComplete(mapActivity);
|
||||
}
|
||||
});
|
||||
} else if (contourDensityProp != null && itemId == contourDensityName.hashCode()) {
|
||||
|
@ -176,7 +160,7 @@ public class ContourLinesMenu {
|
|||
item.setDescription(plugin.getPrefDescription(app, contourDensityProp, densityPref));
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
refreshMapComplete(mapActivity);
|
||||
SRTMPlugin.refreshMapComplete(mapActivity);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -268,7 +252,8 @@ public class ContourLinesMenu {
|
|||
try {
|
||||
IndexItem currentDownloadingItem = downloadThread.getCurrentDownloadingItem();
|
||||
int currentDownloadingProgress = downloadThread.getCurrentDownloadingItemProgress();
|
||||
List<IndexItem> srtms = findSrtmIndexItems(app, mapActivity.getMapLocation());
|
||||
List<IndexItem> srtms = DownloadResources.findIndexItemsAt(
|
||||
app, mapActivity.getMapLocation(), DownloadActivityType.SRTM_COUNTRY_FILE);
|
||||
if (srtms.size() > 0) {
|
||||
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
|
||||
.setTitleId(R.string.shared_string_download_map, mapActivity)
|
||||
|
@ -279,8 +264,8 @@ public class ContourLinesMenu {
|
|||
ContextMenuItem.ItemBuilder itemBuilder = new ContextMenuItem.ItemBuilder()
|
||||
.setLayout(R.layout.list_item_icon_and_download)
|
||||
.setTitle(indexItem.getVisibleName(app, app.getRegions(), false))
|
||||
.setDescription(app.getString(R.string.srtm_plugin_name) + " • " + indexItem.getSizeDescription(app))
|
||||
.setIcon(R.drawable.ic_plugin_srtm)
|
||||
.setDescription(DownloadActivityType.SRTM_COUNTRY_FILE.getString(app) + " • " + indexItem.getSizeDescription(app))
|
||||
.setIcon(DownloadActivityType.SRTM_COUNTRY_FILE.getIconResource())
|
||||
.setListener(new ContextMenuAdapter.ItemClickListener() {
|
||||
@Override
|
||||
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked) {
|
||||
|
@ -347,67 +332,4 @@ public class ContourLinesMenu {
|
|||
public static void closeDashboard(MapActivity mapActivity) {
|
||||
mapActivity.getDashboard().hideDashboard(false);
|
||||
}
|
||||
|
||||
public static void refreshMapComplete(final MapActivity activity) {
|
||||
activity.getMyApplication().getResourceManager().getRenderer().clearCache();
|
||||
activity.updateMapSettings();
|
||||
GPXLayer gpx = activity.getMapView().getLayerByClass(GPXLayer.class);
|
||||
if (gpx != null) {
|
||||
gpx.updateLayerStyle();
|
||||
}
|
||||
RouteLayer rte = activity.getMapView().getLayerByClass(RouteLayer.class);
|
||||
if (rte != null) {
|
||||
rte.updateLayerStyle();
|
||||
}
|
||||
activity.getMapView().refreshMap(true);
|
||||
}
|
||||
|
||||
public static List<IndexItem> findSrtmIndexItems(OsmandApplication app, LatLon latLon) throws IOException {
|
||||
|
||||
List<IndexItem> res = new ArrayList<>();
|
||||
OsmandRegions regions = app.getRegions();
|
||||
DownloadIndexesThread downloadThread = app.getDownloadThread();
|
||||
|
||||
int point31x = MapUtils.get31TileNumberX(latLon.getLongitude());
|
||||
int point31y = MapUtils.get31TileNumberY(latLon.getLatitude());
|
||||
|
||||
List<BinaryMapDataObject> mapDataObjects;
|
||||
try {
|
||||
mapDataObjects = regions.queryBbox(point31x, point31x, point31y, point31y);
|
||||
} catch (IOException e) {
|
||||
throw new IOException("Error while calling queryBbox");
|
||||
}
|
||||
if (mapDataObjects != null) {
|
||||
Iterator<BinaryMapDataObject> it = mapDataObjects.iterator();
|
||||
while (it.hasNext()) {
|
||||
BinaryMapDataObject o = it.next();
|
||||
if (o.getTypes() != null) {
|
||||
boolean isRegion = true;
|
||||
for (int i = 0; i < o.getTypes().length; i++) {
|
||||
BinaryMapIndexReader.TagValuePair tp = o.getMapIndex().decodeType(o.getTypes()[i]);
|
||||
if ("boundary".equals(tp.value)) {
|
||||
isRegion = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
WorldRegion downloadRegion = regions.getRegionData(regions.getFullName(o));
|
||||
if (downloadRegion == null || !isRegion || !regions.contain(o, point31x, point31y)) {
|
||||
it.remove();
|
||||
}
|
||||
List<IndexItem> otherIndexItems = new ArrayList<>(downloadThread.getIndexes().getIndexItems(downloadRegion));
|
||||
for (IndexItem indexItem : otherIndexItems) {
|
||||
if (indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE
|
||||
&& !res.contains(indexItem)) {
|
||||
if (indexItem.isDownloaded()) {
|
||||
res.clear();
|
||||
return res;
|
||||
}
|
||||
res.add(indexItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,12 +11,14 @@ import net.osmand.IndexConstants;
|
|||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.data.QuadRect;
|
||||
import net.osmand.data.QuadTree;
|
||||
import net.osmand.data.RotatedTileBox;
|
||||
import net.osmand.map.TileSourceManager.TileSourceTemplate;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.SQLiteTileSource;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
|
||||
import net.osmand.plus.views.MapTileLayer;
|
||||
import net.osmand.plus.views.OsmandMapLayer;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
|
@ -24,6 +26,7 @@ import android.content.ContentValues;
|
|||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
public class HillshadeLayer extends MapTileLayer {
|
||||
|
@ -32,17 +35,30 @@ public class HillshadeLayer extends MapTileLayer {
|
|||
private Map<String, SQLiteTileSource> resources = new LinkedHashMap<String, SQLiteTileSource>();
|
||||
private final static String HILLSHADE_CACHE = "hillshade.cache";
|
||||
private int ZOOM_BOUNDARY = 15;
|
||||
|
||||
private final static int MAX_TRANSPARENCY_ZOOM = 17;
|
||||
private final static int DEFAULT_ALPHA = 100;
|
||||
private final static int MAX_TRANSPARENCY_ALPHA = 20;
|
||||
|
||||
private QuadTree<String> indexedResources = new QuadTree<String>(new QuadRect(0, 0, 1 << (ZOOM_BOUNDARY+1), 1 << (ZOOM_BOUNDARY+1)), 8, 0.55f);
|
||||
|
||||
public HillshadeLayer(MapActivity activity, SRTMPlugin srtmPlugin) {
|
||||
super(false);
|
||||
final OsmandApplication app = activity.getMyApplication();
|
||||
indexHillshadeFiles(app);
|
||||
setAlpha(100);
|
||||
setAlpha(DEFAULT_ALPHA);
|
||||
setMap(createTileSource(activity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings drawSettings) {
|
||||
if (tileBox.getZoom() >= MAX_TRANSPARENCY_ZOOM) {
|
||||
setAlpha(MAX_TRANSPARENCY_ALPHA);
|
||||
} else {
|
||||
setAlpha(DEFAULT_ALPHA);
|
||||
}
|
||||
super.onPrepareBufferImage(canvas, tileBox, drawSettings);
|
||||
}
|
||||
|
||||
private void indexHillshadeFiles(final OsmandApplication app ) {
|
||||
AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void> () {
|
||||
private SQLiteDatabase sqliteDb;
|
||||
|
|
209
OsmAnd/src/net/osmand/plus/srtmplugin/HillshadeMenu.java
Normal file
209
OsmAnd/src/net/osmand/plus/srtmplugin/HillshadeMenu.java
Normal file
|
@ -0,0 +1,209 @@
|
|||
package net.osmand.plus.srtmplugin;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
|
||||
import net.osmand.plus.ContextMenuAdapter;
|
||||
import net.osmand.plus.ContextMenuItem;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.download.DownloadActivityType;
|
||||
import net.osmand.plus.download.DownloadIndexesThread;
|
||||
import net.osmand.plus.download.DownloadResources;
|
||||
import net.osmand.plus.download.DownloadValidationManager;
|
||||
import net.osmand.plus.download.IndexItem;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class HillshadeMenu {
|
||||
private static final String TAG = "HillshadeMenu";
|
||||
|
||||
|
||||
public static ContextMenuAdapter createListAdapter(final MapActivity mapActivity) {
|
||||
SRTMPlugin plugin = OsmandPlugin.getPlugin(SRTMPlugin.class);
|
||||
if (plugin != null && !plugin.isActive() && !plugin.needsInstallation()) {
|
||||
OsmandPlugin.enablePlugin(mapActivity, mapActivity.getMyApplication(), plugin, true);
|
||||
}
|
||||
ContextMenuAdapter adapter = new ContextMenuAdapter();
|
||||
adapter.setDefaultLayoutId(R.layout.list_item_icon_and_menu);
|
||||
createLayersItems(adapter, mapActivity);
|
||||
return adapter;
|
||||
}
|
||||
|
||||
private static void createLayersItems(final ContextMenuAdapter contextMenuAdapter,
|
||||
final MapActivity mapActivity) {
|
||||
final OsmandApplication app = mapActivity.getMyApplication();
|
||||
final OsmandSettings settings = app.getSettings();
|
||||
final SRTMPlugin plugin = OsmandPlugin.getPlugin(SRTMPlugin.class);
|
||||
final boolean srtmEnabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null;
|
||||
if (plugin == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final boolean selected = plugin.isHillShadeLayerEnabled();
|
||||
final int toggleActionStringId = selected ? R.string.shared_string_enabled : R.string.shared_string_disabled;
|
||||
|
||||
ContextMenuAdapter.OnRowItemClick l = new ContextMenuAdapter.OnRowItemClick() {
|
||||
@Override
|
||||
public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter,
|
||||
View view, int itemId, int pos) {
|
||||
return super.onRowItemClick(adapter, view, itemId, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter,
|
||||
final int itemId, final int pos, final boolean isChecked) {
|
||||
if (itemId == toggleActionStringId) {
|
||||
app.runInUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
plugin.toggleHillshade(mapActivity, isChecked, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mapActivity.getDashboard().refreshContent(true);
|
||||
plugin.updateLayers(mapActivity.getMapView(), mapActivity);
|
||||
SRTMPlugin.refreshMapComplete(mapActivity);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
boolean light = settings.isLightContent();
|
||||
int toggleIconColorId;
|
||||
int toggleIconId;
|
||||
if (selected) {
|
||||
toggleIconId = R.drawable.ic_action_view;
|
||||
toggleIconColorId = light ?
|
||||
R.color.color_dialog_buttons_light : R.color.color_dialog_buttons_dark;
|
||||
} else {
|
||||
toggleIconId = R.drawable.ic_action_hide;
|
||||
toggleIconColorId = light ? R.color.icon_color : 0;
|
||||
}
|
||||
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
|
||||
.setTitleId(toggleActionStringId, mapActivity)
|
||||
.setIcon(toggleIconId)
|
||||
.setColor(toggleIconColorId)
|
||||
.setListener(l)
|
||||
.setSelected(selected).createItem());
|
||||
|
||||
if (!srtmEnabled) {
|
||||
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.hillshade_purchase_header, mapActivity)
|
||||
.setCategory(true).setLayout(R.layout.list_group_title_with_switch_light).createItem());
|
||||
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
|
||||
.setTitleId(R.string.srtm_plugin_name, mapActivity)
|
||||
.setLayout(R.layout.list_item_icon_and_right_btn)
|
||||
.setIcon(R.drawable.ic_plugin_srtm)
|
||||
.setColor(R.color.osmand_orange)
|
||||
.setDescription(app.getString(R.string.shared_string_plugin))
|
||||
.setListener(l).createItem());
|
||||
} else {
|
||||
final DownloadIndexesThread downloadThread = app.getDownloadThread();
|
||||
if (!downloadThread.getIndexes().isDownloadedFromInternet) {
|
||||
if (settings.isInternetConnectionAvailable()) {
|
||||
downloadThread.runReloadIndexFiles();
|
||||
}
|
||||
}
|
||||
final boolean downloadIndexes = settings.isInternetConnectionAvailable()
|
||||
&& !downloadThread.getIndexes().isDownloadedFromInternet
|
||||
&& !downloadThread.getIndexes().downloadFromInternetFailed;
|
||||
|
||||
if (downloadIndexes) {
|
||||
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
|
||||
.setTitleId(R.string.shared_string_download_map, mapActivity)
|
||||
.setDescription(app.getString(R.string.hillshade_menu_download_descr))
|
||||
.setCategory(true)
|
||||
.setLayout(R.layout.list_group_title_with_descr).createItem());
|
||||
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
|
||||
.setLayout(R.layout.list_item_icon_and_download)
|
||||
.setTitleId(R.string.downloading_list_indexes, mapActivity)
|
||||
.setLoading(true)
|
||||
.setListener(l).createItem());
|
||||
} else {
|
||||
try {
|
||||
IndexItem currentDownloadingItem = downloadThread.getCurrentDownloadingItem();
|
||||
int currentDownloadingProgress = downloadThread.getCurrentDownloadingItemProgress();
|
||||
List<IndexItem> hillshadeItems = DownloadResources.findIndexItemsAt(
|
||||
app, mapActivity.getMapLocation(), DownloadActivityType.HILLSHADE_FILE);
|
||||
if (hillshadeItems.size() > 0) {
|
||||
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
|
||||
.setTitleId(R.string.shared_string_download_map, mapActivity)
|
||||
.setDescription(app.getString(R.string.hillshade_menu_download_descr))
|
||||
.setCategory(true)
|
||||
.setLayout(R.layout.list_group_title_with_descr).createItem());
|
||||
for (final IndexItem indexItem : hillshadeItems) {
|
||||
ContextMenuItem.ItemBuilder itemBuilder = new ContextMenuItem.ItemBuilder()
|
||||
.setLayout(R.layout.list_item_icon_and_download)
|
||||
.setTitle(indexItem.getVisibleName(app, app.getRegions(), false))
|
||||
.setDescription(DownloadActivityType.HILLSHADE_FILE.getString(app) + " • " + indexItem.getSizeDescription(app))
|
||||
.setIcon(DownloadActivityType.HILLSHADE_FILE.getIconResource())
|
||||
.setListener(new ContextMenuAdapter.ItemClickListener() {
|
||||
@Override
|
||||
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked) {
|
||||
ContextMenuItem item = adapter.getItem(position);
|
||||
if (downloadThread.isDownloading(indexItem)) {
|
||||
downloadThread.cancelDownload(indexItem);
|
||||
if (item != null) {
|
||||
item.setProgress(ContextMenuItem.INVALID_ID);
|
||||
item.setLoading(false);
|
||||
item.setSecondaryIcon(R.drawable.ic_action_import);
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
} else {
|
||||
new DownloadValidationManager(app).startDownload(mapActivity, indexItem);
|
||||
if (item != null) {
|
||||
item.setProgress(ContextMenuItem.INVALID_ID);
|
||||
item.setLoading(true);
|
||||
item.setSecondaryIcon(R.drawable.ic_action_remove_dark);
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.setProgressListener(new ContextMenuAdapter.ProgressListener() {
|
||||
@Override
|
||||
public boolean onProgressChanged(Object progressObject, int progress,
|
||||
ArrayAdapter<ContextMenuItem> adapter,
|
||||
int itemId, int position) {
|
||||
if (progressObject != null && progressObject instanceof IndexItem) {
|
||||
IndexItem progressItem = (IndexItem) progressObject;
|
||||
if (indexItem.compareTo(progressItem) == 0) {
|
||||
ContextMenuItem item = adapter.getItem(position);
|
||||
if (item != null) {
|
||||
item.setProgress(progress);
|
||||
item.setLoading(true);
|
||||
item.setSecondaryIcon(R.drawable.ic_action_remove_dark);
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
if (indexItem == currentDownloadingItem) {
|
||||
itemBuilder.setLoading(true)
|
||||
.setProgress(currentDownloadingProgress)
|
||||
.setSecondaryIcon(R.drawable.ic_action_remove_dark);
|
||||
} else {
|
||||
itemBuilder.setSecondaryIcon(R.drawable.ic_action_import);
|
||||
}
|
||||
contextMenuAdapter.addItem(itemBuilder.createItem());
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,7 +18,9 @@ import net.osmand.plus.R;
|
|||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.SettingsActivity;
|
||||
import net.osmand.plus.dashboard.DashboardOnMap;
|
||||
import net.osmand.plus.views.GPXLayer;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
import net.osmand.plus.views.RouteLayer;
|
||||
import net.osmand.render.RenderingRuleProperty;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
|
@ -130,6 +132,9 @@ public class SRTMPlugin extends OsmandPlugin {
|
|||
if (itemId == R.string.srtm_plugin_name) {
|
||||
mapActivity.getDashboard().setDashboardVisibility(true, DashboardOnMap.DashboardType.CONTOUR_LINES);
|
||||
return false;
|
||||
} else if (itemId == R.string.layer_hillshade) {
|
||||
mapActivity.getDashboard().setDashboardVisibility(true, DashboardOnMap.DashboardType.HILLSHADE);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -163,16 +168,31 @@ public class SRTMPlugin extends OsmandPlugin {
|
|||
item.setSelected(selected);
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
ContourLinesMenu.refreshMapComplete(mapActivity);
|
||||
refreshMapComplete(mapActivity);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
} else if (itemId == R.string.layer_hillshade) {
|
||||
HILLSHADE.set(!HILLSHADE.get());
|
||||
adapter.getItem(position).setColorRes(HILLSHADE.get() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
|
||||
adapter.notifyDataSetChanged();
|
||||
updateLayers(mapView, mapActivity);
|
||||
toggleHillshade(mapActivity, isChecked, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
boolean selected = HILLSHADE.get();
|
||||
SRTMPlugin plugin = OsmandPlugin.getPlugin(SRTMPlugin.class);
|
||||
if (selected && plugin != null && !plugin.isActive() && !plugin.needsInstallation()) {
|
||||
OsmandPlugin.enablePlugin(mapActivity, mapActivity.getMyApplication(), plugin, true);
|
||||
}
|
||||
|
||||
ContextMenuItem item = adapter.getItem(position);
|
||||
if (item != null) {
|
||||
item.setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
|
||||
item.setSelected(selected);
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
updateLayers(mapView, mapActivity);
|
||||
refreshMapComplete(mapActivity);
|
||||
}
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -196,6 +216,7 @@ public class SRTMPlugin extends OsmandPlugin {
|
|||
.setDescription(app.getString(R.string.display_zoom_level, descr))
|
||||
.setColor(contourLinesSelected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID)
|
||||
.setSecondaryIcon(R.drawable.ic_action_additional_option)
|
||||
.setPosition(12)
|
||||
.setListener(listener).createItem());
|
||||
}
|
||||
adapter.addItem(new ContextMenuItem.ItemBuilder()
|
||||
|
@ -203,6 +224,7 @@ public class SRTMPlugin extends OsmandPlugin {
|
|||
.setSelected(HILLSHADE.get())
|
||||
.setColor(HILLSHADE.get() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID)
|
||||
.setIcon(R.drawable.ic_action_hillshade_dark)
|
||||
.setSecondaryIcon(R.drawable.ic_action_additional_option)
|
||||
.setListener(listener)
|
||||
.setPosition(13)
|
||||
.createItem());
|
||||
|
@ -234,6 +256,15 @@ public class SRTMPlugin extends OsmandPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
public void toggleHillshade(final MapActivity activity,
|
||||
final boolean isChecked,
|
||||
final Runnable callback) {
|
||||
HILLSHADE.set(isChecked);
|
||||
if (callback != null) {
|
||||
callback.run();
|
||||
}
|
||||
}
|
||||
|
||||
public String getPrefDescription(final Context ctx, final RenderingRuleProperty p, final OsmandSettings.CommonPreference<String> pref) {
|
||||
if (!Algorithms.isEmpty(pref.get())) {
|
||||
return SettingsActivity.getStringPropertyValue(ctx, pref.get());
|
||||
|
@ -279,7 +310,7 @@ public class SRTMPlugin extends OsmandPlugin {
|
|||
} else {
|
||||
pref.set(possibleValues[which - 1]);
|
||||
}
|
||||
ContourLinesMenu.refreshMapComplete(activity);
|
||||
refreshMapComplete(activity);
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
@ -304,4 +335,17 @@ public class SRTMPlugin extends OsmandPlugin {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static void refreshMapComplete(final MapActivity activity) {
|
||||
activity.getMyApplication().getResourceManager().getRenderer().clearCache();
|
||||
activity.updateMapSettings();
|
||||
GPXLayer gpx = activity.getMapView().getLayerByClass(GPXLayer.class);
|
||||
if (gpx != null) {
|
||||
gpx.updateLayerStyle();
|
||||
}
|
||||
RouteLayer rte = activity.getMapView().getLayerByClass(RouteLayer.class);
|
||||
if (rte != null) {
|
||||
rte.updateLayerStyle();
|
||||
}
|
||||
activity.getMapView().refreshMap(true);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue