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

Commit c987134f authored by Chaohui Wang's avatar Chaohui Wang
Browse files

[Expressive design] Add NormalPaddingMixin

A base interface to indicate that a Preference should have normal
paddings.

Bug: 366336385
Flag: com.android.settingslib.widget.theme.flags.is_expressive_design_enabled
Test: manual
Change-Id: I00212b46ca66b5e12b1e85d8672a0851bb5af418
parent 90dd45dd
Loading
Loading
Loading
Loading
+25 −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.widget

/**
 * A base interface to indicate that a Preference should have normal paddings.
 *
 * Preferences implementing this interface will be treated as has normal paddings both inside and
 * outside.
 */
interface NormalPaddingMixin
 No newline at end of file
+20 −2
Original line number Diff line number Diff line
@@ -177,14 +177,32 @@ open class SettingsPreferenceGroupAdapter(preferenceGroup: PreferenceGroup) :
        val v = holder.itemView
        // Update padding
        if (SettingsThemeHelper.isExpressiveTheme(context)) {
            val paddingStart = if (backgroundRes == 0) mNormalPaddingStart else mGroupPaddingStart
            val paddingEnd = if (backgroundRes == 0) mNormalPaddingEnd else mGroupPaddingEnd
            val (paddingStart, paddingEnd) = getStartEndPadding(position, backgroundRes)
            v.setPaddingRelative(paddingStart, v.paddingTop, paddingEnd, v.paddingBottom)
            v.clipToOutline = backgroundRes != 0
        }
        // Update background
        v.setBackgroundResource(backgroundRes)
    }

    private fun getStartEndPadding(position: Int, backgroundRes: Int): Pair<Int, Int> {
        val item = getItem(position)
        return when {
            // This item handles edge to edge itself
            item is NormalPaddingMixin && item is GroupSectionDividerMixin -> 0 to 0

            // According to mappingPreferenceGroup(), backgroundRes == 0 means this item is
            // GroupSectionDividerMixin or PreferenceCategory, which is design to have normal
            // padding.
            // NormalPaddingMixin items are also designed to have normal padding.
            backgroundRes == 0 || item is NormalPaddingMixin ->
                mNormalPaddingStart to mNormalPaddingEnd

            // Other items are suppose to have group padding.
            else -> mGroupPaddingStart to mGroupPaddingEnd
        }
    }

    @DrawableRes
    protected fun getRoundCornerDrawableRes(position: Int, isSelected: Boolean): Int {
        return getRoundCornerDrawableRes(position, isSelected, false)