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

Commit 6fb2c183 authored by Roman Birg's avatar Roman Birg
Browse files

SystemUI: add a disabled state for Quick Tiles



Some tiles may want to be visible, but not allow any user interaction
due to security reasons. Add a visual disabled state for tiles which are
not enabled.

With this patch, the Profiles tile and the Lockscreen toggle tile
disable themselves on a secure lock screen.

Ref: CYNGNOS-1597

Change-Id: I65ec7837661483d238d8dc3fa18419f76c8029dd
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
parent f15ce7a7
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -103,4 +103,7 @@
    <color name="qs_detailed_expansion_indicator_color">@color/qs_title_text_color</color>
    <color name="qs_detailed_title_text_color">@color/qs_title_text_color</color>
    <color name="qs_detailed_icon_tint_color">@color/qs_title_text_color</color>

    <!-- Quick tile text color when the tile is disabled -->
    <color name="qs_tile_text_disabled">#ff747474</color>
</resources>
+1 −0
Original line number Diff line number Diff line
@@ -353,6 +353,7 @@ public class QSDragPanel extends QSPanel implements View.OnDragListener, View.On
        }
        final int visibility = state.visible ? VISIBLE : GONE;
        setTileVisibility(r.tileView, visibility);
        setTileEnabled(r.tileView, state.enabled);
        r.tileView.onStateChanged(state);
    }

+12 −0
Original line number Diff line number Diff line
@@ -281,6 +281,15 @@ public class QSPanel extends ViewGroup {
        v.setVisibility(visibility);
    }

    protected void setTileEnabled(View v, boolean enabled) {
        mHandler.obtainMessage(H.SET_TILE_ENABLED, enabled ? 1 : 0, 0, v).sendToTarget();
    }

    private void handleSetTileEnabled(View v, boolean enabled) {
        if (enabled == v.isEnabled()) return;
        v.setEnabled(enabled);
    }

    public void setTiles(Collection<QSTile<?>> tiles) {
        for (TileRecord record : mRecords) {
            removeView(record.tileView);
@@ -606,12 +615,15 @@ public class QSPanel extends ViewGroup {
    private class H extends Handler {
        private static final int SHOW_DETAIL = 1;
        private static final int SET_TILE_VISIBILITY = 2;
        private static final int SET_TILE_ENABLED = 3;
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == SHOW_DETAIL) {
                handleShowDetail((Record)msg.obj, msg.arg1 != 0);
            } else if (msg.what == SET_TILE_VISIBILITY) {
                handleSetTileVisibility((View)msg.obj, msg.arg1);
            } else if (msg.what == SET_TILE_ENABLED) {
                handleSetTileEnabled((View)msg.obj, msg.arg1 == 1);
            }
        }
    }
+4 −0
Original line number Diff line number Diff line
@@ -497,6 +497,7 @@ public abstract class QSTile<TState extends State> implements Listenable {

    public static class State {
        public boolean visible;
        public boolean enabled = true;
        public Icon icon;
        public String label;
        public String contentDescription;
@@ -507,6 +508,7 @@ public abstract class QSTile<TState extends State> implements Listenable {
            if (other == null) throw new IllegalArgumentException();
            if (!other.getClass().equals(getClass())) throw new IllegalArgumentException();
            final boolean changed = other.visible != visible
                    || !Objects.equals(other.enabled, enabled)
                    || !Objects.equals(other.icon, icon)
                    || !Objects.equals(other.label, label)
                    || !Objects.equals(other.contentDescription, contentDescription)
@@ -514,6 +516,7 @@ public abstract class QSTile<TState extends State> implements Listenable {
                    || !Objects.equals(other.dualLabelContentDescription,
                    dualLabelContentDescription);
            other.visible = visible;
            other.enabled = enabled;
            other.icon = icon;
            other.label = label;
            other.contentDescription = contentDescription;
@@ -530,6 +533,7 @@ public abstract class QSTile<TState extends State> implements Listenable {
        protected StringBuilder toStringBuilder() {
            final StringBuilder sb = new StringBuilder(getClass().getSimpleName()).append('[');
            sb.append("visible=").append(visible);
            sb.append(",enabled=").append(enabled);
            sb.append(",icon=").append(icon);
            sb.append(",label=").append(label);
            sb.append(",contentDescription=").append(contentDescription);
+21 −0
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.Typeface;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable;
@@ -328,9 +330,20 @@ public class QSTileView extends ViewGroup {
            mDualLabel.setText(state.label);
            mDualLabel.setContentDescription(state.dualLabelContentDescription);
            mTopBackgroundView.setContentDescription(state.contentDescription);
            if (!Objects.equals(state.enabled, mDualLabel.isEnabled())) {
                mTopBackgroundView.setEnabled(state.enabled);
                mDualLabel.setEnabled(state.enabled);
                mDualLabel.setTextColor(mContext.getResources().getColor(state.enabled ?
                        R.color.qs_tile_text : R.color.qs_tile_text_disabled));
            }
        } else {
            mLabel.setText(state.label);
            setContentDescription(state.contentDescription);
            if (!Objects.equals(state.enabled, mLabel.isEnabled())) {
                mLabel.setEnabled(state.enabled);
                mLabel.setTextColor(mContext.getResources().getColor(state.enabled ?
                        R.color.qs_tile_text : R.color.qs_tile_text_disabled));
            }
        }
    }

@@ -349,6 +362,14 @@ public class QSTileView extends ViewGroup {
                }
            }
        }
        if (!Objects.equals(state.enabled, iv.isEnabled())) {
            iv.setEnabled(state.enabled);
            if (state.enabled) {
                iv.setColorFilter(null);
            } else {
                iv.setColorFilter(Color.GRAY, PorterDuff.Mode.MULTIPLY);
            }
        }
    }

    public void onStateChanged(QSTile.State state) {
Loading