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

Commit 5e9049a3 authored by John Spurlock's avatar John Spurlock
Browse files

QS: Add limit to cellular data panel.

Change-Id: I4d69ffe0681b89670d052ed18c5e4be4674d2d62
parent 0543b17e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@
    <color name="system_primary_color">#ff263238</color>
    <color name="system_secondary_color">#ff384248</color>
    <color name="system_accent_color">#ff80CBC4</color><!-- deep teal 200 -->
    <color name="system_error_color">#fff0592b</color>
    <color name="system_warning_color">#fff4511e</color><!-- deep orange 600 -->
    <color name="qs_tile_divider">#29ffffff</color><!-- 16% white -->
    <color name="qs_tile_text">#B3FFFFFF</color><!-- 70% white -->
    <color name="qs_subhead">#66FFFFFF</color><!-- 40% white -->
+1 −0
Original line number Diff line number Diff line
@@ -326,4 +326,5 @@
    <!-- The thickness of the colored border around the current user. -->
    <dimen name="keyguard_user_switcher_border_thickness">2dp</dimen>

    <dimen name="data_usage_graph_marker_width">4dp</dimen>
</resources>
+8 −0
Original line number Diff line number Diff line
@@ -550,6 +550,14 @@
    <string name="quick_settings_cellular_detail_title">Cellular data</string>
    <!-- QuickSettings: Cellular detail panel, data usage title [CHAR LIMIT=NONE] -->
    <string name="quick_settings_cellular_detail_data_usage">Data usage</string>
    <!-- QuickSettings: Cellular detail panel, remaining data title [CHAR LIMIT=NONE] -->
    <string name="quick_settings_cellular_detail_remaining_data">Remaining data</string>
    <!-- QuickSettings: Cellular detail panel, over limit title [CHAR LIMIT=NONE] -->
    <string name="quick_settings_cellular_detail_over_limit">Over limit</string>
    <!-- QuickSettings: Cellular detail panel, data used format string [CHAR LIMIT=NONE] -->
    <string name="quick_settings_cellular_detail_data_used"><xliff:g id="data_used" example="2.0 GB">%s</xliff:g> used</string>
    <!-- QuickSettings: Cellular detail panel, data limit format string [CHAR LIMIT=NONE] -->
    <string name="quick_settings_cellular_detail_data_limit"><xliff:g id="data_limit" example="2.0 GB">%s</xliff:g> limit</string>

    <!-- Recents: The empty recents string. [CHAR LIMIT=NONE] -->
    <string name="recents_empty_message">No recent apps</string>
+37 −5
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.qs;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
@@ -28,7 +29,10 @@ import com.android.systemui.R;
public class DataUsageGraph extends View {

