diff --git a/res/values-ru/strings.xml b/res/values-ru/strings.xml
index cdb22f0e..dc32f56c 100644
--- a/res/values-ru/strings.xml
+++ b/res/values-ru/strings.xml
@@ -107,7 +107,14 @@
Калькулятор
Устанавливает раскладку кнопок
- Тактильный ввод
+ Отклик на нажатие
Включает/выключает вибрацию по нажатию клавиши
+ Маленькая
+ Средняя
+ Большая
+
+ Длительность отклика
+ Длительность вибрации по нажатию клавиши
+
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index 19744b9e..3e88a0d8 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -36,4 +36,15 @@
- main_calculator
+
+ - @string/p_calc_haptic_feedback_strength_short
+ - @string/p_calc_haptic_feedback_strength_middle
+ - @string/p_calc_haptic_feedback_strength_long
+
+
+ - 30
+ - 60
+ - 100
+
+
\ No newline at end of file
diff --git a/res/values/default_values.xml b/res/values/default_values.xml
index eea88c45..80035004 100644
--- a/res/values/default_values.xml
+++ b/res/values/default_values.xml
@@ -34,6 +34,9 @@
main_calculator
org.solovyev.android.calculator.CalculatorActivity_calc_grouping_separator
-
+ " "
+
+ org.solovyev.android.calculator.CalculatorActivity_calc_haptic_feedback_duration_key
+ " "
\ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index d7fcd38c..30136621 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -111,4 +111,11 @@
Haptic feedback
Toggles vibration on button click
+ Short
+ Middle
+ Long
+
+ Haptic feedback duration
+ Duration vibration on button click
+
diff --git a/res/xml/main_preferences.xml b/res/xml/main_preferences.xml
index e8cce53f..14adcc94 100644
--- a/res/xml/main_preferences.xml
+++ b/res/xml/main_preferences.xml
@@ -40,6 +40,12 @@
a:title="@string/c_calc_haptic_feedback_title"
a:defaultValue="false"/>
+
+
mapper = new NumberMapper(Long.class);
+
+ private static final long defaultVibrationTime = 100;
+
+ private final float vibrationTimeScale;
@Nullable
private final Vibrator vibrator;
private long time = 0;
- public VibratorContainer(@Nullable Vibrator vibrator, @NotNull SharedPreferences preferences, long defaultVibrationTime) {
+ public VibratorContainer(@Nullable Vibrator vibrator, @NotNull SharedPreferences preferences, float vibrationTimeScale) {
this.vibrator = vibrator;
- this.defaultVibrationTime = defaultVibrationTime;
+ this.vibrationTimeScale = vibrationTimeScale;
preferences.registerOnSharedPreferenceChangeListener(this);
onSharedPreferenceChanged(preferences, null);
@@ -44,10 +50,15 @@ public class VibratorContainer implements SharedPreferences.OnSharedPreferenceCh
@Override
public void onSharedPreferenceChanged(SharedPreferences preferences, @Nullable String key) {
- if (preferences.getBoolean(HAPTIC_FEEDBACK_PREFERENCE, false)) {
- this.time = defaultVibrationTime;
+ if (preferences.getBoolean(HAPTIC_FEEDBACK_P_KEY, false)) {
+ //noinspection ConstantConditions
+ this.time = getScaledValue(mapper.parseValue(preferences.getString(HAPTIC_FEEDBACK_DURATION_P_KEY, mapper.formatValue(getScaledValue(defaultVibrationTime)))));
} else {
this.time = 0;
}
}
+
+ private long getScaledValue(long vibrationTime) {
+ return (long) (vibrationTime * vibrationTimeScale);
+ }
}
diff --git a/src/main/java/org/solovyev/common/NumberParser.java b/src/main/java/org/solovyev/common/NumberParser.java
index ce4bdb33..9cb7de97 100644
--- a/src/main/java/org/solovyev/common/NumberParser.java
+++ b/src/main/java/org/solovyev/common/NumberParser.java
@@ -33,6 +33,8 @@ public class NumberParser implements Parser {
result = (T) Integer.valueOf(value);
} else if (this.clazz.equals(Float.class)) {
result = (T) Float.valueOf(value);
+ } else if (this.clazz.equals(Long.class)) {
+ result = (T) Long.valueOf(value);
} else {
throw new UnsupportedOperationException(this.clazz + " is not supported!");
}