TwilightServicepublic final class TwilightService extends com.android.server.SystemService Figures out whether it's twilight time based on the user's location.
Used by the UI mode manager and other components to adjust night mode
effects based on sunrise and sunset. |
Fields Summary |
---|
static final String | TAG | static final boolean | DEBUG | static final String | ACTION_UPDATE_TWILIGHT_STATE | final Object | mLock | android.app.AlarmManager | mAlarmManager | android.location.LocationManager | mLocationManager | LocationHandler | mLocationHandler | final ArrayList | mListeners | TwilightState | mTwilightState | private final TwilightManager | mService | private final android.content.BroadcastReceiver | mUpdateLocationReceiver | private final android.location.LocationListener | mEmptyLocationListener | private final android.location.LocationListener | mLocationListener |
Methods Summary |
---|
private static boolean | hasMoved(android.location.Location from, android.location.Location to)
if (to == null) {
return false;
}
if (from == null) {
return true;
}
// if new location is older than the current one, the device hasn't moved.
if (to.getElapsedRealtimeNanos() < from.getElapsedRealtimeNanos()) {
return false;
}
// Get the distance between the two points.
float distance = from.distanceTo(to);
// Get the total accuracy radius for both locations.
float totalAccuracy = from.getAccuracy() + to.getAccuracy();
// If the distance is greater than the combined accuracy of the two
// points then they can't overlap and hence the user has moved.
return distance >= totalAccuracy;
| public void | onStart()
mAlarmManager = (AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE);
mLocationManager = (LocationManager) getContext().getSystemService(
Context.LOCATION_SERVICE);
mLocationHandler = new LocationHandler();
IntentFilter filter = new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
filter.addAction(Intent.ACTION_TIME_CHANGED);
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
filter.addAction(ACTION_UPDATE_TWILIGHT_STATE);
getContext().registerReceiver(mUpdateLocationReceiver, filter);
publishLocalService(TwilightManager.class, mService);
| private void | setTwilightState(TwilightState state)
synchronized (mLock) {
if (!Objects.equal(mTwilightState, state)) {
if (DEBUG) {
Slog.d(TAG, "Twilight state changed: " + state);
}
mTwilightState = state;
final int listenerLen = mListeners.size();
for (int i = 0; i < listenerLen; i++) {
mListeners.get(i).postUpdate();
}
}
}
|
|