Hiding data remaining text when available space is too small.

Bug: 77799887

Test: manual
Test: make RunSettingsRoboTests
Change-Id: I53390a36e74f9832bdc7757cd67d51064e8a77f3
This commit is contained in:
Jan Nordqvist
2018-04-18 15:20:03 -07:00
parent 04acf2878d
commit b0802bdcb6
4 changed files with 104 additions and 6 deletions

View File

@@ -17,6 +17,10 @@
package com.android.settings.datausage;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.app.Activity;
import android.content.ComponentName;
@@ -82,13 +86,13 @@ public class DataUsageSummaryPreferenceTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mContext = spy(RuntimeEnvironment.application);
mSummaryPreference = new DataUsageSummaryPreference(mContext, null /* attrs */);
LayoutInflater inflater = LayoutInflater.from(mContext);
View view = inflater.inflate(mSummaryPreference.getLayoutResource(), null /* root */,
false /* attachToRoot */);
mHolder = PreferenceViewHolder.createInstanceForTests(view);
mHolder = spy(PreferenceViewHolder.createInstanceForTests(view));
final long now = System.currentTimeMillis();
mCycleEnd = now + CYCLE_DURATION_MILLIS;
@@ -378,6 +382,7 @@ public class DataUsageSummaryPreferenceTest {
bindViewHolder();
assertThat(mDataUsed.getText().toString()).isEqualTo("1.00 MB used");
assertThat(mDataRemaining.getText().toString()).isEqualTo("9.00 MB left");
assertThat(mDataRemaining.getVisibility()).isEqualTo(View.VISIBLE);
final int colorId = Utils.getColorAttrDefaultColor(mContext, android.R.attr.colorAccent);
assertThat(mDataRemaining.getCurrentTextColor()).isEqualTo(colorId);
}
@@ -435,6 +440,46 @@ public class DataUsageSummaryPreferenceTest {
.isEqualTo(42);
}
@Test
public void testSetUsageInfo_withOverflowStrings_dataRemainingNotShown() {
LayoutInflater inflater = LayoutInflater.from(mContext);
View view = inflater.inflate(mSummaryPreference.getLayoutResource(), null /* root */,
false /* attachToRoot */);
TextView dataUsed = spy(new TextView(mContext));
TextView dataRemaining = spy(new TextView(mContext));
doReturn(dataUsed).when(mHolder).findViewById(R.id.data_usage_view);
doReturn(dataRemaining).when(mHolder).findViewById(R.id.data_remaining_view);
mSummaryPreference.setUsageInfo(mCycleEnd, mUpdateTime, DUMMY_CARRIER, 1 /* numPlans */,
new Intent());
mSummaryPreference.setUsageNumbers(
BillingCycleSettings.MIB_IN_BYTES,
10 * BillingCycleSettings.MIB_IN_BYTES,
true /* hasMobileData */);
when(mContext.getResources()).thenCallRealMethod();
when(mContext.getText(R.string.data_used_formatted))
.thenReturn("^1 ^2 used with long trailing text");
when(mContext.getText(R.string.data_remaining)).thenReturn("^1 left");
bindViewHolder();
doReturn(500).when(dataUsed).getMeasuredWidth();
doReturn(500).when(dataRemaining).getMeasuredWidth();
assertThat(dataRemaining.getVisibility()).isEqualTo(View.VISIBLE);
MeasurableLinearLayout layout =
(MeasurableLinearLayout) mHolder.findViewById(R.id.usage_layout);
layout.measure(
View.MeasureSpec.makeMeasureSpec(800, View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(1000, View.MeasureSpec.EXACTLY));
assertThat(dataUsed.getText().toString()).isEqualTo("1.00 MB used with long trailing text");
assertThat(dataRemaining.getVisibility()).isEqualTo(View.GONE);
}
@Test
public void testSetWifiMode_withUsageInfo_dataUsageShown() {
final int daysLeft = 3;
@@ -483,8 +528,8 @@ public class DataUsageSummaryPreferenceTest {
mCycleTime = (TextView) mHolder.findViewById(R.id.cycle_left_time);
mCarrierInfo = (TextView) mHolder.findViewById(R.id.carrier_and_update);
mDataLimits = (TextView) mHolder.findViewById(R.id.data_limits);
mDataUsed = (TextView) mHolder.findViewById(R.id.data_usage_view);
mDataRemaining = (TextView) mHolder.findViewById(R.id.data_remaining_view);
mDataUsed = spy((TextView) mHolder.findViewById(R.id.data_usage_view));
mDataRemaining = spy((TextView) mHolder.findViewById(R.id.data_remaining_view));
mLaunchButton = (Button) mHolder.findViewById(R.id.launch_mdp_app_button);
mLabelBar = (LinearLayout) mHolder.findViewById(R.id.label_bar);
mLabel1 = (TextView) mHolder.findViewById(R.id.text1);