[android] #2758 - add my location tracking mode
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package com.mapbox.mapboxsdk.testapp;
|
||||
|
||||
import android.support.test.rule.ActivityTestRule;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.test.suitebuilder.annotation.LargeTest;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
/**
|
||||
* Tests on User LocationTrackingModeActivity
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@LargeTest
|
||||
public class MyLocationTrackingModeActivityTest extends BaseTest {
|
||||
|
||||
@Rule
|
||||
public ActivityTestRule<MyLocationTrackingModeActivity> mActivityRule = new ActivityTestRule<>(MyLocationTrackingModeActivity.class);
|
||||
|
||||
private MyLocationTrackingModeActivity mActivity = null;
|
||||
|
||||
@Before
|
||||
public void setActivity() {
|
||||
mActivity = mActivityRule.getActivity();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
checkViewIsDisplayed(R.id.mapView);
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@
|
||||
<activity
|
||||
android:name=".InfoWindowActivity"
|
||||
android:label="@string/activity_info_window" />
|
||||
|
||||
|
||||
<activity
|
||||
android:name=".BulkMarkerActivity"
|
||||
android:label="@string/action_add_bulk_markers" />
|
||||
@@ -49,6 +49,10 @@
|
||||
android:name=".PressForMarkerActivity"
|
||||
android:label="@string/activity_press_for_marker" />
|
||||
|
||||
<activity
|
||||
android:name=".MyLocationTrackingModeActivity"
|
||||
android:label="@string/activity_user_tracking_mode" />
|
||||
|
||||
<meta-data
|
||||
android:name="io.fabric.ApiKey"
|
||||
android:value="9724157045ff7d083492c6d9ae03e60e8609d461" />
|
||||
|
||||
@@ -339,6 +339,10 @@ public class MainActivity extends AppCompatActivity {
|
||||
startActivity(new Intent(getApplicationContext(), VisibleCoordinateBoundsActivity.class));
|
||||
return true;
|
||||
|
||||
case R.id.action_user_tracking_mode:
|
||||
startActivity(new Intent(getApplicationContext(), MyLocationTrackingModeActivity.class));
|
||||
return true;
|
||||
|
||||
default:
|
||||
return changeMapStyle(menuItem.getItemId());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
package com.mapbox.mapboxsdk.testapp;
|
||||
|
||||
import android.location.Location;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Spinner;
|
||||
|
||||
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.utils.ApiAccess;
|
||||
import com.mapbox.mapboxsdk.views.MapView;
|
||||
|
||||
public class MyLocationTrackingModeActivity extends AppCompatActivity implements MapView.OnMyLocationChangeListener, AdapterView.OnItemSelectedListener {
|
||||
|
||||
private MapView mMapView;
|
||||
private Spinner mSpinner;
|
||||
private Location mLocation;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_my_location_tracking);
|
||||
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setDisplayShowTitleEnabled(false);
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setDisplayShowHomeEnabled(true);
|
||||
}
|
||||
|
||||
ArrayAdapter<CharSequence> spinnerAdapter = ArrayAdapter.createFromResource(actionBar.getThemedContext(), R.array.user_tracking_mode, android.R.layout.simple_spinner_item);
|
||||
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
mSpinner = (Spinner) findViewById(R.id.spinner);
|
||||
mSpinner.setAdapter(spinnerAdapter);
|
||||
mSpinner.setOnItemSelectedListener(this);
|
||||
mSpinner.setEnabled(false);
|
||||
|
||||
mMapView = (MapView) findViewById(R.id.mapView);
|
||||
mMapView.setAccessToken(ApiAccess.getToken(this));
|
||||
mMapView.onCreate(savedInstanceState);
|
||||
mMapView.setOnMyLocationChangeListener(this);
|
||||
mMapView.setMyLocationEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMyLocationChange(@Nullable Location location) {
|
||||
if (location != null) {
|
||||
if (mLocation == null) {
|
||||
// initial location to reposition map
|
||||
mMapView.setCenterCoordinate(new LatLng(location.getLatitude(), location.getLongitude()));
|
||||
mSpinner.setEnabled(true);
|
||||
}
|
||||
mLocation = location;
|
||||
showSnackBar();
|
||||
}
|
||||
}
|
||||
|
||||
private void showSnackBar() {
|
||||
String desc = "Loc Chg: ";
|
||||
boolean noInfo = true;
|
||||
if (mLocation.hasSpeed()) {
|
||||
desc += String.format("Spd = %.1f km/h ", mLocation.getSpeed() * 3.6f);
|
||||
noInfo = false;
|
||||
}
|
||||
if (mLocation.hasAltitude()) {
|
||||
desc += String.format("Alt = %.0f m ", mLocation.getAltitude());
|
||||
noInfo = false;
|
||||
}
|
||||
if (noInfo) {
|
||||
desc += "No extra info";
|
||||
}
|
||||
Snackbar.make(findViewById(android.R.id.content), desc, Snackbar.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
switch (position) {
|
||||
case 0:
|
||||
mMapView.setMyLocationTrackingMode(MyLocationTracking.TRACKING_NONE);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
mMapView.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW);
|
||||
break;
|
||||
|
||||
// case 2:
|
||||
// mMapView.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW_BEARING_GPS);
|
||||
// break;
|
||||
//
|
||||
// case 3:
|
||||
// mMapView.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW_BEARING_COMPASS);
|
||||
// break;
|
||||
//
|
||||
// case 4:
|
||||
// mMapView.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW_BEARING);
|
||||
// break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
mMapView.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mMapView.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mMapView.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
mMapView.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
mMapView.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
mMapView.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
super.onLowMemory();
|
||||
mMapView.onLowMemory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
onBackPressed();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 546 B |
Binary file not shown.
|
After Width: | Height: | Size: 350 B |
Binary file not shown.
|
After Width: | Height: | Size: 687 B |
Binary file not shown.
|
After Width: | Height: | Size: 1012 B |
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="@color/primary"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/spinner"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</android.support.v7.widget.Toolbar>
|
||||
|
||||
<com.mapbox.mapboxsdk.views.MapView
|
||||
android:id="@+id/mapView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:style_url="@string/style_mapbox_streets"
|
||||
app:zoom_level="15" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -59,20 +59,6 @@
|
||||
</menu>
|
||||
</item>
|
||||
|
||||
<!--
|
||||
<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/testsSeparator" />
|
||||
|
||||
<item
|
||||
@@ -116,6 +102,12 @@
|
||||
android:icon="@drawable/ic_blur_on_white_24dp"
|
||||
android:title="@string/action_add_bulk_markers" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_user_tracking_mode"
|
||||
android:checkable="false"
|
||||
android:icon="@drawable/ic_gps_fixed_white_24dp"
|
||||
android:title="@string/activity_user_tracking_mode" />
|
||||
|
||||
</menu>
|
||||
</item>
|
||||
|
||||
|
||||
@@ -10,14 +10,13 @@
|
||||
<string name="activity_marker_in_bulk">Add Bulk Markers Activity</string>
|
||||
<string name="activity_info_window">InfoWindow Activity</string>
|
||||
<string name="activity_visible_coordinate_bounds">Visible Coordinate Bounds</string>
|
||||
<string name="activity_user_tracking_mode">User tracking mode</string>
|
||||
|
||||
<string name="navdrawer_menu_title_mainactivity_controls">Main Activity Controls</string>
|
||||
<string name="navdrawer_menu_title_mainactivity_styles">Main Activity Styles</string>
|
||||
<string name="navdrawer_menu_title_individual_tests">Individual Tests</string>
|
||||
<string name="action_gps">Toggle GPS location</string>
|
||||
<string name="action_location_none">Disable tracking</string>
|
||||
<string name="action_location_follow">Use follow tracking mode</string>
|
||||
<string name="action_location_bearing">Use bearing tracking mode tracking</string>
|
||||
<string name="action_user_location_tracking">User location tracking</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>
|
||||
@@ -50,4 +49,12 @@
|
||||
<item>10000</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="user_tracking_mode">
|
||||
<item>Disable tracking</item>
|
||||
<item>Follow tracking mode</item>
|
||||
<!--<item>Bearing tracking GPS mode</item>-->
|
||||
<!--<item>Bearing tracking Compass mode</item>-->
|
||||
<!--<item>Bearing tracking mode</item>-->
|
||||
</string-array>
|
||||
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user