Add modifications and improvements to builders and MenuBottomSheetDialogFragment; rewrite UI in AddWaypointBottomSheetDialogFragment
This commit is contained in:
parent
5c78fc904b
commit
2415551520
9 changed files with 307 additions and 282 deletions
|
@ -7,6 +7,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_title_height"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="@dimen/bottom_sheet_title_height"
|
||||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingRight="@dimen/content_padding"
|
||||
android:textAppearance="@style/TextAppearance.ListItemTitle"
|
||||
|
|
32
OsmAnd/res/layout/bottom_sheet_menu_base.xml
Normal file
32
OsmAnd/res/layout/bottom_sheet_menu_base.xml
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?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"
|
||||
tools:background="?attr/bg_color">
|
||||
|
||||
<ScrollView
|
||||
android:id="@+id/scroll_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/items_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="@dimen/bottom_sheet_content_padding_small"/>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
<View
|
||||
android:id="@+id/close_row_divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="?attr/dashboard_divider"/>
|
||||
|
||||
<include layout="@layout/bottom_sheet_item_cancel"/>
|
||||
|
||||
</LinearLayout>
|
|
@ -1,65 +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"
|
||||
tools:background="?attr/bg_color">
|
||||
|
||||
<ScrollView
|
||||
android:id="@+id/scroll_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="@dimen/bottom_sheet_content_padding_small">
|
||||
|
||||
<include layout="@layout/bottom_sheet_item_title"/>
|
||||
|
||||
<include
|
||||
android:id="@+id/replace_dest_row"
|
||||
layout="@layout/bottom_sheet_item_with_descr_56dp"/>
|
||||
|
||||
<include
|
||||
android:id="@+id/replace_start_row"
|
||||
layout="@layout/bottom_sheet_item_with_descr_56dp"/>
|
||||
|
||||
<View
|
||||
android:id="@+id/current_dest_divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginBottom="@dimen/bottom_sheet_content_padding_small"
|
||||
android:layout_marginLeft="@dimen/bottom_sheet_divider_margin_start"
|
||||
android:layout_marginStart="@dimen/bottom_sheet_divider_margin_start"
|
||||
android:layout_marginTop="@dimen/bottom_sheet_content_padding_small"
|
||||
android:background="?attr/dashboard_divider"/>
|
||||
|
||||
<include
|
||||
android:id="@+id/subsequent_dest_row"
|
||||
layout="@layout/bottom_sheet_item_with_descr_56dp"/>
|
||||
|
||||
<include
|
||||
android:id="@+id/first_intermediate_dest_row"
|
||||
layout="@layout/bottom_sheet_item_with_descr_56dp"/>
|
||||
|
||||
<include
|
||||
android:id="@+id/last_intermediate_dest_row"
|
||||
layout="@layout/bottom_sheet_item_with_descr_56dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
<View
|
||||
android:id="@+id/cancel_divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="?attr/dashboard_divider"/>
|
||||
|
||||
<include layout="@layout/bottom_sheet_item_cancel"/>
|
||||
|
||||
</LinearLayout>
|
|
@ -4,24 +4,33 @@ import android.app.Activity;
|
|||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.ColorRes;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.IdRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFragment {
|
||||
|
||||
private static final String USED_ON_MAP_KEY = "used_on_map";
|
||||
|
||||
protected List<BaseBottomSheetItem> items = new ArrayList<>();
|
||||
|
||||
protected boolean usedOnMap = true;
|
||||
protected boolean nightMode;
|
||||
|
||||
|
@ -103,27 +112,46 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
|
|||
});
|
||||
}
|
||||
|
||||
protected void setupItems(@NonNull final View mainView,
|
||||
@NonNull @IdRes int[] itemIds,
|
||||
@NonNull Drawable[] icons,
|
||||
@NonNull String[] titles,
|
||||
@NonNull String[] descriptions,
|
||||
@NonNull View.OnClickListener onClickListener) {
|
||||
for (int i = 0; i < itemIds.length; i++) {
|
||||
View item = mainView.findViewById(itemIds[i]);
|
||||
if (item != null) {
|
||||
if (icons[i] != null) {
|
||||
((ImageView) item.findViewById(R.id.icon)).setImageDrawable(icons[i]);
|
||||
}
|
||||
if (titles[i] != null) {
|
||||
((TextView) item.findViewById(R.id.title)).setText(titles[i]);
|
||||
}
|
||||
if (descriptions[i] != null) {
|
||||
((TextView) item.findViewById(R.id.description)).setText(descriptions[i]);
|
||||
}
|
||||
item.setOnClickListener(onClickListener);
|
||||
}
|
||||
protected View inflateMainView() {
|
||||
OsmandApplication app = getMyApplication();
|
||||
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
|
||||
|
||||
View mainView = View.inflate(new ContextThemeWrapper(app, themeRes), R.layout.bottom_sheet_menu_base, null);
|
||||
LinearLayout container = (LinearLayout) mainView.findViewById(R.id.items_container);
|
||||
|
||||
for (BaseBottomSheetItem item : items) {
|
||||
item.inflate(app, container, nightMode);
|
||||
}
|
||||
|
||||
int closeRowDividerColorId = getCloseRowDividerColorId();
|
||||
if (closeRowDividerColorId != -1) {
|
||||
mainView.findViewById(R.id.close_row_divider)
|
||||
.setBackgroundColor(ContextCompat.getColor(getContext(), closeRowDividerColorId));
|
||||
}
|
||||
mainView.findViewById(R.id.close_row).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
int closeRowTextId = getCloseRowTextId();
|
||||
if (closeRowTextId != -1) {
|
||||
((TextView) mainView.findViewById(R.id.close_row_text)).setText(closeRowTextId);
|
||||
}
|
||||
|
||||
setupHeightAndBackground(mainView, R.id.scroll_view);
|
||||
|
||||
return mainView;
|
||||
}
|
||||
|
||||
@ColorRes
|
||||
protected int getCloseRowDividerColorId() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@StringRes
|
||||
protected int getCloseRowTextId() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@DrawableRes
|
||||
|
|
|
@ -1,51 +1,64 @@
|
|||
package net.osmand.plus.base.bottomsheetmenu;
|
||||
|
||||
import android.support.annotation.LayoutRes;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
|
||||
public class BaseBottomSheetItem {
|
||||
|
||||
public static final int INVALID_POSITION = -1;
|
||||
public static final int INVALID_ID = -1;
|
||||
|
||||
private View customView;
|
||||
protected View view;
|
||||
@LayoutRes
|
||||
private int layoutId;
|
||||
private boolean disabled;
|
||||
private View.OnClickListener onClickListener;
|
||||
private int position;
|
||||
protected int position;
|
||||
|
||||
public BaseBottomSheetItem(View customView,
|
||||
public BaseBottomSheetItem(View view,
|
||||
@LayoutRes int layoutId,
|
||||
boolean disabled,
|
||||
View.OnClickListener onClickListener,
|
||||
int position) {
|
||||
this.customView = customView;
|
||||
this.view = view;
|
||||
this.layoutId = layoutId;
|
||||
this.disabled = disabled;
|
||||
this.onClickListener = onClickListener;
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public View getCustomView() {
|
||||
return customView;
|
||||
BaseBottomSheetItem() {
|
||||
|
||||
}
|
||||
|
||||
@LayoutRes
|
||||
public int getLayoutId() {
|
||||
return layoutId;
|
||||
public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) {
|
||||
View view = getView(app, nightMode);
|
||||
if (disabled) {
|
||||
view.setEnabled(false);
|
||||
view.setAlpha(.5f);
|
||||
}
|
||||
view.setOnClickListener(onClickListener);
|
||||
if (position != INVALID_POSITION) {
|
||||
container.addView(view, position);
|
||||
} else {
|
||||
container.addView(view);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDisabled() {
|
||||
return disabled;
|
||||
}
|
||||
|
||||
public View.OnClickListener getOnClickListener() {
|
||||
return onClickListener;
|
||||
}
|
||||
|
||||
public int getPosition() {
|
||||
return position;
|
||||
private View getView(OsmandApplication app, boolean nightMode) {
|
||||
if (view != null) {
|
||||
return view;
|
||||
}
|
||||
if (layoutId != INVALID_ID) {
|
||||
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
|
||||
return view = View.inflate(new ContextThemeWrapper(app, themeRes), layoutId, null);
|
||||
}
|
||||
throw new RuntimeException("BottomSheetItem must have specified view or layoutId.");
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
|
|
@ -2,16 +2,18 @@ package net.osmand.plus.base.bottomsheetmenu;
|
|||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.ColorRes;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.LayoutRes;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
|
||||
public class BottomSheetItemWithDescription extends SimpleBottomSheetItem {
|
||||
|
||||
private String description;
|
||||
@StringRes
|
||||
private int descriptionId;
|
||||
@ColorRes
|
||||
private int descriptionColorId;
|
||||
|
||||
|
@ -21,39 +23,30 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem {
|
|||
View.OnClickListener onClickListener,
|
||||
int position,
|
||||
Drawable icon,
|
||||
@DrawableRes int iconId,
|
||||
@ColorRes int iconColorId,
|
||||
String title,
|
||||
@StringRes int titleId,
|
||||
@ColorRes int titleColorId,
|
||||
String description,
|
||||
@StringRes int descriptionId,
|
||||
@ColorRes int descriptionColorId) {
|
||||
super(customView, layoutResId, clickable, onClickListener, position, icon, iconId, iconColorId, title, titleId, titleColorId);
|
||||
super(customView, layoutResId, clickable, onClickListener, position, icon, title, titleColorId);
|
||||
this.description = description;
|
||||
this.descriptionId = descriptionId;
|
||||
this.descriptionColorId = descriptionColorId;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
@StringRes
|
||||
public int getDescriptionId() {
|
||||
return descriptionId;
|
||||
}
|
||||
|
||||
@ColorRes
|
||||
public int getDescriptionColorId() {
|
||||
return descriptionColorId;
|
||||
@Override
|
||||
public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) {
|
||||
super.inflate(app, container, nightMode);
|
||||
if (description != null) {
|
||||
TextView descriptionTv = (TextView) view.findViewById(R.id.description);
|
||||
descriptionTv.setText(description);
|
||||
if (descriptionColorId != INVALID_ID) {
|
||||
descriptionTv.setTextColor(ContextCompat.getColor(app, descriptionColorId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder extends SimpleBottomSheetItem.Builder {
|
||||
|
||||
protected String description;
|
||||
@StringRes
|
||||
protected int descriptionId = INVALID_ID;
|
||||
@ColorRes
|
||||
protected int descriptionColorId = INVALID_ID;
|
||||
|
||||
|
@ -62,11 +55,6 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder setDescriptionId(@StringRes int descriptionId) {
|
||||
this.descriptionId = descriptionId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setDescriptionColorId(@ColorRes int descriptionColorId) {
|
||||
this.descriptionColorId = descriptionColorId;
|
||||
return this;
|
||||
|
@ -79,13 +67,9 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem {
|
|||
onClickListener,
|
||||
position,
|
||||
icon,
|
||||
iconId,
|
||||
iconColorId,
|
||||
title,
|
||||
titleId,
|
||||
titleColorId,
|
||||
description,
|
||||
descriptionId,
|
||||
descriptionColorId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
package net.osmand.plus.base.bottomsheetmenu;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.ColorRes;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
|
||||
public class DividerHalfBottomSheetItem extends BaseBottomSheetItem {
|
||||
|
||||
@ColorRes
|
||||
private int colorId;
|
||||
|
||||
public DividerHalfBottomSheetItem(Context context) {
|
||||
setupView(context, INVALID_ID, INVALID_POSITION);
|
||||
}
|
||||
|
||||
public DividerHalfBottomSheetItem(Context context, @ColorRes int colorId) {
|
||||
setupView(context, colorId, INVALID_POSITION);
|
||||
}
|
||||
|
||||
public DividerHalfBottomSheetItem(Context context, @ColorRes int colorId, int position) {
|
||||
setupView(context, colorId, position);
|
||||
}
|
||||
|
||||
private void setupView(Context context, @ColorRes int colorId, int position) {
|
||||
view = new View(context);
|
||||
this.colorId = colorId;
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) {
|
||||
super.inflate(app, container, nightMode);
|
||||
|
||||
int marginTopBottom = app.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_content_padding_small);
|
||||
int marginLeft = app.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_divider_margin_start);
|
||||
int height = AndroidUtils.dpToPx(app, 1);
|
||||
|
||||
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view.getLayoutParams();
|
||||
params.setMargins(marginLeft, marginTopBottom, 0, marginTopBottom);
|
||||
params.height = height;
|
||||
|
||||
view.setMinimumHeight(height);
|
||||
view.setBackgroundColor(ContextCompat.getColor(app, getBgColorId(nightMode)));
|
||||
}
|
||||
|
||||
@ColorRes
|
||||
private int getBgColorId(boolean nightMode) {
|
||||
if (colorId != INVALID_ID) {
|
||||
return colorId;
|
||||
}
|
||||
return nightMode ? R.color.dashboard_divider_dark : R.color.dashboard_divider_light;
|
||||
}
|
||||
}
|
|
@ -2,23 +2,20 @@ package net.osmand.plus.base.bottomsheetmenu;
|
|||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.ColorRes;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.LayoutRes;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
|
||||
public class SimpleBottomSheetItem extends BaseBottomSheetItem {
|
||||
|
||||
public static final int CONTENT_ICON_COLOR = -1;
|
||||
|
||||
private Drawable icon;
|
||||
@DrawableRes
|
||||
private int iconId;
|
||||
@ColorRes
|
||||
private int iconColorId;
|
||||
private String title;
|
||||
@StringRes
|
||||
private int titleId;
|
||||
@ColorRes
|
||||
private int titleColorId;
|
||||
|
||||
|
@ -28,58 +25,33 @@ public class SimpleBottomSheetItem extends BaseBottomSheetItem {
|
|||
View.OnClickListener onClickListener,
|
||||
int position,
|
||||
Drawable icon,
|
||||
@DrawableRes int iconId,
|
||||
@ColorRes int iconColorId,
|
||||
String title,
|
||||
@StringRes int titleId,
|
||||
@ColorRes int titleColorId) {
|
||||
super(customView, layoutResId, clickable, onClickListener, position);
|
||||
this.icon = icon;
|
||||
this.iconId = iconId;
|
||||
this.iconColorId = iconColorId;
|
||||
this.title = title;
|
||||
this.titleId = titleId;
|
||||
this.titleColorId = titleColorId;
|
||||
}
|
||||
|
||||
public Drawable getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
@DrawableRes
|
||||
public int getIconId() {
|
||||
return iconId;
|
||||
}
|
||||
|
||||
@ColorRes
|
||||
public int getIconColorId() {
|
||||
return iconColorId;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
@StringRes
|
||||
public int getTitleId() {
|
||||
return titleId;
|
||||
}
|
||||
|
||||
@ColorRes
|
||||
public int getTitleColorId() {
|
||||
return titleColorId;
|
||||
@Override
|
||||
public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) {
|
||||
super.inflate(app, container, nightMode);
|
||||
if (icon != null) {
|
||||
((ImageView) view.findViewById(R.id.icon)).setImageDrawable(icon);
|
||||
}
|
||||
if (title != null) {
|
||||
TextView titleTv = (TextView) view.findViewById(R.id.title);
|
||||
titleTv.setText(title);
|
||||
if (titleColorId != INVALID_ID) {
|
||||
titleTv.setTextColor(ContextCompat.getColor(app, titleColorId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder extends BaseBottomSheetItem.Builder {
|
||||
|
||||
protected Drawable icon;
|
||||
@DrawableRes
|
||||
protected int iconId = INVALID_ID;
|
||||
@ColorRes
|
||||
protected int iconColorId = CONTENT_ICON_COLOR;
|
||||
protected String title;
|
||||
@StringRes
|
||||
protected int titleId = INVALID_ID;
|
||||
@ColorRes
|
||||
protected int titleColorId = INVALID_ID;
|
||||
|
||||
|
@ -88,26 +60,11 @@ public class SimpleBottomSheetItem extends BaseBottomSheetItem {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder setIconId(@DrawableRes int iconId) {
|
||||
this.iconId = iconId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setIconColorId(@ColorRes int iconColorId) {
|
||||
this.iconColorId = iconColorId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setTitle(String title) {
|
||||
this.title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setTitleId(@StringRes int titleId) {
|
||||
this.titleId = titleId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setTitleColorId(@ColorRes int titleColorId) {
|
||||
this.titleColorId = titleColorId;
|
||||
return this;
|
||||
|
@ -120,10 +77,7 @@ public class SimpleBottomSheetItem extends BaseBottomSheetItem {
|
|||
onClickListener,
|
||||
position,
|
||||
icon,
|
||||
iconId,
|
||||
iconColorId,
|
||||
title,
|
||||
titleId,
|
||||
titleColorId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,14 +7,10 @@ import android.graphics.drawable.Drawable;
|
|||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.IdRes;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
|
@ -23,6 +19,10 @@ import net.osmand.plus.TargetPointsHelper;
|
|||
import net.osmand.plus.TargetPointsHelper.TargetPoint;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
|
||||
import net.osmand.plus.base.bottomsheetmenu.DividerHalfBottomSheetItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
|
||||
|
||||
public class AddWaypointBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
|
||||
|
||||
|
@ -39,84 +39,97 @@ public class AddWaypointBottomSheetDialogFragment extends MenuBottomSheetDialogF
|
|||
final PointDescription name = PointDescription.deserializeFromString(args.getString(POINT_DESCRIPTION_KEY), latLon);
|
||||
final TargetPointsHelper targetPointsHelper = getMyApplication().getTargetPointsHelper();
|
||||
|
||||
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
|
||||
final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes),
|
||||
R.layout.fragment_add_waypoint_bottom_sheet_dialog, container);
|
||||
BaseBottomSheetItem titleItem = new SimpleBottomSheetItem.Builder()
|
||||
.setTitle(getString(R.string.new_destination_point_dialog))
|
||||
.setLayoutId(R.layout.bottom_sheet_item_title)
|
||||
.create();
|
||||
items.add(titleItem);
|
||||
|
||||
((TextView) mainView.findViewById(R.id.title)).setText(R.string.new_destination_point_dialog);
|
||||
|
||||
@IdRes int[] ids = new int[]{
|
||||
R.id.replace_dest_row,
|
||||
R.id.replace_start_row,
|
||||
R.id.subsequent_dest_row,
|
||||
R.id.first_intermediate_dest_row,
|
||||
R.id.last_intermediate_dest_row,
|
||||
R.id.close_row
|
||||
};
|
||||
|
||||
Drawable[] icons = new Drawable[]{
|
||||
getIcon(R.drawable.list_destination, 0),
|
||||
getIcon(R.drawable.list_startpoint, 0),
|
||||
getSubsequentDestIcon(),
|
||||
getFirstIntermDestIcon(),
|
||||
getLastIntermDistIcon(),
|
||||
null
|
||||
};
|
||||
|
||||
String[] titles = new String[]{
|
||||
getString(R.string.replace_destination_point),
|
||||
getString(R.string.make_as_start_point),
|
||||
getString(R.string.keep_and_add_destination_point),
|
||||
getString(R.string.add_as_first_destination_point),
|
||||
getString(R.string.add_as_last_destination_point),
|
||||
null
|
||||
};
|
||||
|
||||
String[] descriptions = new String[]{
|
||||
getCurrentPointName(targetPointsHelper.getPointToNavigate(), false),
|
||||
getCurrentPointName(targetPointsHelper.getPointToStart(), true),
|
||||
getString(R.string.subsequent_dest_description),
|
||||
getString(R.string.first_intermediate_dest_description),
|
||||
getString(R.string.last_intermediate_dest_description),
|
||||
null
|
||||
};
|
||||
|
||||
View.OnClickListener onClickListener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int id = v.getId();
|
||||
if (id == R.id.replace_dest_row) {
|
||||
targetPointsHelper.navigateToPoint(latLon, true, -1, name);
|
||||
} else if (id == R.id.replace_start_row) {
|
||||
TargetPoint start = targetPointsHelper.getPointToStart();
|
||||
if (start != null) {
|
||||
targetPointsHelper.navigateToPoint(new LatLon(start.getLatitude(), start.getLongitude()),
|
||||
false, 0, start.getOriginalPointDescription());
|
||||
BaseBottomSheetItem replaceDestItem = new BottomSheetItemWithDescription.Builder()
|
||||
.setDescription(getCurrentPointName(targetPointsHelper.getPointToNavigate(), false))
|
||||
.setIcon(getIcon(R.drawable.list_destination, 0))
|
||||
.setTitle(getString(R.string.replace_destination_point))
|
||||
.setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
targetPointsHelper.navigateToPoint(latLon, true, -1, name);
|
||||
dismiss();
|
||||
}
|
||||
targetPointsHelper.setStartPoint(latLon, true, name);
|
||||
} else if (id == R.id.subsequent_dest_row) {
|
||||
targetPointsHelper.navigateToPoint(latLon, true,
|
||||
targetPointsHelper.getIntermediatePoints().size() + 1, name);
|
||||
} else if (id == R.id.first_intermediate_dest_row) {
|
||||
targetPointsHelper.navigateToPoint(latLon, true, 0, name);
|
||||
} else if (id == R.id.last_intermediate_dest_row) {
|
||||
targetPointsHelper.navigateToPoint(latLon, true, targetPointsHelper.getIntermediatePoints().size(), name);
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
};
|
||||
})
|
||||
.create();
|
||||
items.add(replaceDestItem);
|
||||
|
||||
setupItems(mainView, ids, icons, titles, descriptions, onClickListener);
|
||||
BaseBottomSheetItem replaceStartItem = new BottomSheetItemWithDescription.Builder()
|
||||
.setDescription(getCurrentPointName(targetPointsHelper.getPointToStart(), true))
|
||||
.setIcon(getIcon(R.drawable.list_startpoint, 0))
|
||||
.setTitle(getString(R.string.make_as_start_point))
|
||||
.setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
TargetPoint start = targetPointsHelper.getPointToStart();
|
||||
if (start != null) {
|
||||
targetPointsHelper.navigateToPoint(new LatLon(start.getLatitude(), start.getLongitude()),
|
||||
false, 0, start.getOriginalPointDescription());
|
||||
}
|
||||
targetPointsHelper.setStartPoint(latLon, true, name);
|
||||
dismiss();
|
||||
}
|
||||
})
|
||||
.create();
|
||||
items.add(replaceStartItem);
|
||||
|
||||
if (nightMode) {
|
||||
int dividerColor = ContextCompat.getColor(getContext(), R.color.route_info_bottom_view_bg_dark);
|
||||
mainView.findViewById(R.id.current_dest_divider).setBackgroundColor(dividerColor);
|
||||
mainView.findViewById(R.id.cancel_divider).setBackgroundColor(dividerColor);
|
||||
}
|
||||
items.add(new DividerHalfBottomSheetItem(getContext(), getCloseRowDividerColorId()));
|
||||
|
||||
setupHeightAndBackground(mainView, R.id.scroll_view);
|
||||
BaseBottomSheetItem subsequentDestItem = new BottomSheetItemWithDescription.Builder()
|
||||
.setDescription(getString(R.string.subsequent_dest_description))
|
||||
.setIcon(getSubsequentDestIcon())
|
||||
.setTitle(getString(R.string.keep_and_add_destination_point))
|
||||
.setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
targetPointsHelper.navigateToPoint(latLon, true,
|
||||
targetPointsHelper.getIntermediatePoints().size() + 1, name);
|
||||
dismiss();
|
||||
}
|
||||
})
|
||||
.create();
|
||||
items.add(subsequentDestItem);
|
||||
|
||||
return mainView;
|
||||
BaseBottomSheetItem firstIntermItem = new BottomSheetItemWithDescription.Builder()
|
||||
.setDescription(getString(R.string.first_intermediate_dest_description))
|
||||
.setIcon(getFirstIntermDestIcon())
|
||||
.setTitle(getString(R.string.add_as_first_destination_point))
|
||||
.setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
targetPointsHelper.navigateToPoint(latLon, true, 0, name);
|
||||
dismiss();
|
||||
}
|
||||
})
|
||||
.create();
|
||||
items.add(firstIntermItem);
|
||||
|
||||
BaseBottomSheetItem lastIntermItem = new BottomSheetItemWithDescription.Builder()
|
||||
.setDescription(getString(R.string.last_intermediate_dest_description))
|
||||
.setIcon(getLastIntermDistIcon())
|
||||
.setTitle(getString(R.string.add_as_last_destination_point))
|
||||
.setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
targetPointsHelper.navigateToPoint(latLon, true,
|
||||
targetPointsHelper.getIntermediatePoints().size(), name);
|
||||
dismiss();
|
||||
}
|
||||
})
|
||||
.create();
|
||||
items.add(lastIntermItem);
|
||||
|
||||
return inflateMainView();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -125,6 +138,11 @@ public class AddWaypointBottomSheetDialogFragment extends MenuBottomSheetDialogF
|
|||
closeContextMenu();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getCloseRowDividerColorId() {
|
||||
return nightMode ? R.color.route_info_bottom_view_bg_dark : -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Drawable getActiveIcon(@DrawableRes int id) {
|
||||
return getIcon(id, nightMode ? R.color.ctx_menu_direction_color_dark : R.color.map_widget_blue);
|
||||
|
|
Loading…
Reference in a new issue