FileDocCategorySizeDatePackage
DataUsageGraph.javaAPI DocAndroid 5.1 API3611Thu Mar 12 22:22:42 GMT 2015com.android.systemui.qs

DataUsageGraph

public class DataUsageGraph extends android.view.View

Fields Summary
private final int
mTrackColor
private final int
mUsageColor
private final int
mOverlimitColor
private final int
mWarningColor
private final int
mMarkerWidth
private final android.graphics.RectF
mTmpRect
private final android.graphics.Paint
mTmpPaint
private long
mLimitLevel
private long
mWarningLevel
private long
mUsageLevel
private long
mMaxLevel
Constructors Summary
public DataUsageGraph(android.content.Context context, android.util.AttributeSet attrs)


         
        super(context, attrs);
        final Resources res = context.getResources();
        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);
        mWarningColor = res.getColor(R.color.data_usage_graph_warning);
        mMarkerWidth = res.getDimensionPixelSize(R.dimen.data_usage_graph_marker_width);
    
Methods Summary
protected voidonDraw(android.graphics.Canvas canvas)

        super.onDraw(canvas);

        final RectF r = mTmpRect;
        final Paint p = mTmpPaint;
        final int w = getWidth();
        final int h = getHeight();

        final boolean overLimit = mLimitLevel > 0 && mUsageLevel > mLimitLevel;
        float usageRight = w * (mUsageLevel / (float) mMaxLevel);
        if (overLimit) {
            // compute the gap
            usageRight = w * (mLimitLevel / (float) mMaxLevel) - (mMarkerWidth / 2);
            usageRight = Math.min(Math.max(usageRight, mMarkerWidth), w - mMarkerWidth * 2);

            // draw overlimit
            r.set(usageRight + mMarkerWidth, 0, w, h);
            p.setColor(mOverlimitColor);
            canvas.drawRect(r, p);
        } else {
            // draw track
            r.set(0, 0, w, h);
            p.setColor(mTrackColor);
            canvas.drawRect(r, p);
        }

        // draw usage
        r.set(0, 0, usageRight, h);
        p.setColor(mUsageColor);
        canvas.drawRect(r, p);

        // draw warning marker
        float warningLeft = w * (mWarningLevel / (float) mMaxLevel) - mMarkerWidth / 2;
        warningLeft = Math.min(Math.max(warningLeft, 0), w - mMarkerWidth);
        r.set(warningLeft, 0, warningLeft + mMarkerWidth, h);
        p.setColor(mWarningColor);
        canvas.drawRect(r, p);
    
public voidsetLevels(long limitLevel, long warningLevel, long usageLevel)

        mLimitLevel = Math.max(0, limitLevel);
        mWarningLevel = Math.max(0, warningLevel);
        mUsageLevel = Math.max(0, usageLevel);
        mMaxLevel = Math.max(Math.max(Math.max(mLimitLevel, mWarningLevel), mUsageLevel), 1);
        postInvalidate();