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

Commit 437d421e authored by Sundeep Ghuman's avatar Sundeep Ghuman Committed by Android (Google) Code Review
Browse files

Merge changes Icf6fafe9,I35eb3f0c,Ieec0c486,I8accb164 into pi-dev

* changes:
  Set color of update line to red if update is older than six hours.
  In Data Usage screen, Below the data bar, Add “X days left” field.
  In Data Usage screen, add over-limit state.
  Change text layout of data usage string.
parents 3618f68c 9a65e5fe
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"
+16 −4
Original line number Diff line number Diff line
@@ -8745,14 +8745,26 @@
    <!-- Data usage title text [CHAR LIMIT=30] -->
    <string name="data_usage_title">Primary data</string>
    <!-- Data usage string [CHAR LIMIT=30] -->
    <!-- Data usage remaining string [CHAR LIMIT=30] -->
    <string name="data_used"><xliff:g name="bytes" example="2 GB">^1</xliff:g> used</string>
    <!-- Data usage over limit string [CHAR LIMIT=30] -->
    <string name="data_overusage"><xliff:g name="bytes" example="2 GB">^1</xliff:g> over</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=60] -->
    <string name="cycle_left_multiple_days"><xliff:g name="time" example="2d">%d</xliff:g> days left</string>
    <!-- Informational text about time left in billing cycle [CHAR LIMIT=60] -->
    <plurals name="billing_cycle_days_left">
        <item quantity="one">%d day left</item>
        <item quantity="other">%d days left</item>
    </plurals>
    <!-- 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>
    <!-- Informational text about time left in billing cycle [CHAR LIMIT=60] -->
    <string name="billing_cycle_less_than_one_day_left">Less than 1 day left</string>
    <!-- Informational text about carrier and update time [CHAR LIMIT=30] -->
    <string name="carrier_and_update_text">Updated by <xliff:g name="carrier" example="T-mobile">%1$s</xliff:g> <xliff:g name="time" example="3m">%2$s</xliff:g></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()));
    }
+81 −10
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;
@@ -28,19 +29,29 @@ import android.widget.ProgressBar;
import android.widget.TextView;

import com.android.settings.R;
import com.android.settingslib.Utils;
import com.android.settingslib.utils.StringUtil;

import java.util.Objects;
import java.util.concurrent.TimeUnit;

/**
 * Provides a summary of data usage.
 */
public class DataUsageSummaryPreference extends Preference {
    private static final long MILLIS_IN_A_DAY = TimeUnit.DAYS.toMillis(1);
    private static final long WARNING_AGE = TimeUnit.HOURS.toMillis(6L);

    private boolean mChartEnabled = true;
    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 boolean mDefaultTextColorSet;
    private int mDefaultTextColor;
    private int mNumPlans;
    /** The ending time of the billing cycle in milliseconds since epoch. */
    private long mCycleEndTimeMs;
@@ -53,6 +64,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 +115,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,16 +137,15 @@ public class DataUsageSummaryPreference extends Preference {
            holder.findViewById(R.id.label_bar).setVisibility(View.GONE);
        }

        updateDataUsageLabels(holder);

        TextView usageTitle = (TextView) holder.findViewById(R.id.usage_title);
        usageTitle.setVisibility(mNumPlans > 1 ? View.VISIBLE : View.GONE);

        TextView cycleTime = (TextView) holder.findViewById(R.id.cycle_left_time);
        cycleTime.setText(getContext().getString(R.string.cycle_left_time_text,
                StringUtil.formatElapsedTime(getContext(),
                        mCycleEndTimeMs - System.currentTimeMillis(),false /* withSeconds */)));
        updateCycleTimeText(holder);


        TextView carrierInfo = (TextView) holder.findViewById(R.id.carrier_and_update);
        setCarrierInfo(carrierInfo, mCarrierName, mSnapshotTimeMs);
        updateCarrierInfo((TextView) holder.findViewById(R.id.carrier_and_update));

        Button launchButton = (Button) holder.findViewById(R.id.launch_mdp_app_button);
        launchButton.setOnClickListener((view) -> {
@@ -135,18 +163,61 @@ public class DataUsageSummaryPreference extends Preference {
        limitInfo.setText(mLimitInfoText);
    }

    private void setCarrierInfo(TextView carrierInfo, CharSequence carrierName, long updateAge) {
        if (mNumPlans > 0 && updateAge >= 0L) {

    private void updateDataUsageLabels(PreferenceViewHolder holder) {
        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);
            long dataRemaining = mDataplanSize - mDataplanUse;
            if (dataRemaining >= 0) {
                usageRemainingField.setText(
                        TextUtils.expandTemplate(getContext().getText(R.string.data_remaining),
                                Formatter.formatFileSize(getContext(), dataRemaining)));
            } else {
                usageRemainingField.setText(
                        TextUtils.expandTemplate(getContext().getText(R.string.data_overusage),
                                Formatter.formatFileSize(getContext(), -dataRemaining)));
            }
        }
    }

    private void updateCycleTimeText(PreferenceViewHolder holder) {
        float daysLeft =
                ((float) mCycleEndTimeMs - System.currentTimeMillis()) / MILLIS_IN_A_DAY;
        if (daysLeft < 0) {
            daysLeft = 0;
        }

        TextView cycleTime = (TextView) holder.findViewById(R.id.cycle_left_time);
        cycleTime.setText(
                (daysLeft > 0 && daysLeft < 1)
                ? getContext().getString(R.string.billing_cycle_less_than_one_day_left)
                : getContext().getResources().getQuantityString(
                        R.plurals.billing_cycle_days_left, (int) daysLeft, (int) daysLeft));
    }


    private void updateCarrierInfo(TextView carrierInfo) {
        if (mNumPlans > 0 && mSnapshotTimeMs >= 0L) {
            long updateAge = System.currentTimeMillis() - mSnapshotTimeMs;
            carrierInfo.setVisibility(View.VISIBLE);
            if (carrierName != null) {
            if (mCarrierName != null) {
                carrierInfo.setText(getContext().getString(R.string.carrier_and_update_text,
                        carrierName, StringUtil.formatRelativeTime(
                        mCarrierName, StringUtil.formatRelativeTime(
                                getContext(), updateAge, false /* withSeconds */)));
            } else {
                carrierInfo.setText(getContext().getString(R.string.no_carrier_update_text,
                        StringUtil.formatRelativeTime(
                                getContext(), updateAge, false /* withSeconds */)));
            }

            carrierInfo.setTextColor(
                    updateAge <= WARNING_AGE
                    ? Utils.getColorAttr(getContext(), android.R.attr.textColorPrimary)
                    : Utils.getColorAttr(getContext(), android.R.attr.colorError));
        } else {
            carrierInfo.setVisibility(View.GONE);
        }
+2 −14
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);
@@ -231,7 +219,7 @@ public class DataUsageSummaryPreferenceController extends BasePreferenceControll
                    mCycleStart = rule.start.toEpochSecond() * 1000L;
                    mCycleEnd = rule.end.toEpochSecond() * 1000L;
                }
                mSnapshotTime = System.currentTimeMillis() - primaryPlan.getDataUsageTime();
                mSnapshotTime = primaryPlan.getDataUsageTime();
            }
        }
        mManageSubscriptionIntent =
Loading