From fa476ec22876eebc3248e798ab2a6ec96e497651 Mon Sep 17 00:00:00 2001 From: serso Date: Wed, 21 Sep 2011 00:50:58 +0400 Subject: [PATCH] fixes --- .../DragButtonCalibrationActivity.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/solovyev/android/calculator/DragButtonCalibrationActivity.java b/src/main/java/org/solovyev/android/calculator/DragButtonCalibrationActivity.java index c5fa014a..e87e9ae0 100644 --- a/src/main/java/org/solovyev/android/calculator/DragButtonCalibrationActivity.java +++ b/src/main/java/org/solovyev/android/calculator/DragButtonCalibrationActivity.java @@ -202,6 +202,8 @@ public class DragButtonCalibrationActivity extends Activity { for (PreferenceType preferenceType : PreferenceType.values()) { for (DragDirection dragDirection : DragDirection.values()) { + Log.d(DragButtonCalibrationActivity.class.getName(), "Determining drag preference for " + preferenceType + ", " + dragDirection); + final Interval defaultValue; switch (preferenceType) { case angle: @@ -210,7 +212,7 @@ public class DragButtonCalibrationActivity extends Activity { defaultValue = new IntervalImpl(130f, 180f); break; case down: - defaultValue = new IntervalImpl(0f, 50f); + defaultValue = new IntervalImpl(130f, 180f); break; default: defaultValue = new IntervalImpl(0f, 0f); @@ -226,12 +228,17 @@ public class DragButtonCalibrationActivity extends Activity { defaultValue = new IntervalImpl(DEFAULT_VALUE, DEFAULT_VALUE); } - final String value = preferences.getString(getPreferenceId(preferenceType, dragDirection), mapper.formatValue(defaultValue)); + final String preferenceId = getPreferenceId(preferenceType, dragDirection); + final String value = preferences.getString(preferenceId, mapper.formatValue(defaultValue)); + Log.d(DragButtonCalibrationActivity.class.getName(), "For " + preferenceId + " next value found in persistence: " + value); final Interval interval = mapper.parseValue(value); + assert interval != null; + transformInterval(preferenceType, dragDirection, interval); - if (new IntervalImpl(DEFAULT_VALUE, DEFAULT_VALUE).equals(interval)) { - assert interval != null; + if (!new IntervalImpl(DEFAULT_VALUE, DEFAULT_VALUE).equals(interval)) { + Log.d(DragButtonCalibrationActivity.class.getName(), "Preference retrieved from persistence. Preference id: " + preferenceId + ", value: " + interval.toString()); + final DragPreference directionPreference = new DragPreference(dragDirection, interval); Preference preference = result.getPreferencesMap().get(preferenceType); @@ -243,7 +250,7 @@ public class DragButtonCalibrationActivity extends Activity { preference.getDirectionPreferences().put(dragDirection, directionPreference); } else { - Log.e(DragButtonCalibrationActivity.class.getName(), "New preference type added: default preferences should be defined!"); + Log.e(DragButtonCalibrationActivity.class.getName(), "New preference type added: default preferences should be defined. Preference id: " + preferenceId); } } } @@ -254,9 +261,11 @@ public class DragButtonCalibrationActivity extends Activity { @NotNull private static Interval transformInterval(@NotNull PreferenceType preferenceType, @NotNull DragDirection dragDirection, @NotNull Interval interval) { if ( preferenceType == PreferenceType.angle && dragDirection == DragDirection.down ) { - final Interval clone = interval.clone(); - interval.setLeftBorder(180f - clone.getRightBorder()); - interval.setRightBorder(180f - clone.getLeftBorder()); + final Float leftBorder = interval.getLeftBorder(); + final Float rightBorder = interval.getRightBorder(); + + interval.setLeftBorder(180f - rightBorder); + interval.setRightBorder(180f - leftBorder); } return interval;