Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8a241f64 authored by Jan Nordqvist's avatar Jan Nordqvist Committed by Sundeep Ghuman
Browse files

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
parent d610e516
Loading
Loading
Loading
Loading
+26 −7
Original line number Diff line number Diff line
@@ -35,15 +35,34 @@
        android:textColor="?android:attr/textColorSecondary"
        android:text="@string/data_usage_title" />

    <TextView
        android:id="@android:id/title"
    <LinearLayout
        android:id="@+id/usage_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="12dp"
        android:paddingBottom="4dp"
        android:layout_width="match_parent"
        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"
+1 −1
Original line number Diff line number Diff line
@@ -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>
+7 −2
Original line number Diff line number Diff line
@@ -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()));
    }
+34 −0
Original line number Diff line number Diff line
@@ -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);

+1 −13
Original line number Diff line number Diff line
@@ -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);
Loading