diff options
Diffstat (limited to 'android')
14 files changed, 96 insertions, 0 deletions
diff --git a/android/java/MapboxGLAndroidSDK/build.gradle b/android/java/MapboxGLAndroidSDK/build.gradle index 44f82831f7..2f09959cc6 100644 --- a/android/java/MapboxGLAndroidSDK/build.gradle +++ b/android/java/MapboxGLAndroidSDK/build.gradle @@ -33,6 +33,7 @@ dependencies { compile 'com.android.support:support-v4:22.2.1' compile 'com.squareup.okhttp:okhttp:2.4.0' compile 'com.mapzen.android:lost:1.0.1' + compile 'com.android.support:design:22.2.1' } android { 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 ed2038c240..953bd6ae0a 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 @@ -7,8 +7,11 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageManager; +import android.content.res.ColorStateList; import android.content.res.TypedArray; import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Color; import android.graphics.Matrix; import android.graphics.PointF; import android.hardware.GeomagneticField; @@ -22,6 +25,8 @@ import android.net.NetworkInfo; import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; +import android.support.design.widget.FloatingActionButton; +import android.support.v4.content.res.ResourcesCompat; import android.support.v4.view.GestureDetectorCompat; import android.support.v4.view.ScaleGestureDetectorCompat; import android.text.TextUtils; @@ -37,6 +42,7 @@ import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.View; import android.view.ViewConfiguration; +import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.ZoomButtonsController; @@ -58,6 +64,7 @@ import com.mapzen.android.lost.api.LostApiClient; import org.apache.commons.validator.routines.UrlValidator; import java.nio.ByteBuffer; import java.util.ArrayList; +import java.util.Date; import java.util.List; // Custom view that shows a Map @@ -141,6 +148,11 @@ public class MapView extends FrameLayout implements LocationListener { private float mCompassBearing; private boolean mCompassValid = false; + // Used for map toggle mode + private FloatingActionButton trackingModeButton; + private int trackingMode = 0; + private long t0 = new Date().getTime(); + // Used to manage Event Listeners private ArrayList<OnMapChangedListener> mOnMapChangedListener; @@ -293,6 +305,20 @@ public class MapView extends FrameLayout implements LocationListener { addView(mCompassView); mCompassView.setOnClickListener(new CompassOnClickListener()); + // Setup tracking mode + trackingModeButton = new FloatingActionButton(mContext); + trackingModeButton.setContentDescription(getResources().getString(R.string.trackingModeButtonContentDescription)); + trackingModeButton.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.background_material_light))); + trackingModeButton.setElevation(4); + trackingModeButton.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.ic_my_location_black_24dp)); + LayoutParams lp2 = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); + lp2.gravity = Gravity.BOTTOM | Gravity.END; + int twentyDp = (int)(20 * mScreenDensity); + lp2.setMargins(twentyDp, twentyDp, twentyDp, twentyDp); + trackingModeButton.setLayoutParams(lp2); + addView(trackingModeButton); + trackingModeButton.setOnClickListener(new ToggleModeClickListener()); + // Setup Support For Listener Tracking // MapView's internal listener is setup in onCreate() mOnMapChangedListener = new ArrayList<OnMapChangedListener>(); @@ -890,6 +916,10 @@ public class MapView extends FrameLayout implements LocationListener { return false; } + if (trackingMode != 0) { + setTrackingMode(0); + } + // Cancel any animation mNativeMapView.cancelTransitions(); // TODO need to test canceling // transitions with touch @@ -1578,6 +1608,9 @@ public class MapView extends FrameLayout implements LocationListener { @Override public void onClick(View view) { + if(trackingMode == 2){ + setTrackingMode(0); + } resetNorth(); } } @@ -1596,6 +1629,12 @@ public class MapView extends FrameLayout implements LocationListener { private void updateLocation(Location location) { if (location != null) { mGpsLocation = location; + + // Update map position if in follow mode + if (trackingMode != 0) { + setCenterCoordinate(new LatLng(mGpsLocation)); + } + updateMap(); } } @@ -1639,6 +1678,16 @@ public class MapView extends FrameLayout implements LocationListener { rotateImageView(mGpsMarker, 0.0f); mGpsMarker.requestLayout(); + // Update direction if tracking mode + if(trackingMode == 2 && mCompassValid){ + // TODO need to do proper filtering (see branch filter-compass) or else map will lock up because of all the compass events + long t = new Date().getTime(); + if((t-t0)>1000){ + t0 = t; + setDirection(-mCompassBearing, true); + } + } + /* // Used For User Location Bearing UI if (mGpsLocation.hasBearing() || mCompassValid) { @@ -1659,4 +1708,49 @@ public class MapView extends FrameLayout implements LocationListener { } } } + + private class ToggleModeClickListener implements OnClickListener { + @Override + public void onClick(View v) { + setTrackingMode((trackingMode + 1) % 3); + } + } + + public void setTrackingMode(int trackingMode) { + + this.trackingMode = trackingMode; + + switch (trackingMode) { + + case 0: { + trackingModeButton.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_my_location_black_24dp, mContext.getTheme())); + trackingModeButton.setColorFilter(Color.TRANSPARENT); + updateMap(); + } + break; + + case 1: { + trackingModeButton.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_my_location_black_24dp, mContext.getTheme())); + trackingModeButton.setColorFilter(Color.BLUE); + if(mGpsLocation != null){ + setCenterCoordinate(new LatLng(mGpsLocation)); + } + updateMap(); + } + break; + + case 2: { + trackingModeButton.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_explore_black_24dp, mContext.getTheme())); + trackingModeButton.setColorFilter(Color.BLUE); + if(mGpsLocation != null){ + setCenterCoordinate(new LatLng(mGpsLocation)); + } + updateMap(); + } + break; + + default: + break; + } + } } diff --git a/android/java/MapboxGLAndroidSDK/src/main/res/drawable-hdpi/ic_explore_black_24dp.png b/android/java/MapboxGLAndroidSDK/src/main/res/drawable-hdpi/ic_explore_black_24dp.png Binary files differnew file mode 100644 index 0000000000..f4bc5acd00 --- /dev/null +++ b/android/java/MapboxGLAndroidSDK/src/main/res/drawable-hdpi/ic_explore_black_24dp.png diff --git a/android/java/MapboxGLAndroidSDK/src/main/res/drawable-hdpi/ic_my_location_black_24dp.png b/android/java/MapboxGLAndroidSDK/src/main/res/drawable-hdpi/ic_my_location_black_24dp.png Binary files differnew file mode 100644 index 0000000000..85e38726dd --- /dev/null +++ b/android/java/MapboxGLAndroidSDK/src/main/res/drawable-hdpi/ic_my_location_black_24dp.png diff --git a/android/java/MapboxGLAndroidSDK/src/main/res/drawable-mdpi/ic_explore_black_24dp.png b/android/java/MapboxGLAndroidSDK/src/main/res/drawable-mdpi/ic_explore_black_24dp.png Binary files differnew file mode 100644 index 0000000000..3c9da64daa --- /dev/null +++ b/android/java/MapboxGLAndroidSDK/src/main/res/drawable-mdpi/ic_explore_black_24dp.png diff --git a/android/java/MapboxGLAndroidSDK/src/main/res/drawable-mdpi/ic_my_location_black_24dp.png b/android/java/MapboxGLAndroidSDK/src/main/res/drawable-mdpi/ic_my_location_black_24dp.png Binary files differnew file mode 100644 index 0000000000..5684aa7dc5 --- /dev/null +++ b/android/java/MapboxGLAndroidSDK/src/main/res/drawable-mdpi/ic_my_location_black_24dp.png diff --git a/android/java/MapboxGLAndroidSDK/src/main/res/drawable-xhdpi/ic_explore_black_24dp.png b/android/java/MapboxGLAndroidSDK/src/main/res/drawable-xhdpi/ic_explore_black_24dp.png Binary files differnew file mode 100644 index 0000000000..2dbd112509 --- /dev/null +++ b/android/java/MapboxGLAndroidSDK/src/main/res/drawable-xhdpi/ic_explore_black_24dp.png diff --git a/android/java/MapboxGLAndroidSDK/src/main/res/drawable-xhdpi/ic_my_location_black_24dp.png b/android/java/MapboxGLAndroidSDK/src/main/res/drawable-xhdpi/ic_my_location_black_24dp.png Binary files differnew file mode 100644 index 0000000000..7faa3455f6 --- /dev/null +++ b/android/java/MapboxGLAndroidSDK/src/main/res/drawable-xhdpi/ic_my_location_black_24dp.png diff --git a/android/java/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/compass.png b/android/java/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/compass.png Binary files differnew file mode 100644 index 0000000000..58e7e08d24 --- /dev/null +++ b/android/java/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/compass.png diff --git a/android/java/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/ic_explore_black_24dp.png b/android/java/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/ic_explore_black_24dp.png Binary files differnew file mode 100644 index 0000000000..11d4c89754 --- /dev/null +++ b/android/java/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/ic_explore_black_24dp.png diff --git a/android/java/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/ic_my_location_black_24dp.png b/android/java/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/ic_my_location_black_24dp.png Binary files differnew file mode 100644 index 0000000000..d3a1ab08c8 --- /dev/null +++ b/android/java/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/ic_my_location_black_24dp.png diff --git a/android/java/MapboxGLAndroidSDK/src/main/res/drawable-xxxhdpi/ic_explore_black_24dp.png b/android/java/MapboxGLAndroidSDK/src/main/res/drawable-xxxhdpi/ic_explore_black_24dp.png Binary files differnew file mode 100644 index 0000000000..684d282b86 --- /dev/null +++ b/android/java/MapboxGLAndroidSDK/src/main/res/drawable-xxxhdpi/ic_explore_black_24dp.png diff --git a/android/java/MapboxGLAndroidSDK/src/main/res/drawable-xxxhdpi/ic_my_location_black_24dp.png b/android/java/MapboxGLAndroidSDK/src/main/res/drawable-xxxhdpi/ic_my_location_black_24dp.png Binary files differnew file mode 100644 index 0000000000..0812b0e31d --- /dev/null +++ b/android/java/MapboxGLAndroidSDK/src/main/res/drawable-xxxhdpi/ic_my_location_black_24dp.png diff --git a/android/java/MapboxGLAndroidSDK/src/main/res/values/strings.xml b/android/java/MapboxGLAndroidSDK/src/main/res/values/strings.xml index df022a4679..78e20893b6 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/res/values/strings.xml +++ b/android/java/MapboxGLAndroidSDK/src/main/res/values/strings.xml @@ -1,4 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> <resources> <string name="compassContentDescription">Map compass. Click to reset the map rotation to North.</string> + <string name="trackingModeButtonContentDescription">Press button to toggle tracking modes (None, Follow, FollowWithHeading)</string> </resources> |