OSDN Git Service

SystemUI: fix toggling lockscreen rotation [1/3]
authorDan Pasanen <invisiblek@cyanogenmod.org>
Mon, 2 May 2016 14:34:21 +0000 (09:34 -0500)
committerSteve Kondik <steve@cyngn.com>
Tue, 13 Sep 2016 07:12:41 +0000 (00:12 -0700)
Change-Id: I28fea0124c91b8efc206a940761e77fa61d1fefc

packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowManager.java

index 888e19c..1b469e4 100644 (file)
@@ -21,6 +21,7 @@ import android.content.pm.ActivityInfo;
 import android.content.res.Resources;
 import android.graphics.PixelFormat;
 import android.os.SystemProperties;
+import android.provider.Settings;
 import android.view.Gravity;
 import android.view.View;
 import android.view.ViewGroup;
@@ -47,7 +48,7 @@ public class StatusBarWindowManager implements RemoteInputController.Callback {
     private WindowManager.LayoutParams mLp;
     private WindowManager.LayoutParams mLpChanged;
     private int mBarHeight;
-    private final boolean mKeyguardScreenRotation;
+    private boolean mKeyguardScreenRotation;
     private final float mScreenBrightnessDoze;
     private final State mCurrentState = new State();
 
@@ -61,8 +62,13 @@ public class StatusBarWindowManager implements RemoteInputController.Callback {
 
     private boolean shouldEnableKeyguardScreenRotation() {
         Resources res = mContext.getResources();
+        boolean enableAccelerometerRotation = Settings.System.getInt(mContext.getContentResolver(),
+                Settings.System.ACCELEROMETER_ROTATION, 1) != 0;
+        boolean enableLockScreenRotation = CMSettings.System.getInt(mContext.getContentResolver(),
+                CMSettings.System.LOCKSCREEN_ROTATION, 0) != 0;
         return SystemProperties.getBoolean("lockscreen.rot_override", false)
-                || res.getBoolean(R.bool.config_enableLockScreenRotation);
+                || (res.getBoolean(R.bool.config_enableLockScreenRotation)
+                && (enableLockScreenRotation && enableAccelerometerRotation));
     }
 
     /**
@@ -96,6 +102,9 @@ public class StatusBarWindowManager implements RemoteInputController.Callback {
         mWindowManager.addView(mStatusBarView, mLp);
         mLpChanged = new WindowManager.LayoutParams();
         mLpChanged.copyFrom(mLp);
+
+        SettingsObserver observer = new SettingsObserver(new Handler());
+        observer.observe(mContext);
     }
 
     private void applyKeyguardFlags(State state) {
@@ -391,4 +400,32 @@ public class StatusBarWindowManager implements RemoteInputController.Callback {
             return result.toString();
         }
     }
+
+    private class SettingsObserver extends ContentObserver {
+        public SettingsObserver(Handler handler) {
+            super(handler);
+        }
+
+        public void observe(Context context) {
+            context.getContentResolver().registerContentObserver(
+                    Settings.System.getUriFor(Settings.System.ACCELEROMETER_ROTATION),
+                    false,
+                    this);
+            context.getContentResolver().registerContentObserver(
+                    CMSettings.System.getUriFor(CMSettings.System.LOCKSCREEN_ROTATION),
+                    false,
+                    this);
+        }
+
+        public void unobserve(Context context) {
+            context.getContentResolver().unregisterContentObserver(this);
+        }
+
+        @Override
+        public void onChange(boolean selfChange) {
+            mKeyguardScreenRotation = shouldEnableKeyguardScreenRotation();
+            // update the state
+            apply(mCurrentState);
+        }
+    }
 }