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

Commit ccb6b9a9 authored by John Spurlock's avatar John Spurlock
Browse files

QuickSettings: only listen when expanded.

Register for active state updates only when the quick settings
panel is open.

Don't allow a dual-target tile and single-target tile on the same row.

Bug:14133785
Change-Id: I8a5ad3df9b67b5bc3518210d62b705483a422d8e
parent f967a548
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -21,10 +21,10 @@ import android.database.ContentObserver;
import android.os.Handler;
import android.provider.Settings.Global;

import com.android.systemui.statusbar.policy.Disposable;
import com.android.systemui.statusbar.policy.Listenable;

/** Helper for managing a global setting. **/
public abstract class GlobalSetting extends ContentObserver implements Disposable {
public abstract class GlobalSetting extends ContentObserver implements Listenable {
    private final Context mContext;
    private final String mSettingName;

@@ -34,8 +34,6 @@ public abstract class GlobalSetting extends ContentObserver implements Disposabl
        super(handler);
        mContext = context;
        mSettingName = settingName;
        mContext.getContentResolver().registerContentObserver(
                Global.getUriFor(mSettingName), false, this);
    }

    public int getValue() {
@@ -47,9 +45,14 @@ public abstract class GlobalSetting extends ContentObserver implements Disposabl
    }

    @Override
    public void dispose() {
    public void setListening(boolean listening) {
        if (listening) {
            mContext.getContentResolver().registerContentObserver(
                    Global.getUriFor(mSettingName), false, this);
        } else {
            mContext.getContentResolver().unregisterContentObserver(this);
        }
    }

    @Override
    public void onChange(boolean selfChange) {
+18 −9
Original line number Diff line number Diff line
@@ -80,7 +80,10 @@ public class QSPanel extends ViewGroup {
            showDetail(false /*show*/, mDetailRecord);
        }
        for (TileRecord r : mRecords) {
            r.tile.setShown(expanded);
            r.tile.setListening(expanded);
            if (expanded) {
                r.tile.refreshState();
            }
        }
    }

@@ -125,6 +128,7 @@ public class QSPanel extends ViewGroup {
            }
        };
        r.tileView.init(click, clickSecondary);
        r.tile.refreshState();
        mRecords.add(r);

