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

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

[Settingslib] Fix TopIntroPreference and IntroPreference.

1. Replace MaterialButton with LinearLayout (with image and text view) for better alignment.
2. Set default value of `isCollapsable` of IntroPreference and TopIntroPreference to `false`.
3. Let the icon not focusable when setting the accessibility

Bug: 405308129
Test: manual + presubmit
Flag: EXEMPT resource update only

Change-Id: I3ec357210f1e5e135fc4a1b5f3b8f8900c175af7
parent a1adde77
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@

        <ImageView
            android:id="@android:id/icon"
            android:importantForAccessibility="no"
            style="@style/SettingsLibEntityHeaderIcon"/>

        <TextView
@@ -41,7 +42,7 @@
            android:layout_height="wrap_content"
            android:gravity="center"
            android:minLines="1"
            app:isCollapsable="true"/>
            app:isCollapsable="false"/>

    </LinearLayout>

+6 −7
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ constructor(
    defStyleRes: Int = 0,
) : Preference(context, attrs, defStyleAttr, defStyleRes), GroupSectionDividerMixin {

    private var isCollapsable: Boolean = true
    private var isCollapsable: Boolean = DEFAULT_COLLAPSABLE
    private var minLines: Int = DEFAULT_MIN_LINES
    private var hyperlinkListener: View.OnClickListener? = null
    private var learnMoreListener: View.OnClickListener? = null
@@ -53,13 +53,11 @@ constructor(
            setCollapsable(isCollapsable)
            setMinLines(minLines)
            visibility = if (summary.isNullOrEmpty()) View.GONE else View.VISIBLE
            setText(summary.toString())
            if (hyperlinkListener != null) {
                setHyperlinkListener(hyperlinkListener)
            }
            if (learnMoreListener != null) {
            summary?.let { setText(it.toString()) }
            hyperlinkListener?.let { setHyperlinkListener(it) }
            learnMoreListener?.let {
                setLearnMoreText(learnMoreText)
                setLearnMoreAction(learnMoreListener)
                setLearnMoreAction(it)
            }
        }
    }
@@ -124,5 +122,6 @@ constructor(
    companion object {
        private const val DEFAULT_MAX_LINES = 10
        private const val DEFAULT_MIN_LINES = 1
        private const val DEFAULT_COLLAPSABLE = false
    }
}
+24 −6
Original line number Diff line number Diff line
@@ -55,12 +55,30 @@
        android:visibility="gone"
        style="@style/SettingslibTextAppearance.LinkableTextStyle.Expressive"/>

    <com.google.android.material.button.MaterialButton
    <LinearLayout
        android:id="@+id/collapse_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/settingslib_expressive_space_extrasmall4"
        android:paddingBottom="@dimen/settingslib_expressive_space_extrasmall4"
        app:layout_constraintTop_toBottomOf="@id/settingslib_expressive_learn_more"
        app:layout_constraintStart_toStartOf="parent"
        android:textColor="@color/settingslib_materialColorOnSurface"
        android:text="@string/settingslib_expressive_text_expand"
        app:icon="@drawable/settingslib_expressive_icon_expand"
        style="@style/SettingslibTextButtonStyle.Expressive"/>
        android:gravity="center"
        android:filterTouchesWhenObscured="false">

        <ImageView
            android:id="@android:id/icon1"
            android:layout_width="@dimen/settingslib_expressive_space_small4"
            android:layout_height="@dimen/settingslib_expressive_space_small4"
            android:importantForAccessibility="no"
            android:scaleType="centerInside"/>

        <TextView
            android:id="@android:id/text1"
            android:layout_marginStart="@dimen/settingslib_expressive_space_extrasmall4"
            style="@style/TextAppearance.SettingsLib.BodyLarge.Emphasized"
            android:layout_width="wrap_content"
            android:layout_height="@dimen/settingslib_expressive_space_small4"/>
    </LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
+11 −9
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@ import android.util.AttributeSet
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import com.android.settingslib.widget.theme.R
@@ -45,7 +47,9 @@ class CollapsableTextView @JvmOverloads constructor(
    private var minLines: Int = DEFAULT_MIN_LINES

    private val titleTextView: TextView
    private val collapseButton: MaterialButton
    private val collapseButton: LinearLayout
    private val collapseButtonIcon: ImageView?
    private val collapseButtonText: TextView?
    private val collapseButtonResources: CollapseButtonResources
    private var hyperlinkListener: View.OnClickListener? = null
    private var learnMoreListener: View.OnClickListener? = null
@@ -59,6 +63,8 @@ class CollapsableTextView @JvmOverloads constructor(
            .inflate(R.layout.settingslib_expressive_collapsable_textview, this)
        titleTextView = findViewById(android.R.id.title)
        collapseButton = findViewById(R.id.collapse_button)
        collapseButtonIcon = collapseButton.findViewById(android.R.id.icon1)
        collapseButtonText = collapseButton.findViewById(android.R.id.text1)
        learnMoreTextView = findViewById(R.id.settingslib_expressive_learn_more)

        collapseButtonResources = CollapseButtonResources(
@@ -223,20 +229,16 @@ class CollapsableTextView @JvmOverloads constructor(
    private fun updateView() {
        when {
            isCollapsed -> {
                collapseButton.apply {
                    text = collapseButtonResources.expandText
                    icon = collapseButtonResources.expandIcon
                }
                collapseButtonIcon?.setImageDrawable(collapseButtonResources.expandIcon)
                collapseButtonText?.text = collapseButtonResources.expandText
                titleTextView.maxLines = minLines
                titleTextView.ellipsize = null
                titleTextView.scrollBarSize = 0
            }

            else -> {
                collapseButton.apply {
                    text = collapseButtonResources.collapseText
                    icon = collapseButtonResources.collapseIcon
                }
                collapseButtonIcon?.setImageDrawable(collapseButtonResources.collapseIcon)
                collapseButtonText?.text = collapseButtonResources.collapseText
                titleTextView.maxLines = DEFAULT_MAX_LINES
                titleTextView.ellipsize = TextUtils.TruncateAt.END
            }
+6 −3
Original line number Diff line number Diff line
@@ -14,7 +14,8 @@
  See the License for the specific language governing permissions and
  limitations under the License.
  -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
@@ -24,5 +25,7 @@
    <com.android.settingslib.widget.CollapsableTextView
        android:id="@+id/collapsable_text_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</LinearLayout>
 No newline at end of file
        android:layout_height="wrap_content"
        android:minLines="2"
        app:isCollapsable="false"/>
</RelativeLayout>
Loading