New feature “Text and reading options” for SetupWizard, Wallpaper, and Settings (9/n).

- 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
This commit is contained in:
Peter_Liang
2022-01-20 01:32:58 +08:00
parent cc5808cbd7
commit 88d63ea3af
3 changed files with 44 additions and 7 deletions

View File

@@ -53,10 +53,12 @@
android:layout_below="@android:id/summary" />
<LinearLayout
android:id="@+id/label_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/seekbar_frame"
android:orientation="horizontal">
android:orientation="horizontal"
android:visibility="gone">
<TextView
android:id="@android:id/text1"

View File

@@ -74,11 +74,9 @@ public class LabeledSeekBarPreference extends SeekBarPreference {
final TypedArray styledAttrs = context.obtainStyledAttributes(attrs,
R.styleable.LabeledSeekBarPreference);
mTextStartId = styledAttrs.getResourceId(
R.styleable.LabeledSeekBarPreference_textStart,
R.string.summary_placeholder);
R.styleable.LabeledSeekBarPreference_textStart, /* defValue= */ 0);
mTextEndId = styledAttrs.getResourceId(
R.styleable.LabeledSeekBarPreference_textEnd,
R.string.summary_placeholder);
R.styleable.LabeledSeekBarPreference_textEnd, /* defValue= */ 0);
mTickMarkId = styledAttrs.getResourceId(
R.styleable.LabeledSeekBarPreference_tickMark, /* defValue= */ 0);
mIconStartId = styledAttrs.getResourceId(
@@ -115,9 +113,18 @@ public class LabeledSeekBarPreference extends SeekBarPreference {
super.onBindViewHolder(holder);
final TextView startText = (TextView) holder.findViewById(android.R.id.text1);
final TextView endText = (TextView) holder.findViewById(android.R.id.text2);
if (mTextStartId > 0) {
startText.setText(mTextStartId);
}
final TextView endText = (TextView) holder.findViewById(android.R.id.text2);
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) {

View File

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