Turn on location dialog when using twilight scheduling

Night light and Dark theme scheduling does not work when in
twiligth mode. For the reason, we added a dialog to inform the user
that they need to turn on location services first.

Fixes: 153115618
Fixes: 153115261
Test: manual
Change-Id: Iea51018a7caba5c0ec93e058ee047d067bc03867
This commit is contained in:
Jay Aliomer
2020-04-02 21:32:32 -04:00
parent 5a950b763f
commit 59c03c23b7
5 changed files with 83 additions and 0 deletions

View File

@@ -18,6 +18,7 @@ package com.android.settings.display;
import android.content.Context;
import android.hardware.display.ColorDisplayManager;
import android.location.LocationManager;
import androidx.preference.DropDownPreference;
import androidx.preference.Preference;
@@ -29,12 +30,14 @@ import com.android.settings.core.BasePreferenceController;
public class NightDisplayAutoModePreferenceController extends BasePreferenceController
implements Preference.OnPreferenceChangeListener {
private final LocationManager mLocationManager;
private DropDownPreference mPreference;
private ColorDisplayManager mColorDisplayManager;
public NightDisplayAutoModePreferenceController(Context context, String key) {
super(context, key);
mColorDisplayManager = context.getSystemService(ColorDisplayManager.class);
mLocationManager = context.getSystemService(LocationManager.class);
}
@Override
@@ -68,6 +71,11 @@ public class NightDisplayAutoModePreferenceController extends BasePreferenceCont
@Override
public final boolean onPreferenceChange(Preference preference, Object newValue) {
if (String.valueOf(ColorDisplayManager.AUTO_MODE_TWILIGHT).equals(newValue)
&& !mLocationManager.isLocationEnabled()) {
TwilightLocationDialog.show(mContext);
return false;
}
return mColorDisplayManager.setNightDisplayAutoMode(Integer.parseInt((String) newValue));
}
}