    private final int mBackgroundColor;
    private final int mTrackColor;
    private final int mUsageColor;
    private final int mOverlimitColor;
    private final int mMarkerWidth;
    private final RectF mTmpRect = new RectF();
    private final Paint mTmpPaint = new Paint();

@@ -39,8 +43,12 @@ public class DataUsageGraph extends View {

    public DataUsageGraph(Context context, AttributeSet attrs) {
        super(context, attrs);
        mBackgroundColor = context.getResources().getColor(R.color.data_usage_graph_track);
        mUsageColor = context.getResources().getColor(R.color.system_accent_color);
        final Resources res = context.getResources();
        mBackgroundColor = res.getColor(R.color.system_primary_color);
        mTrackColor = res.getColor(R.color.data_usage_graph_track);
        mUsageColor = res.getColor(R.color.system_accent_color);
        mOverlimitColor = res.getColor(R.color.system_warning_color);
        mMarkerWidth = res.getDimensionPixelSize(R.dimen.data_usage_graph_marker_width);
    }

    public void setLevels(long maxLevel, long limitLevel, long warningLevel, long usageLevel) {
@@ -60,14 +68,38 @@ public class DataUsageGraph extends View {
        final int w = getWidth();
        final int h = getHeight();

        // draw background
        // draw track
        r.set(0, 0, w, h);
        p.setColor(mBackgroundColor);
        p.setColor(mTrackColor);
        canvas.drawRect(r, p);

        final boolean hasLimit = mLimitLevel > 0;
        final boolean overLimit = hasLimit && mUsageLevel > mLimitLevel;

        final long maxLevel = hasLimit ? Math.max(mUsageLevel, mLimitLevel) : mMaxLevel;
        final long usageLevel = hasLimit ? Math.min(mUsageLevel, mLimitLevel) : mUsageLevel;
        float usageRight = w * (usageLevel / (float) maxLevel);
        if (overLimit) {
            usageRight -= (mMarkerWidth / 2);
            usageRight = Math.min(usageRight, w - mMarkerWidth * 2);
            usageRight = Math.max(usageRight, mMarkerWidth);
        }

        // draw usage
        r.set(0, 0, w * mUsageLevel / (float) mMaxLevel, h);
        r.set(0, 0, usageRight, h);
        p.setColor(mUsageColor);
        canvas.drawRect(r, p);

        if (overLimit) {
            // draw gap
            r.set(usageRight, 0, usageRight + mMarkerWidth, h);
            p.setColor(mBackgroundColor);
            canvas.drawRect(r, p);

            // draw overlimit
            r.set(usageRight + mMarkerWidth, 0, w, h);
            p.setColor(mOverlimitColor);
            canvas.drawRect(r, p);
        }
    }
}
+32 −4
Original line number Diff line number Diff line
@@ -215,10 +215,36 @@ public class CellularTile extends QSTile<QSTile.SignalState> {
                    .inflate(R.layout.data_usage, parent, false);
            final DataUsageInfo info = mController.getDataUsageInfo();
            if (info == null) return v;
            final Resources res = mContext.getResources();
            int titleId;
            long bytes;
            int usageColor = R.color.system_accent_color;
            String top = null, bottom = null;
            if (info.limitLevel <= 0) { // no limit
                titleId = R.string.quick_settings_cellular_detail_data_usage;
                bytes = info.usageLevel;
            } else if (info.usageLevel <= info.limitLevel) { // under limit
                titleId = R.string.quick_settings_cellular_detail_remaining_data;
                bytes = info.limitLevel - info.usageLevel;
                top = res.getString(R.string.quick_settings_cellular_detail_data_used,
                        formatBytes(info.usageLevel));
                bottom = res.getString(R.string.quick_settings_cellular_detail_data_limit,
                        formatBytes(info.limitLevel));
            } else { // over limit
                titleId = R.string.quick_settings_cellular_detail_over_limit;
                bytes = info.usageLevel - info.limitLevel;
                top = res.getString(R.string.quick_settings_cellular_detail_data_used,
                        formatBytes(info.usageLevel));
                bottom = res.getString(R.string.quick_settings_cellular_detail_data_limit,
                        formatBytes(info.limitLevel));
                usageColor = R.color.system_warning_color;
            }

            final TextView title = (TextView) v.findViewById(android.R.id.title);
            title.setText(R.string.quick_settings_cellular_detail_data_usage);
            title.setText(titleId);
            final TextView usage = (TextView) v.findViewById(R.id.usage_text);
            usage.setText(formatBytes(info.usageLevel));
            usage.setText(formatBytes(bytes));
            usage.setTextColor(res.getColor(usageColor));
            final DataUsageGraph graph = (DataUsageGraph) v.findViewById(R.id.usage_graph);
            graph.setLevels(info.maxLevel, info.limitLevel, info.warningLevel, info.usageLevel);
            final TextView carrier = (TextView) v.findViewById(R.id.usage_carrier_text);
@@ -226,9 +252,11 @@ public class CellularTile extends QSTile<QSTile.SignalState> {
            final TextView period = (TextView) v.findViewById(R.id.usage_period_text);
            period.setText(info.period);
            final TextView infoTop = (TextView) v.findViewById(R.id.usage_info_top_text);
            // TODO
            infoTop.setVisibility(top != null ? View.VISIBLE : View.GONE);
            infoTop.setText(top);
            final TextView infoBottom = (TextView) v.findViewById(R.id.usage_info_bottom_text);
            // TODO
            infoBottom.setVisibility(bottom != null ? View.VISIBLE : View.GONE);
            infoBottom.setText(bottom);
            return v;
        }

Loading