From 88d63ea3aff05cfc4798b35b926e4bd10fa04069 Mon Sep 17 00:00:00 2001 From: Peter_Liang Date: Thu, 20 Jan 2022 01:32:58 +0800 Subject: [PATCH] =?UTF-8?q?New=20feature=20=E2=80=9CText=20and=20reading?= =?UTF-8?q?=20options=E2=80=9D=20for=20SetupWizard,=20Wallpaper,=20and=20S?= =?UTF-8?q?ettings=20(9/n).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fine-tune the legacy interface of the LabeledSeekBarPreference 1) If not set any label, the layout should be gone instead of visible. If not gone, the preference will have redundant space. Bug: 211503117 Test: make -j64 RunSettingsRoboTests ROBOTEST_FILTER=LabeledSeekBarPreferenceTest Change-Id: Ideea8589e35083eb89495c0eceba38c62b4807a7 --- res/layout/preference_labeled_slider.xml | 4 ++- .../widget/LabeledSeekBarPreference.java | 19 +++++++++---- .../LabeledSeekBarPreferenceTest.java | 28 +++++++++++++++++++ 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/res/layout/preference_labeled_slider.xml b/res/layout/preference_labeled_slider.xml index ebe3e4ec3b3..294b9794c0c 100644 --- a/res/layout/preference_labeled_slider.xml +++ b/res/layout/preference_labeled_slider.xml @@ -53,10 +53,12 @@ android:layout_below="@android:id/summary" /> + android:orientation="horizontal" + android:visibility="gone"> 0) { + startText.setText(mTextStartId); + } + final TextView endText = (TextView) holder.findViewById(android.R.id.text2); - startText.setText(mTextStartId); - endText.setText(mTextEndId); + if (mTextEndId > 0) { + endText.setText(mTextEndId); + } + + final View labelFrame = holder.findViewById(R.id.label_frame); + final boolean isValidTextResIdExist = mTextStartId > 0 || mTextEndId > 0; + labelFrame.setVisibility(isValidTextResIdExist ? View.VISIBLE : View.GONE); final SeekBar seekBar = (SeekBar) holder.findViewById(com.android.internal.R.id.seekbar); if (mTickMarkId != 0) { diff --git a/tests/robotests/src/com/android/settings/gestures/LabeledSeekBarPreferenceTest.java b/tests/robotests/src/com/android/settings/gestures/LabeledSeekBarPreferenceTest.java index 058e16b6c36..d00e905e816 100644 --- a/tests/robotests/src/com/android/settings/gestures/LabeledSeekBarPreferenceTest.java +++ b/tests/robotests/src/com/android/settings/gestures/LabeledSeekBarPreferenceTest.java @@ -66,6 +66,7 @@ public class LabeledSeekBarPreferenceTest { private TextView mSummary; private ViewGroup mIconStartFrame; private ViewGroup mIconEndFrame; + private View mLabelFrame; private LabeledSeekBarPreference mSeekBarPreference; @Mock @@ -89,6 +90,7 @@ public class LabeledSeekBarPreferenceTest { mSummary = (TextView) mViewHolder.findViewById(android.R.id.summary); mIconStartFrame = (ViewGroup) mViewHolder.findViewById(R.id.icon_start_frame); mIconEndFrame = (ViewGroup) mViewHolder.findViewById(R.id.icon_end_frame); + mLabelFrame = mViewHolder.findViewById(R.id.label_frame); } @Test @@ -120,6 +122,32 @@ public class LabeledSeekBarPreferenceTest { assertThat(mSummary.getVisibility()).isEqualTo(View.GONE); } + @Test + public void setTextAttributes_textStart_textEnd_labelFrameVisible() { + final AttributeSet attributeSet = Robolectric.buildAttributeSet() + .addAttribute(R.attr.textStart, "@string/screen_zoom_make_smaller_desc") + .addAttribute(R.attr.textEnd, "@string/screen_zoom_make_larger_desc") + .build(); + final LabeledSeekBarPreference seekBarPreference = + new LabeledSeekBarPreference(mContext, attributeSet); + + seekBarPreference.onBindViewHolder(mViewHolder); + + assertThat(mLabelFrame.getVisibility()).isEqualTo(View.VISIBLE); + } + + @Test + public void notSetTextAttributes_labelFrameGone() { + final AttributeSet attributeSet = Robolectric.buildAttributeSet() + .build(); + final LabeledSeekBarPreference seekBarPreference = + new LabeledSeekBarPreference(mContext, attributeSet); + + seekBarPreference.onBindViewHolder(mViewHolder); + + assertThat(mLabelFrame.getVisibility()).isEqualTo(View.GONE); + } + @Test public void setIconAttributes_iconVisible() { final AttributeSet attributeSet = Robolectric.buildAttributeSet()