Search in sources :

Example 46 with Criteria

use of android.location.Criteria in project weex-example by KalicyZhou.

the class DefaultLocation method findLocation.

private WXLocationListener findLocation(String watchId, String sucCallback, String errorCallback, boolean enableHighAccuracy, boolean enableAddress) {
    if (mLocationManager == null) {
        mLocationManager = (LocationManager) mWXSDKInstance.getContext().getSystemService(Context.LOCATION_SERVICE);
    }
    Criteria criteria = new Criteria();
    if (enableHighAccuracy) {
        criteria.setAccuracy(Criteria.ACCURACY_COARSE);
    }
    //String provider = locationManager.getBestProvider(criteria, false);
    if (ActivityCompat.checkSelfPermission(mWXSDKInstance.getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(mWXSDKInstance.getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
        WXLocationListener WXLocationListener = new WXLocationListener(mLocationManager, mWXSDKInstance, watchId, sucCallback, errorCallback, enableAddress);
        mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME, MIN_DISTANCE, WXLocationListener);
        mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_TIME, MIN_DISTANCE, WXLocationListener);
        return WXLocationListener;
    } else {
        Map<String, Object> options = new HashMap<>();
        options.put(ERROR_CODE, ErrorCode.NO_PERMISSION_ERROR);
        options.put(ERROR_MSG, ErrorMsg.NO_PERMISSION_ERROR);
        WXSDKManager.getInstance().callback(mWXSDKInstance.getInstanceId(), errorCallback, options);
    }
    return null;
}
Also used : HashMap(java.util.HashMap) Criteria(android.location.Criteria)

Example 47 with Criteria

use of android.location.Criteria in project android_frameworks_base by DirtyUnicorns.

the class FusedPrintersProvider method onStartLoading.

@Override
protected void onStartLoading() {
    if (DEBUG) {
        Log.i(LOG_TAG, "onStartLoading() " + FusedPrintersProvider.this.hashCode());
    }
    mLocationManager.requestLocationUpdates(LocationRequest.create().setQuality(LocationRequest.POWER_LOW).setInterval(LOCATION_UPDATE_MS), this, Looper.getMainLooper());
    Location lastLocation = mLocationManager.getLastLocation();
    if (lastLocation != null) {
        onLocationChanged(lastLocation);
    }
    // Jumpstart location with a single forced update
    Criteria oneTimeCriteria = new Criteria();
    oneTimeCriteria.setAccuracy(Criteria.ACCURACY_FINE);
    mLocationManager.requestSingleUpdate(oneTimeCriteria, this, Looper.getMainLooper());
    // The contract is that if we already have a valid,
    // result the we have to deliver it immediately.
    (new Handler(Looper.getMainLooper())).post(new Runnable() {

        @Override
        public void run() {
            deliverResult(new ArrayList<>(mPrinters));
        }
    });
    // Always load the data to ensure discovery period is
    // started and to make sure obsolete printers are updated.
    onForceLoad();
}
Also used : ArrayList(java.util.ArrayList) Handler(android.os.Handler) Criteria(android.location.Criteria) Location(android.location.Location)

Example 48 with Criteria

use of android.location.Criteria in project android_frameworks_base by DirtyUnicorns.

the class LocationManagerTest method testGetBestProviderPowerCriteria.

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);
    assertNotNull(p);
}
Also used : Criteria(android.location.Criteria)

Example 49 with Criteria

use of android.location.Criteria in project android_frameworks_base by ResurrectionRemix.

the class FusedPrintersProvider method onStartLoading.

@Override
protected void onStartLoading() {
    if (DEBUG) {
        Log.i(LOG_TAG, "onStartLoading() " + FusedPrintersProvider.this.hashCode());
    }
    if (getContext().checkSelfPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
        mLocationManager.requestLocationUpdates(LocationRequest.create().setQuality(LocationRequest.POWER_LOW).setInterval(LOCATION_UPDATE_MS), this, Looper.getMainLooper());
        Location lastLocation = mLocationManager.getLastLocation();
        if (lastLocation != null) {
            onLocationChanged(lastLocation);
        }
        // Jumpstart location with a single forced update
        Criteria oneTimeCriteria = new Criteria();
        oneTimeCriteria.setAccuracy(Criteria.ACCURACY_FINE);
        mLocationManager.requestSingleUpdate(oneTimeCriteria, this, Looper.getMainLooper());
    }
    // The contract is that if we already have a valid,
    // result the we have to deliver it immediately.
    (new Handler(Looper.getMainLooper())).post(new Runnable() {

        @Override
        public void run() {
            deliverResult(new ArrayList<>(mPrinters));
        }
    });
    // Always load the data to ensure discovery period is
    // started and to make sure obsolete printers are updated.
    onForceLoad();
}
Also used : ArrayList(java.util.ArrayList) Handler(android.os.Handler) Criteria(android.location.Criteria) Location(android.location.Location)

Example 50 with Criteria

use of android.location.Criteria in project android_frameworks_base by crdroidandroid.

the class LocationManagerTest method testGetBestProviderPowerCriteria.

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);
    assertNotNull(p);
}
Also used : Criteria(android.location.Criteria)

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