Skip to content

Commit

Permalink
New android sdk version (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanschaller authored Jul 24, 2023
1 parent 492af3d commit ec9808e
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 219 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ MaplibreMap(
)
```

* The old api `registerWith` was removed from the MapboxMapsPlugin.java, since there is no need for that.
* The `minSdkVersion` was bumped to at least 21 now, since the native android sdk constraint expect that.

## 0.16.0, Jun 28, 2022
* cherry-picked all commits from upstream up to [https://github.com/flutter-mapbox-gl/maps/commit/3496907955cd4b442e4eb905d67e8d46692174f1), including up to release 0.16.0 from upstream
* updated Maplibre GL JS for web
Expand Down
20 changes: 12 additions & 8 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.2'
classpath 'com.android.tools.build:gradle:4.1.3'
}
}

Expand All @@ -20,14 +20,15 @@ rootProject.allprojects {
}

apply plugin: 'com.android.library'
apply plugin: 'org.jetbrains.kotlin.android'

android {

compileSdkVersion 31
ndkVersion "20.1.5948944"

defaultConfig {
minSdkVersion 20
minSdkVersion 21
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
Expand All @@ -39,15 +40,18 @@ android {
targetCompatibility JavaVersion.VERSION_1_8
}
dependencies {
implementation 'org.maplibre.gl:android-sdk:9.6.0'
implementation 'org.maplibre.gl:android-plugin-annotation-v9:1.0.0'
implementation 'org.maplibre.gl:android-plugin-localization-v9:1.0.0'
implementation 'org.maplibre.gl:android-plugin-offline-v9:1.0.0'
implementation 'com.squareup.okhttp3:okhttp:4.9.3'

implementation 'org.maplibre.gl:android-sdk:10.2.0'
implementation 'org.maplibre.gl:android-plugin-annotation-v9:2.0.0'
implementation 'org.maplibre.gl:android-plugin-localization-v9:2.0.0'
implementation 'org.maplibre.gl:android-plugin-offline-v9:2.0.0'
implementation 'com.squareup.okhttp3:okhttp:4.10.0'
}
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}

dependencies {
implementation 'androidx.core:core-ktx:1.10.1'
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import android.content.Context;
import android.view.Gravity;
import androidx.annotation.NonNull;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
Expand Down Expand Up @@ -54,14 +55,13 @@ public void setCompassEnabled(boolean compassEnabled) {
}

@Override
public void setCameraTargetBounds(LatLngBounds bounds) {
public void setCameraTargetBounds(@NonNull LatLngBounds bounds) {
this.bounds = bounds;
}

@Override
public void setStyleString(String styleString) {
public void setStyleString(@NonNull String styleString) {
this.styleString = styleString;
// options. styleString(styleString);
}

@Override
Expand Down
38 changes: 18 additions & 20 deletions android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,10 @@
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
// import com.mapbox.android.core.location.LocationEngine;
// import com.mapbox.android.core.location.LocationEngineCallback;
// import com.mapbox.android.core.location.LocationEngineProvider;
// import com.mapbox.android.core.location.LocationEngineResult;
import com.mapbox.android.gestures.AndroidGesturesManager;
// import com.mapbox.android.telemetry.TelemetryEnabler;
import com.mapbox.android.gestures.MoveGestureDetector;
import com.mapbox.geojson.Feature;
import com.mapbox.geojson.FeatureCollection;
import com.mapbox.geojson.BoundingBox;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdate;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
Expand All @@ -50,11 +44,10 @@
import com.mapbox.mapboxsdk.geometry.LatLngQuad;
import com.mapbox.mapboxsdk.geometry.VisibleRegion;
import com.mapbox.mapboxsdk.location.LocationComponent;
import com.mapbox.mapboxsdk.location.LocationComponentActivationOptions;
import com.mapbox.mapboxsdk.location.LocationComponentOptions;
import com.mapbox.mapboxsdk.location.OnCameraTrackingChangedListener;
import com.mapbox.mapboxsdk.location.engine.LocationEngine;
import com.mapbox.mapboxsdk.location.engine.LocationEngineCallback;
import com.mapbox.mapboxsdk.location.engine.LocationEngineProvider;
import com.mapbox.mapboxsdk.location.engine.LocationEngineResult;
import com.mapbox.mapboxsdk.location.modes.CameraMode;
import com.mapbox.mapboxsdk.location.modes.RenderMode;
Expand All @@ -73,6 +66,7 @@
import com.mapbox.mapboxsdk.style.layers.HillshadeLayer;
import com.mapbox.mapboxsdk.style.layers.Layer;
import com.mapbox.mapboxsdk.style.layers.LineLayer;
import com.mapbox.mapboxsdk.style.layers.Property;
import com.mapbox.mapboxsdk.style.layers.PropertyValue;
import com.mapbox.mapboxsdk.style.layers.RasterLayer;
import com.mapbox.mapboxsdk.style.layers.SymbolLayer;
Expand Down Expand Up @@ -136,7 +130,6 @@ final class MapboxMapController
private boolean dragEnabled = true;
private MethodChannel.Result mapReadyResult;
private LocationComponent locationComponent = null;
private LocationEngine locationEngine = null;
private LocationEngineCallback<LocationEngineResult> locationEngineCallback = null;
private LocalizationPlugin localizationPlugin;
private Style style;
Expand Down Expand Up @@ -265,7 +258,7 @@ public boolean onTouch(View v, MotionEvent event) {
}

@Override
public void setStyleString(String styleString) {
public void setStyleString(@NonNull String styleString) {
// clear old layer id from the location Component
clearLocationComponentLayer();
styleString = styleString.trim();
Expand All @@ -290,18 +283,22 @@ public void setStyleString(String styleString) {
}
}



@SuppressWarnings({"MissingPermission"})
private void enableLocationComponent(@NonNull Style style) {
if (hasLocationPermission()) {
locationEngine = LocationEngineProvider.getBestLocationEngine(context);

locationComponent = mapboxMap.getLocationComponent();
locationComponent.activateLocationComponent(
context, style, buildLocationComponentOptions(style));

LocationComponentActivationOptions options =
LocationComponentActivationOptions
.builder(context, style)
.locationComponentOptions(buildLocationComponentOptions(style))
.build();

locationComponent.activateLocationComponent(options);
locationComponent.setLocationComponentEnabled(true);
// locationComponent.setRenderMode(RenderMode.COMPASS); // remove or keep default?
locationComponent.setLocationEngine(locationEngine);
locationComponent.setMaxAnimationFps(30);
updateMyLocationTrackingMode();
updateMyLocationRenderMode();
Expand Down Expand Up @@ -863,7 +860,7 @@ public void onCancel() {
}
case "map#invalidateAmbientCache":
{
OfflineManager fileSource = OfflineManager.getInstance(context);
OfflineManager fileSource = OfflineManager.Companion.getInstance(context);

fileSource.invalidateAmbientCache(
new OfflineManager.FileSourceCallback() {
Expand Down Expand Up @@ -1070,9 +1067,10 @@ public void onError(@NonNull String message) {
case "locationComponent#getLastLocation":
{
Log.e(TAG, "location component: getLastLocation");
if (this.myLocationEnabled && locationComponent != null && locationEngine != null) {
if (this.myLocationEnabled && locationComponent != null) {
Map<String, Object> reply = new HashMap<>();
locationEngine.getLastLocation(

mapboxMap.getLocationComponent().getLocationEngine().getLastLocation(
new LocationEngineCallback<LocationEngineResult>() {
@Override
public void onSuccess(LocationEngineResult locationEngineResult) {
Expand Down Expand Up @@ -1325,7 +1323,7 @@ public void onFailure(@NonNull Exception exception) {

Layer layer = style.getLayer(layerId);

layer.setProperties(PropertyFactory.visibility(visible ? "visible" : "none"));
layer.setProperties(PropertyFactory.visibility(visible ? Property.VISIBLE : Property.NONE));

result.success(null);
break;
Expand Down

This file was deleted.

45 changes: 45 additions & 0 deletions android/src/main/java/com/mapbox/mapboxgl/MapboxMapOptionsSink.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package com.mapbox.mapboxgl

import com.mapbox.mapboxsdk.geometry.LatLngBounds

/** Receiver of MapboxMap configuration options. */
internal interface MapboxMapOptionsSink {
// todo: dddd replace with CameraPosition.Builder target
fun setCameraTargetBounds(bounds: LatLngBounds)

fun setCompassEnabled(compassEnabled: Boolean)

// TODO: styleString is not actually a part of options. consider moving
fun setStyleString(styleString: String)

fun setMinMaxZoomPreference(min: Float?, max: Float?)

fun setRotateGesturesEnabled(rotateGesturesEnabled: Boolean)

fun setScrollGesturesEnabled(scrollGesturesEnabled: Boolean)

fun setTiltGesturesEnabled(tiltGesturesEnabled: Boolean)

fun setTrackCameraPosition(trackCameraPosition: Boolean)

fun setZoomGesturesEnabled(zoomGesturesEnabled: Boolean)

fun setMyLocationEnabled(myLocationEnabled: Boolean)

fun setMyLocationTrackingMode(myLocationTrackingMode: Int)

fun setMyLocationRenderMode(myLocationRenderMode: Int)

fun setLogoViewMargins(x: Int, y: Int)

fun setCompassGravity(gravity: Int)

fun setCompassViewMargins(x: Int, y: Int)

fun setAttributionButtonGravity(gravity: Int)

fun setAttributionButtonMargins(x: Int, y: Int)
}
Loading

0 comments on commit ec9808e

Please sign in to comment.