From 91b4890cc4b6a7f7e545262a5d3316a8b97cb124 Mon Sep 17 00:00:00 2001 From: serso Date: Mon, 19 Sep 2011 17:24:55 +0400 Subject: [PATCH] normalizer added --- .../view/widgets/AbstractRangeSeekBar.java | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/solovyev/android/view/widgets/AbstractRangeSeekBar.java b/src/main/java/org/solovyev/android/view/widgets/AbstractRangeSeekBar.java index 652d4555..29e46d1c 100644 --- a/src/main/java/org/solovyev/android/view/widgets/AbstractRangeSeekBar.java +++ b/src/main/java/org/solovyev/android/view/widgets/AbstractRangeSeekBar.java @@ -15,8 +15,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.solovyev.android.calculator.R; import org.solovyev.common.utils.Converter; -import org.solovyev.common.utils.Interval; -import org.solovyev.common.utils.IntervalImpl; /** * Widget that lets users select a minimum and maximum value on a given numerical range. @@ -135,7 +133,7 @@ public abstract class AbstractRangeSeekBar extends ImageView { * @return The currently selected min value. */ public T getSelectedMinValue() { - return normalizedToValue(normalizedMinValue); + return denormalizeValue(normalizedMinValue); } /** @@ -158,7 +156,7 @@ public abstract class AbstractRangeSeekBar extends ImageView { * @return The currently selected max value. */ public T getSelectedMaxValue() { - return normalizedToValue(normalizedMaxValue); + return denormalizeValue(normalizedMaxValue); } /** @@ -331,7 +329,7 @@ public abstract class AbstractRangeSeekBar extends ImageView { * @return */ @SuppressWarnings("unchecked") - private T normalizedToValue(double normalized) { + private T denormalizeValue(double normalized) { return toTConverter.convert(dMinValue + normalized * (dMaxValue - dMinValue)); } @@ -391,4 +389,28 @@ public abstract class AbstractRangeSeekBar extends ImageView { private static enum Thumb { MIN, MAX } + + private class LinearNormalizer { + + private final double minValue; + private final double maxValue; + + private LinearNormalizer(double minValue, double maxValue) { + this.minValue = minValue; + this.maxValue = maxValue; + } + + double normalize(double value){ + if ((dMaxValue - dMinValue) != 0d) { + return (value - dMinValue) / (dMaxValue - dMinValue); + } else { + return 1d; + } + } + + double denormalize(double value){ + return dMinValue + value * (dMaxValue - dMinValue); + } + + } }