From e46fa446dce1a098657ad85184743dc32c334087 Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 4 Jan 2018 18:29:33 +0200 Subject: [PATCH 1/8] Change behavior for additional actions context menu --- ...ntext_menu_actions_bottom_sheet_dialog.xml | 51 +++++++++---- ...ionalActionsBottomSheetDialogFragment.java | 74 ++++++++----------- 2 files changed, 65 insertions(+), 60 deletions(-) diff --git a/OsmAnd/res/layout/fragment_context_menu_actions_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_context_menu_actions_bottom_sheet_dialog.xml index bfbcb1756b..1d61901d03 100644 --- a/OsmAnd/res/layout/fragment_context_menu_actions_bottom_sheet_dialog.xml +++ b/OsmAnd/res/layout/fragment_context_menu_actions_bottom_sheet_dialog.xml @@ -1,31 +1,50 @@ - + android:orientation="vertical"> - + android:layout_height="0dp" + android:layout_weight="1"> - - - + android:background="?attr/bg_color" + app:behavior_hideable="true" + app:behavior_peekHeight="300dp" + app:layout_behavior="net.osmand.plus.widgets.tools.ExtendedBottomSheetBehavior"> - + android:layout_height="wrap_content" + android:orientation="vertical"> - + + + + + + + + + + + - + diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/AdditionalActionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/AdditionalActionsBottomSheetDialogFragment.java index 4b9d379ef9..ea7a0dac8e 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/AdditionalActionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/AdditionalActionsBottomSheetDialogFragment.java @@ -1,36 +1,29 @@ package net.osmand.plus.mapcontextmenu; -import android.app.Dialog; -import android.content.DialogInterface; import android.graphics.drawable.Drawable; +import android.os.Bundle; import android.support.annotation.DrawableRes; -import android.support.design.widget.BottomSheetBehavior; -import android.support.design.widget.BottomSheetDialog; -import android.support.design.widget.BottomSheetDialogFragment; +import android.support.annotation.NonNull; +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.view.Window; import android.view.WindowManager; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.LinearLayout; -import android.widget.ListView; import android.widget.TextView; -import net.osmand.AndroidUtils; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuItem; -import net.osmand.plus.OsmandApplication; -import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; -import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.AndroidUiHelper; +import net.osmand.plus.widgets.tools.ExtendedBottomSheetBehavior; +import net.osmand.plus.widgets.tools.ExtendedBottomSheetBehavior.BottomSheetCallback; -public class AdditionalActionsBottomSheetDialogFragment extends BottomSheetDialogFragment { +public class AdditionalActionsBottomSheetDialogFragment extends net.osmand.plus.base.BottomSheetDialogFragment { public static final String TAG = "AdditionalActionsBottomSheetDialogFragment"; @@ -44,24 +37,18 @@ public class AdditionalActionsBottomSheetDialogFragment extends BottomSheetDialo this.listener = listener; } + @Nullable @Override - public void setupDialog(Dialog dialog, int style) { - super.setupDialog(dialog, style); - - if (getMyApplication().getSettings().DO_NOT_USE_ANIMATIONS.get()) { - dialog.getWindow().setWindowAnimations(R.style.Animations_NoAnimation); - } - + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls(); portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); - final OsmandSettings settings = getMyApplication().getSettings(); final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_context_menu_actions_bottom_sheet_dialog, null); - AndroidUtils.setBackground(getActivity(), mainView, nightMode, - portrait ? R.drawable.bg_bottom_menu_light : R.drawable.bg_bottom_sheet_topsides_landscape_light, - portrait ? R.drawable.bg_bottom_menu_dark : R.drawable.bg_bottom_sheet_topsides_landscape_dark); +// AndroidUtils.setBackground(getActivity(), mainView, nightMode, +// portrait ? R.drawable.bg_bottom_menu_light : R.drawable.bg_bottom_sheet_topsides_landscape_light, +// portrait ? R.drawable.bg_bottom_menu_dark : R.drawable.bg_bottom_sheet_topsides_landscape_dark); mainView.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() { @Override @@ -74,18 +61,7 @@ public class AdditionalActionsBottomSheetDialogFragment extends BottomSheetDialo if (nightMode) { headerTitle.setTextColor(ContextCompat.getColor(getActivity(), R.color.ctx_menu_info_text_dark)); } - headerTitle.setText(getString(R.string.additional_actions)); - - if (!portrait) { - dialog.setOnShowListener(new DialogInterface.OnShowListener() { - @Override - public void onShow(DialogInterface dialogInterface) { - BottomSheetDialog dialog = (BottomSheetDialog) dialogInterface; - FrameLayout bottomSheet = (FrameLayout) dialog.findViewById(android.support.design.R.id.design_bottom_sheet); - BottomSheetBehavior.from(bottomSheet).setState(BottomSheetBehavior.STATE_EXPANDED); - } - }); - } + headerTitle.setText(R.string.additional_actions); View.OnClickListener onClickListener = new View.OnClickListener() { @Override @@ -114,8 +90,21 @@ public class AdditionalActionsBottomSheetDialogFragment extends BottomSheetDialo itemsLinearLayout.addView(row); } - dialog.setContentView(mainView); - ((View) mainView.getParent()).setBackgroundResource(0); + ExtendedBottomSheetBehavior.from(mainView.findViewById(R.id.bottom_sheet_scroll_view)).setBottomSheetCallback(new BottomSheetCallback() { + @Override + public void onStateChanged(@NonNull View bottomSheet, int newState) { + if (newState == ExtendedBottomSheetBehavior.STATE_HIDDEN) { + dismiss(); + } + } + + @Override + public void onSlide(@NonNull View bottomSheet, float slideOffset) { + + } + }); + + return mainView; } @Override @@ -129,11 +118,8 @@ public class AdditionalActionsBottomSheetDialogFragment extends BottomSheetDialo } } - private OsmandApplication getMyApplication() { - return ((MapActivity) getActivity()).getMyApplication(); - } - - private Drawable getContentIcon(@DrawableRes int id) { + @Override + protected Drawable getContentIcon(@DrawableRes int id) { return getMyApplication().getIconsCache().getIcon(id, nightMode ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color); } From e309f9173ded71be10c0f7301417fdb71d62bc2f Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 5 Jan 2018 16:03:19 +0200 Subject: [PATCH 2/8] Set peek height for 2/3 of the screen height; close the menu after touch outside; calibrate the behavior --- ...ntext_menu_actions_bottom_sheet_dialog.xml | 2 +- ...ionalActionsBottomSheetDialogFragment.java | 20 ++++++++++++++++--- .../tools/ExtendedBottomSheetBehavior.java | 10 ++-------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/OsmAnd/res/layout/fragment_context_menu_actions_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_context_menu_actions_bottom_sheet_dialog.xml index 1d61901d03..ed3110ecc5 100644 --- a/OsmAnd/res/layout/fragment_context_menu_actions_bottom_sheet_dialog.xml +++ b/OsmAnd/res/layout/fragment_context_menu_actions_bottom_sheet_dialog.xml @@ -7,6 +7,7 @@ android:orientation="vertical"> @@ -17,7 +18,6 @@ android:layout_height="wrap_content" android:background="?attr/bg_color" app:behavior_hideable="true" - app:behavior_peekHeight="300dp" app:layout_behavior="net.osmand.plus.widgets.tools.ExtendedBottomSheetBehavior"> extends CoordinatorLayo top = mParentHeight; targetState = STATE_HIDDEN; } else if (mLastNestedScrollDy == 0) { - int currentTop = child.getTop(); - if (Math.abs(currentTop - mMinOffset) < Math.abs(currentTop - mMaxOffset)) { - top = mMinOffset; - targetState = STATE_EXPANDED; - } else { - top = mMaxOffset; - targetState = STATE_COLLAPSED; - } + top = child.getTop(); + targetState = STATE_MANUALLY_MOVED; } else { if (Math.abs(getYVelocity()) > MIN_VELOCITY_FOR_SLIDE) { top = mMaxOffset; From 1b2c81c7b6145c7b7bade7f9a44b363e7d723f5e Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 5 Jan 2018 20:13:09 +0200 Subject: [PATCH 3/8] Change additional options menu from linear mode to grid mode --- ...ntext_menu_actions_bottom_sheet_dialog.xml | 12 +++-- OsmAnd/res/layout/grid_menu_item.xml | 36 +++++++++++++ OsmAnd/res/layout/grid_menu_row.xml | 33 ++++++++++++ OsmAnd/res/values/colors.xml | 2 + ...ionalActionsBottomSheetDialogFragment.java | 54 ++++++++++++++----- 5 files changed, 120 insertions(+), 17 deletions(-) create mode 100644 OsmAnd/res/layout/grid_menu_item.xml create mode 100644 OsmAnd/res/layout/grid_menu_row.xml diff --git a/OsmAnd/res/layout/fragment_context_menu_actions_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_context_menu_actions_bottom_sheet_dialog.xml index ed3110ecc5..5aeecc6553 100644 --- a/OsmAnd/res/layout/fragment_context_menu_actions_bottom_sheet_dialog.xml +++ b/OsmAnd/res/layout/fragment_context_menu_actions_bottom_sheet_dialog.xml @@ -2,6 +2,7 @@ @@ -16,9 +17,9 @@ android:id="@+id/bottom_sheet_scroll_view" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="?attr/bg_color" app:behavior_hideable="true" - app:layout_behavior="net.osmand.plus.widgets.tools.ExtendedBottomSheetBehavior"> + app:layout_behavior="net.osmand.plus.widgets.tools.ExtendedBottomSheetBehavior" + tools:background="?attr/bg_color"> + android:orientation="vertical" + tools:background="?attr/bg_color"> + tools:background="?attr/dashboard_divider"/> + + + + + + + diff --git a/OsmAnd/res/layout/grid_menu_row.xml b/OsmAnd/res/layout/grid_menu_row.xml new file mode 100644 index 0000000000..5bbaf1434f --- /dev/null +++ b/OsmAnd/res/layout/grid_menu_row.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + diff --git a/OsmAnd/res/values/colors.xml b/OsmAnd/res/values/colors.xml index dd9eae0d60..4231a9b5de 100644 --- a/OsmAnd/res/values/colors.xml +++ b/OsmAnd/res/values/colors.xml @@ -371,4 +371,6 @@ #d28521 #727272 + #808080 + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/AdditionalActionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/AdditionalActionsBottomSheetDialogFragment.java index fea48c70e5..22eda3c868 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/AdditionalActionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/AdditionalActionsBottomSheetDialogFragment.java @@ -13,6 +13,7 @@ import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; +import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; @@ -42,16 +43,25 @@ public class AdditionalActionsBottomSheetDialogFragment extends net.osmand.plus. @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + Activity activity = getActivity(); nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls(); - portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); + portrait = AndroidUiHelper.isOrientationPortrait(activity); final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_context_menu_actions_bottom_sheet_dialog, null); + View scrollView = mainView.findViewById(R.id.bottom_sheet_scroll_view); // AndroidUtils.setBackground(getActivity(), mainView, nightMode, // portrait ? R.drawable.bg_bottom_menu_light : R.drawable.bg_bottom_sheet_topsides_landscape_light, // portrait ? R.drawable.bg_bottom_menu_dark : R.drawable.bg_bottom_sheet_topsides_landscape_dark); + AndroidUtils.setBackground(activity, scrollView, nightMode, + R.color.route_info_bottom_view_bg_light, R.color.route_info_bg_dark); + AndroidUtils.setBackground(activity, mainView.findViewById(R.id.cancel_row), nightMode, + R.color.route_info_bottom_view_bg_light, R.color.route_info_bg_dark); + AndroidUtils.setBackground(activity, mainView.findViewById(R.id.divider), nightMode, + R.color.route_info_divider_light, R.color.route_info_bottom_view_bg_dark); + View.OnClickListener dismissOnClickListener = new View.OnClickListener() { @Override public void onClick(View view) { @@ -64,7 +74,7 @@ public class AdditionalActionsBottomSheetDialogFragment extends net.osmand.plus. TextView headerTitle = (TextView) mainView.findViewById(R.id.header_title); if (nightMode) { - headerTitle.setTextColor(ContextCompat.getColor(getActivity(), R.color.ctx_menu_info_text_dark)); + headerTitle.setTextColor(ContextCompat.getColor(activity, R.color.ctx_menu_info_text_dark)); } headerTitle.setText(R.string.additional_actions); @@ -79,23 +89,34 @@ public class AdditionalActionsBottomSheetDialogFragment extends net.osmand.plus. }; LinearLayout itemsLinearLayout = (LinearLayout) mainView.findViewById(R.id.context_menu_items_container); + LinearLayout row = (LinearLayout) View.inflate(getContext(), R.layout.grid_menu_row, null); + int itemsAdded = 0; for (int i = 0; i < adapter.length(); i++) { ContextMenuItem item = adapter.getItem(i); int layoutResId = item.getLayout(); - layoutResId = layoutResId != ContextMenuItem.INVALID_ID ? layoutResId : R.layout.bottom_sheet_dialog_fragment_item; - View row = View.inflate(new ContextThemeWrapper(getContext(), themeRes), layoutResId, null); - if (layoutResId != R.layout.bottom_sheet_dialog_fragment_divider) { + layoutResId = layoutResId == ContextMenuItem.INVALID_ID ? R.layout.grid_menu_item : layoutResId; + boolean dividerItem = layoutResId == R.layout.bottom_sheet_dialog_fragment_divider; + + if (!dividerItem) { + View menuItem = View.inflate(new ContextThemeWrapper(getContext(), themeRes), layoutResId, null); if (item.getIcon() != ContextMenuItem.INVALID_ID) { - ((ImageView) row.findViewById(R.id.icon)).setImageDrawable(getContentIcon(item.getIcon())); + ((ImageView) menuItem.findViewById(R.id.icon)).setImageDrawable(getContentIcon(item.getIcon())); } - ((TextView) row.findViewById(R.id.title)).setText(item.getTitle()); + ((TextView) menuItem.findViewById(R.id.title)).setText(item.getTitle()); + menuItem.setTag(i); + menuItem.setOnClickListener(onClickListener); + ((FrameLayout) row.findViewById(getMenuItemContainerId(itemsAdded))).addView(menuItem); + itemsAdded++; + } + + if (dividerItem || itemsAdded == 3 || (i == adapter.length() - 1 && itemsAdded > 0)) { + itemsLinearLayout.addView(row); + row = (LinearLayout) View.inflate(getContext(), R.layout.grid_menu_row, null); + itemsAdded = 0; } - row.setTag(i); - row.setOnClickListener(onClickListener); - itemsLinearLayout.addView(row); } - ExtendedBottomSheetBehavior behavior = ExtendedBottomSheetBehavior.from(mainView.findViewById(R.id.bottom_sheet_scroll_view)); + ExtendedBottomSheetBehavior behavior = ExtendedBottomSheetBehavior.from(scrollView); behavior.setPeekHeight(getPeekHeight()); behavior.setBottomSheetCallback(new BottomSheetCallback() { @Override @@ -127,7 +148,16 @@ public class AdditionalActionsBottomSheetDialogFragment extends net.osmand.plus. @Override protected Drawable getContentIcon(@DrawableRes int id) { - return getMyApplication().getIconsCache().getIcon(id, nightMode ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color); + return getMyApplication().getIconsCache().getIcon(id, nightMode ? R.color.grid_menu_icon_dark : R.color.on_map_icon_color); + } + + private int getMenuItemContainerId(int itemsAdded) { + if (itemsAdded == 0) { + return R.id.first_item_container; + } else if (itemsAdded == 1) { + return R.id.second_item_container; + } + return R.id.third_item_container; } private int getPeekHeight() { From 871adc8cc6fa99f5e15527e2ba4b9851565ff478 Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 5 Jan 2018 20:17:07 +0200 Subject: [PATCH 4/8] Remove "Additional actions" title --- ...t_context_menu_actions_bottom_sheet_dialog.xml | 15 +++------------ ...dditionalActionsBottomSheetDialogFragment.java | 7 ------- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/OsmAnd/res/layout/fragment_context_menu_actions_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_context_menu_actions_bottom_sheet_dialog.xml index 5aeecc6553..d4f1f35d9c 100644 --- a/OsmAnd/res/layout/fragment_context_menu_actions_bottom_sheet_dialog.xml +++ b/OsmAnd/res/layout/fragment_context_menu_actions_bottom_sheet_dialog.xml @@ -22,20 +22,11 @@ tools:background="?attr/bg_color"> - - - - - - + android:orientation="vertical" + android:paddingBottom="@dimen/bottom_sheet_content_padding_small"/> diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/AdditionalActionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/AdditionalActionsBottomSheetDialogFragment.java index 22eda3c868..2ae057f831 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/AdditionalActionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/AdditionalActionsBottomSheetDialogFragment.java @@ -6,7 +6,6 @@ import android.os.Bundle; import android.support.annotation.DrawableRes; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.support.v4.content.ContextCompat; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; @@ -72,12 +71,6 @@ public class AdditionalActionsBottomSheetDialogFragment extends net.osmand.plus. mainView.findViewById(R.id.cancel_row).setOnClickListener(dismissOnClickListener); mainView.findViewById(R.id.scroll_view_container).setOnClickListener(dismissOnClickListener); - TextView headerTitle = (TextView) mainView.findViewById(R.id.header_title); - if (nightMode) { - headerTitle.setTextColor(ContextCompat.getColor(activity, R.color.ctx_menu_info_text_dark)); - } - headerTitle.setText(R.string.additional_actions); - View.OnClickListener onClickListener = new View.OnClickListener() { @Override public void onClick(View view) { From 095e4512a06e9ed1b161bd70f831c257ad31762b Mon Sep 17 00:00:00 2001 From: alex Date: Wed, 10 Jan 2018 15:32:18 +0200 Subject: [PATCH 5/8] Extract sizes from layouts to resources --- OsmAnd/res/layout/grid_menu_item.xml | 14 +++++++------- OsmAnd/res/layout/grid_menu_row.xml | 8 ++++---- OsmAnd/res/values-large/sizes.xml | 3 +++ OsmAnd/res/values/sizes.xml | 4 ++++ 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/OsmAnd/res/layout/grid_menu_item.xml b/OsmAnd/res/layout/grid_menu_item.xml index 925b4dd888..db4cd1a2df 100644 --- a/OsmAnd/res/layout/grid_menu_item.xml +++ b/OsmAnd/res/layout/grid_menu_item.xml @@ -2,12 +2,12 @@ @@ -15,10 +15,10 @@ android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginBottom="16dp" - android:layout_marginLeft="40dp" - android:layout_marginRight="40dp" - android:layout_marginTop="16dp" + android:layout_marginBottom="@dimen/grid_menu_item_bottom_top_margin" + android:layout_marginLeft="@dimen/grid_menu_item_sides_margin" + android:layout_marginRight="@dimen/grid_menu_item_sides_margin" + android:layout_marginTop="@dimen/grid_menu_item_bottom_top_margin" tools:src="@drawable/ic_action_delete_dark" tools:tint="#808080"/> diff --git a/OsmAnd/res/layout/grid_menu_row.xml b/OsmAnd/res/layout/grid_menu_row.xml index 5bbaf1434f..dbfcdd1d89 100644 --- a/OsmAnd/res/layout/grid_menu_row.xml +++ b/OsmAnd/res/layout/grid_menu_row.xml @@ -3,11 +3,11 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" - android:paddingTop="8dp"> + android:paddingTop="@dimen/bottom_sheet_content_padding_small"> diff --git a/OsmAnd/res/values-large/sizes.xml b/OsmAnd/res/values-large/sizes.xml index d321306578..f3f258f86b 100644 --- a/OsmAnd/res/values-large/sizes.xml +++ b/OsmAnd/res/values-large/sizes.xml @@ -175,4 +175,7 @@ 78dp + 180dp + 24dp + 60dp \ No newline at end of file diff --git a/OsmAnd/res/values/sizes.xml b/OsmAnd/res/values/sizes.xml index 8f73163ed6..356ac895fc 100644 --- a/OsmAnd/res/values/sizes.xml +++ b/OsmAnd/res/values/sizes.xml @@ -247,4 +247,8 @@ 48dp 52dp + + 120dp + 16dp + 40dp \ No newline at end of file From 6db032aa71bf7c9930b7619c77b35206d5303f53 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Thu, 11 Jan 2018 17:05:57 +0200 Subject: [PATCH 6/8] Add shadows to additional options menu --- .../res/drawable/bg_additional_menu_dark.xml | 11 ++++ .../res/drawable/bg_additional_menu_light.xml | 11 ++++ .../bg_additional_menu_sides_dark.xml | 11 ++++ .../bg_additional_menu_sides_light.xml | 11 ++++ .../bg_additional_menu_topsides_dark.xml | 11 ++++ .../bg_additional_menu_topsides_light.xml | 11 ++++ ...ntext_menu_actions_bottom_sheet_dialog.xml | 1 + ...ionalActionsBottomSheetDialogFragment.java | 56 +++++++++++++++---- 8 files changed, 111 insertions(+), 12 deletions(-) create mode 100644 OsmAnd/res/drawable/bg_additional_menu_dark.xml create mode 100644 OsmAnd/res/drawable/bg_additional_menu_light.xml create mode 100644 OsmAnd/res/drawable/bg_additional_menu_sides_dark.xml create mode 100644 OsmAnd/res/drawable/bg_additional_menu_sides_light.xml create mode 100644 OsmAnd/res/drawable/bg_additional_menu_topsides_dark.xml create mode 100644 OsmAnd/res/drawable/bg_additional_menu_topsides_light.xml diff --git a/OsmAnd/res/drawable/bg_additional_menu_dark.xml b/OsmAnd/res/drawable/bg_additional_menu_dark.xml new file mode 100644 index 0000000000..66bd980889 --- /dev/null +++ b/OsmAnd/res/drawable/bg_additional_menu_dark.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/bg_additional_menu_light.xml b/OsmAnd/res/drawable/bg_additional_menu_light.xml new file mode 100644 index 0000000000..3dbefb481c --- /dev/null +++ b/OsmAnd/res/drawable/bg_additional_menu_light.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/bg_additional_menu_sides_dark.xml b/OsmAnd/res/drawable/bg_additional_menu_sides_dark.xml new file mode 100644 index 0000000000..c711c6f92c --- /dev/null +++ b/OsmAnd/res/drawable/bg_additional_menu_sides_dark.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/bg_additional_menu_sides_light.xml b/OsmAnd/res/drawable/bg_additional_menu_sides_light.xml new file mode 100644 index 0000000000..328d6a9d0a --- /dev/null +++ b/OsmAnd/res/drawable/bg_additional_menu_sides_light.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/bg_additional_menu_topsides_dark.xml b/OsmAnd/res/drawable/bg_additional_menu_topsides_dark.xml new file mode 100644 index 0000000000..82ce02c79b --- /dev/null +++ b/OsmAnd/res/drawable/bg_additional_menu_topsides_dark.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/bg_additional_menu_topsides_light.xml b/OsmAnd/res/drawable/bg_additional_menu_topsides_light.xml new file mode 100644 index 0000000000..a3402d8835 --- /dev/null +++ b/OsmAnd/res/drawable/bg_additional_menu_topsides_light.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/fragment_context_menu_actions_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_context_menu_actions_bottom_sheet_dialog.xml index d4f1f35d9c..8010bc503b 100644 --- a/OsmAnd/res/layout/fragment_context_menu_actions_bottom_sheet_dialog.xml +++ b/OsmAnd/res/layout/fragment_context_menu_actions_bottom_sheet_dialog.xml @@ -33,6 +33,7 @@ Date: Thu, 11 Jan 2018 17:15:13 +0200 Subject: [PATCH 7/8] Cache a frequently calculated value --- ...ionalActionsBottomSheetDialogFragment.java | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/AdditionalActionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/AdditionalActionsBottomSheetDialogFragment.java index b0600adf67..4af9abc7c7 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/AdditionalActionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/AdditionalActionsBottomSheetDialogFragment.java @@ -31,11 +31,11 @@ public class AdditionalActionsBottomSheetDialogFragment extends net.osmand.plus. private boolean nightMode; private boolean portrait; + private int availableScreenH; private ContextMenuAdapter adapter; private ContextMenuItemClickListener listener; - private View mainView; private View scrollView; private View cancelRowBgView; @@ -51,8 +51,12 @@ public class AdditionalActionsBottomSheetDialogFragment extends net.osmand.plus. nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls(); portrait = AndroidUiHelper.isOrientationPortrait(activity); final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; + availableScreenH = AndroidUtils.getScreenHeight(activity) - AndroidUtils.getStatusBarHeight(activity); + if (portrait) { + availableScreenH -= AndroidUtils.getNavBarHeight(activity); + } - mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_context_menu_actions_bottom_sheet_dialog, null); + View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_context_menu_actions_bottom_sheet_dialog, null); scrollView = mainView.findViewById(R.id.bottom_sheet_scroll_view); cancelRowBgView = mainView.findViewById(R.id.cancel_row_background); @@ -154,12 +158,7 @@ public class AdditionalActionsBottomSheetDialogFragment extends net.osmand.plus. } private boolean expandedToFullScreen() { - Activity ctx = getActivity(); - int availableH = AndroidUtils.getScreenHeight(ctx) - AndroidUtils.getStatusBarHeight(ctx); - if (portrait) { - availableH -= AndroidUtils.getNavBarHeight(ctx); - } - return availableH - scrollView.getHeight() - cancelRowBgView.getHeight() <= 0; + return availableScreenH - scrollView.getHeight() - cancelRowBgView.getHeight() <= 0; } private void updateBackground(boolean expanded) { @@ -186,10 +185,7 @@ public class AdditionalActionsBottomSheetDialogFragment extends net.osmand.plus. } private int getPeekHeight() { - Activity ctx = getActivity(); - int screenH = AndroidUtils.getScreenHeight(ctx); - int availableH = screenH - AndroidUtils.getNavBarHeight(ctx) - AndroidUtils.getStatusBarHeight(ctx); - return (availableH * 2 / 3) - getResources().getDimensionPixelSize(R.dimen.bottom_sheet_cancel_button_height); + return (availableScreenH * 2 / 3) - getResources().getDimensionPixelSize(R.dimen.bottom_sheet_cancel_button_height); } public interface ContextMenuItemClickListener { From b654b3ee7529109a4c49bbe12c22e684a961ed0c Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Thu, 11 Jan 2018 17:59:41 +0200 Subject: [PATCH 8/8] Refactor code --- .../plus/mapcontextmenu/MenuController.java | 45 +++++++++---------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java index c1a6d78328..7e23482be0 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java @@ -3,8 +3,8 @@ package net.osmand.plus.mapcontextmenu; import android.graphics.drawable.Drawable; import android.os.AsyncTask; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; -import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.LinearLayout; @@ -52,7 +52,6 @@ import net.osmand.plus.mapcontextmenu.controllers.RenderedObjectMenuController; import net.osmand.plus.mapcontextmenu.controllers.TargetPointMenuController; import net.osmand.plus.mapcontextmenu.controllers.TransportRouteController; import net.osmand.plus.mapcontextmenu.controllers.TransportStopController; -import net.osmand.plus.transport.TransportStopRoute; import net.osmand.plus.mapcontextmenu.controllers.WptPtMenuController; import net.osmand.plus.mapcontextmenu.other.ShareMenu; import net.osmand.plus.mapillary.MapillaryImage; @@ -65,6 +64,7 @@ import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoDevice; import net.osmand.plus.osmo.OsMoMenuController; import net.osmand.plus.parkingpoint.ParkingPositionMenuController; import net.osmand.plus.resources.ResourceManager; +import net.osmand.plus.transport.TransportStopRoute; import net.osmand.plus.views.DownloadedRegionsLayer.DownloadMapObject; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControllerType; @@ -554,42 +554,37 @@ public abstract class MenuController extends BaseMenuController { public Drawable rightIcon; public boolean enabled = true; + @Nullable public Drawable getLeftIcon() { - if (leftIcon != null) { - return leftIcon; - } - if (leftIconId != 0) { - if (needColorizeIcon) { - return getIcon(leftIconId, getColorRes()); - } - return ContextCompat.getDrawable(getMapActivity(), leftIconId); - } else { - return null; - } + return getIconDrawable(true); } + @Nullable public Drawable getRightIcon() { - if (rightIcon != null) { - return rightIcon; + return getIconDrawable(false); + } + + @Nullable + private Drawable getIconDrawable(boolean left) { + Drawable drawable = left ? leftIcon : rightIcon; + if (drawable != null) { + return drawable; } - if (rightIconId != 0) { + int resId = left ? leftIconId : rightIconId; + if (resId != 0) { if (needColorizeIcon) { - return getIcon(rightIconId, getColorRes()); + return getIcon(resId, getColorRes()); } - return ContextCompat.getDrawable(getMapActivity(), rightIconId); - } else { - return null; + return ContextCompat.getDrawable(getMapActivity(), resId); } + return null; } private int getColorRes() { - int colorRes; if (enabled) { - colorRes = isLight() ? R.color.map_widget_blue : R.color.osmand_orange; - } else { - colorRes = isLight() ? R.color.ctx_menu_controller_disabled_text_color_light : R.color.ctx_menu_controller_disabled_text_color_dark; + return isLight() ? R.color.map_widget_blue : R.color.osmand_orange; } - return colorRes; + return isLight() ? R.color.ctx_menu_controller_disabled_text_color_light : R.color.ctx_menu_controller_disabled_text_color_dark; } public abstract void buttonPressed();