Merge "Data usage label width, locking, Wi-Fi fixes." into ics-mr1
diff --git a/src/com/android/settings/DataUsageSummary.java b/src/com/android/settings/DataUsageSummary.java
index 21e8caa..46d6c65 100644
--- a/src/com/android/settings/DataUsageSummary.java
+++ b/src/com/android/settings/DataUsageSummary.java
@@ -18,6 +18,7 @@
import static android.net.ConnectivityManager.TYPE_ETHERNET;
import static android.net.ConnectivityManager.TYPE_MOBILE;
+import static android.net.ConnectivityManager.TYPE_WIFI;
import static android.net.ConnectivityManager.TYPE_WIMAX;
import static android.net.NetworkPolicy.LIMIT_DISABLED;
import static android.net.NetworkPolicy.WARNING_DISABLED;
@@ -143,7 +144,7 @@
*/
public class DataUsageSummary extends Fragment {
private static final String TAG = "DataUsage";
- private static final boolean LOGD = true;
+ private static final boolean LOGD = false;
// TODO: remove this testing code
private static final boolean TEST_ANIM = false;
@@ -343,6 +344,7 @@
mChart = (ChartDataUsageView) mHeader.findViewById(R.id.chart);
mChart.setListener(mChartListener);
+ mChart.bindNetworkPolicy(null);
{
// bind app detail controls
@@ -430,7 +432,7 @@
mMenuDataRoaming.setChecked(getDataRoaming());
mMenuRestrictBackground = menu.findItem(R.id.data_usage_menu_restrict_background);
- mMenuRestrictBackground.setVisible(!appDetailMode);
+ mMenuRestrictBackground.setVisible(hasMobileRadio(context) && !appDetailMode);
mMenuRestrictBackground.setChecked(getRestrictBackground());
final MenuItem split4g = menu.findItem(R.id.data_usage_menu_split_4g);
@@ -759,7 +761,8 @@
updateDetailData();
if (NetworkPolicyManager.isUidValidForPolicy(context, primaryUid)
- && !getRestrictBackground() && isBandwidthControlEnabled()) {
+ && !getRestrictBackground() && isBandwidthControlEnabled()
+ && hasMobileRadio(context)) {
setPreferenceTitle(mAppRestrictView, R.string.data_usage_app_restrict_background);
if (hasLimitedNetworks()) {
setPreferenceSummary(mAppRestrictView,
@@ -2042,10 +2045,7 @@
final ConnectivityManager conn = (ConnectivityManager) context.getSystemService(
Context.CONNECTIVITY_SERVICE);
-
- // mobile devices should have MOBILE network tracker regardless of
- // connection status.
- return conn.getNetworkInfo(TYPE_MOBILE) != null;
+ return conn.isNetworkSupported(TYPE_MOBILE);
}
/**
@@ -2064,9 +2064,7 @@
final TelephonyManager telephony = (TelephonyManager) context.getSystemService(
Context.TELEPHONY_SERVICE);
- // WiMAX devices should have WiMAX network tracker regardless of
- // connection status.
- final boolean hasWimax = conn.getNetworkInfo(TYPE_WIMAX) != null;
+ final boolean hasWimax = conn.isNetworkSupported(TYPE_WIMAX);
final boolean hasLte = telephony.getLteOnCdmaMode() == Phone.LTE_ON_CDMA_TRUE;
return hasWimax || hasLte;
}
@@ -2079,7 +2077,9 @@
return SystemProperties.get(TEST_RADIOS_PROP).contains("wifi");
}
- return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI);
+ final ConnectivityManager conn = (ConnectivityManager) context.getSystemService(
+ Context.CONNECTIVITY_SERVICE);
+ return conn.isNetworkSupported(TYPE_WIFI);
}
/**
@@ -2092,7 +2092,7 @@
final ConnectivityManager conn = (ConnectivityManager) context.getSystemService(
Context.CONNECTIVITY_SERVICE);
- return conn.getNetworkInfo(TYPE_ETHERNET) != null;
+ return conn.isNetworkSupported(TYPE_ETHERNET);
}
/**
diff --git a/src/com/android/settings/net/UidDetailProvider.java b/src/com/android/settings/net/UidDetailProvider.java
index 0518b0b..57d585b 100644
--- a/src/com/android/settings/net/UidDetailProvider.java
+++ b/src/com/android/settings/net/UidDetailProvider.java
@@ -39,14 +39,14 @@
mUidDetailCache = new SparseArray<UidDetail>();
}
- public void clearCache() {
+ public synchronized void clearCache() {
mUidDetailCache.clear();
}
/**
* Resolve best descriptive label for the given UID.
*/
- public UidDetail getUidDetail(int uid, boolean blocking) {
+ public synchronized UidDetail getUidDetail(int uid, boolean blocking) {
final UidDetail cached = mUidDetailCache.get(uid);
if (cached != null) {
return cached;
diff --git a/src/com/android/settings/widget/ChartSweepView.java b/src/com/android/settings/widget/ChartSweepView.java
index c5f2aba..68676d8 100644
--- a/src/com/android/settings/widget/ChartSweepView.java
+++ b/src/com/android/settings/widget/ChartSweepView.java
@@ -26,6 +26,7 @@
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.text.DynamicLayout;
+import android.text.Layout;
import android.text.Layout.Alignment;
import android.text.SpannableStringBuilder;
import android.text.TextPaint;
@@ -60,7 +61,9 @@
private int mFollowAxis;
- private int mLabelSize;
+ private int mLabelMinSize;
+ private float mLabelSize;
+
private int mLabelTemplateRes;
private int mLabelColor;
@@ -89,6 +92,8 @@
private static final int MODE_DRAG = 1;
private static final int MODE_LABEL = 2;
+ private static final int LARGE_WIDTH = 1024;
+
private long mDragInterval = 1;
public interface OnSweepListener {
@@ -121,7 +126,7 @@
setFollowAxis(a.getInt(R.styleable.ChartSweepView_followAxis, -1));
setNeighborMargin(a.getDimensionPixelSize(R.styleable.ChartSweepView_neighborMargin, 0));
- setLabelSize(a.getDimensionPixelSize(R.styleable.ChartSweepView_labelSize, 0));
+ setLabelMinSize(a.getDimensionPixelSize(R.styleable.ChartSweepView_labelSize, 0));
setLabelTemplate(a.getResourceId(R.styleable.ChartSweepView_labelTemplate, 0));
setLabelColor(a.getColor(R.styleable.ChartSweepView_labelColor, Color.BLUE));
@@ -231,8 +236,8 @@
mFollowAxis = followAxis;
}
- public void setLabelSize(int size) {
- mLabelSize = size;
+ public void setLabelMinSize(int minSize) {
+ mLabelMinSize = minSize;
invalidateLabelTemplate();
}
@@ -258,7 +263,7 @@
mLabelTemplate = new SpannableStringBuilder(template);
mLabelLayout = new DynamicLayout(
- mLabelTemplate, paint, mLabelSize, Alignment.ALIGN_RIGHT, 1f, 0f, false);
+ mLabelTemplate, paint, LARGE_WIDTH, Alignment.ALIGN_RIGHT, 1f, 0f, false);
invalidateLabel();
} else {
@@ -289,20 +294,26 @@
float labelOffset = 0;
if (mFollowAxis == VERTICAL) {
if (mValidAfterDynamic != null) {
+ mLabelSize = Math.max(getLabelWidth(this), getLabelWidth(mValidAfterDynamic));
margin = getLabelTop(mValidAfterDynamic) - getLabelBottom(this);
if (margin < 0) {
labelOffset = margin / 2;
}
} else if (mValidBeforeDynamic != null) {
+ mLabelSize = Math.max(getLabelWidth(this), getLabelWidth(mValidBeforeDynamic));
margin = getLabelTop(this) - getLabelBottom(mValidBeforeDynamic);
if (margin < 0) {
labelOffset = -margin / 2;
}
+ } else {
+ mLabelSize = getLabelWidth(this);
}
} else {
// TODO: implement horizontal labels
}
+ mLabelSize = Math.max(mLabelSize, mLabelMinSize);
+
// when offsetting label, neighbor probably needs to offset too
if (labelOffset != mLabelOffset) {
mLabelOffset = labelOffset;
@@ -692,11 +703,13 @@
if (isEnabled() && mLabelLayout != null) {
final int count = canvas.save();
{
- canvas.translate(mContentOffset.left, mContentOffset.top + mLabelOffset);
+ final float alignOffset = mLabelSize - LARGE_WIDTH;
+ canvas.translate(
+ mContentOffset.left + alignOffset, mContentOffset.top + mLabelOffset);
mLabelLayout.draw(canvas);
}
canvas.restoreToCount(count);
- labelSize = mLabelSize;
+ labelSize = (int) mLabelSize;
} else {
labelSize = 0;
}
@@ -724,4 +737,8 @@
public static float getLabelBottom(ChartSweepView view) {
return getLabelTop(view) + view.mLabelLayout.getHeight();
}
+
+ public static float getLabelWidth(ChartSweepView view) {
+ return Layout.getDesiredWidth(view.mLabelLayout.getText(), view.mLabelLayout.getPaint());
+ }
}