Search in sources :

Example 1 with Location

use of com.luckycatlabs.sunrisesunset.dto.Location in project Alarmio by TheAndroidMaster.

the class Alarmio method getSunsetCalculator.

/**
 * @return the current SunriseSunsetCalculator object, or null if it cannot
 *         be instantiated.
 * @see [SunriseSunsetLib Repo](https://github.com/mikereedell/sunrisesunsetlib-java)
 */
@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(androidx.annotation.Nullable)

Aggregations

Criteria (android.location.Criteria)1 LocationManager (android.location.LocationManager)1 Nullable (androidx.annotation.Nullable)1 SunriseSunsetCalculator (com.luckycatlabs.sunrisesunset.SunriseSunsetCalculator)1 Location (com.luckycatlabs.sunrisesunset.dto.Location)1