slope legend image / download interface in TerrainFragment

This commit is contained in:
veliymolfar 2020-03-13 18:44:21 +02:00
parent 3a546f4d6a
commit 14f7716ec1
3 changed files with 51 additions and 16 deletions

View file

@ -305,11 +305,22 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingStart="@dimen/content_padding" android:paddingStart="@dimen/content_padding"
android:paddingTop="@dimen/list_header_settings_top_margin" android:paddingTop="@dimen/list_header_settings_top_margin"
android:paddingBottom="@dimen/content_padding"
android:paddingEnd="@dimen/content_padding" android:paddingEnd="@dimen/content_padding"
android:text="@string/shared_string_legend" android:text="@string/shared_string_legend"
android:textColor="@color/preference_category_title" android:textColor="@color/preference_category_title"
android:textSize="@dimen/default_desc_text_size" /> android:textSize="@dimen/default_desc_text_size" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_marginStart="@dimen/content_padding"
android:layout_marginEnd="@dimen/content_padding"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="@drawable/img_legend_slope" />
<net.osmand.plus.widgets.TextViewEx <net.osmand.plus.widgets.TextViewEx
android:id="@+id/slope_read_more_tv" android:id="@+id/slope_read_more_tv"
android:layout_width="match_parent" android:layout_width="match_parent"

View file

