RTL: fix slider on Announcement Time dialog

This commit is contained in:
nazar-kutz 2021-04-22 15:02:10 +03:00
parent 1ac919b8d3
commit 42604ac3b6
5 changed files with 30 additions and 106 deletions

View file

@ -1,15 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/background">
<shape android:shape="rectangle">
<solid android:color="#4d007eb3" />
<corners android:radius="30dp" />
</shape>
</item>
<item android:id="@+id/progress">
<shape android:shape="rectangle">
<solid android:color="@color/color_white" />
<corners android:radius="30dp" />
</shape>
</item>
</layer-list>

View file

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<item android:id="@+id/thump">
<shape android:shape="oval">
<size
android:width="12dp"
android:height="12dp" />
<solid android:color="@color/profile_icon_color_blue_light" />
</shape>
</item>
</layer-list>

View file

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<size
android:width="2dp"
android:height="2dp" />
<solid android:color="#17181A" />
</shape>

View file

@ -62,18 +62,12 @@
osmand:typeface="@string/font_roboto_medium" osmand:typeface="@string/font_roboto_medium"
tools:text="Normal" /> tools:text="Normal" />
<SeekBar <com.google.android.material.slider.Slider
android:id="@+id/seek_bar_arrival" android:id="@+id/arrival_slider"
style="@style/Widget.AppCompat.SeekBar.Discrete"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="@dimen/pages_item_margin" android:layout_marginLeft="@dimen/content_padding"
android:maxHeight="2dp" android:layout_marginRight="@dimen/content_padding" />
android:paddingTop="11dp"
android:paddingBottom="11dp"
osmand:tickMark="@drawable/seekbar_tickmark_announcement_time"
tools:max="3"
tools:progress="1" />
<View <View
android:id="@+id/divider" android:id="@+id/divider"

View file

