From ddd18dc8d5bfe6e9e64f0a4608ab4e170951bf4f Mon Sep 17 00:00:00 2001 From: Sergey Solovyev Date: Thu, 22 Sep 2011 11:08:27 +0400 Subject: [PATCH] fixes for prefs --- res/values/default_values.xml | 2 +- res/xml/preferences.xml | 14 +++++++------- .../android/calculator/CalculatorActivity.java | 17 +++++++++-------- .../DragButtonCalibrationActivity.java | 11 ++++++++--- .../solovyev/common/AbstractIntervalMapper.java | 2 ++ 5 files changed, 27 insertions(+), 19 deletions(-) diff --git a/res/values/default_values.xml b/res/values/default_values.xml index fdac1def..751c789c 100644 --- a/res/values/default_values.xml +++ b/res/values/default_values.xml @@ -9,7 +9,7 @@ org.solovyev.android.calculator.DragButtonCalibrationActivity_distance 15;350 org.solovyev.android.calculator.DragButtonCalibrationActivity_angle - 130;180 + 0;45 org.solovyev.android.calculator.DragButtonCalibrationActivity_duration 40;2500 \ No newline at end of file diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index bd3f65d8..1d426216 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -13,26 +13,26 @@ a:max="60"/> - - - + a:defaultValue="0;45" + range:boundaries="0;45"/> diff --git a/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java b/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java index 45b71ff6..be0ad54d 100644 --- a/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java +++ b/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java @@ -6,10 +6,7 @@ package org.solovyev.android.calculator; import android.app.Activity; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; +import android.content.*; import android.os.Bundle; import android.text.ClipboardManager; import android.util.Log; @@ -20,7 +17,7 @@ import android.widget.TextView; import bsh.EvalError; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.solovyev.android.view.*; +import org.solovyev.android.view.FontSizeAdjuster; import org.solovyev.android.view.widgets.*; import org.solovyev.common.utils.Announcer; import org.solovyev.common.utils.history.HistoryAction; @@ -28,7 +25,7 @@ import org.solovyev.common.utils.history.HistoryAction; import java.lang.reflect.Field; import java.lang.reflect.Modifier; -public class CalculatorActivity extends Activity implements FontSizeAdjuster { +public class CalculatorActivity extends Activity implements FontSizeAdjuster, SharedPreferences.OnSharedPreferenceChangeListener { private static final int HVGA_WIDTH_PIXELS = 320; @@ -99,8 +96,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster { public void onReceive(Context context, Intent intent) { if (DragButtonCalibrationActivity.INTENT_ACTION.equals(intent.getAction())) { - final DragButtonCalibrationActivity.Preferences preferences = DragButtonCalibrationActivity.getPreferences(CalculatorActivity.this); - dpclRegister.announce().onDragPreferencesChange(preferences); + dpclRegister.announce().onDragPreferencesChange(DragButtonCalibrationActivity.getPreferences(CalculatorActivity.this)); } } }; @@ -233,4 +229,9 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster { float ratio = (float) h / HVGA_WIDTH_PIXELS; view.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontPixelSize * ratio); } + + @Override + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) { + dpclRegister.announce().onDragPreferencesChange(DragButtonCalibrationActivity.getPreferences(CalculatorActivity.this)); + } } \ No newline at end of file diff --git a/src/main/java/org/solovyev/android/calculator/DragButtonCalibrationActivity.java b/src/main/java/org/solovyev/android/calculator/DragButtonCalibrationActivity.java index 07b58e1e..c2d5996d 100644 --- a/src/main/java/org/solovyev/android/calculator/DragButtonCalibrationActivity.java +++ b/src/main/java/org/solovyev/android/calculator/DragButtonCalibrationActivity.java @@ -248,12 +248,17 @@ 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 ) { + if (preferenceType == PreferenceType.angle) { final Float leftBorder = interval.getLeftBorder(); final Float rightBorder = interval.getRightBorder(); - interval.setLeftBorder(180f - rightBorder); - interval.setRightBorder(180f - leftBorder); + if (dragDirection == DragDirection.up) { + interval.setLeftBorder(180f - rightBorder); + interval.setRightBorder(180f - leftBorder); + } else if (dragDirection == DragDirection.left || dragDirection == DragDirection.right) { + interval.setLeftBorder(90f - rightBorder / 2); + interval.setRightBorder(90f + leftBorder / 2); + } } return interval; diff --git a/src/main/java/org/solovyev/common/AbstractIntervalMapper.java b/src/main/java/org/solovyev/common/AbstractIntervalMapper.java index bad45364..de6b880b 100644 --- a/src/main/java/org/solovyev/common/AbstractIntervalMapper.java +++ b/src/main/java/org/solovyev/common/AbstractIntervalMapper.java @@ -6,6 +6,7 @@ package org.solovyev.common; +import android.util.Log; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.solovyev.common.utils.*; @@ -34,6 +35,7 @@ public abstract class AbstractIntervalMapper implements Mapper> { @Override public Interval parseValue(@Nullable String s) throws IllegalArgumentException { + Log.d(AbstractIntervalMapper.class.getName(), "Parsing: " + s); final List list = CollectionsUtils.split(s, ";", getParser()); assert list.size() == 2;