Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void locationSourceAdded() throws Exception {
@Override
public void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, MapboxMap mapboxMap,
UiController uiController, Context context) {
locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.TRACKING);
locationLayerPlugin.setLocationLayerMode(LocationLayerMode.NORMAL);
assertTrue(mapboxMap.getSource(LOCATION_SOURCE) != null);
}
});
Expand All @@ -97,7 +97,7 @@ public void locationTrackingLayersAdded() throws Exception {
@Override
public void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, MapboxMap mapboxMap,
UiController uiController, Context context) {
locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.TRACKING);
locationLayerPlugin.setLocationLayerMode(LocationLayerMode.NORMAL);
assertTrue(mapboxMap.getLayer(ACCURACY_LAYER) != null);
assertTrue(mapboxMap.getLayer(BACKGROUND_LAYER) != null);
assertTrue(mapboxMap.getLayer(FOREGROUND_LAYER) != null);
Expand All @@ -111,7 +111,7 @@ public void locationBearingLayersAdded() throws Exception {
@Override
public void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, MapboxMap mapboxMap,
UiController uiController, Context context) {
locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.COMPASS);
locationLayerPlugin.setLocationLayerMode(LocationLayerMode.COMPASS);
assertTrue(mapboxMap.getLayer(ACCURACY_LAYER) != null);
assertTrue(mapboxMap.getLayer(BACKGROUND_LAYER) != null);
assertTrue(mapboxMap.getLayer(FOREGROUND_LAYER) != null);
Expand All @@ -126,7 +126,7 @@ public void locationNavigationLayersAdded() throws Exception {
@Override
public void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, MapboxMap mapboxMap,
UiController uiController, Context context) {
locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.COMPASS);
locationLayerPlugin.setLocationLayerMode(LocationLayerMode.COMPASS);
assertTrue(mapboxMap.getLayer(NAVIGATION_LAYER) != null);
}
});
Expand All @@ -138,9 +138,9 @@ public void locationLayerModeCorrectlySetToNone() throws Exception {
@Override
public void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, MapboxMap mapboxMap,
UiController uiController, Context context) {
locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.TRACKING);
locationLayerPlugin.setLocationLayerMode(LocationLayerMode.NORMAL);
assertTrue(mapboxMap.getLayer(FOREGROUND_LAYER) != null);
locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.NONE);
locationLayerPlugin.setLocationLayerEnabled(false);
assertTrue(mapboxMap.getLayer(FOREGROUND_LAYER).getVisibility().getValue()
.equals(Property.NONE));
}
Expand All @@ -153,11 +153,11 @@ public void onMapChangeLocationLayerRedrawn() throws Exception {
@Override
public void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, MapboxMap mapboxMap,
UiController uiController, Context context) {
locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.TRACKING);
locationLayerPlugin.setLocationLayerMode(LocationLayerMode.NORMAL);
assertTrue(mapboxMap.getLayer(FOREGROUND_LAYER) != null);
mapboxMap.setStyleUrl(Style.SATELLITE);
uiController.loopMainThreadForAtLeast(500);
assertEquals(locationLayerPlugin.getLocationLayerMode(), LocationLayerMode.TRACKING);
assertEquals(locationLayerPlugin.getLocationLayerMode(), LocationLayerMode.NORMAL);
assertTrue(mapboxMap.getLayer(FOREGROUND_LAYER) != null);
assertTrue(mapboxMap.getLayer(FOREGROUND_LAYER).getVisibility().getValue()
.equals(Property.VISIBLE));
Expand All @@ -175,7 +175,7 @@ public void whenStaleTimeSet_iconsDoChangeAtAppropriateTime() throws Exception {
@Override
public void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, MapboxMap mapboxMap,
UiController uiController, Context context) {
locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.TRACKING);
locationLayerPlugin.setLocationLayerMode(LocationLayerMode.NORMAL);
SymbolLayer symbolLayer = mapboxMap.getLayerAs(FOREGROUND_LAYER);
assert symbolLayer != null;
assertThat(symbolLayer.getIconImage().getValue(), equalTo(FOREGROUND_ICON));
Expand All @@ -193,7 +193,7 @@ public void whenDrawableChanged_continuesUsingStaleIcons() throws Exception {
@Override
public void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, MapboxMap mapboxMap,
UiController uiController, Context context) {
locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.TRACKING);
locationLayerPlugin.setLocationLayerMode(LocationLayerMode.NORMAL);
locationLayerPlugin.applyStyle(LocationLayerOptions.builder(context).staleStateDelay(100).build());
locationLayerPlugin.forceLocationUpdate(location);
uiController.loopMainThreadForAtLeast(200);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.mapbox.mapboxsdk.plugins.places.autocomplete.data;

