From 14f7716ec13c98605b42daa01bf6a73ecdbbca52 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Fri, 13 Mar 2020 18:44:21 +0200 Subject: [PATCH] slope legend image / download interface in TerrainFragment --- OsmAnd/res/layout/fragment_terrain.xml | 11 +++++ .../plus/srtmplugin/TerrainFragment.java | 48 ++++++++++++++----- .../osmand/plus/srtmplugin/TerrainLayer.java | 8 ++-- 3 files changed, 51 insertions(+), 16 deletions(-) diff --git a/OsmAnd/res/layout/fragment_terrain.xml b/OsmAnd/res/layout/fragment_terrain.xml index d3986d4125..b16eb61657 100644 --- a/OsmAnd/res/layout/fragment_terrain.xml +++ b/OsmAnd/res/layout/fragment_terrain.xml @@ -305,11 +305,22 @@ android:layout_height="wrap_content" android:paddingStart="@dimen/content_padding" android:paddingTop="@dimen/list_header_settings_top_margin" + android:paddingBottom="@dimen/content_padding" android:paddingEnd="@dimen/content_padding" android:text="@string/shared_string_legend" android:textColor="@color/preference_category_title" android:textSize="@dimen/default_desc_text_size" /> + + listAdapter; public TerrainFragment() { @@ -297,14 +298,14 @@ public class TerrainFragment extends BaseOsmAndFragment implements View.OnClickL } private void adjustLegendVisibility(TerrainMode mode) { - int visibility = SLOPE.equals(mode) ? View.VISIBLE : View.GONE; + int visibility = mode == SLOPE ? View.VISIBLE : View.GONE; legendContainer.setVisibility(visibility); legendBottomDivider.setVisibility(visibility); legendTopDivider.setVisibility(visibility); } private void adjustModeButtons(TerrainMode mode) { - if (SLOPE.equals(mode)) { + if (mode == SLOPE) { slopeBtnContainer.setBackgroundResource(R.drawable.btn_border_right_active); slopeBtn.setTextColor(nightMode ? getResources().getColor(R.color.text_color_primary_dark) @@ -362,7 +363,7 @@ public class TerrainFragment extends BaseOsmAndFragment implements View.OnClickL private void setupTerrainMode(TerrainMode mode) { TerrainMode currentMode = srtmPlugin.getTerrainMode(); - if (!currentMode.equals(mode)) { + if (currentMode != mode) { srtmPlugin.setTerrainMode(mode); updateUiMode(); updateLayers(); @@ -410,9 +411,7 @@ public class TerrainFragment extends BaseOsmAndFragment implements View.OnClickL int currentDownloadingProgress = downloadThread.getCurrentDownloadingItemProgress(); List hillshadeItems = DownloadResources.findIndexItemsAt( app, mapActivity.getMapLocation(), - mode.equals(HILLSHADE) - ? HILLSHADE_FILE - : SLOPE_FILE); + mode == HILLSHADE ? HILLSHADE_FILE : SLOPE_FILE); if (hillshadeItems.size() > 0) { downloadContainer.setVisibility(View.VISIBLE); downloadTopDivider.setVisibility(View.VISIBLE); @@ -421,12 +420,10 @@ public class TerrainFragment extends BaseOsmAndFragment implements View.OnClickL ContextMenuItem.ItemBuilder itemBuilder = new ContextMenuItem.ItemBuilder() .setLayout(R.layout.list_item_icon_and_download) .setTitle(indexItem.getVisibleName(app, app.getRegions(), false)) - .setDescription(mode.equals(HILLSHADE) + .setDescription(mode == HILLSHADE ? HILLSHADE_FILE.getString(app) + " • " + indexItem.getSizeDescription(app) : SLOPE_FILE.getString(app) + " • " + indexItem.getSizeDescription(app)) - .setIcon(mode.equals(HILLSHADE) - ? HILLSHADE_FILE.getIconResource() - : SLOPE_FILE.getIconResource()) + .setIcon(mode == HILLSHADE ? HILLSHADE_FILE.getIconResource() : SLOPE_FILE.getIconResource()) .setListener(new ContextMenuAdapter.ItemClickListener() { @Override public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int position, boolean isChecked, int[] viewCoordinates) { @@ -491,7 +488,7 @@ public class TerrainFragment extends BaseOsmAndFragment implements View.OnClickL e.printStackTrace(); } } - final ArrayAdapter listAdapter = adapter.createListAdapter(mapActivity, !nightMode); + listAdapter = adapter.createListAdapter(mapActivity, !nightMode); observableListView.setAdapter(listAdapter); observableListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override @@ -504,4 +501,31 @@ public class TerrainFragment extends BaseOsmAndFragment implements View.OnClickL } }); } + + @Override + public void newDownloadIndexes() { + updateDownloadSection(); + } + + @Override + public void downloadInProgress() { + DownloadIndexesThread downloadThread = getMyApplication().getDownloadThread(); + IndexItem downloadIndexItem = downloadThread.getCurrentDownloadingItem(); + if (downloadIndexItem != null) { + int downloadProgress = downloadThread.getCurrentDownloadingItemProgress(); + ArrayAdapter adapter = (ArrayAdapter) listAdapter; + for (int i = 0; i < adapter.getCount(); i++) { + ContextMenuItem item = adapter.getItem(i); + if (item != null && item.getProgressListener() != null) { + item.getProgressListener().onProgressChanged( + downloadIndexItem, downloadProgress, adapter, (int) adapter.getItemId(i), i); + } + } + } + } + + @Override + public void downloadHasFinished() { + updateDownloadSection(); + } } diff --git a/OsmAnd/src/net/osmand/plus/srtmplugin/TerrainLayer.java b/OsmAnd/src/net/osmand/plus/srtmplugin/TerrainLayer.java index 67b6d18dd5..af9dcb658a 100644 --- a/OsmAnd/src/net/osmand/plus/srtmplugin/TerrainLayer.java +++ b/OsmAnd/src/net/osmand/plus/srtmplugin/TerrainLayer.java @@ -62,7 +62,7 @@ public class TerrainLayer extends MapTileLayer { if (tileBox.getZoom() >= MAX_TRANSPARENCY_ZOOM) { setAlpha(MAX_TRANSPARENCY_ALPHA); } else { - setAlpha(mode.equals(HILLSHADE) + setAlpha(mode == HILLSHADE ? srtmPlugin.getHillshadeTransparency() : srtmPlugin.getSlopeTransparency()); } @@ -72,7 +72,7 @@ public class TerrainLayer extends MapTileLayer { private void indexTerrainFiles(final OsmandApplication app) { @SuppressLint("StaticFieldLeak") AsyncTask task = new AsyncTask() { private SQLiteDatabase sqliteDb; - private String type = mode.equals(HILLSHADE) ? "hillshade" : "slope"; + private String type = mode == HILLSHADE ? "hillshade" : "slope"; @Override protected Void doInBackground(Void... params) { @@ -80,7 +80,7 @@ public class TerrainLayer extends MapTileLayer { File cacheDir = app.getCacheDir(); // fix http://stackoverflow.com/questions/26937152/workaround-for-nexus-9-sqlite-file-write-operations-on-external-dirs sqliteDb = SQLiteDatabase.openDatabase( - new File(cacheDir, mode.equals(HILLSHADE) ? HILLSHADE_CACHE : SLOPE_CACHE).getPath(), + new File(cacheDir, mode == HILLSHADE ? HILLSHADE_CACHE : SLOPE_CACHE).getPath(), null, SQLiteDatabase.ENABLE_WRITE_AHEAD_LOGGING | SQLiteDatabase.CREATE_IF_NECESSARY ); if(sqliteDb.getVersion() == 0) { @@ -245,7 +245,7 @@ public class TerrainLayer extends MapTileLayer { @Override public String getName() { - return mode.equals(HILLSHADE) ? "Hillshade" : "Slope"; + return mode == HILLSHADE ? "Hillshade" : "Slope"; } @Override