Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog for the Mapbox Gestures for Android

## 0.9.2 - September 29, 2025
* Fix concurrent modification exception for detectors

## 0.9.1 - November 27, 2023
Minor release with internal fixes for publishing library

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;

/**
* Entry point for all of the detectors. Set listener for gestures you'd like to be notified about
Expand Down Expand Up @@ -58,7 +59,7 @@ public class AndroidGesturesManager {
public static final int GESTURE_TYPE_QUICK_SCALE = 15;

private final List<Set<Integer>> mutuallyExclusiveGestures = new ArrayList<>();
private final List<BaseGesture> detectors = new ArrayList<>();
private final List<BaseGesture> detectors;

private final StandardGestureDetector standardGestureDetector;
private final StandardScaleGestureDetector standardScaleGestureDetector;
Expand Down Expand Up @@ -128,13 +129,15 @@ public AndroidGesturesManager(Context context, List<Set<Integer>> exclusiveGestu
moveGestureDetector = new MoveGestureDetector(context, this);
standardGestureDetector = new StandardGestureDetector(context, this);

detectors.add(rotateGestureDetector);
detectors.add(standardScaleGestureDetector);
detectors.add(shoveGestureDetector);
detectors.add(sidewaysShoveGestureDetector);
detectors.add(multiFingerTapGestureDetector);
detectors.add(moveGestureDetector);
detectors.add(standardGestureDetector);
detectors = new CopyOnWriteArrayList<BaseGesture>(Arrays.asList(
rotateGestureDetector,
standardScaleGestureDetector,
shoveGestureDetector,
sidewaysShoveGestureDetector,
multiFingerTapGestureDetector,
moveGestureDetector,
standardGestureDetector
));

if (applyDefaultThresholds) {
initDefaultThresholds();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.mapbox.android.gestures;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import android.view.MotionEvent;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -11,9 +17,6 @@
import java.util.List;
import java.util.Set;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;

@RunWith(RobolectricTestRunner.class)
public class AndroidGesturesManagerTest {
private AndroidGesturesManager androidGesturesManager;
Expand Down Expand Up @@ -44,9 +47,9 @@ public void setUp() throws Exception {
mutuallyExclusivesList.add(set3);

androidGesturesManager =
new AndroidGesturesManager(
RuntimeEnvironment.application.getApplicationContext(),
mutuallyExclusivesList, true);
new AndroidGesturesManager(
RuntimeEnvironment.application.getApplicationContext(),
mutuallyExclusivesList, true);
}

@Test
Expand All @@ -69,4 +72,21 @@ public void setMutuallyExclusivesTest() throws Exception {
androidGesturesManager.setMutuallyExclusiveGestures(mutuallyExclusivesList);
assertEquals(androidGesturesManager.getMutuallyExclusiveGestures(), mutuallyExclusivesList);
}

@Test
public void onSingleTapModifyDetectorsTest() {
final StandardGestureDetector standardGestureDetector = new StandardGestureDetector(RuntimeEnvironment.getApplication().getApplicationContext(), androidGesturesManager);

androidGesturesManager.setStandardGestureListener(new StandardGestureDetector.SimpleStandardOnGestureListener() {
@Override
public boolean onDown(MotionEvent e) {
androidGesturesManager.getDetectors().add(standardGestureDetector);
return true;
}
});

MotionEvent downEvent = TestUtils.INSTANCE.getMotionEvent(MotionEvent.ACTION_DOWN, 0, 0, null);
androidGesturesManager.onTouchEvent(downEvent);
assertTrue(androidGesturesManager.getDetectors().contains(standardGestureDetector));
}
}