Change text layout of data usage string.
In Data Usage screen, Above the data bar, Change font size of number In Data Usage screen, Above the data bar, Update text style of “GB used” In Data Usage screen, Above the data bar, Add “GB left” aligned right of bar (not always shown) Bug: 70950124 Test: manual Test: make RunSettingsRoboTests Change-Id: I8accb16425283cf148ddb6b6646f92ff51a74b7c
This commit is contained in:
committed by
Sundeep Ghuman
parent
d610e51613
commit
8a241f642e
@@ -35,15 +35,34 @@
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:text="@string/data_usage_title" />
|
||||
|
||||
<TextView
|
||||
android:id="@android:id/title"
|
||||
android:paddingTop="12dp"
|
||||
android:paddingBottom="4dp"
|
||||
<LinearLayout
|
||||
android:id="@+id/usage_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="12dp"
|
||||
android:paddingBottom="4dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView android:id="@+id/data_usage_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@*android:string/config_headlineFontFamily"
|
||||
android:textColor="?android:attr/colorAccent"
|
||||
android:textAppearance="@android:style/TextAppearance.Material.Large" />
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:textColor="?android:attr/colorAccent" />
|
||||
|
||||
<Space
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<TextView android:id="@+id/data_remaining_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@*android:string/config_headlineFontFamily"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:textColor="?android:attr/colorAccent" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<android.widget.ProgressBar
|
||||
android:id="@+id/determinateBar"
|
||||
|
@@ -8749,7 +8749,7 @@
|
||||
<string name="data_used"><xliff:g name="bytes" example="2 GB">^1</xliff:g> used</string>
|
||||
|
||||
<!-- Optional part of data usage showing the remaining amount [CHAR LIMIT=30] -->
|
||||
<string name="data_remaining"><xliff:g name="bytes" example="2 GB">, ^1</xliff:g> left</string>
|
||||
<string name="data_remaining"><xliff:g name="bytes" example="2 GB">^1</xliff:g> left</string>
|
||||
|
||||
<!-- Informational text about time left in billing cycle [CHAR LIMIT=30] -->
|
||||
<string name="cycle_left_time_text"><xliff:g name="time" example="2d">%1$s</xliff:g> left in this cycle</string>
|
||||
|
@@ -234,12 +234,17 @@ public class DataUsageSummary extends DataUsageBaseFragment implements Indexable
|
||||
static CharSequence formatUsage(Context context, String template, long usageLevel) {
|
||||
final float LARGER_SIZE = 1.25f * 1.25f; // (1/0.8)^2
|
||||
final float SMALLER_SIZE = 1.0f / LARGER_SIZE; // 0.8^2
|
||||
return formatUsage(context, template, usageLevel, LARGER_SIZE, SMALLER_SIZE);
|
||||
}
|
||||
|
||||
static CharSequence formatUsage(Context context, String template, long usageLevel,
|
||||
float larger, float smaller) {
|
||||
final int FLAGS = Spannable.SPAN_INCLUSIVE_INCLUSIVE;
|
||||
|
||||
final Formatter.BytesResult usedResult = Formatter.formatBytes(context.getResources(),
|
||||
usageLevel, Formatter.FLAG_CALCULATE_ROUNDED);
|
||||
final SpannableString enlargedValue = new SpannableString(usedResult.value);
|
||||
enlargedValue.setSpan(new RelativeSizeSpan(LARGER_SIZE), 0, enlargedValue.length(), FLAGS);
|
||||
enlargedValue.setSpan(new RelativeSizeSpan(larger), 0, enlargedValue.length(), FLAGS);
|
||||
|
||||
final SpannableString amountTemplate = new SpannableString(
|
||||
context.getString(com.android.internal.R.string.fileSizeSuffix)
|
||||
@@ -248,7 +253,7 @@ public class DataUsageSummary extends DataUsageBaseFragment implements Indexable
|
||||
enlargedValue, usedResult.units);
|
||||
|
||||
final SpannableString fullTemplate = new SpannableString(template);
|
||||
fullTemplate.setSpan(new RelativeSizeSpan(SMALLER_SIZE), 0, fullTemplate.length(), FLAGS);
|
||||
fullTemplate.setSpan(new RelativeSizeSpan(smaller), 0, fullTemplate.length(), FLAGS);
|
||||
return TextUtils.expandTemplate(fullTemplate,
|
||||
BidiFormatter.getInstance().unicodeWrap(formattedUsage.toString()));
|
||||
}
|
||||
|
@@ -21,6 +21,7 @@ import android.content.Intent;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.text.TextUtils;
|
||||
import android.text.format.Formatter;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
@@ -41,6 +42,10 @@ public class DataUsageSummaryPreference extends Preference {
|
||||
private String mStartLabel;
|
||||
private String mEndLabel;
|
||||
|
||||
/** large vs small size is 36/16 ~ 2.25 */
|
||||
private static final float LARGER_FONT_RATIO = 2.25f;
|
||||
private static final float SMALLER_FONT_RATIO = 1.0f;
|
||||
|
||||
private int mNumPlans;
|
||||
/** The ending time of the billing cycle in milliseconds since epoch. */
|
||||
private long mCycleEndTimeMs;
|
||||
@@ -53,6 +58,16 @@ public class DataUsageSummaryPreference extends Preference {
|
||||
|
||||
/** Progress to display on ProgressBar */
|
||||
private float mProgress;
|
||||
private boolean mHasMobileData;
|
||||
|
||||
/**
|
||||
* The size of the first registered plan if one exists or the size of the warning if it is set.
|
||||
* -1 if no information is available.
|
||||
*/
|
||||
private long mDataplanSize;
|
||||
|
||||
/** The number of bytes used since the start of the cycle. */
|
||||
private long mDataplanUse;
|
||||
|
||||
public DataUsageSummaryPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
@@ -94,10 +109,18 @@ public class DataUsageSummaryPreference extends Preference {
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
void setUsageNumbers(long used, long dataPlanSize, boolean hasMobileData) {
|
||||
mDataplanUse = used;
|
||||
mDataplanSize = dataPlanSize;
|
||||
mHasMobileData = hasMobileData;
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
super.onBindViewHolder(holder);
|
||||
|
||||
|
||||
if (mChartEnabled && (!TextUtils.isEmpty(mStartLabel) || !TextUtils.isEmpty(mEndLabel))) {
|
||||
holder.findViewById(R.id.label_bar).setVisibility(View.VISIBLE);
|
||||
ProgressBar bar = (ProgressBar) holder.findViewById(R.id.determinateBar);
|
||||
@@ -108,6 +131,17 @@ public class DataUsageSummaryPreference extends Preference {
|
||||
holder.findViewById(R.id.label_bar).setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
TextView usageNumberField = (TextView) holder.findViewById(R.id.data_usage_view);
|
||||
usageNumberField.setText(TextUtils.expandTemplate(
|
||||
getContext().getString(R.string.data_used),
|
||||
Formatter.formatFileSize(getContext(), mDataplanUse)));
|
||||
if (mHasMobileData && mNumPlans >= 0 && mDataplanSize > 0L) {
|
||||
TextView usageRemainingField = (TextView) holder.findViewById(R.id.data_remaining_view);
|
||||
usageRemainingField.setText(
|
||||
TextUtils.expandTemplate(getContext().getText(R.string.data_remaining),
|
||||
Formatter.formatFileSize(getContext(), mDataplanSize - mDataplanUse)));
|
||||
}
|
||||
|
||||
TextView usageTitle = (TextView) holder.findViewById(R.id.usage_title);
|
||||
usageTitle.setVisibility(mNumPlans > 1 ? View.VISIBLE : View.GONE);
|
||||
|
||||
|
@@ -174,19 +174,7 @@ public class DataUsageSummaryPreferenceController extends BasePreferenceControll
|
||||
summaryPreference.setLimitInfo(null);
|
||||
}
|
||||
|
||||
final StringBuilder title = new StringBuilder();
|
||||
if (mHasMobileData) {
|
||||
title.append(formatUsage(mContext, mContext.getString(R.string.data_used),
|
||||
mDataplanUse));
|
||||
if (mDataplanCount >= 0 && mDataplanSize > 0L) {
|
||||
title.append(formatUsage(mContext, mContext.getString(R.string.data_remaining),
|
||||
mDataplanSize - mDataplanUse));
|
||||
}
|
||||
} else {
|
||||
title.append(formatUsage(mContext, mContext.getString(mDataUsageTemplate),
|
||||
mDataplanUse));
|
||||
}
|
||||
summaryPreference.setTitle(title.toString());
|
||||
summaryPreference.setUsageNumbers(mDataplanUse, mDataplanSize, mHasMobileData);
|
||||
|
||||
if (mDataplanSize <= 0) {
|
||||
summaryPreference.setChartEnabled(false);
|
||||
|
@@ -55,6 +55,8 @@ public class DataUsageSummaryPreferenceTest {
|
||||
private TextView mCycleTime;
|
||||
private TextView mCarrierInfo;
|
||||
private TextView mDataLimits;
|
||||
private TextView mDataUsed;
|
||||
private TextView mDataRemaining;
|
||||
private Button mLaunchButton;
|
||||
private LinearLayout mLabelBar;
|
||||
private TextView mLabel1;
|
||||
@@ -205,12 +207,35 @@ public class DataUsageSummaryPreferenceTest {
|
||||
mSummaryPreference.setLabels("0.0 GB", "5.0 GB");
|
||||
}
|
||||
|
||||
public void testSetUsageAndRemainingInfo_withUsageInfo_dataUsageAndRemainingShown() {
|
||||
mSummaryPreference.setUsageInfo(mCycleEnd, mUpdateTime, DUMMY_CARRIER, 1 /* numPlans */,
|
||||
new Intent());
|
||||
mSummaryPreference.setUsageNumbers(1000000L, 10000000L, true);
|
||||
|
||||
bindViewHolder();
|
||||
assertThat(mDataUsed.getText().toString()).isEqualTo("1.00 MB used");
|
||||
assertThat(mDataRemaining.getText().toString()).isEqualTo("9.00 MB left");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetUsageInfo_withUsageInfo_dataUsageShown() {
|
||||
mSummaryPreference.setUsageInfo(mCycleEnd, mUpdateTime, DUMMY_CARRIER, 0 /* numPlans */,
|
||||
new Intent());
|
||||
mSummaryPreference.setUsageNumbers(1000000L, -1L, true);
|
||||
|
||||
bindViewHolder();
|
||||
assertThat(mDataUsed.getText().toString()).isEqualTo("1.00 MB used");
|
||||
assertThat(mDataRemaining.getText()).isEqualTo("");
|
||||
}
|
||||
|
||||
private void bindViewHolder() {
|
||||
mSummaryPreference.onBindViewHolder(mHolder);
|
||||
mUsageTitle = (TextView) mHolder.findViewById(R.id.usage_title);
|
||||
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);
|
||||
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);
|
||||
|
Reference in New Issue
Block a user