@ -56,7 +56,7 @@ import static net.osmand.plus.download.DownloadActivityType.SLOPE_FILE;
public class TerrainFragment extends BaseOsmAndFragment implements View.OnClickListener, public class TerrainFragment extends BaseOsmAndFragment implements View.OnClickListener,
Slider.OnSliderTouchListener, Slider.OnChangeListener { Slider.OnSliderTouchListener, Slider.OnChangeListener, DownloadIndexesThread.DownloadEvents {
public static final String TAG = TerrainFragment.class.getSimpleName(); public static final String TAG = TerrainFragment.class.getSimpleName();
private static final Log LOG = PlatformUtil.getLog(TerrainFragment.class.getSimpleName()); private static final Log LOG = PlatformUtil.getLog(TerrainFragment.class.getSimpleName());
@ -100,6 +100,7 @@ public class TerrainFragment extends BaseOsmAndFragment implements View.OnClickL
private Slider zoomSlider; private Slider zoomSlider;
private ObservableListView observableListView; private ObservableListView observableListView;
private ArrayAdapter<ContextMenuItem> listAdapter;
public TerrainFragment() { public TerrainFragment() {
@ -297,14 +298,14 @@ public class TerrainFragment extends BaseOsmAndFragment implements View.OnClickL
} }
private void adjustLegendVisibility(TerrainMode mode) { 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); legendContainer.setVisibility(visibility);
legendBottomDivider.setVisibility(visibility); legendBottomDivider.setVisibility(visibility);
legendTopDivider.setVisibility(visibility); legendTopDivider.setVisibility(visibility);
} }
private void adjustModeButtons(TerrainMode mode) { private void adjustModeButtons(TerrainMode mode) {
if (SLOPE.equals(mode)) { if (mode == SLOPE) {
slopeBtnContainer.setBackgroundResource(R.drawable.btn_border_right_active); slopeBtnContainer.setBackgroundResource(R.drawable.btn_border_right_active);
slopeBtn.setTextColor(nightMode slopeBtn.setTextColor(nightMode
? getResources().getColor(R.color.text_color_primary_dark) ? 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) { private void setupTerrainMode(TerrainMode mode) {
TerrainMode currentMode = srtmPlugin.getTerrainMode(); TerrainMode currentMode = srtmPlugin.getTerrainMode();
if (!currentMode.equals(mode)) { if (currentMode != mode) {
srtmPlugin.setTerrainMode(mode); srtmPlugin.setTerrainMode(mode);
updateUiMode(); updateUiMode();
updateLayers(); updateLayers();
@ -410,9 +411,7 @@ public class TerrainFragment extends BaseOsmAndFragment implements View.OnClickL
int currentDownloadingProgress = downloadThread.getCurrentDownloadingItemProgress(); int currentDownloadingProgress = downloadThread.getCurrentDownloadingItemProgress();
List<IndexItem> hillshadeItems = DownloadResources.findIndexItemsAt( List<IndexItem> hillshadeItems = DownloadResources.findIndexItemsAt(
app, mapActivity.getMapLocation(), app, mapActivity.getMapLocation(),
mode.equals(HILLSHADE) mode == HILLSHADE ? HILLSHADE_FILE : SLOPE_FILE);
? HILLSHADE_FILE
: SLOPE_FILE);
if (hillshadeItems.size() > 0) { if (hillshadeItems.size() > 0) {
downloadContainer.setVisibility(View.VISIBLE); downloadContainer.setVisibility(View.VISIBLE);
downloadTopDivider.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() ContextMenuItem.ItemBuilder itemBuilder = new ContextMenuItem.ItemBuilder()
.setLayout(R.layout.list_item_icon_and_download) .setLayout(R.layout.list_item_icon_and_download)
.setTitle(indexItem.getVisibleName(app, app.getRegions(), false)) .setTitle(indexItem.getVisibleName(app, app.getRegions(), false))
.setDescription(mode.equals(HILLSHADE) .setDescription(mode == HILLSHADE
? HILLSHADE_FILE.getString(app) + "" + indexItem.getSizeDescription(app) ? HILLSHADE_FILE.getString(app) + "" + indexItem.getSizeDescription(app)
: SLOPE_FILE.getString(app) + "" + indexItem.getSizeDescription(app)) : SLOPE_FILE.getString(app) + "" + indexItem.getSizeDescription(app))
.setIcon(mode.equals(HILLSHADE) .setIcon(mode == HILLSHADE ? HILLSHADE_FILE.getIconResource() : SLOPE_FILE.getIconResource())
? HILLSHADE_FILE.getIconResource()
: SLOPE_FILE.getIconResource())
.setListener(new ContextMenuAdapter.ItemClickListener() { .setListener(new ContextMenuAdapter.ItemClickListener() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked, int[] viewCoordinates) { public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked, int[] viewCoordinates) {
@ -491,7 +488,7 @@ public class TerrainFragment extends BaseOsmAndFragment implements View.OnClickL
e.printStackTrace(); e.printStackTrace();
} }
} }
final ArrayAdapter<ContextMenuItem> listAdapter = adapter.createListAdapter(mapActivity, !nightMode); listAdapter = adapter.createListAdapter(mapActivity, !nightMode);
observableListView.setAdapter(listAdapter); observableListView.setAdapter(listAdapter);
observableListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { observableListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override @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<ContextMenuItem> adapter = (ArrayAdapter<ContextMenuItem>) 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();
}
} }

View file

@ -62,7 +62,7 @@ public class TerrainLayer extends MapTileLayer {
if (tileBox.getZoom() >= MAX_TRANSPARENCY_ZOOM) { if (tileBox.getZoom() >= MAX_TRANSPARENCY_ZOOM) {
setAlpha(MAX_TRANSPARENCY_ALPHA); setAlpha(MAX_TRANSPARENCY_ALPHA);
} else { } else {
setAlpha(mode.equals(HILLSHADE) setAlpha(mode == HILLSHADE
? srtmPlugin.getHillshadeTransparency() ? srtmPlugin.getHillshadeTransparency()
: srtmPlugin.getSlopeTransparency()); : srtmPlugin.getSlopeTransparency());
} }
@ -72,7 +72,7 @@ public class TerrainLayer extends MapTileLayer {
private void indexTerrainFiles(final OsmandApplication app) { private void indexTerrainFiles(final OsmandApplication app) {
@SuppressLint("StaticFieldLeak") AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() { @SuppressLint("StaticFieldLeak") AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
private SQLiteDatabase sqliteDb; private SQLiteDatabase sqliteDb;
private String type = mode.equals(HILLSHADE) ? "hillshade" : "slope"; private String type = mode == HILLSHADE ? "hillshade" : "slope";
@Override @Override
protected Void doInBackground(Void... params) { protected Void doInBackground(Void... params) {
@ -80,7 +80,7 @@ public class TerrainLayer extends MapTileLayer {
File cacheDir = app.getCacheDir(); File cacheDir = app.getCacheDir();
// fix http://stackoverflow.com/questions/26937152/workaround-for-nexus-9-sqlite-file-write-operations-on-external-dirs // fix http://stackoverflow.com/questions/26937152/workaround-for-nexus-9-sqlite-file-write-operations-on-external-dirs
sqliteDb = SQLiteDatabase.openDatabase( 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 null, SQLiteDatabase.ENABLE_WRITE_AHEAD_LOGGING
| SQLiteDatabase.CREATE_IF_NECESSARY ); | SQLiteDatabase.CREATE_IF_NECESSARY );
if(sqliteDb.getVersion() == 0) { if(sqliteDb.getVersion() == 0) {
@ -245,7 +245,7 @@ public class TerrainLayer extends MapTileLayer {
@Override @Override
public String getName() { public String getName() {
return mode.equals(HILLSHADE) ? "Hillshade" : "Slope"; return mode == HILLSHADE ? "Hillshade" : "Slope";
} }
@Override @Override