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

Commit

Permalink
Merge branch '1856-material-take-2'
Browse files Browse the repository at this point in the history
  • Loading branch information
bleege committed Aug 12, 2015
2 parents 772238a + 72aaf39 commit b61aabd
Show file tree
Hide file tree
Showing 32 changed files with 332 additions and 300 deletions.
2 changes: 1 addition & 1 deletion .mason
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
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;
Expand All @@ -25,8 +22,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;
Expand All @@ -42,7 +37,6 @@
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;
Expand Down Expand Up @@ -126,13 +120,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;
Expand All @@ -149,13 +148,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
//
Expand Down Expand Up @@ -309,20 +308,6 @@ private void initialize(Context context, AttributeSet attrs) {
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>();
Expand Down Expand Up @@ -516,6 +501,14 @@ public void toggleDebug() {
mNativeMapView.toggleCollisionDebug();
}

public UserLocationTrackingMode getUserLocationTrackingMode() {
return userLocationTrackingMode;
}

public void setUserLocationTrackingMode(UserLocationTrackingMode userLocationTrackingMode) {
this.userLocationTrackingMode = userLocationTrackingMode;
}

public boolean isFullyLoaded() {
return mNativeMapView.isFullyLoaded();
}
Expand Down Expand Up @@ -920,10 +913,6 @@ public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float d
return false;
}

if (trackingMode != 0) {
setTrackingMode(0);
}

// Cancel any animation
mNativeMapView.cancelTransitions(); // TODO need to test canceling
// transitions with touch
Expand Down Expand Up @@ -1612,11 +1601,9 @@ private class CompassOnClickListener implements View.OnClickListener {

@Override
public void onClick(View view) {
if(trackingMode == 2){
setTrackingMode(0);
}
resetNorth();
}

}

/**
Expand All @@ -1633,12 +1620,6 @@ public void onLocationChanged(Location location) {
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();
}
}
Expand Down Expand Up @@ -1683,7 +1664,7 @@ private void updateMap() {
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){
Expand All @@ -1692,6 +1673,15 @@ private void updateMap() {
}
}

/*
// TODO - Too much overhead on main thread. Needs to be refactored before it
// can be re-enabled
// 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) {
Expand All @@ -1712,49 +1702,4 @@ private void updateMap() {
}
}
}

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;
}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -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>
Loading

0 comments on commit b61aabd

Please sign in to comment.