Search in sources :

Example 6 with Criteria

use of android.location.Criteria in project robolectric by robolectric.

the class ShadowLocationManagerTest method shouldReturnBestCustomProviderUsingCriteria.

@Test
public void shouldReturnBestCustomProviderUsingCriteria() throws Exception {
    Criteria criteria = new Criteria();
    Criteria customProviderCriteria = new Criteria();
    // Manually set best provider should be returned
    ArrayList<Criteria> criteriaList = new ArrayList<>();
    customProviderCriteria.setAccuracy(Criteria.ACCURACY_COARSE);
    criteriaList.add(customProviderCriteria);
    shadowLocationManager.setProviderEnabled("BEST_ENABLED_PROVIDER_WITH_CRITERIA", true, criteriaList);
    assertTrue(shadowLocationManager.setBestProvider("BEST_ENABLED_PROVIDER_WITH_CRITERIA", true));
    criteria.setAccuracy(Criteria.ACCURACY_COARSE);
    criteria.setPowerRequirement(Criteria.NO_REQUIREMENT);
    assertThat("BEST_ENABLED_PROVIDER_WITH_CRITERIA").isEqualTo(locationManager.getBestProvider(criteria, true));
    assertTrue(shadowLocationManager.setBestProvider("BEST_ENABLED_PROVIDER_WITH_CRITERIA", true));
    assertThat("BEST_ENABLED_PROVIDER_WITH_CRITERIA").isEqualTo(locationManager.getBestProvider(criteria, false));
    assertThat("BEST_ENABLED_PROVIDER_WITH_CRITERIA").isEqualTo(locationManager.getBestProvider(criteria, true));
}
Also used : ArrayList(java.util.ArrayList) Criteria(android.location.Criteria) Test(org.junit.Test)

Example 7 with Criteria

use of android.location.Criteria in project robolectric by robolectric.

the class ShadowLocationManagerTest method shouldReturnBestProviderUsingCriteria.

@Test
public void shouldReturnBestProviderUsingCriteria() {
    Criteria criteria = new Criteria();
    shadowLocationManager.setProviderEnabled(LocationManager.GPS_PROVIDER, false);
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    assertThat(LocationManager.GPS_PROVIDER).isEqualTo(locationManager.getBestProvider(criteria, false));
    shadowLocationManager.setProviderEnabled(LocationManager.NETWORK_PROVIDER, false);
    criteria.setAccuracy(Criteria.ACCURACY_COARSE);
    assertThat(LocationManager.NETWORK_PROVIDER).isEqualTo(locationManager.getBestProvider(criteria, false));
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    assertThat(LocationManager.NETWORK_PROVIDER).isEqualTo(locationManager.getBestProvider(criteria, false));
}
Also used : Criteria(android.location.Criteria) Test(org.junit.Test)

Example 8 with Criteria

use of android.location.Criteria in project robolectric by robolectric.

the class ShadowLocationManagerTest method shouldRemovePendingIntentsWhenRequestingLocationUpdatesUsingCriteria.

@Test
public void shouldRemovePendingIntentsWhenRequestingLocationUpdatesUsingCriteria() throws Exception {
    Intent someIntent = new Intent("some_action");
    PendingIntent someLocationListenerPendingIntent = PendingIntent.getBroadcast(ShadowApplication.getInstance().getApplicationContext(), 0, someIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    Intent someOtherIntent = new Intent("some_other_action");
    PendingIntent someOtherLocationListenerPendingIntent = PendingIntent.getBroadcast(ShadowApplication.getInstance().getApplicationContext(), 0, someOtherIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    shadowLocationManager.setProviderEnabled(GPS_PROVIDER, true);
    shadowLocationManager.setBestProvider(LocationManager.GPS_PROVIDER, true);
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    locationManager.requestLocationUpdates(0, 0, criteria, someLocationListenerPendingIntent);
    locationManager.requestLocationUpdates(0, 0, criteria, someOtherLocationListenerPendingIntent);
    locationManager.removeUpdates(someLocationListenerPendingIntent);
    Map<PendingIntent, Criteria> expectedCriteria = new HashMap<>();
    expectedCriteria.put(someOtherLocationListenerPendingIntent, criteria);
    assertThat(shadowLocationManager.getRequestLocationUdpateCriteriaPendingIntents()).isEqualTo(expectedCriteria);
}
Also used : HashMap(java.util.HashMap) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Criteria(android.location.Criteria) Test(org.junit.Test)

Example 9 with Criteria

use of android.location.Criteria in project robolectric by robolectric.

the class ShadowLocationManagerTest method shouldStoreBestProviderCriteriaAndEnabledOnlyFlag.

@Test
public void shouldStoreBestProviderCriteriaAndEnabledOnlyFlag() throws Exception {
    Criteria criteria = new Criteria();
    assertNull(locationManager.getBestProvider(criteria, true));
    assertSame(criteria, shadowLocationManager.getLastBestProviderCriteria());
    assertTrue(shadowLocationManager.getLastBestProviderEnabledOnly());
}
Also used : Criteria(android.location.Criteria) Test(org.junit.Test)

Example 10 with Criteria

use of android.location.Criteria in project robolectric by robolectric.

the class ShadowLocationManagerTest method shouldRegisterLocationUpdatesWhenCriteriaGiven.

@Test
public void shouldRegisterLocationUpdatesWhenCriteriaGiven() throws Exception {
    shadowLocationManager.setProviderEnabled(NETWORK_PROVIDER, true);
    shadowLocationManager.setBestProvider(LocationManager.NETWORK_PROVIDER, true);
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_COARSE);
    Intent someIntent = new Intent("some_action");
    PendingIntent someLocationListenerPendingIntent = PendingIntent.getBroadcast(ShadowApplication.getInstance().getApplicationContext(), 0, someIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    Criteria someCriteria = new Criteria();
    someCriteria.setAccuracy(Criteria.ACCURACY_COARSE);
    locationManager.requestLocationUpdates(0, 0, someCriteria, someLocationListenerPendingIntent);
    assertThat(shadowLocationManager.getRequestLocationUdpateCriteriaPendingIntents().get(someLocationListenerPendingIntent)).isEqualTo(someCriteria);
}
Also used : Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Criteria(android.location.Criteria) PendingIntent(android.app.PendingIntent) Test(org.junit.Test)

Aggregations

Criteria (android.location.Criteria)51 Location (android.location.Location)19 Test (org.junit.Test)12 LocationManager (android.location.LocationManager)8 ArrayList (java.util.ArrayList)8 PendingIntent (android.app.PendingIntent)6 Intent (android.content.Intent)6 Bundle (android.os.Bundle)6 Handler (android.os.Handler)6 LocationListener (android.location.LocationListener)5 SuppressLint (android.annotation.SuppressLint)2 FacebookException (com.facebook.FacebookException)2 HashMap (java.util.HashMap)2 Prefs (nodomain.freeyourgadget.gadgetbridge.util.Prefs)2 PackageManager (android.content.pm.PackageManager)1 ResolveInfo (android.content.pm.ResolveInfo)1 EditTextPreference (android.preference.EditTextPreference)1 ListPreference (android.preference.ListPreference)1 Preference (android.preference.Preference)1 PreferenceCategory (android.preference.PreferenceCategory)1