summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author David Liu <dswliu@google.com> 2025-02-07 18:39:19 -0800
committer David Liu <dswliu@google.com> 2025-02-07 18:44:31 -0800
commitbc3babea78e7a72b6cce9e205e3bc953825b109b (patch)
tree3f7f357992a720a26634c307a3227e26fcbcd0d2
parent177be536819bc3167b82c8f73e469ea9b9b8b71f (diff)
[Settinglib][UI] fixed introPreference summary and button alignment
- Set minLines to 1 according to the UX spec - Set default collapsed - Update Textview alignment to use gravity since width is set to align to parent which make the start/end alignment no use. - Button is subclass of TextView, so we need to add handle case before the Textview. Bug: 380277395 Test: manual Flag: EXEMPT library update Change-Id: I7bb24fe4b6cf39ff351c26099e3cbc20d5667f0d
-rw-r--r--packages/SettingsLib/IntroPreference/res/layout/settingslib_expressive_preference_intro.xml5
-rw-r--r--packages/SettingsLib/IntroPreference/src/com/android/settingslib/widget/IntroPreference.kt31
-rw-r--r--packages/SettingsLib/SettingsTheme/src/com/android/settingslib/widget/CollapsableTextView.kt47
3 files changed, 42 insertions, 41 deletions
diff --git a/packages/SettingsLib/IntroPreference/res/layout/settingslib_expressive_preference_intro.xml b/packages/SettingsLib/IntroPreference/res/layout/settingslib_expressive_preference_intro.xml
index 7adcbf6c6601..cacd2740818c 100644
--- a/packages/SettingsLib/IntroPreference/res/layout/settingslib_expressive_preference_intro.xml
+++ b/packages/SettingsLib/IntroPreference/res/layout/settingslib_expressive_preference_intro.xml
@@ -17,6 +17,7 @@
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/entity_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@@ -38,7 +39,9 @@
android:id="@+id/collapsable_summary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:gravity="center"/>
+ android:gravity="center"
+ android:minLines="1"
+ app:isCollapsable="true"/>
</LinearLayout>
diff --git a/packages/SettingsLib/IntroPreference/src/com/android/settingslib/widget/IntroPreference.kt b/packages/SettingsLib/IntroPreference/src/com/android/settingslib/widget/IntroPreference.kt
index f9931cf3238d..9d037e91a86f 100644
--- a/packages/SettingsLib/IntroPreference/src/com/android/settingslib/widget/IntroPreference.kt
+++ b/packages/SettingsLib/IntroPreference/src/com/android/settingslib/widget/IntroPreference.kt
@@ -33,8 +33,8 @@ class IntroPreference @JvmOverloads constructor(
defStyleRes: Int = 0
) : Preference(context, attrs, defStyleAttr, defStyleRes), GroupSectionDividerMixin {
- private var isCollapsable: Boolean = false
- private var minLines: Int = 2
+ private var isCollapsable: Boolean = true
+ private var minLines: Int = DEFAULT_MIN_LINES
private var hyperlinkListener: View.OnClickListener? = null
private var learnMoreListener: View.OnClickListener? = null
private var learnMoreText: CharSequence? = null
@@ -42,22 +42,6 @@ class IntroPreference @JvmOverloads constructor(
init {
layoutResource = R.layout.settingslib_expressive_preference_intro
isSelectable = false
-
- initAttributes(context, attrs, defStyleAttr)
- }
-
- private fun initAttributes(context: Context, attrs: AttributeSet?, defStyleAttr: Int) {
- context.obtainStyledAttributes(
- attrs,
- COLLAPSABLE_TEXT_VIEW_ATTRS, defStyleAttr, 0
- ).apply {
- isCollapsable = getBoolean(IS_COLLAPSABLE, false)
- minLines = getInt(
- MIN_LINES,
- if (isCollapsable) DEFAULT_MIN_LINES else DEFAULT_MAX_LINES
- ).coerceIn(1, DEFAULT_MAX_LINES)
- recycle()
- }
}
override fun onBindViewHolder(holder: PreferenceViewHolder) {
@@ -139,13 +123,6 @@ class IntroPreference @JvmOverloads constructor(
companion object {
private const val DEFAULT_MAX_LINES = 10
- private const val DEFAULT_MIN_LINES = 2
-
- private val COLLAPSABLE_TEXT_VIEW_ATTRS =
- com.android.settingslib.widget.theme.R.styleable.CollapsableTextView
- private val MIN_LINES =
- com.android.settingslib.widget.theme.R.styleable.CollapsableTextView_android_minLines
- private val IS_COLLAPSABLE =
- com.android.settingslib.widget.theme.R.styleable.CollapsableTextView_isCollapsable
+ private const val DEFAULT_MIN_LINES = 1
}
-} \ No newline at end of file
+}
diff --git a/packages/SettingsLib/SettingsTheme/src/com/android/settingslib/widget/CollapsableTextView.kt b/packages/SettingsLib/SettingsTheme/src/com/android/settingslib/widget/CollapsableTextView.kt
index 7eb9840e3e98..976711bdc5f3 100644
--- a/packages/SettingsLib/SettingsTheme/src/com/android/settingslib/widget/CollapsableTextView.kt
+++ b/packages/SettingsLib/SettingsTheme/src/com/android/settingslib/widget/CollapsableTextView.kt
@@ -40,7 +40,7 @@ class CollapsableTextView @JvmOverloads constructor(
defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr) {
- private var isCollapsable: Boolean = false
+ private var isCollapsable: Boolean = DEFAULT_COLLAPSABLE
private var isCollapsed: Boolean = false
private var minLines: Int = DEFAULT_MIN_LINES
@@ -78,24 +78,38 @@ class CollapsableTextView @JvmOverloads constructor(
private fun initAttributes(context: Context, attrs: AttributeSet?, defStyleAttr: Int) {
context.obtainStyledAttributes(
- attrs, Attrs, defStyleAttr, 0
+ attrs, R.styleable.CollapsableTextView, defStyleAttr, 0
).apply {
- val gravity = getInt(GravityAttr, Gravity.START)
+ val gravity = getInt(gravityAttr, Gravity.START)
when (gravity) {
Gravity.CENTER_VERTICAL, Gravity.CENTER, Gravity.CENTER_HORIZONTAL -> {
centerHorizontally(titleTextView)
centerHorizontally(collapseButton)
}
}
+ isCollapsable = getBoolean(isCollapsableAttr, DEFAULT_COLLAPSABLE)
+ minLines = getInt(minLinesAttr, DEFAULT_MIN_LINES)
recycle()
}
}
private fun centerHorizontally(view: View) {
- (view.layoutParams as LayoutParams).apply {
- startToStart = LayoutParams.PARENT_ID
- endToEnd = LayoutParams.PARENT_ID
- horizontalBias = 0.5f
+ when (view) {
+ is MaterialButton -> {
+ (view.layoutParams as LayoutParams).apply {
+ startToStart = LayoutParams.PARENT_ID
+ endToEnd = LayoutParams.PARENT_ID
+ }
+ }
+ is TextView -> {
+ view.gravity = Gravity.CENTER
+ }
+ else -> {
+ (view.layoutParams as LayoutParams).apply {
+ startToStart = LayoutParams.PARENT_ID
+ endToEnd = LayoutParams.PARENT_ID
+ }
+ }
}
}
@@ -113,6 +127,8 @@ class CollapsableTextView @JvmOverloads constructor(
*/
fun setCollapsable(collapsable: Boolean) {
isCollapsable = collapsable
+ // Make is collapsed when it's collapsable
+ if (isCollapsable) isCollapsed = true
updateView()
}
@@ -120,8 +136,8 @@ class CollapsableTextView @JvmOverloads constructor(
* Sets the minimum number of lines to display when collapsed.
* @param lines The minimum number of lines.
*/
- fun setMinLines(line: Int) {
- minLines = line.coerceIn(1, DEFAULT_MAX_LINES)
+ fun setMinLines(lines: Int) {
+ minLines = lines.coerceIn(1, DEFAULT_MAX_LINES)
updateView()
}
@@ -198,7 +214,7 @@ class CollapsableTextView @JvmOverloads constructor(
}
learnMoreSpan = LearnMoreSpan(clickListener = learnMoreListener!!)
spannableLearnMoreText.setSpan(learnMoreSpan, 0, learnMoreText!!.length, 0)
- learnMoreTextView.setText(spannableLearnMoreText)
+ learnMoreTextView.text = spannableLearnMoreText
learnMoreTextView.visibility = VISIBLE
isLearnMoreEnabled = true
}
@@ -211,6 +227,8 @@ class CollapsableTextView @JvmOverloads constructor(
icon = collapseButtonResources.expandIcon
}
titleTextView.maxLines = minLines
+ titleTextView.ellipsize = null
+ titleTextView.scrollBarSize = 0
}
else -> {
@@ -219,6 +237,7 @@ class CollapsableTextView @JvmOverloads constructor(
icon = collapseButtonResources.collapseIcon
}
titleTextView.maxLines = DEFAULT_MAX_LINES
+ titleTextView.ellipsize = TextUtils.TruncateAt.END
}
}
collapseButton.visibility = if (isCollapsable) VISIBLE else GONE
@@ -235,17 +254,19 @@ class CollapsableTextView @JvmOverloads constructor(
companion object {
private const val DEFAULT_MAX_LINES = 10
private const val DEFAULT_MIN_LINES = 2
+ private const val DEFAULT_COLLAPSABLE = true
private const val LINK_BEGIN_MARKER = "LINK_BEGIN"
private const val LINK_END_MARKER = "LINK_END"
- private val Attrs = R.styleable.CollapsableTextView
- private val GravityAttr = R.styleable.CollapsableTextView_android_gravity
+ private val gravityAttr = R.styleable.CollapsableTextView_android_gravity
+ private val minLinesAttr = R.styleable.CollapsableTextView_android_minLines
+ private val isCollapsableAttr = R.styleable.CollapsableTextView_isCollapsable
}
}
internal class LearnMoreSpan(
- val url: String = "",
+ url: String = "",
val clickListener: View.OnClickListener) : URLSpan(url) {
override fun onClick(widget: View) {
clickListener.onClick(widget)