How to override TouchGestureHandler.onScaleEnd

173 views
Skip to first unread message

hawalter

unread,
Jul 14, 2017, 1:31:38 PM7/14/17
to mapsforge-dev
I need to add an action when onScaleEnd is triggered but still allow the normal onScaleEnd actions to occur. Have tried multiple ways to implement it but nothing works and there are no TouchGestureHandler examples (that I could find). Could you please give a code snippet? Thanks!

Emux

unread,
Jul 14, 2017, 1:57:15 PM7/14/17
to mapsfo...@googlegroups.com, hawalter
You mean in Mapsforge?

I don't think we have events fired from gestures API inside the library.
Though we could add a callback listener or something like that, for users to learn gestures state as they progress.
You can open an issue for that.

Could you play with more high level API, like override MapView.onTouchEvent and add your ScaleGestureDetector to listen for such events first and still allow the internal gesture detector to process them?

--
Emux

hawalter

unread,
Jul 14, 2017, 6:06:08 PM7/14/17
to mapsforge-dev
I obviously don't understand the purpose of mapsforge.map.android.input.TouchGestureHandler.
I was hoping to use it like Android View.OnTouchListener; perhaps something like
mapView.setGestureDetector(new GestureDetector(getContext(), new TouchGestureHandler(mapView) {
            public boolean OnFling(android.view.MotionEvent e1, android.view.MotionEvent e2, float velocityX, float velocityY) {
                //Add my calls here
                return false; // Continue with normal Mapsforge onFling processing
            }

            public void OnScaleEnd(android.view.ScaleGestureDetector detector) {
                //Add my calls here
            }
        }));
This would allow me to add some processing but still keep the normal mapsforge onFling processing.
Is something like this feasible in a future release or is it too off the wall?

hawalter

unread,
Jul 14, 2017, 11:31:38 PM7/14/17
to mapsforge-dev
Actually, I managed to get what I needed without using TouchGestureHandler. For anyone who might need it, the following works

mapView.setOnTouchListener(new View.OnTouchListener() {
            private GestureDetector gestureDetector = new GestureDetector(getContext(),
                    new GestureDetector.SimpleOnGestureListener() {

                        @Override
                        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                            //Log.d(TAG, "MapViewFrag =============== is onFling");
                            //Add call here
                            return false;
                        }
                    });

            private ScaleGestureDetector scaleGestureDetector = new ScaleGestureDetector(getContext(),
                    new ScaleGestureDetector.SimpleOnScaleGestureListener() {

                        @Override
                        public void onScaleEnd(ScaleGestureDetector detector) {
                            //Log.d(TAG, "MapViewFrag =============== is onScaleEnd");
                            //Add call here
                            }
                    });

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                gestureDetector.onTouchEvent(event);
                scaleGestureDetector.onTouchEvent(event);
                return false;
            }
        });

Now if someone could tell me how to get rid of the annoying Lint message "Custom view `MapView` has setOnTouchListener called on it but does not override performClick"?

Emux

unread,
Jul 15, 2017, 2:16:27 AM7/15/17
to mapsfo...@googlegroups.com, hwal...@gmail.com
mapView.setGestureDetector allows adding an external GestureDetector (see here its call inside MapView) which allows interfering the default one.

Can be used like:
mapView.setGestureDetector(new GestureDetector(context, new SimpleOnGestureListener() {
...
}));

Mapsforge TouchGestureHandler handles all MapView gestures and is initialized by it.
Having more than one of them processing the same gestures can lead to malfunctions.
It's not a listener with empty method bodies to override, but a full implemented class.

--
Emux
Reply all
Reply to author
Forward
0 new messages