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

Commit a9e34c6b authored by Haijie Hong's avatar Haijie Hong
Browse files

Add help button on the top right corner of more settings page

BUG: 343317785
Test: atest DeviceSettingRepositoryTest
Flag: com.android.settings.flags.enable_bluetooth_device_details_polish
Change-Id: I1536f416a52096d9e776ca2fdb8ed31541b90b1c
parent 47b0a3cd
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ public class DeviceSettingFooterPreference extends DeviceSettingPreference imple
    DeviceSettingFooterPreference(
            @NonNull String footerText,
            Bundle extras) {
        super(DeviceSettingType.DEVICE_SETTING_TYPE_MULTI_TOGGLE);
        super(DeviceSettingType.DEVICE_SETTING_TYPE_FOOTER);
        mFooterText = footerText;
        mExtras = extras;
    }
+132 −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.settingslib.bluetooth.devicesettings;

import android.content.Intent;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.NonNull;

/** A data class representing a help button displayed on the top right corner of the page. */
public class DeviceSettingHelpPreference extends DeviceSettingPreference implements Parcelable {

    private final Intent mIntent;
    private final Bundle mExtras;

    DeviceSettingHelpPreference(@NonNull Intent intent, Bundle extras) {
        super(DeviceSettingType.DEVICE_SETTING_TYPE_HELP);
        mIntent = intent;
        mExtras = extras;
    }

    /** Read a {@link DeviceSettingHelpPreference} from {@link Parcel}. */
    @NonNull
    public static DeviceSettingHelpPreference readFromParcel(@NonNull Parcel in) {
        Intent intent = in.readParcelable(Intent.class.getClassLoader());
        Bundle extras = in.readBundle(Bundle.class.getClassLoader());
        return new DeviceSettingHelpPreference(intent, extras);
    }

    public static final Creator<DeviceSettingHelpPreference> CREATOR =
            new Creator<>() {
                @Override
                @NonNull
                public DeviceSettingHelpPreference createFromParcel(@NonNull Parcel in) {
                    in.readInt();
                    return readFromParcel(in);
                }

                @Override
                @NonNull
                public DeviceSettingHelpPreference[] newArray(int size) {
                    return new DeviceSettingHelpPreference[size];
                }
            };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        super.writeToParcel(dest, flags);
        dest.writeParcelable(mIntent, flags);
        dest.writeBundle(mExtras);
    }

    /** Builder class for {@link DeviceSettingHelpPreference}. */
    public static final class Builder {
        private Intent mIntent;
        private Bundle mExtras = Bundle.EMPTY;

        /**
         * Sets the intent of the preference, should be an activity intent.
         *
         * @param intent The intent to launch when clicked.
         * @return Returns the Builder object.
         */
        @NonNull
        public DeviceSettingHelpPreference.Builder setIntent(@NonNull Intent intent) {
            mIntent = intent;
            return this;
        }

        /**
         * Sets the extras bundle.
         *
         * @return Returns the Builder object.
         */
        @NonNull
        public DeviceSettingHelpPreference.Builder setExtras(@NonNull Bundle extras) {
            mExtras = extras;
            return this;
        }

        /**
         * Builds the {@link DeviceSettingHelpPreference} object.
         *
         * @return Returns the built {@link DeviceSettingHelpPreference} object.
         */
        @NonNull
        public DeviceSettingHelpPreference build() {
            return new DeviceSettingHelpPreference(mIntent, mExtras);
        }
    }

    /**
     * Gets the intent to launch when clicked.
     *
     * @return The intent.
     */
    @NonNull
    public Intent getIntent() {
        return mIntent;
    }

    /**
     * Gets the extras Bundle.
     *
     * @return Returns a Bundle object.
     */
    @NonNull
    public Bundle getExtras() {
        return mExtras;
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -42,4 +42,7 @@ public @interface DeviceSettingType {

    /** Device setting type is footer preference. */
    int DEVICE_SETTING_TYPE_FOOTER = 3;

    /** Device setting type is "help" preference. */
    int DEVICE_SETTING_TYPE_HELP = 4;
}
+6 −2
Original line number Diff line number Diff line
@@ -25,12 +25,13 @@ import android.os.Parcelable
 *
 * @property mainContentItems The setting items to be shown in main page.
 * @property moreSettingsItems The setting items to be shown in more settings page.
 * @property moreSettingsFooter The footer in more settings page.
 * @property moreSettingsHelpItem The help item displayed on the top right corner of the page.
 * @property extras Extra bundle
 */
data class DeviceSettingsConfig(
    val mainContentItems: List<DeviceSettingItem>,
    val moreSettingsItems: List<DeviceSettingItem>,
    val moreSettingsHelpItem: DeviceSettingItem?,
    val extras: Bundle = Bundle.EMPTY,
) : Parcelable {

@@ -40,6 +41,7 @@ data class DeviceSettingsConfig(
        parcel.run {
            writeTypedList(mainContentItems)
            writeTypedList(moreSettingsItems)
            writeParcelable(moreSettingsHelpItem, flags)
            writeBundle(extras)
        }
    }
@@ -59,7 +61,9 @@ data class DeviceSettingsConfig(
                                arrayListOf<DeviceSettingItem>().also {
                                    readTypedList(it, DeviceSettingItem.CREATOR)
                                },
                            extras = readBundle((Bundle::class.java.classLoader))!!,
                            moreSettingsHelpItem = readParcelable(
                                DeviceSettingItem::class.java.classLoader
                            )
                        )
                    }

+6 −1
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import com.android.settingslib.bluetooth.devicesettings.DeviceSettingId
import com.android.settingslib.bluetooth.devicesettings.DeviceSettingItem
import com.android.settingslib.bluetooth.devicesettings.DeviceSettingsConfig
import com.android.settingslib.bluetooth.devicesettings.DeviceSettingFooterPreference
import com.android.settingslib.bluetooth.devicesettings.DeviceSettingHelpPreference
import com.android.settingslib.bluetooth.devicesettings.MultiTogglePreference
import com.android.settingslib.bluetooth.devicesettings.ToggleInfo
import com.android.settingslib.bluetooth.devicesettings.shared.model.DeviceSettingConfigItemModel
@@ -97,7 +98,8 @@ class DeviceSettingRepositoryImpl(
    private fun DeviceSettingsConfig.toModel(): DeviceSettingConfigModel =
        DeviceSettingConfigModel(
            mainItems = mainContentItems.map { it.toModel() },
            moreSettingsItems = moreSettingsItems.map { it.toModel() })
            moreSettingsItems = moreSettingsItems.map { it.toModel() },
            moreSettingsHelpItem = moreSettingsHelpItem?.toModel(), )

    private fun DeviceSettingItem.toModel(): DeviceSettingConfigItemModel {
        return if (!TextUtils.isEmpty(preferenceKey)) {
@@ -154,6 +156,9 @@ class DeviceSettingRepositoryImpl(
            is DeviceSettingFooterPreference -> DeviceSettingModel.FooterPreference(
                cachedDevice = cachedDevice,
                id = settingId, footerText = pref.footerText)
            is DeviceSettingHelpPreference -> DeviceSettingModel.HelpPreference(
                cachedDevice = cachedDevice,
                id = settingId, intent = pref.intent)
            else -> DeviceSettingModel.Unknown(cachedDevice, settingId)
        }

Loading