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

Commit fa56fb9b authored by Haijie Hong's avatar Haijie Hong Committed by Android (Google) Code Review
Browse files

Merge "Add device details more settings page" into main

parents fa32f347 7cd4a398
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -1864,6 +1864,10 @@
    <string name="device_details_title">Device details</string>
    <!-- Title for keyboard settings preferences. [CHAR LIMIT=50] -->
    <string name="bluetooth_device_keyboard_settings_preference_title">Keyboard settings</string>
    <!-- Title for more settings preferences. [CHAR LIMIT=50] -->
    <string name="bluetooth_device_more_settings_preference_title">More settings</string>
    <!-- Title for more settings summary. [CHAR LIMIT=50] -->
    <string name="bluetooth_device_more_settings_preference_summary">Firmware updates, about, and more</string>
    <!-- Title of the item to show device MAC address -->
    <string name="bluetooth_device_mac_address">Device\'s Bluetooth address: <xliff:g id="address">%1$s</xliff:g></string>
    <!-- Title of the items to show multuple devices MAC address [CHAR LIMIT=NONE]-->
@@ -1884,6 +1888,9 @@
    <!-- Bluetooth device details companion apps. In the confirmation dialog for removing an associated app, this is the label on the button that will complete the disassociate action. [CHAR LIMIT=80] -->
    <string name = "bluetooth_companion_app_remove_association_confirm_button">Disconnect app</string>
    <!-- Title of device details screen [CHAR LIMIT=28]-->
    <string name="device_details_more_settings">More settings</string>
    <!-- Bluetooth developer settings: Maximum number of connected audio devices -->
    <string name="bluetooth_max_connected_audio_devices_string">Maximum connected Bluetooth audio devices</string>
    <!-- Bluetooth developer settings: Maximum number of connected audio devices -->
+24 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2024 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:key="bluetooth_device_more_settings_screen"
    android:title="@string/device_details_more_settings">

    <PreferenceCategory
        android:key="bluetooth_profiles"/>
</PreferenceScreen>
+5 −2
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;

import com.android.settings.R;
import com.android.settings.bluetooth.ui.model.FragmentTypeModel;
import com.android.settings.bluetooth.ui.view.DeviceDetailsFragmentFormatter;
import com.android.settings.connecteddevice.stylus.StylusDevicesController;
import com.android.settings.core.SettingsUIDeviceConfig;
@@ -343,7 +344,7 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment
    public void onCreatePreferences(@NonNull Bundle savedInstanceState, @NonNull String rootKey) {
        super.onCreatePreferences(savedInstanceState, rootKey);
        if (Flags.enableBluetoothDeviceDetailsPolish()) {
            mFormatter.updateLayout();
            mFormatter.updateLayout(FragmentTypeModel.DeviceDetailsMainFragment.INSTANCE);
        }
    }

