Unify data/power layout, confirm disable, round.

Share consistent layout between data usage and battery usage.  Show
confirmation dialog before disabling mobile data.  Round warning/limit
sweep values to match displayed label.  Suppress fade when switching
data usage tabs.

Bug: 5208510, 5058157, 5038589, 5252816
Change-Id: I3c76f3397445d2d3b173666a41672871df4c61af
This commit is contained in:
Jeff Sharkey
2011-09-02 16:10:24 -07:00
parent 4e658ba969
commit 28130d9638
12 changed files with 151 additions and 212 deletions

View File

@@ -35,8 +35,11 @@ public interface ChartAxis {
/** Convert screen point into raw value. */
public long convertToValue(float point);
/** Build label that describes given raw value. */
public void buildLabel(Resources res, SpannableStringBuilder builder, long value);
/**
* Build label that describes given raw value. If the label is rounded for
* display, return the rounded value.
*/
public long buildLabel(Resources res, SpannableStringBuilder builder, long value);
/** Return list of tick points for drawing a grid. */
public float[] getTickPoints();

View File

@@ -27,7 +27,6 @@ import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
@@ -334,11 +333,11 @@ public class ChartDataUsageView extends ChartView {
}
public long getWarningBytes() {
return mSweepWarning.getValue();
return mSweepWarning.getLabelValue();
}
public long getLimitBytes() {
return mSweepLimit.getValue();
return mSweepLimit.getLabelValue();
}
private long getStatsStart() {
@@ -433,9 +432,10 @@ public class ChartDataUsageView extends ChartView {
}
/** {@inheritDoc} */
public void buildLabel(Resources res, SpannableStringBuilder builder, long value) {
public long buildLabel(Resources res, SpannableStringBuilder builder, long value) {
// TODO: convert to better string
builder.replace(0, builder.length(), Long.toString(value));
return value;
}
/** {@inheritDoc} */
@@ -493,16 +493,19 @@ public class ChartDataUsageView extends ChartView {
private static final Object sSpanUnit = new Object();
/** {@inheritDoc} */
public void buildLabel(Resources res, SpannableStringBuilder builder, long value) {
public long buildLabel(Resources res, SpannableStringBuilder builder, long value) {
float result = value;
final CharSequence unit;
float result = value;
long labelValue = 1;
if (result <= 100 * MB_IN_BYTES) {
unit = res.getText(com.android.internal.R.string.megabyteShort);
result /= MB_IN_BYTES;
labelValue = MB_IN_BYTES;
} else {
unit = res.getText(com.android.internal.R.string.gigabyteShort);
result /= GB_IN_BYTES;
labelValue = GB_IN_BYTES;
}
final CharSequence size;
@@ -511,11 +514,14 @@ public class ChartDataUsageView extends ChartView {
} else {
size = String.format("%.0f", result);
}
labelValue *= Float.parseFloat(size.toString());
final int[] sizeBounds = findOrCreateSpan(builder, sSpanSize, "^1");
builder.replace(sizeBounds[0], sizeBounds[1], size);
final int[] unitBounds = findOrCreateSpan(builder, sSpanUnit, "^2");
builder.replace(unitBounds[0], unitBounds[1], unit);
return labelValue;
}
/** {@inheritDoc} */

View File

@@ -67,6 +67,7 @@ public class ChartSweepView extends View {
private ChartAxis mAxis;
private long mValue;
private long mLabelValue;
private long mValidAfter;
private long mValidBefore;
@@ -226,7 +227,7 @@ public class ChartSweepView extends View {
private void invalidateLabel() {
if (mLabelTemplate != null && mAxis != null) {
mAxis.buildLabel(getResources(), mLabelTemplate, mValue);
mLabelValue = mAxis.buildLabel(getResources(), mLabelTemplate, mValue);
invalidate();
}
}
@@ -265,6 +266,10 @@ public class ChartSweepView extends View {
return mValue;
}
public long getLabelValue() {
return mLabelValue;
}
public float getPoint() {
if (isEnabled()) {
return mAxis.convertToPoint(mValue);

View File

@@ -52,8 +52,8 @@ public class InvertedChartAxis implements ChartAxis {
}
/** {@inheritDoc} */
public void buildLabel(Resources res, SpannableStringBuilder builder, long value) {
mWrapped.buildLabel(res, builder, value);
public long buildLabel(Resources res, SpannableStringBuilder builder, long value) {
return mWrapped.buildLabel(res, builder, value);
}
/** {@inheritDoc} */