From eaf9e83701f00fa92a49ba10bf1e32b0946880c6 Mon Sep 17 00:00:00 2001 From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com> Date: Sun, 28 Mar 2021 20:49:30 +0300 Subject: [PATCH] init --- .../editors/PointEditorFragmentNew.java | 33 ++++++++---- .../other/OnSwipeTouchListener.java | 50 +++++++++++++++++++ 2 files changed, 74 insertions(+), 9 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/mapcontextmenu/other/OnSwipeTouchListener.java diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java index b8fb261f09..ec3ac88b68 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java @@ -54,6 +54,7 @@ import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.ColorDialogs; import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter; +import net.osmand.plus.mapcontextmenu.other.OnSwipeTouchListener; import net.osmand.plus.routepreparationmenu.cards.BaseCard; import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener; import net.osmand.plus.track.ColorsCard; @@ -134,6 +135,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen .inflate(R.layout.point_editor_fragment_new, container, false); AndroidUtils.addStatusBarPadding21v(getActivity(), view); + final PointEditor editor = getEditor(); if (editor == null) { return view; @@ -176,6 +178,13 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen } }); + scrollView.setOnTouchListener(new OnSwipeTouchListener(getContext()) { + @Override + public void onSwipeLeft() { + showExitDialog(); + } + }); + final int activeColorResId = getActiveColorRes(); ImageView toolbarAction = view.findViewById(R.id.toolbar_action); view.findViewById(R.id.background_layout).setBackgroundResource(nightMode @@ -371,14 +380,14 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen createShapeSelector(); updateColorSelector(selectedColor, view); updateShapeSelector(selectedShape, view); - scrollView.setOnTouchListener(new View.OnTouchListener() { - - @Override - public boolean onTouch(View v, MotionEvent event) { - descriptionEdit.getParent().requestDisallowInterceptTouchEvent(false); - return false; - } - }); +// scrollView.setOnTouchListener(new View.OnTouchListener() { +// +// @Override +// public boolean onTouch(View v, MotionEvent event) { +// descriptionEdit.getParent().requestDisallowInterceptTouchEvent(false); +// return false; +// } +// }); descriptionEdit.setOnTouchListener(new View.OnTouchListener() { @@ -646,13 +655,19 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen iconCategoriesRecyclerView.setAdapter(horizontalSelectionAdapter); iconCategoriesRecyclerView.setLayoutManager(new LinearLayoutManager(app, RecyclerView.HORIZONTAL, false)); horizontalSelectionAdapter.notifyDataSetChanged(); - iconCategoriesRecyclerView.smoothScrollToPosition(horizontalSelectionAdapter.getItemPositionByTitle(selectedIconCategory)); + iconCategoriesRecyclerView.scrollToPosition(horizontalSelectionAdapter.getItemPositionByTitle(selectedIconCategory)); for (String name : iconNameList) { int minimalPaddingBetweenIcon = app.getResources().getDimensionPixelSize(R.dimen.favorites_select_icon_button_right_padding); selectIcon.addView(createIconItemView(name, selectIcon), new FlowLayout.LayoutParams(minimalPaddingBetweenIcon, 0)); selectIcon.setHorizontalAutoSpacing(true); } } + selectIcon.setOnTouchListener(new OnSwipeTouchListener(getContext()) { + @Override + public void onSwipeLeft() { + showExitDialog(); + } + }); } private View createIconItemView(final String iconName, final ViewGroup rootView) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/OnSwipeTouchListener.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/OnSwipeTouchListener.java new file mode 100644 index 0000000000..e072184325 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/OnSwipeTouchListener.java @@ -0,0 +1,50 @@ +package net.osmand.plus.mapcontextmenu.other; + +import android.content.Context; +import android.view.GestureDetector; +import android.view.MotionEvent; +import android.view.View; + +public class OnSwipeTouchListener implements View.OnTouchListener { + + private final GestureDetector gestureDetector; + + public OnSwipeTouchListener(Context context) { + gestureDetector = new GestureDetector(context, new GestureListener()); + } + + public void onSwipeLeft() { + } + + public void onSwipeRight() { + } + + public boolean onTouch(View v, MotionEvent event) { + return gestureDetector.onTouchEvent(event); + } + + private final class GestureListener extends GestureDetector.SimpleOnGestureListener { + + private static final int SWIPE_DISTANCE_THRESHOLD = 100; + private static final int SWIPE_VELOCITY_THRESHOLD = 100; + + @Override + public boolean onDown(MotionEvent e) { + return true; + } + + @Override + public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { + float distanceX = e2.getX() - e1.getX(); + float distanceY = e2.getY() - e1.getY(); + if (Math.abs(distanceX) > Math.abs(distanceY) && Math.abs(distanceX) > SWIPE_DISTANCE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) { + if (distanceX > 0) + onSwipeRight(); + else + onSwipeLeft(); + return true; + } + return false; + } + } +}