Merge "Hiding data remaining text when available space is too small." into pi-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
5f6937dd88
@@ -34,7 +34,7 @@
|
|||||||
android:textColor="?android:attr/colorAccent"
|
android:textColor="?android:attr/colorAccent"
|
||||||
android:text="@string/data_usage_title" />
|
android:text="@string/data_usage_title" />
|
||||||
|
|
||||||
<LinearLayout
|
<com.android.settings.datausage.MeasurableLinearLayout
|
||||||
android:id="@+id/usage_layout"
|
android:id="@+id/usage_layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@@ -61,7 +61,7 @@
|
|||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
android:textSize="16sp" />
|
android:textSize="16sp" />
|
||||||
|
|
||||||
</LinearLayout>
|
</com.android.settings.datausage.MeasurableLinearLayout>
|
||||||
|
|
||||||
<android.widget.ProgressBar
|
<android.widget.ProgressBar
|
||||||
android:id="@+id/determinateBar"
|
android:id="@+id/determinateBar"
|
||||||
|
@@ -227,6 +227,9 @@ public class DataUsageSummaryPreference extends Preference {
|
|||||||
TextUtils.expandTemplate(template, usageNumberText, usedResult.units);
|
TextUtils.expandTemplate(template, usageNumberText, usedResult.units);
|
||||||
usageNumberField.setText(usageText);
|
usageNumberField.setText(usageText);
|
||||||
|
|
||||||
|
final MeasurableLinearLayout layout =
|
||||||
|
(MeasurableLinearLayout) holder.findViewById(R.id.usage_layout);
|
||||||
|
|
||||||
if (mHasMobileData && mNumPlans >= 0 && mDataplanSize > 0L) {
|
if (mHasMobileData && mNumPlans >= 0 && mDataplanSize > 0L) {
|
||||||
TextView usageRemainingField = (TextView) holder.findViewById(R.id.data_remaining_view);
|
TextView usageRemainingField = (TextView) holder.findViewById(R.id.data_remaining_view);
|
||||||
long dataRemaining = mDataplanSize - mDataplanUse;
|
long dataRemaining = mDataplanSize - mDataplanUse;
|
||||||
@@ -243,6 +246,9 @@ public class DataUsageSummaryPreference extends Preference {
|
|||||||
usageRemainingField.setTextColor(
|
usageRemainingField.setTextColor(
|
||||||
Utils.getColorAttr(getContext(), android.R.attr.colorError));
|
Utils.getColorAttr(getContext(), android.R.attr.colorError));
|
||||||
}
|
}
|
||||||
|
layout.setChildren(usageNumberField, usageRemainingField);
|
||||||
|
} else {
|
||||||
|
layout.setChildren(usageNumberField, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -0,0 +1,47 @@
|
|||||||
|
package com.android.settings.datausage;
|
||||||
|
|
||||||
|
import android.annotation.Nullable;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
|
public class MeasurableLinearLayout extends LinearLayout {
|
||||||
|
private View mFixedView;
|
||||||
|
private View mDisposableView;
|
||||||
|
|
||||||
|
public MeasurableLinearLayout(Context context) {
|
||||||
|
super(context, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MeasurableLinearLayout(Context context, @Nullable AttributeSet attrs) {
|
||||||
|
super(context, attrs, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MeasurableLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MeasurableLinearLayout(Context context, AttributeSet attrs,
|
||||||
|
int defStyleAttr, int defStyleRes) {
|
||||||
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||||
|
if (mDisposableView != null && getMeasuredWidth() - mFixedView.getMeasuredWidth()
|
||||||
|
< mDisposableView.getMeasuredWidth()) {
|
||||||
|
mDisposableView.setVisibility(GONE);
|
||||||
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||||
|
} else if (mDisposableView != null && mDisposableView.getVisibility() != VISIBLE) {
|
||||||
|
mDisposableView.setVisibility(VISIBLE);
|
||||||
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChildren(View fixedView, View disposableView) {
|
||||||
|
mFixedView = fixedView;
|
||||||
|
mDisposableView = disposableView;
|
||||||
|
}
|
||||||
|
}
|
@@ -17,6 +17,10 @@
|
|||||||
package com.android.settings.datausage;
|
package com.android.settings.datausage;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
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.app.Activity;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
@@ -82,13 +86,13 @@ public class DataUsageSummaryPreferenceTest {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mContext = RuntimeEnvironment.application;
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
mSummaryPreference = new DataUsageSummaryPreference(mContext, null /* attrs */);
|
mSummaryPreference = new DataUsageSummaryPreference(mContext, null /* attrs */);
|
||||||
LayoutInflater inflater = LayoutInflater.from(mContext);
|
LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||||
View view = inflater.inflate(mSummaryPreference.getLayoutResource(), null /* root */,
|
View view = inflater.inflate(mSummaryPreference.getLayoutResource(), null /* root */,
|
||||||
false /* attachToRoot */);
|
false /* attachToRoot */);
|
||||||
|
|
||||||
mHolder = PreferenceViewHolder.createInstanceForTests(view);
|
mHolder = spy(PreferenceViewHolder.createInstanceForTests(view));
|
||||||
|
|
||||||
final long now = System.currentTimeMillis();
|
final long now = System.currentTimeMillis();
|
||||||
mCycleEnd = now + CYCLE_DURATION_MILLIS;
|
mCycleEnd = now + CYCLE_DURATION_MILLIS;
|
||||||
@@ -369,6 +373,7 @@ public class DataUsageSummaryPreferenceTest {
|
|||||||
bindViewHolder();
|
bindViewHolder();
|
||||||
assertThat(mDataUsed.getText().toString()).isEqualTo("1.00 MB used");
|
assertThat(mDataUsed.getText().toString()).isEqualTo("1.00 MB used");
|
||||||
assertThat(mDataRemaining.getText().toString()).isEqualTo("9.00 MB left");
|
assertThat(mDataRemaining.getText().toString()).isEqualTo("9.00 MB left");
|
||||||
|
assertThat(mDataRemaining.getVisibility()).isEqualTo(View.VISIBLE);
|
||||||
final int colorId = Utils.getColorAttr(mContext, android.R.attr.colorAccent);
|
final int colorId = Utils.getColorAttr(mContext, android.R.attr.colorAccent);
|
||||||
assertThat(mDataRemaining.getCurrentTextColor()).isEqualTo(colorId);
|
assertThat(mDataRemaining.getCurrentTextColor()).isEqualTo(colorId);
|
||||||
}
|
}
|
||||||
@@ -426,6 +431,46 @@ public class DataUsageSummaryPreferenceTest {
|
|||||||
.isEqualTo(42);
|
.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
|
@Test
|
||||||
public void testSetWifiMode_withUsageInfo_dataUsageShown() {
|
public void testSetWifiMode_withUsageInfo_dataUsageShown() {
|
||||||
final int daysLeft = 3;
|
final int daysLeft = 3;
|
||||||
@@ -474,8 +519,8 @@ public class DataUsageSummaryPreferenceTest {
|
|||||||
mCycleTime = (TextView) mHolder.findViewById(R.id.cycle_left_time);
|
mCycleTime = (TextView) mHolder.findViewById(R.id.cycle_left_time);
|
||||||
mCarrierInfo = (TextView) mHolder.findViewById(R.id.carrier_and_update);
|
mCarrierInfo = (TextView) mHolder.findViewById(R.id.carrier_and_update);
|
||||||
mDataLimits = (TextView) mHolder.findViewById(R.id.data_limits);
|
mDataLimits = (TextView) mHolder.findViewById(R.id.data_limits);
|
||||||
mDataUsed = (TextView) mHolder.findViewById(R.id.data_usage_view);
|
mDataUsed = spy((TextView) mHolder.findViewById(R.id.data_usage_view));
|
||||||
mDataRemaining = (TextView) mHolder.findViewById(R.id.data_remaining_view);
|
mDataRemaining = spy((TextView) mHolder.findViewById(R.id.data_remaining_view));
|
||||||
mLaunchButton = (Button) mHolder.findViewById(R.id.launch_mdp_app_button);
|
mLaunchButton = (Button) mHolder.findViewById(R.id.launch_mdp_app_button);
|
||||||
mLabelBar = (LinearLayout) mHolder.findViewById(R.id.label_bar);
|
mLabelBar = (LinearLayout) mHolder.findViewById(R.id.label_bar);
|
||||||
mLabel1 = (TextView) mHolder.findViewById(R.id.text1);
|
mLabel1 = (TextView) mHolder.findViewById(R.id.text1);
|
||||||
|
Reference in New Issue
Block a user