@@ -400,7 +401,9 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment
    @Override
    protected void addPreferenceController(AbstractPreferenceController controller) {
        if (Flags.enableBluetoothDeviceDetailsPolish()) {
            List<String> keys = mFormatter.getVisiblePreferenceKeysForMainPage();
            List<String> keys =
                    mFormatter.getVisiblePreferenceKeys(
                            FragmentTypeModel.DeviceDetailsMainFragment.INSTANCE);
            Lifecycle lifecycle = getSettingsLifecycle();
            if (keys == null || keys.contains(controller.getPreferenceKey())) {
                super.addPreferenceController(controller);
+7 −9
Original line number Diff line number Diff line
@@ -66,15 +66,14 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.DialogProperties
import com.android.settings.R
import com.android.settings.bluetooth.ui.model.DeviceSettingPreferenceModel
import com.android.settings.bluetooth.ui.composable.Icon as DeviceSettingComposeIcon
import com.android.settingslib.bluetooth.devicesettings.shared.model.DeviceSettingModel
import com.android.settingslib.bluetooth.devicesettings.shared.model.DeviceSettingStateModel
import com.android.settingslib.spa.framework.theme.SettingsDimension
import com.android.settingslib.spa.widget.dialog.getDialogWidth

@Composable
fun MultiTogglePreferenceGroup(
    preferenceModels: List<DeviceSettingModel.MultiTogglePreference>,
    preferenceModels: List<DeviceSettingPreferenceModel.MultiTogglePreference>,
) {
    var settingIdForPopUp by remember { mutableStateOf<Int?>(null) }

@@ -115,7 +114,7 @@ fun MultiTogglePreferenceGroup(
                                colors = getButtonColors(preferenceModel.isActive),
                                contentPadding = PaddingValues(0.dp)) {
                                    DeviceSettingComposeIcon(
                                        preferenceModel.toggles[preferenceModel.state.selectedIndex]
                                        preferenceModel.toggles[preferenceModel.selectedIndex]
                                            .icon,
                                        modifier = Modifier.size(24.dp))
                                }
@@ -144,7 +143,7 @@ private fun getButtonColors(isActive: Boolean) =
@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun dialog(
    multiTogglePreference: DeviceSettingModel.MultiTogglePreference,
    multiTogglePreference: DeviceSettingPreferenceModel.MultiTogglePreference,
    onDismiss: () -> Unit
) {
    BasicAlertDialog(
@@ -179,7 +178,7 @@ private fun dialog(
}

@Composable
private fun dialogContent(multiTogglePreference: DeviceSettingModel.MultiTogglePreference) {
private fun dialogContent(multiTogglePreference: DeviceSettingPreferenceModel.MultiTogglePreference) {
    Column {
        Row(
            modifier = Modifier.fillMaxWidth().height(24.dp),
@@ -219,7 +218,7 @@ private fun dialogContent(multiTogglePreference: DeviceSettingModel.MultiToggleP
                }
                Row {
                    for ((idx, toggle) in multiTogglePreference.toggles.withIndex()) {
                        val selected = idx == multiTogglePreference.state.selectedIndex
                        val selected = idx == multiTogglePreference.selectedIndex
                        Column(
                            modifier =
                                Modifier.weight(1f)
@@ -237,8 +236,7 @@ private fun dialogContent(multiTogglePreference: DeviceSettingModel.MultiToggleP
                        ) {
                            Button(
                                onClick = {
                                    multiTogglePreference.updateState(
                                        DeviceSettingStateModel.MultiTogglePreferenceState(idx))
                                    multiTogglePreference.onSelectedChange(idx)
                                },
                                modifier = Modifier.fillMaxSize(),
                                colors =
+69 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.bluetooth.ui.model

import com.android.settingslib.bluetooth.devicesettings.DeviceSettingId
import com.android.settingslib.bluetooth.devicesettings.shared.model.DeviceSettingIcon
import com.android.settingslib.bluetooth.devicesettings.shared.model.ToggleModel

/** Models a device setting preference. */
sealed interface DeviceSettingPreferenceModel {
    @DeviceSettingId
    val id: Int

    /** Models a plain preference. */
    data class PlainPreference(
        @DeviceSettingId override val id: Int,
        val title: String,
        val summary: String? = null,
        val icon: DeviceSettingIcon? = null,
        val onClick: (() -> Unit)? = null,
    ) : DeviceSettingPreferenceModel

    /** Models a switch preference. */
    data class SwitchPreference(
        @DeviceSettingId override val id: Int,
        val title: String,
        val summary: String? = null,
        val icon: DeviceSettingIcon? = null,
        val checked: Boolean,
        val onCheckedChange: ((Boolean) -> Unit),
        val onPrimaryClick: (() -> Unit)? = null,
    ) : DeviceSettingPreferenceModel

    /** Models a multi-toggle preference. */
    data class MultiTogglePreference(
        @DeviceSettingId override val id: Int,
        val title: String,
        val toggles: List<ToggleModel>,
        val isActive: Boolean,
        val selectedIndex: Int,
        val isAllowedChangingState: Boolean,
        val onSelectedChange: (Int) -> Unit,
    ) : DeviceSettingPreferenceModel

    /** Models a footer preference. */
    data class FooterPreference(
        @DeviceSettingId override val id: Int,
        val footerText: String,
    ) : DeviceSettingPreferenceModel

    /** Models a preference which could navigate to more settings fragment. */
    data class MoreSettingsPreference(
        @DeviceSettingId override val id: Int,
    ) : DeviceSettingPreferenceModel
}
Loading