import com.google.gson.JsonObject;
import com.mapbox.geocoding.v5.models.CarmenFeature;
import com.mapbox.api.geocoding.v5.models.CarmenFeature;
import com.mapbox.plugins.places.autocomplete.data.entity.SearchHistoryEntity;

final class TestData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected void onCreate(Bundle savedInstanceState) {
public void onMapReady(final MapboxMap mapboxMap) {
LocationEngine locationEngine = new LostLocationEngine(this);
locationLayerPlugin = new LocationLayerPlugin(mapView, mapboxMap, locationEngine);
locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.COMPASS);
locationLayerPlugin.setLocationLayerMode(LocationLayerMode.COMPASS);
locationLayerPlugin.addCompassListener(new CompassListener() {
@Override
public void onCompassChanged(float userHeading) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void onMapReady(MapboxMap mapboxMap) {
locationEngine.setPriority(LocationEnginePriority.HIGH_ACCURACY);
locationEngine.activate();
locationPlugin = new LocationLayerPlugin(mapView, mapboxMap, locationEngine);
locationPlugin.setLocationLayerEnabled(LocationLayerMode.COMPASS);
locationPlugin.setLocationLayerMode(LocationLayerMode.COMPASS);
}

@OnClick(R.id.fabStyles)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package com.mapbox.mapboxsdk.plugins.testapp.activity.location;

import android.annotation.SuppressLint;
import android.location.Location;
import android.os.Bundle;
import android.support.annotation.VisibleForTesting;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.ListPopupWindow;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
Expand All @@ -16,13 +21,17 @@
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerMode;
import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerPlugin;
import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerTracking;
import com.mapbox.mapboxsdk.plugins.locationlayer.OnLocationLayerClickListener;
import com.mapbox.mapboxsdk.plugins.testapp.R;
import com.mapbox.services.android.location.LostLocationEngine;
import com.mapbox.services.android.telemetry.location.LocationEngine;
import com.mapbox.services.android.telemetry.location.LocationEngineListener;
import com.mapbox.services.android.telemetry.location.LocationEnginePriority;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
Expand All @@ -32,6 +41,14 @@ public class LocationLayerModesActivity extends AppCompatActivity implements OnM

@BindView(R.id.map_view)
MapView mapView;
@BindView(R.id.tv_mode)
TextView modeText;
@BindView(R.id.tv_tracking)
TextView trackingText;
@BindView(R.id.button_location_mode)
Button locationModeBtn;
@BindView(R.id.button_location_tracking)
Button locationTrackingBtn;

private LocationLayerPlugin locationLayerPlugin;
private LocationEngine locationEngine;
Expand All @@ -49,41 +66,23 @@ protected void onCreate(Bundle savedInstanceState) {
}

@SuppressWarnings( {"MissingPermission"})
@OnClick(R.id.button_location_mode_none)
public void locationModeNone(View view) {
@OnClick(R.id.button_location_mode)
public void locationMode(View view) {
if (locationLayerPlugin == null) {
return;
}
locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.NONE);
showModeListDialog();
}

@SuppressWarnings( {"MissingPermission"})
@OnClick(R.id.button_location_mode_compass)
@OnClick(R.id.button_location_tracking)
public void locationModeCompass(View view) {
if (locationLayerPlugin == null) {
return;
}
locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.COMPASS);
}

@SuppressWarnings( {"MissingPermission"})
@OnClick(R.id.button_location_mode_tracking)
public void locationModeTracking(View view) {
if (locationLayerPlugin == null) {
return;
}
locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.TRACKING);
}

@SuppressWarnings( {"MissingPermission"})
@OnClick(R.id.button_location_mode_navigation)
public void locationModeNavigation(View view) {
if (locationLayerPlugin == null) {
return;
}
locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.NAVIGATION);
showTrackingListDialog();
}

@SuppressLint("MissingPermission")
@Override
public void onMapReady(MapboxMap mapboxMap) {
this.mapboxMap = mapboxMap;
Expand All @@ -93,6 +92,7 @@ public void onMapReady(MapboxMap mapboxMap) {
locationEngine.activate();
locationLayerPlugin = new LocationLayerPlugin(mapView, mapboxMap, locationEngine);
locationLayerPlugin.setOnLocationClickListener(this);
locationLayerPlugin.setLocationLayerEnabled(true);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be the default behaviour, so no additional setter need to be called after using the constructor?

getLifecycle().addObserver(locationLayerPlugin);
}

Expand Down Expand Up @@ -191,10 +191,67 @@ public void onConnected() {
public void onLocationChanged(Location location) {
mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(location.getLatitude(), location.getLongitude()), 16));
locationEngine.removeLocationEngineListener(this);
}

@Override
public void onLocationLayerClick() {
Toast.makeText(this, "OnLocationLayerClick", Toast.LENGTH_LONG).show();
}

