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

Commit d03a7431 authored by Amin Shaikh's avatar Amin Shaikh
Browse files

Immediately enter transient enabling state in QS.

Toggling bluetooth/wifi/tethering can feel unresponsive due to the time
it takes for these services to become enabled. This change immediately
updates the QS tile UI to reflect the transient enabling state.

Fixes: 73714270
Test: visually tapping on each tile slowly and rapidly
Change-Id: Iec10054f2af4ed78e2ddc2fdcd10245a627ca50a
parent 3eef2efe
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -694,7 +694,8 @@
    <string name="quick_settings_bluetooth_secondary_label_headset">Headset</string>
    <!-- QuickSettings: Bluetooth secondary label for an input/IO device being connected [CHAR LIMIT=20]-->
    <string name="quick_settings_bluetooth_secondary_label_input">Input</string>

    <!-- QuickSettings: Bluetooth secondary label shown when bluetooth is being enabled [CHAR LIMIT=NONE] -->
    <string name="quick_settings_bluetooth_secondary_label_transient">Turning on&#8230;</string>
    <!-- QuickSettings: Brightness [CHAR LIMIT=NONE] -->
    <string name="quick_settings_brightness_label">Brightness</string>
    <!-- QuickSettings: Rotation Unlocked [CHAR LIMIT=NONE] -->
@@ -743,6 +744,8 @@
    <string name="quick_settings_wifi_on_label">Wi-Fi On</string>
    <!-- QuickSettings: Wifi detail panel, text when there are no items [CHAR LIMIT=NONE] -->
    <string name="quick_settings_wifi_detail_empty_text">No Wi-Fi networks available</string>
    <!-- QuickSettings: Wifi secondary label shown when the wifi is being enabled [CHAR LIMIT=NONE] -->
    <string name="quick_settings_wifi_secondary_label_transient">Turning on&#8230;</string>
    <!-- QuickSettings: Cast title [CHAR LIMIT=NONE] -->
    <string name="quick_settings_cast_title">Cast</string>
    <!-- QuickSettings: Cast detail panel, status text when casting [CHAR LIMIT=NONE] -->
@@ -776,7 +779,7 @@
    <!-- QuickSettings: Hotspot. [CHAR LIMIT=NONE] -->
    <string name="quick_settings_hotspot_label">Hotspot</string>
    <!-- QuickSettings: Hotspot. Secondary label shown when the hotspot is being enabled [CHAR LIMIT=NONE] -->
    <string name="quick_settings_hotspot_secondary_label_transient">Turning on...</string>
    <string name="quick_settings_hotspot_secondary_label_transient">Turning on&#8230;</string>
    <!-- QuickSettings: Hotspot: Secondary label for how many devices are connected to the hotspot [CHAR LIMIT=NONE] -->
    <plurals name="quick_settings_hotspot_secondary_label_num_devices">
        <item quantity="one">%d device</item>