@ -1,26 +1,24 @@
package net.osmand.plus.settings.bottomsheets; package net.osmand.plus.settings.bottomsheets;
import android.graphics.drawable.ClipDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.LayerDrawable;
import android.os.Bundle; import android.os.Bundle;
import android.view.Gravity;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.SeekBar;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import com.google.android.material.slider.Slider;
import com.google.android.material.slider.Slider.OnChangeListener;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem.Builder;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.routing.data.AnnounceTimeDistances; import net.osmand.plus.routing.data.AnnounceTimeDistances;
import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.ApplicationMode;
@ -33,8 +31,7 @@ import org.apache.commons.logging.Log;
import static net.osmand.plus.settings.bottomsheets.SingleSelectPreferenceBottomSheet.SELECTED_ENTRY_INDEX_KEY; import static net.osmand.plus.settings.bottomsheets.SingleSelectPreferenceBottomSheet.SELECTED_ENTRY_INDEX_KEY;
public class AnnouncementTimeBottomSheet extends BasePreferenceBottomSheet public class AnnouncementTimeBottomSheet extends BasePreferenceBottomSheet {
implements SeekBar.OnSeekBarChangeListener {
public static final String TAG = AnnouncementTimeBottomSheet.class.getSimpleName(); public static final String TAG = AnnouncementTimeBottomSheet.class.getSimpleName();
private static final Log LOG = PlatformUtil.getLog(AnnouncementTimeBottomSheet.class); private static final Log LOG = PlatformUtil.getLog(AnnouncementTimeBottomSheet.class);
@ -46,7 +43,7 @@ public class AnnouncementTimeBottomSheet extends BasePreferenceBottomSheet
private int selectedEntryIndex = -1; private int selectedEntryIndex = -1;
private TextViewEx tvSeekBarLabel; private TextViewEx tvSeekBarLabel;
private SeekBar seekBarArrival; private Slider slider;
private ImageView ivArrow; private ImageView ivArrow;
private TextViewEx tvIntervalsDescr; private TextViewEx tvIntervalsDescr;
@ -110,22 +107,6 @@ public class AnnouncementTimeBottomSheet extends BasePreferenceBottomSheet
dismiss(); dismiss();
} }
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (progress != selectedEntryIndex) {
selectedEntryIndex = progress;
updateViews();
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
private ListPreferenceEx getListPreference() { private ListPreferenceEx getListPreference() {
return (ListPreferenceEx) getPreference(); return (ListPreferenceEx) getPreference();
} }
@ -135,30 +116,40 @@ public class AnnouncementTimeBottomSheet extends BasePreferenceBottomSheet
.inflate(R.layout.bottom_sheet_announcement_time, null); .inflate(R.layout.bottom_sheet_announcement_time, null);
tvSeekBarLabel = rootView.findViewById(R.id.tv_seek_bar_label); tvSeekBarLabel = rootView.findViewById(R.id.tv_seek_bar_label);
seekBarArrival = rootView.findViewById(R.id.seek_bar_arrival); slider = rootView.findViewById(R.id.arrival_slider);
ivArrow = rootView.findViewById(R.id.iv_arrow); ivArrow = rootView.findViewById(R.id.iv_arrow);
tvIntervalsDescr = rootView.findViewById(R.id.tv_interval_descr); tvIntervalsDescr = rootView.findViewById(R.id.tv_interval_descr);
int appModeColor = getAppMode().getProfileColor(nightMode);
setProfileColorToSeekBar(); slider.setValue(selectedEntryIndex);
seekBarArrival.setOnSeekBarChangeListener(this); slider.setValueFrom(0);
seekBarArrival.setProgress(selectedEntryIndex); slider.setValueTo(listPreference.getEntries().length - 1);
seekBarArrival.setMax(listPreference.getEntries().length - 1); slider.setStepSize(1);
rootView.findViewById(R.id.description_container).setOnClickListener(new View.OnClickListener() { slider.addOnChangeListener(new OnChangeListener() {
@Override
public void onValueChange(@NonNull Slider slider, float value, boolean fromUser) {
int intValue = (int) value;
if (intValue != selectedEntryIndex) {
selectedEntryIndex = intValue;
updateViews();
}
}
});
UiUtilities.setupSlider(slider, nightMode, appModeColor, true);
rootView.findViewById(R.id.description_container).setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
toggleDescriptionVisibility(); toggleDescriptionVisibility();
} }
}); });
return new BaseBottomSheetItem.Builder() return new Builder()
.setCustomView(rootView) .setCustomView(rootView)
.create(); .create();
} }
private void updateViews() { private void updateViews() {
seekBarArrival.setProgress(selectedEntryIndex);
tvSeekBarLabel.setText(listPreference.getEntries()[selectedEntryIndex]); tvSeekBarLabel.setText(listPreference.getEntries()[selectedEntryIndex]);
float value = (float) listPreference.getEntryValues()[selectedEntryIndex]; float value = (float) listPreference.getEntryValues()[selectedEntryIndex];
announceTimeDistances.setArrivalDistances(value); announceTimeDistances.setArrivalDistances(value);
tvIntervalsDescr.setText(announceTimeDistances.getIntervalsDescription(app)); tvIntervalsDescr.setText(announceTimeDistances.getIntervalsDescription(app));
@ -170,31 +161,6 @@ public class AnnouncementTimeBottomSheet extends BasePreferenceBottomSheet
AndroidUiHelper.updateVisibility(tvIntervalsDescr, !collapsed); AndroidUiHelper.updateVisibility(tvIntervalsDescr, !collapsed);
} }
private void setProfileColorToSeekBar() {
int color = getAppMode().getProfileColor(nightMode);
LayerDrawable seekBarProgressLayer =
(LayerDrawable) ContextCompat.getDrawable(app, R.drawable.seekbar_progress_announcement_time);
GradientDrawable background = (GradientDrawable) seekBarProgressLayer.findDrawableByLayerId(R.id.background);
background.setColor(color);
background.setAlpha(70);
GradientDrawable progress = (GradientDrawable) seekBarProgressLayer.findDrawableByLayerId(R.id.progress);
progress.setColor(color);
Drawable clippedProgress = new ClipDrawable(progress, Gravity.CENTER_VERTICAL | Gravity.START, 1);
seekBarArrival.setProgressDrawable(new LayerDrawable(new Drawable[] {
background, clippedProgress
}));
LayerDrawable seekBarThumpLayer =
(LayerDrawable) ContextCompat.getDrawable(app, R.drawable.seekbar_thumb_announcement_time);
GradientDrawable thump = (GradientDrawable) seekBarThumpLayer.findDrawableByLayerId(R.id.thump);
thump.setColor(color);
seekBarArrival.setThumb(thump);
}
public static void showInstance(@NonNull FragmentManager fm, String prefKey, Fragment target, public static void showInstance(@NonNull FragmentManager fm, String prefKey, Fragment target,
@Nullable ApplicationMode appMode, boolean usedOnMap) { @Nullable ApplicationMode appMode, boolean usedOnMap) {
try { try {