By: Lukasz Paczos
We just enhanced gesture detection for the Maps SDK for Android. We’ve expanded the core Android SDK to allow more nuanced map interactions like rotation, shoving, two-finger taps, and more. Test out these new gestures in the mapbox-gestures-android repo. The library is open source, and releases are published to Maven Central so they’re available for every Android developer.
What’s different
The old implementation exposed a couple of gesture detectors, totally independent from each other, which required tons of if-checks and hardcoded cases to behave as the map user expects.
mapbox-gestures-android library still wraps GestureDetectorCompat and ScaleGestureDetector exposed by the Android SDK. It keeps the general idea of gesture detectors but couples them together in the AndroidGesturesManager object.
Because detector are kept in the same bucket, they can talk to each other, providing:
- Mutual interaction
- Filtering
- Thresholds
- Velocity support
Seeing it in action
Let’s imagine we want to tilt the map.
Something’s off here, we shouldn’t be able to scale the map while shoving. All we have to do is filter those gestures out:
How about zooming in and out?
No, no, no… it’s all jiggly and chaotic! Let’s set a rotation threshold:
androidGesturesManager.getRotateGestureDetector().setAngleThreshold(15f);
Last but not least, immersion. Every gesture detector performs velocity computations delivered with end-of-gesture callbacks that we can use to animate the map beyond the gesture execution.
The Maps SDK for Android exposes callbacks that fire whenever a gesture is detected. It includes default thresholds setters and much more, letting you tailor gestures to fit your users’ needs.
The LocationLayerPlugin is another great example. Thanks to a clever use of thresholds and gestures interceptions, you can scale the map without resetting the tracking settings. Find the complete implementation details here.
Add the new gestures to your app
We just released the 6.0.1 version of the Maps SDK for Android which includes the revamped gestures experience. You can get started with our gestures for maps guide.
Visit the mapbox-gestures-android repo where you’ll find documentation and examples on how to include the library in your app.
Revamping gestures for Android maps was originally published in Points of interest on Medium, where people are continuing the conversation by highlighting and responding to this story.