Android Criteria - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android Criteria class.

This code example shows how to use the following methods:setAccuracy
 
        resume(); 
 
        Map<PendingIntent, Criteria> locationPendingIntents = shadowLocationManager
                .getRequestLocationUdpateCriteriaPendingIntents(); 
        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
 
        sendBatteryLevelChangedBroadcast(100); 
 
        Intent intent = new Intent(Intent.ACTION_BATTERY_OKAY);
        shadowApp.sendBroadcast(intent);
 
        assertThat("Updates from " + LocationManager.GPS_PROVIDER
                + " provider should be requested when battery power is okay!", 
                locationPendingIntents.containsValue(criteria));
    } 
 
    @Test 
    public void shouldDismissWaitForFixDialogWhenLocationIsAvailable() { 
        shadowLocationManager.setLastKnownLocation(LocationManager.GPS_PROVIDER, null);
8
CodeRank
This code example shows how to use the following methods:getAccuracy, getPowerRequirement, isAltitudeRequired, isBearingRequired, isSpeedRequired
    public boolean supportsSpeed() { 
        return mSupportsSpeed;
    } 
 
    public boolean meetsCriteria(Criteria criteria) {
        if ((criteria.getAccuracy() != Criteria.NO_REQUIREMENT) &&
            (criteria.getAccuracy() < mAccuracy)) {
            return false; 
        } 
        int criteriaPower = criteria.getPowerRequirement();
        if ((criteriaPower != Criteria.NO_REQUIREMENT) &&
            (criteriaPower < mPowerRequirement)) {
            return false; 
        } 
        if (criteria.isAltitudeRequired() && !mSupportsAltitude) {
            return false; 
        } 
        if (criteria.isSpeedRequired() && !mSupportsSpeed) {
            return false; 
        } 

8
CodeRank
This code example shows how to use the following methods:setAccuracy
    protected Location currentLocation;
 
    public IgnitedAbstractLastLocationFinder(Context context) {
        this.context = context.getApplicationContext();
        locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
        criteria = new Criteria();
        // Coarse accuracy is specified here to get the fastest possible result. 
        // The calling Activity will likely (or have already) request ongoing 
        // updates using the Fine location provider. 
        criteria.setAccuracy(Criteria.ACCURACY_COARSE);
    } 
 
    /** 
     * {@inheritDoc} 
     */ 
    @Override 
    public Location getLastBestLocation(int minDistance, long minTime,
            boolean refreshLocationIfLastIsTooOld) {
        Location bestResult = null;
        float bestAccuracy = Float.MAX_VALUE;
8
CodeRank
This code example shows how to use the following methods:setPowerRequirement
        String p = manager.getBestProvider(new Criteria(), true);
        assertNotNull(p);
    } 
 
    public void testGetBestProviderPowerCriteria() { 
        Criteria c = new Criteria();
        c.setPowerRequirement(Criteria.POWER_HIGH);
        String p = manager.getBestProvider(c, true);
        assertNotNull(p);
 
        c.setPowerRequirement(Criteria.POWER_MEDIUM);
        p = manager.getBestProvider(c, true);
        assertNotNull(p);
 
        c.setPowerRequirement(Criteria.POWER_LOW);
        p = manager.getBestProvider(c, true);
        assertNotNull(p);
 
        c.setPowerRequirement(Criteria.NO_REQUIREMENT);
        p = manager.getBestProvider(c, true);

8
CodeRank
This code example shows how to use the following methods:setAccuracy, setAltitudeRequired, setBearingRequired, setCostAllowed, setPowerRequirement
	} 
 
	/** this criteria will settle for less accuracy, high power, and cost */ 
	public static Criteria createCoarseCriteria() {
 
		Criteria c = new Criteria();
		c.setAccuracy(Criteria.ACCURACY_COARSE);
		c.setAltitudeRequired(false);
		c.setBearingRequired(false);
		c.setSpeedRequired(false);
		c.setCostAllowed(true);
		c.setPowerRequirement(Criteria.POWER_HIGH);
		return c;
 
	} 
 
	/** this criteria needs high accuracy, high power, and cost */ 
	public static Criteria createFineCriteria() {
 
		Criteria c = new Criteria();
7
CodeRank
This code example shows how to use the following methods:
public class CriteriaTest { 
    private Criteria criteria;
 
    @Before 
    public void setUp() { 
        criteria = new Criteria();
    } 
 
    @Test 
    public void shouldReturnAccuracy() { 
        criteria.setAccuracy(Criteria.ACCURACY_COARSE);
        assertThat(criteria.getAccuracy()).isEqualTo(Criteria.ACCURACY_COARSE);
    } 
 
    @Test 
    public void shouldReturnPowerRequirement() { 
        criteria.setPowerRequirement(Criteria.POWER_HIGH);
        assertThat(criteria.getPowerRequirement()).isEqualTo(Criteria.POWER_HIGH);
    } 
 
7
CodeRank
This code example shows how to use the following methods:setAccuracy
This code example shows how to use the following methods:getAccuracy, getPowerRequirement
//    private int verticalAccuracy; 
//    private int speedAccuracy; 
    private int powerRequirement = Criteria.NO_REQUIREMENT;
 
    public void __constructor__(Criteria criteria) {
        accuracy = criteria.getAccuracy();
        powerRequirement = criteria.getPowerRequirement();
    } 
 
    @Implementation 
    public int getAccuracy() { 
        return accuracy;
    } 
 
    @Implementation 
    public void setAccuracy(int accuracy) {
        this.accuracy = accuracy;
    } 
 
    @Implementation 
7
CodeRank
This code example shows how to use the following methods:setAccuracy
		AndroidMock.replay(appUtils);
		 
		SocializeLocationManager manager = new SocializeLocationManager(appUtils);
		manager.init(TestUtils.getActivity(this));
		 
        Criteria criteria = new Criteria();
		criteria.setAccuracy(Criteria.ACCURACY_COARSE);
		 
		String bestProvider = manager.getBestProvider(criteria, true);
		 
		assertNotNull(bestProvider);
		 
		// May be null, so don't assert result 
		manager.getLastKnownLocation(bestProvider);
		 
		manager.isProviderEnabled(bestProvider);
		 
		LocationListener listener = new LocationListener() {
			 
			@Override 
7
CodeRank
This code example shows how to use the following methods:setAccuracy, setAltitudeRequired, setBearingRequired, setCostAllowed, setPowerRequirement

Related Android Criteria Questions & Answers:

Other Android Criteria Examples

28:	    // Define the criteria how to select the locatioin provider -> use
29:	    // default
30:	    Criteria criteria = new Criteria();
31:	    provider = locationManager.getBestProvider(criteria, false);
32:	    Location location = locationManager.getLastKnownLocation(provider);
-
28:	    // Define the criteria how to select the locatioin provider -> use
29:	    // default
30:	    Criteria criteria = new Criteria();
31:	    provider = locationManager.getBestProvider(criteria, false);
32:	    Location location = locationManager.getLastKnownLocation(provider);

Read More

See Code Examples for Android Criteria Methods: