Merge "Create a set icon visibility interface for footer" into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
7cb4f13fc3
@@ -40,6 +40,8 @@ public class FooterPreference extends Preference {
|
||||
static final int ORDER_FOOTER = Integer.MAX_VALUE - 1;
|
||||
@VisibleForTesting
|
||||
View.OnClickListener mLearnMoreListener;
|
||||
@VisibleForTesting
|
||||
int mIconVisibility = View.VISIBLE;
|
||||
private CharSequence mContentDescription;
|
||||
private CharSequence mLearnMoreText;
|
||||
private CharSequence mLearnMoreContentDescription;
|
||||
@@ -84,6 +86,9 @@ public class FooterPreference extends Preference {
|
||||
} else {
|
||||
learnMore.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
View icon = holder.itemView.findViewById(R.id.icon_frame);
|
||||
icon.setVisibility(mIconVisibility);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -165,6 +170,17 @@ public class FooterPreference extends Preference {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set visibility of footer icon.
|
||||
*/
|
||||
public void setIconVisibility(int iconVisibility) {
|
||||
if (mIconVisibility == iconVisibility) {
|
||||
return;
|
||||
}
|
||||
mIconVisibility = iconVisibility;
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
setLayoutResource(R.layout.preference_footer);
|
||||
if (getIcon() == null) {
|
||||
|
||||
@@ -20,6 +20,7 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
@@ -61,7 +62,7 @@ public class FooterPreferenceTest {
|
||||
mFooterPreference.onBindViewHolder(holder);
|
||||
|
||||
assertThat(((TextView) holder.findViewById(
|
||||
R.id.settingslib_learn_more)).getText().toString())
|
||||
R.id.settingslib_learn_more)).getText().toString())
|
||||
.isEqualTo("Custom learn more");
|
||||
}
|
||||
|
||||
@@ -86,4 +87,11 @@ public class FooterPreferenceTest {
|
||||
|
||||
assertThat(mFooterPreference.mLearnMoreListener).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setIconVisibility_shouldReturnSameVisibilityType() {
|
||||
mFooterPreference.setIconVisibility(View.GONE);
|
||||
|
||||
assertThat(mFooterPreference.mIconVisibility).isEqualTo(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user