summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SettingsLib/SettingsTheme/src/com/android/settingslib/widget/NormalPaddingMixin.kt25
-rw-r--r--packages/SettingsLib/SettingsTheme/src/com/android/settingslib/widget/SettingsPreferenceGroupAdapter.kt22
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)