Replace all SeekBars with Material Components Sliders

This commit is contained in:
Nazar-Kutz 2020-04-21 16:16:27 +03:00
parent 88d554fbd3
commit 32ec37db0b
24 changed files with 234 additions and 433 deletions

View file

@ -183,8 +183,9 @@
android:layout_marginBottom="@dimen/map_button_size" android:layout_marginBottom="@dimen/map_button_size"
android:orientation="horizontal"> android:orientation="horizontal">
<SeekBar <com.google.android.material.slider.Slider
android:id="@+id/map_transparency_seekbar" android:id="@+id/map_transparency_slider"
style="@style/Widget.Styled.Slider"
android:layout_width="@dimen/map_trans_seek_size" android:layout_width="@dimen/map_trans_seek_size"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center"/> android:layout_gravity="center"/>

View file

@ -80,11 +80,13 @@
</LinearLayout> </LinearLayout>
<SeekBar <com.google.android.material.slider.Slider
android:id="@+id/speed_seekbar" android:id="@+id/speed_slider"
style="@style/Widget.Styled.Slider"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:max="100" android:layout_marginLeft="@dimen/content_padding_small"
android:layout_marginRight="@dimen/content_padding_small"
android:paddingBottom="@dimen/content_padding" /> android:paddingBottom="@dimen/content_padding" />
</LinearLayout> </LinearLayout>

View file

@ -34,9 +34,10 @@
android:layout_marginEnd="@dimen/content_padding" android:layout_marginEnd="@dimen/content_padding"
android:layout_marginStart="@dimen/dialog_content_margin" /> android:layout_marginStart="@dimen/dialog_content_margin" />
<SeekBar <com.google.android.material.slider.Slider
android:id="@+id/Speedup" android:id="@+id/Speedup"
android:layout_width="fill_parent" style="@style/Widget.Styled.Slider"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dialog_content_margin" android:layout_marginLeft="@dimen/dialog_content_margin"
android:layout_marginTop="@dimen/map_small_button_margin" android:layout_marginTop="@dimen/map_small_button_margin"

View file

@ -3,14 +3,14 @@
xmlns:osmand="http://schemas.android.com/apk/res-auto" xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical" android:orientation="vertical"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<FrameLayout <FrameLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding">
<net.osmand.plus.widgets.TextViewEx <net.osmand.plus.widgets.TextViewEx
android:id="@android:id/title" android:id="@android:id/title"
@ -36,10 +36,10 @@
<com.google.android.material.slider.Slider <com.google.android.material.slider.Slider
android:id="@+id/slider" android:id="@+id/slider"
style="@style/Widget.MaterialComponents.Slider" style="@style/Widget.Styled.Slider"
android:theme="@style/Theme.MaterialComponents" android:layout_marginLeft="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content" />
osmand:labelBehavior="gone" />
</LinearLayout> </LinearLayout>

View file

@ -21,8 +21,9 @@
android:layout_marginEnd="10dp" android:layout_marginEnd="10dp"
android:layout_marginStart="10dp" /> android:layout_marginStart="10dp" />
<SeekBar <com.google.android.material.slider.Slider
android:id="@+id/ZoomToDownload" android:id="@+id/ZoomToDownload"
style="@style/Widget.Styled.Slider"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/content_padding" android:layout_marginLeft="@dimen/content_padding"

View file

@ -198,17 +198,14 @@
<com.google.android.material.slider.Slider <com.google.android.material.slider.Slider
android:id="@+id/transparency_slider" android:id="@+id/transparency_slider"
style="@style/Widget.MaterialComponents.Slider" style="@style/Widget.Styled.Slider"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingTop="@dimen/list_header_settings_top_margin" android:paddingTop="@dimen/list_header_settings_top_margin"
android:paddingBottom="@dimen/dialog_content_margin" android:paddingBottom="@dimen/dialog_content_margin"
android:stepSize="1" android:layout_marginLeft="@dimen/content_padding"
android:theme="@style/Theme.MaterialComponents" android:layout_marginRight="@dimen/content_padding"
app:haloRadius="@dimen/slider_thumb_size" android:stepSize="1" />
app:thumbRadius="@dimen/slider_thumb_size"
app:tickColor="@android:color/transparent"
app:trackHeight="@dimen/slider_track_height" />
<View <View
android:layout_width="match_parent" android:layout_width="match_parent"
@ -281,16 +278,13 @@
<com.google.android.material.slider.Slider <com.google.android.material.slider.Slider
android:id="@+id/zoom_slider" android:id="@+id/zoom_slider"
style="@style/Widget.MaterialComponents.Slider" style="@style/Widget.Styled.Slider"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:stepSize="1" android:layout_marginLeft="@dimen/content_padding"
android:theme="@style/Theme.MaterialComponents" android:layout_marginRight="@dimen/content_padding"
app:haloRadius="@dimen/slider_thumb_size" android:stepSize="1" />
app:thumbRadius="@dimen/slider_thumb_size"
app:tickColor="@color/color_black"
app:trackHeight="@dimen/slider_track_height" />
<net.osmand.plus.widgets.TextViewEx <net.osmand.plus.widgets.TextViewEx
android:id="@+id/zoom_value_max" android:id="@+id/zoom_value_max"

View file

@ -33,14 +33,16 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
tools:src="@drawable/ic_action_opacity"/> tools:src="@drawable/ic_action_opacity"/>
<SeekBar <com.google.android.material.slider.Slider
android:id="@+id/seekbar" android:id="@+id/slider"
style="?android:attr/progressBarStyleHorizontal" style="@style/Widget.Styled.Slider"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:valueFrom="0"
android:valueTo="255"
android:layout_gravity="center_vertical"
android:layout_marginLeft="@dimen/content_padding_half" android:layout_marginLeft="@dimen/content_padding_half"
android:layout_marginRight="@dimen/content_padding" android:layout_marginRight="@dimen/content_padding"
android:max="255"
android:layout_marginStart="@dimen/content_padding_half" android:layout_marginStart="@dimen/content_padding_half"
android:layout_marginEnd="@dimen/content_padding" /> android:layout_marginEnd="@dimen/content_padding" />
</LinearLayout> </LinearLayout>

View file

@ -98,15 +98,13 @@
android:layout_marginBottom="@dimen/map_button_size" android:layout_marginBottom="@dimen/map_button_size"
android:orientation="horizontal"> android:orientation="horizontal">
<SeekBar <com.google.android.material.slider.Slider
android:id="@+id/map_transparency_seekbar" android:id="@+id/map_transparency_slider"
style="@style/Widget.Styled.Slider"
android:layout_width="@dimen/map_trans_seek_size" android:layout_width="@dimen/map_trans_seek_size"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
android:paddingLeft="6dp" android:layout_margin="@dimen/dashPadding" />
android:paddingRight="6dp"
android:paddingStart="6dp"
android:paddingEnd="6dp" />
</LinearLayout> </LinearLayout>

View file

