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

Commit c3f42c10 authored by Jason Monk's avatar Jason Monk
Browse files

Add support for auto-adding tiles

hotspot, color inversion, data saver, and work profiles should add
themselves when they first become applicable.

Also refactor the availability flow a little bit.

Change-Id: Iaed89059540a98fefd4d26ce69edc0dde987b992
parent cafda1f9
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -44,6 +44,10 @@ public final class Prefs {
        Key.DND_NONE_SELECTED,
        Key.DND_FAVORITE_ZEN,
        Key.TV_PICTURE_IN_PICTURE_ONBOARDING_SHOWN,
        Key.QS_HOTSPOT_ADDED,
        Key.QS_DATA_SAVER_ADDED,
        Key.QS_INVERT_COLORS_ADDED,
        Key.QS_WORK_ADDED,
    })
    public @interface Key {
        String OVERVIEW_SEARCH_APP_WIDGET_ID = "searchAppWidgetId";
@@ -60,6 +64,10 @@ public final class Prefs {
        String DND_NONE_SELECTED = "DndNoneSelected";
        String DND_FAVORITE_ZEN = "DndFavoriteZen";
        String TV_PICTURE_IN_PICTURE_ONBOARDING_SHOWN = "TvPictureInPictureOnboardingShown";
        String QS_HOTSPOT_ADDED = "QsHotspotAdded";
        String QS_DATA_SAVER_ADDED = "QsDataSaverAdded";
        String QS_INVERT_COLORS_ADDED = "QsInvertColorsAdded";
        String QS_WORK_ADDED = "QsWorkAdded";
    }

    public static boolean getBoolean(Context context, @Key String key, boolean defaultValue) {
+11 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.view.ViewGroup;
import com.android.settingslib.RestrictedLockUtils;
import com.android.systemui.qs.QSTile.State;
import com.android.systemui.qs.external.TileServices;
import com.android.systemui.statusbar.phone.ManagedProfileController;
import com.android.systemui.statusbar.policy.BatteryController;
import com.android.systemui.statusbar.policy.BluetoothController;
import com.android.systemui.statusbar.policy.CastController;
@@ -114,6 +115,15 @@ public abstract class QSTile<TState extends State> implements Listenable {
        return null; // optional
    }

    /**
     * Is a startup check whether this device currently supports this tile.
     * Should not be used to conditionally hide tiles.  Only checked on tile
     * creation or whether should be shown in edit screen.
     */
    public boolean isAvailable() {
        return true;
    }

    public interface DetailAdapter {
        CharSequence getTitle();
        Boolean getToggleState();
@@ -392,6 +402,7 @@ public abstract class QSTile<TState extends State> implements Listenable {
        TileServices getTileServices();
        DisplayController getDisplayController();
        void removeTile(String tileSpec);
        ManagedProfileController getManagedProfileController();


        public interface Callback {
+2 −2
Original line number Diff line number Diff line
@@ -55,14 +55,14 @@ public class TileQueryHelper {
    private void addSystemTiles(QSTileHost host) {
        boolean hasColorMod = host.getDisplayController().isEnabled();
        String possible = mContext.getString(R.string.quick_settings_tiles_default)
                + ",hotspot,inversion,saver" + (hasColorMod ? ",colors" : "");
                + ",hotspot,inversion,saver,work" + (hasColorMod ? ",colors" : "");
        String[] possibleTiles = possible.split(",");
        final Handler qsHandler = new Handler(host.getLooper());
        final Handler mainHandler = new Handler(Looper.getMainLooper());
        for (int i = 0; i < possibleTiles.length; i++) {
            final String spec = possibleTiles[i];
            final QSTile<?> tile = host.createTile(spec);
            if (tile == null) {
            if (tile == null || !tile.isAvailable()) {
                continue;
            }
            tile.setListening(true);
+3 −2
Original line number Diff line number Diff line
@@ -146,8 +146,9 @@ public class BluetoothTile extends QSTile<QSTile.BooleanState> {
        }
    }

    public static boolean isSupported(Host host) {
        return host.getBluetoothController().isBluetoothSupported();
    @Override
    public boolean isAvailable() {
        return mController.isBluetoothSupported();
    }

    private final BluetoothController.Callback mCallback = new BluetoothController.Callback() {
+5 −4
Original line number Diff line number Diff line
@@ -136,6 +136,11 @@ public class CellularTile extends QSTile<QSTile.SignalState> {
        return MetricsEvent.QS_CELLULAR;
    }

    @Override
    public boolean isAvailable() {
        return mController.hasMobileDataFeature();
    }

    // Remove the period from the network name
    public static String removeTrailingPeriod(String string) {
        if (string == null) return null;
@@ -146,10 +151,6 @@ public class CellularTile extends QSTile<QSTile.SignalState> {
        return string;
    }

    public static boolean isSupported(Host host) {
        return host.getNetworkController().hasMobileDataFeature();
    }

    private static final class CallbackInfo {
        boolean enabled;
        boolean wifiEnabled;
Loading