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

Commit cf3544bb authored by chelseahao's avatar chelseahao Committed by Chelsea Hao
Browse files

Add auto on toggle UI.

Test: atest -c com.android.systemui.qs.tiles.dialog.bluetooth
Bug: b/316822488 b/316985153
Flag: ACONFIG com.android.settingslib.flags.bluetooth_qs_tile_dialog_auto_on_toggle DISABLED
Change-Id: I34141bb31a2d1fc51a2162064555645cff6c1db6
parent 69a291fc
Loading
Loading
Loading
Loading
+83 −10
Original line number Diff line number Diff line
@@ -81,7 +81,7 @@
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="21dp"
        android:minHeight="145dp"
        android:minHeight="@dimen/bluetooth_dialog_scroll_view_min_height"
        android:fillViewport="true"
        app:layout_constrainedHeight="true"
        app:layout_constraintStart_toStartOf="parent"
@@ -97,11 +97,11 @@
            <TextView
                android:id="@+id/bluetooth_toggle_title"
                android:layout_width="0dp"
                android:layout_height="64dp"
                android:maxLines="1"
                android:layout_height="68dp"
                android:maxLines="2"
                android:ellipsize="end"
                android:gravity="start|center_vertical"
                android:paddingEnd="0dp"
                android:paddingEnd="15dp"
                android:paddingStart="36dp"
                android:text="@string/turn_on_bluetooth"
                android:clickable="false"
@@ -114,7 +114,7 @@
            <Switch
                android:id="@+id/bluetooth_toggle"
                android:layout_width="wrap_content"
                android:layout_height="64dp"
                android:layout_height="68dp"
                android:gravity="start|center_vertical"
                android:paddingEnd="40dp"
                android:contentDescription="@string/turn_on_bluetooth"
@@ -126,14 +126,79 @@
                app:layout_constraintStart_toEndOf="@+id/bluetooth_toggle_title"
                app:layout_constraintTop_toTopOf="parent" />

            <androidx.constraintlayout.widget.Group
                android:id="@+id/bluetooth_auto_on_toggle_layout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:visibility="gone"
                app:constraint_referenced_ids="bluetooth_auto_on_toggle_title,bluetooth_auto_on_toggle,bluetooth_auto_on_toggle_info_icon,bluetooth_auto_on_toggle_info_text" />

            <TextView
                android:id="@+id/bluetooth_auto_on_toggle_title"
                android:layout_width="0dp"
                android:layout_height="68dp"
                android:layout_marginBottom="20dp"
                android:maxLines="2"
                android:ellipsize="end"
                android:text="@string/turn_on_bluetooth_auto_tomorrow"
                android:gravity="start|center_vertical"
                android:paddingEnd="15dp"
                android:paddingStart="36dp"
                android:clickable="false"
                android:textAppearance="@style/TextAppearance.Dialog.Title"
                android:textSize="16sp"
                app:layout_constraintEnd_toStartOf="@+id/bluetooth_auto_on_toggle"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/bluetooth_toggle_title" />

            <Switch
                android:id="@+id/bluetooth_auto_on_toggle"
                android:layout_width="wrap_content"
                android:layout_height="68dp"
                android:layout_marginBottom="20dp"
                android:gravity="start|center_vertical"
                android:paddingEnd="40dp"
                android:contentDescription="@string/turn_on_bluetooth_auto_tomorrow"
                android:switchMinWidth="@dimen/settingslib_switch_track_width"
                android:theme="@style/MainSwitch.Settingslib"
                android:thumb="@drawable/settingslib_thumb_selector"
                android:track="@drawable/settingslib_track_selector"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toEndOf="@+id/bluetooth_auto_on_toggle_title"
                app:layout_constraintTop_toBottomOf="@+id/bluetooth_toggle" />

            <ImageView
                android:id="@+id/bluetooth_auto_on_toggle_info_icon"
                android:src="@drawable/ic_info_outline"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:tint="?android:attr/textColorTertiary"
                android:paddingStart="36dp"
                android:layout_marginTop="20dp"
                android:layout_marginBottom="@dimen/bluetooth_dialog_layout_margin"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/bluetooth_auto_on_toggle" />

            <TextView
                android:id="@+id/bluetooth_auto_on_toggle_info_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:paddingStart="36dp"
                android:paddingEnd="40dp"
                android:text="@string/turn_on_bluetooth_auto_info"
                android:textAppearance="@style/TextAppearance.Dialog.Body.Message"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/bluetooth_auto_on_toggle_info_icon" />

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/device_list"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/bluetooth_toggle"
                app:layout_constraintBottom_toTopOf="@+id/see_all_button" />
                app:layout_constraintTop_toBottomOf="@+id/bluetooth_toggle" />

            <Button
                android:id="@+id/see_all_button"
