From bdebb86bc6717209c5c4b6c8c492ecc53a03c035 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Mon, 26 Feb 2018 16:00:24 +0200 Subject: [PATCH] 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);