Skip to content

Commit 5caff41

Browse files
committed
expose the concurrent camera animations during navigation to android
this makes it so that users of the android integration can choose to have indepedent camera animations run concurrently instead of them waiting on each other or canceling each other.
1 parent 6e87e7d commit 5caff41

File tree

8 files changed

+66
-4
lines changed

8 files changed

+66
-4
lines changed

platform/android/MapLibreAndroid/src/main/java/org/maplibre/android/location/LocationCameraController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ void setEnabled(boolean enabled) {
330330
isEnabled = enabled;
331331
}
332332

333-
private boolean isLocationTracking() {
333+
boolean isLocationTracking() {
334334
return cameraMode == CameraMode.TRACKING
335335
|| cameraMode == CameraMode.TRACKING_COMPASS
336336
|| cameraMode == CameraMode.TRACKING_GPS

platform/android/MapLibreAndroid/src/main/java/org/maplibre/android/location/LocationComponent.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1387,6 +1387,10 @@ private void updateAnimatorListenerHolders() {
13871387
locationAnimatorCoordinator.resetAllLayerAnimations();
13881388
}
13891389

1390+
public boolean isLocationTracking() {
1391+
return locationCameraController.isLocationTracking();
1392+
}
1393+
13901394
@NonNull
13911395
private OnCameraMoveListener onCameraMoveListener = new OnCameraMoveListener() {
13921396
@Override
@@ -1546,7 +1550,7 @@ public void onRenderModeChanged(int currentMode) {
15461550
new MapLibreMap.OnDeveloperAnimationListener() {
15471551
@Override
15481552
public void onDeveloperAnimationStarted() {
1549-
if (isComponentInitialized && isEnabled) {
1553+
if (isComponentInitialized && isEnabled && !options.concurrentCameraAnimationsEnabled()) {
15501554
setCameraMode(CameraMode.NONE);
15511555
}
15521556
}

platform/android/MapLibreAndroid/src/main/java/org/maplibre/android/location/LocationComponentOptions.java

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ public class LocationComponentOptions implements Parcelable {
144144
private float pulseAlpha;
145145
@Nullable
146146
private Interpolator pulseInterpolator;
147+
private Boolean concurrentCameraAnimationsEnabled;
147148

148149
public LocationComponentOptions(
149150
float accuracyAlpha,
@@ -186,7 +187,8 @@ public LocationComponentOptions(
186187
float pulseSingleDuration,
187188
float pulseMaxRadius,
188189
float pulseAlpha,
189-
@Nullable Interpolator pulseInterpolator) {
190+
@Nullable Interpolator pulseInterpolator,
191+
Boolean concurrentCameraAnimationsEnabled) {
190192
this.accuracyAlpha = accuracyAlpha;
191193
this.accuracyColor = accuracyColor;
192194
this.backgroundDrawableStale = backgroundDrawableStale;
@@ -231,6 +233,7 @@ public LocationComponentOptions(
231233
this.pulseMaxRadius = pulseMaxRadius;
232234
this.pulseAlpha = pulseAlpha;
233235
this.pulseInterpolator = pulseInterpolator;
236+
this.concurrentCameraAnimationsEnabled = concurrentCameraAnimationsEnabled;
234237
}
235238

236239
/**
@@ -373,6 +376,10 @@ public static LocationComponentOptions createFromAttributes(@NonNull Context con
373376
builder.pulseAlpha = typedArray.getFloat(
374377
R.styleable.maplibre_LocationComponent_maplibre_pulsingLocationCircleAlpha, CIRCLE_PULSING_ALPHA_DEFAULT);
375378

379+
builder.concurrentCameraAnimationsEnabled = typedArray.getBoolean(
380+
R.styleable.maplibre_LocationComponent_maplibre_concurrentCameraAnimationsEnabled, false
381+
);
382+
376383
typedArray.recycle();
377384

378385
return builder.build();
@@ -892,6 +899,15 @@ public Interpolator pulseInterpolator() {
892899
return pulseInterpolator;
893900
}
894901

902+
/**
903+
* Enable or disable concurrent camera animations during navigation
904+
*
905+
* @return whether concurrent camera animations are enabled or disabled during navigation
906+
*/
907+
public Boolean concurrentCameraAnimationsEnabled() {
908+
return concurrentCameraAnimationsEnabled;
909+
}
910+
895911
@NonNull
896912
@Override
897913
public String toString() {
@@ -934,6 +950,7 @@ public String toString() {
934950
+ "pulseSingleDuration=" + pulseSingleDuration
935951
+ "pulseMaxRadius=" + pulseMaxRadius
936952
+ "pulseAlpha=" + pulseAlpha
953+
+ "concurrentCameraAnimationsEnabled=" + concurrentCameraAnimationsEnabled
937954
+ "}";
938955
}
939956

@@ -1081,6 +1098,10 @@ public boolean equals(Object o) {
10811098
return false;
10821099
}
10831100

1101+
if (concurrentCameraAnimationsEnabled != options.concurrentCameraAnimationsEnabled) {
1102+
return false;
1103+
}
1104+
10841105
return layerBelow != null ? layerBelow.equals(options.layerBelow) : options.layerBelow == null;
10851106
}
10861107

@@ -1130,6 +1151,7 @@ public int hashCode() {
11301151
result = 31 * result + (pulseSingleDuration != +0.0f ? Float.floatToIntBits(pulseSingleDuration) : 0);
11311152
result = 31 * result + (pulseMaxRadius != +0.0f ? Float.floatToIntBits(pulseMaxRadius) : 0);
11321153
result = 31 * result + (pulseAlpha != +0.0f ? Float.floatToIntBits(pulseAlpha) : 0);
1154+
result = 31 * result + (concurrentCameraAnimationsEnabled ? 1 : 0);
11331155
return result;
11341156
}
11351157

@@ -1180,6 +1202,7 @@ public void writeToParcel(Parcel dest, int flags) {
11801202
dest.writeFloat(this.pulseSingleDuration);
11811203
dest.writeFloat(this.pulseMaxRadius);
11821204
dest.writeFloat(this.pulseAlpha);
1205+
dest.writeByte(this.concurrentCameraAnimationsEnabled ? (byte) 1 : (byte) 0);
11831206
}
11841207

11851208
protected LocationComponentOptions(Parcel in) {
@@ -1223,6 +1246,7 @@ protected LocationComponentOptions(Parcel in) {
12231246
this.pulseSingleDuration = in.readFloat();
12241247
this.pulseMaxRadius = in.readFloat();
12251248
this.pulseAlpha = in.readFloat();
1249+
this.concurrentCameraAnimationsEnabled = in.readByte() != 0;
12261250
}
12271251

12281252
public static final Parcelable.Creator<LocationComponentOptions> CREATOR =
@@ -1349,6 +1373,7 @@ public LocationComponentOptions build() {
13491373
private float pulseAlpha;
13501374
@Nullable
13511375
private Interpolator pulseInterpolator;
1376+
private Boolean concurrentCameraAnimationsEnabled;
13521377

13531378
Builder() {
13541379
}
@@ -1395,6 +1420,7 @@ private Builder(LocationComponentOptions source) {
13951420
this.pulseMaxRadius = source.pulseMaxRadius;
13961421
this.pulseAlpha = source.pulseAlpha;
13971422
this.pulseInterpolator = source.pulseInterpolator;
1423+
this.concurrentCameraAnimationsEnabled = source.concurrentCameraAnimationsEnabled;
13981424
}
13991425

14001426
/**
@@ -1973,6 +1999,16 @@ public LocationComponentOptions.Builder pulseInterpolator(Interpolator pulseInte
19731999
return this;
19742000
}
19752001

2002+
/**
2003+
* Enable or disable the concurrent camera animations during navigation feature
2004+
*
2005+
* @return whether concurrent camera animations are enabled or disabled
2006+
*/
2007+
public LocationComponentOptions.Builder concurrentCameraAnimationsEnabled(Boolean concurrentCameraAnimationsEnabled) {
2008+
this.concurrentCameraAnimationsEnabled = concurrentCameraAnimationsEnabled;
2009+
return this;
2010+
}
2011+
19762012
@Nullable
19772013
LocationComponentOptions autoBuild() {
19782014
String missing = "";
@@ -2074,7 +2110,8 @@ LocationComponentOptions autoBuild() {
20742110
this.pulseSingleDuration,
20752111
this.pulseMaxRadius,
20762112
this.pulseAlpha,
2077-
this.pulseInterpolator);
2113+
this.pulseInterpolator,
2114+
this.concurrentCameraAnimationsEnabled);
20782115
}
20792116
}
20802117
}

platform/android/MapLibreAndroid/src/main/java/org/maplibre/android/maps/MapKeyListener.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,14 @@ boolean onKeyUp(int keyCode, KeyEvent event) {
167167
PointF focalPoint = new PointF(uiSettings.getWidth() / 2, uiSettings.getHeight() / 2);
168168
mapGestureDetector.zoomInAnimated(focalPoint, true);
169169
return true;
170+
case KeyEvent.KEYCODE_DEL:
171+
if (!uiSettings.isZoomGesturesEnabled()) {
172+
return false;
173+
}
174+
175+
// Zoom out
176+
focalPoint = new PointF(uiSettings.getWidth() / 2, uiSettings.getHeight() / 2);
177+
mapGestureDetector.zoomOutAnimated(focalPoint, true);
170178
}
171179

172180
// We are not interested in this key

platform/android/MapLibreAndroid/src/main/java/org/maplibre/android/maps/Transform.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ CameraPosition invalidateCameraPosition() {
190190
}
191191

192192
void cancelTransitions() {
193+
MapLibreMap map = mapView.getMapLibreMap();
194+
if (map != null && map.getLocationComponent().isLocationComponentActivated() && map.getLocationComponent().getLocationComponentOptions().concurrentCameraAnimationsEnabled() && map.getLocationComponent().isLocationTracking()) {
195+
return;
196+
}
197+
193198
// notify user about cancel
194199
cameraChangeDispatcher.onCameraMoveCanceled();
195200

platform/android/MapLibreAndroid/src/main/res-public/values/public.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,7 @@
173173
<public name="maplibre_pulsingLocationCircleAlpha" format="float" type="attr" />
174174
<public name="maplibre_pulsingLocationCircleInterpolator" format="string" type="attr" />
175175

176+
<!-- Camera Animations -->
177+
<public name="maplibre_concurrentCameraAnimationsEnabled" format="boolean" type="attr" />
178+
176179
</resources>

platform/android/MapLibreAndroid/src/main/res/values/attrs.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,5 +202,8 @@
202202
<attr name="maplibre_pulsingLocationCircleAlpha" format="float" />
203203
<attr name="maplibre_pulsingLocationCircleInterpolator" format="string" />
204204

205+
<!-- Concurrent Camera Animations -->
206+
<attr name="maplibre_concurrentCameraAnimationsEnabled" format="boolean" />
207+
205208
</declare-styleable>
206209
</resources>

platform/android/MapLibreAndroid/src/main/res/values/styles.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,7 @@
4242
<item name="maplibre_pulsingLocationCircleAlpha">0.4</item>
4343
<item name="maplibre_pulsingLocationCircleInterpolator">decelerate</item>
4444

45+
<!-- Concurrent Camera Animations -->
46+
<item name="maplibre_concurrentCameraAnimationsEnabled">false</item>
4547
</style>
4648
</resources>

0 commit comments

Comments
 (0)