Merge "Update AppCheckBoxPreference to show summary"
This commit is contained in:
committed by
Android (Google) Code Review
commit
143bd993ab
@@ -17,11 +17,16 @@
|
|||||||
package com.android.settings.widget;
|
package com.android.settings.widget;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
|
||||||
import androidx.preference.CheckBoxPreference;
|
import androidx.preference.CheckBoxPreference;
|
||||||
|
import androidx.preference.PreferenceViewHolder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link CheckBoxPreference} that used only to display app
|
* {@link CheckBoxPreference} that used only to display app
|
||||||
@@ -36,4 +41,20 @@ public class AppCheckBoxPreference extends CheckBoxPreference {
|
|||||||
super(context);
|
super(context);
|
||||||
setLayoutResource(R.layout.preference_app);
|
setLayoutResource(R.layout.preference_app);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||||
|
super.onBindViewHolder(holder);
|
||||||
|
|
||||||
|
final TextView appendix = (TextView) holder.findViewById(R.id.appendix);
|
||||||
|
if (appendix != null) {
|
||||||
|
appendix.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
final LinearLayout layout = (LinearLayout) holder.findViewById(R.id.summary_container);
|
||||||
|
if (layout != null) {
|
||||||
|
// If summary doesn't exist, make it gone
|
||||||
|
layout.setVisibility(TextUtils.isEmpty(getSummary()) ? View.GONE : View.VISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -19,6 +19,8 @@ package com.android.settings.widget;
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
@@ -28,18 +30,25 @@ import org.junit.Test;
|
|||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
|
||||||
|
import androidx.preference.PreferenceViewHolder;
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
public class AppCheckBoxPreferenceTest {
|
public class AppCheckBoxPreferenceTest {
|
||||||
|
|
||||||
|
private static final String SUMMARY = "summary info";
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private AppCheckBoxPreference mPreference;
|
private AppCheckBoxPreference mPreference;
|
||||||
private AppCheckBoxPreference mAttrPreference;
|
private AppCheckBoxPreference mAttrPreference;
|
||||||
|
private PreferenceViewHolder mPreferenceViewHolder;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
mContext = RuntimeEnvironment.application;
|
mContext = RuntimeEnvironment.application;
|
||||||
mPreference = new AppCheckBoxPreference(mContext);
|
mPreference = new AppCheckBoxPreference(mContext);
|
||||||
mAttrPreference = new AppCheckBoxPreference(mContext, null /* attrs */);
|
mAttrPreference = new AppCheckBoxPreference(mContext, null /* attrs */);
|
||||||
|
mPreferenceViewHolder = PreferenceViewHolder.createInstanceForTests(
|
||||||
|
LayoutInflater.from(mContext).inflate(R.layout.preference_app, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -47,4 +56,32 @@ public class AppCheckBoxPreferenceTest {
|
|||||||
assertThat(mPreference.getLayoutResource()).isEqualTo(R.layout.preference_app);
|
assertThat(mPreference.getLayoutResource()).isEqualTo(R.layout.preference_app);
|
||||||
assertThat(mAttrPreference.getLayoutResource()).isEqualTo(R.layout.preference_app);
|
assertThat(mAttrPreference.getLayoutResource()).isEqualTo(R.layout.preference_app);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onBindViewHolder_noSummary_layoutGone() {
|
||||||
|
mPreference.setSummary("");
|
||||||
|
|
||||||
|
mPreference.onBindViewHolder(mPreferenceViewHolder);
|
||||||
|
|
||||||
|
assertThat(mPreferenceViewHolder.findViewById(R.id.summary_container).getVisibility())
|
||||||
|
.isEqualTo(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onBindViewHolder_hasSummary_layoutVisible() {
|
||||||
|
mPreference.setSummary(SUMMARY);
|
||||||
|
|
||||||
|
mPreference.onBindViewHolder(mPreferenceViewHolder);
|
||||||
|
|
||||||
|
assertThat(mPreferenceViewHolder.findViewById(R.id.summary_container).getVisibility())
|
||||||
|
.isEqualTo(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onBindViewHolder_appendixGone() {
|
||||||
|
mPreference.onBindViewHolder(mPreferenceViewHolder);
|
||||||
|
|
||||||
|
assertThat(mPreferenceViewHolder.findViewById(R.id.appendix).getVisibility())
|
||||||
|
.isEqualTo(View.GONE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user