refactoring pr
This commit is contained in:
parent
5c4d628889
commit
1dd909b115
24 changed files with 174 additions and 296 deletions
|
@ -947,9 +947,8 @@ public class MapPoiTypes {
|
|||
}
|
||||
|
||||
public void excludeSpeedCameraPoiType() {
|
||||
Iterator<PoiCategory> categoryIter = categories.iterator();
|
||||
while (categoryIter.hasNext()) {
|
||||
Iterator<PoiType> poiIter = categoryIter.next().getPoiTypes().iterator();
|
||||
for (PoiCategory category : categories) {
|
||||
Iterator<PoiType> poiIter = category.getPoiTypes().iterator();
|
||||
while (poiIter.hasNext()) {
|
||||
PoiType poiType = poiIter.next();
|
||||
if ("speed_camera".equals(poiType.getKeyName())) {
|
||||
|
|
|
@ -657,7 +657,7 @@ public class SearchUICore {
|
|||
private List<MapObject> exportedObjects;
|
||||
private List<City> exportedCities;
|
||||
|
||||
private static boolean speedCamerasUninstalled = false;
|
||||
public static boolean speedCamerasUninstalled = false;
|
||||
|
||||
public SearchResultMatcher(ResultMatcher<SearchResult> matcher, SearchPhrase phrase, int request,
|
||||
AtomicInteger requestNumber, int totalLimit) {
|
||||
|
@ -902,10 +902,6 @@ public class SearchUICore {
|
|||
}
|
||||
return "speed_camera".equals(key);
|
||||
}
|
||||
|
||||
public static void setSpeedCamerasUninstalled(boolean speedCamerasUninstalled) {
|
||||
SearchResultMatcher.speedCamerasUninstalled = speedCamerasUninstalled;
|
||||
}
|
||||
}
|
||||
|
||||
private enum ResultCompareStep {
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<include layout="@layout/preference_switch" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/alert_bg"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/content_padding_half"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
tools:background="?attr/activity_background_basic">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/alert_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/bottom_sheet_image_text_margin_start"
|
||||
android:layout_marginLeft="@dimen/bottom_sheet_image_text_margin_start"
|
||||
android:layout_marginEnd="@dimen/content_padding"
|
||||
android:layout_marginRight="@dimen/content_padding"
|
||||
tools:src="@drawable/ic_action_alert"
|
||||
tools:tint="@color/icon_color_default_dark" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/content_padding"
|
||||
android:layout_marginLeft="@dimen/content_padding"
|
||||
android:layout_marginTop="@dimen/content_padding_small"
|
||||
android:layout_marginEnd="@dimen/content_padding"
|
||||
android:layout_marginRight="@dimen/content_padding"
|
||||
android:layout_marginBottom="@dimen/content_padding_small"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/alert_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/content_padding_small"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="@dimen/default_list_text_size"
|
||||
tools:text="@string/speed_cameras_alert" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/alert_subtitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="@dimen/default_list_text_size"
|
||||
tools:text="@string/read_more" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -66,7 +66,8 @@
|
|||
android:title="@string/shared_string_legal" />
|
||||
|
||||
<Preference
|
||||
android:key="uninstall_speed_cameras"
|
||||
android:key="speed_cameras_uninstalled"
|
||||
android:persistent="false"
|
||||
android:layout="@layout/preference_with_descr"
|
||||
android:title="@string/uninstall_speed_cameras"
|
||||
tools:icon="@drawable/ic_speed_camera_disabled" />
|
||||
|
|
|
@ -28,9 +28,17 @@
|
|||
|
||||
<SwitchPreferenceCompat
|
||||
android:key="show_cameras"
|
||||
android:layout="@layout/preference_switch_with_alert"
|
||||
android:layout="@layout/preference_switch"
|
||||
android:title="@string/show_cameras" />
|
||||
|
||||
<Preference
|
||||
android:key="speed_cameras_uninstalled"
|
||||
android:layout="@layout/preference_permission"
|
||||
android:persistent="false"
|
||||
android:summary="@string/read_more"
|
||||
android:title="@string/speed_cameras_alert"
|
||||
tools:icon="@drawable/ic_action_alert" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:key="show_tunnels"
|
||||
android:layout="@layout/preference_switch"
|
||||
|
|
|
@ -46,9 +46,17 @@
|
|||
|
||||
<SwitchPreferenceCompat
|
||||
android:key="speak_cameras"
|
||||
android:layout="@layout/preference_switch_with_alert"
|
||||
android:layout="@layout/preference_switch"
|
||||
android:title="@string/speak_cameras" />
|
||||
|
||||
<Preference
|
||||
android:key="speed_cameras_uninstalled"
|
||||
android:layout="@layout/preference_permission"
|
||||
android:persistent="false"
|
||||
android:summary="@string/read_more"
|
||||
android:title="@string/speed_cameras_alert"
|
||||
tools:icon="@drawable/ic_action_alert" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:key="speak_tunnels"
|
||||
android:layout="@layout/preference_switch"
|
||||
|
|
|
@ -2,27 +2,20 @@ package net.osmand.access;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.view.View;
|
||||
import android.view.accessibility.AccessibilityManager;
|
||||
import android.view.accessibility.AccessibilityManager.AccessibilityStateChangeListener;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.access.AccessibilityMode;
|
||||
import net.osmand.plus.access.RelativeDirectionStyle;
|
||||
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
|
||||
|
@ -215,23 +208,7 @@ public class AccessibilitySettingsFragment extends BaseSettingsFragment implemen
|
|||
super.onBindPreferenceViewHolder(preference, holder);
|
||||
String prefId = preference.getKey();
|
||||
if (ACCESSIBILITY_OPTIONS.equals(prefId)) {
|
||||
View selectableView = holder.itemView.findViewById(R.id.selectable_list_item);
|
||||
if (selectableView != null) {
|
||||
int color = AndroidUtils.getColorFromAttr(app, R.attr.activity_background_color);
|
||||
int selectedColor = UiUtilities.getColorWithAlpha(getActiveProfileColor(), 0.3f);
|
||||
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
|
||||
Drawable bgDrawable = getPaintedIcon(R.drawable.rectangle_rounded, color);
|
||||
Drawable selectable = getPaintedIcon(R.drawable.ripple_rectangle_rounded, selectedColor);
|
||||
Drawable[] layers = {bgDrawable, selectable};
|
||||
AndroidUtils.setBackground(selectableView, new LayerDrawable(layers));
|
||||
} else {
|
||||
Drawable bgDrawable = getPaintedIcon(R.drawable.rectangle_rounded, color);
|
||||
AndroidUtils.setBackground(selectableView, bgDrawable);
|
||||
}
|
||||
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) selectableView.getLayoutParams();
|
||||
params.setMargins(params.leftMargin, AndroidUtils.dpToPx(app, 6), params.rightMargin, params.bottomMargin);
|
||||
}
|
||||
setupPrefRoundedBg(holder);
|
||||
} else if (settings.ACCESSIBILITY_MODE.getId().equals(prefId)) {
|
||||
ImageView imageView = (ImageView) holder.findViewById(android.R.id.icon);
|
||||
if (imageView != null) {
|
||||
|
|
|
@ -406,6 +406,9 @@ public class AppInitializer implements IProgress {
|
|||
return null;
|
||||
}
|
||||
});
|
||||
if (app.getSettings().SPEED_CAMERAS_UNINSTALLED.get()) {
|
||||
app.getPoiTypes().excludeSpeedCameraPoiType();
|
||||
}
|
||||
}
|
||||
|
||||
public void onCreateApplication() {
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
|
@ -639,44 +640,32 @@ public class UiUtilities {
|
|||
}
|
||||
}
|
||||
|
||||
public static SpannableString createSpannableString(@NonNull String text, @NonNull String textToStyle, @NonNull StyleSpan styleSpan) {
|
||||
SpannableString spannable = new SpannableString(text);
|
||||
try {
|
||||
int startIndex = text.indexOf(textToStyle);
|
||||
spannable.setSpan(
|
||||
styleSpan,
|
||||
startIndex,
|
||||
startIndex + textToStyle.length(),
|
||||
Spanned.SPAN_INCLUSIVE_INCLUSIVE);
|
||||
return spannable;
|
||||
} catch (RuntimeException e) {
|
||||
LOG.error("Error trying to find index of " + textToStyle + " " + e);
|
||||
return spannable;
|
||||
}
|
||||
}
|
||||
|
||||
public static SpannableString setWordsMediumFont(@NonNull Context ctx, @NonNull String text, @NonNull String... textToStyle) {
|
||||
public static SpannableString createSpannableString(@NonNull String text, @NonNull StyleSpan styleSpan, @NonNull String... textToStyle) {
|
||||
SpannableString spannable = new SpannableString(text);
|
||||
for (String t : textToStyle) {
|
||||
try {
|
||||
int startIndex = text.indexOf(t);
|
||||
spannable.setSpan(
|
||||
new CustomTypefaceSpan(FontCache.getRobotoMedium(ctx)),
|
||||
startIndex,
|
||||
startIndex + t.length(),
|
||||
Spanned.SPAN_INCLUSIVE_INCLUSIVE);
|
||||
} catch (RuntimeException e) {
|
||||
LOG.error("Error trying to find index of " + t + " " + e);
|
||||
}
|
||||
setSpan(spannable, styleSpan, text, t);
|
||||
}
|
||||
return spannable;
|
||||
}
|
||||
|
||||
public static GradientDrawable getRoundedBackgroundDrawable(@NonNull Context context, @ColorRes int colorRes, int radius) {
|
||||
int r = AndroidUtils.dpToPx(context, radius);
|
||||
GradientDrawable background = new GradientDrawable();
|
||||
background.setColor(ContextCompat.getColor(context, colorRes));
|
||||
background.setCornerRadius(r);
|
||||
return background;
|
||||
private static void setSpan(@NonNull SpannableString spannable, @NonNull Object styleSpan, @NonNull String text, @NonNull String t) {
|
||||
try {
|
||||
int startIndex = text.indexOf(t);
|
||||
spannable.setSpan(
|
||||
styleSpan,
|
||||
startIndex,
|
||||
startIndex + t.length(),
|
||||
Spanned.SPAN_INCLUSIVE_INCLUSIVE);
|
||||
} catch (RuntimeException e) {
|
||||
LOG.error("Error trying to find index of " + t + " " + e);
|
||||
}
|
||||
}
|
||||
|
||||
public static SpannableString createCustomFontSpannable(@NonNull Typeface typeface, @NonNull String text, @NonNull String... textToStyle) {
|
||||
SpannableString spannable = new SpannableString(text);
|
||||
for (String s : textToStyle) {
|
||||
setSpan(spannable, new CustomTypefaceSpan(typeface), text, s);
|
||||
}
|
||||
return spannable;
|
||||
}
|
||||
}
|
|
@ -389,9 +389,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
lockHelper.setLockUIAdapter(this);
|
||||
|
||||
mIsDestroyed = false;
|
||||
if (settings.SPEED_CAMERAS_UNINSTALLED.get()) {
|
||||
app.getPoiTypes().excludeSpeedCameraPoiType();
|
||||
}
|
||||
}
|
||||
|
||||
public void exitFromFullScreen(View view) {
|
||||
|
|
|
@ -6,7 +6,6 @@ import android.content.Intent;
|
|||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.hardware.Camera;
|
||||
import android.media.CamcorderProfile;
|
||||
import android.media.MediaRecorder;
|
||||
|
@ -14,7 +13,6 @@ import android.os.Build;
|
|||
import android.os.Bundle;
|
||||
import android.os.StatFs;
|
||||
import android.text.SpannableString;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
|
@ -28,7 +26,6 @@ import net.osmand.plus.settings.backend.ApplicationMode;
|
|||
import net.osmand.plus.settings.backend.OsmAndAppCustomization;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.helpers.FontCache;
|
||||
import net.osmand.plus.profiles.SelectCopyAppModeBottomSheet;
|
||||
|
@ -466,21 +463,7 @@ public class MultimediaNotesFragment extends BaseSettingsFragment implements Cop
|
|||
super.onBindPreferenceViewHolder(preference, holder);
|
||||
String prefId = preference.getKey();
|
||||
if (CAMERA_PERMISSION.equals(prefId)) {
|
||||
View selectableView = holder.itemView.findViewById(R.id.selectable_list_item);
|
||||
if (selectableView != null) {
|
||||
int color = AndroidUtils.getColorFromAttr(app, R.attr.activity_background_color);
|
||||
int selectedColor = UiUtilities.getColorWithAlpha(getActiveProfileColor(), 0.3f);
|
||||
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
|
||||
Drawable bgDrawable = getPaintedIcon(R.drawable.rectangle_rounded, color);
|
||||
Drawable selectable = getPaintedIcon(R.drawable.ripple_rectangle_rounded, selectedColor);
|
||||
Drawable[] layers = {bgDrawable, selectable};
|
||||
AndroidUtils.setBackground(selectableView, new LayerDrawable(layers));
|
||||
} else {
|
||||
Drawable bgDrawable = getPaintedIcon(R.drawable.rectangle_rounded, color);
|
||||
AndroidUtils.setBackground(selectableView, bgDrawable);
|
||||
}
|
||||
}
|
||||
setupPrefRoundedBg(holder);
|
||||
} else if (OPEN_NOTES_DESCRIPTION.equals(prefId)) {
|
||||
int minHeight = getResources().getDimensionPixelSize(R.dimen.bottom_sheet_list_item_height);
|
||||
holder.itemView.setMinimumHeight(minHeight);
|
||||
|
|
|
@ -17,12 +17,18 @@ import net.osmand.plus.R;
|
|||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||
import net.osmand.plus.helpers.FontCache;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
|
||||
import net.osmand.plus.settings.fragments.OnPreferenceChanged;
|
||||
import net.osmand.plus.widgets.style.CustomTypefaceSpan;
|
||||
import net.osmand.search.SearchUICore.SearchResultMatcher;
|
||||
|
||||
public class SpeedCamerasBottomSheet extends MenuBottomSheetDialogFragment {
|
||||
|
||||
public static final String TAG = SpeedCamerasBottomSheet.class.getName();
|
||||
private OsmandApplication app;
|
||||
private OsmandSettings settings;
|
||||
|
||||
public static void showInstance(@NonNull FragmentManager fm, @Nullable Fragment targetFragment) {
|
||||
if (!fm.isStateSaved()) {
|
||||
|
@ -36,22 +42,17 @@ public class SpeedCamerasBottomSheet extends MenuBottomSheetDialogFragment {
|
|||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
app = requiredMyApplication();
|
||||
settings = app.getSettings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createMenuItems(Bundle savedInstanceState) {
|
||||
View root = UiUtilities.getInflater(app, nightMode).inflate(R.layout.bottom_sheet_speed_cameras, null);
|
||||
((ImageView) root.findViewById(R.id.icon)).setImageDrawable(ContextCompat.getDrawable(requireContext(), R.drawable.img_speed_camera_warning));
|
||||
((ImageView) root.findViewById(R.id.icon)).setImageDrawable(ContextCompat.getDrawable(app, R.drawable.img_speed_camera_warning));
|
||||
((TextView) root.findViewById(R.id.description)).setText(getDescriptionText());
|
||||
items.add(new BaseBottomSheetItem.Builder().setCustomView(root).create());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
UiUtilities.setupDialogButton(nightMode, rightButton, getDismissButtonType(), R.string.keep_active);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRightBottomButtonClick() {
|
||||
setDialogShowed();
|
||||
|
@ -60,17 +61,17 @@ public class SpeedCamerasBottomSheet extends MenuBottomSheetDialogFragment {
|
|||
|
||||
@Override
|
||||
protected void onDismissButtonClickAction() {
|
||||
app.getSettings().SPEED_CAMERAS_UNINSTALLED.set(true);
|
||||
app.getSettings().SPEAK_SPEED_CAMERA.set(false);
|
||||
app.getSettings().SHOW_CAMERAS.set(false);
|
||||
OsmandPreference<Boolean> speedCamUninstalled = settings.SPEED_CAMERAS_UNINSTALLED;
|
||||
speedCamUninstalled.set(true);
|
||||
settings.SPEAK_SPEED_CAMERA.set(false);
|
||||
settings.SHOW_CAMERAS.set(false);
|
||||
app.getPoiTypes().excludeSpeedCameraPoiType();
|
||||
SearchResultMatcher.setSpeedCamerasUninstalled(true);
|
||||
SearchResultMatcher.speedCamerasUninstalled = true;
|
||||
Fragment targetFragment = getTargetFragment();
|
||||
if (targetFragment instanceof OnSpeedCamerasUninstallListener) {
|
||||
((OnSpeedCamerasUninstallListener) targetFragment).onSpeedCamerasUninstalled();
|
||||
if (targetFragment instanceof OnPreferenceChanged) {
|
||||
((OnPreferenceChanged) targetFragment).onPreferenceChanged(speedCamUninstalled.getId());
|
||||
}
|
||||
setDialogShowed();
|
||||
dismiss();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -83,18 +84,19 @@ public class SpeedCamerasBottomSheet extends MenuBottomSheetDialogFragment {
|
|||
return R.string.keep_active;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UiUtilities.DialogButtonType getRightBottomButtonType() {
|
||||
return getDismissButtonType();
|
||||
}
|
||||
|
||||
private SpannableString getDescriptionText() {
|
||||
String keepActive = getString(R.string.keep_active);
|
||||
String uninstall = getString(R.string.shared_string_uninstall);
|
||||
String text = getString(R.string.speed_cameras_legal_descr, keepActive, uninstall);
|
||||
return UiUtilities.setWordsMediumFont(app, text, keepActive, uninstall);
|
||||
return UiUtilities.createCustomFontSpannable(FontCache.getRobotoMedium(app), text, keepActive, uninstall);
|
||||
}
|
||||
|
||||
private void setDialogShowed() {
|
||||
app.getSettings().SPEED_CAMERAS_ALERT_SHOWED.set(true);
|
||||
}
|
||||
|
||||
public interface OnSpeedCamerasUninstallListener {
|
||||
void onSpeedCamerasUninstalled();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.osmand.plus.mapsource;
|
|||
import android.os.Bundle;
|
||||
import android.text.SpannableString;
|
||||
import android.text.Spanned;
|
||||
import android.text.style.StyleSpan;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
@ -81,7 +82,7 @@ public class InputZoomLevelsBottomSheet extends MenuBottomSheetDialogFragment {
|
|||
String mapSource = getString(R.string.map_source);
|
||||
String overlayUnderlay = getString(R.string.pref_overlay);
|
||||
String dialogDesr = getString(dialogDescrRes, mapSource, overlayUnderlay);
|
||||
dialogDescrTv.setText(createSpannableString(dialogDesr, mapSource, overlayUnderlay));
|
||||
dialogDescrTv.setText(UiUtilities.createCustomFontSpannable(FontCache.getRobotoMedium(app), dialogDesr, mapSource, overlayUnderlay));
|
||||
} else {
|
||||
dialogDescrTv.setText(getString(dialogDescrRes));
|
||||
}
|
||||
|
@ -155,23 +156,6 @@ public class InputZoomLevelsBottomSheet extends MenuBottomSheetDialogFragment {
|
|||
return R.string.shared_string_apply;
|
||||
}
|
||||
|
||||
private SpannableString createSpannableString(@NonNull String text, @NonNull String... textToStyle) {
|
||||
SpannableString spannable = new SpannableString(text);
|
||||
for (String t : textToStyle) {
|
||||
try {
|
||||
int startIndex = text.indexOf(t);
|
||||
spannable.setSpan(
|
||||
new CustomTypefaceSpan(FontCache.getRobotoMedium(requireContext())),
|
||||
startIndex,
|
||||
startIndex + t.length(),
|
||||
Spanned.SPAN_INCLUSIVE_INCLUSIVE);
|
||||
} catch (RuntimeException e) {
|
||||
LOG.error("Error trying to find index of " + t + " " + e);
|
||||
}
|
||||
}
|
||||
return spannable;
|
||||
}
|
||||
|
||||
private void setSliderDescrRes(int sliderDescrRes) {
|
||||
this.sliderDescrRes = sliderDescrRes;
|
||||
}
|
||||
|
|
|
@ -890,7 +890,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment
|
|||
String message = String.format(ctx.getString(
|
||||
R.string.quick_actions_delete_text), actionName);
|
||||
SpannableString styledMessage = UiUtilities.createSpannableString(
|
||||
message, actionName, new StyleSpan(Typeface.BOLD));
|
||||
message, new StyleSpan(Typeface.BOLD), actionName);
|
||||
|
||||
ConfirmationBottomSheet.showInstance(ctx.getSupportFragmentManager(), target,
|
||||
ctx.getString(R.string.quick_actions_delete), styledMessage,
|
||||
|
|
|
@ -1256,7 +1256,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
|||
//show "Apply to all profiles" SnackBar
|
||||
String modeName = appMode.toHumanString();
|
||||
String text = app.getString(R.string.changes_applied_to_profile, modeName);
|
||||
SpannableString message = UiUtilities.createSpannableString(text, modeName, new StyleSpan(Typeface.BOLD));
|
||||
SpannableString message = UiUtilities.createSpannableString(text, new StyleSpan(Typeface.BOLD), modeName);
|
||||
Snackbar snackbar = Snackbar.make(containerView, message, Snackbar.LENGTH_LONG)
|
||||
.setAction(R.string.apply_to_all_profiles, new View.OnClickListener() {
|
||||
@Override
|
||||
|
|
|
@ -29,6 +29,7 @@ import net.osmand.plus.poi.NominatimPoiFilter;
|
|||
import net.osmand.plus.poi.PoiFiltersHelper;
|
||||
import net.osmand.plus.poi.PoiUIFilter;
|
||||
import net.osmand.plus.resources.ResourceManager.ResourceListener;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController;
|
||||
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControllerType;
|
||||
import net.osmand.search.SearchUICore;
|
||||
|
@ -65,10 +66,11 @@ public class QuickSearchHelper implements ResourceListener {
|
|||
|
||||
public QuickSearchHelper(OsmandApplication app) {
|
||||
this.app = app;
|
||||
core = new SearchUICore(app.getPoiTypes(), app.getSettings().MAP_PREFERRED_LOCALE.get(),
|
||||
app.getSettings().MAP_TRANSLITERATE_NAMES.get());
|
||||
OsmandSettings settings = app.getSettings();
|
||||
core = new SearchUICore(app.getPoiTypes(), settings.MAP_PREFERRED_LOCALE.get(),
|
||||
settings.MAP_TRANSLITERATE_NAMES.get());
|
||||
app.getResourceManager().addResourceListener(this);
|
||||
SearchResultMatcher.setSpeedCamerasUninstalled(app.getSettings().SPEED_CAMERAS_UNINSTALLED.get());
|
||||
SearchResultMatcher.speedCamerasUninstalled = settings.SPEED_CAMERAS_UNINSTALLED.get();
|
||||
}
|
||||
|
||||
public SearchUICore getCore() {
|
||||
|
|
|
@ -2108,8 +2108,8 @@ public class OsmandSettings {
|
|||
public final OsmandPreference<Boolean> SPEAK_SPEED_CAMERA = new BooleanPreference("speak_cameras", false).makeProfile().cache();
|
||||
public final OsmandPreference<Boolean> SPEAK_TUNNELS = new BooleanPreference("speak_tunnels", false).makeProfile().cache();
|
||||
|
||||
public final OsmandPreference<Boolean> SPEED_CAMERAS_UNINSTALLED = new BooleanPreference("speed_cameras_uninstalled", false).makeGlobal().cache();
|
||||
public final OsmandPreference<Boolean> SPEED_CAMERAS_ALERT_SHOWED = new BooleanPreference("speed_cameras_alert_showed", false).makeGlobal().cache();
|
||||
public final OsmandPreference<Boolean> SPEED_CAMERAS_UNINSTALLED = new BooleanPreference("speed_cameras_uninstalled", false).makeGlobal();
|
||||
public final OsmandPreference<Boolean> SPEED_CAMERAS_ALERT_SHOWED = new BooleanPreference("speed_cameras_alert_showed", false).makeGlobal();
|
||||
|
||||
public final OsmandPreference<Boolean> ANNOUNCE_WPT = new BooleanPreference("announce_wpt", true) {
|
||||
@Override
|
||||
|
|
|
@ -16,6 +16,7 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
|
@ -923,14 +924,40 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
|
|||
}
|
||||
}
|
||||
|
||||
protected void applyPreferenceWithSnackBar(final String prefId, final Serializable newValue) {
|
||||
public void setupSpeedCamerasAlert() {
|
||||
Preference speedCamerasAlert = findPreference(settings.SPEED_CAMERAS_UNINSTALLED.getId());
|
||||
speedCamerasAlert.setIcon(getContentIcon(R.drawable.ic_action_alert));
|
||||
speedCamerasAlert.setVisible(!settings.SPEED_CAMERAS_UNINSTALLED.get());
|
||||
}
|
||||
|
||||
public void setupPrefRoundedBg(PreferenceViewHolder holder) {
|
||||
View selectableView = holder.itemView.findViewById(R.id.selectable_list_item);
|
||||
if (selectableView != null) {
|
||||
int color = AndroidUtils.getColorFromAttr(app, R.attr.activity_background_color);
|
||||
int selectedColor = UiUtilities.getColorWithAlpha(getActiveProfileColor(), 0.3f);
|
||||
|
||||
Drawable bgDrawable = getPaintedIcon(R.drawable.rectangle_rounded, color);
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
|
||||
Drawable selectable = getPaintedIcon(R.drawable.ripple_rectangle_rounded, selectedColor);
|
||||
Drawable[] layers = {bgDrawable, selectable};
|
||||
AndroidUtils.setBackground(selectableView, new LayerDrawable(layers));
|
||||
} else {
|
||||
AndroidUtils.setBackground(selectableView, bgDrawable);
|
||||
}
|
||||
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) selectableView.getLayoutParams();
|
||||
params.setMargins(params.leftMargin, AndroidUtils.dpToPx(app, 6), params.rightMargin, params.bottomMargin);
|
||||
}
|
||||
}
|
||||
|
||||
protected void applyPreferenceWithSnackBar(final String prefId,
|
||||
final Serializable newValue) {
|
||||
onApplyPreferenceChange(prefId, false, newValue);
|
||||
updateSetting(prefId);
|
||||
View containerView = getView();
|
||||
if (containerView != null) {
|
||||
String modeName = appMode.toHumanString();
|
||||
String text = app.getString(R.string.changes_applied_to_profile, modeName);
|
||||
SpannableString message = UiUtilities.createSpannableString(text, modeName, new StyleSpan(Typeface.BOLD));
|
||||
SpannableString message = UiUtilities.createSpannableString(text, new StyleSpan(Typeface.BOLD), modeName);
|
||||
Snackbar snackbar = Snackbar.make(containerView, message, Snackbar.LENGTH_LONG)
|
||||
.setAction(R.string.apply_to_all_profiles, new View.OnClickListener() {
|
||||
@Override
|
||||
|
|
|
@ -17,7 +17,6 @@ import net.osmand.plus.activities.SettingsGeneralActivity;
|
|||
import net.osmand.plus.dialogs.SendAnalyticsBottomSheetDialogFragment;
|
||||
import net.osmand.plus.dialogs.SendAnalyticsBottomSheetDialogFragment.OnSendAnalyticsPrefsUpdate;
|
||||
import net.osmand.plus.dialogs.SpeedCamerasBottomSheet;
|
||||
import net.osmand.plus.dialogs.SpeedCamerasBottomSheet.OnSpeedCamerasUninstallListener;
|
||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.settings.preferences.ListPreferenceEx;
|
||||
|
@ -25,19 +24,14 @@ import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
|
|||
|
||||
|
||||
public class GlobalSettingsFragment extends BaseSettingsFragment
|
||||
implements OnSendAnalyticsPrefsUpdate, OnPreferenceChanged,
|
||||
OnSpeedCamerasUninstallListener {
|
||||
implements OnSendAnalyticsPrefsUpdate, OnPreferenceChanged {
|
||||
|
||||
public static final String TAG = GlobalSettingsFragment.class.getSimpleName();
|
||||
|
||||
private static final String SEND_ANONYMOUS_DATA_PREF_ID = "send_anonymous_data";
|
||||
private static final String DIALOGS_AND_NOTIFICATIONS_PREF_ID = "dialogs_and_notifications";
|
||||
private static final String UNINSTALL_SPEED_CAMERAS_PREF_ID = "uninstall_speed_cameras";
|
||||
private static final String LEGAL_CATEGORY_ID = "legal";
|
||||
|
||||
private Preference uninstallSpeedCameras;
|
||||
private PreferenceCategory legalCategory;
|
||||
|
||||
@Override
|
||||
protected void setupPreferences() {
|
||||
setupDefaultAppModePref();
|
||||
|
@ -47,12 +41,8 @@ public class GlobalSettingsFragment extends BaseSettingsFragment
|
|||
setupSendAnonymousDataPref();
|
||||
setupDialogsAndNotificationsPref();
|
||||
setupEnableProxyPref();
|
||||
legalCategory = (PreferenceCategory) findPreference(LEGAL_CATEGORY_ID);
|
||||
uninstallSpeedCameras = (Preference) findPreference(UNINSTALL_SPEED_CAMERAS_PREF_ID);
|
||||
uninstallSpeedCameras.setIcon(getPersistentPrefIcon(R.drawable.ic_speed_camera_disabled));
|
||||
if (settings.SPEED_CAMERAS_UNINSTALLED.get()) {
|
||||
onSpeedCamerasUninstalled();
|
||||
}
|
||||
setupLegalCategory();
|
||||
setupUninstallSpeedCamerasPref();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -117,6 +107,9 @@ public class GlobalSettingsFragment extends BaseSettingsFragment
|
|||
app.checkPreferredLocale();
|
||||
app.restartApp(activity);
|
||||
}
|
||||
} else if (prefId.equals(settings.SPEED_CAMERAS_UNINSTALLED.getId())) {
|
||||
setupLegalCategory();
|
||||
setupUninstallSpeedCamerasPref();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,7 +121,7 @@ public class GlobalSettingsFragment extends BaseSettingsFragment
|
|||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
String prefId = preference.getKey();
|
||||
if (UNINSTALL_SPEED_CAMERAS_PREF_ID.equals(prefId)) {
|
||||
if (settings.SPEED_CAMERAS_UNINSTALLED.getId().equals(prefId)) {
|
||||
FragmentManager fm = getFragmentManager();
|
||||
if (fm != null) {
|
||||
SpeedCamerasBottomSheet.showInstance(fm, this);
|
||||
|
@ -221,11 +214,14 @@ public class GlobalSettingsFragment extends BaseSettingsFragment
|
|||
enableProxy.setIcon(getPersistentPrefIcon(R.drawable.ic_action_proxy));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSpeedCamerasUninstalled() {
|
||||
if (uninstallSpeedCameras != null && legalCategory != null) {
|
||||
uninstallSpeedCameras.setVisible(false);
|
||||
legalCategory.setVisible(false);
|
||||
}
|
||||
private void setupLegalCategory() {
|
||||
PreferenceCategory legalCategory = (PreferenceCategory) findPreference(LEGAL_CATEGORY_ID);
|
||||
legalCategory.setVisible(!settings.SPEED_CAMERAS_UNINSTALLED.get());
|
||||
}
|
||||
|
||||
private void setupUninstallSpeedCamerasPref() {
|
||||
Preference uninstallSpeedCameras = (Preference) findPreference(settings.SPEED_CAMERAS_UNINSTALLED.getId());
|
||||
uninstallSpeedCameras.setIcon(getActiveIcon(R.drawable.ic_speed_camera_disabled));
|
||||
uninstallSpeedCameras.setVisible(!settings.SPEED_CAMERAS_UNINSTALLED.get());
|
||||
}
|
||||
}
|
|
@ -77,8 +77,7 @@ public class ImportCompleteFragment extends BaseOsmAndFragment {
|
|||
recyclerView = root.findViewById(R.id.list);
|
||||
description.setText(UiUtilities.createSpannableString(
|
||||
String.format(getString(R.string.import_complete_description), fileName),
|
||||
fileName,
|
||||
new StyleSpan(Typeface.BOLD)
|
||||
new StyleSpan(Typeface.BOLD), fileName
|
||||
));
|
||||
btnClose.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
|
|
@ -257,8 +257,7 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View
|
|||
toolbarLayout.setTitle(getString(R.string.shared_string_importing));
|
||||
description.setText(UiUtilities.createSpannableString(
|
||||
String.format(getString(R.string.importing_from), file.getName()),
|
||||
file.getName(),
|
||||
new StyleSpan(Typeface.BOLD)
|
||||
new StyleSpan(Typeface.BOLD), file.getName()
|
||||
));
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
list.setVisibility(View.GONE);
|
||||
|
|
|
@ -234,8 +234,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment
|
|||
toolbarLayout.setTitle(getString(toolbarTitleRes));
|
||||
description.setText(UiUtilities.createSpannableString(
|
||||
String.format(getString(descriptionRes), fileName),
|
||||
fileName,
|
||||
new StyleSpan(Typeface.BOLD)
|
||||
new StyleSpan(Typeface.BOLD), fileName
|
||||
));
|
||||
buttonsContainer.setVisibility(View.GONE);
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
|
|
|
@ -6,40 +6,29 @@ import android.os.Build;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.SwitchCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
import androidx.preference.SwitchPreferenceCompat;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.dialogs.SpeedCamerasBottomSheet;
|
||||
import net.osmand.plus.dialogs.SpeedCamerasBottomSheet.OnSpeedCamerasUninstallListener;
|
||||
import net.osmand.plus.helpers.FontCache;
|
||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import static net.osmand.plus.UiUtilities.CompoundButtonType.TOOLBAR;
|
||||
|
||||
public class ScreenAlertsFragment extends BaseSettingsFragment implements OnSpeedCamerasUninstallListener {
|
||||
public class ScreenAlertsFragment extends BaseSettingsFragment implements OnPreferenceChanged {
|
||||
|
||||
public static final String TAG = ScreenAlertsFragment.class.getSimpleName();
|
||||
|
||||
private static final String SHOW_ROUTING_ALARMS_INFO = "show_routing_alarms_info";
|
||||
private static final String SCREEN_ALERTS_IMAGE = "screen_alerts_image";
|
||||
private static final String SHOW_CAMERAS = "show_cameras";
|
||||
private SwitchPreferenceCompat showCameras;
|
||||
|
||||
@Override
|
||||
protected void setupPreferences() {
|
||||
|
@ -47,19 +36,16 @@ public class ScreenAlertsFragment extends BaseSettingsFragment implements OnSpee
|
|||
SwitchPreferenceCompat showTrafficWarnings = (SwitchPreferenceCompat) findPreference(settings.SHOW_TRAFFIC_WARNINGS.getId());
|
||||
SwitchPreferenceCompat showPedestrian = (SwitchPreferenceCompat) findPreference(settings.SHOW_PEDESTRIAN.getId());
|
||||
SwitchPreferenceCompat showTunnels = (SwitchPreferenceCompat) findPreference(settings.SHOW_TUNNELS.getId());
|
||||
showCameras = (SwitchPreferenceCompat) findPreference(settings.SHOW_CAMERAS.getId());
|
||||
|
||||
showRoutingAlarmsInfo.setIcon(getContentIcon(R.drawable.ic_action_info_dark));
|
||||
showTrafficWarnings.setIcon(getIcon(R.drawable.list_warnings_traffic_calming));
|
||||
showPedestrian.setIcon(getIcon(R.drawable.list_warnings_pedestrian));
|
||||
showTunnels.setIcon(getIcon(R.drawable.list_warnings_tunnel));
|
||||
showCameras.setIcon(getIcon(R.drawable.list_warnings_speed_camera));
|
||||
|
||||
setupScreenAlertsImage();
|
||||
setupShowCamerasPref();
|
||||
setupSpeedCamerasAlert();
|
||||
enableDisablePreferences(settings.SHOW_ROUTING_ALARMS.getModeValue(getSelectedAppMode()));
|
||||
if (settings.SPEED_CAMERAS_UNINSTALLED.get()) {
|
||||
onSpeedCamerasUninstalled();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -119,8 +105,8 @@ public class ScreenAlertsFragment extends BaseSettingsFragment implements OnSpee
|
|||
|
||||
deviceImage.setImageDrawable(getDeviceImage());
|
||||
warningIcon.setImageDrawable(getWarningIcon());
|
||||
} else if (SHOW_CAMERAS.equals(key)) {
|
||||
setupSpeedCamerasAlert(app, requireMyActivity(), holder, this, isNightMode());
|
||||
} else if (settings.SPEED_CAMERAS_UNINSTALLED.getId().equals(key)) {
|
||||
setupPrefRoundedBg(holder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -131,10 +117,20 @@ public class ScreenAlertsFragment extends BaseSettingsFragment implements OnSpee
|
|||
Preference routeParametersImage = findPreference(SCREEN_ALERTS_IMAGE);
|
||||
updatePreference(routeParametersImage);
|
||||
}
|
||||
|
||||
if (settings.SPEED_CAMERAS_UNINSTALLED.getId().equals(preference.getKey())) {
|
||||
SpeedCamerasBottomSheet.showInstance(requireActivity().getSupportFragmentManager(), this);
|
||||
}
|
||||
return super.onPreferenceClick(preference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPreferenceChanged(String prefId) {
|
||||
if (prefId.equals(settings.SPEED_CAMERAS_UNINSTALLED.getId())) {
|
||||
setupShowCamerasPref();
|
||||
setupSpeedCamerasAlert();
|
||||
}
|
||||
}
|
||||
|
||||
private void setupScreenAlertsImage() {
|
||||
Preference routeParametersImage = findPreference(SCREEN_ALERTS_IMAGE);
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||
|
@ -163,47 +159,9 @@ public class ScreenAlertsFragment extends BaseSettingsFragment implements OnSpee
|
|||
return null;
|
||||
}
|
||||
|
||||
public static void setupSpeedCamerasAlert(@NonNull OsmandApplication app,
|
||||
@NonNull FragmentActivity activity,
|
||||
@NonNull PreferenceViewHolder holder,
|
||||
@Nullable Fragment targetFragment,
|
||||
boolean nightMode) {
|
||||
ImageView alertIcon = (ImageView) holder.itemView.findViewById(R.id.alert_icon);
|
||||
TextView alertTitle = (TextView) holder.itemView.findViewById(R.id.alert_title);
|
||||
TextView alertSubTitle = (TextView) holder.itemView.findViewById(R.id.alert_subtitle);
|
||||
LinearLayout alertBg = (LinearLayout) holder.itemView.findViewById(R.id.alert_bg);
|
||||
|
||||
alertBg.setBackgroundDrawable(UiUtilities.getRoundedBackgroundDrawable(
|
||||
app,
|
||||
nightMode ? R.color.activity_background_color_dark : R.color.activity_background_color_light,
|
||||
6));
|
||||
alertIcon.setImageDrawable(app.getUIUtilities().getIcon(
|
||||
R.drawable.ic_action_alert,
|
||||
nightMode ? R.color.icon_color_default_dark : R.color.icon_color_default_light));
|
||||
alertTitle.setText(R.string.speed_cameras_alert);
|
||||
alertTitle.setTypeface(FontCache.getRobotoMedium(app));
|
||||
alertSubTitle.setText(R.string.read_more);
|
||||
alertSubTitle.setTypeface(FontCache.getRobotoMedium(app));
|
||||
alertSubTitle.setTextColor(nightMode
|
||||
? app.getResources().getColor(R.color.active_color_primary_dark)
|
||||
: app.getResources().getColor(R.color.active_color_primary_light));
|
||||
final WeakReference<FragmentActivity> weakActivity = new WeakReference<>(activity);
|
||||
final WeakReference<Fragment> weakFragment = new WeakReference<>(targetFragment);
|
||||
alertSubTitle.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
FragmentActivity a = weakActivity.get();
|
||||
if (a != null) {
|
||||
SpeedCamerasBottomSheet.showInstance(a.getSupportFragmentManager(), weakFragment.get());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSpeedCamerasUninstalled() {
|
||||
if (showCameras != null) {
|
||||
showCameras.setVisible(false);
|
||||
}
|
||||
private void setupShowCamerasPref() {
|
||||
SwitchPreferenceCompat showCameras = (SwitchPreferenceCompat) findPreference(settings.SHOW_CAMERAS.getId());
|
||||
showCameras.setIcon(getIcon(R.drawable.list_warnings_speed_camera));
|
||||
showCameras.setVisible(!settings.SPEED_CAMERAS_UNINSTALLED.get());
|
||||
}
|
||||
}
|
|
@ -14,9 +14,10 @@ import androidx.appcompat.widget.SwitchCompat;
|
|||
import androidx.core.content.ContextCompat;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
import androidx.preference.SwitchPreferenceCompat;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.plus.dialogs.SpeedCamerasBottomSheet.OnSpeedCamerasUninstallListener;
|
||||
import net.osmand.plus.dialogs.SpeedCamerasBottomSheet;
|
||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -34,10 +35,9 @@ import static net.osmand.plus.settings.backend.OsmandSettings.VOICE_PROVIDER_NOT
|
|||
import static net.osmand.plus.UiUtilities.CompoundButtonType.TOOLBAR;
|
||||
import static net.osmand.plus.activities.SettingsNavigationActivity.MORE_VALUE;
|
||||
|
||||
public class VoiceAnnouncesFragment extends BaseSettingsFragment implements OnSpeedCamerasUninstallListener {
|
||||
public class VoiceAnnouncesFragment extends BaseSettingsFragment implements OnPreferenceChanged {
|
||||
|
||||
public static final String TAG = VoiceAnnouncesFragment.class.getSimpleName();
|
||||
private Preference speakCamera;
|
||||
|
||||
@Override
|
||||
protected void createToolbar(LayoutInflater inflater, View view) {
|
||||
|
@ -98,10 +98,8 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment implements OnSp
|
|||
setupInterruptMusicPref();
|
||||
}
|
||||
enableDisablePreferences(!settings.VOICE_MUTE.getModeValue(getSelectedAppMode()));
|
||||
speakCamera = findPreference(settings.SPEAK_SPEED_CAMERA.getId());
|
||||
if (settings.SPEED_CAMERAS_UNINSTALLED.get()) {
|
||||
onSpeedCamerasUninstalled();
|
||||
}
|
||||
setupSpeakCamerasPref();
|
||||
setupSpeedCamerasAlert();
|
||||
}
|
||||
|
||||
private void setupSpeedLimitExceedPref() {
|
||||
|
@ -231,8 +229,8 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment implements OnSp
|
|||
Object currentValue = ((ListPreferenceEx) preference).getValue();
|
||||
imageView.setEnabled(preference.isEnabled() && !OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(currentValue));
|
||||
}
|
||||
} else if (settings.SPEAK_SPEED_CAMERA.getId().equals(preference.getKey())) {
|
||||
ScreenAlertsFragment.setupSpeedCamerasAlert(app, requireMyActivity(), holder, this, isNightMode());
|
||||
} else if (settings.SPEED_CAMERAS_UNINSTALLED.getId().equals(preference.getKey())) {
|
||||
setupPrefRoundedBg(holder);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -296,9 +294,23 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment implements OnSp
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onSpeedCamerasUninstalled() {
|
||||
if (speakCamera != null) {
|
||||
speakCamera.setVisible(false);
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
if (settings.SPEED_CAMERAS_UNINSTALLED.getId().equals(preference.getKey())) {
|
||||
SpeedCamerasBottomSheet.showInstance(requireActivity().getSupportFragmentManager(), this);
|
||||
}
|
||||
return super.onPreferenceClick(preference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPreferenceChanged(String prefId) {
|
||||
if (prefId.equals(settings.SPEED_CAMERAS_UNINSTALLED.getId())) {
|
||||
setupSpeakCamerasPref();
|
||||
setupSpeedCamerasAlert();
|
||||
}
|
||||
}
|
||||
|
||||
private void setupSpeakCamerasPref() {
|
||||
SwitchPreferenceCompat showCameras = (SwitchPreferenceCompat) findPreference(settings.SPEAK_SPEED_CAMERA.getId());
|
||||
showCameras.setVisible(!settings.SPEED_CAMERAS_UNINSTALLED.get());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue