Skip to content
This repository has been archived by the owner on Apr 23, 2023. It is now read-only.

Commit

Permalink
Removes deprecated location listener callbacks for provider enabled/d…
Browse files Browse the repository at this point in the history
…isabled (#181)

* Speeds up location updates in multiple client demo

* Removes deprecated `LocationListener` callbacks for provider enabled/disabled
  • Loading branch information
ecgreb authored and sarahsnow1 committed Apr 18, 2017
1 parent f9d8b9c commit 678b8bd
Show file tree
Hide file tree
Showing 11 changed files with 2 additions and 179 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,6 @@ public class LocationListenerActivity extends AppCompatActivity implements
@Override public void onLocationChanged(Location location) {
fragment.updateLocation(location);
}

@Override public void onProviderDisabled(String provider) {
Log.d(TAG, "Location provider disabled: " + provider);
}

@Override public void onProviderEnabled(String provider) {
Log.d(TAG, "Location provider enabled: " + provider);
}
};

@Override protected void onCreate(Bundle savedInstanceState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private void initLocationTracking() {
return;
}

long interval = 3 * 60 * 1000; // 3 minutes
long interval = 30 * 1000; // 30 seconds
LocationRequest request = LocationRequest.create()
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setFastestInterval(interval)
Expand All @@ -98,14 +98,6 @@ private void initLocationTracking() {
addItem("Activity");
}

@Override public void onProviderDisabled(String provider) {

}

@Override public void onProviderEnabled(String provider) {

}

public void addItem(String title) {
Date date = new Date(System.currentTimeMillis());
SimpleDateFormat dateformat = new SimpleDateFormat("HH:mm:ss");
Expand Down Expand Up @@ -158,7 +150,7 @@ private void fragmentInitLocationTracking() {
return;
}

long interval = 30 * 1000; // 30 sec
long interval = 15 * 1000; // 15 seconds
LocationRequest request = LocationRequest.create()
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setFastestInterval(interval)
Expand All @@ -172,14 +164,5 @@ private void fragmentInitLocationTracking() {
(MultipleLocationListenerMultipleClientsActivity) getActivity();
a.addItem("Fragment");
}

@Override public void onProviderDisabled(String provider) {

}

@Override public void onProviderEnabled(String provider) {

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,12 @@ public class MultipleLocationListenerSingleClientActivity extends ListActivity {
@Override public void onLocationChanged(Location location) {
addItem("Listener");
}

@Override public void onProviderDisabled(String provider) {

}

@Override public void onProviderEnabled(String provider) {

}
};

LocationListener otherListener = new LocationListener() {
@Override public void onLocationChanged(Location location) {
addItem("Other Listener");
}

@Override public void onProviderDisabled(String provider) {

}

@Override public void onProviderEnabled(String provider) {

}
};

@Override int numOfItems() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,4 @@ public interface LocationListener {
* @param location the newest location.
*/
void onLocationChanged(Location location);

/**
* Called when a location provider is disabled. 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 disabled provider.
*/
@Deprecated
void onProviderDisabled(String provider);

/**
* 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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ ReportedChanges sendPendingIntent(Context context, Location location,
LocationAvailability availability, LocationResult result);
ReportedChanges reportLocationResult(Location location, final LocationResult result);
void updateReportedValues(ReportedChanges changes);
void reportProviderEnabled(String provider);
void reportProviderDisabled(String provider);
void notifyLocationAvailability(final LocationAvailability availability);
boolean hasNoListeners();
Map<LostApiClient, Set<LocationListener>> getLocationListeners();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,11 @@ public void reportLocation(Location location) {

@RequiresPermission(anyOf = {ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION})
public void reportProviderDisabled(String provider) {
clientManager.reportProviderDisabled(provider);
notifyLocationAvailabilityChanged();
}

@RequiresPermission(anyOf = {ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION})
public void reportProviderEnabled(String provider) {
clientManager.reportProviderEnabled(provider);
notifyLocationAvailabilityChanged();
LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
manager.requestSingleUpdate(provider, new android.location.LocationListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,22 +192,6 @@ private void throwIfClientNotAdded(LostApiClient client) {
reportedChanges.putAll(changes);
}

@Override public void reportProviderEnabled(String provider) {
for (LostClientWrapper wrapper : clients.values()) {
for (LocationListener listener : wrapper.locationListeners()) {
listener.onProviderEnabled(provider);
}
}
}

@Override public void reportProviderDisabled(String provider) {
for (LostClientWrapper wrapper : clients.values()) {
for (LocationListener listener : wrapper.locationListeners()) {
listener.onProviderDisabled(provider);
}
}
}

@Override public void notifyLocationAvailability(final LocationAvailability availability) {
for (LostClientWrapper wrapper : clients.values()) {
for (LocationCallback callback : wrapper.locationCallbacks()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,42 +384,6 @@ public void setMockTrace_shouldRespectFastestInterval() throws Exception {
assertThat(api.isProviderEnabled(client, LocationManager.NETWORK_PROVIDER)).isFalse();
}

@Test public void onProviderDisabled_shouldReportWhenGpsIsDisabled() throws Exception {
TestLocationListener listener = new TestLocationListener();
LocationRequest request = LocationRequest.create().setPriority(PRIORITY_HIGH_ACCURACY);
api.requestLocationUpdates(client, request, listener);
listener.setIsGpsEnabled(true);
shadowLocationManager.setProviderEnabled(GPS_PROVIDER, false);
assertThat(listener.getIsGpsEnabled()).isFalse();
}

@Test public void onProviderDisabled_shouldReportWhenNetworkIsDisabled() throws Exception {
TestLocationListener listener = new TestLocationListener();
LocationRequest request = LocationRequest.create();
api.requestLocationUpdates(client, request, listener);
listener.setIsNetworkEnabled(true);
shadowLocationManager.setProviderEnabled(NETWORK_PROVIDER, false);
assertThat(listener.getIsNetworkEnabled()).isFalse();
}

@Test public void onProviderEnabled_shouldReportWhenGpsIsEnabled() throws Exception {
TestLocationListener listener = new TestLocationListener();
LocationRequest request = LocationRequest.create().setPriority(PRIORITY_HIGH_ACCURACY);
api.requestLocationUpdates(client, request, listener);
listener.setIsGpsEnabled(false);
shadowLocationManager.setProviderEnabled(GPS_PROVIDER, true);
assertThat(listener.getIsGpsEnabled()).isTrue();
}

@Test public void onProviderEnabled_shouldReportWhenNetworkIsEnabled() throws Exception {
TestLocationListener listener = new TestLocationListener();
LocationRequest request = LocationRequest.create();
api.requestLocationUpdates(client, request, listener);
listener.setIsNetworkEnabled(false);
shadowLocationManager.setProviderEnabled(NETWORK_PROVIDER, true);
assertThat(listener.getIsNetworkEnabled()).isTrue();
}

private static Location getTestLocation(String provider, float lat, float lng, long time) {
Location location = new Location(provider);
location.setLatitude(lat);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,6 @@ public class LostApiClientImplTest extends BaseRobolectricTest {
new LocationListener() {
@Override public void onLocationChanged(Location location) {
}

@Override public void onProviderDisabled(String provider) {
}

@Override public void onProviderEnabled(String provider) {
}
});

client.disconnect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import java.util.ArrayList;

import static android.location.LocationManager.GPS_PROVIDER;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.robolectric.RuntimeEnvironment.application;
Expand Down Expand Up @@ -172,24 +171,6 @@ public void addLocationCallback_shouldThrowExceptionIfClientWasNotAdded() throws
assertThat(callback.getResult()).isEqualTo(result);
}

@Test public void reportProviderEnabled_shouldNotifyListeners() {
manager.addClient(client);
LocationRequest request = LocationRequest.create();
TestLocationListener listener = new TestLocationListener();
manager.addListener(client, request, listener);
manager.reportProviderEnabled(GPS_PROVIDER);
assertThat(listener.getIsGpsEnabled()).isTrue();
}

@Test public void reportProviderDisabled_shouldNotifyListeners() {
manager.addClient(client);
LocationRequest request = LocationRequest.create();
TestLocationListener listener = new TestLocationListener();
manager.addListener(client, request, listener);
manager.reportProviderDisabled(GPS_PROVIDER);
assertThat(listener.getIsGpsEnabled()).isFalse();
}

@Test public void notifyLocationAvailability_shouldNotifyCallback() {
manager.addClient(client);
LocationRequest request = LocationRequest.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
import java.util.ArrayList;
import java.util.List;

import static android.location.LocationManager.GPS_PROVIDER;
import static android.location.LocationManager.NETWORK_PROVIDER;

public class TestLocationListener implements LocationListener {
private ArrayList<Location> locations = new ArrayList<>();
private boolean isGpsEnabled = true;
Expand All @@ -19,32 +16,6 @@ public class TestLocationListener implements LocationListener {
locations.add(location);
}

@Override public void onProviderDisabled(String provider) {
switch (provider) {
case GPS_PROVIDER:
isGpsEnabled = false;
break;
case NETWORK_PROVIDER:
isNetworkEnabled = false;
break;
default:
break;
}
}

@Override public void onProviderEnabled(String provider) {
switch (provider) {
case GPS_PROVIDER:
isGpsEnabled = true;
break;
case NETWORK_PROVIDER:
isNetworkEnabled = true;
break;
default:
break;
}
}

public List<Location> getAllLocations() {
return locations;
}
Expand Down

0 comments on commit 678b8bd

Please sign in to comment.