@@ -168,12 +233,10 @@
                android:background="@drawable/bluetooth_tile_dialog_bg_off"
                android:layout_width="0dp"
                android:layout_height="64dp"
                android:layout_marginBottom="9dp"
                android:contentDescription="@string/accessibility_bluetooth_device_settings_pair_new_device"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/see_all_button"
                app:layout_constraintBottom_toTopOf="@+id/done_button"
                android:drawableStart="@drawable/ic_add"
                android:drawablePadding="20dp"
                android:drawableTint="?android:attr/textColorPrimary"
@@ -186,11 +249,19 @@
                android:ellipsize="end"
                android:visibility="gone" />

            <androidx.constraintlayout.widget.Barrier
                android:id="@+id/barrier"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:barrierDirection="bottom"
                app:constraint_referenced_ids="pair_new_device_button,bluetooth_auto_on_toggle_info_text" />

            <Button
                android:id="@+id/done_button"
                style="@style/Widget.Dialog.Button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="9dp"
                android:layout_marginBottom="@dimen/dialog_bottom_padding"
                android:layout_marginEnd="@dimen/dialog_side_padding"
                android:layout_marginStart="@dimen/dialog_side_padding"
@@ -200,7 +271,9 @@
                android:maxLines="1"
                android:text="@string/inline_done_button"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintBottom_toBottomOf="parent" />
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/barrier"
                app:layout_constraintVertical_bias="1" />
        </androidx.constraintlayout.widget.ConstraintLayout>
    </androidx.core.widget.NestedScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
 No newline at end of file
+4 −0
Original line number Diff line number Diff line
@@ -1717,6 +1717,10 @@
    <dimen name="bluetooth_dialog_layout_margin">16dp</dimen>
    <!-- The height of the bluetooth device in bluetooth dialog. -->
    <dimen name="bluetooth_dialog_device_height">72dp</dimen>
    <!-- The height of the main scroll view in bluetooth dialog. -->
    <dimen name="bluetooth_dialog_scroll_view_min_height">145dp</dimen>
    <!-- The height of the main scroll view in bluetooth dialog with auto on toggle. -->
    <dimen name="bluetooth_dialog_scroll_view_min_height_with_auto_on">350dp</dimen>

    <!-- Height percentage of the parent container occupied by the communal view -->
    <item name="communal_source_height_percentage" format="float" type="dimen">0.80</item>
+4 −0
Original line number Diff line number Diff line
@@ -669,6 +669,10 @@
    <string name="accessibility_quick_settings_bluetooth_device_tap_to_disconnect">disconnect</string>
    <!-- QuickSettings: Accessibility label to activate a device [CHAR LIMIT=NONE]-->
    <string name="accessibility_quick_settings_bluetooth_device_tap_to_activate">activate</string>
    <!-- QuickSettings: Bluetooth auto on tomorrow [CHAR LIMIT=NONE]-->
    <string name="turn_on_bluetooth_auto_tomorrow">Automatically turn on again tomorrow</string>
    <!-- QuickSettings: Bluetooth auto on info text [CHAR LIMIT=NONE]-->
    <string name="turn_on_bluetooth_auto_info">Features like Quick Share, Find My Device, and device location use Bluetooth</string>

    <!-- QuickSettings: Bluetooth secondary label for the battery level of a connected device [CHAR LIMIT=20]-->
    <string name="quick_settings_bluetooth_secondary_label_battery_level"><xliff:g id="battery_level_as_percentage">%s</xliff:g> battery</string>
