Fix subtext didn't change after toggle changed
Add the ContentObserver to monitor the key value changed in the Settings.System. Fixes: 140475264 Test: manual test Test: make RunSettingsRoboTests -j ROBOTEST_FILTER=com.android.settings.display Change-Id: I3018498ae32fb282bc180db7864a9813a168b9c0
This commit is contained in:
@@ -18,17 +18,34 @@ import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
|
|||||||
import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
|
import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.database.ContentObserver;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.TogglePreferenceController;
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
|
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||||
|
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||||
|
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||||
|
|
||||||
|
public class AutoBrightnessPreferenceController extends TogglePreferenceController implements
|
||||||
public class AutoBrightnessPreferenceController extends TogglePreferenceController {
|
LifecycleObserver, OnStart, OnStop {
|
||||||
|
|
||||||
private final String SYSTEM_KEY = SCREEN_BRIGHTNESS_MODE;
|
private final String SYSTEM_KEY = SCREEN_BRIGHTNESS_MODE;
|
||||||
private final int DEFAULT_VALUE = SCREEN_BRIGHTNESS_MODE_MANUAL;
|
private final int DEFAULT_VALUE = SCREEN_BRIGHTNESS_MODE_MANUAL;
|
||||||
|
|
||||||
|
private Preference mPreference;
|
||||||
|
private ContentObserver mContentObserver =
|
||||||
|
new ContentObserver(new Handler(Looper.getMainLooper())) {
|
||||||
|
@Override
|
||||||
|
public void onChange(boolean selfChange) {
|
||||||
|
refreshSummary(mPreference);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public AutoBrightnessPreferenceController(Context context, String key) {
|
public AutoBrightnessPreferenceController(Context context, String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
}
|
}
|
||||||
@@ -55,10 +72,28 @@ public class AutoBrightnessPreferenceController extends TogglePreferenceControll
|
|||||||
: UNSUPPORTED_ON_DEVICE;
|
: UNSUPPORTED_ON_DEVICE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
|
super.displayPreference(screen);
|
||||||
|
mPreference = screen.findPreference(getPreferenceKey());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getSummary() {
|
public CharSequence getSummary() {
|
||||||
return mContext.getText(isChecked()
|
return mContext.getText(isChecked()
|
||||||
? R.string.auto_brightness_summary_on
|
? R.string.auto_brightness_summary_on
|
||||||
: R.string.auto_brightness_summary_off);
|
: R.string.auto_brightness_summary_off);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStart() {
|
||||||
|
mContext.getContentResolver().registerContentObserver(
|
||||||
|
Settings.System.getUriFor(SYSTEM_KEY), false /* notifyForDescendants */,
|
||||||
|
mContentObserver);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStop() {
|
||||||
|
mContext.getContentResolver().unregisterContentObserver(mContentObserver);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user