Merge "Status Bar: Register for rotation lock status updates." into jb-dev

This commit is contained in:
John Spurlock
2012-05-22 13:40:35 -07:00
committed by Android (Google) Code Review
2 changed files with 28 additions and 10 deletions

View File

@@ -18,32 +18,40 @@ package com.android.systemui.statusbar.policy;
import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.provider.Settings;
import android.util.Log;
import android.util.Slog;
import android.view.IWindowManager;
import android.widget.CompoundButton;
/**
* TODO: Listen for changes to the setting.
*/
public class AutoRotateController implements CompoundButton.OnCheckedChangeListener {
private static final String TAG = "StatusBar.AutoRotateController";
private Context mContext;
private CompoundButton mCheckBox;
private final Context mContext;
private final CompoundButton mCheckbox;
private boolean mAutoRotation;
private ContentObserver mAccelerometerRotationObserver = new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange) {
updateCheckbox();
}
};
public AutoRotateController(Context context, CompoundButton checkbox) {
mContext = context;
mAutoRotation = getAutoRotation();
mCheckBox = checkbox;
checkbox.setChecked(mAutoRotation);
checkbox.setOnCheckedChangeListener(this);
mCheckbox = checkbox;
updateCheckbox();
mCheckbox.setOnCheckedChangeListener(this);
mContext.getContentResolver().registerContentObserver(
Settings.System.getUriFor(Settings.System.ACCELEROMETER_ROTATION), true,
mAccelerometerRotationObserver);
}
public void onCheckedChanged(CompoundButton view, boolean checked) {
@@ -52,6 +60,15 @@ public class AutoRotateController implements CompoundButton.OnCheckedChangeListe
}
}
public void release() {
mContext.getContentResolver().unregisterContentObserver(mAccelerometerRotationObserver);
}
private void updateCheckbox() {
mAutoRotation = getAutoRotation();
mCheckbox.setChecked(mAutoRotation);
}
private boolean getAutoRotation() {
ContentResolver cr = mContext.getContentResolver();
return 0 != Settings.System.getInt(cr, Settings.System.ACCELEROMETER_ROTATION, 0);

View File

@@ -75,6 +75,7 @@ public class SettingsView extends LinearLayout implements View.OnClickListener {
super.onDetachedFromWindow();
mAirplane.release();
mDoNotDisturb.release();
mRotate.release();
}
public void onClick(View v) {