Merge "FooterPreference directs summary to title of preference"
This commit is contained in:
committed by
Android (Google) Code Review
commit
0ebadec6ba
@@ -17,6 +17,7 @@
|
||||
package com.android.settingslib.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.TextView;
|
||||
@@ -55,9 +56,26 @@ public class FooterPreference extends Preference {
|
||||
title.setLongClickable(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSummary(CharSequence summary) {
|
||||
setTitle(summary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSummary(int summaryResId) {
|
||||
setTitle(summaryResId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return getTitle();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
setIcon(R.drawable.ic_info_outline_24);
|
||||
setKey(KEY_FOOTER);
|
||||
setOrder(ORDER_FOOTER);
|
||||
if (TextUtils.isEmpty(getKey())) {
|
||||
setKey(KEY_FOOTER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,28 +37,29 @@ import org.robolectric.RuntimeEnvironment;
|
||||
public class FooterPreferenceTest {
|
||||
|
||||
private Context mContext;
|
||||
private FooterPreference mFooterPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createNewPreference_shouldSetKeyAndOrder() {
|
||||
final FooterPreference preference = new FooterPreference(mContext);
|
||||
|
||||
assertThat(preference.getKey()).isEqualTo(FooterPreference.KEY_FOOTER);
|
||||
assertThat(preference.getOrder()).isEqualTo(FooterPreference.ORDER_FOOTER);
|
||||
mFooterPreference = new FooterPreference(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bindPreference_shouldLinkifyContent() {
|
||||
final FooterPreference preference = new FooterPreference(mContext);
|
||||
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
|
||||
LayoutInflater.from(mContext).inflate(R.layout.preference_footer, null));
|
||||
|
||||
preference.onBindViewHolder(holder);
|
||||
mFooterPreference.onBindViewHolder(holder);
|
||||
|
||||
assertThat(((TextView) holder.findViewById(android.R.id.title)).getMovementMethod())
|
||||
.isInstanceOf(LinkMovementMethod.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSummary_summarySet_shouldSetAsTitle() {
|
||||
mFooterPreference.setSummary("summary");
|
||||
|
||||
assertThat(mFooterPreference.getTitle()).isEqualTo("summary");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user