@ -118,11 +118,15 @@
</LinearLayout> </LinearLayout>
<SeekBar <com.google.android.material.slider.Slider
android:id="@+id/angle_seekbar" android:id="@+id/angle_slider"
style="@style/Widget.Styled.Slider"
android:valueTo="90"
android:stepSize="5"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:max="90" android:layout_marginLeft="@dimen/content_padding_small"
android:layout_marginRight="@dimen/content_padding_small"
android:paddingBottom="@dimen/content_padding" /> android:paddingBottom="@dimen/content_padding" />
</LinearLayout> </LinearLayout>

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/slider_container"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.slider.Slider
android:id="@+id/slider"
style="@style/Widget.Styled.Slider"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</FrameLayout>

View file

@ -361,9 +361,10 @@
<dimen name="setting_select_icon_button_height">128dp</dimen> <dimen name="setting_select_icon_button_height">128dp</dimen>
<dimen name="setting_select_icon_button_width">164dp</dimen> <dimen name="setting_select_icon_button_width">164dp</dimen>
<dimen name="slider_thumb_size">8dp</dimen> <dimen name="slider_thumb_size">6dp</dimen>
<dimen name="slider_thumb_halo_size">12dp</dimen> <dimen name="slider_thumb_halo_size">12dp</dimen>
<dimen name="slider_track_height">2dp</dimen> <dimen name="slider_track_height">2dp</dimen>
<dimen name="mtrl_slider_track_side_padding">@dimen/slider_thumb_size</dimen>
<dimen name="list_item_move_header_min_height">65dp</dimen> <dimen name="list_item_move_header_min_height">65dp</dimen>
</resources> </resources>

View file

@ -112,6 +112,11 @@
<item name="divider_color">@color/divider_color_dark</item> <item name="divider_color">@color/divider_color_dark</item>
</style> </style>
<!-- MaterialComponents Widgets override -->
<style name="Widget.Styled.Slider" parent="Widget.MaterialComponents.Slider">
<item name="android:theme">@style/Theme.MaterialComponents</item>
</style>
<!-- Osmand themes styles --> <!-- Osmand themes styles -->
<style name="OsmandLightTheme" parent="Theme.AppCompat.Light"> <style name="OsmandLightTheme" parent="Theme.AppCompat.Light">
<item name="android:textDirection">locale</item> <item name="android:textDirection">locale</item>

View file

@ -16,7 +16,6 @@ import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.SeekBar;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.ColorRes; import androidx.annotation.ColorRes;
@ -28,6 +27,8 @@ import androidx.appcompat.widget.AppCompatImageView;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import com.google.android.material.slider.Slider;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.plus.activities.HelpActivity; import net.osmand.plus.activities.HelpActivity;
@ -464,33 +465,26 @@ public class ContextMenuAdapter {
} }
} }
if (convertView.findViewById(R.id.seekbar) != null) { Slider slider = (Slider) convertView.findViewById(R.id.slider);
SeekBar seekBar = (SeekBar) convertView.findViewById(R.id.seekbar); if (slider != null) {
if (item.getProgress() != ContextMenuItem.INVALID_ID) { if (item.getProgress() != ContextMenuItem.INVALID_ID) {
seekBar.setProgress(item.getProgress()); slider.setValue(item.getProgress());
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { slider.addOnChangeListener(new Slider.OnChangeListener() {
@Override @Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { public void onValueChange(@NonNull Slider slider, float value, boolean fromUser) {
OnIntegerValueChangedListener listener = item.getIntegerListener(); OnIntegerValueChangedListener listener = item.getIntegerListener();
int progress = (int) value;
item.setProgress(progress); item.setProgress(progress);
if (listener != null && fromUser) { if (listener != null && fromUser) {
listener.onIntegerValueChangedListener(progress); listener.onIntegerValueChangedListener(progress);
} }
} }
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
}); });
seekBar.setVisibility(View.VISIBLE); slider.setVisibility(View.VISIBLE);
} else if (seekBar != null) { } else {
seekBar.setVisibility(View.GONE); slider.setVisibility(View.GONE);
} }
UiUtilities.setupSeekBar(app, seekBar, nightMode, profileDependent); UiUtilities.setupSlider(slider, nightMode, currentModeColor);
} }
View progressBar = convertView.findViewById(R.id.ProgressBar); View progressBar = convertView.findViewById(R.id.ProgressBar);

View file

