diff options
author | Jeff Sharkey <jsharkey@android.com> | 2011-07-26 19:30:26 -0700 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2011-07-27 21:11:39 -0700 |
commit | d360e5efaaf4ea5f487a84787210a6c5d26337a8 (patch) | |
tree | 722de8ff75229978b1a1002a91e0b97caa6ea392 /src/com/android/settings/widget | |
parent | 271ec8a8f81ab714e45cc8c7814ea3c5dfb3f36a (diff) | |
download | packages_apps_Settings-d360e5efaaf4ea5f487a84787210a6c5d26337a8.zip packages_apps_Settings-d360e5efaaf4ea5f487a84787210a6c5d26337a8.tar.gz packages_apps_Settings-d360e5efaaf4ea5f487a84787210a6c5d26337a8.tar.bz2 |
Data usage fit and finish.
Show time range and data summary based on current sweep selection for
both network and app details. Fix animations by opting-out of parent
hierarchy animation, since it fights with ListView.
Switch to using NPMS "restrict background" instead of overloading
setBackgroundDataSetting(), and hide app background checkbox when
global background is restricted.
Limit sweeps to valid historical data, and activate sweeps on touch
instead of requiring separate tap. Fix z-order and avoid animating
sweeps. Align all elements along vertical edge, and fix item layout
to handle long app title.
Bug: 4979025, 5058107, 5038590, 5079887, 5058108, 5058026, 5037381
Change-Id: Ib45b61ff2a62303f47aa3f47f88d2e688fe4d076
Diffstat (limited to 'src/com/android/settings/widget')
-rw-r--r-- | src/com/android/settings/widget/ChartSweepView.java | 85 | ||||
-rw-r--r-- | src/com/android/settings/widget/DataUsageChartView.java | 51 |
2 files changed, 97 insertions, 39 deletions
diff --git a/src/com/android/settings/widget/ChartSweepView.java b/src/com/android/settings/widget/ChartSweepView.java index 4e37657..99c35bd 100644 --- a/src/com/android/settings/widget/ChartSweepView.java +++ b/src/com/android/settings/widget/ChartSweepView.java @@ -61,8 +61,11 @@ public class ChartSweepView extends FrameLayout { private ChartAxis mAxis; private long mValue; - private ChartSweepView mClampAfter; - private ChartSweepView mClampBefore; + private long mValidAfter; + private long mValidBefore; + private ChartSweepView mValidAfterDynamic; + private ChartSweepView mValidBeforeDynamic; + private long mValidBufferArea; public static final int HORIZONTAL = 0; public static final int VERTICAL = 1; @@ -259,12 +262,25 @@ public class ChartSweepView extends FrameLayout { } } - public void setClampAfter(ChartSweepView clampAfter) { - mClampAfter = clampAfter; + /** + * Set valid range this sweep can move within, in {@link #mAxis} values. The + * most restrictive combination of all valid ranges is used. + */ + public void setValidRange(long validAfter, long validBefore) { + mValidAfter = validAfter; + mValidBefore = validBefore; } - public void setClampBefore(ChartSweepView clampBefore) { - mClampBefore = clampBefore; + /** + * Set valid range this sweep can move within, defined by the given + * {@link ChartSweepView}. The most restrictive combination of all valid + * ranges is used. + */ + public void setValidRangeDynamic( + ChartSweepView validAfter, ChartSweepView validBefore, long bufferArea) { + mValidAfterDynamic = validAfter; + mValidBeforeDynamic = validBefore; + mValidBufferArea = bufferArea; } @Override @@ -285,6 +301,12 @@ public class ChartSweepView extends FrameLayout { if (accept) { mTracking = event.copy(); + + // starting drag should activate entire chart + if (!parent.isActivated()) { + parent.setActivated(true); + } + return true; } else { return false; @@ -336,31 +358,52 @@ public class ChartSweepView extends FrameLayout { } } + @Override + public void addOnLayoutChangeListener(OnLayoutChangeListener listener) { + // ignored to keep LayoutTransition from animating us + } + + @Override + public void removeOnLayoutChangeListener(OnLayoutChangeListener listener) { + // ignored to keep LayoutTransition from animating us + } + + private long getValidAfterValue() { + final ChartSweepView dynamic = mValidAfterDynamic; + final boolean dynamicEnabled = dynamic != null && dynamic.isEnabled(); + return Math.max(mValidAfter, + dynamicEnabled ? dynamic.getValue() + mValidBufferArea : Long.MIN_VALUE); + } + + private long getValidBeforeValue() { + final ChartSweepView dynamic = mValidBeforeDynamic; + final boolean dynamicEnabled = dynamic != null && dynamic.isEnabled(); + return Math.min(mValidBefore, + dynamicEnabled ? dynamic.getValue() - mValidBufferArea : Long.MAX_VALUE); + } + /** * Compute {@link Rect} in {@link #getParent()} coordinates that we should - * be clamped inside of, usually from {@link #setClampAfter(ChartSweepView)} + * be clamped inside of, usually from {@link #setValidRange(long, long)} * style rules. */ private Rect computeClampRect(Rect parentContent) { final Rect clampRect = new Rect(parentContent); - final ChartSweepView after = mClampAfter; - final ChartSweepView before = mClampBefore; + float validAfterPoint = mAxis.convertToPoint(getValidAfterValue()); + float validBeforePoint = mAxis.convertToPoint(getValidBeforeValue()); + if (validAfterPoint > validBeforePoint) { + float swap = validBeforePoint; + validBeforePoint = validAfterPoint; + validAfterPoint = swap; + } if (mFollowAxis == VERTICAL) { - if (after != null) { - clampRect.top += after.getPoint(); - } - if (before != null) { - clampRect.bottom -= clampRect.height() - before.getPoint(); - } + clampRect.bottom = clampRect.top + (int) validBeforePoint; + clampRect.top += validAfterPoint; } else { - if (after != null) { - clampRect.left += after.getPoint(); - } - if (before != null) { - clampRect.right -= clampRect.width() - before.getPoint(); - } + clampRect.right = clampRect.left + (int) validBeforePoint; + clampRect.left += validAfterPoint; } return clampRect; } diff --git a/src/com/android/settings/widget/DataUsageChartView.java b/src/com/android/settings/widget/DataUsageChartView.java index affede0..839171e 100644 --- a/src/com/android/settings/widget/DataUsageChartView.java +++ b/src/com/android/settings/widget/DataUsageChartView.java @@ -16,6 +16,8 @@ package com.android.settings.widget; +import static android.text.format.DateUtils.HOUR_IN_MILLIS; + import android.content.Context; import android.content.res.Resources; import android.net.NetworkPolicy; @@ -47,6 +49,8 @@ public class DataUsageChartView extends ChartView { private ChartNetworkSeriesView mSeries; private ChartNetworkSeriesView mDetailSeries; + private NetworkStatsHistory mHistory; + private ChartSweepView mSweepLeft; private ChartSweepView mSweepRight; private ChartSweepView mSweepWarning; @@ -88,10 +92,14 @@ public class DataUsageChartView extends ChartView { mSweepWarning = (ChartSweepView) findViewById(R.id.sweep_warning); // prevent sweeps from crossing each other - mSweepLeft.setClampBefore(mSweepRight); - mSweepRight.setClampAfter(mSweepLeft); - mSweepLimit.setClampBefore(mSweepWarning); - mSweepWarning.setClampAfter(mSweepLimit); + mSweepLeft.setValidRangeDynamic(null, mSweepRight, HOUR_IN_MILLIS); + mSweepRight.setValidRangeDynamic(mSweepLeft, null, HOUR_IN_MILLIS); + + // TODO: assign these ranges as user changes data axis + mSweepWarning.setValidRange(0L, 5 * GB_IN_BYTES); + mSweepWarning.setValidRangeDynamic(null, mSweepLimit, MB_IN_BYTES); + mSweepLimit.setValidRange(0L, 5 * GB_IN_BYTES); + mSweepLimit.setValidRangeDynamic(mSweepWarning, null, MB_IN_BYTES); mSweepLeft.addOnSweepListener(mSweepListener); mSweepRight.addOnSweepListener(mSweepListener); @@ -116,6 +124,7 @@ public class DataUsageChartView extends ChartView { public void bindNetworkStats(NetworkStatsHistory stats) { mSeries.bindNetworkStats(stats); + mHistory = stats; updatePrimaryRange(); requestLayout(); } @@ -197,15 +206,6 @@ public class DataUsageChartView extends ChartView { } } - @Override - public boolean onInterceptTouchEvent(MotionEvent ev) { - if (!isActivated()) { - return true; - } else { - return super.onInterceptTouchEvent(ev); - } - } - public long getInspectStart() { return mSweepLeft.getValue(); } @@ -222,18 +222,33 @@ public class DataUsageChartView extends ChartView { return mSweepLimit.getValue(); } + private long getStatsStart() { + return mHistory != null ? mHistory.getStart() : Long.MIN_VALUE; + } + + private long getStatsEnd() { + return mHistory != null ? mHistory.getEnd() : Long.MAX_VALUE; + } + /** * Set the exact time range that should be displayed, updating how * {@link ChartNetworkSeriesView} paints. Moves inspection ranges to be the * last "week" of available data, without triggering listener events. */ - public void setVisibleRange(long start, long end, long dataBoundary) { - mHoriz.setBounds(start, end); + public void setVisibleRange(long visibleStart, long visibleEnd) { + mHoriz.setBounds(visibleStart, visibleEnd); + + final long validStart = Math.max(visibleStart, getStatsStart()); + final long validEnd = Math.min(visibleEnd, getStatsEnd()); + + // prevent time sweeps from leaving valid data + mSweepLeft.setValidRange(validStart, validEnd); + mSweepRight.setValidRange(validStart, validEnd); // default sweeps to last week of data - final long halfRange = (end + start) / 2; - final long sweepMax = Math.min(end, dataBoundary); - final long sweepMin = Math.max(start, (sweepMax - DateUtils.WEEK_IN_MILLIS)); + final long halfRange = (visibleEnd + visibleStart) / 2; + final long sweepMax = validEnd; + final long sweepMin = Math.max(visibleStart, (sweepMax - DateUtils.WEEK_IN_MILLIS)); mSweepLeft.setValue(sweepMin); mSweepRight.setValue(sweepMax); |