Merge "Updates SeekBarPreference styling" into androidx-master-dev
diff --git a/preference/res/layout/expand_button.xml b/preference/res/layout/expand_button.xml
index b517e99..6bf02a2 100644
--- a/preference/res/layout/expand_button.xml
+++ b/preference/res/layout/expand_button.xml
@@ -20,12 +20,15 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:minHeight="?android:attr/listPreferredItemHeight"
+ android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:gravity="center_vertical"
+ android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
+ android:paddingRight="?android:attr/listPreferredItemPaddingRight"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:background="?android:attr/selectableItemBackground"
android:clipToPadding="false"
+ android:focusable="true"
android:baselineAligned="false">
<include layout="@layout/image_frame"/>
@@ -41,6 +44,7 @@
android:id="@android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
+ android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorPrimary"
android:ellipsize="marquee"/>
@@ -50,11 +54,12 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@android:id/title"
+ android:layout_alignLeft="@android:id/title"
android:layout_alignStart="@android:id/title"
- android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary"
android:ellipsize="marquee"
- android:singleLine="true"/>
+ android:singleLine="true"
+ style="@style/PreferenceSummaryTextStyle"/>
</RelativeLayout>
</LinearLayout>
diff --git a/preference/res/layout/preference_widget_seekbar.xml b/preference/res/layout/preference_widget_seekbar.xml
index e9430a2..6cc98be 100644
--- a/preference/res/layout/preference_widget_seekbar.xml
+++ b/preference/res/layout/preference_widget_seekbar.xml
@@ -75,14 +75,14 @@
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
- android:paddingStart="@dimen/preference_seekbar_padding_start"
- android:paddingEnd="@dimen/preference_seekbar_padding_end"
+ android:paddingStart="@dimen/preference_seekbar_padding_horizontal"
+ android:paddingEnd="22dp"
android:focusable="false"
android:clickable="false"
android:background="@null" />
<TextView android:id="@+id/seekbar_value"
- android:layout_width="@dimen/preference_seekbar_value_width"
+ android:layout_width="@dimen/preference_seekbar_value_minWidth"
android:layout_height="match_parent"
android:gravity="right|center_vertical"
android:fontFamily="sans-serif-condensed"
diff --git a/preference/res/layout/preference_widget_seekbar_material.xml b/preference/res/layout/preference_widget_seekbar_material.xml
index dfd7db7..47a48f6 100644
--- a/preference/res/layout/preference_widget_seekbar_material.xml
+++ b/preference/res/layout/preference_widget_seekbar_material.xml
@@ -20,7 +20,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:minHeight="?android:attr/listPreferredItemHeight"
+ android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:gravity="center_vertical"
android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
android:paddingRight="?android:attr/listPreferredItemPaddingRight"
@@ -33,34 +33,41 @@
<include layout="@layout/image_frame"/>
- <RelativeLayout
- android:layout_width="0dp"
+ <LinearLayout
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_marginEnd="8dip"
- android:layout_marginTop="6dip"
- android:layout_marginBottom="6dip"
- android:layout_weight="1"
+ android:orientation="vertical"
+ android:layout_marginTop="8dp"
+ android:layout_marginBottom="8dp"
android:clipChildren="false"
android:clipToPadding="false">
- <TextView
- android:id="@android:id/title"
+ <RelativeLayout
android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:singleLine="true"
- android:textAppearance="?android:attr/textAppearanceListItem"
- android:ellipsize="marquee"
- android:fadingEdge="horizontal"/>
+ android:layout_height="0dp"
+ android:layout_weight="1">
- <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:textColor="?android:attr/textColorSecondary"
- android:maxLines="4"
- style="@style/PreferenceSummaryTextStyle"/>
+ <TextView
+ android:id="@android:id/title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:singleLine="true"
+ android:textAppearance="?android:attr/textAppearanceListItem"
+ android:ellipsize="marquee"/>
+
+ <TextView
+ android:id="@android:id/summary"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_below="@android:id/title"
+ android:layout_alignLeft="@android:id/title"
+ android:layout_alignStart="@android:id/title"
+ android:textAlignment="viewStart"
+ android:textColor="?android:attr/textColorSecondary"
+ android:maxLines="4"
+ style="@style/PreferenceSummaryTextStyle"/>
+
+ </RelativeLayout>
<!-- Using UnPressableLinearLayout as a workaround to disable the pressed state propagation
to the children of this container layout. Otherwise, the animated pressed state will also
@@ -69,30 +76,43 @@
<androidx.preference.UnPressableLinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_below="@android:id/summary"
- android:layout_alignStart="@android:id/title"
+ android:gravity="center_vertical"
+ android:paddingRight="16dp"
+ android:paddingEnd="16dp"
android:clipChildren="false"
android:clipToPadding="false">
+ <!-- The total height of the Seekbar widget's area should be 48dp - this allows for an
+ increased touch area so you do not need to exactly tap the thumb to move it. However,
+ setting the Seekbar height directly causes the thumb and seekbar to be misaligned on
+ API 22 and 23 - so instead we just set 15dp padding above and below, to account for the
+ 2dp height of the track, and the 8dp margin above and below the whole Preference. -->
<SeekBar
android:id="@+id/seekbar"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
- android:paddingLeft="@dimen/preference_seekbar_padding_start"
- android:paddingRight="@dimen/preference_seekbar_padding_end"
- android:paddingStart="@dimen/preference_seekbar_padding_start"
- android:paddingEnd="@dimen/preference_seekbar_padding_end"
+ android:paddingLeft="@dimen/preference_seekbar_padding_horizontal"
+ android:paddingRight="@dimen/preference_seekbar_padding_horizontal"
+ android:paddingStart="@dimen/preference_seekbar_padding_horizontal"
+ android:paddingEnd="@dimen/preference_seekbar_padding_horizontal"
+ android:paddingTop="@dimen/preference_seekbar_padding_vertical"
+ android:paddingBottom="@dimen/preference_seekbar_padding_vertical"
android:focusable="false"
android:clickable="false"
android:background="@null"/>
+ <!-- If the value is shown, we reserve a minimum width of 36dp to allow for consistent
+ seekbar width for smaller values. If the value is ~4 or more digits, it will expand
+ into the seekbar width. -->
<TextView
android:id="@+id/seekbar_value"
- android:layout_width="@dimen/preference_seekbar_value_width"
- android:layout_height="match_parent"
- android:gravity="right|center_vertical"
- android:fontFamily="sans-serif-condensed"
+ android:minWidth="@dimen/preference_seekbar_value_minWidth"
+ android:paddingLeft="8dp"
+ android:paddingStart="8dp"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:gravity="right"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceListItem"
android:ellipsize="marquee"
@@ -100,5 +120,5 @@
android:scrollbars="none"/>
</androidx.preference.UnPressableLinearLayout>
- </RelativeLayout>
+ </LinearLayout>
</LinearLayout>
diff --git a/preference/res/values/attrs.xml b/preference/res/values/attrs.xml
index d9f8806..8b1d83c 100644
--- a/preference/res/values/attrs.xml
+++ b/preference/res/values/attrs.xml
@@ -322,7 +322,7 @@
<attr name="adjustable" format="boolean" />
<!-- Flag indicating whether the TextView next to the seekbar that shows the current seekbar
value will be displayed. If true, the view is VISIBLE; if false, the view will be GONE.
- By default, this view is VISIBLE. -->
+ By default, this view is GONE. -->
<attr name="showSeekBarValue" format="boolean" />
</declare-styleable>
diff --git a/preference/res/values/dimens.xml b/preference/res/values/dimens.xml
index 8ffc4f0..403523e 100644
--- a/preference/res/values/dimens.xml
+++ b/preference/res/values/dimens.xml
@@ -4,12 +4,12 @@
This helps in aligning titles when some items have icons and some don't. When space is
at a premium, we don't pre-allocate any space. -->
<dimen name="preference_icon_minWidth">0dp</dimen>
- <!-- The padding at the start of the seekbar view within a SeekBarPreference -->
- <dimen name="preference_seekbar_padding_start">0dp</dimen>
- <!-- The padding at the end of the seekbar view within a SeekBarPreference -->
- <dimen name="preference_seekbar_padding_end">22dp</dimen>
- <!-- The width of the TextView indicating the current value of the SeekBarPreference -->
- <dimen name="preference_seekbar_value_width">36dp</dimen>
+ <!-- The padding at the start and end of the Seekbar within a SeekBarPreference -->
+ <dimen name="preference_seekbar_padding_horizontal">0dp</dimen>
+ <!-- The padding at the top and bottom of the Seekbar within a SeekBarPreference -->
+ <dimen name="preference_seekbar_padding_vertical">15dp</dimen>
+ <!-- The minimum width of the TextView indicating the current value of the SeekBarPreference -->
+ <dimen name="preference_seekbar_value_minWidth">36dp</dimen>
<!-- The padding at the start of the dropdown menu within a DropDownPreference
TODO: Pending UX discussion in b/110975540 - keeping old behaviour for now.-->
<dimen name="preference_dropdown_padding_start">0dp</dimen>
diff --git a/preference/res/values/styles.xml b/preference/res/values/styles.xml
index 8dfe8d1..3eaada8 100644
--- a/preference/res/values/styles.xml
+++ b/preference/res/values/styles.xml
@@ -132,7 +132,7 @@
<style name="Preference.SeekBarPreference.Material">
<item name="android:layout">@layout/preference_widget_seekbar_material</item>
<item name="adjustable">true</item>
- <item name="showSeekBarValue">true</item>
+ <item name="showSeekBarValue">false</item>
<item name="allowDividerAbove">false</item>
<item name="allowDividerBelow">true</item>
<item name="iconSpaceReserved">@bool/config_materialPreferenceIconSpaceReserved</item>
diff --git a/preference/src/main/java/androidx/preference/SeekBarPreference.java b/preference/src/main/java/androidx/preference/SeekBarPreference.java
index 1619d37..920fdd7 100644
--- a/preference/src/main/java/androidx/preference/SeekBarPreference.java
+++ b/preference/src/main/java/androidx/preference/SeekBarPreference.java
@@ -135,7 +135,7 @@
setMax(a.getInt(R.styleable.SeekBarPreference_android_max, 100));
setSeekBarIncrement(a.getInt(R.styleable.SeekBarPreference_seekBarIncrement, 0));
mAdjustable = a.getBoolean(R.styleable.SeekBarPreference_adjustable, true);
- mShowSeekBarValue = a.getBoolean(R.styleable.SeekBarPreference_showSeekBarValue, true);
+ mShowSeekBarValue = a.getBoolean(R.styleable.SeekBarPreference_showSeekBarValue, false);
a.recycle();
}
diff --git a/samples/SupportPreferenceDemos/src/main/res/values/strings.xml b/samples/SupportPreferenceDemos/src/main/res/values/strings.xml
index de19c77..7fbc88e 100644
--- a/samples/SupportPreferenceDemos/src/main/res/values/strings.xml
+++ b/samples/SupportPreferenceDemos/src/main/res/values/strings.xml
@@ -51,7 +51,6 @@
<string name="title_dropdown_preference">Dropdown preference</string>
<string name="title_seekbar_preference">Seekbar preference</string>
- <string name="summary_seekbar_preference">This seekbar has a default value of 5 and a max value of 10</string>
<!--This section is for preferences that launch a dialog to edit the preference -->
<string name="dialogs">Dialogs</string>
diff --git a/samples/SupportPreferenceDemos/src/main/res/xml/preferences.xml b/samples/SupportPreferenceDemos/src/main/res/xml/preferences.xml
index 0a5676b..11e9737 100644
--- a/samples/SupportPreferenceDemos/src/main/res/xml/preferences.xml
+++ b/samples/SupportPreferenceDemos/src/main/res/xml/preferences.xml
@@ -70,7 +70,6 @@
<SeekBarPreference
android:key="seekbar"
android:title="@string/title_seekbar_preference"
- android:summary="@string/summary_seekbar_preference"
android:max="10"
android:defaultValue="5"/>
</PreferenceCategory>