@ -4,12 +4,14 @@ package net.osmand.plus;
import android.app.Activity; import android.app.Activity;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.view.View; import android.view.View;
import android.widget.SeekBar;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.view.ContextThemeWrapper; import androidx.appcompat.view.ContextThemeWrapper;
import androidx.core.content.ContextCompat;
import com.google.android.material.slider.Slider;
import net.osmand.CallbackWithObject; import net.osmand.CallbackWithObject;
import net.osmand.GPXUtilities; import net.osmand.GPXUtilities;
@ -55,15 +57,17 @@ public class OsmAndLocationSimulation {
if (useGpx) { if (useGpx) {
boolean nightMode = app.getDaynightHelper().isNightModeForMapControls(); boolean nightMode = app.getDaynightHelper().isNightModeForMapControls();
int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
ApplicationMode appMode = app.getSettings().getApplicationMode();
int selectedModeColor = ContextCompat.getColor(app, appMode.getIconColorInfo().getColor(nightMode));
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(ma, themeRes)); AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(ma, themeRes));
builder.setTitle(R.string.animate_route); builder.setTitle(R.string.animate_route);
final View view = ma.getLayoutInflater().inflate(R.layout.animate_route, null); final View view = ma.getLayoutInflater().inflate(R.layout.animate_route, null);
((TextView) view.findViewById(R.id.MinSpeedup)).setText("1"); //$NON-NLS-1$ ((TextView) view.findViewById(R.id.MinSpeedup)).setText("1"); //$NON-NLS-1$
((TextView) view.findViewById(R.id.MaxSpeedup)).setText("4"); //$NON-NLS-1$ ((TextView) view.findViewById(R.id.MaxSpeedup)).setText("4"); //$NON-NLS-1$
final SeekBar speedup = (SeekBar) view.findViewById(R.id.Speedup); final Slider speedup = (Slider) view.findViewById(R.id.Speedup);
speedup.setMax(3); speedup.setValueTo(3);
UiUtilities.setupSeekBar(app, speedup, nightMode, true); UiUtilities.setupSlider(speedup, nightMode, selectedModeColor, true);
builder.setView(view); builder.setView(view);
builder.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { builder.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@ -74,7 +78,7 @@ public class OsmAndLocationSimulation {
@Override @Override
public boolean processResult(GPXUtilities.GPXFile[] result) { public boolean processResult(GPXUtilities.GPXFile[] result) {
GPXRouteParamsBuilder builder = new GPXRouteParamsBuilder(result[0], app.getSettings()); GPXRouteParamsBuilder builder = new GPXRouteParamsBuilder(result[0], app.getSettings());
startAnimationThread(app, builder.getPoints(), true, speedup.getProgress() + 1); startAnimationThread(app, builder.getPoints(), true, speedup.getValue() + 1);
if (runnable != null) { if (runnable != null) {
runnable.run(); runnable.run();
} }

View file

@ -39,6 +39,7 @@ import androidx.core.view.ViewCompat;
import androidx.core.widget.TintableCompoundButton; import androidx.core.widget.TintableCompoundButton;
import com.google.android.material.snackbar.BaseTransientBottomBar; import com.google.android.material.snackbar.BaseTransientBottomBar;
import com.google.android.material.slider.Slider;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.snackbar.SnackbarContentLayout; import com.google.android.material.snackbar.SnackbarContentLayout;
@ -495,32 +496,57 @@ public class UiUtilities {
} }
compoundButton.setBackgroundColor(Color.TRANSPARENT); compoundButton.setBackgroundColor(Color.TRANSPARENT);
} }
public static void setupSeekBar(@NonNull OsmandApplication app, @NonNull SeekBar seekBar, public static ViewGroup createSliderView(@NonNull Context ctx, boolean nightMode) {
boolean nightMode, boolean profileDependent) { return (ViewGroup) getInflater(ctx, nightMode).inflate(R.layout.slider, null, false);
int activeColor = ContextCompat.getColor(app, profileDependent ?
app.getSettings().APPLICATION_MODE.get().getIconColorInfo().getColor(nightMode) :
nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light);
setupSeekBar(seekBar, activeColor, nightMode);
} }
public static void setupSeekBar(@NonNull SeekBar seekBar, @ColorInt int activeColor, boolean nightMode) { public static void setupSlider(Slider slider, boolean nightMode, @ColorInt Integer activeColor) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { setupSlider(slider, nightMode, activeColor, false);
int backgroundColor = ContextCompat.getColor(seekBar.getContext(), nightMode }
? R.color.icon_color_secondary_dark : R.color.icon_color_default_light);
if (seekBar.getProgressDrawable() instanceof LayerDrawable) { public static void setupSlider(Slider slider, boolean nightMode,
LayerDrawable progressDrawable = (LayerDrawable) seekBar.getProgressDrawable(); @ColorInt Integer activeColor, boolean showTicks) {
Drawable background = progressDrawable.findDrawableByLayerId(android.R.id.background); Context ctx = slider.getContext();
if (background != null) { if (ctx == null) {
background.setColorFilter(backgroundColor, PorterDuff.Mode.SRC_IN); return;
}
Drawable progress = progressDrawable.findDrawableByLayerId(android.R.id.progress);
if (progress != null) {
progress.setColorFilter(activeColor, PorterDuff.Mode.SRC_IN);
}
}
seekBar.getThumb().setColorFilter(activeColor, PorterDuff.Mode.SRC_IN);
} }
int themeId = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
ctx = new ContextThemeWrapper(ctx, themeId);
// colors
int[][] states = new int[][] {
new int[] {android.R.attr.state_enabled},
new int[] {-android.R.attr.state_enabled}
};
if (activeColor == null) {
activeColor = AndroidUtils.getColorFromAttr(ctx, R.attr.active_color_basic);
}
int activeDisableColor = getColorWithAlpha(activeColor, 0.25f);
ColorStateList activeCsl = new ColorStateList(states,
new int[] {activeColor, activeDisableColor});
int inactiveColor = AndroidUtils.getColorFromAttr(ctx, R.attr.default_icon_color);
ColorStateList inactiveCsl = new ColorStateList(states,
new int[] {inactiveColor, inactiveColor});
slider.setTrackColorActive(activeCsl);
slider.setTrackColorInactive(inactiveCsl);
slider.setHaloColor(activeCsl);
slider.setThumbColor(activeCsl);
int ticksColor = showTicks ? ContextCompat.getColor(ctx,
nightMode ? R.color.color_black : R.color.color_white) :
Color.TRANSPARENT;
slider.setTickColor(new ColorStateList(states, new int[] {ticksColor, ticksColor}));
// sizes
int thumbRadius = ctx.getResources().getDimensionPixelSize(R.dimen.slider_thumb_size);
int haloRadius = ctx.getResources().getDimensionPixelSize(R.dimen.slider_thumb_halo_size);
int trackHeight = ctx.getResources().getDimensionPixelSize(R.dimen.slider_track_height);
slider.setThumbRadius(thumbRadius);
slider.setHaloRadius(haloRadius);
slider.setTrackHeight(trackHeight);
// label behavior
slider.setLabelBehavior(Slider.LABEL_GONE);
} }
public static void setupDialogButton(boolean nightMode, View buttonView, DialogButtonType buttonType, @StringRes int buttonTextId) { public static void setupDialogButton(boolean nightMode, View buttonView, DialogButtonType buttonType, @StringRes int buttonTextId) {

View file

@ -5,12 +5,14 @@ import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.SeekBar;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import com.google.android.material.slider.Slider;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.data.QuadRect; import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
@ -71,37 +73,28 @@ public class DownloadTilesDialog {
((TextView)view.findViewById(R.id.MinZoom)).setText(zoom+""); //$NON-NLS-1$ ((TextView)view.findViewById(R.id.MinZoom)).setText(zoom+""); //$NON-NLS-1$
((TextView)view.findViewById(R.id.MaxZoom)).setText(max+""); //$NON-NLS-1$ ((TextView)view.findViewById(R.id.MaxZoom)).setText(max+""); //$NON-NLS-1$
final SeekBar seekBar = (SeekBar) view.findViewById(R.id.ZoomToDownload); final Slider slider = (Slider) view.findViewById(R.id.ZoomToDownload);
seekBar.setMax(max - zoom); slider.setValueTo(max - zoom);
seekBar.setProgress((max - zoom) / 2); int progress = (max - zoom) / 2;
slider.setValue(progress);
final TextView downloadText = ((TextView) view.findViewById(R.id.DownloadDescription)); final TextView downloadText = ((TextView) view.findViewById(R.id.DownloadDescription));
final String template = ctx.getString(R.string.tiles_to_download_estimated_size); final String template = ctx.getString(R.string.tiles_to_download_estimated_size);
updateLabel(zoom, rb.getLatLonBounds(), downloadText, template, seekBar.getProgress()); updateLabel(zoom, rb.getLatLonBounds(), downloadText, template, (int) slider.getValue());
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){ slider.addOnChangeListener(new Slider.OnChangeListener() {
@Override @Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { public void onValueChange(@NonNull Slider slider, float value, boolean fromUser) {
updateLabel(zoom, rb.getLatLonBounds(), downloadText, template, progress); updateLabel(zoom, rb.getLatLonBounds(), downloadText, template, (int) value);
} }
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
}); });
builder.setPositiveButton(R.string.shared_string_download, new DialogInterface.OnClickListener(){ builder.setPositiveButton(R.string.shared_string_download, new DialogInterface.OnClickListener(){
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
dialog.dismiss(); dialog.dismiss();
run(zoom, seekBar.getProgress(), rb.getLatLonBounds(), mapSource); run(zoom, (int) slider.getValue(), rb.getLatLonBounds(), mapSource);
} }
}); });
builder.setNegativeButton(R.string.shared_string_cancel, null); builder.setNegativeButton(R.string.shared_string_cancel, null);

View file

