added tracking modes
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
After Width: | Height: | Size: 465 B |
|
After Width: | Height: | Size: 549 B |
|
After Width: | Height: | Size: 322 B |
|
After Width: | Height: | Size: 341 B |
|
After Width: | Height: | Size: 624 B |
|
After Width: | Height: | Size: 660 B |
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 913 B |
|
After Width: | Height: | Size: 976 B |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
@@ -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>
|
||||
|
||||