+15 −5
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ import kotlinx.coroutines.withContext
internal class BluetoothTileDialog
constructor(
    private val bluetoothToggleInitialValue: Boolean,
    private val subtitleResIdInitialValue: Int,
    private val initialUiProperties: BluetoothTileDialogViewModel.UiProperties,
    private val cachedContentHeight: Int,
    private val bluetoothTileDialogCallback: BluetoothTileDialogCallback,
    @Main private val mainDispatcher: CoroutineDispatcher,
@@ -89,6 +89,7 @@ constructor(

    private lateinit var toggleView: Switch
    private lateinit var subtitleTextView: TextView
    private lateinit var autoOnToggleView: View
    private lateinit var doneButton: View
    private lateinit var seeAllButton: View
    private lateinit var pairNewDeviceButton: View
@@ -108,6 +109,7 @@ constructor(

        toggleView = requireViewById(R.id.bluetooth_toggle)
        subtitleTextView = requireViewById(R.id.bluetooth_tile_dialog_subtitle) as TextView
        autoOnToggleView = requireViewById(R.id.bluetooth_auto_on_toggle_layout)
        doneButton = requireViewById(R.id.done_button)
        seeAllButton = requireViewById(R.id.see_all_button)
        pairNewDeviceButton = requireViewById(R.id.pair_new_device_button)
@@ -116,7 +118,7 @@ constructor(
        setupToggle()
        setupRecyclerView()

        subtitleTextView.text = context.getString(subtitleResIdInitialValue)
        subtitleTextView.text = context.getString(initialUiProperties.subTitleResId)
        doneButton.setOnClickListener { dismiss() }
        seeAllButton.setOnClickListener { bluetoothTileDialogCallback.onSeeAllClicked(it) }
        pairNewDeviceButton.setOnClickListener {
@@ -124,7 +126,9 @@ constructor(
        }
        requireViewById<View>(R.id.scroll_view).apply {
            scrollViewContent = this
            layoutParams.height = cachedContentHeight
            minimumHeight =
                resources.getDimensionPixelSize(initialUiProperties.scrollViewMinHeightResId)
            layoutParams.height = maxOf(cachedContentHeight, minimumHeight)
        }
        progressBarAnimation = requireViewById(R.id.bluetooth_tile_dialog_progress_animation)
        progressBarBackground = requireViewById(R.id.bluetooth_tile_dialog_progress_background)
@@ -178,13 +182,17 @@ constructor(
        }
    }

    internal fun onBluetoothStateUpdated(isEnabled: Boolean, subtitleResId: Int) {
    internal fun onBluetoothStateUpdated(
        isEnabled: Boolean,
        uiProperties: BluetoothTileDialogViewModel.UiProperties
    ) {
        toggleView.apply {
            isChecked = isEnabled
            setEnabled(true)
            alpha = ENABLED_ALPHA
        }
        subtitleTextView.text = context.getString(subtitleResId)
        subtitleTextView.text = context.getString(uiProperties.subTitleResId)
        autoOnToggleView.visibility = uiProperties.autoOnToggleVisibility
    }

    private fun setupToggle() {
@@ -198,6 +206,8 @@ constructor(
            logger.logBluetoothState(BluetoothStateStage.USER_TOGGLED, isChecked.toString())
            uiEventLogger.log(BluetoothTileDialogUiEvent.BLUETOOTH_TOGGLE_CLICKED)
        }

        autoOnToggleView.visibility = initialUiProperties.autoOnToggleVisibility
    }

    private fun setupRecyclerView() {
+27 −2
Original line number Diff line number Diff line
@@ -21,9 +21,14 @@ import android.content.Intent
import android.content.SharedPreferences
import android.os.Bundle
import android.view.View
import android.view.View.GONE
import android.view.View.VISIBLE
import android.view.ViewGroup
import androidx.annotation.DimenRes
import androidx.annotation.StringRes
import com.android.internal.jank.InteractionJankMonitor
import com.android.internal.logging.UiEventLogger
import com.android.settingslib.flags.Flags.bluetoothQsTileDialogAutoOnToggle
import com.android.systemui.Prefs
import com.android.systemui.animation.DialogCuj
import com.android.systemui.animation.DialogTransitionAnimator
@@ -143,7 +148,7 @@ constructor(
                bluetoothStateInteractor.bluetoothStateUpdate
                    .filterNotNull()
                    .onEach {
                        dialog.onBluetoothStateUpdated(it, getSubtitleResId(it))
                        dialog.onBluetoothStateUpdated(it, UiProperties.build(it))
                        updateDeviceItemJob?.cancel()
                        updateDeviceItemJob = launch {
                            deviceItemInteractor.updateDeviceItems(
@@ -192,7 +197,7 @@ constructor(

        return BluetoothTileDialog(
                bluetoothStateInteractor.isBluetoothEnabled,
                getSubtitleResId(bluetoothStateInteractor.isBluetoothEnabled),
                UiProperties.build(bluetoothStateInteractor.isBluetoothEnabled),
                cachedContentHeight,
                this@BluetoothTileDialogViewModel,
                mainDispatcher,
@@ -251,6 +256,26 @@ constructor(
            if (isBluetoothEnabled) R.string.quick_settings_bluetooth_tile_subtitle
            else R.string.bt_is_off
    }

    internal data class UiProperties(
        @StringRes val subTitleResId: Int,
        val autoOnToggleVisibility: Int,
        @DimenRes val scrollViewMinHeightResId: Int,
    ) {
        companion object {
            internal fun build(isBluetoothEnabled: Boolean) =
                UiProperties(
                    subTitleResId = getSubtitleResId(isBluetoothEnabled),
                    autoOnToggleVisibility =
                        if (bluetoothQsTileDialogAutoOnToggle() && !isBluetoothEnabled) VISIBLE
                        else GONE,
                    scrollViewMinHeightResId =
                        if (bluetoothQsTileDialogAutoOnToggle())
                            R.dimen.bluetooth_dialog_scroll_view_min_height_with_auto_on
                        else R.dimen.bluetooth_dialog_scroll_view_min_height
                )
        }
    }
}

internal interface BluetoothTileDialogCallback {
Loading