@ -31,7 +31,6 @@ import net.osmand.plus.OsmandSettings.OsmandPreference;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.profiles.AppProfileArrayAdapter; import net.osmand.plus.profiles.AppProfileArrayAdapter;
import net.osmand.plus.profiles.ProfileDataObject; import net.osmand.plus.profiles.ProfileDataObject;
import net.osmand.plus.views.SeekBarPreference;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -61,7 +60,6 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
private Map<String, OsmandPreference<Boolean>> booleanPreferences = new LinkedHashMap<String, OsmandPreference<Boolean>>(); private Map<String, OsmandPreference<Boolean>> booleanPreferences = new LinkedHashMap<String, OsmandPreference<Boolean>>();
private Map<String, OsmandPreference<?>> listPreferences = new LinkedHashMap<String, OsmandPreference<?>>(); private Map<String, OsmandPreference<?>> listPreferences = new LinkedHashMap<String, OsmandPreference<?>>();
private Map<String, OsmandPreference<String>> editTextPreferences = new LinkedHashMap<String, OsmandPreference<String>>(); private Map<String, OsmandPreference<String>> editTextPreferences = new LinkedHashMap<String, OsmandPreference<String>>();
private Map<String, OsmandPreference<Integer>> seekBarPreferences = new LinkedHashMap<String, OsmandPreference<Integer>>();
private Map<String, Map<String, ?>> listPrefValues = new LinkedHashMap<String, Map<String, ?>>(); private Map<String, Map<String, ?>> listPrefValues = new LinkedHashMap<String, Map<String, ?>>();
@ -114,13 +112,6 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
booleanPreferences.put(b.getId(), b); booleanPreferences.put(b.getId(), b);
return p; return p;
} }
public void registerSeekBarPreference(OsmandPreference<Integer> b, PreferenceScreen screen) {
SeekBarPreference p = (SeekBarPreference) screen.findPreference(b.getId());
p.setOnPreferenceChangeListener(this);
screenPreferences.put(b.getId(), p);
seekBarPreferences.put(b.getId(), b);
}
public static String getRoutingStringPropertyName(Context ctx, String propertyName, String defValue) { public static String getRoutingStringPropertyName(Context ctx, String propertyName, String defValue) {
try { try {
@ -209,18 +200,6 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
return propertyValue; return propertyValue;
} }
public SeekBarPreference createSeekBarPreference(OsmandPreference<Integer> b, int title, int summary, int dialogTextId, int defValue,
int maxValue) {
SeekBarPreference p = new SeekBarPreference(this, dialogTextId, defValue, maxValue);
p.setTitle(title);
p.setKey(b.getId());
p.setSummary(summary);
p.setOnPreferenceChangeListener(this);
screenPreferences.put(b.getId(), p);
seekBarPreferences.put(b.getId(), b);
return p;
}
public <T> void registerListPreference(OsmandPreference<T> b, PreferenceGroup screen, String[] names, T[] values) { public <T> void registerListPreference(OsmandPreference<T> b, PreferenceGroup screen, String[] names, T[] values) {
ListPreference p = (ListPreference) screen.findPreference(b.getId()); ListPreference p = (ListPreference) screen.findPreference(b.getId());
prepareListPreference(b, names, values, p); prepareListPreference(b, names, values, p);
@ -531,11 +510,6 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
pref.setChecked(b.get()); pref.setChecked(b.get());
} }
for (OsmandPreference<Integer> b : seekBarPreferences.values()) {
SeekBarPreference pref = (SeekBarPreference) screenPreferences.get(b.getId());
pref.setValue(b.get());
}
for (OsmandPreference<?> p : listPreferences.values()) { for (OsmandPreference<?> p : listPreferences.values()) {
ListPreference listPref = (ListPreference) screenPreferences.get(p.getId()); ListPreference listPref = (ListPreference) screenPreferences.get(p.getId());
Map<String, ?> prefValues = listPrefValues.get(p.getId()); Map<String, ?> prefValues = listPrefValues.get(p.getId());
@ -563,13 +537,10 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
// handle boolean preferences // handle boolean preferences
OsmandPreference<Boolean> boolPref = booleanPreferences.get(preference.getKey()); OsmandPreference<Boolean> boolPref = booleanPreferences.get(preference.getKey());
OsmandPreference<Integer> seekPref = seekBarPreferences.get(preference.getKey());
OsmandPreference<Object> listPref = (OsmandPreference<Object>) listPreferences.get(preference.getKey()); OsmandPreference<Object> listPref = (OsmandPreference<Object>) listPreferences.get(preference.getKey());
OsmandPreference<String> editPref = editTextPreferences.get(preference.getKey()); OsmandPreference<String> editPref = editTextPreferences.get(preference.getKey());
if (boolPref != null) { if (boolPref != null) {
boolPref.set((Boolean) newValue); boolPref.set((Boolean) newValue);
} else if (seekPref != null) {
seekPref.set((Integer) newValue);
} else if (editPref != null) { } else if (editPref != null) {
editPref.set((String) newValue); editPref.set((String) newValue);
} else if (listPref != null) { } else if (listPref != null) {

View file

@ -21,8 +21,6 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -30,6 +28,8 @@ import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import com.google.android.material.slider.Slider;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem; import net.osmand.plus.ContextMenuItem;
@ -829,70 +829,71 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
final int[] minValue, final int[] defaultValue, final int[] maxValue, final int[] minValue, final int[] defaultValue, final int[] maxValue,
final int min, final int max, View seekbarView, final boolean nightMode, final int min, final int max, View seekbarView, final boolean nightMode,
final int activeColor) { final int activeColor) {
View seekbarLayout; View sliderLayout;
int titleId; int titleId;
final int[] speedValue; final int[] speedValue;
switch (type) { switch (type) {
case DEFAULT_SPEED_ONLY: case DEFAULT_SPEED_ONLY:
speedValue = defaultValue; speedValue = defaultValue;
seekbarLayout = seekbarView.findViewById(R.id.min_speed_layout); sliderLayout = seekbarView.findViewById(R.id.min_speed_layout);
titleId = R.string.default_speed_setting_title; titleId = R.string.default_speed_setting_title;
break; break;
case MIN_SPEED: case MIN_SPEED:
speedValue = minValue; speedValue = minValue;
seekbarLayout = seekbarView.findViewById(R.id.min_speed_layout); sliderLayout = seekbarView.findViewById(R.id.min_speed_layout);
titleId = R.string.shared_string_min_speed; titleId = R.string.shared_string_min_speed;
break; break;
case MAX_SPEED: case MAX_SPEED:
speedValue = maxValue; speedValue = maxValue;
seekbarLayout = seekbarView.findViewById(R.id.max_speed_layout); sliderLayout = seekbarView.findViewById(R.id.max_speed_layout);
titleId = R.string.shared_string_max_speed; titleId = R.string.shared_string_max_speed;
break; break;
default: default:
speedValue = defaultValue; speedValue = defaultValue;
seekbarLayout = seekbarView.findViewById(R.id.default_speed_layout); sliderLayout = seekbarView.findViewById(R.id.default_speed_layout);
titleId = R.string.default_speed_setting_title; titleId = R.string.default_speed_setting_title;
break; break;
} }
final SeekBar speedSeekBar = seekbarLayout.findViewById(R.id.speed_seekbar); final Slider slider = sliderLayout.findViewById(R.id.speed_slider);
final TextView speedTitleTv = seekbarLayout.findViewById(R.id.speed_title); final TextView speedTitleTv = sliderLayout.findViewById(R.id.speed_title);
final TextView speedMinTv = seekbarLayout.findViewById(R.id.speed_seekbar_min_text); final TextView speedMinTv = sliderLayout.findViewById(R.id.speed_seekbar_min_text);
final TextView speedMaxTv = seekbarLayout.findViewById(R.id.speed_seekbar_max_text); final TextView speedMaxTv = sliderLayout.findViewById(R.id.speed_seekbar_max_text);
final TextView speedUnitsTv = seekbarLayout.findViewById(R.id.speed_units); final TextView speedUnitsTv = sliderLayout.findViewById(R.id.speed_units);
final TextView speedTv = seekbarLayout.findViewById(R.id.speed_text); final TextView speedTv = sliderLayout.findViewById(R.id.speed_text);
speedTitleTv.setText(titleId); speedTitleTv.setText(titleId);
speedMinTv.setText(String.valueOf(min)); speedMinTv.setText(String.valueOf(min));
speedMaxTv.setText(String.valueOf(max)); speedMaxTv.setText(String.valueOf(max));
speedTv.setText(String.valueOf(speedValue[0])); speedTv.setText(String.valueOf(speedValue[0]));
speedUnitsTv.setText(speedUnits); speedUnitsTv.setText(speedUnits);
speedSeekBar.setMax(max - min); slider.setValueTo(max - min);
speedSeekBar.setProgress(Math.max(speedValue[0] - min, 0)); slider.setValue(Math.max(speedValue[0] - min, 0));
speedSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { slider.addOnChangeListener(new Slider.OnChangeListener() {
@Override @Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { public void onValueChange(@NonNull Slider slider, float val, boolean fromUser) {
int progress = (int) val;
int value = progress + min; int value = progress + min;
switch (type) { switch (type) {
case DEFAULT_SPEED: case DEFAULT_SPEED:
case DEFAULT_SPEED_ONLY: case DEFAULT_SPEED_ONLY:
if (value > maxValue[0]) { if (value > maxValue[0]) {
value = maxValue[0]; value = maxValue[0];
speedSeekBar.setProgress(Math.max(value - min, 0)); slider.setValue(Math.max(value - min, 0));
} else if (value < minValue[0]) { } else if (value < minValue[0]) {
value = minValue[0]; value = minValue[0];
speedSeekBar.setProgress(Math.max(value - min, 0)); slider.setValue(Math.max(value - min, 0));
} }
break; break;
case MIN_SPEED: case MIN_SPEED:
if (value > defaultValue[0]) { if (value > defaultValue[0]) {
value = defaultValue[0]; value = defaultValue[0];
speedSeekBar.setProgress(Math.max(value - min, 0)); slider.setValue(Math.max(value - min, 0));
} }
break; break;
case MAX_SPEED: case MAX_SPEED:
if (value < defaultValue[0]) { if (value < defaultValue[0]) {
value = defaultValue[0]; value = defaultValue[0];
speedSeekBar.setProgress(Math.max(value - min, 0)); slider.setValue(Math.max(value - min, 0));
} }
break; break;
default: default:
@ -901,15 +902,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
speedValue[0] = value; speedValue[0] = value;
speedTv.setText(String.valueOf(value)); speedTv.setText(String.valueOf(value));
} }
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
}); });
UiUtilities.setupSeekBar(speedSeekBar, activeColor, nightMode); UiUtilities.setupSlider(slider, nightMode, activeColor);
} }
} }

View file

@ -6,20 +6,22 @@ import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnClickListener;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams; import android.widget.LinearLayout.LayoutParams;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.AppCompatCheckBox; import androidx.appcompat.widget.AppCompatCheckBox;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import com.google.android.material.slider.Slider;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.ValueHolder; import net.osmand.ValueHolder;
@ -506,8 +508,10 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
final int[] minutes, final ValueHolder<Boolean> choice, final int[] minutes, final ValueHolder<Boolean> choice,
final ValueHolder<Integer> v, final ValueHolder<Integer> v,
final boolean showTrackSelection, boolean nightMode) { final boolean showTrackSelection, boolean nightMode) {
ApplicationMode appMode = app.getSettings().getApplicationMode();
int textColorPrimary = ContextCompat.getColor(app, nightMode ? R.color.text_color_primary_dark : R.color.text_color_primary_light); int textColorPrimary = ContextCompat.getColor(app, nightMode ? R.color.text_color_primary_dark : R.color.text_color_primary_light);
int textColorSecondary = ContextCompat.getColor(app, nightMode ? R.color.text_color_secondary_dark : R.color.text_color_secondary_light); int textColorSecondary = ContextCompat.getColor(app, nightMode ? R.color.text_color_secondary_dark : R.color.text_color_secondary_light);
int selectedModeColor = ContextCompat.getColor(uiCtx, appMode.getIconColorInfo().getColor(nightMode));
LinearLayout ll = new LinearLayout(uiCtx); LinearLayout ll = new LinearLayout(uiCtx);
final int dp24 = AndroidUtils.dpToPx(uiCtx, 24f); final int dp24 = AndroidUtils.dpToPx(uiCtx, 24f);
final int dp8 = AndroidUtils.dpToPx(uiCtx, 8f); final int dp8 = AndroidUtils.dpToPx(uiCtx, 8f);
@ -516,22 +520,20 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
tv.setText(String.format(patternMsg, uiCtx.getString(R.string.int_continuosly))); tv.setText(String.format(patternMsg, uiCtx.getString(R.string.int_continuosly)));
tv.setTextColor(textColorSecondary); tv.setTextColor(textColorSecondary);
SeekBar sp = new SeekBar(uiCtx);
sp.setPadding(dp24 + dp8, dp8, dp24 + dp8, dp8);
final int secondsLength = seconds.length; final int secondsLength = seconds.length;
final int minutesLength = minutes.length; final int minutesLength = minutes.length;
sp.setMax(secondsLength + minutesLength - 1); ViewGroup sliderContainer = UiUtilities.createSliderView(uiCtx, nightMode);
sp.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { sliderContainer.setPadding(dp24, dp8, dp24, dp8);
Slider sp = sliderContainer.findViewById(R.id.slider);
UiUtilities.setupSlider(sp, nightMode, selectedModeColor, true);
sp.setValueTo(secondsLength + minutesLength - 1);
sp.setStepSize(1);
sp.addOnChangeListener(new Slider.OnChangeListener() {
@Override @Override
public void onStopTrackingTouch(SeekBar seekBar) { public void onValueChange(@NonNull Slider slider, float value, boolean fromUser) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
String s; String s;
int progress = (int) value;
if(progress == 0) { if(progress == 0) {
s = uiCtx.getString(R.string.int_continuosly); s = uiCtx.getString(R.string.int_continuosly);
v.value = 0; v.value = 0;
@ -545,20 +547,18 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
} }
} }
tv.setText(String.format(patternMsg, s)); tv.setText(String.format(patternMsg, s));
} }
}); });
UiUtilities.setupSeekBar(app, sp, nightMode, true);
for (int i = 0; i < secondsLength + minutesLength - 1; i++) { for (int i = 0; i < secondsLength + minutesLength - 1; i++) {
if (i < secondsLength) { if (i < secondsLength) {
if (v.value <= seconds[i] * 1000) { if (v.value <= seconds[i] * 1000) {
sp.setProgress(i); sp.setValue(i);
break; break;
} }
} else { } else {
if (v.value <= minutes[i - secondsLength] * 1000 * 60) { if (v.value <= minutes[i - secondsLength] * 1000 * 60) {
sp.setProgress(i); sp.setValue(i);
break; break;
} }
} }
@ -566,7 +566,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
ll.setOrientation(LinearLayout.VERTICAL); ll.setOrientation(LinearLayout.VERTICAL);
ll.addView(tv); ll.addView(tv);
ll.addView(sp); ll.addView(sliderContainer);
if (choice != null) { if (choice != null) {
final AppCompatCheckBox cb = new AppCompatCheckBox(uiCtx); final AppCompatCheckBox cb = new AppCompatCheckBox(uiCtx);
cb.setText(R.string.confirm_every_run); cb.setText(R.string.confirm_every_run);

View file

@ -9,9 +9,9 @@ import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
@ -19,6 +19,8 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import androidx.preference.PreferenceViewHolder; import androidx.preference.PreferenceViewHolder;
import com.google.android.material.slider.Slider;
import net.osmand.StateChangedListener; import net.osmand.StateChangedListener;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
@ -287,8 +289,9 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
boolean nightMode = !app.getSettings().isLightContentForMode(mode); boolean nightMode = !app.getSettings().isLightContentForMode(mode);
Context themedContext = UiUtilities.getThemedContext(activity, nightMode); Context themedContext = UiUtilities.getThemedContext(activity, nightMode);
AlertDialog.Builder builder = new AlertDialog.Builder(themedContext); AlertDialog.Builder builder = new AlertDialog.Builder(themedContext);
View seekbarView = LayoutInflater.from(themedContext).inflate(R.layout.recalculation_angle_dialog, null, false); View sliderView = LayoutInflater.from(themedContext).inflate(
builder.setView(seekbarView); R.layout.recalculation_angle_dialog, null, false);
builder.setView(sliderView);
builder.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { builder.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
@ -303,36 +306,28 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
builder.setNegativeButton(R.string.shared_string_cancel, null); builder.setNegativeButton(R.string.shared_string_cancel, null);
int selectedModeColor = ContextCompat.getColor(app, mode.getIconColorInfo().getColor(nightMode)); int selectedModeColor = ContextCompat.getColor(app, mode.getIconColorInfo().getColor(nightMode));
setupAngleSlider(angleValue, seekbarView, nightMode, selectedModeColor); setupAngleSlider(angleValue, sliderView, nightMode, selectedModeColor);
builder.show(); builder.show();
} }
private static void setupAngleSlider(final float[] angleValue, private static void setupAngleSlider(final float[] angleValue,
View seekbarView, View sliderView,
final boolean nightMode, final boolean nightMode,
final int activeColor) { final int activeColor) {
final SeekBar angleBar = seekbarView.findViewById(R.id.angle_seekbar); final Slider angleBar = sliderView.findViewById(R.id.angle_slider);
final TextView angleTv = seekbarView.findViewById(R.id.angle_text); final TextView angleTv = sliderView.findViewById(R.id.angle_text);
angleTv.setText(String.valueOf(angleValue[0])); angleTv.setText(String.valueOf(angleValue[0]));
angleBar.setProgress((int) angleValue[0]); angleBar.setValue((int) angleValue[0]);
angleBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { angleBar.addOnChangeListener(new Slider.OnChangeListener() {
@Override @Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { public void onValueChange(@NonNull Slider slider, float value, boolean fromUser) {
int value = progress - (progress % 5);
angleValue[0] = value; angleValue[0] = value;
angleTv.setText(String.valueOf(value)); angleTv.setText(String.valueOf(value));
} }
@Override
public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {}
}); });
UiUtilities.setupSeekBar(angleBar, activeColor, nightMode); UiUtilities.setupSlider(angleBar, nightMode, activeColor, true);
} }
private void setupSelectRouteRecalcDistance(PreferenceScreen screen) { private void setupSelectRouteRecalcDistance(PreferenceScreen screen) {

View file

@ -71,7 +71,7 @@ public class RecalculateRouteInDeviationBottomSheet extends BooleanPreferenceBot
} }
int contentPaddingSmall = app.getResources().getDimensionPixelSize(R.dimen.content_padding_small); int contentPaddingSmall = app.getResources().getDimensionPixelSize(R.dimen.content_padding_small);
int dialogContentMargin = app.getResources().getDimensionPixelSize(R.dimen.dialog_content_margin); int contentPadding = app.getResources().getDimensionPixelSize(R.dimen.content_padding);
OsmandSettings.MetricsConstants mc = settings.METRIC_SYSTEM.get(); OsmandSettings.MetricsConstants mc = settings.METRIC_SYSTEM.get();
if (mc == OsmandSettings.MetricsConstants.KILOMETERS_AND_METERS) { if (mc == OsmandSettings.MetricsConstants.KILOMETERS_AND_METERS) {
@ -80,14 +80,16 @@ public class RecalculateRouteInDeviationBottomSheet extends BooleanPreferenceBot
entryValues = new Float[]{9.1f, 18.3f, 30.5f, 45.7f, 91.5f, 183.0f, 482.0f, 965.0f, 1609.0f}; entryValues = new Float[]{9.1f, 18.3f, 30.5f, 45.7f, 91.5f, 183.0f, 482.0f, 965.0f, 1609.0f};
} }
final int appModeColor = appMode.getIconColorInfo().getColor(nightMode); final int appModeColorId = appMode.getIconColorInfo().getColor(nightMode);
final int appModeColor = ContextCompat.getColor(app, appModeColorId);
final int activeColor = AndroidUtils.resolveAttribute(app, R.attr.active_color_basic); final int activeColor = AndroidUtils.resolveAttribute(app, R.attr.active_color_basic);
final int disabledColor = AndroidUtils.resolveAttribute(app, android.R.attr.textColorSecondary); final int disabledColor = AndroidUtils.resolveAttribute(app, android.R.attr.textColorSecondary);
String title = getString(R.string.recalculate_route_in_deviation); String title = getString(R.string.recalculate_route_in_deviation);
items.add(new TitleItem(title)); items.add(new TitleItem(title));
final View sliderView = UiUtilities.getInflater(getContext(), nightMode).inflate(R.layout.bottom_sheet_item_slider_with_two_text, null); final View sliderView = UiUtilities.getInflater(getContext(), nightMode)
.inflate(R.layout.bottom_sheet_item_slider_with_two_text, null);
slider = sliderView.findViewById(R.id.slider); slider = sliderView.findViewById(R.id.slider);
tvSliderTitle = sliderView.findViewById(android.R.id.title); tvSliderTitle = sliderView.findViewById(android.R.id.title);
tvSliderTitle.setText(getString(R.string.distance)); tvSliderTitle.setText(getString(R.string.distance));
@ -102,7 +104,7 @@ public class RecalculateRouteInDeviationBottomSheet extends BooleanPreferenceBot
final BottomSheetItemWithCompoundButton[] preferenceBtn = new BottomSheetItemWithCompoundButton[1]; final BottomSheetItemWithCompoundButton[] preferenceBtn = new BottomSheetItemWithCompoundButton[1];
preferenceBtn[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder() preferenceBtn[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder()
.setChecked(enabled) .setChecked(enabled)
.setCompoundButtonColorId(appModeColor) .setCompoundButtonColorId(appModeColorId)
.setTitle(enabled ? on : off) .setTitle(enabled ? on : off)
.setTitleColorId(enabled ? activeColor : disabledColor) .setTitleColorId(enabled ? activeColor : disabledColor)
.setCustomView(getCustomButtonView(enabled)) .setCustomView(getCustomButtonView(enabled))
@ -129,7 +131,7 @@ public class RecalculateRouteInDeviationBottomSheet extends BooleanPreferenceBot
items.add(preferenceBtn[0]); items.add(preferenceBtn[0]);
items.add(new DividerSpaceItem(app, contentPaddingSmall)); items.add(new DividerSpaceItem(app, contentPaddingSmall));
items.add(new LongDescriptionItem(getString(R.string.select_distance_route_will_recalc))); items.add(new LongDescriptionItem(getString(R.string.select_distance_route_will_recalc)));
items.add(new DividerSpaceItem(app, dialogContentMargin)); items.add(new DividerSpaceItem(app, contentPadding));
slider.addOnChangeListener(new Slider.OnChangeListener() { slider.addOnChangeListener(new Slider.OnChangeListener() {
@Override @Override
@ -141,6 +143,7 @@ public class RecalculateRouteInDeviationBottomSheet extends BooleanPreferenceBot
} }
} }
}); });
UiUtilities.setupSlider(slider, nightMode, appModeColor, true);
items.add(new BaseBottomSheetItem.Builder() items.add(new BaseBottomSheetItem.Builder()
.setCustomView(sliderView) .setCustomView(sliderView)
.create()); .create());

