diff --git a/OsmAnd/res/layout-land/menu_obj_selection_fragment.xml b/OsmAnd/res/layout-land/menu_obj_selection_fragment.xml index 5102244cbd..0b54849f1c 100644 --- a/OsmAnd/res/layout-land/menu_obj_selection_fragment.xml +++ b/OsmAnd/res/layout-land/menu_obj_selection_fragment.xml @@ -15,7 +15,7 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - - + android:foreground="?attr/selectableItemBackground"> = 21) { AndroidUtils.addStatusBarPadding21v(getActivity(), listView); } - View headerView = inflater.inflate(R.layout.menu_obj_selection_header, listView, false); - headerView.setOnClickListener(null); - listView.addHeaderView(headerView); listAdapter = createAdapter(); listAdapter.setListener(this); listView.setAdapter(listAdapter); - runLayoutListener(); + if (!menu.isLandscapeLayout()) { + final Context context = getContext(); + + FrameLayout paddingView = new FrameLayout(context); + paddingView.setLayoutParams(new AbsListView.LayoutParams( + AbsListView.LayoutParams.MATCH_PARENT, getPaddingViewHeight()) + ); + paddingView.setClickable(true); + paddingView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + dismissMenu(); + } + }); + + FrameLayout shadowContainer = new FrameLayout(context); + shadowContainer.setLayoutParams(new FrameLayout.LayoutParams( + FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT, Gravity.BOTTOM + )); + + ImageView shadow = new ImageView(context); + shadow.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.bg_shadow_onmap)); + shadow.setLayoutParams(new FrameLayout.LayoutParams( + FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.BOTTOM + )); + shadow.setScaleType(ImageView.ScaleType.FIT_XY); + + shadowContainer.addView(shadow); + paddingView.addView(shadowContainer); + listView.addHeaderView(paddingView); + + view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + float titleHeight = getResources().getDimension(R.dimen.multi_selection_header_height); + int maxHeight = (int) (titleHeight); + for (int i = 0; i < 3 && i < listAdapter.getCount(); i++) { + View childView = listAdapter.getView(0, null, (ListView) view.findViewById(R.id.list)); + childView.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), + View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); + maxHeight += childView.getMeasuredHeight(); + } + + listView.setSelectionFromTop(0, -maxHeight); + + ViewTreeObserver obs = view.getViewTreeObserver(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + obs.removeOnGlobalLayoutListener(this); + } else { + obs.removeGlobalOnLayoutListener(this); + } + } + }); + + ((ObservableListView) listView).setScrollViewCallbacks(new ObservableScrollViewCallbacks() { + + boolean initialScroll = true; + int minHeight = getResources().getDimensionPixelSize(R.dimen.multi_selection_header_height) + + getResources().getDimensionPixelSize(R.dimen.list_item_height); + + @Override + public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) { + if (scrollY <= minHeight && !initialScroll) { + dismissMenu(); + } + } + + @Override + public void onDownMotionEvent() { + initialScroll = false; + } + + @Override + public void onUpOrCancelMotionEvent(ScrollState scrollState) { + + } + }); + } + + View headerView = inflater.inflate(R.layout.menu_obj_selection_header, listView, false); + if (!menu.isLandscapeLayout()) { + AndroidUtils.setBackground(getContext(), headerView, !menu.isLight(), R.color.ctx_menu_bg_light, R.color.ctx_menu_bg_dark); + } + headerView.setOnClickListener(null); + listView.addHeaderView(headerView); view.findViewById(R.id.divider).setBackgroundColor(ContextCompat.getColor(getContext(), menu.isLight() ? R.color.multi_selection_menu_divider_light : R.color.multi_selection_menu_divider_dark)); @@ -111,6 +202,12 @@ public class MapMultiSelectionMenuFragment extends Fragment implements MultiSele menu.getMapActivity().getMapLayers().getMapControlsLayer().setControlsClickable(true); } + private int getPaddingViewHeight() { + Activity activity = getActivity(); + return AndroidUtils.getScreenHeight(activity) + - activity.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_cancel_button_height); + } + public static void showInstance(final MapActivity mapActivity) { if (mapActivity.isActivityDestroyed()) { @@ -137,45 +234,6 @@ public class MapMultiSelectionMenuFragment extends Fragment implements MultiSele .addToBackStack(TAG).commitAllowingStateLoss(); } - private void runLayoutListener() { - ViewTreeObserver vto = view.getViewTreeObserver(); - vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { - - @Override - public void onGlobalLayout() { - - if (!menu.isLandscapeLayout() && listAdapter.getCount() > 3) { - View contentView = view.findViewById(R.id.content); - float headerHeight = contentView.getResources().getDimension(R.dimen.multi_selection_header_height); - float cancelRowHeight = contentView.getResources().getDimension(R.dimen.bottom_sheet_cancel_button_height); - int maxHeight = (int) (headerHeight + cancelRowHeight); - for (int i = 0; i < 3; i++) { - View childView = listAdapter.getView(0, null, (ListView) contentView.findViewById(R.id.list)); - childView.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), - View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); - maxHeight += childView.getMeasuredHeight(); - } - int height = contentView.getHeight(); - - if (height > maxHeight) { - ViewGroup.LayoutParams lp = contentView.getLayoutParams(); - lp.height = maxHeight; - contentView.setLayoutParams(lp); - contentView.requestLayout(); - } - } - - ViewTreeObserver obs = view.getViewTreeObserver(); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { - obs.removeOnGlobalLayoutListener(this); - } else { - obs.removeGlobalOnLayoutListener(this); - } - } - }); - } - private MultiSelectionArrayAdapter createAdapter() { final List items = new LinkedList<>(menu.getObjects()); return new MultiSelectionArrayAdapter(menu, R.layout.menu_obj_list_item, items); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MultiSelectionArrayAdapter.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MultiSelectionArrayAdapter.java index c98342c0e2..d714caf0e2 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MultiSelectionArrayAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MultiSelectionArrayAdapter.java @@ -38,6 +38,10 @@ public class MultiSelectionArrayAdapter extends ArrayAdapter