+1 −0
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ public abstract class QSTileImpl<TState extends State> implements QSTile {
    protected static final boolean DEBUG = Log.isLoggable("Tile", Log.DEBUG);

    private static final long DEFAULT_STALE_TIMEOUT = 10 * DateUtils.MINUTE_IN_MILLIS;
    protected static final Object ARG_SHOW_TRANSIENT_ENABLING = new Object();

    protected final QSHost mHost;
    protected final Context mContext;
+11 −6
Original line number Diff line number Diff line
@@ -90,6 +90,8 @@ public class BluetoothTile extends QSTileImpl<BooleanState> {
    protected void handleClick() {
        // Secondary clicks are header clicks, just toggle.
        final boolean isEnabled = mState.value;
        // Immediately enter transient enabling state when turning bluetooth on.
        refreshState(isEnabled ? null : ARG_SHOW_TRANSIENT_ENABLING);
        mController.setBluetoothEnabled(!isEnabled);
    }

@@ -118,9 +120,10 @@ public class BluetoothTile extends QSTileImpl<BooleanState> {

    @Override
    protected void handleUpdateState(BooleanState state, Object arg) {
        final boolean enabled = mController.isBluetoothEnabled();
        final boolean transientEnabling = arg == ARG_SHOW_TRANSIENT_ENABLING;
        final boolean enabled = transientEnabling || mController.isBluetoothEnabled();
        final boolean connected = mController.isBluetoothConnected();
        state.isTransient = mController.isBluetoothConnecting()
        state.isTransient = transientEnabling || mController.isBluetoothConnecting()
                || mController.getBluetoothState() == BluetoothAdapter.STATE_TURNING_ON;
        state.dualTarget = true;
        state.value = enabled;
@@ -129,7 +132,6 @@ public class BluetoothTile extends QSTileImpl<BooleanState> {
        }
        state.slash.isSlashed = !enabled;
        state.label = mContext.getString(R.string.quick_settings_bluetooth_label);

        if (enabled) {
            if (connected) {
                state.icon = new BluetoothConnectedTileIcon();
@@ -155,8 +157,7 @@ public class BluetoothTile extends QSTileImpl<BooleanState> {
            state.state = Tile.STATE_INACTIVE;
        }

        state.secondaryLabel = getSecondaryLabel(enabled, connected);

        state.secondaryLabel = getSecondaryLabel(enabled, connected, state.isTransient);
        state.dualLabelContentDescription = mContext.getResources().getString(
                R.string.accessibility_quick_settings_open_settings, getTileLabel());
        state.expandedAccessibilityClassName = Switch.class.getName();
@@ -169,9 +170,13 @@ public class BluetoothTile extends QSTileImpl<BooleanState> {
     *
     * @param enabled whether bluetooth is enabled
     * @param connected whether there's a device connected via bluetooth
     * @param isTransient whether bluetooth is currently in a transient state turning on
     */
    @Nullable
    private String getSecondaryLabel(boolean enabled, boolean connected) {
    private String getSecondaryLabel(boolean enabled, boolean connected, boolean isTransient) {
        if (isTransient) {
            return mContext.getString(R.string.quick_settings_bluetooth_secondary_label_transient);
        }
        final CachedBluetoothDevice lastDevice = mController.getLastDevice();

        if (enabled && connected && lastDevice != null) {
+7 −5
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import android.content.ComponentName;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.UserManager;

import android.provider.Settings.Global;
import android.service.quicksettings.Tile;
import android.widget.Switch;
@@ -29,9 +28,9 @@ import android.widget.Switch;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.plugins.qs.QSTile.AirplaneBooleanState;
import com.android.systemui.qs.GlobalSetting;
import com.android.systemui.qs.QSHost;
import com.android.systemui.plugins.qs.QSTile.AirplaneBooleanState;
import com.android.systemui.qs.tileimpl.QSTileImpl;
import com.android.systemui.statusbar.policy.HotspotController;

@@ -96,10 +95,12 @@ public class HotspotTile extends QSTileImpl<AirplaneBooleanState> {

    @Override
    protected void handleClick() {
        final boolean isEnabled = (Boolean) mState.value;
        final boolean isEnabled = mState.value;
        if (!isEnabled && mAirplaneMode.getValue() != 0) {
            return;
        }
        // Immediately enter transient enabling state when turning hotspot on.
        refreshState(isEnabled ? null : ARG_SHOW_TRANSIENT_ENABLING);
        mController.setHotspotEnabled(!isEnabled);
    }

@@ -110,12 +111,13 @@ public class HotspotTile extends QSTileImpl<AirplaneBooleanState> {

    @Override
    protected void handleUpdateState(AirplaneBooleanState state, Object arg) {
        final boolean transientEnabling = arg == ARG_SHOW_TRANSIENT_ENABLING;
        if (state.slash == null) {
            state.slash = new SlashState();
        }

        final int numConnectedDevices;
        final boolean isTransient = mController.isHotspotTransient();
        final boolean isTransient = transientEnabling || mController.isHotspotTransient();

        checkIfRestrictionEnforcedByAdminOnly(state, UserManager.DISALLOW_CONFIG_TETHERING);
        if (arg instanceof CallbackInfo) {
@@ -123,7 +125,7 @@ public class HotspotTile extends QSTileImpl<AirplaneBooleanState> {
            state.value = info.enabled;
            numConnectedDevices = info.numConnectedDevices;
        } else {
            state.value = mController.isHotspotEnabled();
            state.value = transientEnabling || mController.isHotspotEnabled();
            numConnectedDevices = mController.getNumConnectedDevices();
        }

+19 −8
Original line number Diff line number Diff line
@@ -117,7 +117,10 @@ public class WifiTile extends QSTileImpl<SignalState> {
    protected void handleClick() {
        // Secondary clicks are header clicks, just toggle.
        mState.copyTo(mStateBeforeClick);
        mController.setWifiEnabled(!mState.value);
        boolean wifiEnabled = mState.value;
        // Immediately enter transient state when turning on wifi.
        refreshState(wifiEnabled ? null : ARG_SHOW_TRANSIENT_ENABLING);
        mController.setWifiEnabled(!wifiEnabled);
    }

    @Override
@@ -141,11 +144,13 @@ public class WifiTile extends QSTileImpl<SignalState> {
    @Override
    protected void handleUpdateState(SignalState state, Object arg) {
        if (DEBUG) Log.d(TAG, "handleUpdateState arg=" + arg);
        CallbackInfo cb = (CallbackInfo) arg;
        if (cb == null) {
        final CallbackInfo cb;
        if (arg != null && arg instanceof CallbackInfo) {
            cb = (CallbackInfo) arg;
        } else {
            cb = mSignalCallback.mInfo;
        }

        boolean transientEnabling = arg == ARG_SHOW_TRANSIENT_ENABLING;
        boolean wifiConnected = cb.enabled && (cb.wifiSignalIconId > 0) && (cb.enabledDesc != null);
        boolean wifiNotConnected = (cb.wifiSignalIconId > 0) && (cb.enabledDesc == null);
        boolean enabledChanging = state.value != cb.enabled;
@@ -158,14 +163,16 @@ public class WifiTile extends QSTileImpl<SignalState> {
            state.slash.rotation = 6;
        }
        state.slash.isSlashed = false;
        boolean isTransient = transientEnabling || cb.isTransient;
        state.secondaryLabel = getSecondaryLabel(isTransient);
        state.state = Tile.STATE_ACTIVE;
        state.dualTarget = true;
        state.value = cb.enabled;
        state.value = transientEnabling || cb.enabled;
        state.activityIn = cb.enabled && cb.activityIn;
        state.activityOut = cb.enabled && cb.activityOut;
        final StringBuffer minimalContentDescription = new StringBuffer();
        final Resources r = mContext.getResources();
        if (cb.isTransient) {
        if (isTransient) {
            state.icon = ResourceIcon.get(R.drawable.ic_signal_wifi_transient_animation);
            state.label = r.getString(R.string.quick_settings_wifi_label);
        } else if (!state.value) {
@@ -197,6 +204,12 @@ public class WifiTile extends QSTileImpl<SignalState> {
        state.expandedAccessibilityClassName = Switch.class.getName();
    }

    private CharSequence getSecondaryLabel(boolean isTransient) {
        return isTransient
                ? mContext.getString(R.string.quick_settings_wifi_secondary_label_transient)
                : null;
    }

    @Override
    public int getMetricsCategory() {
        return MetricsEvent.QS_WIFI;
@@ -277,8 +290,6 @@ public class WifiTile extends QSTileImpl<SignalState> {
        }
    }

    ;

    protected class WifiDetailAdapter implements DetailAdapter,
            NetworkController.AccessPointController.AccessPointCallback, QSDetailItems.Callback {

Loading