View file

@ -2,7 +2,6 @@ package net.osmand.plus.srtmplugin;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.content.res.ColorStateList;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.drawable.GradientDrawable; import android.graphics.drawable.GradientDrawable;
import android.net.Uri; import android.net.Uri;
@ -77,8 +76,8 @@ public class TerrainFragment extends BaseOsmAndFragment implements View.OnClickL
private boolean nightMode; private boolean nightMode;
private boolean terrainEnabled; private boolean terrainEnabled;
private int colorProfileRes;
private int colorProfile; private int colorProfile;
private ColorStateList colorProfileStateList;
private TextView downloadDescriptionTv; private TextView downloadDescriptionTv;
private TextView transparencyValueTv; private TextView transparencyValueTv;
@ -115,8 +114,8 @@ public class TerrainFragment extends BaseOsmAndFragment implements View.OnClickL
uiUtilities = app.getUIUtilities(); uiUtilities = app.getUIUtilities();
nightMode = !settings.isLightContent(); nightMode = !settings.isLightContent();
srtmPlugin = OsmandPlugin.getPlugin(SRTMPlugin.class); srtmPlugin = OsmandPlugin.getPlugin(SRTMPlugin.class);
colorProfile = settings.getApplicationMode().getIconColorInfo().getColor(nightMode); colorProfileRes = settings.getApplicationMode().getIconColorInfo().getColor(nightMode);
colorProfileStateList = ColorStateList.valueOf(ContextCompat.getColor(app, colorProfile)); colorProfile = ContextCompat.getColor(app, colorProfileRes);
terrainEnabled = srtmPlugin.isTerrainLayerEnabled(); terrainEnabled = srtmPlugin.isTerrainLayerEnabled();
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
} }
@ -174,15 +173,8 @@ public class TerrainFragment extends BaseOsmAndFragment implements View.OnClickL
switchCompat.setOnClickListener(this); switchCompat.setOnClickListener(this);
slopeBtn.setOnClickListener(this); slopeBtn.setOnClickListener(this);
transparencySlider.setTrackColorActive(colorProfileStateList); UiUtilities.setupSlider(transparencySlider, nightMode, colorProfile);
transparencySlider.setThumbColor(colorProfileStateList); UiUtilities.setupSlider(zoomSlider, nightMode, colorProfile, true);
transparencySlider.setLabelBehavior(Slider.LABEL_GONE);
zoomSlider.setTrackColorActive(colorProfileStateList);
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); transparencySlider.addOnSliderTouchListener(this);
zoomSlider.addOnSliderTouchListener(this); zoomSlider.addOnSliderTouchListener(this);
@ -264,7 +256,7 @@ public class TerrainFragment extends BaseOsmAndFragment implements View.OnClickL
String transparency = transparencyValue + "%"; String transparency = transparencyValue + "%";
int minZoom = Math.max(srtmPlugin.getTerrainMinZoom(), TERRAIN_MIN_ZOOM); int minZoom = Math.max(srtmPlugin.getTerrainMinZoom(), TERRAIN_MIN_ZOOM);
int maxZoom = Math.min(srtmPlugin.getTerrainMaxZoom(), TERRAIN_MAX_ZOOM); int maxZoom = Math.min(srtmPlugin.getTerrainMaxZoom(), TERRAIN_MAX_ZOOM);
iconIv.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_action_hillshade_dark, colorProfile)); iconIv.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_action_hillshade_dark, colorProfileRes));
stateTv.setText(R.string.shared_string_enabled); stateTv.setText(R.string.shared_string_enabled);
transparencySlider.setValue(transparencyValue); transparencySlider.setValue(transparencyValue);
transparencyValueTv.setText(transparency); transparencyValueTv.setText(transparency);