        addView(r.tileView);
@@ -156,24 +160,29 @@ public class QSPanel extends ViewGroup {
        mCellHeight = (int)(mCellWidth / TILE_ASPECT);
        mLargeCellWidth = (int)(mCellWidth * LARGE_TILE_FACTOR);
        mLargeCellHeight = (int)(mCellHeight * LARGE_TILE_FACTOR);
        int r = 0;
        int c = 0;
        int r = -1;
        int c = -1;
        int rows = 0;
        boolean rowIsDual = false;
        for (TileRecord record : mRecords) {
            if (record.tileView.getVisibility() == GONE) continue;
            // wrap to next column if we've reached the max # of columns
            // also don't allow dual + single tiles on the same row
            if (r == -1 || c == (mColumns - 1) || rowIsDual != record.tile.supportsDualTargets()) {
                r++;
                c = 0;
                rowIsDual = record.tile.supportsDualTargets();
            } else {
                c++;
            }
            record.row = r;
            record.col = c;
            rows = r + 1;
            c++;
            if (c == mColumns /*end of normal column*/ || r == 0 && c == 2 /*end of 1st column*/) {
                c = 0;
                r++;
            }
        }

        for (TileRecord record : mRecords) {
            if (record.tileView.getVisibility() == GONE) continue;
            record.tileView.setDual(record.row == 0);
            record.tileView.setDual(record.tile.supportsDualTargets());
            final int cw = record.row == 0 ? mLargeCellWidth : mCellWidth;
            final int ch = record.row == 0 ? mLargeCellHeight : mCellHeight;
            record.tileView.measure(exactly(cw), exactly(ch));
+8 −15
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ import android.view.ViewGroup;
import com.android.systemui.qs.QSTile.State;
import com.android.systemui.statusbar.policy.BluetoothController;
import com.android.systemui.statusbar.policy.CastController;
import com.android.systemui.statusbar.policy.Disposable;
import com.android.systemui.statusbar.policy.Listenable;
import com.android.systemui.statusbar.policy.LocationController;
import com.android.systemui.statusbar.policy.NetworkController;
import com.android.systemui.statusbar.policy.RotationLockController;
@@ -47,8 +47,9 @@ import java.util.Objects;
 * handleUpdateState.  Callbacks affecting state should use refreshState to trigger another
 * state update pass on tile looper.
 */
public abstract class QSTile<TState extends State> implements Disposable {
    private final String TAG = "QSTile." + getClass().getSimpleName();
public abstract class QSTile<TState extends State> implements Listenable {
    protected final String TAG = "QSTile." + getClass().getSimpleName();
    protected static final boolean DEBUG = false;

    protected final Host mHost;
    protected final Context mContext;
@@ -69,6 +70,10 @@ public abstract class QSTile<TState extends State> implements Disposable {
        mHandler = new H(host.getLooper());
    }

    public boolean supportsDualTargets() {
        return false;
    }

    public Host getHost() {
        return mHost;
    }
@@ -111,10 +116,6 @@ public abstract class QSTile<TState extends State> implements Disposable {
        mHandler.obtainMessage(H.USER_SWITCH, newUserId).sendToTarget();
    }

    public void setShown(boolean shown) {
        mHandler.obtainMessage(H.SHOWN, shown ? 1 : 0, 0).sendToTarget();
    }

    // call only on tile worker looper

    private void handleSetCallback(Callback callback) {
@@ -126,10 +127,6 @@ public abstract class QSTile<TState extends State> implements Disposable {
        // optional
    }

    protected void handleShown(boolean shown) {
        // optional, discouraged
    }

    protected void handleRefreshState(Object arg) {
        handleUpdateState(mTmpState, arg);
        final boolean changed = mTmpState.copyTo(mState);
@@ -161,7 +158,6 @@ public abstract class QSTile<TState extends State> implements Disposable {
        private static final int REFRESH_STATE = 4;
        private static final int SHOW_DETAIL = 5;
        private static final int USER_SWITCH = 6;
        private static final int SHOWN = 7;

        private H(Looper looper) {
            super(looper);
@@ -189,9 +185,6 @@ public abstract class QSTile<TState extends State> implements Disposable {
                } else if (msg.what == USER_SWITCH) {
                    name = "handleUserSwitch";
                    handleUserSwitch(msg.arg1);
                } else if (msg.what == SHOWN) {
                    name = "handleShown";
                    handleShown(msg.arg1 != 0);
                }
            } catch (Throwable t) {
                final String error = "Error in " + name;
+10 −6
Original line number Diff line number Diff line
@@ -21,10 +21,10 @@ import android.database.ContentObserver;
import android.os.Handler;
import android.provider.Settings.Secure;

import com.android.systemui.statusbar.policy.Disposable;
import com.android.systemui.statusbar.policy.Listenable;

/** Helper for managing a secure setting. **/
public abstract class SecureSetting extends ContentObserver implements Disposable {
public abstract class SecureSetting extends ContentObserver implements Listenable {
    private final Context mContext;
    private final String mSettingName;

@@ -38,8 +38,7 @@ public abstract class SecureSetting extends ContentObserver implements Disposabl
    }

    public void rebindForCurrentUser() {
        mContext.getContentResolver().registerContentObserver(
                Secure.getUriFor(mSettingName), false, this);
        setListening(true);
    }

    public int getValue() {
@@ -51,9 +50,14 @@ public abstract class SecureSetting extends ContentObserver implements Disposabl
    }

    @Override
    public void dispose() {
    public void setListening(boolean listening) {
        if (listening) {
            mContext.getContentResolver().registerContentObserver(
                    Secure.getUriFor(mSettingName), false, this);
        } else {
            mContext.getContentResolver().unregisterContentObserver(this);
        }
    }

    @Override
    public void onChange(boolean selfChange) {
+9 −8
Original line number Diff line number Diff line
@@ -39,11 +39,6 @@ public class AirplaneModeTile extends QSTile<QSTile.BooleanState> {
                handleRefreshState(value);
            }
        };

        final IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED);
        mContext.registerReceiver(mReceiver, filter);
        refreshState();
    }

    @Override
@@ -84,10 +79,16 @@ public class AirplaneModeTile extends QSTile<QSTile.BooleanState> {
        }
    }

    public void dispose() {
        mSetting.dispose();
    public void setListening(boolean listening) {
        if (listening) {
            final IntentFilter filter = new IntentFilter();
            filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED);
            mContext.registerReceiver(mReceiver, filter);
        } else {
            mContext.unregisterReceiver(mReceiver);
        }
        mSetting.setListening(listening);
    }

    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override
Loading