v7/appcompat/src/main/java/androidx/appcompat/app/TwilightManager.java
boolean isNight() {
        final TwilightState state = mTwilightState;

        if (isStateValid()) {
            // If the current twilight state is still valid, use it
            return state.isNight;
        }

        // Else, we will try and grab the last known location
        final Location location = getLastKnownLocation();
        if (location != null) {
            updateState(location);
            return state.isNight;
        }

        Log.i(TAG, "Could not get last known location. This is probably because the app does not"
                + " have any location permissions. Falling back to hardcoded"
                + " sunrise/sunset values.");

        // If we don't have a location, we'll use our hardcoded sunrise/sunset values.
        // These aren't great, but it's better than nothing.
        Calendar calendar = Calendar.getInstance();
        final int hour = calendar.get(Calendar.HOUR_OF_DAY);
        return hour < SUNRISE || hour >= SUNSET;
    }
/**
     * Returns true we are currently in the 'night'.
     *
     * @return true if we are at night, false if the day.
     */
Returns true we are currently in the 'night'.
@return true if we are at night, false if the day.
Returns true we are currently in the ' night ' . @return true if we are at night false if the day .
boolean isNight() {
        final TwilightState state = mTwilightState;
        if (isStateValid()) {
            return state.isNight;
        }
        final Location location = getLastKnownLocation();
        if (location != null) {
            updateState(location);
            return state.isNight;
        }
        Log.i(TAG, "Could not get last known location. This is probably because the app does not"
                + " have any location permissions. Falling back to hardcoded"
                + " sunrise/sunset values.");
        Calendar calendar = Calendar.getInstance();
        final int hour = calendar.get(Calendar.HOUR_OF_DAY);
        return hour < SUNRISE || hour >= SUNSET;
    }
boolean isNight ( ) { final TwilightState state = mTwilightState ; if ( isStateValid ( ) ) { return state . isNight ; } final Location location = getLastKnownLocation ( ) ; if ( location != null ) { updateState ( location ) ; return state . isNight ; } Log . i ( TAG , "Could not get last known location. This is probably because the app does not" + " have any location permissions. Falling back to hardcoded" + " sunrise/sunset values." ) ; Calendar calendar = Calendar . getInstance ( ) ; final int hour = calendar . get ( Calendar . HOUR_OF_DAY ) ; return hour < SUNRISE || hour >= SUNSET ; }
Returns true we are currently in the 'night'.
Returns true we are currently in the ' night ' .
// If the current twilight state is still valid, use it // Else, we will try and grab the last known location // If we don't have a location, we'll use our hardcoded sunrise/sunset values. // These aren't great, but it's better than nothing.