View file

@ -18,22 +18,25 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.view.ViewCompat; import androidx.core.view.ViewCompat;
import androidx.core.view.ViewPropertyAnimatorCompat; import androidx.core.view.ViewPropertyAnimatorCompat;
import androidx.core.view.ViewPropertyAnimatorListener; import androidx.core.view.ViewPropertyAnimatorListener;
import com.google.android.material.slider.Slider;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.core.android.MapRendererContext; import net.osmand.core.android.MapRendererContext;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmAndAppCustomization; import net.osmand.plus.OsmAndAppCustomization;
import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmAndLocationProvider;
import net.osmand.plus.OsmAndLocationSimulation; import net.osmand.plus.OsmAndLocationSimulation;
@ -97,7 +100,7 @@ public class MapControlsLayer extends OsmandMapLayer {
// private RulerControl rulerControl; // private RulerControl rulerControl;
// private List<MapControls> allControls = new ArrayList<MapControls>(); // private List<MapControls> allControls = new ArrayList<MapControls>();
private SeekBar transparencyBar; private Slider transparencySlider;
private LinearLayout transparencyBarLayout; private LinearLayout transparencyBarLayout;
private static CommonPreference<Integer> transparencySetting; private static CommonPreference<Integer> transparencySetting;
private boolean isTransparencyBarEnabled; private boolean isTransparencyBarEnabled;
@ -921,28 +924,19 @@ public class MapControlsLayer extends OsmandMapLayer {
// /////////////// Transparency bar ///////////////////////// // /////////////// Transparency bar /////////////////////////
private void initTransparencyBar() { private void initTransparencyBar() {
transparencyBarLayout = (LinearLayout) mapActivity.findViewById(R.id.map_transparency_layout); transparencyBarLayout = (LinearLayout) mapActivity.findViewById(R.id.map_transparency_layout);
transparencyBar = (SeekBar) mapActivity.findViewById(R.id.map_transparency_seekbar); transparencySlider = (Slider) mapActivity.findViewById(R.id.map_transparency_slider);
transparencyBar.setMax(255); transparencySlider.setValueTo(255);
if (transparencySetting != null) { if (transparencySetting != null) {
transparencyBar.setProgress(transparencySetting.get()); transparencySlider.setValue(transparencySetting.get());
transparencyBarLayout.setVisibility(View.VISIBLE); transparencyBarLayout.setVisibility(View.VISIBLE);
} else { } else {
transparencyBarLayout.setVisibility(View.GONE); transparencyBarLayout.setVisibility(View.GONE);
} }
transparencyBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { transparencySlider.addOnChangeListener(new Slider.OnChangeListener() {
@Override @Override
public void onStopTrackingTouch(SeekBar seekBar) { public void onValueChange(@NonNull Slider slider, float value, boolean fromUser) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (transparencySetting != null) { if (transparencySetting != null) {
transparencySetting.set(progress); transparencySetting.set((int) value);
mapActivity.getMapView().refreshMap(); mapActivity.getMapView().refreshMap();
} }
} }
@ -961,18 +955,21 @@ public class MapControlsLayer extends OsmandMapLayer {
public void showTransparencyBar(CommonPreference<Integer> transparenPreference, public void showTransparencyBar(CommonPreference<Integer> transparenPreference,
boolean isTransparencyBarEnabled) { boolean isTransparencyBarEnabled) {
this.isTransparencyBarEnabled = isTransparencyBarEnabled; this.isTransparencyBarEnabled = isTransparencyBarEnabled;
ApplicationMode appMode = app.getSettings().getApplicationMode();
if (MapControlsLayer.transparencySetting != transparenPreference) { if (MapControlsLayer.transparencySetting != transparenPreference) {
MapControlsLayer.transparencySetting = transparenPreference; MapControlsLayer.transparencySetting = transparenPreference;
} }
if (transparenPreference != null && isTransparencyBarEnabled) { if (transparenPreference != null && isTransparencyBarEnabled) {
transparencyBarLayout.setVisibility(View.VISIBLE); transparencyBarLayout.setVisibility(View.VISIBLE);
transparencyBar.setProgress(transparenPreference.get()); transparencySlider.setValue(transparenPreference.get());
} else { } else {
transparencyBarLayout.setVisibility(View.GONE); transparencyBarLayout.setVisibility(View.GONE);
} }
boolean nightMode = app.getDaynightHelper().isNightModeForMapControls(); boolean nightMode = app.getDaynightHelper().isNightModeForMapControls();
UiUtilities.setupSeekBar(app, transparencyBar, nightMode, true); int selectedModeColor = ContextCompat.getColor(app,
appMode.getIconColorInfo().getColor(nightMode));
UiUtilities.setupSlider(transparencySlider, nightMode, selectedModeColor);
} }
public void hideTransparencyBar() { public void hideTransparencyBar() {

View file

@ -1,189 +0,0 @@
/*
* Copyright (c) 2010 Jordan Frank, HumanSense Project, McGill University
* Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
* See LICENSE for more information
*/
package net.osmand.plus.views;
import net.osmand.plus.R;
import android.content.Context;
import android.preference.DialogPreference;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.TextView;
/**
* A preference item that uses a seek-bar, or slider to set the value.
*
* @author Jordan Frank <jordan.frank@cs.mcgill.ca>
*
*/
public class SeekBarPreference extends DialogPreference implements
SeekBar.OnSeekBarChangeListener {
private static final String MAX_VALUE_ID = "max";
private static final String DEFAULT_VALUE_ID = "defaultValue";
private static final String DIALOG_TEXT_ID = "text";
private static final String DIALOG_MESSAGE_ID = "dialogMessage";
private static final String ANDROID_NS = "http://schemas.android.com/apk/res/android";
private SeekBar seekBar;
private TextView dialogTextView, valueTextView;
private final Context context;
private final String dialogText, valueText;
private final int defaultValue;
private int maxValue, value, valueToSave = 0;
/**
* Default constructor.
*
* @param context
* The application context.
* @param attrs
* The attribute set, containing the text, title, values, and
* range for the slider dialog.
*/
public SeekBarPreference(final Context context, final AttributeSet attrs) {
super(context, attrs);
this.context = context;
dialogText = context.getResources().getString(
attrs.getAttributeResourceValue(ANDROID_NS, DIALOG_MESSAGE_ID,
R.string.app_name));
valueText = attrs.getAttributeValue(ANDROID_NS, DIALOG_TEXT_ID);
defaultValue = attrs.getAttributeIntValue(ANDROID_NS, DEFAULT_VALUE_ID,
0);
maxValue = attrs.getAttributeIntValue(ANDROID_NS, MAX_VALUE_ID, 100);
}
/**
* Default constructor.
*
* @param context
* The application context.
* @param attrs
* The attribute set, containing the text, title, values, and
* range for the slider dialog.
*/
public SeekBarPreference(final Context context, int dialogTextId, int defValue, int maxValue) {
super(context, null);
this.context = context;
dialogText = context.getResources().getString(dialogTextId);
valueText = null;
this.defaultValue = defValue;
this.maxValue = maxValue;
}
public int getMax() {
return maxValue;
}
public int getValue() {
return value;
}
@Override
protected void onBindDialogView(final View v) {
super.onBindDialogView(v);
seekBar.setMax(maxValue);
seekBar.setProgress(value);
}
@Override
protected View onCreateDialogView() {
LinearLayout.LayoutParams params;
final LinearLayout layout = new LinearLayout(context);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setPadding(6, 6, 6, 6);
dialogTextView = new TextView(context);
if (dialogText != null) {
dialogTextView.setText(dialogText);
}
layout.addView(dialogTextView);
valueTextView = new TextView(context);
valueTextView.setGravity(Gravity.CENTER_HORIZONTAL);
valueTextView.setTextSize(32);
params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
layout.addView(valueTextView, params);
seekBar = new SeekBar(context);
seekBar.setOnSeekBarChangeListener(this);
layout.addView(seekBar, new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
if (shouldPersist()) {
value = getPersistedInt(defaultValue);
}
seekBar.setMax(maxValue);
seekBar.setProgress(value);
return layout;
}
@Override
protected void onDialogClosed(boolean positiveResult) {
super.onDialogClosed(positiveResult);
if(positiveResult){
if (shouldPersist()) {
persistInt(valueToSave);
}
callChangeListener(Integer.valueOf(valueToSave));
} else {
this.valueToSave = value;
}
}
@Override
public void onProgressChanged(final SeekBar seek, final int value,
final boolean fromTouch) {
final String t = String.valueOf(value);
valueTextView.setText(valueText == null ? t : t + valueText);
valueToSave = value;
}
@Override
protected void onSetInitialValue(final boolean restore,
final Object defaultValue) {
super.onSetInitialValue(restore, defaultValue);
if (restore) {
value = shouldPersist() ? getPersistedInt(this.defaultValue) : 0;
} else {
value = (Integer) defaultValue;
}
valueToSave = value;
}
@Override
public void onStartTrackingTouch(final SeekBar seek) {
}
@Override
public void onStopTrackingTouch(final SeekBar seek) {
}
public void setMax(final int max) {
maxValue = max;
}
public void setValue(final int value) {
this.value = value;
this.valueToSave = value;
persistInt(value);
if (seekBar != null) {
seekBar.setProgress(value);
}
}
}