diff options
author | Jeff Sharkey <jsharkey@android.com> | 2011-07-10 12:23:55 -0700 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2011-07-10 12:23:55 -0700 |
commit | 4ec71e79efdb4250f8971eadf195a5ad826cb457 (patch) | |
tree | 9d2804ad06e017c879f404ee68b18a1c69e8abad /src/com/android/settings/widget | |
parent | 9fab0da184b07f7a355909d84429a8ea41985e74 (diff) | |
download | packages_apps_Settings-4ec71e79efdb4250f8971eadf195a5ad826cb457.tar.gz packages_apps_Settings-4ec71e79efdb4250f8971eadf195a5ad826cb457.tar.bz2 packages_apps_Settings-4ec71e79efdb4250f8971eadf195a5ad826cb457.zip |
Prevent data usage chart sweeps from crossing.
Add rules to clamp sweeps, since it doesn't make sense to have a
limit below warning.
Bug: 4598462
Change-Id: I3323c7bca7fabe3e3f1e9c89906c3a921103579c
Diffstat (limited to 'src/com/android/settings/widget')
-rw-r--r-- | src/com/android/settings/widget/ChartSweepView.java | 45 | ||||
-rw-r--r-- | src/com/android/settings/widget/DataUsageChartView.java | 6 |
2 files changed, 49 insertions, 2 deletions
diff --git a/src/com/android/settings/widget/ChartSweepView.java b/src/com/android/settings/widget/ChartSweepView.java index b0d00bb89..4e3765766 100644 --- a/src/com/android/settings/widget/ChartSweepView.java +++ b/src/com/android/settings/widget/ChartSweepView.java @@ -61,6 +61,9 @@ public class ChartSweepView extends FrameLayout { private ChartAxis mAxis; private long mValue; + private ChartSweepView mClampAfter; + private ChartSweepView mClampBefore; + public static final int HORIZONTAL = 0; public static final int VERTICAL = 1; @@ -256,6 +259,14 @@ public class ChartSweepView extends FrameLayout { } } + public void setClampAfter(ChartSweepView clampAfter) { + mClampAfter = clampAfter; + } + + public void setClampBefore(ChartSweepView clampBefore) { + mClampBefore = clampBefore; + } + @Override public boolean onTouchEvent(MotionEvent event) { if (!isEnabled()) return false; @@ -286,13 +297,14 @@ public class ChartSweepView extends FrameLayout { final Rect parentContent = new Rect(parent.getPaddingLeft(), parent.getPaddingTop(), parent.getWidth() - parent.getPaddingRight(), parent.getHeight() - parent.getPaddingBottom()); + final Rect clampRect = computeClampRect(parentContent); if (mFollowAxis == VERTICAL) { final float currentTargetY = getTop() - mMargins.top; final float requestedTargetY = currentTargetY + (event.getRawY() - mTracking.getRawY()); final float clampedTargetY = MathUtils.constrain( - requestedTargetY, parentContent.top, parentContent.bottom); + requestedTargetY, clampRect.top, clampRect.bottom); setTranslationY(clampedTargetY - currentTargetY); setValue(mAxis.convertToValue(clampedTargetY - parentContent.top)); @@ -301,7 +313,7 @@ public class ChartSweepView extends FrameLayout { final float requestedTargetX = currentTargetX + (event.getRawX() - mTracking.getRawX()); final float clampedTargetX = MathUtils.constrain( - requestedTargetX, parentContent.left, parentContent.right); + requestedTargetX, clampRect.left, clampRect.right); setTranslationX(clampedTargetX - currentTargetX); setValue(mAxis.convertToValue(clampedTargetX - parentContent.left)); @@ -324,6 +336,35 @@ public class ChartSweepView extends FrameLayout { } } + /** + * Compute {@link Rect} in {@link #getParent()} coordinates that we should + * be clamped inside of, usually from {@link #setClampAfter(ChartSweepView)} + * style rules. + */ + private Rect computeClampRect(Rect parentContent) { + final Rect clampRect = new Rect(parentContent); + + final ChartSweepView after = mClampAfter; + final ChartSweepView before = mClampBefore; + + if (mFollowAxis == VERTICAL) { + if (after != null) { + clampRect.top += after.getPoint(); + } + if (before != null) { + clampRect.bottom -= clampRect.height() - before.getPoint(); + } + } else { + if (after != null) { + clampRect.left += after.getPoint(); + } + if (before != null) { + clampRect.right -= clampRect.width() - before.getPoint(); + } + } + return clampRect; + } + @Override protected void drawableStateChanged() { super.drawableStateChanged(); diff --git a/src/com/android/settings/widget/DataUsageChartView.java b/src/com/android/settings/widget/DataUsageChartView.java index 89caef17e..88f0a198a 100644 --- a/src/com/android/settings/widget/DataUsageChartView.java +++ b/src/com/android/settings/widget/DataUsageChartView.java @@ -87,6 +87,12 @@ public class DataUsageChartView extends ChartView { mSweepLimit = (ChartSweepView) findViewById(R.id.sweep_limit); 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.addOnSweepListener(mSweepListener); mSweepRight.addOnSweepListener(mSweepListener); mSweepWarning.addOnSweepListener(mWarningListener); |