summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/display/SmartAutoRotatePreferenceController.java
diff options
context:
space:
mode:
authorAbel Tesfaye <tesfaye@google.com>2021-06-04 17:53:45 +0000
committerAbel Tesfaye <tesfaye@google.com>2021-06-04 18:00:21 +0000
commit4763e1f16b6d1968d0226c0efac688eabf28a1ca (patch)
tree280852d19feaf98cfbae3f79b0d87e7468462b03 /src/com/android/settings/display/SmartAutoRotatePreferenceController.java
parent6c0a701540ee3f4caa0450e58420e46ca74a54d7 (diff)
downloadpackages_apps_Settings-4763e1f16b6d1968d0226c0efac688eabf28a1ca.tar.gz
packages_apps_Settings-4763e1f16b6d1968d0226c0efac688eabf28a1ca.tar.bz2
packages_apps_Settings-4763e1f16b6d1968d0226c0efac688eabf28a1ca.zip
Fix for Smart auto rotate text summary not updating after QS toggle is modified
Test: locally with flame Bug: 190198617 Change-Id: I7f896cd5e9bdd0974775eff01120527602662c5b
Diffstat (limited to 'src/com/android/settings/display/SmartAutoRotatePreferenceController.java')
-rw-r--r--src/com/android/settings/display/SmartAutoRotatePreferenceController.java40
1 files changed, 37 insertions, 3 deletions
diff --git a/src/com/android/settings/display/SmartAutoRotatePreferenceController.java b/src/com/android/settings/display/SmartAutoRotatePreferenceController.java
index 0e2e013c6e..8c25a05ca3 100644
--- a/src/com/android/settings/display/SmartAutoRotatePreferenceController.java
+++ b/src/com/android/settings/display/SmartAutoRotatePreferenceController.java
@@ -23,15 +23,23 @@ import android.os.UserHandle;
import android.provider.Settings;
import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
import com.android.internal.view.RotationPolicy;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnStart;
+import com.android.settingslib.core.lifecycle.events.OnStop;
/**
* SmartAutoRotatePreferenceController provides auto rotate summary in display settings
*/
-public class SmartAutoRotatePreferenceController extends BasePreferenceController {
+public class SmartAutoRotatePreferenceController extends BasePreferenceController
+ implements LifecycleObserver, OnStart, OnStop {
+
+ private RotationPolicy.RotationPolicyListener mRotationPolicyListener;
+ private Preference mPreference;
public SmartAutoRotatePreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
@@ -43,8 +51,34 @@ public class SmartAutoRotatePreferenceController extends BasePreferenceControlle
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
- protected void update(Preference preference) {
- refreshSummary(preference);
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mPreference = screen.findPreference(getPreferenceKey());
+ }
+
+ @Override
+ public void onStart() {
+ if (mRotationPolicyListener == null) {
+ mRotationPolicyListener = new RotationPolicy.RotationPolicyListener() {
+ @Override
+ public void onChange() {
+ if (mPreference != null) {
+ refreshSummary(mPreference);
+ }
+ }
+ };
+ }
+ RotationPolicy.registerRotationPolicyListener(mContext,
+ mRotationPolicyListener);
+ }
+
+ @Override
+ public void onStop() {
+ if (mRotationPolicyListener != null) {
+ RotationPolicy.unregisterRotationPolicyListener(mContext,
+ mRotationPolicyListener);
+ }
}
@Override