private void showModeListDialog() {
List<String> modes = new ArrayList<>();
modes.add("Normal");
modes.add("Compass");
modes.add("Navigation");
ArrayAdapter<String> profileAdapter = new ArrayAdapter<>(this,
android.R.layout.simple_list_item_1, modes);
ListPopupWindow listPopup = new ListPopupWindow(this);
listPopup.setAdapter(profileAdapter);
listPopup.setAnchorView(locationModeBtn);
listPopup.setOnItemClickListener((parent, itemView, position, id) -> {
String selectedMode = modes.get(position);
locationModeBtn.setText(selectedMode);
if (selectedMode.contentEquals("Normal")) {
locationLayerPlugin.setLocationLayerMode(LocationLayerMode.NORMAL);
} else if (selectedMode.contentEquals("Compass")) {
locationLayerPlugin.setLocationLayerMode(LocationLayerMode.COMPASS);
} else if (selectedMode.contentEquals("Navigation")) {
locationLayerPlugin.setLocationLayerMode(LocationLayerMode.NAVIGATION);
}
listPopup.dismiss();
});
listPopup.show();
}

private void showTrackingListDialog() {
List<String> trackingTypes = new ArrayList<>();
trackingTypes.add("None");
trackingTypes.add("Tracking");
trackingTypes.add("Tracking Compass");
trackingTypes.add("Tracking GPS");
trackingTypes.add("Tracking GPS North");
ArrayAdapter<String> profileAdapter = new ArrayAdapter<>(this,
android.R.layout.simple_list_item_1, trackingTypes);
ListPopupWindow listPopup = new ListPopupWindow(this);
listPopup.setAdapter(profileAdapter);
listPopup.setAnchorView(locationTrackingBtn);
listPopup.setOnItemClickListener((parent, itemView, position, id) -> {
String selectedTrackingType = trackingTypes.get(position);
locationTrackingBtn.setText(selectedTrackingType);
if (selectedTrackingType.contentEquals("None")) {
locationLayerPlugin.setLocationLayerTracking(LocationLayerTracking.NONE);
} else if (selectedTrackingType.contentEquals("Tracking")) {
locationLayerPlugin.setLocationLayerTracking(LocationLayerTracking.TRACKING);
} else if (selectedTrackingType.contentEquals("Tracking Compass")) {
locationLayerPlugin.setLocationLayerTracking(LocationLayerTracking.TRACKING_COMPASS);
} else if (selectedTrackingType.contentEquals("Tracking GPS")) {
locationLayerPlugin.setLocationLayerTracking(LocationLayerTracking.TRACKING_GPS);
} else if (selectedTrackingType.contentEquals("Tracking GPS North")) {
locationLayerPlugin.setLocationLayerTracking(LocationLayerTracking.TRACKING_GPS_NORTH);
}
listPopup.dismiss();
});
listPopup.show();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void onMapReady(MapboxMap mapboxMap) {
locationEngine.setPriority(LocationEnginePriority.HIGH_ACCURACY);
locationEngine.activate();
locationLayerPlugin = new LocationLayerPlugin(mapView, mapboxMap, null);
locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.TRACKING);
locationLayerPlugin.setLocationLayerMode(LocationLayerMode.NORMAL);
getLifecycle().addObserver(locationLayerPlugin);
}

Expand Down
46 changes: 26 additions & 20 deletions app/src/main/res/layout/activity_location_layer_mode.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,40 +32,46 @@
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1">

<Button
android:id="@+id/button_location_mode_none"
style="?android:attr/buttonBarButtonStyle"
<TextView
android:id="@+id/tv_mode"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/button_location_mode_none"
android:textColor="@android:color/white"/>
android:layout_height="match_parent"
android:layout_weight=".75"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/mapboxWhite"
android:gravity="center"
android:text="@string/mode"/>

<Button
android:id="@+id/button_location_mode_tracking"
android:id="@+id/button_location_mode"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/button_location_mode_tracking"
android:layout_weight="1.25"
android:gravity="center"
android:text="@string/button_location_mode_none"
android:textColor="@android:color/white"/>

<Button
android:id="@+id/button_location_mode_compass"
style="?android:attr/buttonBarButtonStyle"
<TextView
android:id="@+id/tv_tracking"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/button_location_mode_compass"
android:textColor="@android:color/white"/>
android:layout_height="match_parent"
android:layout_weight=".85"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/mapboxWhite"
android:gravity="center"
android:text="@string/tracking"/>

<Button
android:id="@+id/button_location_mode_navigation"
android:id="@+id/button_location_tracking"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/button_location_mode_navigation"
android:layout_weight="1.15"
android:gravity="center"
android:text="@string/button_location_mode_tracking"
android:textColor="@android:color/white"/>

</LinearLayout>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@

<!-- Place picker -->
<string name="detailed_description_place_picker">Example shows how to launch the Place Picker using the Floating action button and receiving a result in onActivityResult.</string>
<string name="mode">Mode:</string>
<string name="tracking">Tracking:</string>
</resources>
Loading