Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 781f0f49 authored by John Spurlock's avatar John Spurlock
Browse files

Status Bar: Register for rotation lock status updates.

Updating the rotation lock status in Settings is now instantly
reflected in the status bar icon.

Bug: 6481542
Change-Id: Ic592119f63306c97a961038a82526b339d063f66
parent 6a080bff
Loading
Loading
Loading
Loading
+27 −10
Original line number Diff line number Diff line
@@ -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);
+1 −0
Original line number Diff line number Diff line
@@ -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) {