Search in sources :

Example 1 with SunriseSunsetCalculator

use of com.luckycatlabs.sunrisesunset.SunriseSunsetCalculator in project Alarmio by TheAndroidMaster.

the class Alarmio method getSunsetCalculator.

@Nullable
private SunriseSunsetCalculator getSunsetCalculator() {
    if (sunsetCalculator == null && ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
        try {
            LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
            android.location.Location location = locationManager.getLastKnownLocation(locationManager.getBestProvider(new Criteria(), false));
            sunsetCalculator = new SunriseSunsetCalculator(new Location(location.getLatitude(), location.getLongitude()), TimeZone.getDefault().getID());
        } catch (NullPointerException ignored) {
        }
    }
    return sunsetCalculator;
}
Also used : LocationManager(android.location.LocationManager) SunriseSunsetCalculator(com.luckycatlabs.sunrisesunset.SunriseSunsetCalculator) Criteria(android.location.Criteria) Location(com.luckycatlabs.sunrisesunset.dto.Location) Nullable(io.reactivex.annotations.Nullable)

Aggregations

Criteria (android.location.Criteria)1 LocationManager (android.location.LocationManager)1 SunriseSunsetCalculator (com.luckycatlabs.sunrisesunset.SunriseSunsetCalculator)1 Location (com.luckycatlabs.sunrisesunset.dto.Location)1 Nullable (io.reactivex.annotations.Nullable)1