Skip to content

Commit 638e012

Browse files
John SpurlockAndroid (Google) Code Review
authored andcommitted
Merge "Status Bar: Register for rotation lock status updates." into jb-dev
2 parents 2bccea2 + 781f0f4 commit 638e012

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

packages/SystemUI/src/com/android/systemui/statusbar/policy/AutoRotateController.java

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,40 @@
1818

1919
import android.content.ContentResolver;
2020
import android.content.Context;
21+
import android.database.ContentObserver;
2122
import android.os.AsyncTask;
23+
import android.os.Handler;
2224
import android.os.RemoteException;
2325
import android.os.ServiceManager;
2426
import android.provider.Settings;
2527
import android.util.Log;
26-
import android.util.Slog;
2728
import android.view.IWindowManager;
2829
import android.widget.CompoundButton;
2930

30-
/**
31-
* TODO: Listen for changes to the setting.
32-
*/
3331
public class AutoRotateController implements CompoundButton.OnCheckedChangeListener {
3432
private static final String TAG = "StatusBar.AutoRotateController";
3533

36-
private Context mContext;
37-
private CompoundButton mCheckBox;
34+
private final Context mContext;
35+
private final CompoundButton mCheckbox;
3836

3937
private boolean mAutoRotation;
4038

39+
private ContentObserver mAccelerometerRotationObserver = new ContentObserver(new Handler()) {
40+
@Override
41+
public void onChange(boolean selfChange) {
42+
updateCheckbox();
43+
}
44+
};
45+
4146
public AutoRotateController(Context context, CompoundButton checkbox) {
4247
mContext = context;
43-
mAutoRotation = getAutoRotation();
44-
mCheckBox = checkbox;
45-
checkbox.setChecked(mAutoRotation);
46-
checkbox.setOnCheckedChangeListener(this);
48+
mCheckbox = checkbox;
49+
updateCheckbox();
50+
mCheckbox.setOnCheckedChangeListener(this);
51+
52+
mContext.getContentResolver().registerContentObserver(
53+
Settings.System.getUriFor(Settings.System.ACCELEROMETER_ROTATION), true,
54+
mAccelerometerRotationObserver);
4755
}
4856

4957
public void onCheckedChanged(CompoundButton view, boolean checked) {
@@ -52,6 +60,15 @@ public void onCheckedChanged(CompoundButton view, boolean checked) {
5260
}
5361
}
5462

63+
public void release() {
64+
mContext.getContentResolver().unregisterContentObserver(mAccelerometerRotationObserver);
65+
}
66+
67+
private void updateCheckbox() {
68+
mAutoRotation = getAutoRotation();
69+
mCheckbox.setChecked(mAutoRotation);
70+
}
71+
5572
private boolean getAutoRotation() {
5673
ContentResolver cr = mContext.getContentResolver();
5774
return 0 != Settings.System.getInt(cr, Settings.System.ACCELEROMETER_ROTATION, 0);

packages/SystemUI/src/com/android/systemui/statusbar/tablet/SettingsView.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ protected void onDetachedFromWindow() {
7575
super.onDetachedFromWindow();
7676
mAirplane.release();
7777
mDoNotDisturb.release();
78+
mRotate.release();
7879
}
7980

8081
public void onClick(View v) {

0 commit comments

Comments
 (0)