Search in sources :

Example 11 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 12 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 13 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)

Example 14 with Criteria

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

the class ShadowLocationManagerTest method shouldThrowExceptionIfTheBestProviderIsUnknown.

@Test
public void shouldThrowExceptionIfTheBestProviderIsUnknown() throws Exception {
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    try {
        shadowLocationManager.setBestProvider("BEST_ENABLED_PROVIDER", true);
        Assert.fail("The best provider is unknown!");
    } catch (Exception e) {
    // No worries, everything is fine...
    }
}
Also used : Criteria(android.location.Criteria) Test(org.junit.Test)

Example 15 with Criteria

use of android.location.Criteria in project ignition by mttkay.

the class AbstractIgnitedLocationManagerTest method shouldNotRequestUpdatesFromGpsIfBatteryLow.

@Test
public void shouldNotRequestUpdatesFromGpsIfBatteryLow() {
    sendBatteryLevelChangedBroadcast(10);
    resume();
    Map<PendingIntent, Criteria> locationPendingIntents = shadowLocationManager.getRequestLocationUdpateCriteriaPendingIntents();
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    assertThat("Updates from " + LocationManager.GPS_PROVIDER + " provider shouldn't be requested when battery power is low!", !locationPendingIntents.containsValue(criteria));
}
Also used : PendingIntent(android.app.PendingIntent) Criteria(android.location.Criteria) Test(org.junit.Test)

Aggregations

Criteria (android.location.Criteria)52 Location (android.location.Location)20 Test (org.junit.Test)12 LocationManager (android.location.LocationManager)9 ArrayList (java.util.ArrayList)8 Bundle (android.os.Bundle)7 PendingIntent (android.app.PendingIntent)6 Intent (android.content.Intent)6 LocationListener (android.location.LocationListener)6 Handler (android.os.Handler)6 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