This repository has been archived by the owner on Apr 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 70
Location provider enabled/disabled #137
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a60c1cf
Deprecate and document provider enabled/disabled methods
c99fd5d
Add location availability example
48a050a
Add LocationCallback listener to LocationAvailability example
35d2293
Checkstyle
5c8cbcc
Fire additional LocationAvailability notification when provider enabled
51a8c3e
Create Lost shadow for LocationManager, implement missing method
72572fc
Fix dupe listener bug in shadow location manager and rm workaround
6225eae
Checkstyle
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
88 changes: 88 additions & 0 deletions
88
lost-sample/src/main/java/com/example/lost/LocationAvailabilityActivity.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,88 @@ | ||
package com.example.lost; | ||
|
||
import android.os.Bundle; | ||
import android.os.Looper; | ||
import android.support.annotation.Nullable; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.Toast; | ||
|
||
import com.mapzen.android.lost.api.LocationAvailability; | ||
import com.mapzen.android.lost.api.LocationCallback; | ||
import com.mapzen.android.lost.api.LocationRequest; | ||
import com.mapzen.android.lost.api.LocationResult; | ||
import com.mapzen.android.lost.api.LocationServices; | ||
import com.mapzen.android.lost.api.LostApiClient; | ||
|
||
import static com.mapzen.android.lost.api.LocationRequest.PRIORITY_HIGH_ACCURACY; | ||
|
||
public class LocationAvailabilityActivity extends AppCompatActivity { | ||
|
||
LostApiClient client; | ||
|
||
LocationCallback callback = new LocationCallback() { | ||
@Override | ||
public void onLocationAvailability(LocationAvailability locationAvailability) { | ||
boolean isAvailable = locationAvailability.isLocationAvailable(); | ||
Toast.makeText(LocationAvailabilityActivity.this, isAvailable ? | ||
R.string.location_available : R.string.location_unavailable, | ||
Toast.LENGTH_SHORT).show(); | ||
} | ||
|
||
@Override | ||
public void onLocationResult(LocationResult result) { | ||
|
||
} | ||
}; | ||
|
||
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_location_availability); | ||
|
||
setupLocationAvailabilityBtn(); | ||
} | ||
|
||
private void setupLocationAvailabilityBtn() { | ||
Button connect = (Button) findViewById(R.id.check_availability); | ||
connect.setOnClickListener(new View.OnClickListener() { | ||
@Override public void onClick(View v) { | ||
if (client == null || !client.isConnected()) { | ||
connect(); | ||
} else { | ||
checkLocationAvailability(); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
private void connect() { | ||
client = new LostApiClient.Builder(this).addConnectionCallbacks( | ||
new LostApiClient.ConnectionCallbacks() { | ||
@Override | ||
public void onConnected() { | ||
checkLocationAvailability(); | ||
} | ||
|
||
@Override | ||
public void onConnectionSuspended() { | ||
|
||
} | ||
}).build(); | ||
client.connect(); | ||
} | ||
|
||
private void checkLocationAvailability() { | ||
LocationAvailability availability = | ||
LocationServices.FusedLocationApi.getLocationAvailability(client); | ||
boolean isAvailable = availability.isLocationAvailable(); | ||
Toast.makeText(LocationAvailabilityActivity.this, isAvailable ? R.string.location_available | ||
: R.string.location_unavailable, Toast.LENGTH_SHORT).show(); | ||
|
||
final LocationRequest locationRequest = LocationRequest.create() | ||
.setPriority(PRIORITY_HIGH_ACCURACY); | ||
LocationServices.FusedLocationApi.requestLocationUpdates(client, locationRequest, callback, | ||
Looper.myLooper()); | ||
|
||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
lost-sample/src/main/res/layout/activity_location_availability.xml
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,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<Button | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:id="@+id/check_availability" | ||
android:text="@string/check_availability"/> | ||
|
||
</LinearLayout> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,14 +17,28 @@ public interface LocationListener { | |
void onLocationChanged(Location location); | ||
|
||
/** | ||
* Called when a location provider is disabled. | ||
* Called when a location provider is disabled. You will only receive updates for the priority | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
* level set in the location request used to register for updates in | ||
* {@link FusedLocationProviderApi#requestLocationUpdates(LostApiClient, LocationRequest, | ||
* LocationListener)}. Ie. {@link LocationRequest#PRIORITY_HIGH_ACCURACY} will invoke this method | ||
* for gps and network changes but {@link LocationRequest#PRIORITY_BALANCED_POWER_ACCURACY} will | ||
* only invoke it for network changes. This method will be removed in the next major release, it | ||
* is recommended that you use {@link LocationAvailability} instead. | ||
* @param provider the disabled provider. | ||
*/ | ||
@Deprecated | ||
void onProviderDisabled(String provider); | ||
|
||
/** | ||
* Called when a location provider is enabled. | ||
* Called when a location provider is enabled. You will only receive updates for the priority | ||
* level set in the location request used to register for updates in | ||
* {@link FusedLocationProviderApi#requestLocationUpdates(LostApiClient, LocationRequest, | ||
* LocationListener)}. Ie. {@link LocationRequest#PRIORITY_HIGH_ACCURACY} will invoke this method | ||
* for gps and network changes but {@link LocationRequest#PRIORITY_BALANCED_POWER_ACCURACY} will | ||
* only invoke it for network changes. This method will be removed in the next major release, it | ||
* is recommended that you use {@link LocationAvailability} instead. | ||
* @param provider the enabled provider. | ||
*/ | ||
@Deprecated | ||
void onProviderEnabled(String provider); | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While exercising a call to
FusedLocationApi.getLocationAvailability(client)
is good we should also verify thatLocationCallback
is properly invoked when location updates have been requested and provider status changes occur.https://github.com/mapzen/lost/blob/master/lost/src/main/java/com/mapzen/android/lost/api/FusedLocationProviderApi.java#L100-L101
This is the use case that would more suitably replace
LocationListener.onProviderEnabled(String provider)
andLocationListener.onProviderDisabled(String provider)
since the client app is relying on a push style notification rather than actively polling the provider status.