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

Merge LocationLayerPlugin to the Maps SDK #12786

Merged
merged 14 commits into from
Sep 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 6 additions & 2 deletions platform/android/MapboxGLAndroidSDK/build.gradle
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
apply plugin: 'com.android.library'
apply plugin: "com.jaredsburrows.license"
apply plugin: 'kotlin-android'

dependencies {
lintChecks project(":MapboxGLAndroidSDKLint")
api (dependenciesList.mapboxAndroidTelemetry) {
api(dependenciesList.mapboxAndroidTelemetry) {
exclude group: 'com.android.support', module: 'appcompat-v7'
}
api dependenciesList.mapboxJavaGeoJSON
api (dependenciesList.mapboxAndroidGestures) {
api(dependenciesList.mapboxAndroidGestures) {
exclude group: 'com.android.support', module: 'appcompat-v7'
}
implementation dependenciesList.mapboxJavaTurf
implementation dependenciesList.supportAppcompatV7
implementation dependenciesList.supportAnnotations
implementation dependenciesList.supportFragmentV4
implementation dependenciesList.okhttp3
testImplementation dependenciesList.junit
testImplementation dependenciesList.mockito
testImplementation dependenciesList.robolectric
testImplementation dependenciesList.kotlinLib
}

android {
compileSdkVersion androidVersions.compileSdkVersion
buildToolsVersion androidVersions.buildToolsVersion

defaultConfig {
vectorDrawables.useSupportLibrary = true
minSdkVersion androidVersions.minSdkVersion
targetSdkVersion androidVersions.targetSdkVersion
buildConfigField "String", "GIT_REVISION_SHORT", String.format("\"%s\"", getGitRevision())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.mapbox.mapboxsdk.location;

import android.animation.ValueAnimator;

import java.util.List;

class CameraCompassBearingAnimator extends MapboxFloatAnimator<MapboxAnimator.OnCameraAnimationsValuesChangeListener> {
CameraCompassBearingAnimator(Float previous, Float target,
List<OnCameraAnimationsValuesChangeListener> updateListeners) {
super(previous, target, updateListeners);
}

@Override
int provideAnimatorType() {
return ANIMATOR_CAMERA_COMPASS_BEARING;
}

@Override
public void onAnimationUpdate(ValueAnimator animation) {
for (OnCameraAnimationsValuesChangeListener listener : updateListeners) {
listener.onNewCompassBearingValue((Float) animation.getAnimatedValue());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.mapbox.mapboxsdk.location;

import android.animation.ValueAnimator;

import java.util.List;

class CameraGpsBearingAnimator extends MapboxFloatAnimator<MapboxAnimator.OnCameraAnimationsValuesChangeListener> {
CameraGpsBearingAnimator(Float previous, Float target, List<OnCameraAnimationsValuesChangeListener> updateListeners) {
super(previous, target, updateListeners);
}

@Override
int provideAnimatorType() {
return ANIMATOR_CAMERA_GPS_BEARING;
}

@Override
public void onAnimationUpdate(ValueAnimator animation) {
for (OnCameraAnimationsValuesChangeListener listener : updateListeners) {
listener.onNewGpsBearingValue((Float) animation.getAnimatedValue());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.mapbox.mapboxsdk.location;

import android.animation.ValueAnimator;

import com.mapbox.mapboxsdk.geometry.LatLng;

import java.util.List;

class CameraLatLngAnimator extends MapboxLatLngAnimator<MapboxAnimator.OnCameraAnimationsValuesChangeListener> {
CameraLatLngAnimator(LatLng previous, LatLng target, List<OnCameraAnimationsValuesChangeListener> updateListeners) {
super(previous, target, updateListeners);
}

@Override
int provideAnimatorType() {
return ANIMATOR_CAMERA_LATLNG;
}

@Override
public void onAnimationUpdate(ValueAnimator animation) {
for (OnCameraAnimationsValuesChangeListener listener : updateListeners) {
listener.onNewLatLngValue((LatLng) animation.getAnimatedValue());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.mapbox.mapboxsdk.location;

import android.support.annotation.NonNull;

import com.mapbox.mapboxsdk.location.modes.CameraMode;
import com.mapbox.mapboxsdk.location.modes.RenderMode;

/**
* Interface defining the source of compass heading data that is
* consumed by the {@link LocationComponent} when in compass related
* {@link RenderMode} or
* {@link CameraMode}s.
*/
public interface CompassEngine {

/**
* Adds a {@link CompassListener} that can be used to
* receive heading and state changes.
*
* @param compassListener to be added
*/
void addCompassListener(@NonNull CompassListener compassListener);

/**
* Removes a {@link CompassListener} that can be used to
* receive heading and state changes.
*
* @param compassListener to be removed
*/
void removeCompassListener(@NonNull CompassListener compassListener);

/**
* Returns the last heading value produced and pushed via
* a compass listener.
*
* @return last heading value
*/
float getLastHeading();

/**
* Provides the last know accuracy status from the sensor manager.
* <p>
* An integer value which is identical to the {@code SensorManager} class constants:
* <ul>
* <li>{@link android.hardware.SensorManager#SENSOR_STATUS_NO_CONTACT}</li>
* <li>{@link android.hardware.SensorManager#SENSOR_STATUS_UNRELIABLE}</li>
* <li>{@link android.hardware.SensorManager#SENSOR_STATUS_ACCURACY_LOW}</li>
* <li>{@link android.hardware.SensorManager#SENSOR_STATUS_ACCURACY_MEDIUM}</li>
* <li>{@link android.hardware.SensorManager#SENSOR_STATUS_ACCURACY_HIGH}</li>
* </ul>
*
* @return last accuracy status
*/
int getLastAccuracySensorStatus();

/**
* Lifecycle method that can be used for adding or releasing resources.
*/
void onStart();

/**
* Lifecycle method that can be used for adding or releasing resources.
*/
void onStop();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.mapbox.mapboxsdk.location;

/**
* Callbacks related to the compass
*/
public interface CompassListener {

/**
* Callback's invoked when a new compass update occurs. You can listen into the compass updates
* using {@link LocationComponent#addCompassListener(CompassListener)} and implementing these
* callbacks. Note that this interface is also used internally to to update the UI chevron/arrow.
*
* @param userHeading the new compass heading
*/
void onCompassChanged(float userHeading);

/**
* This gets invoked when the compass accuracy status changes from one value to another. It
* provides an integer value which is identical to the {@code SensorManager} class constants:
* <ul>
* <li>{@link android.hardware.SensorManager#SENSOR_STATUS_NO_CONTACT}</li>
* <li>{@link android.hardware.SensorManager#SENSOR_STATUS_UNRELIABLE}</li>
* <li>{@link android.hardware.SensorManager#SENSOR_STATUS_ACCURACY_LOW}</li>
* <li>{@link android.hardware.SensorManager#SENSOR_STATUS_ACCURACY_MEDIUM}</li>
* <li>{@link android.hardware.SensorManager#SENSOR_STATUS_ACCURACY_HIGH}</li>
* </ul>
*
* @param compassStatus the new accuracy of this sensor, one of
* {@code SensorManager.SENSOR_STATUS_*}
*/
void onCompassAccuracyChange(int compassStatus);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.mapbox.mapboxsdk.location;

import android.animation.TypeEvaluator;

import com.mapbox.mapboxsdk.geometry.LatLng;

class LatLngEvaluator implements TypeEvaluator<LatLng> {

private final LatLng latLng = new LatLng();

@Override
public LatLng evaluate(float fraction, LatLng startValue, LatLng endValue) {
latLng.setLatitude(startValue.getLatitude()
+ ((endValue.getLatitude() - startValue.getLatitude()) * fraction));
latLng.setLongitude(startValue.getLongitude()
+ ((endValue.getLongitude() - startValue.getLongitude()) * fraction));
return latLng;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.mapbox.mapboxsdk.location;

import android.animation.ValueAnimator;

import java.util.List;

class LayerAccuracyAnimator extends MapboxFloatAnimator<MapboxAnimator.OnLayerAnimationsValuesChangeListener> {

LayerAccuracyAnimator(Float previous, Float target, List<OnLayerAnimationsValuesChangeListener> updateListeners) {
super(previous, target, updateListeners);
}

@Override
int provideAnimatorType() {
return ANIMATOR_LAYER_ACCURACY;
}

@Override
public void onAnimationUpdate(ValueAnimator animation) {
for (OnLayerAnimationsValuesChangeListener listener : updateListeners) {
listener.onNewAccuracyRadiusValue((Float) animation.getAnimatedValue());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.mapbox.mapboxsdk.location;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.support.annotation.ColorInt;
import android.support.annotation.DrawableRes;
import android.support.v4.content.ContextCompat;

import com.mapbox.mapboxsdk.R;

import static com.mapbox.mapboxsdk.location.Utils.generateShadow;
import static com.mapbox.mapboxsdk.location.Utils.getBitmapFromDrawable;
import static com.mapbox.mapboxsdk.location.Utils.getDrawable;

class LayerBitmapProvider {

private final Context context;

LayerBitmapProvider(Context context) {
this.context = context;
}

Bitmap generateBitmap(@DrawableRes int drawableRes, @ColorInt Integer tintColor) {
Drawable drawable = getDrawable(context, drawableRes, tintColor);
return getBitmapFromDrawable(drawable);
}

Bitmap generateShadowBitmap(LocationComponentOptions options) {
Drawable shadowDrawable = ContextCompat.getDrawable(context, R.drawable.mapbox_user_icon_shadow);
return generateShadow(shadowDrawable, options.elevation());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.mapbox.mapboxsdk.location;

import android.animation.ValueAnimator;

import java.util.List;

class LayerCompassBearingAnimator extends MapboxFloatAnimator<MapboxAnimator.OnLayerAnimationsValuesChangeListener> {
LayerCompassBearingAnimator(Float previous,
Float target, List<OnLayerAnimationsValuesChangeListener> updateListeners) {
super(previous, target, updateListeners);
}

@Override
int provideAnimatorType() {
return ANIMATOR_LAYER_COMPASS_BEARING;
}

@Override
public void onAnimationUpdate(ValueAnimator animation) {
for (OnLayerAnimationsValuesChangeListener listener : updateListeners) {
listener.onNewCompassBearingValue((Float) animation.getAnimatedValue());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.mapbox.mapboxsdk.location;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.mapbox.geojson.Feature;
import com.mapbox.geojson.Point;

import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_COMPASS_BEARING;
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_GPS_BEARING;
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_LOCATION_STALE;

class LayerFeatureProvider {

@NonNull
Feature generateLocationFeature(@Nullable Feature locationFeature, LocationComponentOptions options) {
if (locationFeature != null) {
return locationFeature;
}
locationFeature = Feature.fromGeometry(Point.fromLngLat(0.0, 0.0));
locationFeature.addNumberProperty(PROPERTY_GPS_BEARING, 0f);
locationFeature.addNumberProperty(PROPERTY_COMPASS_BEARING, 0f);
locationFeature.addBooleanProperty(PROPERTY_LOCATION_STALE, options.enableStaleState());
return locationFeature;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.mapbox.mapboxsdk.location;

import android.animation.ValueAnimator;

import java.util.List;

class LayerGpsBearingAnimator extends MapboxFloatAnimator<MapboxAnimator.OnLayerAnimationsValuesChangeListener> {
LayerGpsBearingAnimator(Float previous, Float target, List<OnLayerAnimationsValuesChangeListener> updateListeners) {
super(previous, target, updateListeners);
}

@Override
int provideAnimatorType() {
return ANIMATOR_LAYER_GPS_BEARING;
}

@Override
public void onAnimationUpdate(ValueAnimator animation) {
for (OnLayerAnimationsValuesChangeListener listener : updateListeners) {
listener.onNewGpsBearingValue((Float) animation.getAnimatedValue());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.mapbox.mapboxsdk.location;

import android.animation.ValueAnimator;

import com.mapbox.mapboxsdk.geometry.LatLng;

import java.util.List;

class LayerLatLngAnimator extends MapboxLatLngAnimator<MapboxAnimator.OnLayerAnimationsValuesChangeListener> {
LayerLatLngAnimator(LatLng previous, LatLng target, List<OnLayerAnimationsValuesChangeListener> updateListeners) {
super(previous, target, updateListeners);
}

@Override
int provideAnimatorType() {
return ANIMATOR_LAYER_LATLNG;
}

@Override
public void onAnimationUpdate(ValueAnimator animation) {
for (OnLayerAnimationsValuesChangeListener listener : updateListeners) {
listener.onNewLatLngValue((LatLng) animation.getAnimatedValue());
}
}
}
Loading