Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animator Updates #349

Merged
merged 25 commits into from
Mar 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6f79da7
Add initial animators
danesfeder Feb 19, 2018
d25dafa
Add Camera and Tracking Modes (#294)
danesfeder Feb 21, 2018
5031e32
Update with Render / Camera Modes (#297)
danesfeder Feb 21, 2018
b66d653
Add animator class (#302)
danesfeder Feb 22, 2018
4588147
Cleanup stale runnable (#304)
Feb 23, 2018
612f227
only update the location layer accuracy when not in RenderMode.GPS (#…
tobrun Feb 23, 2018
44a6602
Improve enabling/disabling location layer plugin (#308)
Feb 27, 2018
ce02ede
LocationLayerPlugin Javadoc (#309)
danesfeder Feb 27, 2018
a5f2dc9
LocationEngine listening to updates after resetting (#307)
Feb 27, 2018
999d19d
Add max / min zoom and padding APIs (#313)
danesfeder Feb 27, 2018
62a0e1c
Gestures logic for camera tracking, new telemetry library (#327)
Mar 1, 2018
ca7b10a
Update dependencies
danesfeder Mar 6, 2018
1b0e98d
Add missing long click listener
danesfeder Mar 7, 2018
94520b5
[location-layer] - fix crash on startup
tobrun Mar 7, 2018
cf665f1
Merge branch 'map-location-animators' of github.com:mapbox/mapbox-plu…
danesfeder Mar 21, 2018
83645b7
Smooth bearing animation
danesfeder Mar 7, 2018
18a0805
Add separate camera animators
danesfeder Mar 8, 2018
45dad00
Fix camera transitions between animators
danesfeder Mar 9, 2018
8cd8b21
Add reset function for switching camera modes
danesfeder Mar 21, 2018
1b7478a
Add gps north functionality to camera animator
danesfeder Mar 21, 2018
f46e83f
Camera transition updates
danesfeder Mar 23, 2018
4ecea1f
[location-layer-plugin] - fixed camera tracking callbacks
LukasPaczos Mar 27, 2018
5abf888
[location-layer-plugin] - decreased default max zoom
LukasPaczos Mar 27, 2018
a015408
[location-layer-plugin] - saving state in LocationLayerModesActivity
LukasPaczos Mar 27, 2018
ea2e885
update maps sdk to latest beta (#384)
tobrun Mar 28, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ public void whenMapCameraInitializesTilted_iconsGetPlacedWithCorrectOffset() thr
locationLayerPlugin.setRenderMode(RenderMode.NORMAL);
locationLayerPlugin.forceLocationUpdate(location);
SymbolLayer layer = mapboxMap.getLayerAs(FOREGROUND_LAYER);
uiController.loopMainThreadForAtLeast(200);
Float[] value = layer.getIconOffset().getValue();
Assert.assertEquals((-0.05 * 60), value[1], 0.1);
});
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,25 @@
import android.app.Activity;
import android.support.test.espresso.IdlingResource;

import timber.log.Timber;

import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;

import java.lang.reflect.Field;

public class OnMapReadyIdlingResource implements IdlingResource {
public class OnMapReadyIdlingResource implements IdlingResource, OnMapReadyCallback {

private final Activity activity;
private MapboxMap mapboxMap;
private IdlingResource.ResourceCallback resourceCallback;

public OnMapReadyIdlingResource(Activity activity) {
this.activity = activity;
try {
Field field = activity.getClass().getDeclaredField("mapView");
field.setAccessible(true);
((MapView) field.get(activity)).getMapAsync(this);
} catch (Exception err) {
throw new RuntimeException(err);
}
}

@Override
Expand All @@ -26,32 +31,23 @@ public String getName() {

@Override
public boolean isIdleNow() {
boolean idle = isMapboxMapReady();
if (idle && resourceCallback != null) {
resourceCallback.onTransitionToIdle();
}
return idle;
return mapboxMap != null;
}

@Override
public void registerIdleTransitionCallback(ResourceCallback resourceCallback) {
this.resourceCallback = resourceCallback;
}

private boolean isMapboxMapReady() {
try {
Field field = activity.getClass().getDeclaredField("mapboxMap");
field.setAccessible(true);
mapboxMap = (MapboxMap) field.get(activity);
Timber.e("isMapboxReady called with value " + (mapboxMap != null));
return mapboxMap != null;
} catch (Exception exception) {
Timber.e("could not reflect", exception);
return false;
}
}

public MapboxMap getMapboxMap() {
return mapboxMap;
}

@Override
public void onMapReady(MapboxMap mapboxMap) {
this.mapboxMap = mapboxMap;
if (resourceCallback != null) {
resourceCallback.onTransitionToIdle();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}


switch (item.getItemId()) {
case R.id.menu_building_min_zoom:
buildingPlugin.setMinZoomLevel(14);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mapbox.mapboxsdk.plugins.testapp.activity.location;

import android.annotation.SuppressLint;
import android.content.res.Configuration;
import android.location.Location;
import android.os.Bundle;
import android.support.annotation.VisibleForTesting;
Expand Down Expand Up @@ -57,6 +58,15 @@ public class LocationLayerModesActivity extends AppCompatActivity implements OnM
private MapboxMap mapboxMap;
private boolean customStyle;

private static final String SAVED_STATE_CAMERA = "saved_state_camera";
private static final String SAVED_STATE_RENDER = "saved_state_render";

@CameraMode.Mode
private int cameraMode = CameraMode.NONE;

@RenderMode.Mode
private int renderMode = RenderMode.NORMAL;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -65,6 +75,11 @@ protected void onCreate(Bundle savedInstanceState) {

mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);

if (savedInstanceState != null) {
cameraMode = savedInstanceState.getInt(SAVED_STATE_CAMERA);
renderMode = savedInstanceState.getInt(SAVED_STATE_RENDER);
}
}

@SuppressWarnings( {"MissingPermission"})
Expand All @@ -88,16 +103,28 @@ public void locationModeCompass(View view) {
@Override
public void onMapReady(MapboxMap mapboxMap) {
this.mapboxMap = mapboxMap;

locationEngine = new LocationEngineProvider(this).obtainBestLocationEngineAvailable();
locationEngine.setPriority(LocationEnginePriority.HIGH_ACCURACY);
locationEngine.setFastestInterval(1000);
locationEngine.addLocationEngineListener(this);
locationEngine.activate();

int[] padding;
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
padding = new int[] {0, 750, 0, 0};
} else {
padding = new int[] {0, 250, 0, 0};
}
LocationLayerOptions options = LocationLayerOptions.builder(this)
.padding(new int[] {0, 650, 0, 0})
.padding(padding)
.build();
locationLayerPlugin = new LocationLayerPlugin(mapView, mapboxMap, locationEngine, options);
locationLayerPlugin.addOnLocationClickListener(this);
locationLayerPlugin.addOnCameraTrackingChangedListener(this);
locationLayerPlugin.setCameraMode(cameraMode);
setRendererMode(renderMode);

getLifecycle().addObserver(locationLayerPlugin);
}

Expand Down Expand Up @@ -177,6 +204,8 @@ protected void onStop() {
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
outState.putInt(SAVED_STATE_CAMERA, cameraMode);
outState.putInt(SAVED_STATE_RENDER, renderMode);
}

@Override
Expand Down Expand Up @@ -226,17 +255,29 @@ private void showModeListDialog() {
String selectedMode = modes.get(position);
locationModeBtn.setText(selectedMode);
if (selectedMode.contentEquals("Normal")) {
locationLayerPlugin.setRenderMode(RenderMode.NORMAL);
setRendererMode(RenderMode.NORMAL);
} else if (selectedMode.contentEquals("Compass")) {
locationLayerPlugin.setRenderMode(RenderMode.COMPASS);
setRendererMode(RenderMode.COMPASS);
} else if (selectedMode.contentEquals("GPS")) {
locationLayerPlugin.setRenderMode(RenderMode.GPS);
setRendererMode(RenderMode.GPS);
}
listPopup.dismiss();
});
listPopup.show();
}

private void setRendererMode(@RenderMode.Mode int mode) {
renderMode = mode;
locationLayerPlugin.setRenderMode(mode);
if (mode == RenderMode.NORMAL) {
locationModeBtn.setText("Normal");
} else if (mode == RenderMode.COMPASS) {
locationModeBtn.setText("Compass");
} else if (mode == RenderMode.GPS) {
locationModeBtn.setText("Gps");
}
}

private void showTrackingListDialog() {
List<String> trackingTypes = new ArrayList<>();
trackingTypes.add("None");
Expand Down Expand Up @@ -275,6 +316,18 @@ public void onCameraTrackingDismissed() {

@Override
public void onCameraTrackingChanged(int currentMode) {
// do nothing
this.cameraMode = currentMode;

if (cameraMode == CameraMode.NONE) {
locationTrackingBtn.setText("None");
} else if (cameraMode == CameraMode.TRACKING) {
locationTrackingBtn.setText("Tracking");
} else if (cameraMode == CameraMode.TRACKING_COMPASS) {
locationTrackingBtn.setText("Tracking Compass");
} else if (cameraMode == CameraMode.TRACKING_GPS) {
locationTrackingBtn.setText("Tracking GPS");
} else if (cameraMode == CameraMode.TRACKING_GPS_NORTH) {
locationTrackingBtn.setText("Tracking GPS North");
}
}
}
2 changes: 1 addition & 1 deletion gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ext {
]

version = [
mapboxMapSdk : '6.0.0-beta.3',
mapboxMapSdk : '6.0.0-beta.5',
mapboxGeocoding : '3.0.0-beta.3',
mapboxGeoJson : '3.0.0-beta.3',
mapboxServices : '2.2.10',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@

import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.style.functions.Function;
import com.mapbox.mapboxsdk.style.layers.FillExtrusionLayer;
import com.mapbox.mapboxsdk.style.light.Light;

import static com.mapbox.mapboxsdk.constants.MapboxConstants.MAXIMUM_ZOOM;
import static com.mapbox.mapboxsdk.constants.MapboxConstants.MINIMUM_ZOOM;
import static com.mapbox.mapboxsdk.style.functions.stops.Stop.stop;
import static com.mapbox.mapboxsdk.style.functions.stops.Stops.exponential;
import static com.mapbox.mapboxsdk.style.expressions.Expression.exponential;
import static com.mapbox.mapboxsdk.style.expressions.Expression.get;
import static com.mapbox.mapboxsdk.style.expressions.Expression.interpolate;
import static com.mapbox.mapboxsdk.style.expressions.Expression.literal;
import static com.mapbox.mapboxsdk.style.expressions.Expression.stop;
import static com.mapbox.mapboxsdk.style.expressions.Expression.zoom;
import static com.mapbox.mapboxsdk.style.layers.Property.NONE;
import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillExtrusionColor;
Expand Down Expand Up @@ -93,13 +96,14 @@ private void initLayer(String belowLayer) {
fillExtrusionLayer.setProperties(
visibility(visible ? VISIBLE : NONE),
fillExtrusionColor(color),
fillExtrusionHeight(Function.composite(
"height",
exponential(
stop(15f, 0f, fillExtrusionHeight(0f)),
stop(16f, 0f, fillExtrusionHeight(0f)),
stop(16f, 1000f, fillExtrusionHeight(1000f))
))),
fillExtrusionHeight(
interpolate(
exponential(1f),
zoom(),
stop(15, literal(0)),
stop(16, get("height"))
)
),
fillExtrusionOpacity(opacity)
);
addLayer(fillExtrusionLayer, belowLayer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@
import static com.mapbox.mapboxsdk.plugins.locationlayer.Utils.generateShadow;
import static com.mapbox.mapboxsdk.plugins.locationlayer.Utils.getBitmapFromDrawable;
import static com.mapbox.mapboxsdk.plugins.locationlayer.Utils.getDrawable;
import static com.mapbox.mapboxsdk.style.functions.Function.zoom;
import static com.mapbox.mapboxsdk.style.functions.stops.Stop.stop;
import static com.mapbox.mapboxsdk.style.functions.stops.Stops.exponential;
import static com.mapbox.mapboxsdk.style.expressions.Expression.exponential;
import static com.mapbox.mapboxsdk.style.expressions.Expression.interpolate;
import static com.mapbox.mapboxsdk.style.expressions.Expression.stop;
import static com.mapbox.mapboxsdk.style.expressions.Expression.zoom;
import static com.mapbox.mapboxsdk.style.layers.Property.ICON_ROTATION_ALIGNMENT_MAP;
import static com.mapbox.mapboxsdk.style.layers.Property.NONE;
import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE;
Expand All @@ -62,7 +63,7 @@
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconSize;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility;

final class LocationLayer implements LocationLayerAnimator.OnAnimationsValuesChangeListener {
final class LocationLayer implements LocationLayerAnimator.OnLayerAnimationsValuesChangeListener {

@RenderMode.Mode
private int renderMode;
Expand Down Expand Up @@ -164,14 +165,14 @@ private void addSymbolLayer(String layerId, String beforeLayerId) {
layer.setProperties(
iconAllowOverlap(true),
iconIgnorePlacement(true),
iconSize(zoom(
exponential(
stop(22f, iconSize(1f)),
stop(12f, iconSize(1f)),
stop(10f, iconSize(0.6f)),
stop(0f, iconSize(0.6f))
).withBase(1f)
)),
iconSize(
interpolate(exponential(1f), zoom(),
stop(22f, 1f),
stop(12f, 1f),
stop(10f, 0.6f),
stop(0f, 0.6f)
)
),
iconRotationAlignment(ICON_ROTATION_ALIGNMENT_MAP));
addLayerToMap(layer, beforeLayerId);
}
Expand Down Expand Up @@ -301,7 +302,9 @@ void setLocationsStale(boolean isStale) {
this.isStale = isStale;
layerMap.get(FOREGROUND_LAYER).setProperties(iconImage(isStale ? FOREGROUND_STALE_ICON : FOREGROUND_ICON));
layerMap.get(BACKGROUND_LAYER).setProperties(iconImage(isStale ? BACKGROUND_STALE_ICON : BACKGROUND_ICON));
layerMap.get(ACCURACY_LAYER).setProperties(visibility(isStale && renderMode != RenderMode.GPS ? NONE : VISIBLE));
if (renderMode != RenderMode.GPS) {
layerMap.get(ACCURACY_LAYER).setProperties(visibility(isStale ? NONE : VISIBLE));
}
}

//
Expand Down
Loading