From 70f4ec953ab233f28a2ed41b17bdfeb653461e19 Mon Sep 17 00:00:00 2001 From: serso Date: Mon, 16 Feb 2015 21:56:45 +0100 Subject: [PATCH] cpp-124: Phone vibrates even if button action is not triggered Vibration is now requested manually from places where needed Fixes #124 --- .../calculator/AndroidCalculatorKeyboard.java | 22 ++++----- .../org/solovyev/android/calculator/App.java | 16 ++++++- .../solovyev/android/calculator/BaseUi.java | 46 +++++++------------ .../android/calculator/CalculatorButtons.java | 11 ++++- .../calculator/CursorDragProcessor.java | 2 + .../calculator/EqualsDragProcessor.java | 2 + .../android/calculator/Preferences.java | 22 +++++---- .../solovyev/android/calculator/Vibrator.java | 42 +++++++++++++++++ .../history/BaseHistoryFragment.java | 5 +- .../history/HistoryDragProcessor.java | 3 ++ .../preferences/PreferencesFragment.java | 8 ---- .../wizard/DragButtonWizardStep.java | 7 +++ .../src/main/res/values-ru/text_strings.xml | 1 + android-app/src/main/res/values/arrays.xml | 6 ++- .../src/main/res/values/preferences.xml | 5 -- .../src/main/res/values/text_strings.xml | 3 +- .../main/res/xml/preferences_appearance.xml | 16 ++----- .../calculator/CalculatorKeyboard.java | 2 +- .../calculator/CalculatorKeyboardImpl.java | 4 +- 19 files changed, 141 insertions(+), 82 deletions(-) create mode 100644 android-app/src/main/java/org/solovyev/android/calculator/Vibrator.java diff --git a/android-app/src/main/java/org/solovyev/android/calculator/AndroidCalculatorKeyboard.java b/android-app/src/main/java/org/solovyev/android/calculator/AndroidCalculatorKeyboard.java index 2c7df587..7493ec63 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/AndroidCalculatorKeyboard.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/AndroidCalculatorKeyboard.java @@ -46,7 +46,8 @@ public class AndroidCalculatorKeyboard implements CalculatorKeyboard { @Nonnull private final Context context; - private VibratorContainer vibrator; + @android.support.annotation.Nullable + private org.solovyev.android.calculator.Vibrator vibrator; public AndroidCalculatorKeyboard(@Nonnull Application application, @Nonnull CalculatorKeyboard calculatorKeyboard) { @@ -55,21 +56,20 @@ public class AndroidCalculatorKeyboard implements CalculatorKeyboard { } @Override - public void buttonPressed(@Nullable String text) { - vibrate(); + public boolean buttonPressed(@Nullable String text) { App.getGa().onButtonPressed(text); - calculatorKeyboard.buttonPressed(text); + final boolean processed = calculatorKeyboard.buttonPressed(text); + if (processed) { + vibrate(); + } + return processed; } private void vibrate() { - if (this.vibrator == null) { - final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); - final Vibrator vibrator = (Vibrator) context.getSystemService(Activity.VIBRATOR_SERVICE); - - this.vibrator = new VibratorContainer(vibrator, preferences, 0.5f); + if (vibrator == null) { + vibrator = App.getVibrator(); } - - this.vibrator.vibrate(); + vibrator.vibrate(); } @Override diff --git a/android-app/src/main/java/org/solovyev/android/calculator/App.java b/android-app/src/main/java/org/solovyev/android/calculator/App.java index 13f66a37..0a701b12 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/App.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/App.java @@ -23,16 +23,19 @@ package org.solovyev.android.calculator; import android.app.Application; +import android.content.Context; import android.content.SharedPreferences; import android.content.res.Configuration; import android.os.Build; import android.preference.PreferenceManager; import android.text.TextUtils; +import android.util.Log; import org.solovyev.android.UiThreadExecutor; import org.solovyev.android.Views; import org.solovyev.android.calculator.ga.Ga; import org.solovyev.android.checkout.*; +import org.solovyev.android.view.VibratorContainer; import org.solovyev.common.listeners.JEvent; import org.solovyev.common.listeners.JEventListener; import org.solovyev.common.listeners.JEventListeners; @@ -41,6 +44,7 @@ import org.solovyev.common.threads.DelayedExecutor; import javax.annotation.Nonnull; import javax.annotation.Nullable; + import java.util.Arrays; import java.util.concurrent.Executor; @@ -98,12 +102,15 @@ public final class App { @Nullable private static Boolean lg = null; + @Nonnull + private static volatile Vibrator vibrator; + private App() { throw new AssertionError(); } /* - ********************************************************************** + ********************************************************************** * * METHODS * @@ -153,7 +160,7 @@ public final class App { }; } App.broadcaster = new CalculatorBroadcaster(application); - + App.vibrator = new Vibrator(application, preferences); App.initialized = true; } else { throw new IllegalStateException("Already initialized!"); @@ -249,4 +256,9 @@ public final class App { public static boolean shouldOpenMenuManually() { return isLg() && Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN; } + + @Nonnull + public static Vibrator getVibrator() { + return vibrator; + } } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/BaseUi.java b/android-app/src/main/java/org/solovyev/android/calculator/BaseUi.java index 162aeb2d..72943256 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/BaseUi.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/BaseUi.java @@ -27,7 +27,6 @@ import android.app.KeyguardManager; import android.content.Context; import android.content.SharedPreferences; import android.graphics.Typeface; -import android.os.Vibrator; import android.preference.PreferenceManager; import android.util.Log; import android.view.MotionEvent; @@ -38,7 +37,6 @@ import org.solovyev.android.calculator.drag.*; import org.solovyev.android.calculator.history.CalculatorHistoryState; import org.solovyev.android.calculator.history.HistoryDragProcessor; import org.solovyev.android.calculator.view.AngleUnitsButton; -import org.solovyev.android.calculator.view.DragListenerVibrator; import org.solovyev.android.calculator.view.LongClickEraser; import org.solovyev.android.calculator.view.NumeralBasesButton; import org.solovyev.android.calculator.view.ViewsCache; @@ -54,15 +52,10 @@ import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple_mobi import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.angleUnit; import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.numeralBase; -/** - * User: serso - * Date: 9/28/12 - * Time: 12:12 AM - */ public abstract class BaseUi implements SharedPreferences.OnSharedPreferenceChangeListener { @Nonnull - private static final List viewIds = new ArrayList(200); + private static final List viewIds = new ArrayList<>(200); @Nonnull protected Preferences.Gui.Layout layout; @@ -73,9 +66,6 @@ public abstract class BaseUi implements SharedPreferences.OnSharedPreferenceChan @Nonnull private String logTag = "CalculatorActivity"; - @Nullable - private Vibrator vibrator; - @Nullable private AngleUnitsButton angleUnitsButton; @@ -92,7 +82,6 @@ public abstract class BaseUi implements SharedPreferences.OnSharedPreferenceChan protected void onCreate(@Nonnull Activity activity) { final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); - vibrator = (Vibrator) activity.getSystemService(Activity.VIBRATOR_SERVICE); layout = Preferences.Gui.layout.getPreferenceNoError(preferences); theme = Preferences.Gui.theme.getPreferenceNoError(preferences); @@ -101,14 +90,11 @@ public abstract class BaseUi implements SharedPreferences.OnSharedPreferenceChan // let's disable locking of screen for monkeyrunner if (CalculatorApplication.isMonkeyRunner(activity)) { final KeyguardManager km = (KeyguardManager) activity.getSystemService(Context.KEYGUARD_SERVICE); + //noinspection deprecation km.newKeyguardLock(activity.getClass().getName()).disableKeyguard(); } } - public void logDebug(@Nonnull String message) { - Log.d(logTag, message); - } - public void logError(@Nonnull String message) { Log.e(logTag, message); } @@ -139,10 +125,10 @@ public abstract class BaseUi implements SharedPreferences.OnSharedPreferenceChan final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); final ViewsCache views = ViewsCache.forView(root); - setOnDragListeners(views, preferences, activity); + setOnDragListeners(views, activity); HistoryDragProcessor historyDragProcessor = new HistoryDragProcessor<>(getCalculator()); - final DragListener historyDragListener = new DragListenerVibrator(newDragListener(historyDragProcessor, activity), vibrator, preferences); + final DragListener historyDragListener = newDragListener(historyDragProcessor, activity); final DragButton historyButton = getButton(views, R.id.cpp_button_history); if (historyButton != null) { historyButton.setOnDragListener(historyDragListener); @@ -150,10 +136,10 @@ public abstract class BaseUi implements SharedPreferences.OnSharedPreferenceChan final DragButton minusButton = getButton(views, R.id.cpp_button_subtraction); if (minusButton != null) { - minusButton.setOnDragListener(new DragListenerVibrator(newDragListener(new MinusButtonDragProcessor(), activity), vibrator, preferences)); + minusButton.setOnDragListener(newDragListener(new OperatorsDragProcessor(), activity)); } - final DragListener toPositionDragListener = new DragListenerVibrator(new SimpleDragListener(new CursorDragProcessor(), activity), vibrator, preferences); + final DragListener toPositionDragListener = new SimpleDragListener(new CursorDragProcessor(), activity); final DragButton rightButton = getButton(views, R.id.cpp_button_right); if (rightButton != null) { @@ -167,12 +153,12 @@ public abstract class BaseUi implements SharedPreferences.OnSharedPreferenceChan final DragButton equalsButton = getButton(views, R.id.cpp_button_equals); if (equalsButton != null) { - equalsButton.setOnDragListener(new DragListenerVibrator(newDragListener(new EqualsDragProcessor(), activity), vibrator, preferences)); + equalsButton.setOnDragListener(newDragListener(new EqualsDragProcessor(), activity)); } angleUnitsButton = getButton(views, R.id.cpp_button_6); if (angleUnitsButton != null) { - angleUnitsButton.setOnDragListener(new DragListenerVibrator(newDragListener(new CalculatorButtons.AngleUnitsChanger(activity), activity), vibrator, preferences)); + angleUnitsButton.setOnDragListener(newDragListener(new CalculatorButtons.AngleUnitsChanger(activity), activity)); } final View eraseButton = getButton(views, R.id.cpp_button_erase); @@ -182,22 +168,22 @@ public abstract class BaseUi implements SharedPreferences.OnSharedPreferenceChan clearButton = getButton(views, R.id.cpp_button_clear); if (clearButton != null) { - clearButton.setOnDragListener(new DragListenerVibrator(newDragListener(new CalculatorButtons.NumeralBasesChanger(activity), activity), vibrator, preferences)); + clearButton.setOnDragListener(newDragListener(new CalculatorButtons.NumeralBasesChanger(activity), activity)); } final DragButton varsButton = getButton(views, R.id.cpp_button_vars); if (varsButton != null) { - varsButton.setOnDragListener(new DragListenerVibrator(newDragListener(new CalculatorButtons.VarsDragProcessor(activity), activity), vibrator, preferences)); + varsButton.setOnDragListener(newDragListener(new CalculatorButtons.VarsDragProcessor(activity), activity)); } final DragButton functionsButton = getButton(views, R.id.cpp_button_functions); if (functionsButton != null) { - functionsButton.setOnDragListener(new DragListenerVibrator(newDragListener(new CalculatorButtons.FunctionsDragProcessor(activity), activity), vibrator, preferences)); + functionsButton.setOnDragListener(newDragListener(new CalculatorButtons.FunctionsDragProcessor(activity), activity)); } final DragButton roundBracketsButton = getButton(views, R.id.cpp_button_round_brackets); if (roundBracketsButton != null) { - roundBracketsButton.setOnDragListener(new DragListenerVibrator(newDragListener(new CalculatorButtons.RoundBracketsDragProcessor(), activity), vibrator, preferences)); + roundBracketsButton.setOnDragListener(newDragListener(new CalculatorButtons.RoundBracketsDragProcessor(), activity)); } if (layout == simple || layout == simple_mobile) { @@ -228,8 +214,8 @@ public abstract class BaseUi implements SharedPreferences.OnSharedPreferenceChan new ButtonOnClickListener().attachToViews(views); } - private void setOnDragListeners(@Nonnull ViewsCache views, @Nonnull SharedPreferences preferences, @Nonnull Context context) { - final DragListener dragListener = new DragListenerVibrator(newDragListener(new DigitButtonDragProcessor(getKeyboard()), context), vibrator, preferences); + private void setOnDragListeners(@Nonnull ViewsCache views, @Nonnull Context context) { + final DragListener dragListener = newDragListener(new DigitButtonDragProcessor(getKeyboard()), context); final List viewIds = getViewIds(); for (Integer viewId : viewIds) { @@ -299,6 +285,7 @@ public abstract class BaseUi implements SharedPreferences.OnSharedPreferenceChan @Nullable private V getButton(@Nonnull ViewsCache views, int buttonId) { + //noinspection unchecked return (V) views.findViewById(buttonId); } @@ -315,10 +302,11 @@ public abstract class BaseUi implements SharedPreferences.OnSharedPreferenceChan } } - private static class MinusButtonDragProcessor implements SimpleDragListener.DragProcessor { + private static class OperatorsDragProcessor implements SimpleDragListener.DragProcessor { @Override public boolean processDragEvent(@Nonnull DragDirection dragDirection, @Nonnull DragButton dragButton, @Nonnull Point2d startPoint2d, @Nonnull MotionEvent motionEvent) { if (dragDirection == DragDirection.down) { + App.getVibrator().vibrate(); Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_operators, null); return true; } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorButtons.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorButtons.java index 2b10327e..cacc9c96 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorButtons.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorButtons.java @@ -118,15 +118,20 @@ public final class CalculatorButtons { */ static class RoundBracketsDragProcessor implements SimpleDragListener.DragProcessor { + + @Nonnull + private final DigitButtonDragProcessor upDownProcessor = new DigitButtonDragProcessor(getKeyboard()); + @Override public boolean processDragEvent(@Nonnull DragDirection dragDirection, @Nonnull DragButton dragButton, @Nonnull Point2d startPoint2d, @Nonnull MotionEvent motionEvent) { final boolean result; if (dragDirection == DragDirection.left) { + App.getVibrator().vibrate(); getKeyboard().roundBracketsButtonPressed(); result = true; } else { - result = new DigitButtonDragProcessor(getKeyboard()).processDragEvent(dragDirection, dragButton, startPoint2d, motionEvent); + result = upDownProcessor.processDragEvent(dragDirection, dragButton, startPoint2d, motionEvent); } return result; @@ -155,6 +160,7 @@ public final class CalculatorButtons { boolean result = false; if (dragDirection == DragDirection.up) { + App.getVibrator().vibrate(); Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_create_var_dialog, null, context); result = true; }/* else if (dragDirection == DragDirection.down) { @@ -198,6 +204,7 @@ public final class CalculatorButtons { final AngleUnit oldAngleUnits = AndroidCalculatorEngine.Preferences.angleUnit.getPreference(preferences); if (oldAngleUnits != angleUnits) { + App.getVibrator().vibrate(); Locator.getInstance().getPreferenceService().setAngleUnits(angleUnits); } @@ -242,6 +249,7 @@ public final class CalculatorButtons { final NumeralBase oldNumeralBase = AndroidCalculatorEngine.Preferences.numeralBase.getPreference(preferences); if (oldNumeralBase != numeralBase) { + App.getVibrator().vibrate(); Locator.getInstance().getPreferenceService().setNumeralBase(numeralBase); } @@ -273,6 +281,7 @@ public final class CalculatorButtons { boolean result = false; if (dragDirection == DragDirection.up) { + App.getVibrator().vibrate(); Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_create_function_dialog, null, context); result = true; } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CursorDragProcessor.java b/android-app/src/main/java/org/solovyev/android/calculator/CursorDragProcessor.java index 4a6c6ea2..89fb3f30 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/CursorDragProcessor.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CursorDragProcessor.java @@ -48,9 +48,11 @@ public class CursorDragProcessor implements SimpleDragListener.DragProcessor { if (dragButton instanceof DirectionDragButton) { String text = ((DirectionDragButton) dragButton).getText(dragDirection); if ("◁◁".equals(text)) { + App.getVibrator().vibrate(); Locator.getInstance().getEditor().setCursorOnStart(); result = true; } else if ("▷▷".equals(text)) { + App.getVibrator().vibrate(); Locator.getInstance().getEditor().setCursorOnEnd(); result = true; } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/EqualsDragProcessor.java b/android-app/src/main/java/org/solovyev/android/calculator/EqualsDragProcessor.java index 5c33d4e6..2ed66dc1 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/EqualsDragProcessor.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/EqualsDragProcessor.java @@ -48,11 +48,13 @@ public class EqualsDragProcessor implements SimpleDragListener.DragProcessor { if (dragButton instanceof DirectionDragButton) { if (dragDirection == DragDirection.down) { + App.getVibrator().vibrate(); CalculatorActivityLauncher.tryPlot(); result = true; } else { final String text = ((DirectionDragButton) dragButton).getText(dragDirection); if ("≡".equals(text)) { + App.getVibrator().vibrate(); Locator.getInstance().getCalculator().simplify(); result = true; } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/Preferences.java b/android-app/src/main/java/org/solovyev/android/calculator/Preferences.java index 88692583..ed17617a 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/Preferences.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/Preferences.java @@ -37,7 +37,6 @@ import org.solovyev.android.calculator.onscreen.CalculatorOnscreenService; import org.solovyev.android.calculator.preferences.PurchaseDialogActivity; import org.solovyev.android.calculator.wizard.WizardActivity; import org.solovyev.android.prefs.*; -import org.solovyev.android.view.VibratorContainer; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -90,6 +89,10 @@ public final class Preferences { public static final Preference hideNumeralBaseDigits = BooleanPreference.of("hideNumeralBaseDigits", true); public static final Preference preventScreenFromFading = BooleanPreference.of("preventScreenFromFading", true); public static final Preference colorDisplay = BooleanPreference.of("org.solovyev.android.calculator.CalculatorModel_color_display", true); + public static final Preference hapticFeedback = NumberToStringPreference.of("hapticFeedback", 60L, Long.class); + + private static final Preference hapticFeedbackEnabled = BooleanPreference.of("org.solovyev.android.calculator.CalculatorModel_haptic_feedback", false); + private static final Preference hapticFeedbackDuration = NumberToStringPreference.of("org.solovyev.android.calculator.CalculatorActivity_calc_haptic_feedback_duration_key", 60L, Long.class); @Nonnull public static Theme getTheme(@Nonnull SharedPreferences preferences) { @@ -286,14 +289,17 @@ public final class Preferences { Calculations.showCalculationMessagesDialog.putDefault(preferences); Calculations.lastPreferredPreferencesCheck.putDefault(preferences); - if (!VibratorContainer.Preferences.hapticFeedbackEnabled.isSet(preferences)) { - VibratorContainer.Preferences.hapticFeedbackEnabled.putPreference(preferences, true); + if (!Gui.hapticFeedback.isSet(preferences)) { + final Preference hfEnabled = Gui.hapticFeedbackEnabled; + final boolean enabled = !hfEnabled.isSet(preferences) ? true : hfEnabled.getPreference(preferences); + if (enabled) { + final Preference hfDuration = Gui.hapticFeedbackDuration; + final long duration = !hfDuration.isSet(preferences) ? 60L : hfDuration.getPreference(preferences); + Gui.hapticFeedback.putPreference(preferences, duration); + } else { + Gui.hapticFeedback.putPreference(preferences, 0L); + } } - - if (!VibratorContainer.Preferences.hapticFeedbackDuration.isSet(preferences)) { - VibratorContainer.Preferences.hapticFeedbackDuration.putPreference(preferences, 60L); - } - } private static void applyDefaultPreference(@Nonnull SharedPreferences preferences, @Nonnull Preference preference) { diff --git a/android-app/src/main/java/org/solovyev/android/calculator/Vibrator.java b/android-app/src/main/java/org/solovyev/android/calculator/Vibrator.java new file mode 100644 index 00000000..b646fa42 --- /dev/null +++ b/android-app/src/main/java/org/solovyev/android/calculator/Vibrator.java @@ -0,0 +1,42 @@ +package org.solovyev.android.calculator; + +import android.content.Context; +import android.content.SharedPreferences; +import android.util.Log; + +import javax.annotation.Nonnull; + +public final class Vibrator implements SharedPreferences.OnSharedPreferenceChangeListener { + + @Nonnull + private final android.os.Vibrator service; + + private long time = 0; + + public Vibrator(@Nonnull Context context, @Nonnull SharedPreferences preferences) { + service = (android.os.Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); + preferences.registerOnSharedPreferenceChangeListener(this); + updateTime(preferences); + } + + private void updateTime(@Nonnull SharedPreferences preferences) { + time = Preferences.Gui.hapticFeedback.getPreference(preferences) / 2; + } + + public void vibrate() { + try { + if (time > 0) { + service.vibrate(time); + } + } catch (SecurityException e) { + Log.e("Vibrator", e.getMessage(), e); + } + } + + @Override + public void onSharedPreferenceChanged(@Nonnull SharedPreferences preferences, String key) { + if (Preferences.Gui.hapticFeedback.isSameKey(key)) { + updateTime(preferences); + } + } +} diff --git a/android-app/src/main/java/org/solovyev/android/calculator/history/BaseHistoryFragment.java b/android-app/src/main/java/org/solovyev/android/calculator/history/BaseHistoryFragment.java index 96f3fea2..fc0ffee9 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/history/BaseHistoryFragment.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/history/BaseHistoryFragment.java @@ -283,6 +283,7 @@ public abstract class BaseHistoryFragment extends ListFragment implements Calcul } public static void useHistoryItem(@Nonnull final CalculatorHistoryState historyState) { + App.getVibrator().vibrate(); Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.use_history_state, historyState); } @@ -292,7 +293,7 @@ public abstract class BaseHistoryFragment extends ListFragment implements Calcul java.util.Collections.sort(calculatorHistoryStates, COMPARATOR); - final FilterRulesChain filterRulesChain = new FilterRulesChain(); + final FilterRulesChain filterRulesChain = new FilterRulesChain<>(); filterRulesChain.addFilterRule(new JPredicate() { @Override public boolean apply(CalculatorHistoryState object) { @@ -300,7 +301,7 @@ public abstract class BaseHistoryFragment extends ListFragment implements Calcul } }); - new Filter(filterRulesChain).filter(calculatorHistoryStates.iterator()); + new Filter<>(filterRulesChain).filter(calculatorHistoryStates.iterator()); return calculatorHistoryStates; } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/history/HistoryDragProcessor.java b/android-app/src/main/java/org/solovyev/android/calculator/history/HistoryDragProcessor.java index 1817b3a8..267a32b1 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/history/HistoryDragProcessor.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/history/HistoryDragProcessor.java @@ -24,6 +24,8 @@ package org.solovyev.android.calculator.history; import android.util.Log; import android.view.MotionEvent; + +import org.solovyev.android.calculator.App; import org.solovyev.android.calculator.drag.DragButton; import org.solovyev.android.calculator.drag.DragDirection; import org.solovyev.android.calculator.drag.SimpleDragListener; @@ -63,6 +65,7 @@ public class HistoryDragProcessor implements SimpleDragListener.DragProcessor } if (historyAction != null) { + App.getVibrator().vibrate(); result = true; historyControl.doHistoryAction(historyAction); } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesFragment.java b/android-app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesFragment.java index 8348ff6b..2d4d4a06 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesFragment.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesFragment.java @@ -25,8 +25,6 @@ import javax.annotation.Nullable; import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.precision; import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.roundResult; import static org.solovyev.android.calculator.wizard.CalculatorWizards.DEFAULT_WIZARD_FLOW; -import static org.solovyev.android.view.VibratorContainer.Preferences.hapticFeedbackDuration; -import static org.solovyev.android.view.VibratorContainer.Preferences.hapticFeedbackEnabled; import static org.solovyev.android.wizard.WizardUi.startWizard; public class PreferencesFragment extends org.solovyev.android.material.preferences.PreferencesFragment implements SharedPreferences.OnSharedPreferenceChangeListener { @@ -121,7 +119,6 @@ public class PreferencesFragment extends org.solovyev.android.material.preferenc final SharedPreferences preferences = App.getPreferences(); onSharedPreferenceChanged(preferences, roundResult.getKey()); - onSharedPreferenceChanged(preferences, hapticFeedbackEnabled.getKey()); } @Nonnull @@ -136,11 +133,6 @@ public class PreferencesFragment extends org.solovyev.android.material.preferenc if (preference != null) { preference.setEnabled(preferences.getBoolean(key, roundResult.getDefaultValue())); } - } else if (hapticFeedbackEnabled.getKey().equals(key)) { - final Preference preference = findPreference(hapticFeedbackDuration.getKey()); - if (preference != null) { - preference.setEnabled(hapticFeedbackEnabled.getPreference(preferences)); - } } } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/wizard/DragButtonWizardStep.java b/android-app/src/main/java/org/solovyev/android/calculator/wizard/DragButtonWizardStep.java index c5d352ad..dc6377a5 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/wizard/DragButtonWizardStep.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/wizard/DragButtonWizardStep.java @@ -26,6 +26,8 @@ import android.os.Bundle; import android.view.MotionEvent; import android.view.View; import android.widget.TextView; + +import org.solovyev.android.calculator.App; import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.drag.DirectionDragButton; import org.solovyev.android.calculator.drag.DragButton; @@ -139,6 +141,7 @@ public class DragButtonWizardStep extends WizardFragment { private class DragButtonOnClickListener implements View.OnClickListener { @Override public void onClick(View v) { + App.getVibrator().vibrate(); if (action == DragButtonAction.center || action == DragButtonAction.end) { setNextAction(); } @@ -155,6 +158,10 @@ public class DragButtonWizardStep extends WizardFragment { @Nonnull DragButton dragButton, @Nonnull Point2d startPoint2d, @Nonnull MotionEvent motionEvent) { + if (dragDirection == DragDirection.up || dragDirection == DragDirection.down) { + App.getVibrator().vibrate(); + } + if (action.dragDirection == dragDirection) { setNextAction(); return true; diff --git a/android-app/src/main/res/values-ru/text_strings.xml b/android-app/src/main/res/values-ru/text_strings.xml index 9ad9a792..fb5e10c2 100644 --- a/android-app/src/main/res/values-ru/text_strings.xml +++ b/android-app/src/main/res/values-ru/text_strings.xml @@ -119,6 +119,7 @@ Устанавливает раскладку кнопок Отклик на нажатие Включает/выключает вибрацию по нажатию клавиши + Выключена Маленькая Средняя Большая diff --git a/android-app/src/main/res/values/arrays.xml b/android-app/src/main/res/values/arrays.xml index 6237ebdf..b0d385fd 100644 --- a/android-app/src/main/res/values/arrays.xml +++ b/android-app/src/main/res/values/arrays.xml @@ -62,12 +62,14 @@ simple - + + @string/p_calc_haptic_feedback_strength_disabled @string/p_calc_haptic_feedback_strength_short @string/p_calc_haptic_feedback_strength_middle @string/p_calc_haptic_feedback_strength_long - + + 0 30 60 100 diff --git a/android-app/src/main/res/values/preferences.xml b/android-app/src/main/res/values/preferences.xml index 02a14348..376e022d 100644 --- a/android-app/src/main/res/values/preferences.xml +++ b/android-app/src/main/res/values/preferences.xml @@ -83,11 +83,6 @@ "×" - - org.solovyev.android.calculator.CalculatorActivity_calc_haptic_feedback_duration_key - - " " - false \ No newline at end of file diff --git a/android-app/src/main/res/values/text_strings.xml b/android-app/src/main/res/values/text_strings.xml index 74167da8..487fcbce 100644 --- a/android-app/src/main/res/values/text_strings.xml +++ b/android-app/src/main/res/values/text_strings.xml @@ -115,7 +115,8 @@ Sets layout of buttons Haptic feedback Toggles vibration on button click - Short + Disabled + Short Middle Long Haptic feedback duration diff --git a/android-app/src/main/res/xml/preferences_appearance.xml b/android-app/src/main/res/xml/preferences_appearance.xml index e4cb95b0..ebd879ae 100644 --- a/android-app/src/main/res/xml/preferences_appearance.xml +++ b/android-app/src/main/res/xml/preferences_appearance.xml @@ -31,18 +31,12 @@ a:title="@string/c_calc_color_display_title" a:defaultValue="true"/> - - + a:key="hapticFeedback" + a:title="@string/c_calc_haptic_feedback_title" + a:entries="@array/cpp_haptic_feedback_names" + a:summary="@string/c_calc_haptic_feedback_summary" + a:entryValues="@array/cpp_haptic_feedback_values"/>