Skip to content

Commit

Permalink
Kujaku migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleem92 committed Jan 31, 2025
1 parent 8c1aae0 commit fc1c571
Show file tree
Hide file tree
Showing 24 changed files with 342 additions and 326 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ The library offers a view `KujakuMapView` that provides more functionality than

## `Unable to resolve artifact: Missing` while running tests

This is encountered when Robolectric has problems downloading the jars it needs for different Android SDK levels. If you keep running into this you can download the JARs locally and point Robolectric to them by doing:
This is encountered when Robolectric has problems downloading the jars it needs for different Android SDK levels. If you keep running into this you can download the JARs locally and pointModel Robolectric to them by doing:

```
./download-robolectric-deps.sh
Expand Down
10 changes: 5 additions & 5 deletions SPECIFICATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Steps for creating the mapbox style with Kujaku configuration:
3. Add the Kujaku config

The Kujaku config is a JSON Object with the following:
1. `data_sources` JSON Array of `name`-only JSON Objects - The name points to the data source name in the style
1. `data_sources` JSON Array of `name`-only JSON Objects - The name pointModels to the data source name in the style
```json
"data_sources": [
{
Expand Down Expand Up @@ -238,7 +238,7 @@ public void addWmtsLayer(WmtsCapabilities capabilities, String layerIdentifier,

## 2. Using Tracking Service

The Tracking Service is a foreground service providing Locations points regarding some options.
The Tracking Service is a foreground service providing Locations pointModels regarding some options.
The application needs to register the TrackingService listener to be able to receive notifications when :
- First location as been received
- A new location has been recorded
Expand Down Expand Up @@ -351,7 +351,7 @@ The **MapActivity** will request some permissions(during runtime & in the manife
The `KujakuMapView` enables a developer to have low level access to the geo-spatial widget. The developer can access the Mapbox APIs exposed on the mapbox `MapView` and have the flexibility to implement the widget in whatever view they want.

Example usage:
1. Add point without GPS
1. Add pointModel without GPS

```java
kujakuMapView.addPoint(false, new AddPointCallback() {
Expand All @@ -369,7 +369,7 @@ Example usage:
});
```

2. Add point with GPS
2. Add pointModel with GPS

```java
kujakuMapView.addPoint(true, new AddPointCallback() {
Expand All @@ -382,7 +382,7 @@ Example usage:
public void onCancel() {
// Do something here -->
// 1. Explain to the user that a location is required
// 2. Give them the option of manually locating the point
// 2. Give them the option of manually locating the pointModel
}
});

Expand Down
17 changes: 8 additions & 9 deletions configs.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -101,26 +101,26 @@ ext.localProperties = properties
*/

ext {

// Dependency and other versions
androidxTestCoreVersion = "1.4.0"
compileSdkVersion = 34
jacocoVersion = "0.8.11"
junitVersion = "4.13.2"
mapboxAnnotationPluginVersion = "0.9.0"
mapboxSdkVersion = "9.7.1"
mapboxSdkTurfVersion = "7.2.0"
mapboxVersion = "10.19.0"
mapboxServicesVersion = "5.4.1" // For Services, GeoJSON, and Turf
robolectricVersion = "4.13"
supportVersion = "1.0.0"
volleyVersion = "1.2.1"
targetSdkVersion = 34

// Dependency names
androidxTestCore = "androidx.test:core:$androidxTestCoreVersion"
junit = "junit:junit:$junitVersion"
mapboxSDK = "com.mapbox.mapboxsdk:mapbox-android-sdk:$mapboxSdkVersion"
mapboxSDKTurf = "com.mapbox.mapboxsdk:mapbox-sdk-turf:$mapboxSdkTurfVersion"
mapboxAnnotationPlugin = "com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v9:$mapboxAnnotationPluginVersion"

mapboxSDK = "com.mapbox.maps:android:$mapboxVersion"
mapboxLocation = "com.mapbox.maps:plugin-locationcomponent:$mapboxVersion"
mapboxGestures = "com.mapbox.maps:plugin-gestures:$mapboxVersion"
mapboxStyleEx = "com.mapbox.maps:android-plugin-style-extension:$mapboxVersion"
mapboxSDKTurf = "com.mapbox.mapboxsdk:mapbox-sdk-turf:$mapboxServicesVersion"
robolectric = "org.robolectric:robolectric:$robolectricVersion"
}

Expand All @@ -138,7 +138,6 @@ ext.mapboxDependencies = { instance, configuration ->
// is a dependency of the mapbox-android-sdk. The mapbox-sdk-turf is declared as
// a runtime dependency
configuration.implementation "com.mapbox.mapboxsdk:mapbox-sdk-turf:$instance.mapboxSdkTurfVersion"
configuration.implementation "com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v7:${instance.mapboxAnnotationPluginVersion}"

}

Expand Down
5 changes: 4 additions & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ dependencies { configuration ->
// is a dependency of the mapbox-android-sdk. The mapbox-sdk-turf is declared as
// a runtime dependency
implementation mapboxSDKTurf
implementation mapboxAnnotationPlugin
implementation mapboxStyleEx
implementation mapboxLocation
implementation mapboxGestures
// implementation mapboxAnnotationPlugin

// Comment the line below when creating releases - The line is for development of the library & utils
implementation (project(":utils")) {
Expand Down
6 changes: 3 additions & 3 deletions library/src/main/java/io/ona/kujaku/KujakuLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.util.List;

import io.ona.kujaku.data.realm.RealmDatabase;
import io.ona.kujaku.domain.Point;
import io.ona.kujaku.domain.PointModel;
import io.ona.kujaku.exceptions.KujakuLibraryInitializationException;
import io.ona.kujaku.helpers.ActivityLauncherHelper;
import io.ona.kujaku.receivers.KujakuNetworkChangeReceiver;
Expand Down Expand Up @@ -87,8 +87,8 @@ public static void setEnableMapDownloadResume(boolean isEnableMapDownloadResume)
}

public void launchMapActivity(@NonNull Activity hostActivity, @NonNull String mapboxAccessToken
, @Nullable List<Point> points, boolean enableDropPoint) {
ActivityLauncherHelper.launchMapActivity(hostActivity, mapboxAccessToken, points, enableDropPoint);
, @Nullable List<PointModel> pointModels, boolean enableDropPoint) {
ActivityLauncherHelper.launchMapActivity(hostActivity, mapboxAccessToken, pointModels, enableDropPoint);
}

public void showToast(@NonNull String text) {
Expand Down
23 changes: 8 additions & 15 deletions library/src/main/java/io/ona/kujaku/activities/MapActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@
import android.widget.RelativeLayout;

import com.mapbox.geojson.Feature;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.maps.Style;
import com.mapbox.maps.MapboxMap;

import org.json.JSONArray;
import org.json.JSONException;
Expand All @@ -44,7 +39,7 @@
import io.ona.kujaku.adapters.InfoWindowAdapter;
import io.ona.kujaku.adapters.InfoWindowObject;
import io.ona.kujaku.adapters.holders.InfoWindowViewHolder;
import io.ona.kujaku.domain.Point;
import io.ona.kujaku.domain.PointModel;
import io.ona.kujaku.helpers.storage.MapBoxStyleStorage;
import io.ona.kujaku.sorting.Sorter;
import io.ona.kujaku.utils.Constants;
Expand Down Expand Up @@ -76,7 +71,7 @@
* <p>
* Created by Ephraim Kigamba - ekigamba@ona.io
*/
public class MapActivity extends AppCompatActivity implements MapboxMap.OnMapClickListener {
public class MapActivity extends AppCompatActivity {
private static final int PERMISSIONS_REQUEST_CODE = 342;
private KujakuMapView kujakuMapView;
private String currentStylePath;
Expand Down Expand Up @@ -127,13 +122,11 @@ protected void onCreate(Bundle savedInstanceState) {
if (bundle != null
&& bundle.containsKey(Constants.PARCELABLE_KEY_MAPBOX_ACCESS_TOKEN)
&& bundle.getString(Constants.PARCELABLE_KEY_MAPBOX_ACCESS_TOKEN) != null) {
String mapBoxAccessToken = bundle.getString(Constants.PARCELABLE_KEY_MAPBOX_ACCESS_TOKEN);
Mapbox.getInstance(this, mapBoxAccessToken);
List<Point> points = bundle.getParcelableArrayList(PARCELABLE_POINTS_LIST);
List<PointModel> pointModels = bundle.getParcelableArrayList(PARCELABLE_POINTS_LIST);
enableDropPoint = bundle.getBoolean(ENABLE_DROP_POINT_BUTTON, false);

setContentView(R.layout.activity_map);
initializeViews(points, enableDropPoint);
initializeViews(pointModels, enableDropPoint);
checkPermissions(savedInstanceState);
} else {
finish();
Expand Down Expand Up @@ -270,7 +263,7 @@ private LatLng getBoundsCenter(LatLng topLeftBound, LatLng bottomRightBound) {
);
}

private void initializeViews(List<Point> points, boolean enableDropPoint) {
private void initializeViews(List<PointModel> pointModels, boolean enableDropPoint) {
dismissAllDialogs();
alertDialogs = new HashMap<>();
infoWindowsRecyclerView = findViewById(R.id.rv_mapActivity_infoWindow);
Expand Down Expand Up @@ -309,8 +302,8 @@ public void onClick(View v) {
});
btnDone.setVisibility(View.VISIBLE);

if (points != null) {
kujakuMapView.updateDroppedPoints(new ArrayList<>(points));
if (pointModels != null) {
kujakuMapView.updateDroppedPoints(new ArrayList<>(pointModels));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
/**
* @author Vincent Karuri
*/
public class Point implements Parcelable {
public class PointModel implements Parcelable {

private Integer id;
private double lat;
private double lng;
private Long dateUpdated;

public Point(Integer id, double lat, double lng) {
public PointModel(Integer id, double lat, double lng) {
this.id = id;
this.lat = lat;
this.lng = lng;
Expand Down Expand Up @@ -55,12 +55,12 @@ public void setDateUpdated(Long dateUpdated) {

@Override
public boolean equals(Object o) {
if (o == null || !(o instanceof Point)) {
if (o == null || !(o instanceof PointModel)) {
return false;
}
Point point = (Point) o;
return Double.compare(point.getLat(), getLat()) == 0 &&
Double.compare(point.getLng(), getLng()) == 0;
PointModel pointModel = (PointModel) o;
return Double.compare(pointModel.getLat(), getLat()) == 0 &&
Double.compare(pointModel.getLng(), getLng()) == 0;
}

@Override
Expand All @@ -69,19 +69,19 @@ public int hashCode() {
}

// Parcelable methods
public Point(Parcel in) {
public PointModel(Parcel in) {
this.id = in.readInt();
this.lat = in.readDouble();
this.lng = in.readDouble();
}

public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public Point createFromParcel(Parcel in) {
return new Point(in);
public PointModel createFromParcel(Parcel in) {
return new PointModel(in);
}

public Point[] newArray(int size) {
return new Point[size];
public PointModel[] newArray(int size) {
return new PointModel[size];
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Parcelable;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand All @@ -16,7 +15,7 @@

import io.ona.kujaku.activities.MapActivity;
import io.ona.kujaku.callables.AsyncTaskCallable;
import io.ona.kujaku.domain.Point;
import io.ona.kujaku.domain.PointModel;
import io.ona.kujaku.listeners.OnFinishedListener;
import io.ona.kujaku.tasks.GenericAsyncTask;
import io.ona.kujaku.utils.Constants;
Expand All @@ -35,7 +34,7 @@ public class ActivityLauncherHelper {
public static final String TAG = ActivityLauncherHelper.class.getName();

public static void launchMapActivity(@NonNull Activity hostActivity, @NonNull String mapboxAccessToken
, @Nullable List<Point> points, boolean enableDropPoint) {
, @Nullable List<PointModel> pointModels, boolean enableDropPoint) {
Intent intent = new Intent(hostActivity, MapActivity.class);
createCustomStyleLayer(hostActivity.getApplicationContext(), new OnFinishedListener() {
@Override
Expand All @@ -48,7 +47,7 @@ public void onSuccess(Object[] objects) {

intent.putExtra(Constants.PARCELABLE_KEY_MAPBOX_ACCESS_TOKEN, mapboxAccessToken);
intent.putExtra(ENABLE_DROP_POINT_BUTTON, enableDropPoint);
intent.putParcelableArrayListExtra(PARCELABLE_POINTS_LIST, (ArrayList<? extends Parcelable>) points);
intent.putParcelableArrayListExtra(PARCELABLE_POINTS_LIST, (ArrayList<? extends Parcelable>) pointModels);

hostActivity.startActivityForResult(intent, MAP_ACTIVITY_REQUEST_CODE);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package io.ona.kujaku.helpers;

import static com.mapbox.maps.plugin.Plugin.MAPBOX_LOCATION_COMPONENT_PLUGIN_ID;

import android.content.Context;
import android.content.pm.PackageManager;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.mapbox.mapboxsdk.location.LocationComponent;
import com.mapbox.mapboxsdk.location.modes.CameraMode;
import com.mapbox.mapboxsdk.location.modes.RenderMode;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.maps.MapView;
import com.mapbox.maps.plugin.LocationPuck2D;
import com.mapbox.maps.plugin.locationcomponent.LocationComponentPlugin;

import io.ona.kujaku.callbacks.OnLocationComponentInitializedCallback;

Expand All @@ -17,43 +19,51 @@
*/
public class MapboxLocationComponentWrapper {

private LocationComponent locationComponent;

private LocationComponentPlugin locationComponent;
private OnLocationComponentInitializedCallback onLocationComponentInitializedCallback;

/**
* Init Location Component Wrapper
*
* @param mapboxMap {@link MapboxMap}
* @param mapView {@link MapView}
* @param context
* @param locationRenderMode {@link RenderMode}
* @param showBearing whether to show bearing indicator
*/
@SuppressWarnings( {"MissingPermission"})
public void init(@NonNull MapboxMap mapboxMap, @NonNull Context context, int locationRenderMode) {
locationComponent = mapboxMap.getLocationComponent();
locationComponent.activateLocationComponent(context, mapboxMap.getStyle(), false);
locationComponent.setLocationComponentEnabled(true);
locationComponent.setCameraMode(CameraMode.NONE);
@SuppressWarnings({"MissingPermission"})
public void init(@NonNull MapView mapView, @NonNull Context context, boolean showBearing) {
locationComponent = mapView.getPlugin(MAPBOX_LOCATION_COMPONENT_PLUGIN_ID);

LocationPuck2D locationPuck = new LocationPuck2D();

PackageManager pm = context.getPackageManager();
if (pm != null && !pm.hasSystemFeature(PackageManager.FEATURE_SENSOR_COMPASS)) {
// This device does not have a compass, turn off the compass feature
locationComponent.setRenderMode(RenderMode.NORMAL);
} else {
locationComponent.setRenderMode(locationRenderMode);
boolean hasCompass = pm != null && pm.hasSystemFeature(PackageManager.FEATURE_SENSOR_COMPASS);

locationComponent.setLocationPuck(locationPuck);
locationComponent.setEnabled(true);

if (hasCompass && showBearing) {
locationPuck.setBearingImage(null);
locationComponent.setPulsingEnabled(true);
}

if (onLocationComponentInitializedCallback != null) {
onLocationComponentInitializedCallback.onLocationComponentInitialized();
}
}

/**
* Get the location component
* @return LocationComponentPlugin instance
*/
@Nullable
public LocationComponent getLocationComponent() {
return locationComponent;
public LocationComponentPlugin getLocationComponent() {
return locationComponent;
}

public void setOnLocationComponentInitializedCallback(OnLocationComponentInitializedCallback onLocationComponentInitializedCallback) {
this.onLocationComponentInitializedCallback = onLocationComponentInitializedCallback;
/**
* Set callback for when location component is initialized
* @param callback OnLocationComponentInitializedCallback
*/
public void setOnLocationComponentInitializedCallback(OnLocationComponentInitializedCallback callback) {
this.onLocationComponentInitializedCallback = callback;
}
}
}
Loading

0 comments on commit fc1c571

Please sign in to comment.