summaryrefslogtreecommitdiffstats
path: root/packages/SystemUI/src/com/android/systemui
diff options
context:
space:
mode:
authorJohn Spurlock <jspurlock@google.com>2014-07-08 23:40:46 -0400
committerJohn Spurlock <jspurlock@google.com>2014-07-08 23:50:04 -0400
commit5e9049a362016c9f00823346d619303674f9df0e (patch)
treec0b76c7691c975c92cb96ac733ada7ec10fa091c /packages/SystemUI/src/com/android/systemui
parent0543b17e84f970751d12bf8cd9fb8c8f22b1f52b (diff)
downloadframeworks_base-5e9049a362016c9f00823346d619303674f9df0e.zip
frameworks_base-5e9049a362016c9f00823346d619303674f9df0e.tar.gz
frameworks_base-5e9049a362016c9f00823346d619303674f9df0e.tar.bz2
QS: Add limit to cellular data panel.
Change-Id: I4d69ffe0681b89670d052ed18c5e4be4674d2d62
Diffstat (limited to 'packages/SystemUI/src/com/android/systemui')
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/DataUsageGraph.java42
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/tiles/CellularTile.java36
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/policy/MobileDataController.java24
3 files changed, 93 insertions, 9 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/qs/DataUsageGraph.java b/packages/SystemUI/src/com/android/systemui/qs/DataUsageGraph.java
index 8b1c778..fa11af6 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/DataUsageGraph.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/DataUsageGraph.java
@@ -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);
+ }
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/CellularTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/CellularTile.java
index 9048ee8..1f12b2a 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/CellularTile.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/CellularTile.java
@@ -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;
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/MobileDataController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/MobileDataController.java
index 40549e8..ac9d807 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/MobileDataController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/MobileDataController.java
@@ -25,6 +25,8 @@ import android.content.Context;
import android.net.ConnectivityManager;
import android.net.INetworkStatsService;
import android.net.INetworkStatsSession;
+import android.net.NetworkPolicy;
+import android.net.NetworkPolicyManager;
import android.net.NetworkStatsHistory;
import android.net.NetworkTemplate;
import android.os.RemoteException;
@@ -49,6 +51,7 @@ public class MobileDataController {
private final TelephonyManager mTelephonyManager;
private final ConnectivityManager mConnectivityManager;
private final INetworkStatsService mStatsService;
+ private final NetworkPolicyManager mPolicyManager;
private INetworkStatsSession mSession;
private Callback mCallback;
@@ -59,6 +62,8 @@ public class MobileDataController {
mConnectivityManager = ConnectivityManager.from(context);
mStatsService = INetworkStatsService.Stub.asInterface(
ServiceManager.getService(Context.NETWORK_STATS_SERVICE));
+ mPolicyManager = NetworkPolicyManager.from(mContext);
+
try {
mSession = mStatsService.openSession();
} catch (RemoteException e) {
@@ -85,6 +90,7 @@ public class MobileDataController {
return warn("no stats session");
}
final NetworkTemplate template = NetworkTemplate.buildTemplateMobileAll(subscriberId);
+ final NetworkPolicy policy = findNetworkPolicy(template);
try {
final NetworkStatsHistory history = mSession.getHistoryForNetwork(template, FIELDS);
final long now = System.currentTimeMillis();
@@ -105,12 +111,30 @@ public class MobileDataController {
usage.maxLevel = (long) (totalBytes / .4);
usage.usageLevel = totalBytes;
usage.period = MMM_D.format(new Date(start)) + " - " + MMM_D.format(new Date(end));
+ if (policy != null) {
+ usage.limitLevel = policy.limitBytes > 0 ? policy.limitBytes : 0;
+ usage.warningLevel = policy.warningBytes > 0 ? policy.warningBytes : 0;
+ }
return usage;
} catch (RemoteException e) {
return warn("remote call failed");
}
}
+ private NetworkPolicy findNetworkPolicy(NetworkTemplate template) {
+ if (mPolicyManager == null || template == null) return null;
+ final NetworkPolicy[] policies = mPolicyManager.getNetworkPolicies();
+ if (policies == null) return null;
+ final int N = policies.length;
+ for (int i = 0; i < N; i++) {
+ final NetworkPolicy policy = policies[i];
+ if (policy != null && template.equals(policy.template)) {
+ return policy;
+ }
+ }
+ return null;
+ }
+
private static String historyEntryToString(NetworkStatsHistory.Entry entry) {
return entry == null ? null : new StringBuilder("Entry[")
.append("bucketDuration=").append(entry.bucketDuration)