Loading packages/SettingsLib/ValuePreference/res/values/styles.xml→packages/SettingsLib/ValuePreference/res/drawable/settingslib_value_preference_background.xml +11 −6 Original line number Diff line number Diff line Loading @@ -15,9 +15,14 @@ limitations under the License. --> <resources xmlns:tools="http://schemas.android.com/tools"> <style name="TextAppearance.SettingsLib.ValuePreferenceTitle" parent="@style/TextAppearance.SettingsLib.DisplaySmall"> <item name="android:textColor">@color/settingslib_text_color_primary</item> </style> </resources> <ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="?android:colorControlHighlight"> <item> <shape android:shape="rectangle"> <solid android:color="@color/settingslib_materialColorSurfaceBright" /> <corners android:radius="@dimen/settingslib_expressive_radius_large2" /> </shape> </item> </ripple> No newline at end of file packages/SettingsLib/ValuePreference/res/layout/settingslib_expressive_value_preference.xml +63 −17 Original line number Diff line number Diff line Loading @@ -15,30 +15,76 @@ limitations under the License. --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="72dp" android:gravity="center_vertical" android:paddingTop="@dimen/settingslib_expressive_space_extrasmall4" android:paddingStart="?android:attr/listPreferredItemPaddingStart" android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" android:background="?android:attr/selectableItemBackground" android:clipToPadding="false" android:baselineAligned="false" android:filterTouchesWhenObscured="false"> android:clipToPadding="false" android:filterTouchesWhenObscured="false" android:gravity="center_vertical" android:minHeight="?android:attr/listPreferredItemHeight"> <include layout="@layout/settingslib_expressive_preference_icon_frame"/> <LinearLayout android:id="@+id/value_container_1" android:layout_width="@dimen/settingslib_expressive_space_none" android:layout_height="wrap_content" android:layout_weight="1" android:background="@drawable/settingslib_value_preference_background" android:baselineAligned="false" android:gravity="center_vertical" android:minHeight="?android:attr/listPreferredItemHeight"> <include layout="@layout/settingslib_expressive_value_preference_text_frame"/> <!-- Preference should place its actual preference widget here. --> </LinearLayout> <LinearLayout android:id="@android:id/widget_frame" android:id="@+id/value_container_2" android:layout_width="@dimen/settingslib_expressive_space_none" android:layout_height="wrap_content" android:layout_weight="1" android:layout_marginStart="@dimen/settingslib_expressive_space_small1" android:background="@drawable/settingslib_value_preference_background" android:visibility="gone" android:baselineAligned="false" android:gravity="center_vertical" android:minHeight="?android:attr/listPreferredItemHeight"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingStart="@dimen/settingslib_expressive_space_small1" android:paddingEnd="@dimen/settingslib_expressive_space_small1" android:filterTouchesWhenObscured="false" android:paddingVertical="@dimen/settingslib_expressive_space_small1"> <TextView android:id="@+id/title2" android:layout_width="wrap_content" android:layout_height="match_parent" android:gravity="end|center_vertical" android:minWidth="@dimen/settingslib_expressive_space_medium4" android:orientation="vertical"/> android:layout_height="wrap_content" android:layout_gravity="start" android:ellipsize="marquee" android:singleLine="true" android:textAlignment="viewStart" android:textAppearance="@style/TextAppearance.SettingsLib.DisplaySmall" android:textColor="@color/settingslib_text_color_primary"/> <TextView android:id="@+id/summary2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignStart="@id/title2" android:layout_below="@id/title2" android:layout_gravity="start" android:maxLines="2" android:textAlignment="viewStart" android:textAppearance="?android:attr/textAppearanceListItemSecondary" android:textColor="?android:attr/textColorSecondary"/> </RelativeLayout> </LinearLayout> </LinearLayout> No newline at end of file packages/SettingsLib/ValuePreference/res/layout/settingslib_expressive_value_preference_text_frame.xml +22 −21 Original line number Diff line number Diff line Loading @@ -21,7 +21,7 @@ android:layout_height="wrap_content" android:layout_weight="1" android:paddingVertical="@dimen/settingslib_expressive_space_small1" android:paddingStart="@dimen/settingslib_expressive_space_none" android:paddingStart="@dimen/settingslib_expressive_space_small1" android:paddingEnd="@dimen/settingslib_expressive_space_small1" android:filterTouchesWhenObscured="false"> Loading @@ -30,20 +30,21 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="start" android:ellipsize="marquee" android:singleLine="true" android:textAlignment="viewStart" android:maxLines="2" android:textAppearance="@style/TextAppearance.SettingsLib.ValuePreferenceTitle" android:ellipsize="marquee"/> android:textAppearance="@style/TextAppearance.SettingsLib.DisplaySmall" android:textColor="@color/settingslib_text_color_primary"/> <TextView android:id="@android:id/summary" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@android:id/title" android:layout_alignStart="@android:id/title" android:layout_below="@android:id/title" android:layout_gravity="start" android:maxLines="2" android:textAlignment="viewStart" android:textAppearance="?android:attr/textAppearanceListItemSecondary" android:textColor="?android:attr/textColorSecondary" android:maxLines="10"/> android:textColor="?android:attr/textColorSecondary"/> </RelativeLayout> No newline at end of file packages/SettingsLib/ValuePreference/src/com/android/settingslib/widget/ValuePreference.kt +100 −13 Original line number Diff line number Diff line Loading @@ -18,27 +18,114 @@ package com.android.settingslib.widget import android.content.Context import android.util.AttributeSet import android.view.View.GONE import android.view.View.VISIBLE import android.widget.TextView import androidx.preference.Preference import androidx.preference.PreferenceViewHolder import com.android.settingslib.widget.preference.value.R /** The BulletPreference shows a text which describe a feature. */ /** The ValuePreference shows a text which describe a feature. */ class ValuePreference @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0, defStyleRes: Int = 0 ) : Preference(context, attrs, defStyleAttr, defStyleRes) { defStyleRes: Int = 0, ) : Preference(context, attrs, defStyleAttr, defStyleRes), GroupSectionDividerMixin { /** The secondary title of value preference. */ var secondaryTitle: String? = null set(value) { if (field != value) { field = value notifyChanged() } } /** The secondary summary of value preference. */ var secondarySummary: String? = null set(value) { if (field != value) { field = value notifyChanged() } } /** The visibility of secondary container. */ var secondaryContainerVisibility: Boolean = false set(value) { if (field != value) { field = value notifyChanged() } } /** The first content description of value preference. */ var firstContentDescription: String? = null set(value) { if (field != value) { field = value notifyChanged() } } /** The secondary content description of value preference. */ var secondaryContentDescription: String? = null set(value) { if (field != value) { field = value notifyChanged() } } /** A callback set to be invoked when value preference is clicked. */ var onValueClickListener: OnValueClickListener? = null set(value) { if (field != value) { field = value notifyChanged() } } init { layoutResource = R.layout.settingslib_expressive_value_preference } /** Interface definition for a callback to be invoked when a view is clicked. */ interface OnValueClickListener { /** Called when a view has been clicked. */ fun onValueClick(index: Int) } override fun onBindViewHolder(holder: PreferenceViewHolder) { super.onBindViewHolder(holder) holder.isDividerAllowedAbove = false holder.isDividerAllowedBelow = false holder.findViewById(R.id.value_container_1)?.apply { setOnClickListener { onValueClickListener?.onValueClick(FIRST_ITEM) } contentDescription = firstContentDescription } holder.findViewById(R.id.value_container_2)?.apply { if (secondaryContainerVisibility) { setOnClickListener { onValueClickListener?.onValueClick(SECOND_ITEM) } visibility = VISIBLE contentDescription = secondaryContentDescription } else { visibility = GONE } } if (secondaryContainerVisibility) { (holder.findViewById(R.id.title2) as? TextView)?.text = secondaryTitle (holder.findViewById(R.id.summary2) as? TextView)?.text = secondarySummary } } companion object { const val FIRST_ITEM = 1 const val SECOND_ITEM = 2 } } Loading
packages/SettingsLib/ValuePreference/res/values/styles.xml→packages/SettingsLib/ValuePreference/res/drawable/settingslib_value_preference_background.xml +11 −6 Original line number Diff line number Diff line Loading @@ -15,9 +15,14 @@ limitations under the License. --> <resources xmlns:tools="http://schemas.android.com/tools"> <style name="TextAppearance.SettingsLib.ValuePreferenceTitle" parent="@style/TextAppearance.SettingsLib.DisplaySmall"> <item name="android:textColor">@color/settingslib_text_color_primary</item> </style> </resources> <ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="?android:colorControlHighlight"> <item> <shape android:shape="rectangle"> <solid android:color="@color/settingslib_materialColorSurfaceBright" /> <corners android:radius="@dimen/settingslib_expressive_radius_large2" /> </shape> </item> </ripple> No newline at end of file
packages/SettingsLib/ValuePreference/res/layout/settingslib_expressive_value_preference.xml +63 −17 Original line number Diff line number Diff line Loading @@ -15,30 +15,76 @@ limitations under the License. --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="72dp" android:gravity="center_vertical" android:paddingTop="@dimen/settingslib_expressive_space_extrasmall4" android:paddingStart="?android:attr/listPreferredItemPaddingStart" android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" android:background="?android:attr/selectableItemBackground" android:clipToPadding="false" android:baselineAligned="false" android:filterTouchesWhenObscured="false"> android:clipToPadding="false" android:filterTouchesWhenObscured="false" android:gravity="center_vertical" android:minHeight="?android:attr/listPreferredItemHeight"> <include layout="@layout/settingslib_expressive_preference_icon_frame"/> <LinearLayout android:id="@+id/value_container_1" android:layout_width="@dimen/settingslib_expressive_space_none" android:layout_height="wrap_content" android:layout_weight="1" android:background="@drawable/settingslib_value_preference_background" android:baselineAligned="false" android:gravity="center_vertical" android:minHeight="?android:attr/listPreferredItemHeight"> <include layout="@layout/settingslib_expressive_value_preference_text_frame"/> <!-- Preference should place its actual preference widget here. --> </LinearLayout> <LinearLayout android:id="@android:id/widget_frame" android:id="@+id/value_container_2" android:layout_width="@dimen/settingslib_expressive_space_none" android:layout_height="wrap_content" android:layout_weight="1" android:layout_marginStart="@dimen/settingslib_expressive_space_small1" android:background="@drawable/settingslib_value_preference_background" android:visibility="gone" android:baselineAligned="false" android:gravity="center_vertical" android:minHeight="?android:attr/listPreferredItemHeight"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingStart="@dimen/settingslib_expressive_space_small1" android:paddingEnd="@dimen/settingslib_expressive_space_small1" android:filterTouchesWhenObscured="false" android:paddingVertical="@dimen/settingslib_expressive_space_small1"> <TextView android:id="@+id/title2" android:layout_width="wrap_content" android:layout_height="match_parent" android:gravity="end|center_vertical" android:minWidth="@dimen/settingslib_expressive_space_medium4" android:orientation="vertical"/> android:layout_height="wrap_content" android:layout_gravity="start" android:ellipsize="marquee" android:singleLine="true" android:textAlignment="viewStart" android:textAppearance="@style/TextAppearance.SettingsLib.DisplaySmall" android:textColor="@color/settingslib_text_color_primary"/> <TextView android:id="@+id/summary2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignStart="@id/title2" android:layout_below="@id/title2" android:layout_gravity="start" android:maxLines="2" android:textAlignment="viewStart" android:textAppearance="?android:attr/textAppearanceListItemSecondary" android:textColor="?android:attr/textColorSecondary"/> </RelativeLayout> </LinearLayout> </LinearLayout> No newline at end of file
packages/SettingsLib/ValuePreference/res/layout/settingslib_expressive_value_preference_text_frame.xml +22 −21 Original line number Diff line number Diff line Loading @@ -21,7 +21,7 @@ android:layout_height="wrap_content" android:layout_weight="1" android:paddingVertical="@dimen/settingslib_expressive_space_small1" android:paddingStart="@dimen/settingslib_expressive_space_none" android:paddingStart="@dimen/settingslib_expressive_space_small1" android:paddingEnd="@dimen/settingslib_expressive_space_small1" android:filterTouchesWhenObscured="false"> Loading @@ -30,20 +30,21 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="start" android:ellipsize="marquee" android:singleLine="true" android:textAlignment="viewStart" android:maxLines="2" android:textAppearance="@style/TextAppearance.SettingsLib.ValuePreferenceTitle" android:ellipsize="marquee"/> android:textAppearance="@style/TextAppearance.SettingsLib.DisplaySmall" android:textColor="@color/settingslib_text_color_primary"/> <TextView android:id="@android:id/summary" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@android:id/title" android:layout_alignStart="@android:id/title" android:layout_below="@android:id/title" android:layout_gravity="start" android:maxLines="2" android:textAlignment="viewStart" android:textAppearance="?android:attr/textAppearanceListItemSecondary" android:textColor="?android:attr/textColorSecondary" android:maxLines="10"/> android:textColor="?android:attr/textColorSecondary"/> </RelativeLayout> No newline at end of file
packages/SettingsLib/ValuePreference/src/com/android/settingslib/widget/ValuePreference.kt +100 −13 Original line number Diff line number Diff line Loading @@ -18,27 +18,114 @@ package com.android.settingslib.widget import android.content.Context import android.util.AttributeSet import android.view.View.GONE import android.view.View.VISIBLE import android.widget.TextView import androidx.preference.Preference import androidx.preference.PreferenceViewHolder import com.android.settingslib.widget.preference.value.R /** The BulletPreference shows a text which describe a feature. */ /** The ValuePreference shows a text which describe a feature. */ class ValuePreference @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0, defStyleRes: Int = 0 ) : Preference(context, attrs, defStyleAttr, defStyleRes) { defStyleRes: Int = 0, ) : Preference(context, attrs, defStyleAttr, defStyleRes), GroupSectionDividerMixin { /** The secondary title of value preference. */ var secondaryTitle: String? = null set(value) { if (field != value) { field = value notifyChanged() } } /** The secondary summary of value preference. */ var secondarySummary: String? = null set(value) { if (field != value) { field = value notifyChanged() } } /** The visibility of secondary container. */ var secondaryContainerVisibility: Boolean = false set(value) { if (field != value) { field = value notifyChanged() } } /** The first content description of value preference. */ var firstContentDescription: String? = null set(value) { if (field != value) { field = value notifyChanged() } } /** The secondary content description of value preference. */ var secondaryContentDescription: String? = null set(value) { if (field != value) { field = value notifyChanged() } } /** A callback set to be invoked when value preference is clicked. */ var onValueClickListener: OnValueClickListener? = null set(value) { if (field != value) { field = value notifyChanged() } } init { layoutResource = R.layout.settingslib_expressive_value_preference } /** Interface definition for a callback to be invoked when a view is clicked. */ interface OnValueClickListener { /** Called when a view has been clicked. */ fun onValueClick(index: Int) } override fun onBindViewHolder(holder: PreferenceViewHolder) { super.onBindViewHolder(holder) holder.isDividerAllowedAbove = false holder.isDividerAllowedBelow = false holder.findViewById(R.id.value_container_1)?.apply { setOnClickListener { onValueClickListener?.onValueClick(FIRST_ITEM) } contentDescription = firstContentDescription } holder.findViewById(R.id.value_container_2)?.apply { if (secondaryContainerVisibility) { setOnClickListener { onValueClickListener?.onValueClick(SECOND_ITEM) } visibility = VISIBLE contentDescription = secondaryContentDescription } else { visibility = GONE } } if (secondaryContainerVisibility) { (holder.findViewById(R.id.title2) as? TextView)?.text = secondaryTitle (holder.findViewById(R.id.summary2) as? TextView)?.text = secondarySummary } } companion object { const val FIRST_ITEM = 1 const val SECOND_ITEM = 2 } }