Merge pull request #9119 from osmandapp/details_dialog_redesign
configure map details dialog redesign
This commit is contained in:
commit
3ae3a48a2f
11 changed files with 564 additions and 13 deletions
|
@ -8,6 +8,9 @@ import java.util.Map;
|
|||
public class RenderingRuleStorageProperties {
|
||||
|
||||
public static final String UI_CATEGORY_HIDDEN = "ui_hidden";
|
||||
public static final String UI_CATEGORY_DETAILS = "details";
|
||||
public static final String UI_CATEGORY_HIDE = "hide";
|
||||
public static final String UI_CATEGORY_ROUTES = "routes";
|
||||
public static final String A_ENGINE_V1 = "engine_v1";
|
||||
public static final String A_APP_MODE= "appMode";
|
||||
public static final String A_BASE_APP_MODE = "baseAppMode";
|
||||
|
|
63
OsmAnd/res/layout/bottom_sheet_item_two_choices.xml
Normal file
63
OsmAnd/res/layout/bottom_sheet_item_two_choices.xml
Normal file
|
@ -0,0 +1,63 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:osmand="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<include layout="@layout/bottom_sheet_item_with_switch" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/bottom_btns"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/dialog_button_height"
|
||||
android:layout_marginStart="@dimen/content_padding"
|
||||
android:layout_marginTop="@dimen/text_margin_small"
|
||||
android:layout_marginEnd="@dimen/content_padding"
|
||||
android:layout_marginBottom="@dimen/content_padding_small"
|
||||
android:background="?attr/btn_bg_border_inactive"
|
||||
android:baselineAligned="false"
|
||||
android:orientation="horizontal"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/left_btn_container"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1">
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/left_btn"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center"
|
||||
android:text="@string/shared_string_hillshade"
|
||||
android:textSize="@dimen/default_desc_text_size"
|
||||
osmand:typeface="@string/font_roboto_medium" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/right_btn_container"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1">
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/right_btn"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center"
|
||||
android:text="@string/shared_string_slope"
|
||||
android:textSize="@dimen/default_desc_text_size"
|
||||
osmand:typeface="@string/font_roboto_medium" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -40,6 +40,7 @@
|
|||
android:background="@null"
|
||||
android:clickable="false"
|
||||
android:focusable="false"
|
||||
android:focusableInTouchMode="false"/>
|
||||
android:focusableInTouchMode="false"
|
||||
android:saveEnabled="false"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
Thx - Hardy
|
||||
|
||||
-->
|
||||
<string name="shared_string_all_time">All time</string>
|
||||
<string name="shared_string_night_map">Night map</string>
|
||||
<string name="details_dialog_decr">Control visibility of additional details showed on the map</string>
|
||||
<string name="shared_string_meters">meters</string>
|
||||
<string name="shared_string_tones">tones</string>
|
||||
<string name="default_screen_timeout">Default screen timeout</string>
|
||||
|
|
|
@ -34,6 +34,7 @@ public class BottomSheetItemTitleWithDescrAndButton extends BottomSheetItemWithD
|
|||
Drawable background,
|
||||
CharSequence title,
|
||||
@ColorRes int titleColorId,
|
||||
boolean iconHidden,
|
||||
CharSequence description,
|
||||
@ColorRes int descriptionColorId,
|
||||
int descriptionMaxLines,
|
||||
|
@ -53,6 +54,7 @@ public class BottomSheetItemTitleWithDescrAndButton extends BottomSheetItemWithD
|
|||
background,
|
||||
title,
|
||||
titleColorId,
|
||||
iconHidden,
|
||||
description,
|
||||
descriptionColorId,
|
||||
descriptionMaxLines,
|
||||
|
@ -128,6 +130,7 @@ public class BottomSheetItemTitleWithDescrAndButton extends BottomSheetItemWithD
|
|||
background,
|
||||
title,
|
||||
titleColorId,
|
||||
iconHidden,
|
||||
description,
|
||||
descriptionColorId,
|
||||
descriptionMaxLines,
|
||||
|
|
|
@ -0,0 +1,231 @@
|
|||
package net.osmand.plus.base.bottomsheetmenu;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
|
||||
|
||||
public class BottomSheetItemTwoChoicesButton extends BottomSheetItemWithCompoundButton {
|
||||
|
||||
private LinearLayout bottomButtons;
|
||||
private FrameLayout leftBtnContainer;
|
||||
private FrameLayout rightBtnContainer;
|
||||
private TextView leftBtn;
|
||||
private TextView rightBtn;
|
||||
|
||||
@StringRes
|
||||
private int leftBtnTitleRes;
|
||||
@StringRes
|
||||
private int rightBtnTitleRes;
|
||||
private boolean isLeftBtnSelected;
|
||||
private OnBottomBtnClickListener onBottomBtnClickListener;
|
||||
private int bottomBtnBgRadius;
|
||||
private int bottomBtnTextColor;
|
||||
private int activeColor;
|
||||
private GradientDrawable bottomBtnBg;
|
||||
|
||||
public BottomSheetItemTwoChoicesButton(View customView,
|
||||
int layoutId,
|
||||
Object tag,
|
||||
boolean disabled,
|
||||
View.OnClickListener onClickListener,
|
||||
int position,
|
||||
Drawable icon,
|
||||
Drawable background,
|
||||
CharSequence title,
|
||||
int titleColorId,
|
||||
boolean iconHidden,
|
||||
CharSequence description,
|
||||
int descriptionColorId,
|
||||
int descriptionMaxLines,
|
||||
boolean descriptionLinksClickable,
|
||||
boolean checked,
|
||||
ColorStateList buttonTintList,
|
||||
CompoundButton.OnCheckedChangeListener onCheckedChangeListener,
|
||||
int compoundButtonColorId,
|
||||
boolean isLeftBtnSelected,
|
||||
int leftBtnTitleRes,
|
||||
int rightBtnTitleRes,
|
||||
OnBottomBtnClickListener onBottomBtnClickListener) {
|
||||
super(customView,
|
||||
layoutId,
|
||||
tag,
|
||||
disabled,
|
||||
onClickListener,
|
||||
position,
|
||||
icon,
|
||||
background,
|
||||
title,
|
||||
titleColorId,
|
||||
iconHidden,
|
||||
description,
|
||||
descriptionColorId,
|
||||
descriptionMaxLines,
|
||||
descriptionLinksClickable,
|
||||
checked,
|
||||
buttonTintList,
|
||||
onCheckedChangeListener,
|
||||
compoundButtonColorId);
|
||||
this.leftBtnTitleRes = leftBtnTitleRes;
|
||||
this.rightBtnTitleRes = rightBtnTitleRes;
|
||||
this.isLeftBtnSelected = isLeftBtnSelected;
|
||||
this.onBottomBtnClickListener = onBottomBtnClickListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inflate(Context context, ViewGroup container, boolean nightMode) {
|
||||
super.inflate(context, container, nightMode);
|
||||
bottomBtnBgRadius = AndroidUtils.dpToPx(context, 4);
|
||||
bottomBtnTextColor = ContextCompat.getColor(context, nightMode
|
||||
? R.color.text_color_primary_dark
|
||||
: R.color.text_color_primary_light);
|
||||
activeColor = ContextCompat.getColor(context, nightMode
|
||||
? R.color.active_color_primary_dark
|
||||
: R.color.active_color_primary_light);
|
||||
bottomBtnBg = new GradientDrawable();
|
||||
bottomBtnBg.setColor(UiUtilities.getColorWithAlpha(activeColor, 0.1f));
|
||||
bottomBtnBg.setStroke(AndroidUtils.dpToPx(context, 1), UiUtilities.getColorWithAlpha(activeColor, 0.5f));
|
||||
|
||||
bottomButtons = view.findViewById(R.id.bottom_btns);
|
||||
leftBtnContainer = view.findViewById(R.id.left_btn_container);
|
||||
rightBtnContainer = view.findViewById(R.id.right_btn_container);
|
||||
leftBtn = view.findViewById(R.id.left_btn);
|
||||
rightBtn = view.findViewById(R.id.right_btn);
|
||||
|
||||
AndroidUiHelper.updateVisibility(bottomButtons, isChecked());
|
||||
if (leftBtn != null) {
|
||||
leftBtn.setText(leftBtnTitleRes);
|
||||
leftBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
isLeftBtnSelected = true;
|
||||
if (onBottomBtnClickListener != null) {
|
||||
onBottomBtnClickListener.onBottomBtnClick(true);
|
||||
}
|
||||
updateBottomButtons();
|
||||
}
|
||||
});
|
||||
}
|
||||
if (rightBtn != null) {
|
||||
rightBtn.setText(rightBtnTitleRes);
|
||||
rightBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
isLeftBtnSelected = false;
|
||||
if (onBottomBtnClickListener != null) {
|
||||
onBottomBtnClickListener.onBottomBtnClick(false);
|
||||
}
|
||||
updateBottomButtons();
|
||||
}
|
||||
});
|
||||
}
|
||||
updateBottomButtons();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChecked(boolean checked) {
|
||||
super.setChecked(checked);
|
||||
AndroidUiHelper.updateVisibility(bottomButtons, checked);
|
||||
updateBottomButtons();
|
||||
}
|
||||
|
||||
public void setIsLeftBtnSelected(boolean isLeftBtnSelected) {
|
||||
this.isLeftBtnSelected = isLeftBtnSelected;
|
||||
updateBottomButtons();
|
||||
}
|
||||
|
||||
private void updateBottomButtons() {
|
||||
if (bottomBtnBg == null || rightBtn == null || rightBtnContainer == null || leftBtn == null || leftBtnContainer == null) {
|
||||
return;
|
||||
}
|
||||
if (isLeftBtnSelected) {
|
||||
bottomBtnBg.setCornerRadii(new float[]{bottomBtnBgRadius, bottomBtnBgRadius, 0, 0, 0, 0, bottomBtnBgRadius, bottomBtnBgRadius});
|
||||
rightBtnContainer.setBackgroundColor(Color.TRANSPARENT);
|
||||
rightBtn.setTextColor(activeColor);
|
||||
leftBtnContainer.setBackgroundDrawable(bottomBtnBg);
|
||||
leftBtn.setTextColor(bottomBtnTextColor);
|
||||
} else {
|
||||
bottomBtnBg.setCornerRadii(new float[]{0, 0, bottomBtnBgRadius, bottomBtnBgRadius, bottomBtnBgRadius, bottomBtnBgRadius, 0, 0});
|
||||
rightBtnContainer.setBackgroundDrawable(bottomBtnBg);
|
||||
rightBtn.setTextColor(bottomBtnTextColor);
|
||||
leftBtnContainer.setBackgroundColor(Color.TRANSPARENT);
|
||||
leftBtn.setTextColor(activeColor);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder extends BottomSheetItemWithCompoundButton.Builder {
|
||||
|
||||
@StringRes
|
||||
private int leftBtnTitleRes;
|
||||
@StringRes
|
||||
private int rightBtnTitleRes;
|
||||
private boolean isLeftBtnSelected;
|
||||
private OnBottomBtnClickListener onBottomBtnClickListener;
|
||||
|
||||
public Builder setLeftBtnTitleRes(int leftBtnTitleRes) {
|
||||
this.leftBtnTitleRes = leftBtnTitleRes;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setRightBtnTitleRes(int rightBtnTitleRes) {
|
||||
this.rightBtnTitleRes = rightBtnTitleRes;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setLeftBtnSelected(boolean leftBtnSelected) {
|
||||
isLeftBtnSelected = leftBtnSelected;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setOnBottomBtnClickListener(OnBottomBtnClickListener onBottomBtnClickListener) {
|
||||
this.onBottomBtnClickListener = onBottomBtnClickListener;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BottomSheetItemTwoChoicesButton create() {
|
||||
return new BottomSheetItemTwoChoicesButton(customView,
|
||||
layoutId,
|
||||
tag,
|
||||
disabled,
|
||||
onClickListener,
|
||||
position,
|
||||
icon,
|
||||
background,
|
||||
title,
|
||||
titleColorId,
|
||||
iconHidden,
|
||||
description,
|
||||
descriptionColorId,
|
||||
descriptionMaxLines,
|
||||
descriptionLinksClickable,
|
||||
checked,
|
||||
buttonTintList,
|
||||
onCheckedChangeListener,
|
||||
compoundButtonColorId,
|
||||
isLeftBtnSelected,
|
||||
leftBtnTitleRes,
|
||||
rightBtnTitleRes,
|
||||
onBottomBtnClickListener);
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnBottomBtnClickListener {
|
||||
void onBottomBtnClick(boolean onLeftClick);
|
||||
}
|
||||
}
|
|
@ -39,6 +39,7 @@ public class BottomSheetItemWithCompoundButton extends BottomSheetItemWithDescri
|
|||
Drawable background,
|
||||
CharSequence title,
|
||||
@ColorRes int titleColorId,
|
||||
boolean iconHidden,
|
||||
CharSequence description,
|
||||
@ColorRes int descriptionColorId,
|
||||
int descriptionMaxLines,
|
||||
|
@ -57,6 +58,7 @@ public class BottomSheetItemWithCompoundButton extends BottomSheetItemWithDescri
|
|||
background,
|
||||
title,
|
||||
titleColorId,
|
||||
iconHidden,
|
||||
description,
|
||||
descriptionColorId,
|
||||
descriptionMaxLines,
|
||||
|
@ -135,6 +137,7 @@ public class BottomSheetItemWithCompoundButton extends BottomSheetItemWithDescri
|
|||
background,
|
||||
title,
|
||||
titleColorId,
|
||||
iconHidden,
|
||||
description,
|
||||
descriptionColorId,
|
||||
descriptionMaxLines,
|
||||
|
|
|
@ -33,11 +33,12 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem {
|
|||
Drawable background,
|
||||
CharSequence title,
|
||||
@ColorRes int titleColorId,
|
||||
boolean iconHidden,
|
||||
CharSequence description,
|
||||
@ColorRes int descriptionColorId,
|
||||
int descriptionMaxLines,
|
||||
boolean descriptionLinksClickable) {
|
||||
super(customView, layoutId, tag, disabled, onClickListener, position, icon, background, title, titleColorId);
|
||||
super(customView, layoutId, tag, disabled, onClickListener, position, icon, background, title, titleColorId, iconHidden);
|
||||
this.description = description;
|
||||
this.descriptionColorId = descriptionColorId;
|
||||
this.descriptionMaxLines = descriptionMaxLines;
|
||||
|
@ -126,6 +127,7 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem {
|
|||
background,
|
||||
title,
|
||||
titleColorId,
|
||||
iconHidden,
|
||||
description,
|
||||
descriptionColorId,
|
||||
descriptionMaxLines,
|
||||
|
|
|
@ -18,6 +18,7 @@ public class SimpleBottomSheetItem extends BaseBottomSheetItem {
|
|||
|
||||
private Drawable background;
|
||||
private Drawable icon;
|
||||
private boolean iconHidden;
|
||||
protected CharSequence title;
|
||||
@ColorRes
|
||||
protected int titleColorId = INVALID_ID;
|
||||
|
@ -34,12 +35,14 @@ public class SimpleBottomSheetItem extends BaseBottomSheetItem {
|
|||
Drawable icon,
|
||||
Drawable background,
|
||||
CharSequence title,
|
||||
@ColorRes int titleColorId) {
|
||||
@ColorRes int titleColorId,
|
||||
boolean iconHidden) {
|
||||
super(customView, layoutId, tag, disabled, onClickListener, position);
|
||||
this.icon = icon;
|
||||
this.background = background;
|
||||
this.title = title;
|
||||
this.titleColorId = titleColorId;
|
||||
this.iconHidden = iconHidden;
|
||||
}
|
||||
|
||||
protected SimpleBottomSheetItem() {
|
||||
|
@ -67,6 +70,7 @@ public class SimpleBottomSheetItem extends BaseBottomSheetItem {
|
|||
iconView = ((ImageView) view.findViewById(R.id.icon));
|
||||
if (iconView != null) {
|
||||
iconView.setImageDrawable(icon);
|
||||
iconView.setVisibility(iconHidden ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
titleTv = (TextView) view.findViewById(R.id.title);
|
||||
if (title != null && titleTv != null) {
|
||||
|
@ -87,6 +91,7 @@ public class SimpleBottomSheetItem extends BaseBottomSheetItem {
|
|||
protected CharSequence title;
|
||||
@ColorRes
|
||||
protected int titleColorId = INVALID_ID;
|
||||
protected boolean iconHidden;
|
||||
|
||||
public Builder setIcon(Drawable icon) {
|
||||
this.icon = icon;
|
||||
|
@ -108,6 +113,11 @@ public class SimpleBottomSheetItem extends BaseBottomSheetItem {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder setIconHidden(boolean iconHidden) {
|
||||
this.iconHidden = iconHidden;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SimpleBottomSheetItem create() {
|
||||
return new SimpleBottomSheetItem(customView,
|
||||
layoutId,
|
||||
|
@ -118,7 +128,8 @@ public class SimpleBottomSheetItem extends BaseBottomSheetItem {
|
|||
icon,
|
||||
background,
|
||||
title,
|
||||
titleColorId);
|
||||
titleColorId,
|
||||
iconHidden);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,6 +107,9 @@ import static net.osmand.plus.srtmplugin.SRTMPlugin.CONTOUR_LINES_ATTR;
|
|||
import static net.osmand.plus.srtmplugin.SRTMPlugin.CONTOUR_LINES_SCHEME_ATTR;
|
||||
import static net.osmand.plus.srtmplugin.SRTMPlugin.CONTOUR_WIDTH_ATTR;
|
||||
import static net.osmand.plus.transport.TransportLinesMenu.RENDERING_CATEGORY_TRANSPORT;
|
||||
import static net.osmand.render.RenderingRuleStorageProperties.UI_CATEGORY_DETAILS;
|
||||
import static net.osmand.render.RenderingRuleStorageProperties.UI_CATEGORY_HIDE;
|
||||
import static net.osmand.render.RenderingRuleStorageProperties.UI_CATEGORY_ROUTES;
|
||||
|
||||
public class ConfigureMapMenu {
|
||||
private static final Log LOG = PlatformUtil.getLog(ConfigureMapMenu.class);
|
||||
|
@ -787,12 +790,12 @@ public class ConfigureMapMenu {
|
|||
.createItem());
|
||||
|
||||
props = createProperties(customRules, null, R.string.rendering_category_details, R.drawable.ic_action_layers,
|
||||
"details", null, adapter, activity, true, DETAILS_ID, themeRes, nightMode, selectedProfileColor);
|
||||
UI_CATEGORY_DETAILS, null, adapter, activity, true, DETAILS_ID, themeRes, nightMode, selectedProfileColor);
|
||||
if (props != null) {
|
||||
adapter.addItem(props);
|
||||
}
|
||||
props = createProperties(customRules, null, R.string.rendering_category_hide, R.drawable.ic_action_hide,
|
||||
"hide", null, adapter, activity, true, HIDE_ID, themeRes, nightMode, selectedProfileColor);
|
||||
UI_CATEGORY_HIDE, null, adapter, activity, true, HIDE_ID, themeRes, nightMode, selectedProfileColor);
|
||||
if (props != null) {
|
||||
adapter.addItem(props);
|
||||
}
|
||||
|
@ -804,7 +807,7 @@ public class ConfigureMapMenu {
|
|||
}
|
||||
}
|
||||
props = createProperties(customRules, customRulesIncluded, R.string.rendering_category_routes, R.drawable.ic_action_map_routes,
|
||||
"routes", null, adapter, activity, true, ROUTES_ID, themeRes, nightMode, selectedProfileColor);
|
||||
UI_CATEGORY_ROUTES, null, adapter, activity, true, ROUTES_ID, themeRes, nightMode, selectedProfileColor);
|
||||
if (props != null) {
|
||||
adapter.addItem(props);
|
||||
}
|
||||
|
@ -862,15 +865,15 @@ public class ConfigureMapMenu {
|
|||
final List<RenderingRuleProperty> customRulesIncluded,
|
||||
@StringRes final int strId,
|
||||
@DrawableRes final int icon,
|
||||
String category,
|
||||
final String category,
|
||||
final ListStringPreference defaultSettings,
|
||||
final ContextMenuAdapter adapter,
|
||||
final MapActivity activity,
|
||||
final boolean useDescription,
|
||||
final String id,
|
||||
final int themeRes,
|
||||
final boolean nightMode,
|
||||
@ColorInt final int selectedProfileColor) {
|
||||
final int themeRes,
|
||||
final boolean nightMode,
|
||||
@ColorInt final int selectedProfileColor) {
|
||||
|
||||
final List<RenderingRuleProperty> ps = new ArrayList<>();
|
||||
final List<OsmandSettings.CommonPreference<Boolean>> prefs = new ArrayList<>();
|
||||
|
@ -918,8 +921,12 @@ public class ConfigureMapMenu {
|
|||
refreshMapComplete(activity);
|
||||
activity.getMapLayers().updateLayers(activity.getMapView());
|
||||
} else {
|
||||
showPreferencesDialog(adapter, a, pos, activity, activity.getString(strId), ps, prefs,
|
||||
useDescription, defaultSettings, true, customRulesIncluded, themeRes, nightMode, selectedProfileColor);
|
||||
if (UI_CATEGORY_DETAILS.equals(category)) {
|
||||
DetailsBottomSheet.showInstance(activity.getSupportFragmentManager(), ps, prefs, a, adapter, pos);
|
||||
} else {
|
||||
showPreferencesDialog(adapter, a, pos, activity, activity.getString(strId), ps, prefs,
|
||||
useDescription, defaultSettings, true, customRulesIncluded, themeRes, nightMode, selectedProfileColor);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
224
OsmAnd/src/net/osmand/plus/dialogs/DetailsBottomSheet.java
Normal file
224
OsmAnd/src/net/osmand/plus/dialogs/DetailsBottomSheet.java
Normal file
|
@ -0,0 +1,224 @@
|
|||
package net.osmand.plus.dialogs;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import net.osmand.plus.ContextMenuAdapter;
|
||||
import net.osmand.plus.ContextMenuItem;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemTwoChoicesButton;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemTwoChoicesButton.OnBottomBtnClickListener;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.ShortDescriptionItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
|
||||
import net.osmand.plus.settings.bottomsheets.BasePreferenceBottomSheet;
|
||||
import net.osmand.render.RenderingRuleProperty;
|
||||
import net.osmand.render.RenderingRuleStorageProperties;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static net.osmand.plus.transport.TransportLinesMenu.RENDERING_CATEGORY_TRANSPORT;
|
||||
import static net.osmand.render.RenderingRuleStorageProperties.UI_CATEGORY_DETAILS;
|
||||
|
||||
public class DetailsBottomSheet extends BasePreferenceBottomSheet {
|
||||
|
||||
public static final String TAG = DetailsBottomSheet.class.getName();
|
||||
public static final String STREET_LIGHTING = "streetLighting";
|
||||
public static final String STREET_LIGHTING_NIGHT = "streetLightingNight";
|
||||
public static final String MORE_DETAILED = "moreDetailed";
|
||||
public static final String SHOW_SURFACE_GRADE = "showSurfaceGrade";
|
||||
public static final String COLORED_BUILDINGS = "coloredBuildings";
|
||||
private OsmandApplication app;
|
||||
private List<RenderingRuleProperty> properties;
|
||||
private List<CommonPreference<Boolean>> preferences;
|
||||
private ArrayAdapter<?> arrayAdapter;
|
||||
private ContextMenuAdapter adapter;
|
||||
private int position;
|
||||
|
||||
public static void showInstance(@NonNull FragmentManager fm,
|
||||
List<RenderingRuleProperty> properties,
|
||||
List<CommonPreference<Boolean>> preferences,
|
||||
ArrayAdapter<?> arrayAdapter,
|
||||
ContextMenuAdapter adapter,
|
||||
int position) {
|
||||
if (!fm.isStateSaved()) {
|
||||
DetailsBottomSheet bottomSheet = new DetailsBottomSheet();
|
||||
bottomSheet.setProperties(properties);
|
||||
bottomSheet.setPreferences(preferences);
|
||||
bottomSheet.setAdapter(adapter);
|
||||
bottomSheet.setPosition(position);
|
||||
bottomSheet.setArrayAdapter(arrayAdapter);
|
||||
bottomSheet.show(fm, TAG);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
app = requiredMyApplication();
|
||||
if (properties == null || preferences == null) {
|
||||
properties = new ArrayList<>();
|
||||
preferences = new ArrayList<>();
|
||||
List<RenderingRuleProperty> customRules = ConfigureMapMenu.getCustomRules(app,
|
||||
RenderingRuleStorageProperties.UI_CATEGORY_HIDDEN, RENDERING_CATEGORY_TRANSPORT);
|
||||
for (RenderingRuleProperty pr : customRules) {
|
||||
if (UI_CATEGORY_DETAILS.equals(pr.getCategory()) && pr.isBoolean()) {
|
||||
properties.add(pr);
|
||||
final CommonPreference<Boolean> pref = app.getSettings()
|
||||
.getCustomRenderBooleanProperty(pr.getAttrName());
|
||||
preferences.add(pref);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createMenuItems(Bundle savedInstanceState) {
|
||||
int selectedProfileColorRes = app.getSettings().APPLICATION_MODE.get().getIconColorInfo().getColor(nightMode);
|
||||
TitleItem titleItem = new TitleItem(getString(R.string.rendering_category_details));
|
||||
items.add(titleItem);
|
||||
ShortDescriptionItem descriptionItem = new ShortDescriptionItem(getString(R.string.details_dialog_decr));
|
||||
items.add(descriptionItem);
|
||||
if (preferences != null && properties != null) {
|
||||
RenderingRuleProperty streetLightNightProp = getStreetLightNightProp();
|
||||
for (int i = 0; i < properties.size(); i++) {
|
||||
RenderingRuleProperty property = properties.get(i);
|
||||
final CommonPreference<Boolean> pref = preferences.get(i);
|
||||
if (STREET_LIGHTING.equals(property.getAttrName()) && streetLightNightProp != null) {
|
||||
final CommonPreference<Boolean> streetLightsNightPref = preferences.get(properties.indexOf(streetLightNightProp));
|
||||
final BottomSheetItemTwoChoicesButton[] item = new BottomSheetItemTwoChoicesButton[1];
|
||||
item[0] = (BottomSheetItemTwoChoicesButton) new BottomSheetItemTwoChoicesButton.Builder()
|
||||
.setLeftBtnSelected(!streetLightsNightPref.get())
|
||||
.setLeftBtnTitleRes(R.string.shared_string_all_time)
|
||||
.setRightBtnTitleRes(R.string.shared_string_night_map)
|
||||
.setOnBottomBtnClickListener(new OnBottomBtnClickListener() {
|
||||
@Override
|
||||
public void onBottomBtnClick(boolean onLeftClick) {
|
||||
streetLightsNightPref.set(!onLeftClick);
|
||||
}
|
||||
})
|
||||
.setCompoundButtonColorId(selectedProfileColorRes)
|
||||
.setChecked(pref.get())
|
||||
.setTitle(property.getName())
|
||||
.setIconHidden(true)
|
||||
.setLayoutId(R.layout.bottom_sheet_item_two_choices)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
boolean checked = !pref.get();
|
||||
pref.set(checked);
|
||||
streetLightsNightPref.set(false);
|
||||
item[0].setChecked(checked);
|
||||
item[0].setIsLeftBtnSelected(true);
|
||||
}
|
||||
})
|
||||
.create();
|
||||
items.add(item[0]);
|
||||
} else if (!STREET_LIGHTING_NIGHT.equals(property.getAttrName())) {
|
||||
final BottomSheetItemWithCompoundButton[] item = new BottomSheetItemWithCompoundButton[1];
|
||||
item[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder()
|
||||
.setCompoundButtonColorId(selectedProfileColorRes)
|
||||
.setChecked(pref.get())
|
||||
.setTitle(property.getName())
|
||||
.setIconHidden(true)
|
||||
.setLayoutId(R.layout.bottom_sheet_item_with_switch)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
boolean checked = !pref.get();
|
||||
pref.set(checked);
|
||||
item[0].setChecked(checked);
|
||||
}
|
||||
})
|
||||
.create();
|
||||
items.add(item[0]);
|
||||
}
|
||||
String attrName = property.getAttrName();
|
||||
if (MORE_DETAILED.equals(attrName) || SHOW_SURFACE_GRADE.equals(attrName)
|
||||
|| COLORED_BUILDINGS.equals(attrName) || STREET_LIGHTING.equals(attrName)) {
|
||||
items.add(new DividerItem(app));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private RenderingRuleProperty getStreetLightNightProp() {
|
||||
if (properties != null) {
|
||||
for (RenderingRuleProperty property : properties) {
|
||||
if (STREET_LIGHTING_NIGHT.equals(property.getAttrName())) {
|
||||
return property;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getDismissButtonTextId() {
|
||||
return R.string.shared_string_close;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismiss(@NonNull DialogInterface dialog) {
|
||||
boolean checked = false;
|
||||
int selected = 0;
|
||||
for (int i = 0; i < preferences.size(); i++) {
|
||||
boolean active = preferences.get(i).get();
|
||||
checked |= active;
|
||||
if (active) {
|
||||
selected++;
|
||||
}
|
||||
}
|
||||
if (adapter != null) {
|
||||
adapter.getItem(position).setSelected(checked);
|
||||
adapter.getItem(position).setColorRes(checked ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
|
||||
adapter.getItem(position).setDescription(getString(
|
||||
R.string.ltr_or_rtl_combine_via_slash,
|
||||
String.valueOf(selected),
|
||||
String.valueOf(preferences.size())));
|
||||
}
|
||||
if (arrayAdapter != null) {
|
||||
arrayAdapter.notifyDataSetInvalidated();
|
||||
}
|
||||
Activity activity = getActivity();
|
||||
if (activity instanceof MapActivity) {
|
||||
MapActivity a = (MapActivity) activity;
|
||||
ConfigureMapMenu.refreshMapComplete(a);
|
||||
a.getMapLayers().updateLayers(a.getMapView());
|
||||
}
|
||||
super.onDismiss(dialog);
|
||||
}
|
||||
|
||||
public void setProperties(List<RenderingRuleProperty> properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public void setPreferences(List<CommonPreference<Boolean>> preferences) {
|
||||
this.preferences = preferences;
|
||||
}
|
||||
|
||||
public void setAdapter(ContextMenuAdapter adapter) {
|
||||
this.adapter = adapter;
|
||||
}
|
||||
|
||||
public void setPosition(int position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public void setArrayAdapter(ArrayAdapter<?> arrayAdapter) {
|
||||
this.arrayAdapter = arrayAdapter;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue