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

Commit fa5d378d authored by David Liu's avatar David Liu
Browse files

[Expressive design] Add SpacePreference

- Add SpacePreference for add custom padding in the screen
- Support SpacePreference on rounded background rendering

Fix: 407671669
Test: manual + presubmit
Flag: EXEMPT library update

Change-Id: I8a7eb193cb1489bb88d54e578a86a9d44362dfba
parent d9806f11
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
<!--
     Copyright (C) 2025 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.
-->
<Space xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
+6 −0
Original line number Diff line number Diff line
@@ -138,6 +138,12 @@ open class SettingsPreferenceGroupAdapter(preferenceGroup: PreferenceGroup) :
                    }
                }

                // SpacePreference should not have round corner background.
                is SpacePreference -> {
                    cornerStyles[i] = 0
                    endIndex = endIndex - 1
                }

                else -> {
                    val parent = pref?.parent

+67 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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

import android.content.Context
import android.util.AttributeSet
import android.view.ViewGroup
import androidx.core.content.res.TypedArrayUtils
import androidx.core.content.withStyledAttributes
import androidx.preference.Preference
import androidx.preference.PreferenceViewHolder
import com.android.settingslib.widget.theme.R

/**
 * A blank preference that has a specified height by android:layout_height. It can be used to fine
 * tune screens that combine custom layouts and standard preferences.
 */
class SpacePreference
@JvmOverloads
constructor(
    context: Context,
    attrs: AttributeSet?,
    defStyleAttr: Int =
        TypedArrayUtils.getAttr(context, androidx.preference.R.attr.preferenceStyle, android.R.attr.preferenceStyle),
    defStyleRes: Int = 0,
) : Preference(context, attrs, defStyleAttr, defStyleRes) {
    private var mHeight: Int = 0

    init {
        layoutResource = R.layout.settingslib_space_preference

        context.withStyledAttributes(
            attrs,
            intArrayOf(android.R.attr.layout_height),
            defStyleAttr,
            defStyleRes,
        ) {
            mHeight = getDimensionPixelSize(0, 0)
        }
    }

    fun setHeight(height: Int) {
        mHeight = height
    }

    override fun onBindViewHolder(view: PreferenceViewHolder) {
        super.onBindViewHolder(view)
        view.isDividerAllowedAbove = false
        view.isDividerAllowedBelow = false
        val params = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, mHeight)
        view.itemView.layoutParams = params
    }
}