Support bottom text in UsageProgressBarPreference
- Add text view under progressbar Bug: 177617478 Test: atest UsageProgressBarPreferenceTest Change-Id: I8b6c00752d3a7d0b1281bb84904f32e3df3e0721
This commit is contained in:
committed by
Wesley Wang
parent
64f8341998
commit
f52c07b730
@@ -70,4 +70,13 @@
|
||||
android:scaleY="2"
|
||||
android:layout_marginTop="4dp"
|
||||
android:max="100"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/bottom_summary"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
android:ellipsize="marquee"
|
||||
android:textAppearance="@*android:style/TextAppearance.DeviceDefault.Body1"
|
||||
android:textSize="14sp"/>
|
||||
</LinearLayout>
|
||||
|
||||
@@ -44,6 +44,7 @@ public class UsageProgressBarPreference extends Preference {
|
||||
|
||||
private CharSequence mUsageSummary;
|
||||
private CharSequence mTotalSummary;
|
||||
private CharSequence mBottomSummary;
|
||||
private ImageView mCustomImageView;
|
||||
private int mPercent = -1;
|
||||
|
||||
@@ -101,6 +102,15 @@ public class UsageProgressBarPreference extends Preference {
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
/** Set bottom summary. */
|
||||
public void setBottomSummary(CharSequence bottomSummary) {
|
||||
if (TextUtils.equals(mBottomSummary, bottomSummary)) {
|
||||
return;
|
||||
}
|
||||
mBottomSummary = bottomSummary;
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
/** Set percentage of the progress bar. */
|
||||
public void setPercent(long usage, long total) {
|
||||
if (total == 0L || usage > total) {
|
||||
@@ -147,6 +157,14 @@ public class UsageProgressBarPreference extends Preference {
|
||||
totalSummary.setText(mTotalSummary);
|
||||
}
|
||||
|
||||
final TextView bottomSummary = (TextView) holder.findViewById(R.id.bottom_summary);
|
||||
if (TextUtils.isEmpty(mBottomSummary)) {
|
||||
bottomSummary.setVisibility(View.GONE);
|
||||
} else {
|
||||
bottomSummary.setVisibility(View.VISIBLE);
|
||||
bottomSummary.setText(mBottomSummary);
|
||||
}
|
||||
|
||||
final ProgressBar progressBar = (ProgressBar) holder.findViewById(android.R.id.progress);
|
||||
if (mPercent < 0) {
|
||||
progressBar.setIndeterminate(true);
|
||||
|
||||
@@ -91,6 +91,28 @@ public class UsageProgressBarPreferenceTest {
|
||||
.isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setBottomSummary_getCorrectSummary() {
|
||||
final String expectedText = "Should last until about 7:45 PM";
|
||||
mUsageProgressBarPreference.setBottomSummary(expectedText);
|
||||
|
||||
mUsageProgressBarPreference.onBindViewHolder(mViewHolder);
|
||||
|
||||
final TextView bottomSummary = (TextView) mViewHolder.findViewById(R.id.bottom_summary);
|
||||
assertThat(bottomSummary.getText()).isEqualTo(expectedText);
|
||||
assertThat(bottomSummary.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setBottomSummary_emptyText_isGone() {
|
||||
mUsageProgressBarPreference.setBottomSummary(null);
|
||||
|
||||
mUsageProgressBarPreference.onBindViewHolder(mViewHolder);
|
||||
|
||||
final TextView bottomSummary = (TextView) mViewHolder.findViewById(R.id.bottom_summary);
|
||||
assertThat(bottomSummary.getVisibility()).isEqualTo(View.GONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setPercent_getCorrectProgress() {
|
||||
mUsageProgressBarPreference.setPercent(31, 80);
|
||||
|
||||
Reference in New Issue
Block a user