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

Commit e6f1d4e5 authored by Jorge Martín's avatar Jorge Martín
Browse files

Add customization for Quick Settings [1/2]

Allow Quick Settings tiles to be arranged any way you want, delete them or add some.

I removed the "dual" status that was hardcoded into Wifi and BT tiles and added it
as a variable which is true when the tile is on the first row.

Also, the first row is now hardcoded to have only 2 items to follow the same design as before.

Inversion and Hotspot tile are no longer contextual and can be added, rmeoved or rearranged at will.

Settings: http://review.cyanogenmod.org/83418

Change-Id: Ie596a54a5c4eb777782fb047496cfcd0a6cd2e89
parent 3c081ac2
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -2096,6 +2096,19 @@ public final class Settings {
         */
        public static final String STATUS_BAR_QUICK_QS_PULLDOWN = "status_bar_quick_qs_pulldown";

        /**
         * List of QS tile names
         * @hide
         */
        public static final String QS_TILES = "sysui_qs_tiles";

        /**
         * Use "main" tiles on the first row of the quick settings panel
         * 0 = no, 1 = yes
         * @hide
         */
        public static final String QS_USE_MAIN_TILES = "sysui_qs_main_tiles";

        /**
         * Control whether the process CPU usage meter should be shown.
         *
+18 −11
Original line number Diff line number Diff line
@@ -25,8 +25,9 @@ import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Handler;
import android.os.Message;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -78,6 +79,8 @@ public class QSPanel extends ViewGroup {
    private QSFooter mFooter;
    private boolean mGridContentVisible = true;

    private boolean mUseMainTiles = false;

    public QSPanel(Context context) {
        this(context, null);
    }
@@ -204,7 +207,11 @@ public class QSPanel extends ViewGroup {
    }

    private void refreshAllTiles() {
        for (TileRecord r : mRecords) {
        mUseMainTiles = Settings.System.getIntForUser(getContext().getContentResolver(),
                Settings.System.QS_USE_MAIN_TILES, 1, UserHandle.myUserId()) == 1;
        for (int i = 0; i < mRecords.size(); i++) {
            TileRecord r = mRecords.get(i);
            r.tileView.setDual(mUseMainTiles && i < 2);
            r.tile.refreshState();
        }
        mFooter.refreshState();
@@ -394,15 +401,15 @@ public class QSPanel extends ViewGroup {
        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()) {
            if (mUseMainTiles && r == 0 && c == 1) {
                r = 1;
                c = 0;
            } else if (r == -1 || c == (mColumns - 1)) {
                r++;
                c = 0;
                rowIsDual = record.tile.supportsDualTargets();
            } else {
                c++;
            }
@@ -412,10 +419,9 @@ public class QSPanel extends ViewGroup {
        }

        for (TileRecord record : mRecords) {
            record.tileView.setDual(record.tile.supportsDualTargets());
            if (record.tileView.getVisibility() == GONE) continue;
            final int cw = record.row == 0 ? mLargeCellWidth : mCellWidth;
            final int ch = record.row == 0 ? mLargeCellHeight : mCellHeight;
            final int cw = (mUseMainTiles && record.row == 0) ? mLargeCellWidth : mCellWidth;
            final int ch = (mUseMainTiles && record.row == 0) ? mLargeCellHeight : mCellHeight;
            record.tileView.measure(exactly(cw), exactly(ch));
        }
        int h = rows == 0 ? brightnessHeight : (getRowTop(rows) + mPanelPaddingBottom);
@@ -443,7 +449,7 @@ public class QSPanel extends ViewGroup {
        for (TileRecord record : mRecords) {
            if (record.tileView.getVisibility() == GONE) continue;
            final int cols = getColumnCount(record.row);
            final int cw = record.row == 0 ? mLargeCellWidth : mCellWidth;
            final int cw = (mUseMainTiles && record.row == 0) ? mLargeCellWidth : mCellWidth;
            final int extra = (w - cw * cols) / (cols + 1);
            int left = record.col * cw + (record.col + 1) * extra;
            final int top = getRowTop(record.row);
@@ -469,7 +475,8 @@ public class QSPanel extends ViewGroup {
    private int getRowTop(int row) {
        if (row <= 0) return mBrightnessView.getMeasuredHeight() + mBrightnessPaddingTop;
        return mBrightnessView.getMeasuredHeight() + mBrightnessPaddingTop
                + mLargeCellHeight - mDualTileUnderlap + (row - 1) * mCellHeight;
                + (mUseMainTiles ? mLargeCellHeight - mDualTileUnderlap : mCellHeight)
                + (row - 1) * mCellHeight;
    }

    private int getColumnCount(int row) {
+7 −4
Original line number Diff line number Diff line
@@ -124,7 +124,9 @@ public class QSTileView extends ViewGroup {
        }
        if (mDualLabel != null) {
            labelText = mDualLabel.getText();
            if (mLabel != null) {
                labelDescription = mLabel.getContentDescription();
            }
            removeView(mDualLabel);
            mDualLabel = null;
        }
@@ -169,9 +171,6 @@ public class QSTileView extends ViewGroup {
    public void setDual(boolean dual) {
        final boolean changed = dual != mDual;
        mDual = dual;
        if (changed) {
            recreateLabel();
        }
        Drawable tileBackground = getTileBackground();
        if (tileBackground instanceof RippleDrawable) {
            setRipple((RippleDrawable) tileBackground);
@@ -194,6 +193,10 @@ public class QSTileView extends ViewGroup {
        mTopBackgroundView.setFocusable(dual);
        setFocusable(!dual);
        mDivider.setVisibility(dual ? VISIBLE : GONE);
        if (changed) {
            recreateLabel();
            updateTopPadding();
        }
        postInvalidate();
    }

+0 −5
Original line number Diff line number Diff line
@@ -45,11 +45,6 @@ public class BluetoothTile extends QSTile<QSTile.BooleanState> {
        mDetailAdapter = new BluetoothDetailAdapter();
    }

    @Override
    public boolean supportsDualTargets() {
        return true;
    }

    @Override
    public DetailAdapter getDetailAdapter() {
        return mDetailAdapter;
+1 −1
Original line number Diff line number Diff line
@@ -92,7 +92,7 @@ public class ColorInversionTile extends QSTile<QSTile.BooleanState> {
    protected void handleUpdateState(BooleanState state, Object arg) {
        final int value = arg instanceof Integer ? (Integer) arg : mSetting.getValue();
        final boolean enabled = value != 0;
        state.visible = enabled || mUsageTracker.isRecentlyUsed();
        state.visible = true;
        state.value = enabled;
        state.label = mContext.getString(R.string.quick_settings_inversion_label);
        state.iconId = enabled ? R.drawable.ic_qs_inversion_on : R.drawable.ic_qs_inversion_off;
Loading