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
4 changes: 3 additions & 1 deletion mapbox/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ dependencies {
compile rootProject.ext.dep.gmsLocation

// LOST
compile "com.mapzen.android:lost:3.0.3"
compile(rootProject.ext.dep.lost) {
exclude group: 'com.google.guava'
}

// Picasso (Static Image)
compile rootProject.ext.dep.picasso
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ public void removeLocationUpdates() {
*
* @param location the new location
*/
@Deprecated
@Override
public void onLocationChanged(Location location) {
for (LocationEngineListener listener : locationListeners) {
Expand Down
4 changes: 3 additions & 1 deletion mapbox/libandroid-telemetry/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ dependencies {
provided rootProject.ext.dep.gmsLocation

// LOST
provided "com.mapzen.android:lost:3.0.3"
provided(rootProject.ext.dep.lost) {
exclude group: 'com.google.guava'
}

// Testing
testCompile rootProject.ext.dep.junit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.content.Context;
import android.location.Location;
import android.support.annotation.Nullable;
import android.util.Log;

import com.mapzen.android.lost.api.LocationListener;
import com.mapzen.android.lost.api.LocationRequest;
Expand All @@ -15,10 +14,7 @@
/**
* Sample LocationEngine using the Open Source Lost library
*/
public class LostLocationEngine extends LocationEngine implements
LostApiClient.ConnectionCallbacks, LocationListener {

private static final String LOG_TAG = LostLocationEngine.class.getSimpleName();
public class LostLocationEngine extends LocationEngine implements LocationListener {

private static LocationEngine instance;

Expand All @@ -28,9 +24,7 @@ public class LostLocationEngine extends LocationEngine implements
public LostLocationEngine(Context context) {
super();
this.context = new WeakReference<>(context);
lostApiClient = new LostApiClient.Builder(this.context.get())
.addConnectionCallbacks(this)
.build();
lostApiClient = new LostApiClient.Builder(this.context.get()).build();
}

public static synchronized LocationEngine getLocationEngine(Context context) {
Expand All @@ -47,7 +41,12 @@ public static synchronized LocationEngine getLocationEngine(Context context) {
*/
@Override
public void activate() {
connect();
if (!lostApiClient.isConnected()) {
lostApiClient.connect();
}
for (LocationEngineListener listener : locationListeners) {
listener.onConnected();
}
}

/**
Expand All @@ -57,7 +56,7 @@ public void activate() {
*/
@Override
public void deactivate() {
if (lostApiClient != null && lostApiClient.isConnected()) {
if (lostApiClient.isConnected()) {
lostApiClient.disconnect();
}
}
Expand All @@ -74,25 +73,7 @@ public boolean isConnected() {
}

/**
* Invoked when the location provider has connected.
*/
@Override
public void onConnected() {
for (LocationEngineListener listener : locationListeners) {
listener.onConnected();
}
}

/**
* Invoked when the location provider connection has been suspended.
*/
@Override
public void onConnectionSuspended() {
Log.d(LOG_TAG, "Connection suspended");
}

/**
* Returns the Last known location if the location provider is connected.
* Returns the Last known location if the location provider is connected and location permissions are granted.
*
* @return the last known location
*/
Expand All @@ -101,7 +82,7 @@ public void onConnectionSuspended() {
public Location getLastLocation() {
if (lostApiClient.isConnected()) {
//noinspection MissingPermission
return LocationServices.FusedLocationApi.getLastLocation(lostApiClient);
return LocationServices.FusedLocationApi.getLastLocation();
}
return null;
}
Expand All @@ -123,6 +104,7 @@ public void requestLocationUpdates() {
request.setSmallestDisplacement(smallestDisplacement);
}

// Priority matching is straightforward
if (priority == LocationEnginePriority.NO_POWER) {
request.setPriority(LocationRequest.PRIORITY_NO_POWER);
} else if (priority == LocationEnginePriority.LOW_POWER) {
Expand All @@ -135,25 +117,25 @@ public void requestLocationUpdates() {

if (lostApiClient.isConnected()) {
//noinspection MissingPermission
LocationServices.FusedLocationApi.requestLocationUpdates(lostApiClient, request, this);
LocationServices.FusedLocationApi.requestLocationUpdates(request, this);
}
}

@Override
public Type obtainType() {
return Type.LOST;
}

/**
* Dismiss ongoing location update to the location provider.
*/
@Override
public void removeLocationUpdates() {
if (lostApiClient.isConnected()) {
LocationServices.FusedLocationApi.removeLocationUpdates(lostApiClient, this);
LocationServices.FusedLocationApi.removeLocationUpdates(this);
}
}

@Override
public Type obtainType() {
return Type.LOST;
}

/**
* Invoked when the Location has changed.
*
Expand All @@ -165,14 +147,4 @@ public void onLocationChanged(Location location) {
listener.onLocationChanged(location);
}
}

private void connect() {
if (lostApiClient != null) {
if (lostApiClient.isConnected()) {
onConnected();
} else {
lostApiClient.connect();
}
}
}
}