diff options
author | Tobrun <tobrun.van.nuland@gmail.com> | 2015-10-27 12:28:19 +0100 |
---|---|---|
committer | Tobrun <tobrun.van.nuland@gmail.com> | 2015-10-28 11:22:50 +0100 |
commit | 8fdc033eabe9a14729c4910933ab472a3aa4e825 (patch) | |
tree | cd0435128ea1b82bae4a5030a2ef860bbe6bb1c7 /android/MapboxGLAndroidSDKTestApp | |
parent | a2ac435171e1b3bfbd93015aca996f2ae68b4b2e (diff) | |
download | qtlocation-mapboxgl-8fdc033eabe9a14729c4910933ab472a3aa4e825.tar.gz |
[android] #2797 - addLocationBearing part one
Diffstat (limited to 'android/MapboxGLAndroidSDKTestApp')
4 files changed, 84 insertions, 37 deletions
diff --git a/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java b/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java index a8d465d7a0..29d6de7f4f 100644 --- a/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java +++ b/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java @@ -23,22 +23,27 @@ import android.util.Log; import android.view.MenuItem; import android.view.View; import android.widget.TextView; + import com.crashlytics.android.Crashlytics; import com.mapbox.mapboxsdk.annotations.Marker; import com.mapbox.mapboxsdk.annotations.MarkerOptions; import com.mapbox.mapboxsdk.annotations.PolygonOptions; import com.mapbox.mapboxsdk.annotations.PolylineOptions; import com.mapbox.mapboxsdk.annotations.Sprite; +import com.mapbox.mapboxsdk.constants.MyBearingTracking; +import com.mapbox.mapboxsdk.constants.MyLocationTracking; import com.mapbox.mapboxsdk.constants.Style; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.testapp.utils.GeoParseUtil; import com.mapbox.mapboxsdk.utils.ApiAccess; import com.mapbox.mapboxsdk.views.MapView; -import io.fabric.sdk.android.Fabric; + import java.text.DecimalFormat; import java.util.ArrayList; import java.util.List; +import io.fabric.sdk.android.Fabric; + public class MainActivity extends AppCompatActivity { private static final String TAG = "MainActivity"; @@ -428,6 +433,8 @@ public class MainActivity extends AppCompatActivity { } }); mMapView.setMyLocationEnabled(true); + mMapView.setMyLocationTrackingMode(MyLocationTracking.TRACKING_NONE); + mMapView.setMyBearingTrackingMode(MyBearingTracking.GPS); mLocationFAB.setColorFilter(ContextCompat.getColor(this, R.color.primary)); } @@ -467,7 +474,7 @@ public class MainActivity extends AppCompatActivity { List<Marker> markers = mMapView.addMarkers(markerOptionsList); } - private MarkerOptions generateMarker(String title, String snippet, Sprite icon, double lat, double lng){ + private MarkerOptions generateMarker(String title, String snippet, Sprite icon, double lat, double lng) { return new MarkerOptions() .position(new LatLng(lat, lng)) .title(title) diff --git a/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MyLocationTrackingModeActivity.java b/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MyLocationTrackingModeActivity.java index 366db4b8f4..c5d8b16d86 100644 --- a/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MyLocationTrackingModeActivity.java +++ b/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MyLocationTrackingModeActivity.java @@ -13,6 +13,7 @@ import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Spinner; +import com.mapbox.mapboxsdk.constants.MyBearingTracking; import com.mapbox.mapboxsdk.constants.MyLocationTracking; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.utils.ApiAccess; @@ -21,7 +22,7 @@ import com.mapbox.mapboxsdk.views.MapView; public class MyLocationTrackingModeActivity extends AppCompatActivity implements MapView.OnMyLocationChangeListener, AdapterView.OnItemSelectedListener { private MapView mMapView; - private Spinner mSpinner; + private Spinner mLocationSpinner, mBearingSpinner; private Location mLocation; @Override @@ -39,12 +40,19 @@ public class MyLocationTrackingModeActivity extends AppCompatActivity implements 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); + ArrayAdapter<CharSequence> locationTrackingAdapter = ArrayAdapter.createFromResource(actionBar.getThemedContext(), R.array.user_tracking_mode, android.R.layout.simple_spinner_item); + locationTrackingAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + mLocationSpinner = (Spinner) findViewById(R.id.spinner_location); + mLocationSpinner.setAdapter(locationTrackingAdapter); + mLocationSpinner.setOnItemSelectedListener(this); +// mLocationSpinner.setEnabled(false); + + ArrayAdapter<CharSequence> bearingTrackingAdapter = ArrayAdapter.createFromResource(actionBar.getThemedContext(), R.array.user_bearing_mode, android.R.layout.simple_spinner_item); + bearingTrackingAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + mBearingSpinner = (Spinner) findViewById(R.id.spinner_bearing); + mBearingSpinner.setAdapter(bearingTrackingAdapter); + mBearingSpinner.setOnItemSelectedListener(this); +// mBearingSpinner.setEnabled(false); mMapView = (MapView) findViewById(R.id.mapView); mMapView.setAccessToken(ApiAccess.getToken(this)); @@ -59,7 +67,8 @@ public class MyLocationTrackingModeActivity extends AppCompatActivity implements if (mLocation == null) { // initial location to reposition map mMapView.setCenterCoordinate(new LatLng(location.getLatitude(), location.getLongitude())); - mSpinner.setEnabled(true); + mLocationSpinner.setEnabled(true); + mBearingSpinner.setEnabled(true); } mLocation = location; showSnackBar(); @@ -85,26 +94,34 @@ public class MyLocationTrackingModeActivity extends AppCompatActivity implements @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; + if (parent.getId() == R.id.spinner_location) { + switch (position) { + case 0: + mMapView.setMyLocationTrackingMode(MyLocationTracking.TRACKING_NONE); + break; + + case 1: + mMapView.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW); + break; + } + } else if (parent.getId() == R.id.spinner_bearing) { + switch (position) { + case 0: + mMapView.setMyBearingTrackingMode(MyBearingTracking.NONE); + break; + + case 1: + mMapView.setMyBearingTrackingMode(MyBearingTracking.GPS); + break; + + case 2: + mMapView.setMyBearingTrackingMode(MyBearingTracking.COMPASS); + break; + +// case 3: +// mMapView.setMyBearingTrackingMode(MyBearingTracking.COMBINED); +// break; + } } } diff --git a/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_my_location_tracking.xml b/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_my_location_tracking.xml index 0a750b074c..e526faeaa6 100644 --- a/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_my_location_tracking.xml +++ b/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_my_location_tracking.xml @@ -12,10 +12,29 @@ 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" /> + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:weightSum="2"> + + <Spinner + android:id="@+id/spinner_location" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_marginEnd="8dp" + android:layout_marginRight="8dp" + android:layout_weight="1" /> + + <Spinner + android:id="@+id/spinner_bearing" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_marginLeft="8dp" + android:layout_marginStart="8dp" + android:layout_weight="1" /> + + </LinearLayout> + </android.support.v7.widget.Toolbar> diff --git a/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml b/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml index 6f1263dcab..6a281d01f1 100644 --- a/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml +++ b/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml @@ -54,9 +54,13 @@ <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> + + <string-array name="user_bearing_mode"> + <item>Disable bearing</item> + <item>GPS mode</item> + <item>Compass mode</item> + <!--<item>Combined mode</item>--> </string-array> </resources> |