diff --git a/OsmAnd/res/drawable/bg_dark_transp.xml b/OsmAnd/res/drawable/bg_dark_transp.xml new file mode 100644 index 0000000000..604a548c11 --- /dev/null +++ b/OsmAnd/res/drawable/bg_dark_transp.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/fragment_terrain.xml b/OsmAnd/res/layout/fragment_terrain.xml index a42231bf4b..c53bb69604 100644 --- a/OsmAnd/res/layout/fragment_terrain.xml +++ b/OsmAnd/res/layout/fragment_terrain.xml @@ -1,5 +1,6 @@ - + android:layout_marginTop="@dimen/list_header_settings_top_margin" + android:stepSize="1" + android:theme="@style/Theme.MaterialComponents" + android:valueFrom="0" + android:valueTo="100" + app:haloRadius="@dimen/slider_thumb_halo_size" + app:thumbRadius="@dimen/slider_thumb_size" + app:tickColor="@android:color/transparent" + app:trackHeight="@dimen/slider_track_height" /> @@ -242,17 +253,24 @@ tools:text="3" /> + android:layout_weight="1" + android:stepSize="1" + android:theme="@style/Theme.MaterialComponents" + android:valueFrom="2" + android:valueTo="22" + app:haloRadius="@dimen/slider_thumb_halo_size" + app:thumbRadius="@dimen/slider_thumb_size" + app:trackHeight="@dimen/slider_track_height" /> @@ -358,16 +376,72 @@ android:background="?attr/bg_color" android:orientation="vertical"> - + android:layout_height="wrap_content" + android:layout_margin="@dimen/content_padding_small"> + + + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/res/values/colors.xml b/OsmAnd/res/values/colors.xml index c13c922373..4c1af68f9f 100644 --- a/OsmAnd/res/values/colors.xml +++ b/OsmAnd/res/values/colors.xml @@ -460,5 +460,6 @@ #1A237BFF #80237BFF + #80000000 \ No newline at end of file diff --git a/OsmAnd/res/values/sizes.xml b/OsmAnd/res/values/sizes.xml index ad201fa4c5..bb0d12faf0 100644 --- a/OsmAnd/res/values/sizes.xml +++ b/OsmAnd/res/values/sizes.xml @@ -12,9 +12,9 @@ 64dp 32dp 20dp - 28sp - 64dp - 48dp + 28sp + 64dp + 48dp 58dp 32dp 24dp @@ -26,43 +26,43 @@ 2dp 18dp - 48dp + 48dp 36dp 15dp 32dp - 50dp + 50dp 40dp 240dp 360dp - 56dp + 56dp 78dp 15dp - 2dp - 15dp - 15dp - 14dp - 36dp - 28dp - 12dp - 10dp + 2dp + 15dp + 15dp + 14dp + 36dp + 28dp + 12dp + 10dp 14dp - 28dp - 4dp - 8dp - 90dp - 17dp - 11dp - 6dp - 4dp + 28dp + 4dp + 8dp + 90dp + 17dp + 11dp + 6dp + 4dp 4dp - 0dp + 0dp - 16dp - 8dp + 16dp + 8dp 16dp 10dp @@ -127,7 +127,6 @@ 100dp - 23sp 22sp 15sp @@ -145,17 +144,17 @@ 20dp - 17dp - 14dp - 16dp - 4dp - 76dp - 10dp - -16dp - 4dp - 54dp - 44dp - 54dp + 17dp + 14dp + 16dp + 4dp + 76dp + 10dp + -16dp + 4dp + 54dp + 44dp + 54dp 24dp 48dp 20dp @@ -182,14 +181,14 @@ 40dp 62dp - 12dp - 72dp + 12dp + 72dp - - 19sp - 16sp - 14sp - 12sp + + 19sp + 16sp + 14sp + 12sp 10sp 23sp 15sp @@ -220,7 +219,7 @@ 60dp 64dp - 48dp + 48dp 36dp 360dp @@ -307,9 +306,9 @@ 13dp 15dp - 120dp - 16dp - 40dp + 120dp + 16dp + 40dp 300dp @@ -356,4 +355,8 @@ 72dp 42dp + 8dp + 12dp + 2dp + \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index a00d39e6ad..1204f64d7c 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -16,7 +16,7 @@ Saving new profile Could not back up profile. Hillshade - Turn on to view the layer with shading relief or a map of the slope of the slopes. \n\nYou can find out why such cards are needed and how they work on our website + Enable to view hillshade or slope map. You can read more about this map types on our site Legend Zoom levels Transparency diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index ef884e7c3d..318412a0fa 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -2097,6 +2097,18 @@ public class OsmandSettings { public final CommonPreference HILLSHADE = new BooleanPreference("hillshade_layer", true).makeProfile(); + public final CommonPreference HILLSHADE_MIN_ZOOM = new IntPreference("hillshade_min_zoom", 3).makeProfile(); + + public final CommonPreference HILLSHADE_MAX_ZOOM = new IntPreference("hillshade_max_zoom", 19).makeProfile(); + + public final CommonPreference HILLSHADE_TRANSPARENCY = new IntPreference("hillshade_transparency", 100).makeProfile(); + + public final CommonPreference SLOPE_MIN_ZOOM = new IntPreference("slope_min_zoom", 3).makeProfile(); + + public final CommonPreference SLOPE_MAX_ZOOM = new IntPreference("slope_max_zoom", 19).makeProfile(); + + public final CommonPreference SLOPE_TRANSPARENCY = new IntPreference("slope_transparency", 100).makeProfile(); + public final CommonPreference TERRAIN = new BooleanPreference("terrain_layer", true).makeProfile(); public final CommonPreference TERRAIN_MODE = new EnumIntPreference<>("terrain_mode", TerrainMode.HILLSHADE, TerrainMode.values()).makeProfile(); diff --git a/OsmAnd/src/net/osmand/plus/srtmplugin/HillshadeLayer.java b/OsmAnd/src/net/osmand/plus/srtmplugin/HillshadeLayer.java index bc6091eff9..122ba7eaed 100644 --- a/OsmAnd/src/net/osmand/plus/srtmplugin/HillshadeLayer.java +++ b/OsmAnd/src/net/osmand/plus/srtmplugin/HillshadeLayer.java @@ -38,6 +38,7 @@ public class HillshadeLayer extends MapTileLayer { private final static int MAX_TRANSPARENCY_ZOOM = 17; private final static int DEFAULT_ALPHA = 100; private final static int MAX_TRANSPARENCY_ALPHA = 20; + private SRTMPlugin srtmPlugin; private QuadTree indexedResources = new QuadTree(new QuadRect(0, 0, 1 << (ZOOM_BOUNDARY+1), 1 << (ZOOM_BOUNDARY+1)), 8, 0.55f); @@ -47,6 +48,7 @@ public class HillshadeLayer extends MapTileLayer { indexHillshadeFiles(app); setAlpha(DEFAULT_ALPHA); setMap(createTileSource(activity)); + this.srtmPlugin = srtmPlugin; } @Override @@ -54,7 +56,7 @@ public class HillshadeLayer extends MapTileLayer { if (tileBox.getZoom() >= MAX_TRANSPARENCY_ZOOM) { setAlpha(MAX_TRANSPARENCY_ALPHA); } else { - setAlpha(DEFAULT_ALPHA); + setAlpha(srtmPlugin.getHillshadeTransparency()); } super.onPrepareBufferImage(canvas, tileBox, drawSettings); } diff --git a/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java b/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java index c7b395cc9a..ea23d9b10b 100644 --- a/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java +++ b/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java @@ -74,12 +74,12 @@ public class SRTMPlugin extends OsmandPlugin { this.app = app; settings = app.getSettings(); } - + @Override public int getLogoResourceId() { return R.drawable.ic_plugin_srtm; } - + @Override public int getAssetResourceName() { return R.drawable.contour_lines; @@ -129,13 +129,14 @@ public class SRTMPlugin extends OsmandPlugin { public String getHelpFileName() { return "feature_articles/contour-lines-plugin.html"; } + @Override public boolean init(@NonNull final OsmandApplication app, Activity activity) { OsmandSettings settings = app.getSettings(); CommonPreference pref = settings.getCustomRenderProperty("contourLines"); - if(pref.get().equals("")) { - for(ApplicationMode m : ApplicationMode.allPossibleValues()) { - if(pref.getModeValue(m).equals("")) { + if (pref.get().equals("")) { + for (ApplicationMode m : ApplicationMode.allPossibleValues()) { + if (pref.getModeValue(m).equals("")) { pref.setModeValue(m, "13"); } } @@ -174,6 +175,72 @@ public class SRTMPlugin extends OsmandPlugin { settings.TERRAIN_MODE.set(mode); } + public void setTransparency(int transparency) { + switch (getTerrainMode()) { + case HILLSHADE: + settings.HILLSHADE_TRANSPARENCY.set(transparency); + break; + case SLOPE: + settings.SLOPE_TRANSPARENCY.set(transparency); + break; + } + } + + public void setZoomValues(int minZoom, int maxZoom) { + switch (getTerrainMode()) { + case HILLSHADE: + settings.HILLSHADE_MIN_ZOOM.set(minZoom); + settings.HILLSHADE_MAX_ZOOM.set(maxZoom); + break; + case SLOPE: + settings.SLOPE_MIN_ZOOM.set(minZoom); + settings.SLOPE_MAX_ZOOM.set(maxZoom); + break; + } + } + + public int getTransparency() { + switch (getTerrainMode()) { + case HILLSHADE: + return settings.HILLSHADE_TRANSPARENCY.get(); + case SLOPE: + return settings.SLOPE_TRANSPARENCY.get(); + } + return 100; + } + + public int getHillshadeTransparency(){ + return settings.HILLSHADE_TRANSPARENCY.get(); + } + + public int getHillshadeMinZoom(){ + return settings.HILLSHADE_MIN_ZOOM.get(); + } + public int getHillshadeMaxZoom(){ + return settings.HILLSHADE_MAX_ZOOM.get(); + } + + + public int getMinZoom() { + switch (getTerrainMode()) { + case HILLSHADE: + return settings.HILLSHADE_MIN_ZOOM.get(); + case SLOPE: + return settings.SLOPE_MIN_ZOOM.get(); + } + return 2; + } + + public int getMaxZoom() { + switch (getTerrainMode()) { + case HILLSHADE: + return settings.HILLSHADE_MAX_ZOOM.get(); + case SLOPE: + return settings.SLOPE_MAX_ZOOM.get(); + } + return 19; + } + public static boolean isContourLinesLayerEnabled(OsmandApplication app) { boolean contourLinesEnabled = false; @@ -203,7 +270,7 @@ public class SRTMPlugin extends OsmandPlugin { } } } - + @Override public void registerLayerContextMenuActions(final OsmandMapTileView mapView, ContextMenuAdapter adapter, final MapActivity mapActivity) { ContextMenuAdapter.ItemClickListener listener = new ContextMenuAdapter.OnRowItemClick() { @@ -379,8 +446,8 @@ public class SRTMPlugin extends OsmandPlugin { } public void toggleHillshade(final MapActivity activity, - final boolean isChecked, - final Runnable callback) { + final boolean isChecked, + final Runnable callback) { settings.HILLSHADE.set(isChecked); if (callback != null) { callback.run(); @@ -396,9 +463,9 @@ public class SRTMPlugin extends OsmandPlugin { } public void selectPropertyValue(final MapActivity activity, - final RenderingRuleProperty p, - final OsmandSettings.CommonPreference pref, - final Runnable callback) { + final RenderingRuleProperty p, + final OsmandSettings.CommonPreference pref, + final Runnable callback) { final String propertyDescr = SettingsActivity.getStringPropertyDescription(activity, p.getAttrName(), p.getName()); boolean nightMode = isNightMode(activity, app); diff --git a/OsmAnd/src/net/osmand/plus/srtmplugin/TerrainFragment.java b/OsmAnd/src/net/osmand/plus/srtmplugin/TerrainFragment.java index 795e9b786a..9e1464cedb 100644 --- a/OsmAnd/src/net/osmand/plus/srtmplugin/TerrainFragment.java +++ b/OsmAnd/src/net/osmand/plus/srtmplugin/TerrainFragment.java @@ -1,9 +1,8 @@ package net.osmand.plus.srtmplugin; import android.content.Intent; -import android.graphics.Color; +import android.content.res.ColorStateList; import android.net.Uri; -import android.os.Build; import android.os.Bundle; import android.text.SpannableString; import android.text.Spanned; @@ -12,7 +11,6 @@ import android.text.style.ClickableSpan; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ArrayAdapter; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.LinearLayout; @@ -20,11 +18,12 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.widget.AppCompatSeekBar; import androidx.appcompat.widget.SwitchCompat; +import androidx.core.content.ContextCompat; -import net.osmand.plus.ContextMenuAdapter; -import net.osmand.plus.ContextMenuItem; +import com.google.android.material.slider.Slider; + +import net.osmand.PlatformUtil; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; @@ -33,25 +32,19 @@ import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.BaseOsmAndFragment; -import net.osmand.plus.chooseplan.ChoosePlanDialogFragment; -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.inapp.InAppPurchaseHelper; -import java.io.IOException; +import org.apache.commons.logging.Log; + import java.util.List; -import static net.osmand.plus.srtmplugin.ContourLinesMenu.closeDashboard; -public class TerrainFragment extends BaseOsmAndFragment implements View.OnClickListener { +public class TerrainFragment extends BaseOsmAndFragment implements View.OnClickListener, + Slider.OnSliderTouchListener, Slider.OnChangeListener { public static final String TAG = TerrainFragment.class.getSimpleName(); - - // TODO replace with correct string - private static final String SLOPES_WIKI_URL = "https://osmand.net/features/contour-lines-plugin"; + private static final Log LOG = PlatformUtil.getLog(TerrainFragment.class.getSimpleName()); + private static final String SLOPES_WIKI_URL = "https://en.wikipedia.org/wiki/Grade_(slope)"; private static final String PLUGIN_URL = "https://osmand.net/features/contour-lines-plugin"; private OsmandApplication app; @@ -63,28 +56,33 @@ public class TerrainFragment extends BaseOsmAndFragment implements View.OnClickL private boolean terrainEnabled; private int colorProfile; + private ColorStateList colorProfileStateList; + private ColorStateList colorProfileInactiveStateList; - private TextView downloadDescriptionTv; private TextView emptyStateDescriptionTv; + private TextView downloadDescriptionTv; private TextView transparencyValueTv; private TextView slopeReadMoreTv; private TextView descriptionTv; + private TextView hillshadeBtn; + private TextView minZoomTv; + private TextView maxZoomTv; + private TextView slopeBtn; private TextView titleTv; private TextView stateTv; - private TextView slopeBtn; - private TextView hillshadeBtn; - private FrameLayout slopeBtnContainer; private FrameLayout hillshadeBtnContainer; + private FrameLayout slopeBtnContainer; private SwitchCompat switchCompat; private ImageView iconIv; - private LinearLayout legendContainer; private LinearLayout emptyState; + private LinearLayout legendContainer; private LinearLayout contentContainer; private LinearLayout downloadContainer; - private View legendTopDivider; private View legendBottomDivider; private View titleBottomDivider; - private AppCompatSeekBar transparencySlider; + private View legendTopDivider; + private Slider transparencySlider; + private Slider zoomSlider; public TerrainFragment() { @@ -100,6 +98,9 @@ public class TerrainFragment extends BaseOsmAndFragment implements View.OnClickL srtmEnabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null || InAppPurchaseHelper.isSubscribedToLiveUpdates(app); colorProfile = settings.getApplicationMode().getIconColorInfo().getColor(nightMode); + colorProfileStateList = ColorStateList.valueOf(ContextCompat.getColor(app, colorProfile)); + colorProfileInactiveStateList = ColorStateList + .valueOf(UiUtilities.getColorWithAlpha(colorProfile, 0.6f)); terrainEnabled = srtmPlugin.isTerrainLayerEnabled(); super.onCreate(savedInstanceState); } @@ -126,29 +127,54 @@ public class TerrainFragment extends BaseOsmAndFragment implements View.OnClickL stateTv = root.findViewById(R.id.state_tv); iconIv = root.findViewById(R.id.icon_iv); slopeBtn = root.findViewById(R.id.slope_btn); + zoomSlider = root.findViewById(R.id.zoom_slider); + minZoomTv = root.findViewById(R.id.zoom_value_min); + maxZoomTv = root.findViewById(R.id.zoom_value_max); hillshadeBtn = root.findViewById(R.id.hillshade_btn); slopeBtnContainer = root.findViewById(R.id.slope_btn_container); - hillshadeBtnContainer = root.findViewById(R.id.hillshade_btn_container); downloadContainer = root.findViewById(R.id.download_container); + hillshadeBtnContainer = root.findViewById(R.id.hillshade_btn_container); titleTv.setText(R.string.shared_string_terrain); - String emptyStateText = String.format( - getString(R.string.ltr_or_rtl_combine_via_colon), - getString(R.string.terrain_empty_state_text), - PLUGIN_URL - ); - setupClickableText(emptyStateDescriptionTv, emptyStateText, PLUGIN_URL, PLUGIN_URL); String wikiString = getString(R.string.shared_string_wikipedia); String readMoreText = String.format( getString(R.string.slope_read_more), wikiString ); + String emptyStateText = String.format( + getString(R.string.ltr_or_rtl_combine_via_space), + getString(R.string.terrain_empty_state_text), + PLUGIN_URL + ); setupClickableText(slopeReadMoreTv, readMoreText, wikiString, SLOPES_WIKI_URL); + setupClickableText(emptyStateDescriptionTv, emptyStateText, PLUGIN_URL, PLUGIN_URL); switchCompat.setChecked(terrainEnabled); + hillshadeBtn.setOnClickListener(this); switchCompat.setOnClickListener(this); slopeBtn.setOnClickListener(this); - hillshadeBtn.setOnClickListener(this); + + transparencySlider.setTrackColorInactive(colorProfileInactiveStateList); + transparencySlider.setTrackColorActive(colorProfileStateList); + transparencySlider.setHaloColor(colorProfileInactiveStateList); + transparencySlider.setThumbColor(colorProfileStateList); + transparencySlider.setLabelBehavior(Slider.LABEL_GONE); + zoomSlider.setTrackColorInactive(colorProfileInactiveStateList); + zoomSlider.setTrackColorActive(colorProfileStateList); + zoomSlider.setHaloColor(colorProfileInactiveStateList); + zoomSlider.setThumbColor(colorProfileStateList); + zoomSlider.setLabelBehavior(Slider.LABEL_GONE); + zoomSlider.setTickColor(nightMode + ? ColorStateList.valueOf(R.color.color_white) + : ColorStateList.valueOf(R.color.color_black)); + + transparencySlider.addOnSliderTouchListener(this); + zoomSlider.addOnSliderTouchListener(this); + transparencySlider.addOnChangeListener(this); + zoomSlider.addOnChangeListener(this); + + UiUtilities.setupCompoundButton(switchCompat, nightMode, UiUtilities.CompoundButtonType.PROFILE_DEPENDENT); + updateUiMode(); return root; } @@ -170,15 +196,63 @@ public class TerrainFragment extends BaseOsmAndFragment implements View.OnClickL } } + @Override + public void onStartTrackingTouch(@NonNull Slider slider) { + + } + + @Override + public void onStopTrackingTouch(@NonNull Slider slider) { + switch (slider.getId()) { + case R.id.transparency_slider: + srtmPlugin.setTransparency((int) slider.getValue()); + break; + case R.id.zoom_slider: + List values = slider.getValues(); + srtmPlugin.setZoomValues(values.get(0).intValue(), values.get(1).intValue()); + break; + } + MapActivity mapActivity = (MapActivity) getActivity(); + srtmPlugin.updateLayers(mapActivity.getMapView(), mapActivity); + } + + @Override + public void onValueChange(@NonNull Slider slider, float value, boolean fromUser) { + if (fromUser) { + switch (slider.getId()) { + case R.id.transparency_slider: + String transparency = (int) value + "%"; + transparencyValueTv.setText(transparency); + break; + case R.id.zoom_slider: + List values = slider.getValues(); + minZoomTv.setText(String.valueOf(values.get(0).intValue())); + maxZoomTv.setText(String.valueOf(values.get(1).intValue())); + break; + } + } + } + private void updateUiMode() { TerrainMode mode = srtmPlugin.getTerrainMode(); if (terrainEnabled) { + int transparencyValue = srtmPlugin.getTransparency(); + String transparency = transparencyValue + "%"; + int minZoom = srtmPlugin.getMinZoom(); + int maxZoom = srtmPlugin.getMaxZoom(); iconIv.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_action_hillshade_dark, colorProfile)); stateTv.setText(R.string.shared_string_enabled); + transparencySlider.setValue(transparencyValue); + transparencyValueTv.setText(transparency); + zoomSlider.setValues((float) minZoom, (float) maxZoom); + minZoomTv.setText(String.valueOf(minZoom)); + maxZoomTv.setText(String.valueOf(maxZoom)); switch (mode) { case HILLSHADE: descriptionTv.setText(R.string.hillshade_description); downloadDescriptionTv.setText(R.string.hillshade_download_description); +// zoomSlider.setValueFrom(); +// zoomSlider.setValueTo(); break; case SLOPE: descriptionTv.setText(R.string.slope_description); @@ -255,7 +329,7 @@ public class TerrainFragment extends BaseOsmAndFragment implements View.OnClickL ? getResources().getColor(R.color.active_color_primary_dark) : getResources().getColor(R.color.active_color_primary_light)); } catch (RuntimeException e) { -// LOG.error("Error trying to find index of " + clickableText + " " + e); + LOG.error("Error trying to find index of " + clickableText + " " + e); } } @@ -273,6 +347,4 @@ public class TerrainFragment extends BaseOsmAndFragment implements View.OnClickL updateUiMode(); } } - } -