This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[android] make location provider optional (#9488)
- Loading branch information
1 parent
ae1ada3
commit f13a8b0
Showing
16 changed files
with
280 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
...rm/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/EmptyLocationSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package com.mapbox.mapboxsdk; | ||
|
||
|
||
import android.location.Location; | ||
import android.support.annotation.Nullable; | ||
|
||
import com.mapbox.mapboxsdk.location.LocationSource; | ||
import com.mapbox.services.android.core.location.LocationEngine; | ||
import com.mapbox.services.android.core.location.LocationEngineListener; | ||
|
||
class EmptyLocationSource extends LocationSource { | ||
|
||
/** | ||
* Activate the location engine which will connect whichever location provider you are using. You'll need to call | ||
* this before requesting user location updates using {@link LocationEngine#requestLocationUpdates()}. | ||
*/ | ||
@Override | ||
public void activate() { | ||
// Intentionally left empty | ||
} | ||
|
||
/** | ||
* Disconnect the location engine which is useful when you no longer need location updates or requesting the users | ||
* {@link LocationEngine#getLastLocation()}. Before deactivating, you'll need to stop request user location updates | ||
* using {@link LocationEngine#removeLocationUpdates()}. | ||
*/ | ||
@Override | ||
public void deactivate() { | ||
// Intentionally left empty | ||
} | ||
|
||
/** | ||
* Check if your location provider has been activated/connected. This is mainly used internally but is also useful in | ||
* the rare case when you'd like to know if your location engine is connected or not. | ||
* | ||
* @return boolean true if the location engine has been activated/connected, else false. | ||
*/ | ||
@Override | ||
public boolean isConnected() { | ||
return false; | ||
} | ||
|
||
/** | ||
* Returns the Last known location is the location provider is connected and location permissions are granted. | ||
* | ||
* @return the last known location | ||
*/ | ||
@Override | ||
@Nullable | ||
public Location getLastLocation() { | ||
return null; | ||
} | ||
|
||
/** | ||
* Request location updates to the location provider. | ||
*/ | ||
@Override | ||
public void requestLocationUpdates() { | ||
// Intentionally left empty | ||
} | ||
|
||
/** | ||
* Dismiss ongoing location update to the location provider. | ||
*/ | ||
@Override | ||
public void removeLocationUpdates() { | ||
// Intentionally left empty | ||
} | ||
|
||
/** | ||
* Invoked when the Location has changed. | ||
* | ||
* @param location the new location | ||
*/ | ||
@Override | ||
public void onLocationChanged(Location location) { | ||
// Intentionally left empty | ||
} | ||
|
||
/** | ||
* Useful when you'd like to add a location listener to handle location connections and update events. It is important | ||
* to note, that the callback will continue getting called even when your application isn't in the foreground. | ||
* Therefore, it is a good idea to use {@link LocationEngine#removeLocationEngineListener(LocationEngineListener)} | ||
* inside your activities {@code onStop()} method. | ||
* | ||
* @param listener A {@link LocationEngineListener} which you'd like to add to your location engine. | ||
* @since 2.0.0 | ||
*/ | ||
@Override | ||
public void addLocationEngineListener(LocationEngineListener listener) { | ||
// Intentionally left empty | ||
} | ||
|
||
/** | ||
* If you no longer need your {@link LocationEngineListener} to be invoked with every location update, use this | ||
* method to remove it. It's also important to remove your listeners before the activity is destroyed to prevent any | ||
* potential memory leaks. | ||
* | ||
* @param listener the {@link LocationEngineListener} you'd like to remove from this {@link LocationEngine}. | ||
* @return true. | ||
* @since 2.0.0 | ||
*/ | ||
@Override | ||
public boolean removeLocationEngineListener(LocationEngineListener listener) { | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/** | ||
* Contains the Mapbox Maps Android Location API classes. | ||
*/ | ||
package com.mapbox.mapboxsdk.location; | ||
package com.mapbox.mapboxsdk.location; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.