Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

plumb map notifications through JNI to Android - #2255

Merged
incanus merged 1 commit into
masterfrom
android-map-notify-types
Sep 4, 2015
Merged

incanus merged 1 commit into
masterfrom
android-map-notify-types

Conversation

@incanus

@incanus incanus commented Sep 4, 2015

Copy link
Copy Markdown
Contributor

Passes through mbgl::MapChange notification types into native Java.

Two review issues:

  1. I think that I am using Java enum right here — backing with an int value, but since unable to instantiate in the style of classes, using a switch later on to deduce the raw int passed and map to the enum case. This seems verbose and redundant (i.e. specifying the raw values -1 to 13 two times).
  2. Since we already made use of pure Java updateMap() in places, I added a Java-only case MapChangeNullChange(-1) for these cases. However I'm confused why/if we need to notify at all in these cases since we're only modifying map properties such as tracking state, compass visibility, and the like and not actually modifying fetch/parse/render properties.

Unblocks #894 (comment).

/cc @bleege @ljbade

@incanus incanus added GL JS parity For feature parity with Mapbox GL JS Android Mapbox Maps SDK for Android in progress labels Sep 4, 2015
@incanus

incanus commented Sep 4, 2015

Copy link
Copy Markdown
Contributor Author

You can easily test this with a patch such as the following:

diff --git a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java
index b75aaba..9382bee 100644
--- a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java
+++ b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java
@@ -1829,6 +1829,9 @@ public class MapView extends FrameLayout implements LocationListener {

     // Updates the UI to match the current map's position
     private void updateMap(MapChange change) {
+
+        Log.d(TAG, "updateMap: " + Integer.toString(change.value));
+
         // Using direct access to mIsCompassEnabled instead of isCompassEnabled() for
         // small performance boost as this method is called rapidly.
         if (mIsCompassEnabled) {

Then see the following in the logs as you interact with the map:

09-03 17:17:51.202  31972-31972/com.mapbox.mapboxgl.testapp D/MapView﹕ updateMap: 8
09-03 17:17:51.219  31972-31972/com.mapbox.mapboxgl.testapp D/MapView﹕ updateMap: 9
09-03 17:17:51.219  31972-31972/com.mapbox.mapboxgl.testapp D/MapView﹕ updateMap: 8
09-03 17:17:51.219  31972-31972/com.mapbox.mapboxgl.testapp D/MapView﹕ updateMap: 10
09-03 17:17:51.219  31972-31972/com.mapbox.mapboxgl.testapp D/MapView﹕ updateMap: 13
09-03 17:17:51.239  31972-31972/com.mapbox.mapboxgl.testapp D/MapView﹕ updateMap: 8
09-03 17:17:51.254  31972-31972/com.mapbox.mapboxgl.testapp D/MapView﹕ updateMap: 10
09-03 17:17:51.254  31972-31972/com.mapbox.mapboxgl.testapp D/MapView﹕ updateMap: 8
09-03 17:17:51.269  31972-31972/com.mapbox.mapboxgl.testapp D/MapView﹕ updateMap: 10

@ljbade

ljbade commented Sep 4, 2015

Copy link
Copy Markdown
Contributor

The switch is pretty much the accepted way to int -> enum: http://stackoverflow.com/questions/5878952/cast-int-to-enum-in-java

I think the idea with updateMap() on Java side was related to triggering the UI to fetch updated GPS coordinates and update the location of the GPS marker dot (it made sense at the time to use same code for map pan/zoom updates).

@ljbade

ljbade commented Sep 4, 2015

Copy link
Copy Markdown
Contributor

Also looking at Google Maps: https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap

They split each type of map update into separate listeners? Should we do the same?

@incanus

incanus commented Sep 4, 2015

Copy link
Copy Markdown
Contributor Author

Ah, that's a nice reference link; better than the stuff I was finding. I'll tune this up to move the switch into the class itself.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will definitely work, but if we don't need to maintain value for any particular reason it can definitely be safely removed.

private enum MapChange {
MapChangeNullChange,
MapChangeRegionWillChange,
MapChangeRegionWillChangeAnimated,
...
}

// Comparison works this way then
MapChange mcEvent;
switch (mcEvent) {
   case MapChange.MapChangeNullChange:
      break;
   case MapChange.MapChangeRegionWillChange:
     break;
   case MapChange.MapChangeRegionWillChangeAnimated
     break;

....
   default:
     // Shouldn't get here
}

It can lead to a bit more verbose switch statements, but also safer ones as it doesn't require values to be copied and stored multiple places.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we don't need to maintain value for any particular reason it can definitely be safely removed.

I want to maintain equivalence to this enum on the native side.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah.. that makes sense. 👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@incanus
incanus force-pushed the android-map-notify-types branch from 472846e to e78eace Compare September 4, 2015 17:06
@incanus
incanus merged commit e78eace into master Sep 4, 2015
@incanus
incanus deleted the android-map-notify-types branch September 4, 2015 17:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Android Mapbox Maps SDK for Android GL JS parity For feature parity with Mapbox GL JS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants