#1856 - Removing FAB from SDK and replacing with intial tracking mode API. Making Compass visible under Toolbar.
@@ -11,7 +11,6 @@ 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;
|
||||
@@ -26,7 +25,6 @@ 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;
|
||||
@@ -126,13 +124,18 @@ public class MapView extends FrameLayout implements LocationListener {
|
||||
// Holds the context
|
||||
private Context mContext;
|
||||
|
||||
// Used for GPS
|
||||
// Used for GPS / Location
|
||||
private boolean mIsGpsOn = false;
|
||||
private LostApiClient mLocationClient;
|
||||
private LocationRequest mLocationRequest;
|
||||
private ImageView mGpsMarker;
|
||||
private Location mGpsLocation;
|
||||
|
||||
public enum UserLocationTrackingMode {
|
||||
NONE, FOLLOW, FOLLOW_BEARING;
|
||||
}
|
||||
private UserLocationTrackingMode userLocationTrackingMode = UserLocationTrackingMode.FOLLOW;
|
||||
|
||||
// Used for compass
|
||||
private boolean mIsCompassEnabled = true;
|
||||
private ImageView mCompassView;
|
||||
@@ -149,13 +152,13 @@ public class MapView extends FrameLayout implements LocationListener {
|
||||
private boolean mCompassValid = false;
|
||||
|
||||
// Used for map toggle mode
|
||||
private FloatingActionButton trackingModeButton;
|
||||
private int trackingMode = 0;
|
||||
// private FloatingActionButton trackingModeButton;
|
||||
private long t0 = new Date().getTime();
|
||||
|
||||
// Used to manage Event Listeners
|
||||
private ArrayList<OnMapChangedListener> mOnMapChangedListener;
|
||||
|
||||
|
||||
//
|
||||
// Properties
|
||||
//
|
||||
@@ -299,26 +302,12 @@ public class MapView extends FrameLayout implements LocationListener {
|
||||
mCompassView.setContentDescription(getResources().getString(R.string.compassContentDescription));
|
||||
LayoutParams lp = new FrameLayout.LayoutParams((int)(48 * mScreenDensity), (int)(48 * mScreenDensity));
|
||||
lp.gravity = Gravity.TOP | Gravity.END;
|
||||
int tenDp = (int)(10 * mScreenDensity);
|
||||
lp.setMargins(tenDp, tenDp, tenDp, tenDp);
|
||||
int twentyDp = (int)(20 * mScreenDensity);
|
||||
lp.setMargins(twentyDp, twentyDp * 4, twentyDp, twentyDp);
|
||||
mCompassView.setLayoutParams(lp);
|
||||
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>();
|
||||
@@ -512,6 +501,14 @@ public class MapView extends FrameLayout implements LocationListener {
|
||||
mNativeMapView.toggleCollisionDebug();
|
||||
}
|
||||
|
||||
public UserLocationTrackingMode getUserLocationTrackingMode() {
|
||||
return userLocationTrackingMode;
|
||||
}
|
||||
|
||||
public void setUserLocationTrackingMode(UserLocationTrackingMode userLocationTrackingMode) {
|
||||
this.userLocationTrackingMode = userLocationTrackingMode;
|
||||
}
|
||||
|
||||
public boolean isFullyLoaded() {
|
||||
return mNativeMapView.isFullyLoaded();
|
||||
}
|
||||
@@ -916,10 +913,6 @@ 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
|
||||
@@ -1608,11 +1601,9 @@ public class MapView extends FrameLayout implements LocationListener {
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if(trackingMode == 2){
|
||||
setTrackingMode(0);
|
||||
}
|
||||
resetNorth();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1629,12 +1620,6 @@ 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();
|
||||
}
|
||||
}
|
||||
@@ -1679,7 +1664,7 @@ public class MapView extends FrameLayout implements LocationListener {
|
||||
mGpsMarker.requestLayout();
|
||||
|
||||
// Update direction if tracking mode
|
||||
if(trackingMode == 2 && mCompassValid){
|
||||
if(userLocationTrackingMode == UserLocationTrackingMode.FOLLOW_BEARING && 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){
|
||||
@@ -1688,6 +1673,13 @@ public class MapView extends FrameLayout implements LocationListener {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
// Update map position if NOT in NONE mode
|
||||
if (userLocationTrackingMode != UserLocationTrackingMode.NONE) {
|
||||
setCenterCoordinate(new LatLng(mGpsLocation));
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
// Used For User Location Bearing UI
|
||||
if (mGpsLocation.hasBearing() || mCompassValid) {
|
||||
@@ -1708,49 +1700,4 @@ 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Before Width: | Height: | Size: 465 B |
|
Before Width: | Height: | Size: 549 B |
|
Before Width: | Height: | Size: 322 B |
|
Before Width: | Height: | Size: 341 B |
|
Before Width: | Height: | Size: 624 B |
|
Before Width: | Height: | Size: 660 B |
|
Before Width: | Height: | Size: 913 B |
|
Before Width: | Height: | Size: 976 B |
|
Before Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 1.3 KiB |
@@ -1,5 +1,4 @@
|
||||
<?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>
|
||||
|
||||