From bdebb86bc6717209c5c4b6c8c492ecc53a03c035 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Mon, 26 Feb 2018 16:00:24 +0200 Subject: [PATCH 01/30] Optimising bottom sheet menus in progress --- .../res/layout/bottom_sheet_item_cancel.xml | 19 ++ OsmAnd/res/layout/bottom_sheet_item_title.xml | 14 + .../bottom_sheet_item_with_descr_56dp.xml | 48 ++++ ...gment_add_waypoint_bottom_sheet_dialog.xml | 268 +----------------- ...t_marker_add_group_bottom_sheet_dialog.xml | 17 +- .../base/MenuBottomSheetDialogFragment.java | 27 ++ .../AddWaypointBottomSheetDialogFragment.java | 52 +++- 7 files changed, 159 insertions(+), 286 deletions(-) create mode 100644 OsmAnd/res/layout/bottom_sheet_item_cancel.xml create mode 100644 OsmAnd/res/layout/bottom_sheet_item_title.xml create mode 100644 OsmAnd/res/layout/bottom_sheet_item_with_descr_56dp.xml diff --git a/OsmAnd/res/layout/bottom_sheet_item_cancel.xml b/OsmAnd/res/layout/bottom_sheet_item_cancel.xml new file mode 100644 index 0000000000..ede9b7246f --- /dev/null +++ b/OsmAnd/res/layout/bottom_sheet_item_cancel.xml @@ -0,0 +1,19 @@ + + + + + diff --git a/OsmAnd/res/layout/bottom_sheet_item_title.xml b/OsmAnd/res/layout/bottom_sheet_item_title.xml new file mode 100644 index 0000000000..20e13b51c9 --- /dev/null +++ b/OsmAnd/res/layout/bottom_sheet_item_title.xml @@ -0,0 +1,14 @@ + + diff --git a/OsmAnd/res/layout/bottom_sheet_item_with_descr_56dp.xml b/OsmAnd/res/layout/bottom_sheet_item_with_descr_56dp.xml new file mode 100644 index 0000000000..547a1f51aa --- /dev/null +++ b/OsmAnd/res/layout/bottom_sheet_item_with_descr_56dp.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + diff --git a/OsmAnd/res/layout/fragment_add_waypoint_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_add_waypoint_bottom_sheet_dialog.xml index f38c3a37f2..0aa0256853 100644 --- a/OsmAnd/res/layout/fragment_add_waypoint_bottom_sheet_dialog.xml +++ b/OsmAnd/res/layout/fragment_add_waypoint_bottom_sheet_dialog.xml @@ -1,7 +1,6 @@ - + - + layout="@layout/bottom_sheet_item_with_descr_56dp"/> - - - - - - - - - - - - - - - - - - - - - - - + layout="@layout/bottom_sheet_item_with_descr_56dp"/> - + layout="@layout/bottom_sheet_item_with_descr_56dp"/> - - - - - - - - - - - - + layout="@layout/bottom_sheet_item_with_descr_56dp"/> - - - - - - - - - - - - - - - - - - - - - - - + layout="@layout/bottom_sheet_item_with_descr_56dp"/> @@ -289,21 +60,6 @@ android:layout_height="1dp" android:background="?attr/dashboard_divider"/> - - - - + diff --git a/OsmAnd/res/layout/fragment_marker_add_group_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_marker_add_group_bottom_sheet_dialog.xml index 51a0820240..f3d754416f 100644 --- a/OsmAnd/res/layout/fragment_marker_add_group_bottom_sheet_dialog.xml +++ b/OsmAnd/res/layout/fragment_marker_add_group_bottom_sheet_dialog.xml @@ -41,21 +41,6 @@ android:layout_height="1dp" android:background="?attr/dashboard_divider"/> - - - - + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java index 59d3d52d56..0029563f61 100644 --- a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java @@ -5,10 +5,14 @@ import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; import android.support.annotation.DrawableRes; +import android.support.annotation.IdRes; +import android.support.annotation.NonNull; import android.view.View; import android.view.ViewTreeObserver; import android.view.Window; import android.view.WindowManager; +import android.widget.ImageView; +import android.widget.TextView; import net.osmand.AndroidUtils; import net.osmand.plus.R; @@ -99,6 +103,29 @@ 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); + } + } + } + @DrawableRes protected int getPortraitBgResId() { return nightMode ? R.drawable.bg_bottom_menu_dark : R.drawable.bg_bottom_menu_light; diff --git a/OsmAnd/src/net/osmand/plus/dialogs/AddWaypointBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/dialogs/AddWaypointBottomSheetDialogFragment.java index 67f1c11105..12858f5497 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/AddWaypointBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/AddWaypointBottomSheetDialogFragment.java @@ -7,13 +7,13 @@ 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.ImageView; import android.widget.TextView; import net.osmand.data.LatLon; @@ -43,14 +43,43 @@ public class AddWaypointBottomSheetDialogFragment extends MenuBottomSheetDialogF final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_add_waypoint_bottom_sheet_dialog, container); - ((TextView) mainView.findViewById(R.id.current_dest_text_view)) - .setText(getCurrentPointName(targetPointsHelper.getPointToNavigate(), false)); - ((TextView) mainView.findViewById(R.id.current_start_text_view)) - .setText(getCurrentPointName(targetPointsHelper.getPointToStart(), true)); + ((TextView) mainView.findViewById(R.id.title)).setText(R.string.new_destination_point_dialog); - ((ImageView) mainView.findViewById(R.id.subsequent_dest_icon)).setImageDrawable(getSubsequentDestIcon()); - ((ImageView) mainView.findViewById(R.id.first_interm_dest_icon)).setImageDrawable(getFirstIntermDestIcon()); - ((ImageView) mainView.findViewById(R.id.last_interm_dest_icon)).setImageDrawable(getLastIntermDistIcon()); + @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 @@ -77,12 +106,7 @@ public class AddWaypointBottomSheetDialogFragment extends MenuBottomSheetDialogF } }; - mainView.findViewById(R.id.replace_dest_row).setOnClickListener(onClickListener); - mainView.findViewById(R.id.replace_start_row).setOnClickListener(onClickListener); - mainView.findViewById(R.id.subsequent_dest_row).setOnClickListener(onClickListener); - mainView.findViewById(R.id.first_intermediate_dest_row).setOnClickListener(onClickListener); - mainView.findViewById(R.id.last_intermediate_dest_row).setOnClickListener(onClickListener); - mainView.findViewById(R.id.cancel_row).setOnClickListener(onClickListener); + setupItems(mainView, ids, icons, titles, descriptions, onClickListener); if (nightMode) { int dividerColor = ContextCompat.getColor(getContext(), R.color.route_info_bottom_view_bg_dark); From 348251306646bc5368b1a06c05f2033b62b8e549 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Mon, 26 Feb 2018 18:02:32 +0200 Subject: [PATCH 02/30] Remove unused files --- .../bottom_sheet_dialog_fragment_divider.xml | 16 ---------- .../bottom_sheet_dialog_fragment_item.xml | 31 ------------------- .../bottom_sheet_dialog_fragment_title.xml | 22 ------------- 3 files changed, 69 deletions(-) delete mode 100644 OsmAnd/res/layout/bottom_sheet_dialog_fragment_divider.xml delete mode 100644 OsmAnd/res/layout/bottom_sheet_dialog_fragment_item.xml delete mode 100644 OsmAnd/res/layout/bottom_sheet_dialog_fragment_title.xml diff --git a/OsmAnd/res/layout/bottom_sheet_dialog_fragment_divider.xml b/OsmAnd/res/layout/bottom_sheet_dialog_fragment_divider.xml deleted file mode 100644 index 05cc926985..0000000000 --- a/OsmAnd/res/layout/bottom_sheet_dialog_fragment_divider.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/OsmAnd/res/layout/bottom_sheet_dialog_fragment_item.xml b/OsmAnd/res/layout/bottom_sheet_dialog_fragment_item.xml deleted file mode 100644 index b0b4855034..0000000000 --- a/OsmAnd/res/layout/bottom_sheet_dialog_fragment_item.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/OsmAnd/res/layout/bottom_sheet_dialog_fragment_title.xml b/OsmAnd/res/layout/bottom_sheet_dialog_fragment_title.xml deleted file mode 100644 index a70510f0d2..0000000000 --- a/OsmAnd/res/layout/bottom_sheet_dialog_fragment_title.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - \ No newline at end of file From 5e3a6135b7dca3f3f7af057ba8dcfee8fa252921 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Mon, 26 Feb 2018 18:38:31 +0200 Subject: [PATCH 03/30] Create BaseBottomSheetItem and SimpleBottomSheetItem --- .../bottomsheetmenu/BaseBottomSheetItem.java | 86 +++++++++++++ .../SimpleBottomSheetItem.java | 119 ++++++++++++++++++ 2 files changed, 205 insertions(+) create mode 100644 OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java create mode 100644 OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java new file mode 100644 index 0000000000..0c8d18c3cd --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java @@ -0,0 +1,86 @@ +package net.osmand.plus.base.bottomsheetmenu; + +import android.support.annotation.LayoutRes; +import android.view.View; + +public class BaseBottomSheetItem { + + private View customView; + @LayoutRes + private int layoutResId; + private boolean clickable = true; + private View.OnClickListener onClickListener; + private int position = -1; + + public BaseBottomSheetItem(View customView, + @LayoutRes int layoutResId, + boolean clickable, + View.OnClickListener onClickListener, + int position) { + this.customView = customView; + this.layoutResId = layoutResId; + this.clickable = clickable; + this.onClickListener = onClickListener; + this.position = position; + } + + public View getCustomView() { + return customView; + } + + @LayoutRes + public int getLayoutResId() { + return layoutResId; + } + + public boolean isClickable() { + return clickable; + } + + public View.OnClickListener getOnClickListener() { + return onClickListener; + } + + public int getPosition() { + return position; + } + + public static class Builder { + + protected View customView; + @LayoutRes + protected int layoutResId; + protected boolean clickable; + protected View.OnClickListener onClickListener; + protected int position; + + public Builder setCustomView(View customView) { + this.customView = customView; + return this; + } + + public Builder setLayoutResId(@LayoutRes int layoutResId) { + this.layoutResId = layoutResId; + return this; + } + + public Builder setClickable(boolean clickable) { + this.clickable = clickable; + return this; + } + + public Builder setOnClickListener(View.OnClickListener onClickListener) { + this.onClickListener = onClickListener; + return this; + } + + public Builder setPosition(int position) { + this.position = position; + return this; + } + + public BaseBottomSheetItem create() { + return new BaseBottomSheetItem(customView, layoutResId, clickable, onClickListener, position); + } + } +} diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java new file mode 100644 index 0000000000..f0fc76a28d --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java @@ -0,0 +1,119 @@ +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.StringRes; +import android.view.View; + +public class SimpleBottomSheetItem extends BaseBottomSheetItem { + + private Drawable icon; + @DrawableRes + private int iconResId; + @ColorRes + private int iconColorResId; + private String title; + @StringRes + private int titleResId; + @ColorRes + private int titleColorResId; + + public SimpleBottomSheetItem(View customView, + int layoutResId, + boolean clickable, + View.OnClickListener onClickListener, + int position, + Drawable icon, + int iconResId, + int iconColorResId, + String title, + int titleResId, + int titleColorResId) { + super(customView, layoutResId, clickable, onClickListener, position); + this.icon = icon; + this.iconResId = iconResId; + this.iconColorResId = iconColorResId; + this.title = title; + this.titleResId = titleResId; + this.titleColorResId = titleColorResId; + } + + public Drawable getIcon() { + return icon; + } + + public int getIconResId() { + return iconResId; + } + + public int getIconColorResId() { + return iconColorResId; + } + + public String getTitle() { + return title; + } + + public int getTitleResId() { + return titleResId; + } + + public int getTitleColorResId() { + return titleColorResId; + } + + public static class Builder extends BaseBottomSheetItem.Builder { + + private Drawable icon; + private int iconResId; + private int iconColorResId; + private String title; + private int titleResId; + private int titleColorResId; + + public Builder setIcon(Drawable icon) { + this.icon = icon; + return this; + } + + public Builder setIconResId(int iconResId) { + this.iconResId = iconResId; + return this; + } + + public Builder setIconColorResId(int iconColorResId) { + this.iconColorResId = iconColorResId; + return this; + } + + public Builder setTitle(String title) { + this.title = title; + return this; + } + + public Builder setTitleResId(int titleResId) { + this.titleResId = titleResId; + return this; + } + + public Builder setTitleColorResId(int titleColorResId) { + this.titleColorResId = titleColorResId; + return this; + } + + public SimpleBottomSheetItem createSimpleBottomSheetItem() { + return new SimpleBottomSheetItem(customView, + layoutResId, + clickable, + onClickListener, + position, + icon, + iconResId, + iconColorResId, + title, + titleResId, + titleColorResId); + } + } +} From ba2819cb7c3d1e1b38271bd04cd79d2b7989f685 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Mon, 26 Feb 2018 18:54:33 +0200 Subject: [PATCH 04/30] Add small fixes to BaseBottomSheetItem and SimpleBottomSheetItem --- .../bottomsheetmenu/BaseBottomSheetItem.java | 34 +++---- .../SimpleBottomSheetItem.java | 90 ++++++++++--------- 2 files changed, 66 insertions(+), 58 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java index 0c8d18c3cd..8efc9d7969 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java @@ -7,19 +7,19 @@ public class BaseBottomSheetItem { private View customView; @LayoutRes - private int layoutResId; - private boolean clickable = true; + private int layoutId; + private boolean disabled; private View.OnClickListener onClickListener; private int position = -1; public BaseBottomSheetItem(View customView, - @LayoutRes int layoutResId, - boolean clickable, + @LayoutRes int layoutId, + boolean disabled, View.OnClickListener onClickListener, int position) { this.customView = customView; - this.layoutResId = layoutResId; - this.clickable = clickable; + this.layoutId = layoutId; + this.disabled = disabled; this.onClickListener = onClickListener; this.position = position; } @@ -29,12 +29,12 @@ public class BaseBottomSheetItem { } @LayoutRes - public int getLayoutResId() { - return layoutResId; + public int getLayoutId() { + return layoutId; } - public boolean isClickable() { - return clickable; + public boolean isDisabled() { + return disabled; } public View.OnClickListener getOnClickListener() { @@ -49,8 +49,8 @@ public class BaseBottomSheetItem { protected View customView; @LayoutRes - protected int layoutResId; - protected boolean clickable; + protected int layoutId; + protected boolean disabled; protected View.OnClickListener onClickListener; protected int position; @@ -59,13 +59,13 @@ public class BaseBottomSheetItem { return this; } - public Builder setLayoutResId(@LayoutRes int layoutResId) { - this.layoutResId = layoutResId; + public Builder setLayoutId(@LayoutRes int layoutId) { + this.layoutId = layoutId; return this; } - public Builder setClickable(boolean clickable) { - this.clickable = clickable; + public Builder setDisabled(boolean disabled) { + this.disabled = disabled; return this; } @@ -80,7 +80,7 @@ public class BaseBottomSheetItem { } public BaseBottomSheetItem create() { - return new BaseBottomSheetItem(customView, layoutResId, clickable, onClickListener, position); + return new BaseBottomSheetItem(customView, layoutId, disabled, onClickListener, position); } } } diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java index f0fc76a28d..25cae08154 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java @@ -10,14 +10,14 @@ public class SimpleBottomSheetItem extends BaseBottomSheetItem { private Drawable icon; @DrawableRes - private int iconResId; + private int iconId; @ColorRes - private int iconColorResId; + private int iconColorId; private String title; @StringRes - private int titleResId; + private int titleId; @ColorRes - private int titleColorResId; + private int titleColorId; public SimpleBottomSheetItem(View customView, int layoutResId, @@ -25,65 +25,73 @@ public class SimpleBottomSheetItem extends BaseBottomSheetItem { View.OnClickListener onClickListener, int position, Drawable icon, - int iconResId, - int iconColorResId, + @DrawableRes int iconId, + @ColorRes int iconColorId, String title, - int titleResId, - int titleColorResId) { + @StringRes int titleId, + @ColorRes int titleColorId) { super(customView, layoutResId, clickable, onClickListener, position); this.icon = icon; - this.iconResId = iconResId; - this.iconColorResId = iconColorResId; + this.iconId = iconId; + this.iconColorId = iconColorId; this.title = title; - this.titleResId = titleResId; - this.titleColorResId = titleColorResId; + this.titleId = titleId; + this.titleColorId = titleColorId; } public Drawable getIcon() { return icon; } - public int getIconResId() { - return iconResId; + @DrawableRes + public int getIconId() { + return iconId; } - public int getIconColorResId() { - return iconColorResId; + @ColorRes + public int getIconColorId() { + return iconColorId; } public String getTitle() { return title; } - public int getTitleResId() { - return titleResId; + @StringRes + public int getTitleId() { + return titleId; } - public int getTitleColorResId() { - return titleColorResId; + @ColorRes + public int getTitleColorId() { + return titleColorId; } public static class Builder extends BaseBottomSheetItem.Builder { - private Drawable icon; - private int iconResId; - private int iconColorResId; - private String title; - private int titleResId; - private int titleColorResId; + protected Drawable icon; + @DrawableRes + protected int iconId; + @ColorRes + protected int iconColorId; + protected String title; + @StringRes + protected int titleId; + @ColorRes + protected int titleColorId; public Builder setIcon(Drawable icon) { this.icon = icon; return this; } - public Builder setIconResId(int iconResId) { - this.iconResId = iconResId; + public Builder setIconId(@DrawableRes int iconId) { + this.iconId = iconId; return this; } - public Builder setIconColorResId(int iconColorResId) { - this.iconColorResId = iconColorResId; + public Builder setIconColorId(@ColorRes int iconColorId) { + this.iconColorId = iconColorId; return this; } @@ -92,28 +100,28 @@ public class SimpleBottomSheetItem extends BaseBottomSheetItem { return this; } - public Builder setTitleResId(int titleResId) { - this.titleResId = titleResId; + public Builder setTitleId(@StringRes int titleId) { + this.titleId = titleId; return this; } - public Builder setTitleColorResId(int titleColorResId) { - this.titleColorResId = titleColorResId; + public Builder setTitleColorId(@ColorRes int titleColorId) { + this.titleColorId = titleColorId; return this; } - public SimpleBottomSheetItem createSimpleBottomSheetItem() { + public SimpleBottomSheetItem create() { return new SimpleBottomSheetItem(customView, - layoutResId, - clickable, + layoutId, + disabled, onClickListener, position, icon, - iconResId, - iconColorResId, + iconId, + iconColorId, title, - titleResId, - titleColorResId); + titleId, + titleColorId); } } } From baffc79c545a10b84be6acf453a0f4eee9368023 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Mon, 26 Feb 2018 19:09:00 +0200 Subject: [PATCH 05/30] Add bottomSheetItemWithDescription --- .../BottomSheetItemWithDescription.java | 92 +++++++++++++++++++ .../SimpleBottomSheetItem.java | 3 +- 2 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java new file mode 100644 index 0000000000..d6eef8e95e --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java @@ -0,0 +1,92 @@ +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.view.View; + +public class BottomSheetItemWithDescription extends SimpleBottomSheetItem { + + private String description; + @StringRes + private int descriptionId; + @ColorRes + private int descriptionColorId; + + public BottomSheetItemWithDescription(View customView, + @LayoutRes int layoutResId, + boolean clickable, + 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); + 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; + } + + public static class Builder extends SimpleBottomSheetItem.Builder { + + protected String description; + @StringRes + protected int descriptionId; + @ColorRes + protected int descriptionColorId; + + public Builder setDescription(String description) { + this.description = description; + return this; + } + + public Builder setDescriptionId(@StringRes int descriptionId) { + this.descriptionId = descriptionId; + return this; + } + + public Builder setDescriptionColorId(@ColorRes int descriptionColorId) { + this.descriptionColorId = descriptionColorId; + return this; + } + + public BottomSheetItemWithDescription create() { + return new BottomSheetItemWithDescription(customView, + layoutId, + disabled, + onClickListener, + position, + icon, + iconId, + iconColorId, + title, + titleId, + titleColorId, + description, + descriptionId, + descriptionColorId); + } + } +} diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java index 25cae08154..37290afcc5 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java @@ -3,6 +3,7 @@ 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.view.View; @@ -20,7 +21,7 @@ public class SimpleBottomSheetItem extends BaseBottomSheetItem { private int titleColorId; public SimpleBottomSheetItem(View customView, - int layoutResId, + @LayoutRes int layoutResId, boolean clickable, View.OnClickListener onClickListener, int position, From 5c78fc904b92053829a078778a2572e84d672624 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Tue, 27 Feb 2018 12:31:19 +0200 Subject: [PATCH 06/30] Add some default values to builders --- .../plus/base/bottomsheetmenu/BaseBottomSheetItem.java | 9 ++++++--- .../BottomSheetItemWithDescription.java | 4 ++-- .../base/bottomsheetmenu/SimpleBottomSheetItem.java | 10 ++++++---- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java index 8efc9d7969..c25a20e4a4 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java @@ -5,12 +5,15 @@ import android.view.View; public class BaseBottomSheetItem { + public static final int INVALID_POSITION = -1; + public static final int INVALID_ID = -1; + private View customView; @LayoutRes private int layoutId; private boolean disabled; private View.OnClickListener onClickListener; - private int position = -1; + private int position; public BaseBottomSheetItem(View customView, @LayoutRes int layoutId, @@ -49,10 +52,10 @@ public class BaseBottomSheetItem { protected View customView; @LayoutRes - protected int layoutId; + protected int layoutId = INVALID_ID; protected boolean disabled; protected View.OnClickListener onClickListener; - protected int position; + protected int position = INVALID_POSITION; public Builder setCustomView(View customView) { this.customView = customView; diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java index d6eef8e95e..b1f78f5486 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java @@ -53,9 +53,9 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem { protected String description; @StringRes - protected int descriptionId; + protected int descriptionId = INVALID_ID; @ColorRes - protected int descriptionColorId; + protected int descriptionColorId = INVALID_ID; public Builder setDescription(String description) { this.description = description; diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java index 37290afcc5..d0e72734ce 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java @@ -9,6 +9,8 @@ import android.view.View; public class SimpleBottomSheetItem extends BaseBottomSheetItem { + public static final int CONTENT_ICON_COLOR = -1; + private Drawable icon; @DrawableRes private int iconId; @@ -72,14 +74,14 @@ public class SimpleBottomSheetItem extends BaseBottomSheetItem { protected Drawable icon; @DrawableRes - protected int iconId; + protected int iconId = INVALID_ID; @ColorRes - protected int iconColorId; + protected int iconColorId = CONTENT_ICON_COLOR; protected String title; @StringRes - protected int titleId; + protected int titleId = INVALID_ID; @ColorRes - protected int titleColorId; + protected int titleColorId = INVALID_ID; public Builder setIcon(Drawable icon) { this.icon = icon; From 2415551520cd8af2df7cff5a223f4fded90c69b6 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Tue, 27 Feb 2018 16:13:23 +0200 Subject: [PATCH 07/30] Add modifications and improvements to builders and MenuBottomSheetDialogFragment; rewrite UI in AddWaypointBottomSheetDialogFragment --- OsmAnd/res/layout/bottom_sheet_item_title.xml | 1 + OsmAnd/res/layout/bottom_sheet_menu_base.xml | 32 ++++ ...gment_add_waypoint_bottom_sheet_dialog.xml | 65 ------- .../base/MenuBottomSheetDialogFragment.java | 74 +++++--- .../bottomsheetmenu/BaseBottomSheetItem.java | 51 ++++-- .../BottomSheetItemWithDescription.java | 50 ++---- .../DividerHalfBottomSheetItem.java | 60 +++++++ .../SimpleBottomSheetItem.java | 86 +++------ .../AddWaypointBottomSheetDialogFragment.java | 170 ++++++++++-------- 9 files changed, 307 insertions(+), 282 deletions(-) create mode 100644 OsmAnd/res/layout/bottom_sheet_menu_base.xml delete mode 100644 OsmAnd/res/layout/fragment_add_waypoint_bottom_sheet_dialog.xml create mode 100644 OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/DividerHalfBottomSheetItem.java diff --git a/OsmAnd/res/layout/bottom_sheet_item_title.xml b/OsmAnd/res/layout/bottom_sheet_item_title.xml index 20e13b51c9..2f740ed30a 100644 --- a/OsmAnd/res/layout/bottom_sheet_item_title.xml +++ b/OsmAnd/res/layout/bottom_sheet_item_title.xml @@ -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" diff --git a/OsmAnd/res/layout/bottom_sheet_menu_base.xml b/OsmAnd/res/layout/bottom_sheet_menu_base.xml new file mode 100644 index 0000000000..ce1ee74322 --- /dev/null +++ b/OsmAnd/res/layout/bottom_sheet_menu_base.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + diff --git a/OsmAnd/res/layout/fragment_add_waypoint_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_add_waypoint_bottom_sheet_dialog.xml deleted file mode 100644 index 0aa0256853..0000000000 --- a/OsmAnd/res/layout/fragment_add_waypoint_bottom_sheet_dialog.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java index 0029563f61..695418a78a 100644 --- a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java @@ -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 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 diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java index c25a20e4a4..d86727cd50 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java @@ -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 { diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java index b1f78f5486..e4e42b6619 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java @@ -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); } } diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/DividerHalfBottomSheetItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/DividerHalfBottomSheetItem.java new file mode 100644 index 0000000000..ad473ca65d --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/DividerHalfBottomSheetItem.java @@ -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; + } +} diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java index d0e72734ce..509adae923 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java @@ -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); } } diff --git a/OsmAnd/src/net/osmand/plus/dialogs/AddWaypointBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/dialogs/AddWaypointBottomSheetDialogFragment.java index 12858f5497..51cc2e7ee8 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/AddWaypointBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/AddWaypointBottomSheetDialogFragment.java @@ -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); From 3c1f14b1fe368ef73a3a443419e6c00cab73b841 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Tue, 27 Feb 2018 17:19:58 +0200 Subject: [PATCH 08/30] Rename layoutResId to layoutId; replace MenuBottomSheetDialogFragment#onCreateView with MenuBottomSheetDialogFragment#createMenuItems --- .../ItemMenuBottomSheetDialogFragment.java | 4 +- .../SortByMenuBottomSheetDialogFragment.java | 4 +- .../base/MenuBottomSheetDialogFragment.java | 77 +++++++++++-------- .../BottomSheetItemWithDescription.java | 4 +- .../SimpleBottomSheetItem.java | 4 +- .../AddWaypointBottomSheetDialogFragment.java | 5 +- .../net/osmand/plus/helpers/ImportHelper.java | 3 +- .../other/ShareMenuFragment.java | 4 +- .../AddGroupBottomSheetDialogFragment.java | 4 +- ...rdinateInputBottomSheetDialogFragment.java | 3 +- ...ryMarkerMenuBottomSheetDialogFragment.java | 4 +- .../OrderByBottomSheetDialogFragment.java | 4 +- ...RouteOptionsBottomSheetDialogFragment.java | 4 +- ...MarkersGroupBottomSheetDialogFragment.java | 4 +- .../OptionsBottomSheetDialogFragment.java | 4 +- ...veAsNewTrackBottomSheetDialogFragment.java | 4 +- ...electedPointBottomSheetDialogFragment.java | 4 +- ...xportOptionsBottomSheetDialogFragment.java | 4 +- .../FileTypeBottomSheetDialogFragment.java | 4 +- ...mEditOptionsBottomSheetDialogFragment.java | 4 +- 20 files changed, 67 insertions(+), 85 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/audionotes/ItemMenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/audionotes/ItemMenuBottomSheetDialogFragment.java index e0184bf6e0..de18984f67 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/ItemMenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/ItemMenuBottomSheetDialogFragment.java @@ -1,7 +1,6 @@ package net.osmand.plus.audionotes; import android.os.Bundle; -import android.support.annotation.Nullable; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; @@ -32,9 +31,8 @@ public class ItemMenuBottomSheetDialogFragment extends MenuBottomSheetDialogFrag this.recording = recording; } - @Nullable @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), diff --git a/OsmAnd/src/net/osmand/plus/audionotes/SortByMenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/audionotes/SortByMenuBottomSheetDialogFragment.java index 96e7d6b185..a8e240f26b 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/SortByMenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/SortByMenuBottomSheetDialogFragment.java @@ -1,7 +1,6 @@ package net.osmand.plus.audionotes; import android.os.Bundle; -import android.support.annotation.Nullable; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; @@ -24,9 +23,8 @@ public class SortByMenuBottomSheetDialogFragment extends MenuBottomSheetDialogFr this.listener = listener; } - @Nullable @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), diff --git a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java index 695418a78a..dbebf0aa59 100644 --- a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java @@ -6,10 +6,13 @@ import android.os.Build; import android.os.Bundle; import android.support.annotation.ColorRes; import android.support.annotation.DrawableRes; +import android.support.annotation.Nullable; import android.support.annotation.StringRes; import android.support.v4.content.ContextCompat; import android.view.ContextThemeWrapper; +import android.view.LayoutInflater; import android.view.View; +import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.view.Window; import android.view.WindowManager; @@ -47,6 +50,45 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra nightMode = isNightMode(); } + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) { + View view = createMenuItems(inflater, parent, savedInstanceState); + if (view != null) { + return view; + } + + 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; + } + @Override public void onStart() { super.onStart(); @@ -64,6 +106,9 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra outState.putBoolean(USED_ON_MAP_KEY, usedOnMap); } + // inflater, parent and return value are temporary and will be deleted + public abstract View createMenuItems(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState); + @Override protected Drawable getContentIcon(@DrawableRes int id) { return getIcon(id, nightMode ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color); @@ -112,38 +157,6 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra }); } - 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; diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java index e4e42b6619..d2fd6b8f81 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java @@ -18,7 +18,7 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem { private int descriptionColorId; public BottomSheetItemWithDescription(View customView, - @LayoutRes int layoutResId, + @LayoutRes int layoutId, boolean clickable, View.OnClickListener onClickListener, int position, @@ -27,7 +27,7 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem { @ColorRes int titleColorId, String description, @ColorRes int descriptionColorId) { - super(customView, layoutResId, clickable, onClickListener, position, icon, title, titleColorId); + super(customView, layoutId, clickable, onClickListener, position, icon, title, titleColorId); this.description = description; this.descriptionColorId = descriptionColorId; } diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java index 509adae923..9c9ac3a160 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java @@ -20,14 +20,14 @@ public class SimpleBottomSheetItem extends BaseBottomSheetItem { private int titleColorId; public SimpleBottomSheetItem(View customView, - @LayoutRes int layoutResId, + @LayoutRes int layoutId, boolean clickable, View.OnClickListener onClickListener, int position, Drawable icon, String title, @ColorRes int titleColorId) { - super(customView, layoutResId, clickable, onClickListener, position); + super(customView, layoutId, clickable, onClickListener, position); this.icon = icon; this.title = title; this.titleColorId = titleColorId; diff --git a/OsmAnd/src/net/osmand/plus/dialogs/AddWaypointBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/dialogs/AddWaypointBottomSheetDialogFragment.java index 51cc2e7ee8..e6341b264f 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/AddWaypointBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/AddWaypointBottomSheetDialogFragment.java @@ -31,9 +31,8 @@ public class AddWaypointBottomSheetDialogFragment extends MenuBottomSheetDialogF public static final String LON_KEY = "longitude"; public static final String POINT_DESCRIPTION_KEY = "point_description"; - @Nullable @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Bundle args = getArguments(); final LatLon latLon = new LatLon(args.getDouble(LAT_KEY), args.getDouble(LON_KEY)); final PointDescription name = PointDescription.deserializeFromString(args.getString(POINT_DESCRIPTION_KEY), latLon); @@ -129,7 +128,7 @@ public class AddWaypointBottomSheetDialogFragment extends MenuBottomSheetDialogF .create(); items.add(lastIntermItem); - return inflateMainView(); + return null; } @Override diff --git a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java index 9fa877cf67..b420dedcf5 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java @@ -742,9 +742,8 @@ public class ImportHelper { this.useImportDir = useImportDir; } - @Nullable @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_import_gpx_bottom_sheet_dialog, container); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ShareMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ShareMenuFragment.java index 650cfa12c9..0487aa8aab 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ShareMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ShareMenuFragment.java @@ -2,7 +2,6 @@ package net.osmand.plus.mapcontextmenu.other; import android.annotation.SuppressLint; import android.os.Bundle; -import android.support.annotation.Nullable; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; @@ -38,9 +37,8 @@ public class ShareMenuFragment extends MenuBottomSheetDialogFragment implements } } - @Nullable @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; final View view = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.share_menu_fragment, container); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/AddGroupBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/AddGroupBottomSheetDialogFragment.java index 9366dab18e..73a0762911 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/AddGroupBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/AddGroupBottomSheetDialogFragment.java @@ -2,7 +2,6 @@ package net.osmand.plus.mapmarkers; import android.app.Dialog; import android.os.Bundle; -import android.support.annotation.Nullable; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.ContextThemeWrapper; @@ -35,9 +34,8 @@ public abstract class AddGroupBottomSheetDialogFragment extends MenuBottomSheetD mapMarkersHelper = getMyApplication().getMapMarkersHelper(); } - @Nullable @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_add_group_bottom_sheet_dialog, container); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java index dea0ec8632..22a031c0a7 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java @@ -51,9 +51,8 @@ public class CoordinateInputBottomSheetDialogFragment extends MenuBottomSheetDia } } - @Nullable @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final Context context = getContext(); final OsmandSettings settings = getMyApplication().getSettings(); final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java index 3fe99d59cb..62cbfd4412 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java @@ -1,7 +1,6 @@ package net.osmand.plus.mapmarkers; import android.os.Bundle; -import android.support.annotation.Nullable; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; @@ -32,9 +31,8 @@ public class HistoryMarkerMenuBottomSheetDialogFragment extends MenuBottomSheetD this.listener = listener; } - @Nullable @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_history_bottom_sheet_dialog, container); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java index b50682748d..45acbc3514 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java @@ -2,7 +2,6 @@ package net.osmand.plus.mapmarkers; import android.graphics.drawable.Drawable; import android.os.Bundle; -import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; @@ -26,9 +25,8 @@ public class OrderByBottomSheetDialogFragment extends MenuBottomSheetDialogFragm this.listener = listener; } - @Nullable @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java index fe04c57e83..53be218d7c 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java @@ -1,7 +1,6 @@ package net.osmand.plus.mapmarkers; import android.os.Bundle; -import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; @@ -30,9 +29,8 @@ public class PlanRouteOptionsBottomSheetDialogFragment extends MenuBottomSheetDi this.selectAll = selectAll; } - @Nullable @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { boolean portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/SelectionMarkersGroupBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/SelectionMarkersGroupBottomSheetDialogFragment.java index 720cb2068e..f661e14c0e 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/SelectionMarkersGroupBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/SelectionMarkersGroupBottomSheetDialogFragment.java @@ -1,7 +1,6 @@ package net.osmand.plus.mapmarkers; import android.os.Bundle; -import android.support.annotation.Nullable; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; @@ -22,9 +21,8 @@ public class SelectionMarkersGroupBottomSheetDialogFragment extends MenuBottomSh this.listener = listener; } - @Nullable @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_add_markers_group_bottom_sheet_dialog, container); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java index ab83c69048..6666fa933b 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java @@ -1,7 +1,6 @@ package net.osmand.plus.measurementtool; import android.os.Bundle; -import android.support.annotation.Nullable; import android.support.v7.widget.SwitchCompat; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; @@ -33,9 +32,8 @@ public class OptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragm this.snapToRoadEnabled = snapToRoadEnabled; } - @Nullable @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_options_bottom_sheet_dialog, null); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java index b277349831..a349d03da3 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java @@ -1,7 +1,6 @@ package net.osmand.plus.measurementtool; import android.os.Bundle; -import android.support.annotation.Nullable; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.MotionEvent; @@ -23,9 +22,8 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial this.listener = listener; } - @Nullable @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_save_as_new_track_bottom_sheet_dialog, container); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java index 58900037e5..e59a41a948 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java @@ -2,7 +2,6 @@ package net.osmand.plus.measurementtool; import android.content.DialogInterface; import android.os.Bundle; -import android.support.annotation.Nullable; import android.text.TextUtils; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; @@ -31,9 +30,8 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo this.listener = listener; } - @Nullable @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final MapActivity mapActivity = (MapActivity) getActivity(); final MeasurementToolLayer measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer(); final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; diff --git a/OsmAnd/src/net/osmand/plus/osmedit/ExportOptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/ExportOptionsBottomSheetDialogFragment.java index 2fcc6742ff..fd852081ea 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/ExportOptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/ExportOptionsBottomSheetDialogFragment.java @@ -1,7 +1,6 @@ package net.osmand.plus.osmedit; import android.os.Bundle; -import android.support.annotation.Nullable; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; @@ -29,9 +28,8 @@ public class ExportOptionsBottomSheetDialogFragment extends MenuBottomSheetDialo this.listener = listener; } - @Nullable @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_osm_export_options_bottom_sheet_dialog, container); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/FileTypeBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/FileTypeBottomSheetDialogFragment.java index ce23d47238..48cfbc97e5 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/FileTypeBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/FileTypeBottomSheetDialogFragment.java @@ -2,7 +2,6 @@ package net.osmand.plus.osmedit; import android.graphics.drawable.Drawable; import android.os.Bundle; -import android.support.annotation.Nullable; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; @@ -24,9 +23,8 @@ public class FileTypeBottomSheetDialogFragment extends MenuBottomSheetDialogFrag this.listener = listener; } - @Nullable @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_osm_file_type_bottom_sheet_dialog, container); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditOptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditOptionsBottomSheetDialogFragment.java index ef45713fb6..20e492bf05 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditOptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditOptionsBottomSheetDialogFragment.java @@ -1,7 +1,6 @@ package net.osmand.plus.osmedit; import android.os.Bundle; -import android.support.annotation.Nullable; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; @@ -24,9 +23,8 @@ public class OsmEditOptionsBottomSheetDialogFragment extends MenuBottomSheetDial this.listener = listener; } - @Nullable @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_osm_edit_options_bottom_sheet_dialog, container); From fa4a8ef87629d2751742000354b24727639be349 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Tue, 27 Feb 2018 18:50:06 +0200 Subject: [PATCH 09/30] Rewrite UI in AddGroupBottomSheetDialogFragment --- .../res/layout/bottom_sheet_item_cancel.xml | 19 ------------------- OsmAnd/res/layout/bottom_sheet_menu_base.xml | 19 ++++++++++++++++++- ...t_marker_add_group_bottom_sheet_dialog.xml | 10 +--------- .../base/MenuBottomSheetDialogFragment.java | 15 +++++++++++++-- .../AddGroupBottomSheetDialogFragment.java | 15 +++++---------- 5 files changed, 37 insertions(+), 41 deletions(-) delete mode 100644 OsmAnd/res/layout/bottom_sheet_item_cancel.xml diff --git a/OsmAnd/res/layout/bottom_sheet_item_cancel.xml b/OsmAnd/res/layout/bottom_sheet_item_cancel.xml deleted file mode 100644 index ede9b7246f..0000000000 --- a/OsmAnd/res/layout/bottom_sheet_item_cancel.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - diff --git a/OsmAnd/res/layout/bottom_sheet_menu_base.xml b/OsmAnd/res/layout/bottom_sheet_menu_base.xml index ce1ee74322..0cd6c6fc04 100644 --- a/OsmAnd/res/layout/bottom_sheet_menu_base.xml +++ b/OsmAnd/res/layout/bottom_sheet_menu_base.xml @@ -27,6 +27,23 @@ android:layout_height="1dp" android:background="?attr/dashboard_divider"/> - + + + + + diff --git a/OsmAnd/res/layout/fragment_marker_add_group_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_marker_add_group_bottom_sheet_dialog.xml index f3d754416f..8d5b5f0bef 100644 --- a/OsmAnd/res/layout/fragment_marker_add_group_bottom_sheet_dialog.xml +++ b/OsmAnd/res/layout/fragment_marker_add_group_bottom_sheet_dialog.xml @@ -11,8 +11,7 @@ android:id="@+id/groups_recycler_view" android:layout_width="match_parent" android:layout_height="wrap_content" - android:clipToPadding="false" - android:paddingBottom="@dimen/bottom_sheet_content_padding_small"/> + android:clipToPadding="false"/> - - - - \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java index dbebf0aa59..b0a9ebfe6b 100644 --- a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java @@ -37,6 +37,8 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra protected boolean usedOnMap = true; protected boolean nightMode; + private LinearLayout itemsContainer; + public void setUsedOnMap(boolean usedOnMap) { this.usedOnMap = usedOnMap; } @@ -62,10 +64,10 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra 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); + itemsContainer = (LinearLayout) mainView.findViewById(R.id.items_container); for (BaseBottomSheetItem item : items) { - item.inflate(app, container, nightMode); + item.inflate(app, itemsContainer, nightMode); } int closeRowDividerColorId = getCloseRowDividerColorId(); @@ -106,6 +108,15 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra outState.putBoolean(USED_ON_MAP_KEY, usedOnMap); } + @Override + public void onDestroyView() { + super.onDestroyView(); + items.clear(); + if (itemsContainer != null) { + itemsContainer.removeAllViews(); + } + } + // inflater, parent and return value are temporary and will be deleted public abstract View createMenuItems(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/AddGroupBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/AddGroupBottomSheetDialogFragment.java index 73a0762911..47fe043663 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/AddGroupBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/AddGroupBottomSheetDialogFragment.java @@ -13,6 +13,7 @@ import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup; import net.osmand.plus.R; import net.osmand.plus.base.MenuBottomSheetDialogFragment; +import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.mapmarkers.adapters.GroupsAdapter; public abstract class AddGroupBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { @@ -37,7 +38,8 @@ public abstract class AddGroupBottomSheetDialogFragment extends MenuBottomSheetD @Override public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; - mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_add_group_bottom_sheet_dialog, container); + mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), + R.layout.fragment_marker_add_group_bottom_sheet_dialog, null); final RecyclerView recyclerView = mainView.findViewById(R.id.groups_recycler_view); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); @@ -65,16 +67,9 @@ public abstract class AddGroupBottomSheetDialogFragment extends MenuBottomSheetD }); recyclerView.setAdapter(adapter); - mainView.findViewById(R.id.close_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - dismiss(); - } - }); + items.add(new BaseBottomSheetItem.Builder().setCustomView(mainView).create()); - setupHeightAndBackground(mainView, R.id.groups_recycler_view); - - return mainView; + return null; } @Override From 29b164350b57e56d82f36d845aeb1e7361af5962 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Tue, 27 Feb 2018 20:00:30 +0200 Subject: [PATCH 10/30] Refactor some code; rewrite UI in ExportOptionsBottomSheetDialogFragment --- .../layout/bottom_sheet_item_description.xml | 15 ++ OsmAnd/res/layout/bottom_sheet_item_title.xml | 2 + .../bottom_sheet_item_with_right_descr.xml | 43 ++++ ...osm_export_options_bottom_sheet_dialog.xml | 195 ------------------ .../bottomsheetmenu/BaseBottomSheetItem.java | 6 +- .../BottomSheetItemWithDescription.java | 8 +- .../SimpleBottomSheetItem.java | 8 +- .../simpleitems/DescriptionItem.java | 12 ++ .../DividerHalfItem.java} | 11 +- .../simpleitems/TitleItem.java | 21 ++ .../AddWaypointBottomSheetDialogFragment.java | 12 +- ...xportOptionsBottomSheetDialogFragment.java | 127 +++++------- 12 files changed, 173 insertions(+), 287 deletions(-) create mode 100644 OsmAnd/res/layout/bottom_sheet_item_description.xml create mode 100644 OsmAnd/res/layout/bottom_sheet_item_with_right_descr.xml delete mode 100644 OsmAnd/res/layout/fragment_osm_export_options_bottom_sheet_dialog.xml create mode 100644 OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DescriptionItem.java rename OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/{DividerHalfBottomSheetItem.java => simpleitems/DividerHalfItem.java} (81%) create mode 100644 OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/TitleItem.java diff --git a/OsmAnd/res/layout/bottom_sheet_item_description.xml b/OsmAnd/res/layout/bottom_sheet_item_description.xml new file mode 100644 index 0000000000..91d1ef1d99 --- /dev/null +++ b/OsmAnd/res/layout/bottom_sheet_item_description.xml @@ -0,0 +1,15 @@ + + diff --git a/OsmAnd/res/layout/bottom_sheet_item_title.xml b/OsmAnd/res/layout/bottom_sheet_item_title.xml index 2f740ed30a..6fa4eb12fe 100644 --- a/OsmAnd/res/layout/bottom_sheet_item_title.xml +++ b/OsmAnd/res/layout/bottom_sheet_item_title.xml @@ -6,7 +6,9 @@ android:id="@+id/title" android:layout_width="match_parent" android:layout_height="@dimen/bottom_sheet_title_height" + android:ellipsize="end" android:gravity="center_vertical" + android:maxLines="1" android:minHeight="@dimen/bottom_sheet_title_height" android:paddingLeft="@dimen/content_padding" android:paddingRight="@dimen/content_padding" diff --git a/OsmAnd/res/layout/bottom_sheet_item_with_right_descr.xml b/OsmAnd/res/layout/bottom_sheet_item_with_right_descr.xml new file mode 100644 index 0000000000..3c34cb0979 --- /dev/null +++ b/OsmAnd/res/layout/bottom_sheet_item_with_right_descr.xml @@ -0,0 +1,43 @@ + + + + + + + + + + diff --git a/OsmAnd/res/layout/fragment_osm_export_options_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_osm_export_options_bottom_sheet_dialog.xml deleted file mode 100644 index db5d8c5b42..0000000000 --- a/OsmAnd/res/layout/fragment_osm_export_options_bottom_sheet_dialog.xml +++ /dev/null @@ -1,195 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java index d86727cd50..5d1999dc9f 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java @@ -15,10 +15,10 @@ public class BaseBottomSheetItem { protected View view; @LayoutRes - private int layoutId; + protected int layoutId = INVALID_ID; private boolean disabled; private View.OnClickListener onClickListener; - protected int position; + protected int position = INVALID_POSITION; public BaseBottomSheetItem(View view, @LayoutRes int layoutId, @@ -32,7 +32,7 @@ public class BaseBottomSheetItem { this.position = position; } - BaseBottomSheetItem() { + protected BaseBottomSheetItem() { } diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java index d2fd6b8f81..5792e859f4 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java @@ -13,9 +13,9 @@ import net.osmand.plus.R; public class BottomSheetItemWithDescription extends SimpleBottomSheetItem { - private String description; + protected String description; @ColorRes - private int descriptionColorId; + private int descriptionColorId = INVALID_ID; public BottomSheetItemWithDescription(View customView, @LayoutRes int layoutId, @@ -32,6 +32,10 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem { this.descriptionColorId = descriptionColorId; } + protected BottomSheetItemWithDescription() { + + } + @Override public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) { super.inflate(app, container, nightMode); diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java index 9c9ac3a160..a3e6eb8e37 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java @@ -15,9 +15,9 @@ import net.osmand.plus.R; public class SimpleBottomSheetItem extends BaseBottomSheetItem { private Drawable icon; - private String title; + protected String title; @ColorRes - private int titleColorId; + protected int titleColorId = INVALID_ID; public SimpleBottomSheetItem(View customView, @LayoutRes int layoutId, @@ -33,6 +33,10 @@ public class SimpleBottomSheetItem extends BaseBottomSheetItem { this.titleColorId = titleColorId; } + protected SimpleBottomSheetItem() { + + } + @Override public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) { super.inflate(app, container, nightMode); diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DescriptionItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DescriptionItem.java new file mode 100644 index 0000000000..a271d15647 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DescriptionItem.java @@ -0,0 +1,12 @@ +package net.osmand.plus.base.bottomsheetmenu.simpleitems; + +import net.osmand.plus.R; +import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription; + +public class DescriptionItem extends BottomSheetItemWithDescription { + + public DescriptionItem(String description) { + this.description = description; + this.layoutId = R.layout.bottom_sheet_item_description; + } +} diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/DividerHalfBottomSheetItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DividerHalfItem.java similarity index 81% rename from OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/DividerHalfBottomSheetItem.java rename to OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DividerHalfItem.java index ad473ca65d..6f55a2bb0b 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/DividerHalfBottomSheetItem.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DividerHalfItem.java @@ -1,4 +1,4 @@ -package net.osmand.plus.base.bottomsheetmenu; +package net.osmand.plus.base.bottomsheetmenu.simpleitems; import android.content.Context; import android.support.annotation.ColorRes; @@ -10,21 +10,22 @@ import android.widget.LinearLayout; import net.osmand.AndroidUtils; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; +import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; -public class DividerHalfBottomSheetItem extends BaseBottomSheetItem { +public class DividerHalfItem extends BaseBottomSheetItem { @ColorRes private int colorId; - public DividerHalfBottomSheetItem(Context context) { + public DividerHalfItem(Context context) { setupView(context, INVALID_ID, INVALID_POSITION); } - public DividerHalfBottomSheetItem(Context context, @ColorRes int colorId) { + public DividerHalfItem(Context context, @ColorRes int colorId) { setupView(context, colorId, INVALID_POSITION); } - public DividerHalfBottomSheetItem(Context context, @ColorRes int colorId, int position) { + public DividerHalfItem(Context context, @ColorRes int colorId, int position) { setupView(context, colorId, position); } diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/TitleItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/TitleItem.java new file mode 100644 index 0000000000..18a25d73b3 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/TitleItem.java @@ -0,0 +1,21 @@ +package net.osmand.plus.base.bottomsheetmenu.simpleitems; + +import android.view.ViewGroup; + +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; + +public class TitleItem extends SimpleBottomSheetItem { + + public TitleItem(String title) { + this.title = title; + this.layoutId = R.layout.bottom_sheet_item_title; + } + + @Override + public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) { + titleColorId = nightMode ? R.color.ctx_menu_info_text_dark : INVALID_ID; + super.inflate(app, container, nightMode); + } +} diff --git a/OsmAnd/src/net/osmand/plus/dialogs/AddWaypointBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/dialogs/AddWaypointBottomSheetDialogFragment.java index e6341b264f..33724a34e1 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/AddWaypointBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/AddWaypointBottomSheetDialogFragment.java @@ -21,8 +21,8 @@ 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; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; public class AddWaypointBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { @@ -38,11 +38,7 @@ public class AddWaypointBottomSheetDialogFragment extends MenuBottomSheetDialogF final PointDescription name = PointDescription.deserializeFromString(args.getString(POINT_DESCRIPTION_KEY), latLon); final TargetPointsHelper targetPointsHelper = getMyApplication().getTargetPointsHelper(); - BaseBottomSheetItem titleItem = new SimpleBottomSheetItem.Builder() - .setTitle(getString(R.string.new_destination_point_dialog)) - .setLayoutId(R.layout.bottom_sheet_item_title) - .create(); - items.add(titleItem); + items.add(new TitleItem(getString(R.string.new_destination_point_dialog))); BaseBottomSheetItem replaceDestItem = new BottomSheetItemWithDescription.Builder() .setDescription(getCurrentPointName(targetPointsHelper.getPointToNavigate(), false)) @@ -79,7 +75,7 @@ public class AddWaypointBottomSheetDialogFragment extends MenuBottomSheetDialogF .create(); items.add(replaceStartItem); - items.add(new DividerHalfBottomSheetItem(getContext(), getCloseRowDividerColorId())); + items.add(new DividerHalfItem(getContext(), getCloseRowDividerColorId())); BaseBottomSheetItem subsequentDestItem = new BottomSheetItemWithDescription.Builder() .setDescription(getString(R.string.subsequent_dest_description)) diff --git a/OsmAnd/src/net/osmand/plus/osmedit/ExportOptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/ExportOptionsBottomSheetDialogFragment.java index fd852081ea..359ee0bf5d 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/ExportOptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/ExportOptionsBottomSheetDialogFragment.java @@ -1,17 +1,17 @@ package net.osmand.plus.osmedit; import android.os.Bundle; -import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; import net.osmand.plus.R; 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.simpleitems.DescriptionItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; import net.osmand.plus.osmedit.OsmEditsFragment.ExportTypesDef; -import net.osmand.plus.widgets.TextViewEx; public class ExportOptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { @@ -30,88 +30,71 @@ public class ExportOptionsBottomSheetDialogFragment extends MenuBottomSheetDialo @Override public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; - final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), - R.layout.fragment_osm_export_options_bottom_sheet_dialog, container); - Bundle args = getArguments(); if (args != null) { poiCount = args.getInt(POI_COUNT_KEY); osmNotesCount = args.getInt(NOTES_COUNT_KEY); } - if (nightMode) { - ((TextViewEx) mainView.findViewById(R.id.title_text_view)).setTextColor(getResources().getColor(R.color.ctx_menu_info_text_dark)); - } + items.add(new TitleItem(getString(R.string.shared_string_export))); - ((ImageView) mainView.findViewById(R.id.poi_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_info_dark)); - ((ImageView) mainView.findViewById(R.id.osm_notes_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_bug_dark)); - ((ImageView) mainView.findViewById(R.id.all_data_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_folder)); + items.add(new DescriptionItem(getString(R.string.osm_edits_export_desc))); - ((TextView) mainView.findViewById(R.id.poi_count_text_view)).setText(String.valueOf(poiCount)); - ((TextView) mainView.findViewById(R.id.osm_notes_count_text_view)).setText(String.valueOf(osmNotesCount)); - ((TextView) mainView.findViewById(R.id.all_data_count_text_view)).setText(String.valueOf(poiCount + osmNotesCount)); - - View poiRow = mainView.findViewById(R.id.poi_row); - if (poiCount > 0) { - poiRow.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (listener != null) { - listener.onClick(OsmEditsFragment.EXPORT_TYPE_POI); + BaseBottomSheetItem poiItem = new BottomSheetItemWithDescription.Builder() + .setDescription(String.valueOf(poiCount)) + .setIcon(getContentIcon(R.drawable.ic_action_info_dark)) + .setTitle(getString(R.string.poi)) + .setLayoutId(R.layout.bottom_sheet_item_with_right_descr) + .setDisabled(!(poiCount > 0)) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.onClick(OsmEditsFragment.EXPORT_TYPE_POI); + } + dismiss(); } - dismiss(); - } - }); - } else { - disable(poiRow); - } + }) + .create(); + items.add(poiItem); - View osmNotesRow = mainView.findViewById(R.id.osm_notes_row); - if (osmNotesCount > 0) { - osmNotesRow.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (listener != null) { - listener.onClick(OsmEditsFragment.EXPORT_TYPE_NOTES); + BaseBottomSheetItem osmNotesItem = new BottomSheetItemWithDescription.Builder() + .setDescription(String.valueOf(osmNotesCount)) + .setIcon(getContentIcon(R.drawable.ic_action_bug_dark)) + .setTitle(getString(R.string.osm_notes)) + .setLayoutId(R.layout.bottom_sheet_item_with_right_descr) + .setDisabled(!(osmNotesCount > 0)) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.onClick(OsmEditsFragment.EXPORT_TYPE_NOTES); + } + dismiss(); } - dismiss(); - } - }); - } else { - disable(osmNotesRow); - } + }) + .create(); + items.add(osmNotesItem); - View allDataRow = mainView.findViewById(R.id.all_data_row); - if ((poiCount + osmNotesCount) > 0) { - allDataRow.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (listener != null) { - listener.onClick(OsmEditsFragment.EXPORT_TYPE_ALL); + BaseBottomSheetItem allDataItem = new BottomSheetItemWithDescription.Builder() + .setDescription(String.valueOf(poiCount + osmNotesCount)) + .setIcon(getContentIcon(R.drawable.ic_action_folder)) + .setTitle(getString(R.string.all_data)) + .setLayoutId(R.layout.bottom_sheet_item_with_right_descr) + .setDisabled(!(poiCount + osmNotesCount > 0)) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.onClick(OsmEditsFragment.EXPORT_TYPE_ALL); + } + dismiss(); } - dismiss(); - } - }); - } else { - disable(allDataRow); - } + }) + .create(); + items.add(allDataItem); - mainView.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - dismiss(); - } - }); - - setupHeightAndBackground(mainView, R.id.scroll_view); - - return mainView; - } - - private void disable(View view) { - view.setEnabled(false); - view.setAlpha(.5f); + return null; } public interface ExportOptionsFragmentListener { From 679a28bde5b10ba4624e698dc7e35f9f960b8579 Mon Sep 17 00:00:00 2001 From: alex Date: Wed, 28 Feb 2018 10:36:25 +0200 Subject: [PATCH 11/30] Rewrite UI in FileTypeBottomSheetDialogFragment --- ...ment_osm_file_type_bottom_sheet_dialog.xml | 164 ------------------ .../FileTypeBottomSheetDialogFragment.java | 78 ++++----- 2 files changed, 39 insertions(+), 203 deletions(-) delete mode 100644 OsmAnd/res/layout/fragment_osm_file_type_bottom_sheet_dialog.xml diff --git a/OsmAnd/res/layout/fragment_osm_file_type_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_osm_file_type_bottom_sheet_dialog.xml deleted file mode 100644 index 77911fdab2..0000000000 --- a/OsmAnd/res/layout/fragment_osm_file_type_bottom_sheet_dialog.xml +++ /dev/null @@ -1,164 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/OsmAnd/src/net/osmand/plus/osmedit/FileTypeBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/FileTypeBottomSheetDialogFragment.java index 48cfbc97e5..242338544c 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/FileTypeBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/FileTypeBottomSheetDialogFragment.java @@ -2,16 +2,17 @@ package net.osmand.plus.osmedit; import android.graphics.drawable.Drawable; import android.os.Bundle; -import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; import net.osmand.plus.R; 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.simpleitems.DividerHalfItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; import net.osmand.plus.osmedit.OsmEditsFragment.FileTypesDef; -import net.osmand.plus.widgets.TextViewEx; public class FileTypeBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { @@ -25,48 +26,47 @@ public class FileTypeBottomSheetDialogFragment extends MenuBottomSheetDialogFrag @Override public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; - final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), - R.layout.fragment_osm_file_type_bottom_sheet_dialog, container); - - if (nightMode) { - ((TextViewEx) mainView.findViewById(R.id.title_text_view)).setTextColor(getResources().getColor(R.color.ctx_menu_info_text_dark)); - } + items.add(new TitleItem(getString(R.string.choose_file_type))); Drawable fileIcon = getContentIcon(R.drawable.ic_type_file); - ((ImageView) mainView.findViewById(R.id.osc_file_icon)).setImageDrawable(fileIcon); - ((ImageView) mainView.findViewById(R.id.gpx_file_icon)).setImageDrawable(fileIcon); - mainView.findViewById(R.id.osc_file_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (listener != null) { - listener.onClick(OsmEditsFragment.FILE_TYPE_OSC); - } - dismiss(); - } - }); + BaseBottomSheetItem oscItem = new BottomSheetItemWithDescription.Builder() + .setDescription(getString(R.string.osc_file_desc)) + .setIcon(fileIcon) + .setTitle(getString(R.string.osc_file)) + .setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.onClick(OsmEditsFragment.FILE_TYPE_OSC); + } + dismiss(); + } + }) + .create(); + items.add(oscItem); - mainView.findViewById(R.id.gpx_file_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (listener != null) { - listener.onClick(OsmEditsFragment.FILE_TYPE_GPX); - } - dismiss(); - } - }); + items.add(new DividerHalfItem(getContext())); - mainView.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - dismiss(); - } - }); + BaseBottomSheetItem gpxItem = new BottomSheetItemWithDescription.Builder() + .setDescription(getString(R.string.gpx_file_desc)) + .setIcon(fileIcon) + .setTitle(getString(R.string.gpx_file)) + .setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.onClick(OsmEditsFragment.FILE_TYPE_GPX); + } + dismiss(); + } + }) + .create(); + items.add(gpxItem); - setupHeightAndBackground(mainView, R.id.scroll_view); - - return mainView; + return null; } public interface FileTypeFragmentListener { From 63623fb269a1ee14892ac2935267ccd41316a4d8 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 28 Feb 2018 14:34:16 +0200 Subject: [PATCH 12/30] Refactor dividers --- .../simpleitems/DividerHalfItem.java | 47 ++------------ .../simpleitems/DividerItem.java | 64 +++++++++++++++++++ 2 files changed, 70 insertions(+), 41 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DividerItem.java diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DividerHalfItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DividerHalfItem.java index 6f55a2bb0b..a8b7ed9b6c 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DividerHalfItem.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DividerHalfItem.java @@ -2,60 +2,25 @@ package net.osmand.plus.base.bottomsheetmenu.simpleitems; 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; -import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; -public class DividerHalfItem extends BaseBottomSheetItem { - - @ColorRes - private int colorId; +public class DividerHalfItem extends DividerItem { public DividerHalfItem(Context context) { - setupView(context, INVALID_ID, INVALID_POSITION); + super(context); } public DividerHalfItem(Context context, @ColorRes int colorId) { - setupView(context, colorId, INVALID_POSITION); + super(context, colorId); } public DividerHalfItem(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; + super(context, colorId, 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; + protected int getLeftMargin(Context context) { + return context.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_divider_margin_start); } } diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DividerItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DividerItem.java new file mode 100644 index 0000000000..b199554f90 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DividerItem.java @@ -0,0 +1,64 @@ +package net.osmand.plus.base.bottomsheetmenu.simpleitems; + +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; +import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; + +public class DividerItem extends BaseBottomSheetItem { + + @ColorRes + private int colorId; + + public DividerItem(Context context) { + setupView(context, INVALID_ID, INVALID_POSITION); + } + + public DividerItem(Context context, @ColorRes int colorId) { + setupView(context, colorId, INVALID_POSITION); + } + + public DividerItem(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 height = AndroidUtils.dpToPx(app, 1); + + LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view.getLayoutParams(); + params.setMargins(getLeftMargin(app), marginTopBottom, 0, marginTopBottom); + params.height = height; + + view.setMinimumHeight(height); + view.setBackgroundColor(ContextCompat.getColor(app, getBgColorId(nightMode))); + } + + protected int getLeftMargin(Context context) { + return 0; + } + + @ColorRes + private int getBgColorId(boolean nightMode) { + if (colorId != INVALID_ID) { + return colorId; + } + return nightMode ? R.color.dashboard_divider_dark : R.color.dashboard_divider_light; + } +} From 8d3e0bcdf2fbc39af10667d2e0cc558c9d999a03 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 28 Feb 2018 14:42:27 +0200 Subject: [PATCH 13/30] Fix default description text color --- OsmAnd/res/layout/bottom_sheet_item_with_descr_56dp.xml | 3 +-- .../plus/dialogs/AddWaypointBottomSheetDialogFragment.java | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/OsmAnd/res/layout/bottom_sheet_item_with_descr_56dp.xml b/OsmAnd/res/layout/bottom_sheet_item_with_descr_56dp.xml index 547a1f51aa..25ee93e4e2 100644 --- a/OsmAnd/res/layout/bottom_sheet_item_with_descr_56dp.xml +++ b/OsmAnd/res/layout/bottom_sheet_item_with_descr_56dp.xml @@ -40,8 +40,7 @@ android:layout_height="wrap_content" android:ellipsize="end" android:maxLines="2" - android:textColor="@color/searchbar_text_hint_light" - android:textSize="@dimen/default_desc_text_size" + android:textAppearance="@style/TextAppearance.ContextMenuSubtitle" tools:text="Some description"/> diff --git a/OsmAnd/src/net/osmand/plus/dialogs/AddWaypointBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/dialogs/AddWaypointBottomSheetDialogFragment.java index 33724a34e1..8be79919f4 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/AddWaypointBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/AddWaypointBottomSheetDialogFragment.java @@ -42,6 +42,7 @@ public class AddWaypointBottomSheetDialogFragment extends MenuBottomSheetDialogF BaseBottomSheetItem replaceDestItem = new BottomSheetItemWithDescription.Builder() .setDescription(getCurrentPointName(targetPointsHelper.getPointToNavigate(), false)) + .setDescriptionColorId(R.color.searchbar_text_hint_light) .setIcon(getIcon(R.drawable.list_destination, 0)) .setTitle(getString(R.string.replace_destination_point)) .setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp) @@ -57,6 +58,7 @@ public class AddWaypointBottomSheetDialogFragment extends MenuBottomSheetDialogF BaseBottomSheetItem replaceStartItem = new BottomSheetItemWithDescription.Builder() .setDescription(getCurrentPointName(targetPointsHelper.getPointToStart(), true)) + .setDescriptionColorId(R.color.searchbar_text_hint_light) .setIcon(getIcon(R.drawable.list_startpoint, 0)) .setTitle(getString(R.string.make_as_start_point)) .setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp) @@ -79,6 +81,7 @@ public class AddWaypointBottomSheetDialogFragment extends MenuBottomSheetDialogF BaseBottomSheetItem subsequentDestItem = new BottomSheetItemWithDescription.Builder() .setDescription(getString(R.string.subsequent_dest_description)) + .setDescriptionColorId(R.color.searchbar_text_hint_light) .setIcon(getSubsequentDestIcon()) .setTitle(getString(R.string.keep_and_add_destination_point)) .setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp) @@ -95,6 +98,7 @@ public class AddWaypointBottomSheetDialogFragment extends MenuBottomSheetDialogF BaseBottomSheetItem firstIntermItem = new BottomSheetItemWithDescription.Builder() .setDescription(getString(R.string.first_intermediate_dest_description)) + .setDescriptionColorId(R.color.searchbar_text_hint_light) .setIcon(getFirstIntermDestIcon()) .setTitle(getString(R.string.add_as_first_destination_point)) .setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp) @@ -110,6 +114,7 @@ public class AddWaypointBottomSheetDialogFragment extends MenuBottomSheetDialogF BaseBottomSheetItem lastIntermItem = new BottomSheetItemWithDescription.Builder() .setDescription(getString(R.string.last_intermediate_dest_description)) + .setDescriptionColorId(R.color.searchbar_text_hint_light) .setIcon(getLastIntermDistIcon()) .setTitle(getString(R.string.add_as_last_destination_point)) .setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp) From eb3ed364d8a36ed0360116b10b65d9361cac7020 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 28 Feb 2018 15:24:10 +0200 Subject: [PATCH 14/30] Rewrite UI in HistoryMarkerMenuBottomSheetDialogFragment; fix some small issues --- .../res/layout/bottom_sheet_item_simple.xml | 33 ++++ .../bottom_sheet_item_with_right_descr.xml | 3 + ...ent_marker_history_bottom_sheet_dialog.xml | 161 ------------------ .../bottomsheetmenu/BaseBottomSheetItem.java | 1 + ...ryMarkerMenuBottomSheetDialogFragment.java | 103 ++++++----- 5 files changed, 94 insertions(+), 207 deletions(-) create mode 100644 OsmAnd/res/layout/bottom_sheet_item_simple.xml delete mode 100644 OsmAnd/res/layout/fragment_marker_history_bottom_sheet_dialog.xml diff --git a/OsmAnd/res/layout/bottom_sheet_item_simple.xml b/OsmAnd/res/layout/bottom_sheet_item_simple.xml new file mode 100644 index 0000000000..296ba82392 --- /dev/null +++ b/OsmAnd/res/layout/bottom_sheet_item_simple.xml @@ -0,0 +1,33 @@ + + + + + + + + diff --git a/OsmAnd/res/layout/bottom_sheet_item_with_right_descr.xml b/OsmAnd/res/layout/bottom_sheet_item_with_right_descr.xml index 3c34cb0979..a5ebb7fd3a 100644 --- a/OsmAnd/res/layout/bottom_sheet_item_with_right_descr.xml +++ b/OsmAnd/res/layout/bottom_sheet_item_with_right_descr.xml @@ -5,6 +5,7 @@ android:layout_width="match_parent" android:layout_height="@dimen/bottom_sheet_list_item_height" android:background="?attr/selectableItemBackground" + android:gravity="center_vertical" android:minHeight="@dimen/bottom_sheet_list_item_height" android:paddingLeft="@dimen/content_padding" android:paddingRight="@dimen/content_padding"> @@ -36,6 +37,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" + android:ellipsize="end" + android:maxLines="1" android:textColor="?android:textColorSecondary" android:textSize="@dimen/default_list_text_size" tools:text="Description"/> diff --git a/OsmAnd/res/layout/fragment_marker_history_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_marker_history_bottom_sheet_dialog.xml deleted file mode 100644 index a53f553019..0000000000 --- a/OsmAnd/res/layout/fragment_marker_history_bottom_sheet_dialog.xml +++ /dev/null @@ -1,161 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java index 5d1999dc9f..a35d59840b 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java @@ -43,6 +43,7 @@ public class BaseBottomSheetItem { view.setAlpha(.5f); } view.setOnClickListener(onClickListener); + view.setClickable(onClickListener != null); if (position != INVALID_POSITION) { container.addView(view, position); } else { diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java index 62cbfd4412..28920114c4 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java @@ -1,16 +1,18 @@ package net.osmand.plus.mapmarkers; import android.os.Bundle; -import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.R; 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.SimpleBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem; +import net.osmand.util.Algorithms; import java.text.SimpleDateFormat; import java.util.Date; @@ -33,60 +35,69 @@ public class HistoryMarkerMenuBottomSheetDialogFragment extends MenuBottomSheetD @Override public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; - - final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_history_bottom_sheet_dialog, container); - Bundle arguments = getArguments(); + if (arguments != null) { final int pos = arguments.getInt(MARKER_POSITION); - String markerName = arguments.getString(MARKER_NAME); - int markerColorIndex = arguments.getInt(MARKER_COLOR_INDEX); - long markerVisitedDate = arguments.getLong(MARKER_VISITED_DATE); - ((TextView) mainView.findViewById(R.id.map_marker_title)).setText(markerName); - ((ImageView) mainView.findViewById(R.id.map_marker_icon)).setImageDrawable(getIcon(R.drawable.ic_action_flag_dark, MapMarker.getColorId(markerColorIndex))); + final String markerName = arguments.getString(MARKER_NAME); + final int markerColorIndex = arguments.getInt(MARKER_COLOR_INDEX); + final long markerVisitedDate = arguments.getLong(MARKER_VISITED_DATE); + Date date = new Date(markerVisitedDate); String month = new SimpleDateFormat("MMM", Locale.getDefault()).format(date); - if (month.length() > 1) { - month = Character.toUpperCase(month.charAt(0)) + month.substring(1); - } + month = Algorithms.capitalizeFirstLetter(month); month = month.replaceAll("\\.", ""); String day = new SimpleDateFormat("d", Locale.getDefault()).format(date); - ((TextView) mainView.findViewById(R.id.map_marker_passed_info)).setText(getString(R.string.passed, month + " " + day)); - mainView.findViewById(R.id.make_active_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (listener != null) { - listener.onMakeMarkerActive(pos); - } - dismiss(); - } - }); - mainView.findViewById(R.id.delete_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (listener != null) { - listener.onDeleteMarker(pos); - } - dismiss(); - } - }); + BaseBottomSheetItem markerItem = new BottomSheetItemWithDescription.Builder() + .setDescription(getString(R.string.passed, month + " " + day)) + .setIcon(getIcon(R.drawable.ic_action_flag_dark, MapMarker.getColorId(markerColorIndex))) + .setTitle(markerName) + .setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp) + .create(); + items.add(markerItem); + + items.add(new DividerItem(getContext())); + + BaseBottomSheetItem makeActiveItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_reset_to_default_dark)) + .setTitle(getString(R.string.make_active)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.onMakeMarkerActive(pos); + } + dismiss(); + } + }) + .create(); + items.add(makeActiveItem); + + BaseBottomSheetItem deleteItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_delete_dark)) + .setTitle(getString(R.string.shared_string_delete)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.onDeleteMarker(pos); + } + dismiss(); + } + }) + .create(); + items.add(deleteItem); } - ((ImageView) mainView.findViewById(R.id.make_active_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_reset_to_default_dark)); - ((ImageView) mainView.findViewById(R.id.delete_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_delete_dark)); + return null; + } - mainView.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - dismiss(); - } - }); - - setupHeightAndBackground(mainView, R.id.history_marker_scroll_view); - - return mainView; + @Override + protected int getCloseRowTextId() { + return R.string.shared_string_close; } interface HistoryMarkerMenuFragmentListener { From abbe3284d2d3d4f790d7bae393f8e8bc7b8984fa Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 28 Feb 2018 16:01:58 +0200 Subject: [PATCH 15/30] Rewrite UI in ImportGpxBottomSheetDialogFragment; fix some small issues --- ...ragment_import_gpx_bottom_sheet_dialog.xml | 142 ------------------ .../BottomSheetItemWithDescription.java | 8 +- .../simpleitems/DescriptionItem.java | 2 +- .../simpleitems/DividerHalfItem.java | 5 + .../simpleitems/DividerItem.java | 11 +- .../net/osmand/plus/helpers/ImportHelper.java | 84 ++++++----- 6 files changed, 64 insertions(+), 188 deletions(-) delete mode 100644 OsmAnd/res/layout/fragment_import_gpx_bottom_sheet_dialog.xml diff --git a/OsmAnd/res/layout/fragment_import_gpx_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_import_gpx_bottom_sheet_dialog.xml deleted file mode 100644 index 67525105f1..0000000000 --- a/OsmAnd/res/layout/fragment_import_gpx_bottom_sheet_dialog.xml +++ /dev/null @@ -1,142 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java index 5792e859f4..c6294d4384 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java @@ -13,7 +13,7 @@ import net.osmand.plus.R; public class BottomSheetItemWithDescription extends SimpleBottomSheetItem { - protected String description; + protected CharSequence description; @ColorRes private int descriptionColorId = INVALID_ID; @@ -25,7 +25,7 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem { Drawable icon, String title, @ColorRes int titleColorId, - String description, + CharSequence description, @ColorRes int descriptionColorId) { super(customView, layoutId, clickable, onClickListener, position, icon, title, titleColorId); this.description = description; @@ -50,11 +50,11 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem { public static class Builder extends SimpleBottomSheetItem.Builder { - protected String description; + protected CharSequence description; @ColorRes protected int descriptionColorId = INVALID_ID; - public Builder setDescription(String description) { + public Builder setDescription(CharSequence description) { this.description = description; return this; } diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DescriptionItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DescriptionItem.java index a271d15647..759c2273bb 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DescriptionItem.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DescriptionItem.java @@ -5,7 +5,7 @@ import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription; public class DescriptionItem extends BottomSheetItemWithDescription { - public DescriptionItem(String description) { + public DescriptionItem(CharSequence description) { this.description = description; this.layoutId = R.layout.bottom_sheet_item_description; } diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DividerHalfItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DividerHalfItem.java index a8b7ed9b6c..4d2b965a9e 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DividerHalfItem.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DividerHalfItem.java @@ -19,6 +19,11 @@ public class DividerHalfItem extends DividerItem { super(context, colorId, position); } + @Override + protected int getTopMargin(Context context) { + return context.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_divider_margin_top); + } + @Override protected int getLeftMargin(Context context) { return context.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_divider_margin_start); diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DividerItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DividerItem.java index b199554f90..749235b733 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DividerItem.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/DividerItem.java @@ -39,21 +39,28 @@ public class DividerItem extends BaseBottomSheetItem { 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 height = AndroidUtils.dpToPx(app, 1); LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view.getLayoutParams(); - params.setMargins(getLeftMargin(app), marginTopBottom, 0, marginTopBottom); + params.setMargins(getLeftMargin(app), getTopMargin(app), 0, getBottomMargin(app)); params.height = height; view.setMinimumHeight(height); view.setBackgroundColor(ContextCompat.getColor(app, getBgColorId(nightMode))); } + protected int getTopMargin(Context context) { + return context.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_content_padding_small); + } + protected int getLeftMargin(Context context) { return 0; } + protected int getBottomMargin(Context context) { + return context.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_content_padding_small); + } + @ColorRes private int getBgColorId(boolean nightMode) { if (colorId != INVALID_ID) { diff --git a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java index b420dedcf5..b721b408d8 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java @@ -13,20 +13,18 @@ import android.os.Bundle; import android.os.ParcelFileDescriptor; import android.provider.OpenableColumns; import android.provider.Settings; +import android.support.annotation.ColorInt; +import android.support.annotation.ColorRes; import android.support.annotation.NonNull; -import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.text.SpannableStringBuilder; import android.text.Spanned; import android.text.style.ForegroundColorSpan; -import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; import android.widget.Toast; import net.osmand.IProgress; @@ -39,6 +37,11 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; 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.SimpleBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.DescriptionItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; import net.osmand.plus.myplaces.FavoritesActivity; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.util.Algorithms; @@ -744,50 +747,53 @@ public class ImportHelper { @Override public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; + items.add(new TitleItem(getString(R.string.import_file))); - final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_import_gpx_bottom_sheet_dialog, container); - - if (nightMode) { - ((TextView) mainView.findViewById(R.id.import_gpx_title)).setTextColor(ContextCompat.getColor(getActivity(), R.color.ctx_menu_info_text_dark)); - } - - ((ImageView) mainView.findViewById(R.id.import_as_favorites_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_fav_dark)); - ((ImageView) mainView.findViewById(R.id.import_as_gpx_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_polygom_dark)); - - int nameColor = ContextCompat.getColor(getContext(), nightMode ? R.color.osmand_orange : R.color.dashboard_blue); - int descrColor = ContextCompat.getColor(getContext(), nightMode ? R.color.dashboard_subheader_text_dark : R.color.dashboard_subheader_text_light); + int nameColor = getResolvedColor(nightMode ? R.color.osmand_orange : R.color.dashboard_blue); + int descrColor = getResolvedColor(nightMode ? R.color.dashboard_subheader_text_dark : R.color.dashboard_subheader_text_light); String descr = getString(R.string.import_gpx_file_description); SpannableStringBuilder text = new SpannableStringBuilder(fileName).append(" ").append(descr); text.setSpan(new ForegroundColorSpan(nameColor), 0, fileName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); text.setSpan(new ForegroundColorSpan(descrColor), fileName.length() + 1, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - ((TextView) mainView.findViewById(R.id.import_gpx_description)).setText(text); - mainView.findViewById(R.id.import_as_favorites_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - importHelper.importFavoritesImpl(gpxFile, fileName, false); - dismiss(); - } - }); - mainView.findViewById(R.id.import_as_gpx_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - importHelper.handleResult(gpxFile, fileName, save, useImportDir, false); - dismiss(); - } - }); + items.add(new DescriptionItem(text)); - mainView.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - dismiss(); - } - }); + BaseBottomSheetItem asFavoritesItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_fav_dark)) + .setTitle(getString(R.string.import_as_favorites)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + importHelper.importFavoritesImpl(gpxFile, fileName, false); + dismiss(); + } + }) + .create(); + items.add(asFavoritesItem); - setupHeightAndBackground(mainView, R.id.import_gpx_scroll_view); + items.add(new DividerHalfItem(getContext())); - return mainView; + BaseBottomSheetItem asGpxItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_polygom_dark)) + .setTitle(getString(R.string.import_as_gpx)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + importHelper.handleResult(gpxFile, fileName, save, useImportDir, false); + dismiss(); + } + }) + .create(); + items.add(asGpxItem); + + return null; + } + + @ColorInt + private int getResolvedColor(@ColorRes int colorId) { + return ContextCompat.getColor(getContext(), colorId); } } } From b127d8c992cd5c6f73fedfdfb5b0bdf532f8888b Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 28 Feb 2018 16:33:48 +0200 Subject: [PATCH 16/30] Rewrite UI in ItemMenuBottomSheetDialogFragment --- ...nt_notes_item_menu_bottom_sheet_dialog.xml | 220 ------------------ .../ItemMenuBottomSheetDialogFragment.java | 175 +++++++------- 2 files changed, 95 insertions(+), 300 deletions(-) delete mode 100644 OsmAnd/res/layout/fragment_notes_item_menu_bottom_sheet_dialog.xml diff --git a/OsmAnd/res/layout/fragment_notes_item_menu_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_notes_item_menu_bottom_sheet_dialog.xml deleted file mode 100644 index c7f722c621..0000000000 --- a/OsmAnd/res/layout/fragment_notes_item_menu_bottom_sheet_dialog.xml +++ /dev/null @@ -1,220 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/OsmAnd/src/net/osmand/plus/audionotes/ItemMenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/audionotes/ItemMenuBottomSheetDialogFragment.java index de18984f67..1f4d53f442 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/ItemMenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/ItemMenuBottomSheetDialogFragment.java @@ -1,19 +1,18 @@ package net.osmand.plus.audionotes; import android.os.Bundle; -import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; import net.osmand.plus.R; import net.osmand.plus.audionotes.AudioVideoNotesPlugin.Recording; import net.osmand.plus.base.MenuBottomSheetDialogFragment; - -import java.text.DecimalFormat; -import java.text.NumberFormat; +import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription; +import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; public class ItemMenuBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { @@ -33,83 +32,94 @@ public class ItemMenuBottomSheetDialogFragment extends MenuBottomSheetDialogFrag @Override public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; - - final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), - R.layout.fragment_notes_item_menu_bottom_sheet_dialog, null); - if (recording != null) { - NumberFormat f = new DecimalFormat("#0.00000"); - ((TextView) mainView.findViewById(R.id.title_text_view)) - .setText(recording.getName(getActivity(), true)); - ((TextView) mainView.findViewById(R.id.play_text_view)) - .setText(recording.isPhoto() ? R.string.watch : R.string.recording_context_menu_play); - ((TextView) mainView.findViewById(R.id.show_on_map_descr_text_view)) - .setText(f.format(recording.getLatitude()) + ", " + f.format(recording.getLongitude())); - ((ImageView) mainView.findViewById(R.id.play_icon)) - .setImageDrawable(getContentIcon(recording.isPhoto() ? R.drawable.ic_action_view : R.drawable.ic_play_dark)); + items.add(new TitleItem(recording.getName(getContext(), true))); + + BaseBottomSheetItem playItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(recording.isPhoto() ? R.drawable.ic_action_view : R.drawable.ic_play_dark)) + .setTitle(getString(recording.isPhoto() ? R.string.watch : R.string.recording_context_menu_play)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.playOnClick(recording); + } + dismiss(); + } + }) + .create(); + items.add(playItem); + + BaseBottomSheetItem shareItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_gshare_dark)) + .setTitle(getString(R.string.shared_string_share)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.shareOnClick(recording); + } + dismiss(); + } + }) + .create(); + items.add(shareItem); + + BaseBottomSheetItem showOnMapItem = new BottomSheetItemWithDescription.Builder() + .setDescription(getString(R.string.route_descr_lat_lon, recording.getLatitude(), recording.getLongitude())) + .setIcon(getContentIcon(R.drawable.ic_show_on_map)) + .setTitle(getString(R.string.shared_string_show_on_map)) + .setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.showOnMapOnClick(recording); + } + dismiss(); + } + }) + .create(); + items.add(showOnMapItem); + + items.add(new DividerHalfItem(getContext())); + + BaseBottomSheetItem renameItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_edit_dark)) + .setTitle(getString(R.string.shared_string_rename)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.renameOnClick(recording); + } + dismiss(); + } + }) + .create(); + items.add(renameItem); + + BaseBottomSheetItem deleteItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_delete_dark)) + .setTitle(getString(R.string.shared_string_delete)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.deleteOnClick(recording); + } + dismiss(); + } + }) + .create(); + items.add(deleteItem); } - ((ImageView) mainView.findViewById(R.id.share_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_gshare_dark)); - ((ImageView) mainView.findViewById(R.id.show_on_map_icon)).setImageDrawable(getContentIcon(R.drawable.ic_show_on_map)); - ((ImageView) mainView.findViewById(R.id.rename_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_edit_dark)); - ((ImageView) mainView.findViewById(R.id.delete_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_delete_dark)); - - mainView.findViewById(R.id.play_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (listener != null && recording != null) { - listener.playOnClick(recording); - } - dismiss(); - } - }); - mainView.findViewById(R.id.share_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (listener != null && recording != null) { - listener.shareOnClick(recording); - } - dismiss(); - } - }); - mainView.findViewById(R.id.show_on_map_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (listener != null && recording != null) { - listener.showOnMapOnClick(recording); - } - dismiss(); - } - }); - mainView.findViewById(R.id.rename_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (listener != null && recording != null) { - listener.renameOnClick(recording); - } - dismiss(); - } - }); - mainView.findViewById(R.id.delete_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (listener != null && recording != null) { - listener.deleteOnClick(recording); - } - dismiss(); - } - }); - mainView.findViewById(R.id.close_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - dismiss(); - } - }); - - setupHeightAndBackground(mainView, R.id.scroll_view); - - return mainView; + return null; } @Override @@ -120,6 +130,11 @@ public class ItemMenuBottomSheetDialogFragment extends MenuBottomSheetDialogFrag super.onDestroyView(); } + @Override + protected int getCloseRowTextId() { + return R.string.shared_string_close; + } + interface ItemMenuFragmentListener { void playOnClick(Recording recording); From 0ab22fe00d2edf5fc2bdcbb8b653f441c1107e87 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 28 Feb 2018 18:25:58 +0200 Subject: [PATCH 17/30] Rewrite UI in OrderByBottomSheetDialogFragment --- ...nt_marker_order_by_bottom_sheet_dialog.xml | 224 ------------------ .../OrderByBottomSheetDialogFragment.java | 149 +++++++----- 2 files changed, 92 insertions(+), 281 deletions(-) delete mode 100644 OsmAnd/res/layout/fragment_marker_order_by_bottom_sheet_dialog.xml diff --git a/OsmAnd/res/layout/fragment_marker_order_by_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_marker_order_by_bottom_sheet_dialog.xml deleted file mode 100644 index 617d985df1..0000000000 --- a/OsmAnd/res/layout/fragment_marker_order_by_bottom_sheet_dialog.xml +++ /dev/null @@ -1,224 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java index 45acbc3514..3487d52a85 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java @@ -2,18 +2,18 @@ package net.osmand.plus.mapmarkers; import android.graphics.drawable.Drawable; import android.os.Bundle; -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.ImageView; -import android.widget.TextView; import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper.MapMarkersSortByDef; import net.osmand.plus.R; import net.osmand.plus.base.MenuBottomSheetDialogFragment; +import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; public class OrderByBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { @@ -27,66 +27,101 @@ public class OrderByBottomSheetDialogFragment extends MenuBottomSheetDialogFragm @Override public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; - - final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), - R.layout.fragment_marker_order_by_bottom_sheet_dialog, container); - - if (nightMode) { - ((TextView) mainView.findViewById(R.id.order_by_title)).setTextColor( - ContextCompat.getColor(getContext(), R.color.ctx_menu_info_text_dark) - ); - } - Drawable distanceIcon = getContentIcon(R.drawable.ic_action_markers_dark); Drawable dateIcon = getContentIcon(R.drawable.ic_action_sort_by_date); - ((ImageView) mainView.findViewById(R.id.name_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_sort_by_name)); - ((ImageView) mainView.findViewById(R.id.distance_nearest_icon)).setImageDrawable(distanceIcon); - ((ImageView) mainView.findViewById(R.id.distance_farthest_icon)).setImageDrawable(distanceIcon); - ((ImageView) mainView.findViewById(R.id.date_added_asc_icon)).setImageDrawable(dateIcon); - ((ImageView) mainView.findViewById(R.id.date_added_desc_icon)).setImageDrawable(dateIcon); - ((TextView) mainView.findViewById(R.id.date_added_asc_text)).setText(getString(R.string.date_added) + " (" + getString(R.string.ascendingly) + ")"); - ((TextView) mainView.findViewById(R.id.date_added_desc_text)).setText(getString(R.string.date_added) + " (" + getString(R.string.descendingly) + ")"); + items.add(new TitleItem(getString(R.string.sort_by))); - View.OnClickListener onClickListener = new View.OnClickListener() { - @Override - public void onClick(View v) { - int sortByMode = -1; - switch (v.getId()) { - case R.id.name_row: - sortByMode = MapMarkersHelper.BY_NAME; - break; - case R.id.distance_nearest_row: - sortByMode = MapMarkersHelper.BY_DISTANCE_ASC; - break; - case R.id.distance_farthest_row: - sortByMode = MapMarkersHelper.BY_DISTANCE_DESC; - break; - case R.id.date_added_asc_row: - sortByMode = MapMarkersHelper.BY_DATE_ADDED_ASC; - break; - case R.id.date_added_desc_row: - sortByMode = MapMarkersHelper.BY_DATE_ADDED_DESC; - break; - } - if (sortByMode != -1 && listener != null) { - listener.onMapMarkersOrderByModeChanged(sortByMode); - } - dismiss(); - } - }; + BaseBottomSheetItem byNameItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_sort_by_name)) + .setTitle(getString(R.string.shared_string_name)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.onMapMarkersOrderByModeChanged(MapMarkersHelper.BY_NAME); + } + dismiss(); + } + }) + .create(); + items.add(byNameItem); - mainView.findViewById(R.id.name_row).setOnClickListener(onClickListener); - mainView.findViewById(R.id.distance_nearest_row).setOnClickListener(onClickListener); - mainView.findViewById(R.id.distance_farthest_row).setOnClickListener(onClickListener); - mainView.findViewById(R.id.date_added_asc_row).setOnClickListener(onClickListener); - mainView.findViewById(R.id.date_added_desc_row).setOnClickListener(onClickListener); - mainView.findViewById(R.id.close_row).setOnClickListener(onClickListener); + items.add(new DividerHalfItem(getContext())); - setupHeightAndBackground(mainView, R.id.marker_order_by_scroll_view); + BaseBottomSheetItem distNearestItem = new SimpleBottomSheetItem.Builder() + .setIcon(distanceIcon) + .setTitle(getString(R.string.distance_nearest)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.onMapMarkersOrderByModeChanged(MapMarkersHelper.BY_DISTANCE_ASC); + } + dismiss(); + } + }) + .create(); + items.add(distNearestItem); - return mainView; + BaseBottomSheetItem distFarthestItem = new SimpleBottomSheetItem.Builder() + .setIcon(distanceIcon) + .setTitle(getString(R.string.distance_farthest)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.onMapMarkersOrderByModeChanged(MapMarkersHelper.BY_DISTANCE_DESC); + } + dismiss(); + } + }) + .create(); + items.add(distFarthestItem); + + items.add(new DividerHalfItem(getContext())); + + BaseBottomSheetItem dateAscItem = new SimpleBottomSheetItem.Builder() + .setIcon(dateIcon) + .setTitle(getString(R.string.date_added) + " (" + getString(R.string.ascendingly) + ")") + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.onMapMarkersOrderByModeChanged(MapMarkersHelper.BY_DATE_ADDED_ASC); + } + dismiss(); + } + }) + .create(); + items.add(dateAscItem); + + BaseBottomSheetItem dateDescItem = new SimpleBottomSheetItem.Builder() + .setIcon(dateIcon) + .setTitle(getString(R.string.date_added) + " (" + getString(R.string.descendingly) + ")") + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.onMapMarkersOrderByModeChanged(MapMarkersHelper.BY_DATE_ADDED_DESC); + } + dismiss(); + } + }) + .create(); + items.add(dateDescItem); + + return null; + } + + @Override + protected int getCloseRowTextId() { + return R.string.shared_string_close; } interface OrderByFragmentListener { From 670cfcf62cf62b96ab2e07f204412f28e55e587f Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 28 Feb 2018 18:42:51 +0200 Subject: [PATCH 18/30] Rewrite UI in OsmEditOptionsBottomSheetDialogFragment --- ...t_osm_edit_options_bottom_sheet_dialog.xml | 210 ------------------ ...mEditOptionsBottomSheetDialogFragment.java | 163 ++++++++------ 2 files changed, 89 insertions(+), 284 deletions(-) delete mode 100644 OsmAnd/res/layout/fragment_osm_edit_options_bottom_sheet_dialog.xml diff --git a/OsmAnd/res/layout/fragment_osm_edit_options_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_osm_edit_options_bottom_sheet_dialog.xml deleted file mode 100644 index 61e0860e73..0000000000 --- a/OsmAnd/res/layout/fragment_osm_edit_options_bottom_sheet_dialog.xml +++ /dev/null @@ -1,210 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditOptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditOptionsBottomSheetDialogFragment.java index 20e492bf05..aacb47d3ff 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditOptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditOptionsBottomSheetDialogFragment.java @@ -1,19 +1,20 @@ package net.osmand.plus.osmedit; import android.os.Bundle; -import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; import net.osmand.plus.R; import net.osmand.plus.base.MenuBottomSheetDialogFragment; -import net.osmand.plus.widgets.TextViewEx; +import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; public class OsmEditOptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { - public final static String TAG = "OsmEditOptionsBottomSheetDialogFragment"; + public static final String TAG = "OsmEditOptionsBottomSheetDialogFragment"; public static final String OSM_POINT = "osm_point"; @@ -25,91 +26,105 @@ public class OsmEditOptionsBottomSheetDialogFragment extends MenuBottomSheetDial @Override public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; - final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_osm_edit_options_bottom_sheet_dialog, container); - Bundle args = getArguments(); if (args != null) { final OsmPoint osmPoint = (OsmPoint) args.getSerializable(OSM_POINT); - ((TextViewEx) mainView.findViewById(R.id.osm_edit_name)).setText(OsmEditingPlugin.getName(osmPoint) + ":"); + items.add(new TitleItem(OsmEditingPlugin.getName(osmPoint) + ":")); - ((ImageView) mainView.findViewById(R.id.upload_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_export)); - mainView.findViewById(R.id.upload_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (listener != null) { - listener.onUploadClick(osmPoint); - } - dismiss(); - } - }); + BaseBottomSheetItem uploadItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_export)) + .setTitle(getString(R.string.local_openstreetmap_upload)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.onUploadClick(osmPoint); + } + dismiss(); + } + }) + .create(); + items.add(uploadItem); - ((ImageView) mainView.findViewById(R.id.show_on_map_icon)).setImageDrawable(getContentIcon(R.drawable.ic_show_on_map)); - mainView.findViewById(R.id.show_on_map_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (listener != null) { - listener.onShowOnMapClick(osmPoint); - } - dismiss(); - } - }); + BaseBottomSheetItem showOnMapItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_show_on_map)) + .setTitle(getString(R.string.shared_string_show_on_map)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.onShowOnMapClick(osmPoint); + } + dismiss(); + } + }) + .create(); + items.add(showOnMapItem); + + items.add(new DividerHalfItem(getContext())); if (osmPoint instanceof OpenstreetmapPoint && osmPoint.getAction() != OsmPoint.Action.DELETE) { - mainView.findViewById(R.id.modify_osm_change_row).setVisibility(View.VISIBLE); - ((ImageView) mainView.findViewById(R.id.modify_osm_change_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_edit_dark)); - mainView.findViewById(R.id.modify_osm_change_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (listener != null) { - listener.onModifyOsmChangeClick(osmPoint); - } - dismiss(); - } - }); + BaseBottomSheetItem modifyOsmChangeItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_edit_dark)) + .setTitle(getString(R.string.poi_context_menu_modify_osm_change)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.onModifyOsmChangeClick(osmPoint); + } + dismiss(); + } + }) + .create(); + items.add(modifyOsmChangeItem); } if (osmPoint instanceof OsmNotesPoint) { - mainView.findViewById(R.id.modify_osm_note_row).setVisibility(View.VISIBLE); - ((ImageView) mainView.findViewById(R.id.modify_osm_note_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_edit_dark)); - mainView.findViewById(R.id.modify_osm_note_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (listener != null) { - listener.onModifyOsmNoteClick(osmPoint); + BaseBottomSheetItem modifyOsmNoteItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_edit_dark)) + .setTitle(getString(R.string.context_menu_item_modify_note)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.onModifyOsmNoteClick(osmPoint); + } + dismiss(); + } + }) + .create(); + items.add(modifyOsmNoteItem); + } + + BaseBottomSheetItem deleteItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_delete_dark)) + .setTitle(getString(R.string.shared_string_delete)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.onDeleteClick(osmPoint); + } + dismiss(); } - dismiss(); - } - }); - } - - ((ImageView) mainView.findViewById(R.id.delete_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_delete_dark)); - mainView.findViewById(R.id.delete_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (listener != null) { - listener.onDeleteClick(osmPoint); - } - dismiss(); - } - }); + }) + .create(); + items.add(deleteItem); } - if (nightMode) { - ((TextViewEx) mainView.findViewById(R.id.osm_edit_name)).setTextColor(getResources().getColor(R.color.ctx_menu_info_text_dark)); - } + return null; + } - mainView.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - dismiss(); - } - }); - - setupHeightAndBackground(mainView, R.id.osm_edit_options_scroll_view); - - return mainView; + @Override + protected int getCloseRowTextId() { + return R.string.shared_string_close; } public interface OsmEditOptionsFragmentListener { From 1f3d98480e1966cc82996f09d35f2322da15c6be Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 1 Mar 2018 11:25:54 +0200 Subject: [PATCH 19/30] Rewrite UI in SelectionMarkersGroupBottomSheetDialogFragment --- ..._add_markers_group_bottom_sheet_dialog.xml | 129 ------------------ ...MarkersGroupBottomSheetDialogFragment.java | 78 ++++++----- 2 files changed, 41 insertions(+), 166 deletions(-) delete mode 100644 OsmAnd/res/layout/fragment_marker_add_markers_group_bottom_sheet_dialog.xml diff --git a/OsmAnd/res/layout/fragment_marker_add_markers_group_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_marker_add_markers_group_bottom_sheet_dialog.xml deleted file mode 100644 index baacf61b55..0000000000 --- a/OsmAnd/res/layout/fragment_marker_add_markers_group_bottom_sheet_dialog.xml +++ /dev/null @@ -1,129 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/SelectionMarkersGroupBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/SelectionMarkersGroupBottomSheetDialogFragment.java index f661e14c0e..1a63dfc074 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/SelectionMarkersGroupBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/SelectionMarkersGroupBottomSheetDialogFragment.java @@ -1,15 +1,16 @@ package net.osmand.plus.mapmarkers; import android.os.Bundle; -import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; import net.osmand.plus.R; import net.osmand.plus.base.MenuBottomSheetDialogFragment; +import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.DescriptionItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; public class SelectionMarkersGroupBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { @@ -23,45 +24,48 @@ public class SelectionMarkersGroupBottomSheetDialogFragment extends MenuBottomSh @Override public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; - final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_add_markers_group_bottom_sheet_dialog, container); + items.add(new TitleItem(getString(R.string.add_group))); - if (nightMode) { - ((TextView) mainView.findViewById(R.id.add_group_title)).setTextColor(getResources().getColor(R.color.ctx_menu_info_text_dark)); - } + items.add(new DescriptionItem(getString(R.string.add_group_descr))); - ((ImageView) mainView.findViewById(R.id.favourites_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_fav_dark)); - ((ImageView) mainView.findViewById(R.id.waypoints_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_polygom_dark)); + BaseBottomSheetItem favoritesItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_fav_dark)) + .setTitle(getString(R.string.favourites_group)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.favouritesOnClick(); + } + dismiss(); + } + }) + .create(); + items.add(favoritesItem); - mainView.findViewById(R.id.favourites_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (listener != null) { - listener.favouritesOnClick(); - } - dismiss(); - } - }); - mainView.findViewById(R.id.waypoints_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (listener != null) { - listener.waypointsOnClick(); - } - dismiss(); - } - }); + BaseBottomSheetItem waypointsItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_polygom_dark)) + .setTitle(getString(R.string.track_waypoints)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.waypointsOnClick(); + } + dismiss(); + } + }) + .create(); + items.add(waypointsItem); - mainView.findViewById(R.id.close_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - dismiss(); - } - }); + return null; + } - setupHeightAndBackground(mainView, R.id.add_markers_group_scroll_view); - - return mainView; + @Override + protected int getCloseRowTextId() { + return R.string.shared_string_close; } interface AddMarkersGroupFragmentListener { From ebeb0710fc2e25f4a30ec969e2649610c5bf322d Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 1 Mar 2018 11:33:20 +0200 Subject: [PATCH 20/30] Rewrite UI in SortByMenuBottomSheetDialogFragment --- ...ragment_notes_sort_bottom_sheet_dialog.xml | 111 ------------------ .../SortByMenuBottomSheetDialogFragment.java | 59 +++++----- 2 files changed, 29 insertions(+), 141 deletions(-) delete mode 100644 OsmAnd/res/layout/fragment_notes_sort_bottom_sheet_dialog.xml diff --git a/OsmAnd/res/layout/fragment_notes_sort_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_notes_sort_bottom_sheet_dialog.xml deleted file mode 100644 index a307700dd6..0000000000 --- a/OsmAnd/res/layout/fragment_notes_sort_bottom_sheet_dialog.xml +++ /dev/null @@ -1,111 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/OsmAnd/src/net/osmand/plus/audionotes/SortByMenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/audionotes/SortByMenuBottomSheetDialogFragment.java index a8e240f26b..8f946975ea 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/SortByMenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/SortByMenuBottomSheetDialogFragment.java @@ -1,17 +1,17 @@ package net.osmand.plus.audionotes; import android.os.Bundle; -import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; -import android.view.View.OnClickListener; import android.view.ViewGroup; -import android.widget.ImageView; import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.NotesSortByMode; import net.osmand.plus.R; import net.osmand.plus.base.MenuBottomSheetDialogFragment; +import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; public class SortByMenuBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { @@ -25,36 +25,35 @@ public class SortByMenuBottomSheetDialogFragment extends MenuBottomSheetDialogFr @Override public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; + items.add(new TitleItem(getString(R.string.shared_string_sort))); - final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), - R.layout.fragment_notes_sort_bottom_sheet_dialog, null); + BaseBottomSheetItem byTypeItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_groped_by_type)) + .setTitle(getString(R.string.by_type)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + selectSortByMode(NotesSortByMode.BY_TYPE); + } + }) + .create(); + items.add(byTypeItem); - ((ImageView) mainView.findViewById(R.id.by_type_icon)).setImageDrawable(getContentIcon(R.drawable.ic_groped_by_type)); - ((ImageView) mainView.findViewById(R.id.by_date_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_sort_by_date)); + BaseBottomSheetItem byDateItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_sort_by_date)) + .setTitle(getString(R.string.by_date)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + selectSortByMode(NotesSortByMode.BY_DATE); + } + }) + .create(); + items.add(byDateItem); - mainView.findViewById(R.id.by_type_row).setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - selectSortByMode(NotesSortByMode.BY_TYPE); - } - }); - mainView.findViewById(R.id.by_date_row).setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - selectSortByMode(NotesSortByMode.BY_DATE); - } - }); - mainView.findViewById(R.id.close_row).setOnClickListener(new OnClickListener() { - @Override - public void onClick(View view) { - dismiss(); - } - }); - - setupHeightAndBackground(mainView, R.id.scroll_view); - - return mainView; + return null; } private void selectSortByMode(NotesSortByMode mode) { From 60541c21658480c2e7458ad5ec90162164c92539 Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 1 Mar 2018 13:58:44 +0200 Subject: [PATCH 21/30] Rewrite UI in MenuBottomSheetDialogFragment; fix small issues; add new bottom sheet item --- ..._sheet_item_with_descr_and_switch_56dp.xml | 60 ++++ OsmAnd/res/layout/bottom_sheet_menu_base.xml | 4 +- .../fragment_options_bottom_sheet_dialog.xml | 269 ------------------ .../base/MenuBottomSheetDialogFragment.java | 7 +- .../BottomSheetItemWithCompoundButton.java | 61 ++++ .../BottomSheetItemWithDescription.java | 4 +- .../SimpleBottomSheetItem.java | 4 +- .../MeasurementToolFragment.java | 6 +- .../OptionsBottomSheetDialogFragment.java | 205 ++++++------- 9 files changed, 242 insertions(+), 378 deletions(-) create mode 100644 OsmAnd/res/layout/bottom_sheet_item_with_descr_and_switch_56dp.xml delete mode 100644 OsmAnd/res/layout/fragment_options_bottom_sheet_dialog.xml create mode 100644 OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithCompoundButton.java diff --git a/OsmAnd/res/layout/bottom_sheet_item_with_descr_and_switch_56dp.xml b/OsmAnd/res/layout/bottom_sheet_item_with_descr_and_switch_56dp.xml new file mode 100644 index 0000000000..b166524d6e --- /dev/null +++ b/OsmAnd/res/layout/bottom_sheet_item_with_descr_and_switch_56dp.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + diff --git a/OsmAnd/res/layout/bottom_sheet_menu_base.xml b/OsmAnd/res/layout/bottom_sheet_menu_base.xml index 0cd6c6fc04..8a575be9ee 100644 --- a/OsmAnd/res/layout/bottom_sheet_menu_base.xml +++ b/OsmAnd/res/layout/bottom_sheet_menu_base.xml @@ -38,11 +38,11 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" - android:text="@string/shared_string_cancel" android:textAllCaps="true" android:textColor="?attr/color_dialog_buttons" android:textSize="@dimen/default_desc_text_size" - android:textStyle="bold"/> + android:textStyle="bold" + tools:text="@string/shared_string_cancel"/> diff --git a/OsmAnd/res/layout/fragment_options_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_options_bottom_sheet_dialog.xml deleted file mode 100644 index dabbd5dcea..0000000000 --- a/OsmAnd/res/layout/fragment_options_bottom_sheet_dialog.xml +++ /dev/null @@ -1,269 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java index b0a9ebfe6b..044e3d47f1 100644 --- a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java @@ -81,10 +81,7 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra dismiss(); } }); - int closeRowTextId = getCloseRowTextId(); - if (closeRowTextId != -1) { - ((TextView) mainView.findViewById(R.id.close_row_text)).setText(closeRowTextId); - } + ((TextView) mainView.findViewById(R.id.close_row_text)).setText(getCloseRowTextId()); setupHeightAndBackground(mainView, R.id.scroll_view); @@ -175,7 +172,7 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra @StringRes protected int getCloseRowTextId() { - return -1; + return R.string.shared_string_cancel; } @DrawableRes diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithCompoundButton.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithCompoundButton.java new file mode 100644 index 0000000000..8fccb21bda --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithCompoundButton.java @@ -0,0 +1,61 @@ +package net.osmand.plus.base.bottomsheetmenu; + +import android.graphics.drawable.Drawable; +import android.support.annotation.ColorRes; +import android.support.annotation.LayoutRes; +import android.view.View; +import android.view.ViewGroup; +import android.widget.CompoundButton; + +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; + +public class BottomSheetItemWithCompoundButton extends BottomSheetItemWithDescription { + + private boolean checked; + + public BottomSheetItemWithCompoundButton(View customView, + @LayoutRes int layoutId, + boolean disabled, + View.OnClickListener onClickListener, + int position, + Drawable icon, + String title, + @ColorRes int titleColorId, + CharSequence description, + @ColorRes int descriptionColorId, + boolean checked) { + super(customView, layoutId, disabled, onClickListener, position, icon, title, titleColorId, description, descriptionColorId); + this.checked = checked; + } + + @Override + public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) { + super.inflate(app, container, nightMode); + ((CompoundButton) view.findViewById(R.id.compound_button)).setChecked(checked); + } + + public static class Builder extends BottomSheetItemWithDescription.Builder { + + protected boolean checked; + + public Builder setChecked(boolean checked) { + this.checked = checked; + return this; + } + + public BottomSheetItemWithCompoundButton create() { + return new BottomSheetItemWithCompoundButton(customView, + layoutId, + disabled, + onClickListener, + position, + icon, + title, + titleColorId, + description, + descriptionColorId, + checked); + } + } +} diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java index c6294d4384..4617ff192c 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java @@ -19,7 +19,7 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem { public BottomSheetItemWithDescription(View customView, @LayoutRes int layoutId, - boolean clickable, + boolean disabled, View.OnClickListener onClickListener, int position, Drawable icon, @@ -27,7 +27,7 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem { @ColorRes int titleColorId, CharSequence description, @ColorRes int descriptionColorId) { - super(customView, layoutId, clickable, onClickListener, position, icon, title, titleColorId); + super(customView, layoutId, disabled, onClickListener, position, icon, title, titleColorId); this.description = description; this.descriptionColorId = descriptionColorId; } diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java index a3e6eb8e37..d0fe3104ea 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java @@ -21,13 +21,13 @@ public class SimpleBottomSheetItem extends BaseBottomSheetItem { public SimpleBottomSheetItem(View customView, @LayoutRes int layoutId, - boolean clickable, + boolean disabled, View.OnClickListener onClickListener, int position, Drawable icon, String title, @ColorRes int titleColorId) { - super(customView, layoutId, clickable, onClickListener, position); + super(customView, layoutId, disabled, onClickListener, position); this.icon = icon; this.title = title; this.titleColorId = titleColorId; diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index d44cba2a34..0de6179047 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -272,11 +272,13 @@ public class MeasurementToolFragment extends BaseOsmAndFragment { mainView.findViewById(R.id.options_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { + Bundle args = new Bundle(); + args.putBoolean(OptionsBottomSheetDialogFragment.SNAP_TO_ROAD_ENABLED_KEY, editingCtx.isInSnapToRoadMode()); + args.putBoolean(OptionsBottomSheetDialogFragment.ADD_LINE_MODE_KEY, newGpxData != null); OptionsBottomSheetDialogFragment fragment = new OptionsBottomSheetDialogFragment(); + fragment.setArguments(args); fragment.setUsedOnMap(true); - fragment.setSnapToRoadEnabled(editingCtx.isInSnapToRoadMode()); fragment.setListener(createOptionsFragmentListener()); - fragment.setAddLineMode(newGpxData != null); fragment.show(mapActivity.getSupportFragmentManager(), OptionsBottomSheetDialogFragment.TAG); } }); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java index 6666fa933b..03f53b6d78 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java @@ -1,122 +1,135 @@ package net.osmand.plus.measurementtool; import android.os.Bundle; -import android.support.v7.widget.SwitchCompat; -import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; import net.osmand.plus.R; import net.osmand.plus.base.MenuBottomSheetDialogFragment; -import net.osmand.plus.widgets.TextViewEx; +import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton; +import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; public class OptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { - public final static String TAG = "OptionsBottomSheetDialogFragment"; + public static final String TAG = "OptionsBottomSheetDialogFragment"; + + public static final String SNAP_TO_ROAD_ENABLED_KEY = "snap_to_road_enabled"; + public static final String ADD_LINE_MODE_KEY = "add_line_mode"; private OptionsFragmentListener listener; - private boolean addLineMode; - private boolean snapToRoadEnabled; public void setListener(OptionsFragmentListener listener) { this.listener = listener; } - public void setAddLineMode(boolean addLineMode) { - this.addLineMode = addLineMode; - } + @Override + public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + Bundle args = getArguments(); + boolean snapToRoadEnabled = args.getBoolean(SNAP_TO_ROAD_ENABLED_KEY); + boolean addLineMode = args.getBoolean(ADD_LINE_MODE_KEY); - public void setSnapToRoadEnabled(boolean snapToRoadEnabled) { - this.snapToRoadEnabled = snapToRoadEnabled; + items.add(new TitleItem(getString(R.string.shared_string_options))); + + BaseBottomSheetItem snapToRoadItem = new BottomSheetItemWithCompoundButton.Builder() + .setChecked(snapToRoadEnabled) + .setDescription(getString(snapToRoadEnabled ? R.string.shared_string_enabled : R.string.shared_string_disabled)) + .setIcon(snapToRoadEnabled + ? getActiveIcon(R.drawable.ic_action_snap_to_road) + : getContentIcon(R.drawable.ic_action_snap_to_road)) + .setTitle(getString(R.string.snap_to_road)) + .setLayoutId(R.layout.bottom_sheet_item_with_descr_and_switch_56dp) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.snapToRoadOnCLick(); + } + dismiss(); + } + }) + .create(); + items.add(snapToRoadItem); + + items.add(new DividerHalfItem(getContext())); + + if (addLineMode) { + BaseBottomSheetItem saveAsNewSegmentItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_polygom_dark)) + .setTitle(getString(R.string.shared_string_save)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.addToGpxOnClick(); + } + dismiss(); + } + }) + .create(); + items.add(saveAsNewSegmentItem); + } else { + BaseBottomSheetItem saveAsNewTrackItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_polygom_dark)) + .setTitle(getString(R.string.shared_string_save_as_gpx)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.saveAsNewTrackOnClick(); + } + dismiss(); + } + }) + .create(); + items.add(saveAsNewTrackItem); + + BaseBottomSheetItem addToTrackItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_split_interval)) + .setTitle(getString(R.string.add_segment_to_the_track)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.addToTheTrackOnClick(); + } + dismiss(); + } + }) + .create(); + items.add(addToTrackItem); + } + + items.add(new DividerHalfItem(getContext())); + + BaseBottomSheetItem clearAllItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_reset_to_default_dark)) + .setTitle(getString(R.string.shared_string_clear_all)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.clearAllOnClick(); + } + dismiss(); + } + }) + .create(); + items.add(clearAllItem); + + return null; } @Override - public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; - - final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_options_bottom_sheet_dialog, null); - - if (nightMode) { - ((TextViewEx) mainView.findViewById(R.id.options_title)).setTextColor(getResources().getColor(R.color.ctx_menu_info_text_dark)); - } - if (snapToRoadEnabled) { - mainView.findViewById(R.id.snap_to_road_enabled_text_view).setVisibility(View.VISIBLE); - ((SwitchCompat) mainView.findViewById(R.id.snap_to_road_switch)).setChecked(true); - } - ((ImageView) mainView.findViewById(R.id.snap_to_road_icon)).setImageDrawable(snapToRoadEnabled - ? getActiveIcon(R.drawable.ic_action_snap_to_road) - : getContentIcon(R.drawable.ic_action_snap_to_road)); - ((ImageView) mainView.findViewById(R.id.clear_all_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_reset_to_default_dark)); - if (!addLineMode) { - ((ImageView) mainView.findViewById(R.id.save_as_new_track_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_polygom_dark)); - ((ImageView) mainView.findViewById(R.id.add_to_the_track_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_split_interval)); - } else { - mainView.findViewById(R.id.save_as_new_track_row).setVisibility(View.GONE); - mainView.findViewById(R.id.add_to_the_track_row).setVisibility(View.GONE); - mainView.findViewById(R.id.save_as_new_segment_row).setVisibility(View.VISIBLE); - ((ImageView) mainView.findViewById(R.id.save_as_new_segment_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_polygom_dark)); - } - - mainView.findViewById(R.id.snap_to_road_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (listener != null) { - listener.snapToRoadOnCLick(); - } - dismiss(); - } - }); - mainView.findViewById(R.id.clear_all_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (listener != null) { - listener.clearAllOnClick(); - } - dismiss(); - } - }); - if (!addLineMode) { - mainView.findViewById(R.id.save_as_new_track_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (listener != null) { - listener.saveAsNewTrackOnClick(); - } - dismiss(); - } - }); - mainView.findViewById(R.id.add_to_the_track_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (listener != null) { - listener.addToTheTrackOnClick(); - } - dismiss(); - } - }); - } else { - mainView.findViewById(R.id.save_as_new_segment_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (listener != null) { - listener.addToGpxOnClick(); - } - dismiss(); - } - }); - } - mainView.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - dismiss(); - } - }); - - setupHeightAndBackground(mainView, R.id.measure_options_scroll_view); - - return mainView; + protected int getCloseRowTextId() { + return R.string.shared_string_close; } interface OptionsFragmentListener { From a67a2e1c286cf1bdbe69021662d6326e3be124da Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 1 Mar 2018 14:38:09 +0200 Subject: [PATCH 22/30] Rewrite UI in PlanRouteOptionsBottomSheetDialogFragment --- ...plan_route_options_bottom_sheet_dialog.xml | 258 ------------------ .../plus/mapmarkers/PlanRouteFragment.java | 9 +- ...RouteOptionsBottomSheetDialogFragment.java | 196 +++++++------ 3 files changed, 111 insertions(+), 352 deletions(-) delete mode 100644 OsmAnd/res/layout/fragment_plan_route_options_bottom_sheet_dialog.xml diff --git a/OsmAnd/res/layout/fragment_plan_route_options_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_plan_route_options_bottom_sheet_dialog.xml deleted file mode 100644 index 1c9345234f..0000000000 --- a/OsmAnd/res/layout/fragment_plan_route_options_bottom_sheet_dialog.xml +++ /dev/null @@ -1,258 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java index fab4fcc504..a14e2e306a 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java @@ -150,9 +150,7 @@ public class PlanRouteFragment extends BaseOsmAndFragment implements OsmAndLocat } Fragment optionsFragment = fragmentManager.findFragmentByTag(PlanRouteOptionsBottomSheetDialogFragment.TAG); if (optionsFragment != null) { - PlanRouteOptionsBottomSheetDialogFragment fragment = (PlanRouteOptionsBottomSheetDialogFragment) optionsFragment; - fragment.setSelectAll(!(selectedCount == markersHelper.getMapMarkers().size() && markersHelper.isStartFromMyLocation())); - fragment.setListener(createOptionsFragmentListener()); + ((PlanRouteOptionsBottomSheetDialogFragment) optionsFragment).setListener(createOptionsFragmentListener()); } toolbarHeight = mapActivity.getResources().getDimensionPixelSize(R.dimen.dashboard_map_toolbar); @@ -722,9 +720,12 @@ public class PlanRouteFragment extends BaseOsmAndFragment implements OsmAndLocat private void optionsOnClick() { MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { + Bundle args = new Bundle(); + args.putBoolean(PlanRouteOptionsBottomSheetDialogFragment.SELECT_ALL_KEY, + !(selectedCount == markersHelper.getMapMarkers().size() && markersHelper.isStartFromMyLocation())); PlanRouteOptionsBottomSheetDialogFragment fragment = new PlanRouteOptionsBottomSheetDialogFragment(); + fragment.setArguments(args); fragment.setUsedOnMap(true); - fragment.setSelectAll(!(selectedCount == markersHelper.getMapMarkers().size() && markersHelper.isStartFromMyLocation())); fragment.setListener(createOptionsFragmentListener()); fragment.show(mapActivity.getSupportFragmentManager(), PlanRouteOptionsBottomSheetDialogFragment.TAG); } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java index 53be218d7c..46f647a985 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java @@ -1,116 +1,132 @@ package net.osmand.plus.mapmarkers; import android.os.Bundle; -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.CompoundButton; -import android.widget.ImageView; -import android.widget.TextView; import net.osmand.plus.R; import net.osmand.plus.base.MenuBottomSheetDialogFragment; +import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton; +import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.DescriptionItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; import net.osmand.plus.helpers.AndroidUiHelper; public class PlanRouteOptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { - public final static String TAG = "PlanRouteOptionsBottomSheetDialogFragment"; + public static final String TAG = "PlanRouteOptionsBottomSheetDialogFragment"; + + public static final String SELECT_ALL_KEY = "select_all"; private PlanRouteOptionsFragmentListener listener; - private boolean selectAll; public void setListener(PlanRouteOptionsFragmentListener listener) { this.listener = listener; } - public void setSelectAll(boolean selectAll) { - this.selectAll = selectAll; + @Override + public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + items.add(new TitleItem(getString(R.string.shared_string_options))); + + if (!AndroidUiHelper.isOrientationPortrait(getActivity())) { + boolean selectAll = getArguments().getBoolean(SELECT_ALL_KEY); + + BaseBottomSheetItem selectItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(selectAll ? R.drawable.ic_action_select_all : R.drawable.ic_action_deselect_all)) + .setTitle(getString(selectAll ? R.string.shared_string_select_all : R.string.shared_string_deselect_all)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.selectOnClick(); + } + dismiss(); + } + }) + .create(); + items.add(selectItem); + } + + BaseBottomSheetItem navigateItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_gdirections_dark)) + .setTitle(getString(R.string.get_directions)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.navigateOnClick(); + } + dismiss(); + } + }) + .create(); + items.add(navigateItem); + + BaseBottomSheetItem roundTripItem = new BottomSheetItemWithCompoundButton.Builder() + .setChecked(getMyApplication().getSettings().ROUTE_MAP_MARKERS_ROUND_TRIP.get()) + .setDescription(getString(R.string.make_round_trip_descr)) + .setIcon(getContentIcon(R.drawable.ic_action_trip_round)) + .setTitle(getString(R.string.make_round_trip)) + .setLayoutId(R.layout.bottom_sheet_item_with_descr_and_switch_56dp) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.makeRoundTripOnClick(); + } + dismiss(); + } + }) + .create(); + items.add(roundTripItem); + + items.add(new DividerItem(getContext())); + + items.add(new DescriptionItem(getString(R.string.sort_by))); + + BaseBottomSheetItem doorToDoorItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_sort_door_to_door)) + .setTitle(getString(R.string.intermediate_items_sort_by_distance)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.doorToDoorOnClick(); + } + dismiss(); + } + }) + .create(); + items.add(doorToDoorItem); + + BaseBottomSheetItem reversItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_sort_reverse_order)) + .setTitle(getString(R.string.shared_string_reverse_order)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.reverseOrderOnClick(); + } + dismiss(); + } + }) + .create(); + items.add(reversItem); + + return null; } @Override - public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - boolean portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); - final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; - - final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_plan_route_options_bottom_sheet_dialog, container); - - if (nightMode) { - ((TextView) mainView.findViewById(R.id.title)).setTextColor(ContextCompat.getColor(getActivity(), R.color.ctx_menu_info_text_dark)); - } - - ((ImageView) mainView.findViewById(R.id.navigate_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_gdirections_dark)); - ((ImageView) mainView.findViewById(R.id.make_round_trip_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_trip_round)); - ((ImageView) mainView.findViewById(R.id.door_to_door_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_sort_door_to_door)); - ((ImageView) mainView.findViewById(R.id.reverse_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_sort_reverse_order)); - - ((CompoundButton) mainView.findViewById(R.id.make_round_trip_switch)).setChecked(getMyApplication().getSettings().ROUTE_MAP_MARKERS_ROUND_TRIP.get()); - - if (!portrait) { - ((ImageView) mainView.findViewById(R.id.select_icon)) - .setImageDrawable(getContentIcon(selectAll ? R.drawable.ic_action_select_all : R.drawable.ic_action_deselect_all)); - - ((TextView) mainView.findViewById(R.id.select_title)) - .setText(getString(selectAll ? R.string.shared_string_select_all : R.string.shared_string_deselect_all)); - - View selectRow = mainView.findViewById(R.id.select_row); - selectRow.setVisibility(View.VISIBLE); - selectRow.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - listener.selectOnClick(); - dismiss(); - } - }); - } - mainView.findViewById(R.id.navigate_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (listener != null) { - listener.navigateOnClick(); - dismiss(); - } - } - }); - mainView.findViewById(R.id.make_round_trip_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (listener != null) { - listener.makeRoundTripOnClick(); - dismiss(); - } - } - }); - mainView.findViewById(R.id.door_to_door_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (listener != null) { - listener.doorToDoorOnClick(); - dismiss(); - } - } - }); - mainView.findViewById(R.id.reverse_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (listener != null) { - listener.reverseOrderOnClick(); - dismiss(); - } - } - }); - - mainView.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - dismiss(); - } - }); - - setupHeightAndBackground(mainView, R.id.sort_by_scroll_view); - - return mainView; + protected int getCloseRowTextId() { + return R.string.shared_string_close; } interface PlanRouteOptionsFragmentListener { From 2e4b15a3c43ff9b633207824c6b90ad347eb2735 Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 1 Mar 2018 15:29:02 +0200 Subject: [PATCH 23/30] Add some new items; add small refactoring --- OsmAnd/res/layout/bottom_sheet_item_subtitle.xml | 16 ++++++++++++++++ .../layout/bottom_sheet_item_with_radio_btn.xml | 6 +++--- .../simpleitems/SubtitleItem.java | 12 ++++++++++++ ...CoordinateInputBottomSheetDialogFragment.java | 6 +++--- ...lanRouteOptionsBottomSheetDialogFragment.java | 4 ++-- 5 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 OsmAnd/res/layout/bottom_sheet_item_subtitle.xml create mode 100644 OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/SubtitleItem.java diff --git a/OsmAnd/res/layout/bottom_sheet_item_subtitle.xml b/OsmAnd/res/layout/bottom_sheet_item_subtitle.xml new file mode 100644 index 0000000000..e0c850a458 --- /dev/null +++ b/OsmAnd/res/layout/bottom_sheet_item_subtitle.xml @@ -0,0 +1,16 @@ + + diff --git a/OsmAnd/res/layout/bottom_sheet_item_with_radio_btn.xml b/OsmAnd/res/layout/bottom_sheet_item_with_radio_btn.xml index 5e4a692f66..28aaab9914 100644 --- a/OsmAnd/res/layout/bottom_sheet_item_with_radio_btn.xml +++ b/OsmAnd/res/layout/bottom_sheet_item_with_radio_btn.xml @@ -13,7 +13,7 @@ android:paddingStart="@dimen/content_padding"> Date: Thu, 1 Mar 2018 19:11:45 +0200 Subject: [PATCH 24/30] Create and use SubtitleDividerItem --- .../simpleitems/SubtitleDividerItem.java | 24 +++++++++++++++++++ ...RouteOptionsBottomSheetDialogFragment.java | 4 ++-- 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/SubtitleDividerItem.java diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/SubtitleDividerItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/SubtitleDividerItem.java new file mode 100644 index 0000000000..ab94b87737 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/SubtitleDividerItem.java @@ -0,0 +1,24 @@ +package net.osmand.plus.base.bottomsheetmenu.simpleitems; + +import android.content.Context; +import android.support.annotation.ColorRes; + +public class SubtitleDividerItem extends DividerItem { + + public SubtitleDividerItem(Context context) { + super(context); + } + + public SubtitleDividerItem(Context context, @ColorRes int colorId) { + super(context, colorId); + } + + public SubtitleDividerItem(Context context, @ColorRes int colorId, int position) { + super(context, colorId, position); + } + + @Override + protected int getBottomMargin(Context context) { + return 0; + } +} diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java index e572378ea0..c228e895b9 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java @@ -10,7 +10,7 @@ import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; -import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.SubtitleDividerItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.SubtitleItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; import net.osmand.plus.helpers.AndroidUiHelper; @@ -85,7 +85,7 @@ public class PlanRouteOptionsBottomSheetDialogFragment extends MenuBottomSheetDi .create(); items.add(roundTripItem); - items.add(new DividerItem(getContext())); + items.add(new SubtitleDividerItem(getContext())); items.add(new SubtitleItem(getString(R.string.sort_by))); From 65d60d6a7ca257312ab1f6b6a4e84995fc08991f Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 1 Mar 2018 19:41:24 +0200 Subject: [PATCH 25/30] Add field "tag" to BaseBottomSheetItem --- .../base/bottomsheetmenu/BaseBottomSheetItem.java | 14 +++++++++++++- .../BottomSheetItemWithCompoundButton.java | 14 +++++++++++++- .../BottomSheetItemWithDescription.java | 4 +++- .../bottomsheetmenu/SimpleBottomSheetItem.java | 4 +++- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java index a35d59840b..2eff160b71 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BaseBottomSheetItem.java @@ -16,17 +16,20 @@ public class BaseBottomSheetItem { protected View view; @LayoutRes protected int layoutId = INVALID_ID; + private Object tag; private boolean disabled; private View.OnClickListener onClickListener; protected int position = INVALID_POSITION; public BaseBottomSheetItem(View view, @LayoutRes int layoutId, + Object tag, boolean disabled, View.OnClickListener onClickListener, int position) { this.view = view; this.layoutId = layoutId; + this.tag = tag; this.disabled = disabled; this.onClickListener = onClickListener; this.position = position; @@ -38,6 +41,9 @@ public class BaseBottomSheetItem { public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) { View view = getView(app, nightMode); + if (tag != null) { + view.setTag(tag); + } if (disabled) { view.setEnabled(false); view.setAlpha(.5f); @@ -67,6 +73,7 @@ public class BaseBottomSheetItem { protected View customView; @LayoutRes protected int layoutId = INVALID_ID; + protected Object tag; protected boolean disabled; protected View.OnClickListener onClickListener; protected int position = INVALID_POSITION; @@ -81,6 +88,11 @@ public class BaseBottomSheetItem { return this; } + public Builder setTag(Object tag) { + this.tag = tag; + return this; + } + public Builder setDisabled(boolean disabled) { this.disabled = disabled; return this; @@ -97,7 +109,7 @@ public class BaseBottomSheetItem { } public BaseBottomSheetItem create() { - return new BaseBottomSheetItem(customView, layoutId, disabled, onClickListener, position); + return new BaseBottomSheetItem(customView, layoutId, tag, disabled, onClickListener, position); } } } diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithCompoundButton.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithCompoundButton.java index 8fccb21bda..68ba49f35e 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithCompoundButton.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithCompoundButton.java @@ -16,6 +16,7 @@ public class BottomSheetItemWithCompoundButton extends BottomSheetItemWithDescri public BottomSheetItemWithCompoundButton(View customView, @LayoutRes int layoutId, + Object tag, boolean disabled, View.OnClickListener onClickListener, int position, @@ -25,7 +26,17 @@ public class BottomSheetItemWithCompoundButton extends BottomSheetItemWithDescri CharSequence description, @ColorRes int descriptionColorId, boolean checked) { - super(customView, layoutId, disabled, onClickListener, position, icon, title, titleColorId, description, descriptionColorId); + super(customView, + layoutId, + tag, + disabled, + onClickListener, + position, + icon, + title, + titleColorId, + description, + descriptionColorId); this.checked = checked; } @@ -47,6 +58,7 @@ public class BottomSheetItemWithCompoundButton extends BottomSheetItemWithDescri public BottomSheetItemWithCompoundButton create() { return new BottomSheetItemWithCompoundButton(customView, layoutId, + tag, disabled, onClickListener, position, diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java index 4617ff192c..7b5896c3f7 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescription.java @@ -19,6 +19,7 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem { public BottomSheetItemWithDescription(View customView, @LayoutRes int layoutId, + Object tag, boolean disabled, View.OnClickListener onClickListener, int position, @@ -27,7 +28,7 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem { @ColorRes int titleColorId, CharSequence description, @ColorRes int descriptionColorId) { - super(customView, layoutId, disabled, onClickListener, position, icon, title, titleColorId); + super(customView, layoutId, tag, disabled, onClickListener, position, icon, title, titleColorId); this.description = description; this.descriptionColorId = descriptionColorId; } @@ -67,6 +68,7 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem { public BottomSheetItemWithDescription create() { return new BottomSheetItemWithDescription(customView, layoutId, + tag, disabled, onClickListener, position, diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java index d0fe3104ea..53b861fea6 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/SimpleBottomSheetItem.java @@ -21,13 +21,14 @@ public class SimpleBottomSheetItem extends BaseBottomSheetItem { public SimpleBottomSheetItem(View customView, @LayoutRes int layoutId, + Object tag, boolean disabled, View.OnClickListener onClickListener, int position, Drawable icon, String title, @ColorRes int titleColorId) { - super(customView, layoutId, disabled, onClickListener, position); + super(customView, layoutId, tag, disabled, onClickListener, position); this.icon = icon; this.title = title; this.titleColorId = titleColorId; @@ -77,6 +78,7 @@ public class SimpleBottomSheetItem extends BaseBottomSheetItem { public SimpleBottomSheetItem create() { return new SimpleBottomSheetItem(customView, layoutId, + tag, disabled, onClickListener, position, From 1eb418d180fc37aec35c3241affd8a4371f81649 Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 1 Mar 2018 20:17:42 +0200 Subject: [PATCH 26/30] Rewrite UI in CoordinateInputBottomSheetDialogFragment --- .../layout/bottom_sheet_item_with_switch.xml | 43 +++++ ...nate_input_options_bottom_sheet_dialog.xml | 168 ------------------ .../BottomSheetItemWithCompoundButton.java | 20 ++- ...rdinateInputBottomSheetDialogFragment.java | 150 ++++++++-------- 4 files changed, 135 insertions(+), 246 deletions(-) create mode 100644 OsmAnd/res/layout/bottom_sheet_item_with_switch.xml delete mode 100644 OsmAnd/res/layout/fragment_marker_coordinate_input_options_bottom_sheet_dialog.xml diff --git a/OsmAnd/res/layout/bottom_sheet_item_with_switch.xml b/OsmAnd/res/layout/bottom_sheet_item_with_switch.xml new file mode 100644 index 0000000000..365bc4a467 --- /dev/null +++ b/OsmAnd/res/layout/bottom_sheet_item_with_switch.xml @@ -0,0 +1,43 @@ + + + + + + + + + + diff --git a/OsmAnd/res/layout/fragment_marker_coordinate_input_options_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_marker_coordinate_input_options_bottom_sheet_dialog.xml deleted file mode 100644 index 887d3c7a07..0000000000 --- a/OsmAnd/res/layout/fragment_marker_coordinate_input_options_bottom_sheet_dialog.xml +++ /dev/null @@ -1,168 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithCompoundButton.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithCompoundButton.java index 68ba49f35e..8a967beab4 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithCompoundButton.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithCompoundButton.java @@ -1,8 +1,10 @@ package net.osmand.plus.base.bottomsheetmenu; +import android.content.res.ColorStateList; import android.graphics.drawable.Drawable; import android.support.annotation.ColorRes; import android.support.annotation.LayoutRes; +import android.support.v4.widget.CompoundButtonCompat; import android.view.View; import android.view.ViewGroup; import android.widget.CompoundButton; @@ -13,6 +15,7 @@ import net.osmand.plus.R; public class BottomSheetItemWithCompoundButton extends BottomSheetItemWithDescription { private boolean checked; + private ColorStateList buttonTintList; public BottomSheetItemWithCompoundButton(View customView, @LayoutRes int layoutId, @@ -25,7 +28,8 @@ public class BottomSheetItemWithCompoundButton extends BottomSheetItemWithDescri @ColorRes int titleColorId, CharSequence description, @ColorRes int descriptionColorId, - boolean checked) { + boolean checked, + ColorStateList buttonTintList) { super(customView, layoutId, tag, @@ -38,23 +42,32 @@ public class BottomSheetItemWithCompoundButton extends BottomSheetItemWithDescri description, descriptionColorId); this.checked = checked; + this.buttonTintList = buttonTintList; } @Override public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) { super.inflate(app, container, nightMode); - ((CompoundButton) view.findViewById(R.id.compound_button)).setChecked(checked); + CompoundButton compoundButton = (CompoundButton) view.findViewById(R.id.compound_button); + compoundButton.setChecked(checked); + CompoundButtonCompat.setButtonTintList(compoundButton, buttonTintList); } public static class Builder extends BottomSheetItemWithDescription.Builder { protected boolean checked; + protected ColorStateList buttonTintList; public Builder setChecked(boolean checked) { this.checked = checked; return this; } + public Builder setButtonTintList(ColorStateList buttonTintList) { + this.buttonTintList = buttonTintList; + return this; + } + public BottomSheetItemWithCompoundButton create() { return new BottomSheetItemWithCompoundButton(customView, layoutId, @@ -67,7 +80,8 @@ public class BottomSheetItemWithCompoundButton extends BottomSheetItemWithDescri titleColorId, description, descriptionColorId, - checked); + checked, + buttonTintList); } } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java index 1e5e81cbc5..1c155d29c8 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java @@ -4,23 +4,22 @@ import android.content.Context; import android.content.res.ColorStateList; import android.graphics.drawable.Drawable; import android.os.Bundle; -import android.support.annotation.ColorInt; +import android.support.annotation.ColorRes; import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; -import android.support.v4.widget.CompoundButtonCompat; -import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.CompoundButton; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.RadioButton; -import android.widget.TextView; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.base.MenuBottomSheetDialogFragment; +import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton; +import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.SubtitleDividerItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.SubtitleItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.mapmarkers.CoordinateInputFormats.CoordinateInputFormatDef; @@ -55,53 +54,58 @@ public class CoordinateInputBottomSheetDialogFragment extends MenuBottomSheetDia public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final Context context = getContext(); final OsmandSettings settings = getMyApplication().getSettings(); - final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; - boolean portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); - View mainView = View.inflate(new ContextThemeWrapper(context, themeRes), - R.layout.fragment_marker_coordinate_input_options_bottom_sheet_dialog, container); + items.add(new TitleItem(getString(R.string.shared_string_options))); - if (nightMode) { - ((TextView) mainView.findViewById(R.id.coordinate_input_title)) - .setTextColor(ContextCompat.getColor(context, R.color.ctx_menu_info_text_dark)); - } - - ((ImageView) mainView.findViewById(R.id.use_system_keyboard_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_keyboard)); - ((CompoundButton) mainView.findViewById(R.id.use_system_keyboard_switch)).setChecked(!useOsmandKeyboard); - - View.OnClickListener itemsOnClickListener = new View.OnClickListener() { - @Override - public void onClick(View v) { - if (listener != null) { - int id = v.getId(); - if (id == R.id.use_system_keyboard_row) { - listener.onKeyboardChanged(!useOsmandKeyboard); - } else if (id == R.id.hand_row) { - OsmandSettings.CommonPreference pref = settings.COORDS_INPUT_USE_RIGHT_SIDE; - pref.set(!pref.get()); - listener.onHandChanged(); + BaseBottomSheetItem useSystemKeyboardItem = new BottomSheetItemWithCompoundButton.Builder() + .setChecked(!useOsmandKeyboard) + .setIcon(getContentIcon(R.drawable.ic_action_keyboard)) + .setTitle(getString(R.string.use_system_keyboard)) + .setLayoutId(R.layout.bottom_sheet_item_with_switch) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.onKeyboardChanged(!useOsmandKeyboard); + } + dismiss(); } - } - dismiss(); - } - }; + }) + .create(); + items.add(useSystemKeyboardItem); - mainView.findViewById(R.id.use_system_keyboard_row).setOnClickListener(itemsOnClickListener); - mainView.findViewById(R.id.cancel_row).setOnClickListener(itemsOnClickListener); - - View handRow = mainView.findViewById(R.id.hand_row); - if (portrait) { - handRow.setVisibility(View.GONE); - } else { + if (!AndroidUiHelper.isOrientationPortrait(getActivity())) { boolean rightHand = settings.COORDS_INPUT_USE_RIGHT_SIDE.get(); - ((ImageView) mainView.findViewById(R.id.hand_icon)).setImageDrawable(getContentIcon(rightHand - ? R.drawable.ic_action_show_keypad_right : R.drawable.ic_action_show_keypad_left)); - ((TextView) mainView.findViewById(R.id.hand_text_view)).setText(getString(rightHand - ? R.string.shared_string_right : R.string.shared_string_left)); - ((TextView) mainView.findViewById(R.id.hand_text_view)).setTextColor(getResolvedActiveColor()); - handRow.setOnClickListener(itemsOnClickListener); + + BaseBottomSheetItem showNumberPadItem = new BottomSheetItemWithDescription.Builder() + .setDescription(getString(rightHand ? R.string.shared_string_right : R.string.shared_string_left)) + .setDescriptionColorId(getActiveColorId()) + .setIcon(getContentIcon(rightHand + ? R.drawable.ic_action_show_keypad_right + : R.drawable.ic_action_show_keypad_left)) + .setTitle(getString(R.string.show_number_pad)) + .setLayoutId(R.layout.bottom_sheet_item_with_right_descr) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + OsmandSettings.CommonPreference pref = settings.COORDS_INPUT_USE_RIGHT_SIDE; + pref.set(!pref.get()); + listener.onHandChanged(); + } + dismiss(); + } + }) + .create(); + items.add(showNumberPadItem); } + items.add(new SubtitleDividerItem(context)); + + items.add(new SubtitleItem(getString(R.string.coordinates_format))); + + int selectedFormat = settings.COORDS_INPUT_FORMAT.get(); + Drawable formatIcon = getContentIcon(R.drawable.ic_action_coordinates_latitude); View.OnClickListener formatsOnClickListener = new View.OnClickListener() { @Override public void onClick(View v) { @@ -114,34 +118,25 @@ public class CoordinateInputBottomSheetDialogFragment extends MenuBottomSheetDia } }; - LinearLayout formatsContainer = (LinearLayout) mainView.findViewById(R.id.formats_container); - Drawable formatIcon = getContentIcon(R.drawable.ic_action_coordinates_latitude); - int selectedFormat = settings.COORDS_INPUT_FORMAT.get(); for (@CoordinateInputFormatDef int format : CoordinateInputFormats.VALUES) { - boolean selectedRow = format == selectedFormat; + boolean selectedItem = format == selectedFormat; - View row = View.inflate(new ContextThemeWrapper(context, themeRes), - R.layout.bottom_sheet_item_with_radio_btn, null); - row.setTag(format); - row.setOnClickListener(formatsOnClickListener); - - ((ImageView) row.findViewById(R.id.icon)).setImageDrawable(selectedRow - ? getActiveIcon(R.drawable.ic_action_coordinates_latitude) : formatIcon); - TextView nameTv = (TextView) row.findViewById(R.id.title); - nameTv.setText(CoordinateInputFormats.formatToHumanString(context, format)); - if (selectedRow) { - nameTv.setTextColor(getResolvedActiveColor()); - RadioButton rb = (RadioButton) row.findViewById(R.id.compound_button); - rb.setChecked(true); - CompoundButtonCompat.setButtonTintList(rb, ColorStateList.valueOf(getResolvedActiveColor())); - } - - formatsContainer.addView(row); + BaseBottomSheetItem formatItem = new BottomSheetItemWithCompoundButton.Builder() + .setChecked(selectedItem) + .setButtonTintList(selectedItem + ? ColorStateList.valueOf(ContextCompat.getColor(context, getActiveColorId())) + : null) + .setIcon(selectedItem ? getActiveIcon(R.drawable.ic_action_coordinates_latitude) : formatIcon) + .setTitle(CoordinateInputFormats.formatToHumanString(context, format)) + .setTitleColorId(selectedItem ? getActiveColorId() : BaseBottomSheetItem.INVALID_ID) + .setLayoutId(R.layout.bottom_sheet_item_with_radio_btn) + .setOnClickListener(formatsOnClickListener) + .setTag(format) + .create(); + items.add(formatItem); } - setupHeightAndBackground(mainView, R.id.marker_coordinate_input_scroll_view); - - return mainView; + return null; } @Override @@ -150,9 +145,14 @@ public class CoordinateInputBottomSheetDialogFragment extends MenuBottomSheetDia super.onSaveInstanceState(outState); } - @ColorInt - private int getResolvedActiveColor() { - return ContextCompat.getColor(getContext(), nightMode ? R.color.osmand_orange : R.color.color_myloc_distance); + @Override + protected int getCloseRowTextId() { + return R.string.shared_string_close; + } + + @ColorRes + private int getActiveColorId() { + return nightMode ? R.color.osmand_orange : R.color.color_myloc_distance; } interface CoordinateInputFormatChangeListener { From d85d3063c1a6e2727c51a001dfa5bd92971943e3 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Fri, 2 Mar 2018 12:03:50 +0200 Subject: [PATCH 27/30] Rewrite UI in SaveAsNewTrackBottomSheetDialogFragment --- ..._save_as_new_track_bottom_sheet_dialog.xml | 206 ------------------ .../fragment_save_as_new_track_images_row.xml | 81 +++++++ ...veAsNewTrackBottomSheetDialogFragment.java | 85 ++++---- 3 files changed, 123 insertions(+), 249 deletions(-) delete mode 100644 OsmAnd/res/layout/fragment_save_as_new_track_bottom_sheet_dialog.xml create mode 100644 OsmAnd/res/layout/fragment_save_as_new_track_images_row.xml diff --git a/OsmAnd/res/layout/fragment_save_as_new_track_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_save_as_new_track_bottom_sheet_dialog.xml deleted file mode 100644 index 5606b9625f..0000000000 --- a/OsmAnd/res/layout/fragment_save_as_new_track_bottom_sheet_dialog.xml +++ /dev/null @@ -1,206 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/OsmAnd/res/layout/fragment_save_as_new_track_images_row.xml b/OsmAnd/res/layout/fragment_save_as_new_track_images_row.xml new file mode 100644 index 0000000000..ebdea2f235 --- /dev/null +++ b/OsmAnd/res/layout/fragment_save_as_new_track_images_row.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java index a349d03da3..ac3f023a9a 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java @@ -1,5 +1,6 @@ package net.osmand.plus.measurementtool; +import android.os.Build; import android.os.Bundle; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; @@ -7,10 +8,13 @@ import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; -import android.widget.TextView; import net.osmand.plus.R; import net.osmand.plus.base.MenuBottomSheetDialogFragment; +import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.DescriptionItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { @@ -24,60 +28,55 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial @Override public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; + items.add(new TitleItem(getString(R.string.shared_string_save_as_gpx))); - final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_save_as_new_track_bottom_sheet_dialog, container); + items.add(new DescriptionItem(getString(R.string.measurement_tool_save_as_new_track_descr))); - if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { - mainView.findViewById(R.id.images_row).setVisibility(View.GONE); - } else { - final ImageView routePointImage = (ImageView) mainView.findViewById(R.id.route_point_image); - ImageView lineImage = (ImageView) mainView.findViewById(R.id.line_image); - if (nightMode) { - routePointImage.setImageResource(R.drawable.img_help_trip_route_points_night); - lineImage.setImageResource(R.drawable.img_help_trip_track_night); - } else { - routePointImage.setImageResource(R.drawable.img_help_trip_route_points_day); - lineImage.setImageResource(R.drawable.img_help_trip_track_day); - } + if (Build.VERSION.SDK_INT >= 17) { + final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; + View imagesRow = View.inflate(new ContextThemeWrapper(getContext(), themeRes), + R.layout.fragment_save_as_new_track_images_row, null); - mainView.findViewById(R.id.line_text).setOnTouchListener(new View.OnTouchListener() { - @Override - public boolean onTouch(View view, MotionEvent motionEvent) { - return false; - } - }); + final ImageView routePointImage = (ImageView) imagesRow.findViewById(R.id.route_point_image); + final ImageView lineImage = (ImageView) imagesRow.findViewById(R.id.line_image); + routePointImage.setImageResource(nightMode + ? R.drawable.img_help_trip_route_points_night + : R.drawable.img_help_trip_route_points_day); + lineImage.setImageResource(nightMode + ? R.drawable.img_help_trip_track_night + : R.drawable.img_help_trip_track_day); + routePointImage.setOnClickListener(saveAsRoutePointOnClickListener); lineImage.setOnClickListener(saveAsLineOnClickListener); - mainView.findViewById(R.id.route_point_text).setOnTouchListener(new View.OnTouchListener() { + View.OnTouchListener textOnTouchListener = new View.OnTouchListener() { @Override - public boolean onTouch(View view, MotionEvent motionEvent) { + public boolean onTouch(View v, MotionEvent event) { return false; } - }); - routePointImage.setOnClickListener(saveAsRoutePointOnClickListener); + }; + imagesRow.findViewById(R.id.line_text).setOnTouchListener(textOnTouchListener); + imagesRow.findViewById(R.id.route_point_text).setOnTouchListener(textOnTouchListener); + + items.add(new BaseBottomSheetItem.Builder().setCustomView(imagesRow).create()); } - if (nightMode) { - ((TextView) mainView.findViewById(R.id.save_as_new_track_title)).setTextColor(getResources().getColor(R.color.ctx_menu_info_text_dark)); - } + BaseBottomSheetItem saveAsRoutePointsItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_route_points)) + .setTitle(getString(R.string.save_as_route_point)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(saveAsRoutePointOnClickListener) + .create(); + items.add(saveAsRoutePointsItem); - ((ImageView) mainView.findViewById(R.id.route_point_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_route_points)); - ((ImageView) mainView.findViewById(R.id.line_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_split_interval)); + BaseBottomSheetItem saveAsLineItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_split_interval)) + .setTitle(getString(R.string.save_as_line)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(saveAsLineOnClickListener) + .create(); + items.add(saveAsLineItem); - mainView.findViewById(R.id.save_as_line_row).setOnClickListener(saveAsLineOnClickListener); - mainView.findViewById(R.id.save_as_route_point_row).setOnClickListener(saveAsRoutePointOnClickListener); - - mainView.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - dismiss(); - } - }); - - setupHeightAndBackground(mainView, R.id.save_as_new_track_scroll_view); - - return mainView; + return null; } private View.OnClickListener saveAsLineOnClickListener = new View.OnClickListener() { From 6dd0e35702fbb3758e77bcd81fb712bc6c6a7b61 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Fri, 2 Mar 2018 12:39:39 +0200 Subject: [PATCH 28/30] Rewrite UI in ShareMenuFragment --- OsmAnd/res/layout/share_menu_fragment.xml | 61 ------------ .../other/ShareMenuFragment.java | 93 +++++-------------- 2 files changed, 24 insertions(+), 130 deletions(-) delete mode 100644 OsmAnd/res/layout/share_menu_fragment.xml diff --git a/OsmAnd/res/layout/share_menu_fragment.xml b/OsmAnd/res/layout/share_menu_fragment.xml deleted file mode 100644 index c4bcd564c6..0000000000 --- a/OsmAnd/res/layout/share_menu_fragment.xml +++ /dev/null @@ -1,61 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ShareMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ShareMenuFragment.java index 0487aa8aab..5137fd5585 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ShareMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ShareMenuFragment.java @@ -1,32 +1,22 @@ package net.osmand.plus.mapcontextmenu.other; -import android.annotation.SuppressLint; import android.os.Bundle; -import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.AdapterView; -import android.widget.AdapterView.OnItemClickListener; -import android.widget.ArrayAdapter; -import android.widget.ImageView; -import android.widget.ListView; -import android.widget.TextView; -import net.osmand.AndroidUtils; import net.osmand.plus.R; 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.SimpleBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; import net.osmand.plus.mapcontextmenu.other.ShareMenu.ShareItem; -import net.osmand.plus.widgets.TextViewEx; -import java.util.List; +public class ShareMenuFragment extends MenuBottomSheetDialogFragment { - -public class ShareMenuFragment extends MenuBottomSheetDialogFragment implements OnItemClickListener { public static final String TAG = "ShareMenuFragment"; - private ArrayAdapter listAdapter; private ShareMenu menu; @Override @@ -39,33 +29,33 @@ public class ShareMenuFragment extends MenuBottomSheetDialogFragment implements @Override public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; - final View view = View.inflate(new ContextThemeWrapper(getContext(), themeRes), - R.layout.share_menu_fragment, container); + items.add(new TitleItem(getString(R.string.share_menu_location))); - if (nightMode) { - ((TextViewEx) view.findViewById(R.id.title_text_view)).setTextColor(getResources().getColor(R.color.ctx_menu_info_text_dark)); + View.OnClickListener itemOnClickListener = new View.OnClickListener() { + @Override + public void onClick(View v) { + dismiss(); + menu.share((ShareItem) v.getTag()); + } + }; + + for (ShareItem shareItem : menu.getItems()) { + BaseBottomSheetItem item = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(shareItem.getIconResourceId())) + .setTitle(getString(shareItem.getTitleResourceId())) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(itemOnClickListener) + .setTag(shareItem) + .create(); + items.add(item); } - ListView listView = (ListView) view.findViewById(R.id.list); - listAdapter = createAdapter(); - listView.setAdapter(listAdapter); - listView.setOnItemClickListener(this); - - view.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - dismiss(); - } - }); - - setupHeightAndBackground(view, R.id.scroll_view); - - return view; + return null; } @Override public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); menu.saveMenu(outState); } @@ -75,39 +65,4 @@ public class ShareMenuFragment extends MenuBottomSheetDialogFragment implements fragment.setUsedOnMap(true); fragment.show(menu.getMapActivity().getSupportFragmentManager(), ShareMenuFragment.TAG); } - - private ArrayAdapter createAdapter() { - final List items = menu.getItems(); - return new ArrayAdapter(menu.getMapActivity(), R.layout.share_list_item, items) { - - @SuppressLint("InflateParams") - @Override - public View getView(final int position, View convertView, ViewGroup parent) { - View v = convertView; - if (v == null) { - v = menu.getMapActivity().getLayoutInflater().inflate(R.layout.share_list_item, null); - } - AndroidUtils.setBackground(v.getContext(), v, nightMode, R.drawable.expandable_list_item_background_light, R.drawable.expandable_list_item_background_dark); - final ShareItem item = getItem(position); - ImageView icon = (ImageView) v.findViewById(R.id.icon); - icon.setImageDrawable(menu.getMapActivity().getMyApplication() - .getIconsCache().getIcon(item.getIconResourceId(), !nightMode)); - TextView name = (TextView) v.findViewById(R.id.name); - AndroidUtils.setTextPrimaryColor(v.getContext(), name, nightMode); - name.setText(getContext().getText(item.getTitleResourceId())); - return v; - } - }; - } - - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - dismiss(); - menu.share(listAdapter.getItem(position)); - } - - public void dismissMenu() { - dismiss(); - menu.getMapActivity().getContextMenu().close(); - } } From 3f2c1f7a6fd08a0b387746c4298804279bc0f12c Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Fri, 2 Mar 2018 14:12:24 +0200 Subject: [PATCH 29/30] Rewrite UI in SelectedPointBottomSheetDialogFragment --- ...ment_selected_menu_bottom_sheet_dialog.xml | 261 ----------------- .../base/MenuBottomSheetDialogFragment.java | 5 + .../simpleitems/TitleDividerItem.java | 24 ++ ...electedPointBottomSheetDialogFragment.java | 274 +++++++++++------- 4 files changed, 198 insertions(+), 366 deletions(-) delete mode 100644 OsmAnd/res/layout/fragment_selected_menu_bottom_sheet_dialog.xml create mode 100644 OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/TitleDividerItem.java diff --git a/OsmAnd/res/layout/fragment_selected_menu_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_selected_menu_bottom_sheet_dialog.xml deleted file mode 100644 index ff13e0cad9..0000000000 --- a/OsmAnd/res/layout/fragment_selected_menu_bottom_sheet_dialog.xml +++ /dev/null @@ -1,261 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java index 044e3d47f1..4804078a8a 100644 --- a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java @@ -78,6 +78,7 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra mainView.findViewById(R.id.close_row).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + onCloseRowClickAction(); dismiss(); } }); @@ -175,6 +176,10 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra return R.string.shared_string_cancel; } + protected void onCloseRowClickAction() { + + } + @DrawableRes protected int getPortraitBgResId() { return nightMode ? R.drawable.bg_bottom_menu_dark : R.drawable.bg_bottom_menu_light; diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/TitleDividerItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/TitleDividerItem.java new file mode 100644 index 0000000000..d1531d80b5 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/TitleDividerItem.java @@ -0,0 +1,24 @@ +package net.osmand.plus.base.bottomsheetmenu.simpleitems; + +import android.content.Context; +import android.support.annotation.ColorRes; + +public class TitleDividerItem extends DividerItem { + + public TitleDividerItem(Context context) { + super(context); + } + + public TitleDividerItem(Context context, @ColorRes int colorId) { + super(context, colorId); + } + + public TitleDividerItem(Context context, @ColorRes int colorId, int position) { + super(context, colorId, position); + } + + @Override + protected int getTopMargin(Context context) { + return 0; + } +} diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java index e59a41a948..7b9215a2ac 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java @@ -1,20 +1,25 @@ package net.osmand.plus.measurementtool; +import android.app.Activity; import android.content.DialogInterface; import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.text.TextUtils; -import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.R; 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.SimpleBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleDividerItem; import net.osmand.plus.measurementtool.NewGpxData.ActionType; import net.osmand.util.MapUtils; @@ -32,114 +37,83 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo @Override public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - final MapActivity mapActivity = (MapActivity) getActivity(); - final MeasurementToolLayer measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer(); - final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; + BaseBottomSheetItem titleItem = new BottomSheetItemWithDescription.Builder() + .setDescription(getDescription()) + .setIcon(getActiveIcon(R.drawable.ic_action_measure_point)) + .setTitle(getTitle()) + .setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp) + .create(); + items.add(titleItem); - final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_selected_menu_bottom_sheet_dialog, null); + items.add(new TitleDividerItem(getContext())); - ((ImageView) mainView.findViewById(R.id.selected_point_icon)).setImageDrawable(getActiveIcon(R.drawable.ic_action_measure_point)); - ((ImageView) mainView.findViewById(R.id.move_point_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_move_point)); - ((ImageView) mainView.findViewById(R.id.delete_point_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_remove_dark)); - ((ImageView) mainView.findViewById(R.id.add_point_after_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_addpoint_above)); - ((ImageView) mainView.findViewById(R.id.add_point_before_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_addpoint_below)); + BaseBottomSheetItem moveItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_move_point)) + .setTitle(getString(R.string.shared_string_move)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.moveOnClick(); + } + dismiss(); + } + }) + .create(); + items.add(moveItem); - mainView.findViewById(R.id.move_point_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (listener != null) { - listener.moveOnClick(); - } - dismiss(); - } - }); - mainView.findViewById(R.id.delete_point_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (listener != null) { - listener.deleteOnClick(); - } - dismiss(); - } - }); - mainView.findViewById(R.id.add_point_after_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (listener != null) { - listener.addPointAfterOnClick(); - } - dismiss(); - } - }); - mainView.findViewById(R.id.add_point_before_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (listener != null) { - listener.addPointBeforeOnClick(); - } - dismiss(); - } - }); - mainView.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (listener != null) { - listener.onClearSelection(); - } - dismiss(); - } - }); + BaseBottomSheetItem deleteItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_remove_dark)) + .setTitle(getString(R.string.shared_string_delete)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.deleteOnClick(); + } + dismiss(); + } + }) + .create(); + items.add(deleteItem); - List points = measurementLayer.getEditingCtx().getPoints(); - int pos = measurementLayer.getEditingCtx().getSelectedPointPosition(); - WptPt pt = points.get(pos); - String pointTitle = pt.name; - if (!TextUtils.isEmpty(pointTitle)) { - ((TextView) mainView.findViewById(R.id.selected_point_title)).setText(pointTitle); - } else { - NewGpxData newGpxData = measurementLayer.getEditingCtx().getNewGpxData(); - if (newGpxData != null) { - ActionType actionType = measurementLayer.getEditingCtx().getNewGpxData().getActionType(); - if (actionType == ActionType.ADD_ROUTE_POINTS) { - ((TextView) mainView.findViewById(R.id.selected_point_title)).setText(mapActivity.getString(R.string.route_point) + " - " + (pos + 1)); - } else { - ((TextView) mainView.findViewById(R.id.selected_point_title)).setText(mapActivity.getString(R.string.plugin_distance_point) + " - " + (pos + 1)); - } - } else { - ((TextView) mainView.findViewById(R.id.selected_point_title)).setText(mapActivity.getString(R.string.plugin_distance_point) + " - " + (pos + 1)); - } - } - String pointDesc = pt.desc; - if (!TextUtils.isEmpty(pointDesc)) { - ((TextView) mainView.findViewById(R.id.selected_point_distance)).setText(pointDesc); - } else { - if (pos < 1) { - ((TextView) mainView.findViewById(R.id.selected_point_distance)).setText(mapActivity.getString(R.string.shared_string_control_start)); - } else { - float dist = 0; - for (int i = 1; i <= pos; i++) { - dist += MapUtils.getDistance(points.get(i - 1).lat, points.get(i - 1).lon, points.get(i).lat, points.get(i).lon); - } - ((TextView) mainView.findViewById(R.id.selected_point_distance)).setText(OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication())); - } - } - NewGpxData newGpxData = measurementLayer.getEditingCtx().getNewGpxData(); - if (newGpxData != null && newGpxData.getActionType() == ActionType.EDIT_SEGMENT) { - double elevation = pt.ele; - if (!Double.isNaN(elevation)) { - String eleStr = (mapActivity.getString(R.string.altitude)).substring(0, 1); - ((TextView) mainView.findViewById(R.id.selected_point_ele)).setText(eleStr + ": " + OsmAndFormatter.getFormattedAlt(elevation, mapActivity.getMyApplication())); - } - float speed = (float) pt.speed; - if (speed != 0) { - String speedStr = (mapActivity.getString(R.string.map_widget_speed)).substring(0, 1); - ((TextView) mainView.findViewById(R.id.selected_point_speed)).setText(speedStr + ": " + OsmAndFormatter.getFormattedSpeed(speed, mapActivity.getMyApplication())); - } - } + items.add(new DividerHalfItem(getContext())); - setupHeightAndBackground(mainView, R.id.selected_point_options_scroll_view); + BaseBottomSheetItem addAfterItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_addpoint_above)) + .setTitle(getString(R.string.add_point_after)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.addPointAfterOnClick(); + } + dismiss(); + } + }) + .create(); + items.add(addAfterItem); - return mainView; + BaseBottomSheetItem addBeforeItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_addpoint_below)) + .setTitle(getString(R.string.add_point_before)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.addPointBeforeOnClick(); + } + dismiss(); + } + }) + .create(); + items.add(addBeforeItem); + + return null; } @Override @@ -159,6 +133,96 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo super.onCancel(dialog); } + @Override + protected int getCloseRowTextId() { + return R.string.shared_string_close; + } + + @Override + protected void onCloseRowClickAction() { + if (listener != null) { + listener.onClearSelection(); + } + } + + @Nullable + private MapActivity getMapActivity() { + Activity activity = getActivity(); + if (activity instanceof MapActivity) { + return (MapActivity) activity; + } + return null; + } + + @NonNull + private String getTitle() { + MapActivity mapActivity = getMapActivity(); + if (mapActivity == null) { + return ""; + } + + MeasurementEditingContext editingCtx = mapActivity.getMapLayers().getMeasurementToolLayer().getEditingCtx(); + int pos = editingCtx.getSelectedPointPosition(); + + String pointName = editingCtx.getPoints().get(pos).name; + if (!TextUtils.isEmpty(pointName)) { + return pointName; + } + + NewGpxData newGpxData = editingCtx.getNewGpxData(); + if (newGpxData != null && newGpxData.getActionType() == ActionType.ADD_ROUTE_POINTS) { + return getString(R.string.route_point) + " - " + (pos + 1); + } + + return getString(R.string.plugin_distance_point) + " - " + (pos + 1); + } + + @NonNull + private String getDescription() { + MapActivity mapActivity = getMapActivity(); + if (mapActivity == null) { + return ""; + } + + StringBuilder description = new StringBuilder(); + + MeasurementEditingContext editingCtx = mapActivity.getMapLayers().getMeasurementToolLayer().getEditingCtx(); + int pos = editingCtx.getSelectedPointPosition(); + List points = editingCtx.getPoints(); + WptPt pt = points.get(pos); + + String pointDesc = pt.desc; + if (!TextUtils.isEmpty(pointDesc)) { + description.append(pointDesc); + } else if (pos < 1) { + description.append(getString(R.string.shared_string_control_start)); + } else { + float dist = 0; + for (int i = 1; i <= pos; i++) { + WptPt first = points.get(i - 1); + WptPt second = points.get(i); + dist += MapUtils.getDistance(first.lat, first.lon, second.lat, second.lon); + } + description.append(OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication())); + } + + NewGpxData newGpxData = editingCtx.getNewGpxData(); + if (newGpxData != null && newGpxData.getActionType() == ActionType.EDIT_SEGMENT) { + double elevation = pt.ele; + if (!Double.isNaN(elevation)) { + description.append(" ").append((getString(R.string.altitude)).substring(0, 1)).append(": "); + description.append(OsmAndFormatter.getFormattedAlt(elevation, mapActivity.getMyApplication())); + } + float speed = (float) pt.speed; + if (speed != 0) { + description.append(" ").append((getString(R.string.map_widget_speed)).substring(0, 1)).append(": "); + description.append(OsmAndFormatter.getFormattedSpeed(speed, mapActivity.getMyApplication())); + } + } + + return description.toString(); + } + interface SelectedPointFragmentListener { void moveOnClick(); From 38c71bb5f7e2a63acb0e258e3cccdd12fa969d9f Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Fri, 2 Mar 2018 14:20:51 +0200 Subject: [PATCH 30/30] Fix signature and return value of createMenuItems method --- .../audionotes/ItemMenuBottomSheetDialogFragment.java | 6 +----- .../audionotes/SortByMenuBottomSheetDialogFragment.java | 6 +----- .../osmand/plus/base/MenuBottomSheetDialogFragment.java | 8 ++------ .../dialogs/AddWaypointBottomSheetDialogFragment.java | 6 +----- OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java | 4 +--- .../plus/mapcontextmenu/other/ShareMenuFragment.java | 6 +----- .../mapmarkers/AddGroupBottomSheetDialogFragment.java | 6 +----- .../CoordinateInputBottomSheetDialogFragment.java | 6 +----- .../HistoryMarkerMenuBottomSheetDialogFragment.java | 6 +----- .../plus/mapmarkers/OrderByBottomSheetDialogFragment.java | 6 +----- .../PlanRouteOptionsBottomSheetDialogFragment.java | 6 +----- .../SelectionMarkersGroupBottomSheetDialogFragment.java | 6 +----- .../measurementtool/OptionsBottomSheetDialogFragment.java | 6 +----- .../SaveAsNewTrackBottomSheetDialogFragment.java | 6 +----- .../SelectedPointBottomSheetDialogFragment.java | 6 +----- .../osmedit/ExportOptionsBottomSheetDialogFragment.java | 6 +----- .../plus/osmedit/FileTypeBottomSheetDialogFragment.java | 6 +----- .../osmedit/OsmEditOptionsBottomSheetDialogFragment.java | 6 +----- 18 files changed, 19 insertions(+), 89 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/audionotes/ItemMenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/audionotes/ItemMenuBottomSheetDialogFragment.java index 1f4d53f442..26014c4cb7 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/ItemMenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/ItemMenuBottomSheetDialogFragment.java @@ -1,9 +1,7 @@ package net.osmand.plus.audionotes; import android.os.Bundle; -import android.view.LayoutInflater; import android.view.View; -import android.view.ViewGroup; import net.osmand.plus.R; import net.osmand.plus.audionotes.AudioVideoNotesPlugin.Recording; @@ -31,7 +29,7 @@ public class ItemMenuBottomSheetDialogFragment extends MenuBottomSheetDialogFrag } @Override - public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public void createMenuItems(Bundle savedInstanceState) { if (recording != null) { items.add(new TitleItem(recording.getName(getContext(), true))); @@ -118,8 +116,6 @@ public class ItemMenuBottomSheetDialogFragment extends MenuBottomSheetDialogFrag .create(); items.add(deleteItem); } - - return null; } @Override diff --git a/OsmAnd/src/net/osmand/plus/audionotes/SortByMenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/audionotes/SortByMenuBottomSheetDialogFragment.java index 8f946975ea..9fc75f7f5d 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/SortByMenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/SortByMenuBottomSheetDialogFragment.java @@ -1,9 +1,7 @@ package net.osmand.plus.audionotes; import android.os.Bundle; -import android.view.LayoutInflater; import android.view.View; -import android.view.ViewGroup; import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.NotesSortByMode; @@ -24,7 +22,7 @@ public class SortByMenuBottomSheetDialogFragment extends MenuBottomSheetDialogFr } @Override - public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public void createMenuItems(Bundle savedInstanceState) { items.add(new TitleItem(getString(R.string.shared_string_sort))); BaseBottomSheetItem byTypeItem = new SimpleBottomSheetItem.Builder() @@ -52,8 +50,6 @@ public class SortByMenuBottomSheetDialogFragment extends MenuBottomSheetDialogFr }) .create(); items.add(byDateItem); - - return null; } private void selectSortByMode(NotesSortByMode mode) { diff --git a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java index 4804078a8a..f1b2034b3c 100644 --- a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java @@ -55,10 +55,7 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) { - View view = createMenuItems(inflater, parent, savedInstanceState); - if (view != null) { - return view; - } + createMenuItems(savedInstanceState); OsmandApplication app = getMyApplication(); final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; @@ -115,8 +112,7 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra } } - // inflater, parent and return value are temporary and will be deleted - public abstract View createMenuItems(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState); + public abstract void createMenuItems(Bundle savedInstanceState); @Override protected Drawable getContentIcon(@DrawableRes int id) { diff --git a/OsmAnd/src/net/osmand/plus/dialogs/AddWaypointBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/dialogs/AddWaypointBottomSheetDialogFragment.java index 8be79919f4..17d5b7c289 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/AddWaypointBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/AddWaypointBottomSheetDialogFragment.java @@ -8,9 +8,7 @@ import android.graphics.drawable.LayerDrawable; import android.os.Bundle; import android.support.annotation.DrawableRes; import android.support.annotation.Nullable; -import android.view.LayoutInflater; import android.view.View; -import android.view.ViewGroup; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; @@ -32,7 +30,7 @@ public class AddWaypointBottomSheetDialogFragment extends MenuBottomSheetDialogF public static final String POINT_DESCRIPTION_KEY = "point_description"; @Override - public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public void createMenuItems(Bundle savedInstanceState) { Bundle args = getArguments(); final LatLon latLon = new LatLon(args.getDouble(LAT_KEY), args.getDouble(LON_KEY)); final PointDescription name = PointDescription.deserializeFromString(args.getString(POINT_DESCRIPTION_KEY), latLon); @@ -128,8 +126,6 @@ public class AddWaypointBottomSheetDialogFragment extends MenuBottomSheetDialogF }) .create(); items.add(lastIntermItem); - - return null; } @Override diff --git a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java index b721b408d8..a7c2593f1b 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java @@ -746,7 +746,7 @@ public class ImportHelper { } @Override - public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public void createMenuItems(Bundle savedInstanceState) { items.add(new TitleItem(getString(R.string.import_file))); int nameColor = getResolvedColor(nightMode ? R.color.osmand_orange : R.color.dashboard_blue); @@ -787,8 +787,6 @@ public class ImportHelper { }) .create(); items.add(asGpxItem); - - return null; } @ColorInt diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ShareMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ShareMenuFragment.java index 5137fd5585..9be893ee1e 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ShareMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ShareMenuFragment.java @@ -1,9 +1,7 @@ package net.osmand.plus.mapcontextmenu.other; import android.os.Bundle; -import android.view.LayoutInflater; import android.view.View; -import android.view.ViewGroup; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; @@ -28,7 +26,7 @@ public class ShareMenuFragment extends MenuBottomSheetDialogFragment { } @Override - public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public void createMenuItems(Bundle savedInstanceState) { items.add(new TitleItem(getString(R.string.share_menu_location))); View.OnClickListener itemOnClickListener = new View.OnClickListener() { @@ -49,8 +47,6 @@ public class ShareMenuFragment extends MenuBottomSheetDialogFragment { .create(); items.add(item); } - - return null; } @Override diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/AddGroupBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/AddGroupBottomSheetDialogFragment.java index 47fe043663..6dc530bef5 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/AddGroupBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/AddGroupBottomSheetDialogFragment.java @@ -5,9 +5,7 @@ import android.os.Bundle; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.ContextThemeWrapper; -import android.view.LayoutInflater; import android.view.View; -import android.view.ViewGroup; import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup; @@ -36,7 +34,7 @@ public abstract class AddGroupBottomSheetDialogFragment extends MenuBottomSheetD } @Override - public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public void createMenuItems(Bundle savedInstanceState) { final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_add_group_bottom_sheet_dialog, null); @@ -68,8 +66,6 @@ public abstract class AddGroupBottomSheetDialogFragment extends MenuBottomSheetD recyclerView.setAdapter(adapter); items.add(new BaseBottomSheetItem.Builder().setCustomView(mainView).create()); - - return null; } @Override diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java index 1c155d29c8..75472c3b3b 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java @@ -7,9 +7,7 @@ import android.os.Bundle; import android.support.annotation.ColorRes; import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; -import android.view.LayoutInflater; import android.view.View; -import android.view.ViewGroup; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; @@ -51,7 +49,7 @@ public class CoordinateInputBottomSheetDialogFragment extends MenuBottomSheetDia } @Override - public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public void createMenuItems(Bundle savedInstanceState) { final Context context = getContext(); final OsmandSettings settings = getMyApplication().getSettings(); @@ -135,8 +133,6 @@ public class CoordinateInputBottomSheetDialogFragment extends MenuBottomSheetDia .create(); items.add(formatItem); } - - return null; } @Override diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java index 28920114c4..798729d301 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java @@ -1,9 +1,7 @@ package net.osmand.plus.mapmarkers; import android.os.Bundle; -import android.view.LayoutInflater; import android.view.View; -import android.view.ViewGroup; import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.R; @@ -34,7 +32,7 @@ public class HistoryMarkerMenuBottomSheetDialogFragment extends MenuBottomSheetD } @Override - public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public void createMenuItems(Bundle savedInstanceState) { Bundle arguments = getArguments(); if (arguments != null) { @@ -91,8 +89,6 @@ public class HistoryMarkerMenuBottomSheetDialogFragment extends MenuBottomSheetD .create(); items.add(deleteItem); } - - return null; } @Override diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java index 3487d52a85..7b786261ca 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java @@ -2,9 +2,7 @@ package net.osmand.plus.mapmarkers; import android.graphics.drawable.Drawable; import android.os.Bundle; -import android.view.LayoutInflater; import android.view.View; -import android.view.ViewGroup; import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper.MapMarkersSortByDef; @@ -26,7 +24,7 @@ public class OrderByBottomSheetDialogFragment extends MenuBottomSheetDialogFragm } @Override - public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public void createMenuItems(Bundle savedInstanceState) { Drawable distanceIcon = getContentIcon(R.drawable.ic_action_markers_dark); Drawable dateIcon = getContentIcon(R.drawable.ic_action_sort_by_date); @@ -115,8 +113,6 @@ public class OrderByBottomSheetDialogFragment extends MenuBottomSheetDialogFragm }) .create(); items.add(dateDescItem); - - return null; } @Override diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java index c228e895b9..2386569c32 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java @@ -1,9 +1,7 @@ package net.osmand.plus.mapmarkers; import android.os.Bundle; -import android.view.LayoutInflater; import android.view.View; -import android.view.ViewGroup; import net.osmand.plus.R; import net.osmand.plus.base.MenuBottomSheetDialogFragment; @@ -28,7 +26,7 @@ public class PlanRouteOptionsBottomSheetDialogFragment extends MenuBottomSheetDi } @Override - public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public void createMenuItems(Bundle savedInstanceState) { items.add(new TitleItem(getString(R.string.shared_string_options))); if (!AndroidUiHelper.isOrientationPortrait(getActivity())) { @@ -120,8 +118,6 @@ public class PlanRouteOptionsBottomSheetDialogFragment extends MenuBottomSheetDi }) .create(); items.add(reversItem); - - return null; } @Override diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/SelectionMarkersGroupBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/SelectionMarkersGroupBottomSheetDialogFragment.java index 1a63dfc074..2d6923d8d3 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/SelectionMarkersGroupBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/SelectionMarkersGroupBottomSheetDialogFragment.java @@ -1,9 +1,7 @@ package net.osmand.plus.mapmarkers; import android.os.Bundle; -import android.view.LayoutInflater; import android.view.View; -import android.view.ViewGroup; import net.osmand.plus.R; import net.osmand.plus.base.MenuBottomSheetDialogFragment; @@ -23,7 +21,7 @@ public class SelectionMarkersGroupBottomSheetDialogFragment extends MenuBottomSh } @Override - public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public void createMenuItems(Bundle savedInstanceState) { items.add(new TitleItem(getString(R.string.add_group))); items.add(new DescriptionItem(getString(R.string.add_group_descr))); @@ -59,8 +57,6 @@ public class SelectionMarkersGroupBottomSheetDialogFragment extends MenuBottomSh }) .create(); items.add(waypointsItem); - - return null; } @Override diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java index 03f53b6d78..c171c60f85 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java @@ -1,9 +1,7 @@ package net.osmand.plus.measurementtool; import android.os.Bundle; -import android.view.LayoutInflater; import android.view.View; -import android.view.ViewGroup; import net.osmand.plus.R; import net.osmand.plus.base.MenuBottomSheetDialogFragment; @@ -27,7 +25,7 @@ public class OptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragm } @Override - public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public void createMenuItems(Bundle savedInstanceState) { Bundle args = getArguments(); boolean snapToRoadEnabled = args.getBoolean(SNAP_TO_ROAD_ENABLED_KEY); boolean addLineMode = args.getBoolean(ADD_LINE_MODE_KEY); @@ -123,8 +121,6 @@ public class OptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragm }) .create(); items.add(clearAllItem); - - return null; } @Override diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java index ac3f023a9a..f70bc6d4c3 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java @@ -3,10 +3,8 @@ package net.osmand.plus.measurementtool; import android.os.Build; import android.os.Bundle; import android.view.ContextThemeWrapper; -import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; -import android.view.ViewGroup; import android.widget.ImageView; import net.osmand.plus.R; @@ -27,7 +25,7 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial } @Override - public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public void createMenuItems(Bundle savedInstanceState) { items.add(new TitleItem(getString(R.string.shared_string_save_as_gpx))); items.add(new DescriptionItem(getString(R.string.measurement_tool_save_as_new_track_descr))); @@ -75,8 +73,6 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial .setOnClickListener(saveAsLineOnClickListener) .create(); items.add(saveAsLineItem); - - return null; } private View.OnClickListener saveAsLineOnClickListener = new View.OnClickListener() { diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java index 7b9215a2ac..893dc62845 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java @@ -6,9 +6,7 @@ import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.text.TextUtils; -import android.view.LayoutInflater; import android.view.View; -import android.view.ViewGroup; import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.OsmAndFormatter; @@ -36,7 +34,7 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo } @Override - public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public void createMenuItems(Bundle savedInstanceState) { BaseBottomSheetItem titleItem = new BottomSheetItemWithDescription.Builder() .setDescription(getDescription()) .setIcon(getActiveIcon(R.drawable.ic_action_measure_point)) @@ -112,8 +110,6 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo }) .create(); items.add(addBeforeItem); - - return null; } @Override diff --git a/OsmAnd/src/net/osmand/plus/osmedit/ExportOptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/ExportOptionsBottomSheetDialogFragment.java index 359ee0bf5d..fde5b31358 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/ExportOptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/ExportOptionsBottomSheetDialogFragment.java @@ -1,9 +1,7 @@ package net.osmand.plus.osmedit; import android.os.Bundle; -import android.view.LayoutInflater; import android.view.View; -import android.view.ViewGroup; import net.osmand.plus.R; import net.osmand.plus.base.MenuBottomSheetDialogFragment; @@ -29,7 +27,7 @@ public class ExportOptionsBottomSheetDialogFragment extends MenuBottomSheetDialo } @Override - public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public void createMenuItems(Bundle savedInstanceState) { Bundle args = getArguments(); if (args != null) { poiCount = args.getInt(POI_COUNT_KEY); @@ -93,8 +91,6 @@ public class ExportOptionsBottomSheetDialogFragment extends MenuBottomSheetDialo }) .create(); items.add(allDataItem); - - return null; } public interface ExportOptionsFragmentListener { diff --git a/OsmAnd/src/net/osmand/plus/osmedit/FileTypeBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/FileTypeBottomSheetDialogFragment.java index 242338544c..b09c6c1f28 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/FileTypeBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/FileTypeBottomSheetDialogFragment.java @@ -2,9 +2,7 @@ package net.osmand.plus.osmedit; import android.graphics.drawable.Drawable; import android.os.Bundle; -import android.view.LayoutInflater; import android.view.View; -import android.view.ViewGroup; import net.osmand.plus.R; import net.osmand.plus.base.MenuBottomSheetDialogFragment; @@ -25,7 +23,7 @@ public class FileTypeBottomSheetDialogFragment extends MenuBottomSheetDialogFrag } @Override - public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public void createMenuItems(Bundle savedInstanceState) { items.add(new TitleItem(getString(R.string.choose_file_type))); Drawable fileIcon = getContentIcon(R.drawable.ic_type_file); @@ -65,8 +63,6 @@ public class FileTypeBottomSheetDialogFragment extends MenuBottomSheetDialogFrag }) .create(); items.add(gpxItem); - - return null; } public interface FileTypeFragmentListener { diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditOptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditOptionsBottomSheetDialogFragment.java index aacb47d3ff..d95f9e540f 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditOptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditOptionsBottomSheetDialogFragment.java @@ -1,9 +1,7 @@ package net.osmand.plus.osmedit; import android.os.Bundle; -import android.view.LayoutInflater; import android.view.View; -import android.view.ViewGroup; import net.osmand.plus.R; import net.osmand.plus.base.MenuBottomSheetDialogFragment; @@ -25,7 +23,7 @@ public class OsmEditOptionsBottomSheetDialogFragment extends MenuBottomSheetDial } @Override - public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public void createMenuItems(Bundle savedInstanceState) { Bundle args = getArguments(); if (args != null) { final OsmPoint osmPoint = (OsmPoint) args.getSerializable(OSM_POINT); @@ -118,8 +116,6 @@ public class OsmEditOptionsBottomSheetDialogFragment extends MenuBottomSheetDial .create(); items.add(deleteItem); } - - return null; } @Override