Merge branch '1856-material-take-2'
2
.mason
@@ -7,11 +7,8 @@ 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;
|
||||
@@ -25,8 +22,6 @@ 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;
|
||||
@@ -42,7 +37,6 @@ 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;
|
||||
@@ -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;
|
||||
@@ -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
|
||||
//
|
||||
@@ -309,20 +308,6 @@ 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>();
|
||||
@@ -516,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();
|
||||
}
|
||||
@@ -920,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
|
||||
@@ -1612,11 +1601,9 @@ public class MapView extends FrameLayout implements LocationListener {
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if(trackingMode == 2){
|
||||
setTrackingMode(0);
|
||||
}
|
||||
resetNorth();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1633,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();
|
||||
}
|
||||
}
|
||||
@@ -1683,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){
|
||||
@@ -1692,6 +1673,15 @@ public class MapView extends FrameLayout implements LocationListener {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
// 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) {
|
||||
@@ -1712,49 +1702,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>
|
||||
|
||||
@@ -2,13 +2,18 @@ package com.mapbox.mapboxgl.testapp;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PointF;
|
||||
import android.location.Location;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.design.widget.NavigationView;
|
||||
import android.support.v4.view.GravityCompat;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
@@ -27,13 +32,12 @@ import com.mapbox.mapboxgl.annotations.PolylineOptions;
|
||||
import com.mapbox.mapboxgl.geometry.LatLng;
|
||||
import com.mapbox.mapboxgl.views.MapView;
|
||||
import io.fabric.sdk.android.Fabric;
|
||||
import org.json.JSONException;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class MainActivity extends ActionBarActivity {
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
private static final String TAG = "MainActivity";
|
||||
|
||||
@@ -49,6 +53,7 @@ public class MainActivity extends ActionBarActivity {
|
||||
//
|
||||
|
||||
// Used for the UI
|
||||
private DrawerLayout mDrawerLayout;
|
||||
private MapView mapView;
|
||||
private TextView mFpsTextView;
|
||||
private FrameLayout mMapFrameLayout;
|
||||
@@ -58,10 +63,10 @@ public class MainActivity extends ActionBarActivity {
|
||||
private ArrayAdapter mSatelliteClassAdapter;
|
||||
|
||||
// Used for GPS
|
||||
private MenuItem mGpsMenuItem;
|
||||
private FloatingActionButton locationFAB;
|
||||
|
||||
// Used for markers
|
||||
private boolean mIsMarkersOn = false;
|
||||
// Used for Annotations
|
||||
private boolean mIsAnnotationsOn = false;
|
||||
|
||||
private Marker marker;
|
||||
|
||||
@@ -79,6 +84,21 @@ public class MainActivity extends ActionBarActivity {
|
||||
|
||||
// Load the layout
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
final ActionBar ab = getSupportActionBar();
|
||||
ab.setHomeAsUpIndicator(R.drawable.ic_menu);
|
||||
ab.setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
|
||||
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
|
||||
if (navigationView != null) {
|
||||
setupDrawerContent(navigationView);
|
||||
}
|
||||
|
||||
mapView = (MapView) findViewById(R.id.mainMapView);
|
||||
// Load the access token
|
||||
try {
|
||||
@@ -93,6 +113,9 @@ public class MainActivity extends ActionBarActivity {
|
||||
mapView.setOnFpsChangedListener(new MyOnFpsChangedListener());
|
||||
mapView.addOnMapChangedListener(new MyOnMapChangedListener());
|
||||
|
||||
changeMapStyle(getString(R.string.styleURLMapboxStreets));
|
||||
navigationView.getMenu().findItem(R.id.actionStyleMapboxStreets).setChecked(true);
|
||||
|
||||
final GestureDetector gestureDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {
|
||||
public void onLongPress(final MotionEvent e) {
|
||||
float x = e.getX();
|
||||
@@ -119,23 +142,30 @@ public class MainActivity extends ActionBarActivity {
|
||||
mFpsTextView = (TextView) findViewById(R.id.view_fps);
|
||||
mFpsTextView.setText("");
|
||||
|
||||
mMapFrameLayout = (FrameLayout) findViewById(R.id.layout_map);
|
||||
// Add a toolbar as the action bar
|
||||
Toolbar mainToolbar = (Toolbar) findViewById(R.id.toolbar_main);
|
||||
setSupportActionBar(mainToolbar);
|
||||
getSupportActionBar().setDisplayShowTitleEnabled(false);
|
||||
// mMapFrameLayout = (FrameLayout) findViewById(R.id.layout_map);
|
||||
|
||||
// Add the spinner to select map styles
|
||||
Spinner styleSpinner = (Spinner) findViewById(R.id.spinner_style);
|
||||
ArrayAdapter styleAdapter = ArrayAdapter.createFromResource(getSupportActionBar().getThemedContext(),
|
||||
R.array.style_list, android.R.layout.simple_spinner_dropdown_item);
|
||||
styleSpinner.setAdapter(styleAdapter);
|
||||
styleSpinner.setOnItemSelectedListener(new StyleSpinnerListener());
|
||||
locationFAB = (FloatingActionButton)findViewById(R.id.locationFAB);
|
||||
locationFAB.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// Toggle GPS position updates
|
||||
toggleGps(!mapView.isMyLocationEnabled());
|
||||
updateMap();
|
||||
// Snackbar.make(v, "Snack time!", Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
// Add the spinner to select class styles
|
||||
mClassSpinner = (Spinner) findViewById(R.id.spinner_class);
|
||||
mOutdoorsClassAdapter = ArrayAdapter.createFromResource(getSupportActionBar().getThemedContext(),
|
||||
R.array.outdoors_class_list, android.R.layout.simple_spinner_dropdown_item);
|
||||
*/
|
||||
|
||||
// Set default UI state
|
||||
navigationView.getMenu().findItem(R.id.action_compass).setChecked(mapView.isCompassEnabled());
|
||||
navigationView.getMenu().findItem(R.id.action_debug).setChecked(mapView.isDebugActive());
|
||||
navigationView.getMenu().findItem(R.id.action_markers).setChecked(mIsAnnotationsOn);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
mapView.setMyLocationEnabled(savedInstanceState.getBoolean(STATE_IS_GPS_ON, false));
|
||||
@@ -207,58 +237,104 @@ public class MainActivity extends ActionBarActivity {
|
||||
// Other events
|
||||
//
|
||||
|
||||
// Adds items to the action bar menu
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.menu_main, menu);
|
||||
mGpsMenuItem = menu.findItem(R.id.action_gps);
|
||||
if (mapView.isMyLocationEnabled()) {
|
||||
mGpsMenuItem.setIcon(R.drawable.ic_action_location_found);
|
||||
} else {
|
||||
mGpsMenuItem.setIcon(R.drawable.ic_action_location_searching);
|
||||
}
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
// Called when pressing action bar items
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_gps:
|
||||
// Toggle GPS position updates
|
||||
toggleGps(!mapView.isMyLocationEnabled());
|
||||
updateMap();
|
||||
case android.R.id.home:
|
||||
mDrawerLayout.openDrawer(GravityCompat.START);
|
||||
return true;
|
||||
|
||||
case R.id.action_debug:
|
||||
// Toggle debug mode
|
||||
mapView.toggleDebug();
|
||||
|
||||
// Show the FPS counter
|
||||
if (mapView.isDebugActive()) {
|
||||
mFpsTextView.setVisibility(View.VISIBLE);
|
||||
mFpsTextView.setText(getResources().getString(R.string.label_fps));
|
||||
} else {
|
||||
mFpsTextView.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
return true;
|
||||
|
||||
case R.id.action_markers:
|
||||
// Toggle markers
|
||||
toggleMarkers(!mIsMarkersOn);
|
||||
return true;
|
||||
|
||||
case R.id.action_compass:
|
||||
// Toggle compass
|
||||
mapView.setCompassEnabled(!mapView.isCompassEnabled());
|
||||
return true;
|
||||
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void setupDrawerContent(NavigationView navigationView) {
|
||||
navigationView.setNavigationItemSelectedListener(
|
||||
new NavigationView.OnNavigationItemSelectedListener() {
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(MenuItem menuItem) {
|
||||
mDrawerLayout.closeDrawers();
|
||||
|
||||
// Respond To Selection
|
||||
switch (menuItem.getItemId()) {
|
||||
|
||||
case R.id.action_debug:
|
||||
// Toggle debug mode
|
||||
mapView.toggleDebug();
|
||||
|
||||
menuItem.setChecked(mapView.isDebugActive());
|
||||
|
||||
// Show the FPS counter
|
||||
if (mapView.isDebugActive()) {
|
||||
mFpsTextView.setVisibility(View.VISIBLE);
|
||||
mFpsTextView.setText(getResources().getString(R.string.label_fps));
|
||||
} else {
|
||||
mFpsTextView.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
break;
|
||||
|
||||
case R.id.action_markers:
|
||||
// Toggle markers
|
||||
toggleAnnotations(!mIsAnnotationsOn);
|
||||
menuItem.setChecked(mIsAnnotationsOn);
|
||||
break;
|
||||
|
||||
case R.id.action_compass:
|
||||
// Toggle compass
|
||||
mapView.setCompassEnabled(!mapView.isCompassEnabled());
|
||||
menuItem.setChecked(mapView.isCompassEnabled());
|
||||
break;
|
||||
|
||||
/*
|
||||
case R.id.followNone:
|
||||
mapView.setUserLocationTrackingMode(MapView.UserLocationTrackingMode.NONE);
|
||||
break;
|
||||
|
||||
case R.id.followFollow:
|
||||
mapView.setUserLocationTrackingMode(MapView.UserLocationTrackingMode.FOLLOW);
|
||||
break;
|
||||
|
||||
case R.id.followBearing:
|
||||
mapView.setUserLocationTrackingMode(MapView.UserLocationTrackingMode.FOLLOW_BEARING);
|
||||
break;
|
||||
*/
|
||||
|
||||
case R.id.actionStyleMapboxStreets:
|
||||
changeMapStyle(getString(R.string.styleURLMapboxStreets));
|
||||
menuItem.setChecked(true);
|
||||
break;
|
||||
|
||||
case R.id.actionStyleEmerald:
|
||||
changeMapStyle(getString(R.string.styleURLEmerald));
|
||||
menuItem.setChecked(true);
|
||||
break;
|
||||
|
||||
case R.id.actionStyleLight:
|
||||
changeMapStyle(getString(R.string.styleURLLight));
|
||||
menuItem.setChecked(true);
|
||||
break;
|
||||
|
||||
case R.id.actionStyleDark:
|
||||
changeMapStyle(getString(R.string.styleURLDark));
|
||||
menuItem.setChecked(true);
|
||||
break;
|
||||
|
||||
case R.id.actionStyleSatellite:
|
||||
changeMapStyle(getString(R.string.styleURLSatellite));
|
||||
menuItem.setChecked(true);
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void changeMapStyle(@NonNull String styleURL) {
|
||||
mapView.setStyleUrl(styleURL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enabled / Disable GPS location updates along with updating the UI
|
||||
* @param enableGps true if GPS is to be enabled, false if GPS is to be disabled
|
||||
@@ -268,36 +344,39 @@ public class MainActivity extends ActionBarActivity {
|
||||
if (enableGps) {
|
||||
if (!mapView.isMyLocationEnabled()) {
|
||||
mapView.setMyLocationEnabled(enableGps);
|
||||
if (mGpsMenuItem != null) {
|
||||
mGpsMenuItem.setIcon(R.drawable.ic_action_location_found);
|
||||
Location location = mapView.getMyLocation();
|
||||
if (location != null) {
|
||||
mapView.setZoomLevel(8);
|
||||
mapView.setCenterCoordinate(new LatLng(location));
|
||||
}
|
||||
locationFAB.setColorFilter(getResources().getColor(R.color.primary));
|
||||
}
|
||||
} else {
|
||||
if (mapView.isMyLocationEnabled()) {
|
||||
mapView.setMyLocationEnabled(enableGps);
|
||||
if (mGpsMenuItem != null) {
|
||||
mGpsMenuItem.setIcon(R.drawable.ic_action_location_searching);
|
||||
}
|
||||
locationFAB.setColorFilter(Color.TRANSPARENT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable / Disable markers.
|
||||
* Enable / Disable Annotations.
|
||||
*
|
||||
* @param enableMarkers
|
||||
* @param enableAnnotations True to display, False to hide
|
||||
*/
|
||||
private void toggleMarkers(boolean enableMarkers) {
|
||||
if (enableMarkers) {
|
||||
if (!mIsMarkersOn) {
|
||||
mIsMarkersOn = true;
|
||||
private void toggleAnnotations(boolean enableAnnotations) {
|
||||
if (enableAnnotations) {
|
||||
if (!mIsAnnotationsOn) {
|
||||
mIsAnnotationsOn = true;
|
||||
addMarkers();
|
||||
addPolyline();
|
||||
addPolygon();
|
||||
mapView.setZoomLevel(7);
|
||||
mapView.setCenterCoordinate(new LatLng(38.11727, -122.22839));
|
||||
}
|
||||
} else {
|
||||
if (mIsMarkersOn) {
|
||||
mIsMarkersOn = false;
|
||||
if (mIsAnnotationsOn) {
|
||||
mIsAnnotationsOn = false;
|
||||
removeAnnotations();
|
||||
}
|
||||
}
|
||||
@@ -328,9 +407,8 @@ public class MainActivity extends ActionBarActivity {
|
||||
.add(latLngs)
|
||||
.width(2)
|
||||
.color(Color.RED));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (JSONException e) {
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Error adding Polyline: "+ e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -347,9 +425,8 @@ public class MainActivity extends ActionBarActivity {
|
||||
.strokeColor(Color.MAGENTA)
|
||||
.fillColor(Color.BLUE));
|
||||
Polygon polygon = map.addPolygons(opts).get(0);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (JSONException e) {
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Error adding Polygon: "+ e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -358,70 +435,6 @@ public class MainActivity extends ActionBarActivity {
|
||||
mapView.removeAnnotations();
|
||||
}
|
||||
|
||||
// This class handles style change events
|
||||
private class StyleSpinnerListener implements AdapterView.OnItemSelectedListener {
|
||||
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
switch (position) {
|
||||
|
||||
// Mapbox Streets
|
||||
case 0:
|
||||
mapView.setStyleUrl("asset://styles/mapbox-streets-v7.json");
|
||||
mapView.removeAllStyleClasses();
|
||||
mClassSpinner.setVisibility(View.INVISIBLE);
|
||||
mClassSpinner.setAdapter(null);
|
||||
mClassSpinner.setOnItemSelectedListener(null);
|
||||
break;
|
||||
|
||||
// Emerald
|
||||
case 1:
|
||||
mapView.setStyleUrl("asset://styles/emerald-v7.json");
|
||||
mapView.removeAllStyleClasses();
|
||||
mClassSpinner.setVisibility(View.INVISIBLE);
|
||||
mClassSpinner.setAdapter(null);
|
||||
mClassSpinner.setOnItemSelectedListener(null);
|
||||
break;
|
||||
|
||||
// Light
|
||||
case 2:
|
||||
mapView.setStyleUrl("asset://styles/light-v7.json");
|
||||
mapView.removeAllStyleClasses();
|
||||
mClassSpinner.setVisibility(View.INVISIBLE);
|
||||
mClassSpinner.setAdapter(null);
|
||||
mClassSpinner.setOnItemSelectedListener(null);
|
||||
break;
|
||||
|
||||
// Dark
|
||||
case 3:
|
||||
mapView.setStyleUrl("asset://styles/dark-v7.json");
|
||||
mapView.removeAllStyleClasses();
|
||||
mClassSpinner.setVisibility(View.INVISIBLE);
|
||||
mClassSpinner.setAdapter(null);
|
||||
mClassSpinner.setOnItemSelectedListener(null);
|
||||
break;
|
||||
|
||||
// Outdoors
|
||||
case 4:
|
||||
mapView.setStyleUrl("asset://styles/outdoors-v7.json");
|
||||
mapView.removeAllStyleClasses();
|
||||
mClassSpinner.setVisibility(View.VISIBLE);
|
||||
mClassSpinner.setAdapter(mOutdoorsClassAdapter);
|
||||
mClassSpinner.setOnItemSelectedListener(new OutdoorClassSpinnerListener());
|
||||
break;
|
||||
|
||||
default:
|
||||
onNothingSelected(parent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
mapView.setStyleUrl("");
|
||||
}
|
||||
}
|
||||
|
||||
// This class handles outdoor class change events
|
||||
private class OutdoorClassSpinnerListener implements AdapterView.OnItemSelectedListener {
|
||||
|
||||
|
||||
|
After Width: | Height: | Size: 116 B |
|
After Width: | Height: | Size: 546 B |
|
After Width: | Height: | Size: 99 B |
|
After Width: | Height: | Size: 350 B |
|
After Width: | Height: | Size: 135 B |
|
After Width: | Height: | Size: 687 B |
|
After Width: | Height: | Size: 183 B |
|
After Width: | Height: | Size: 1012 B |
|
After Width: | Height: | Size: 235 B |
|
After Width: | Height: | Size: 1.3 KiB |
@@ -1,59 +1,70 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
|
||||
<android.support.v4.widget.DrawerLayout
|
||||
android:id="@+id/drawer_layout"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
android:fitsSystemWindows="true">
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar_main"
|
||||
android:layout_height="wrap_content"
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:minHeight="?attr/actionBarSize"
|
||||
android:background="?attr/colorPrimary">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/spinner_style"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/spinner_class"
|
||||
android:visibility="invisible"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</android.support.v7.widget.Toolbar>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/layout_map"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<!--
|
||||
<fragment
|
||||
android:name="com.mapbox.mapboxgl.testapp.MapFragment"
|
||||
android:id="@+id/fragment_map"
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="${packageName}.${activityClass}"
|
||||
tools:layout="@layout/fragment_main" />
|
||||
-->
|
||||
|
||||
<com.mapbox.mapboxgl.views.MapView
|
||||
android:id="@+id/mainMapView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/view_fps"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:text="@string/label_fps"
|
||||
android:layout_margin="10dp" />
|
||||
android:background="?attr/colorPrimary"
|
||||
android:minHeight="?attr/actionBarSize"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
|
||||
|
||||
</FrameLayout>
|
||||
</LinearLayout>
|
||||
<FrameLayout
|
||||
android:id="@+id/content_frame"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@+id/toolbar">
|
||||
|
||||
<android.support.design.widget.CoordinatorLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.mapbox.mapboxgl.views.MapView
|
||||
android:id="@+id/mainMapView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/view_fps"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp"
|
||||
android:text="@string/label_fps"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"/>
|
||||
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/locationFAB"
|
||||
android:src="@drawable/ic_my_location_white_24dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end|bottom"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
/>
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<android.support.design.widget.NavigationView
|
||||
android:id="@+id/nav_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="start"
|
||||
android:fitsSystemWindows="true"
|
||||
app:menu="@menu/menu_drawer"/>
|
||||
|
||||
</android.support.v4.widget.DrawerLayout>
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item
|
||||
android:id="@+id/action_debug"
|
||||
android:icon="@drawable/ic_action_about"
|
||||
android:title="@string/action_debug"
|
||||
android:checkable="true"
|
||||
/>
|
||||
<item
|
||||
android:id="@+id/action_markers"
|
||||
android:icon="@android:drawable/ic_menu_myplaces"
|
||||
android:title="@string/action_point_annotations"
|
||||
android:checkable="true"
|
||||
/>
|
||||
<item android:id="@+id/action_compass"
|
||||
android:icon="@drawable/ic_explore_white_24dp"
|
||||
android:title="@string/action_compass"
|
||||
android:checkable="true"
|
||||
/>
|
||||
|
||||
<!--
|
||||
<group android:id="@+id/locationFollowModesSeparator"/>
|
||||
|
||||
<group android:id="@+id/locationFollowModes" android:checkableBehavior="single">
|
||||
<item android:id="@+id/followNone"
|
||||
android:title="@string/action_location_none"/>
|
||||
<item android:id="@+id/followFollow"
|
||||
android:title="@string/action_location_follow"/>
|
||||
<item android:id="@+id/followBearing"
|
||||
android:title="@string/action_location_bearing"/>
|
||||
</group>
|
||||
-->
|
||||
|
||||
<group android:id="@+id/stylesSeparator"/>
|
||||
|
||||
<group android:id="@+id/stylesGroup" android:checkableBehavior="single">
|
||||
<item
|
||||
android:id="@+id/actionStyleMapboxStreets"
|
||||
android:title="@string/styleMapboxStreets" />
|
||||
<item
|
||||
android:id="@+id/actionStyleEmerald"
|
||||
android:title="@string/styleEmerald" />
|
||||
<item
|
||||
android:id="@+id/actionStyleLight"
|
||||
android:title="@string/styleLight" />
|
||||
<item
|
||||
android:id="@+id/actionStyleDark"
|
||||
android:title="@string/styleDark" />
|
||||
<item
|
||||
android:id="@+id/actionStyleSatellite"
|
||||
android:title="@string/styleSatellite" />
|
||||
</group>
|
||||
|
||||
</menu>
|
||||
@@ -1,19 +1,3 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item android:id="@+id/action_debug"
|
||||
android:icon="@drawable/ic_action_about"
|
||||
android:title="@string/action_debug"
|
||||
app:showAsAction="ifRoom" />
|
||||
<item android:id="@+id/action_markers"
|
||||
android:icon="@android:drawable/ic_menu_myplaces"
|
||||
android:title="@string/action_point_annotations"
|
||||
app:showAsAction="ifRoom" />
|
||||
<item android:id="@+id/action_gps"
|
||||
android:icon="@drawable/ic_action_location_searching"
|
||||
android:title="@string/action_gps"
|
||||
app:showAsAction="ifRoom" />
|
||||
<item android:id="@+id/action_compass"
|
||||
android:icon="@drawable/ic_explore_white_24dp"
|
||||
android:title="@string/action_compass"
|
||||
app:showAsAction="ifRoom"/>
|
||||
</menu>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="primary">#1E8CAB</color>
|
||||
<color name="primaryDark">#166B83</color>
|
||||
<color name="accent">#E55E5E</color>
|
||||
<color name="white">#FFFFFF</color>
|
||||
</resources>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<dimen name="fab_margin">16dp</dimen>
|
||||
</resources>
|
||||
@@ -4,20 +4,26 @@
|
||||
<string name="app_name">Mapbox GL</string>
|
||||
|
||||
<string name="action_gps">Toggle GPS location</string>
|
||||
<string name="action_location_none">Toggle Location Bearing Tracking</string>
|
||||
<string name="action_location_follow">Follow</string>
|
||||
<string name="action_location_bearing">Bearing</string>
|
||||
<string name="action_compass">Toggle Compass</string>
|
||||
|
||||
<string name="action_debug">Toggle debug mode</string>
|
||||
|
||||
<string name="action_point_annotations">Toggle point annotations</string>
|
||||
|
||||
<string name="label_fps">FPS:</string>
|
||||
|
||||
<string-array name="style_list">
|
||||
<item>Mapbox Streets</item>
|
||||
<item>Emerald</item>
|
||||
<item>Light</item>
|
||||
<item>Dark</item>
|
||||
</string-array>
|
||||
<string name="styleMapboxStreets">Mapbox Streets</string>
|
||||
<string name="styleEmerald">Emerald</string>
|
||||
<string name="styleLight">Light</string>
|
||||
<string name="styleDark">Dark</string>
|
||||
<string name="styleSatellite">Satellite</string>
|
||||
|
||||
<string name="styleURLMapboxStreets">asset://styles/mapbox-streets-v7.json</string>
|
||||
<string name="styleURLEmerald">asset://styles/emerald-v7.json</string>
|
||||
<string name="styleURLLight">asset://styles/light-v7.json</string>
|
||||
<string name="styleURLDark">asset://styles/dark-v7.json</string>
|
||||
<string name="styleURLSatellite">asset://styles/satellite-v7.json</string>
|
||||
|
||||
<string-array name="outdoors_class_list">
|
||||
<item>Day</item>
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light.NoActionBar" />
|
||||
|
||||
<style name="AppTheme" parent="AppBaseTheme" />
|
||||
|
||||
<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
|
||||
<item name="colorPrimary">@color/primary</item>
|
||||
<item name="colorPrimaryDark">@color/primaryDark</item>
|
||||
<item name="colorAccent">@color/accent</item>
|
||||
<item name="android:windowBackground">@color/white</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
||||