diff options
| author | 2024-11-18 11:48:37 +0800 | |
|---|---|---|
| committer | 2025-02-25 22:55:07 -0800 | |
| commit | c987134f0c4795f7bb495598d40ba21cf117dcae (patch) | |
| tree | 5f76b3c839f784a55c546c16380b85c121133c28 | |
| parent | 90dd45dd3cf350dfd2b1c1781706932553163a69 (diff) | |
[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
2 files changed, 45 insertions, 2 deletions
diff --git a/packages/SettingsLib/SettingsTheme/src/com/android/settingslib/widget/NormalPaddingMixin.kt b/packages/SettingsLib/SettingsTheme/src/com/android/settingslib/widget/NormalPaddingMixin.kt new file mode 100644 index 000000000000..5035542b9783 --- /dev/null +++ b/packages/SettingsLib/SettingsTheme/src/com/android/settingslib/widget/NormalPaddingMixin.kt @@ -0,0 +1,25 @@ +/* + * 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 diff --git a/packages/SettingsLib/SettingsTheme/src/com/android/settingslib/widget/SettingsPreferenceGroupAdapter.kt b/packages/SettingsLib/SettingsTheme/src/com/android/settingslib/widget/SettingsPreferenceGroupAdapter.kt index a04fce7eeb86..2672787a0519 100644 --- a/packages/SettingsLib/SettingsTheme/src/com/android/settingslib/widget/SettingsPreferenceGroupAdapter.kt +++ b/packages/SettingsLib/SettingsTheme/src/com/android/settingslib/widget/SettingsPreferenceGroupAdapter.kt @@ -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) |