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()