diff --git a/app/build.gradle b/app/build.gradle
index e5a9b952..f7f3a535 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -64,7 +64,7 @@ dependencies {
compile('ch.acra:acra:4.7.0') {
exclude group: 'org.json'
}
- compile 'org.solovyev.android.views.dragbutton:drag-button:1.0@aar'
+ compile 'org.solovyev.android.views.dragbutton:drag-button:1.1@aar'
compile 'org.solovyev.android:android-common-lists:1.1.18@aar'
compile 'org.solovyev.android:android-common-core:1.1.18@aar'
compile 'org.solovyev.android:android-common-other:1.1.18@aar'
diff --git a/app/misc/libs/drag-button-1.0.aar b/app/misc/libs/drag-button-1.0.aar
deleted file mode 100644
index f9c4de7d..00000000
Binary files a/app/misc/libs/drag-button-1.0.aar and /dev/null differ
diff --git a/app/misc/libs/drag-button-1.1.aar b/app/misc/libs/drag-button-1.1.aar
new file mode 100644
index 00000000..04ed325e
Binary files /dev/null and b/app/misc/libs/drag-button-1.1.aar differ
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index c99831e9..b16a64d7 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -3,7 +3,6 @@
package="org.solovyev.android.calculator"
android:installLocation="auto">
-
diff --git a/app/src/main/java/org/solovyev/android/calculator/AndroidCalculatorKeyboard.java b/app/src/main/java/org/solovyev/android/calculator/AndroidCalculatorKeyboard.java
deleted file mode 100644
index 943a6712..00000000
--- a/app/src/main/java/org/solovyev/android/calculator/AndroidCalculatorKeyboard.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright 2013 serso aka se.solovyev
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- * Contact details
- *
- * Email: se.solovyev@gmail.com
- * Site: http://se.solovyev.org
- */
-
-package org.solovyev.android.calculator;
-
-import android.app.Application;
-import android.content.Context;
-
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
-/**
- * User: serso
- * Date: 11/18/12
- * Time: 6:05 PM
- */
-public class AndroidCalculatorKeyboard implements CalculatorKeyboard {
-
- @Nonnull
- private final CalculatorKeyboard calculatorKeyboard;
-
- @Nonnull
- private final Context context;
-
- @android.support.annotation.Nullable
- private org.solovyev.android.calculator.Vibrator vibrator;
-
- public AndroidCalculatorKeyboard(@Nonnull Application application,
- @Nonnull CalculatorKeyboard calculatorKeyboard) {
- this.context = application;
- this.calculatorKeyboard = calculatorKeyboard;
- }
-
- @Override
- public boolean buttonPressed(@Nullable String text) {
- App.getGa().onButtonPressed(text);
- final boolean processed = calculatorKeyboard.buttonPressed(text);
- if (processed) {
- vibrate();
- }
- return processed;
- }
-
- private void vibrate() {
- if (vibrator == null) {
- vibrator = App.getVibrator();
- }
- vibrator.vibrate();
- }
-
- @Override
- public void roundBracketsButtonPressed() {
- vibrate();
- calculatorKeyboard.roundBracketsButtonPressed();
- }
-
- @Override
- public void pasteButtonPressed() {
- vibrate();
- calculatorKeyboard.pasteButtonPressed();
- }
-
- @Override
- public void clearButtonPressed() {
- vibrate();
- calculatorKeyboard.clearButtonPressed();
- }
-
- @Override
- public void copyButtonPressed() {
- vibrate();
- calculatorKeyboard.copyButtonPressed();
- }
-
- @Override
- public void moveCursorLeft() {
- vibrate();
- calculatorKeyboard.moveCursorLeft();
- }
-
- @Override
- public void moveCursorRight() {
- vibrate();
- calculatorKeyboard.moveCursorRight();
- }
-}
diff --git a/app/src/main/java/org/solovyev/android/calculator/App.java b/app/src/main/java/org/solovyev/android/calculator/App.java
index a641dda0..3a919368 100644
--- a/app/src/main/java/org/solovyev/android/calculator/App.java
+++ b/app/src/main/java/org/solovyev/android/calculator/App.java
@@ -103,8 +103,6 @@ public final class App {
@Nullable
private static Boolean lg = null;
@Nonnull
- private static volatile Vibrator vibrator;
- @Nonnull
private static volatile ScreenMetrics screenMetrics;
private App() {
@@ -150,7 +148,6 @@ public final class App {
}
});
App.broadcaster = new CalculatorBroadcaster(application, preferences);
- App.vibrator = new Vibrator(application, preferences);
App.screenMetrics = new ScreenMetrics(application);
App.languages.init(App.preferences);
@@ -273,11 +270,6 @@ public final class App {
return isLg() && Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN;
}
- @Nonnull
- public static Vibrator getVibrator() {
- return vibrator;
- }
-
@Nonnull
public static ScreenMetrics getScreenMetrics() {
return screenMetrics;
diff --git a/app/src/main/java/org/solovyev/android/calculator/BaseUi.java b/app/src/main/java/org/solovyev/android/calculator/BaseUi.java
index a3e929a2..bff45d9c 100644
--- a/app/src/main/java/org/solovyev/android/calculator/BaseUi.java
+++ b/app/src/main/java/org/solovyev/android/calculator/BaseUi.java
@@ -312,7 +312,6 @@ public abstract class BaseUi implements SharedPreferences.OnSharedPreferenceChan
@Override
public boolean processDragEvent(@Nonnull DragDirection dragDirection, @Nonnull DragButton dragButton, @Nonnull PointF startPoint, @Nonnull MotionEvent motionEvent) {
if (dragDirection == DragDirection.down) {
- App.getVibrator().vibrate();
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_operators, null);
return true;
}
diff --git a/app/src/main/java/org/solovyev/android/calculator/ButtonOnClickListener.java b/app/src/main/java/org/solovyev/android/calculator/ButtonOnClickListener.java
index 727f567b..8eb10505 100644
--- a/app/src/main/java/org/solovyev/android/calculator/ButtonOnClickListener.java
+++ b/app/src/main/java/org/solovyev/android/calculator/ButtonOnClickListener.java
@@ -1,6 +1,7 @@
package org.solovyev.android.calculator;
import android.support.annotation.IdRes;
+import android.view.HapticFeedbackConstants;
import android.view.View;
import android.widget.Button;
@@ -31,47 +32,49 @@ final class ButtonOnClickListener implements View.OnClickListener {
case R.id.cpp_button_plus:
case R.id.cpp_button_right:
case R.id.cpp_button_round_brackets:
- onClick(((Button) v).getText().toString());
+ onClick(v, ((Button) v).getText().toString());
break;
case R.id.cpp_button_clear:
- onClick(CalculatorSpecialButton.clear);
+ onClick(v, CalculatorSpecialButton.clear);
break;
case R.id.cpp_button_functions:
- onClick(CalculatorSpecialButton.functions);
+ onClick(v, CalculatorSpecialButton.functions);
break;
case R.id.cpp_button_history:
- onClick(CalculatorSpecialButton.history);
+ onClick(v, CalculatorSpecialButton.history);
break;
case R.id.cpp_button_erase:
- onClick(CalculatorSpecialButton.erase);
+ onClick(v, CalculatorSpecialButton.erase);
break;
case R.id.cpp_button_paste:
- onClick(CalculatorSpecialButton.paste);
+ onClick(v, CalculatorSpecialButton.paste);
break;
case R.id.cpp_button_copy:
- onClick(CalculatorSpecialButton.copy);
+ onClick(v, CalculatorSpecialButton.copy);
break;
case R.id.cpp_button_like:
- onClick(CalculatorSpecialButton.like);
+ onClick(v, CalculatorSpecialButton.like);
break;
case R.id.cpp_button_operators:
- onClick(CalculatorSpecialButton.operators);
+ onClick(v, CalculatorSpecialButton.operators);
break;
case R.id.cpp_button_vars:
- onClick(CalculatorSpecialButton.vars);
+ onClick(v, CalculatorSpecialButton.vars);
break;
case R.id.cpp_button_equals:
- onClick(CalculatorSpecialButton.equals);
+ onClick(v, CalculatorSpecialButton.equals);
break;
}
}
- private void onClick(@Nonnull CalculatorSpecialButton b) {
- onClick(b.getActionCode());
+ private void onClick(@Nonnull View v, @Nonnull CalculatorSpecialButton b) {
+ onClick(v, b.getActionCode());
}
- private void onClick(@Nonnull String s) {
- Locator.getInstance().getKeyboard().buttonPressed(s);
+ private void onClick(@Nonnull View v, @Nonnull String s) {
+ if (Locator.getInstance().getKeyboard().buttonPressed(s)) {
+ v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
+ }
}
public void attachToViews(@Nonnull ViewsCache views) {
diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java
index 0f632e84..551908f1 100644
--- a/app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java
+++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java
@@ -171,7 +171,7 @@ public class CalculatorApplication extends android.app.Application implements Sh
new AndroidCalculatorHistory(this, calculator),
new AndroidCalculatorLogger(),
new AndroidCalculatorPreferenceService(this),
- new AndroidCalculatorKeyboard(this, new CalculatorKeyboardImpl()),
+ new CalculatorKeyboard(),
new AndroidCalculatorPlotter(this, new CalculatorPlotterImpl(calculator)),
editorTextProcessor);
diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorButton.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorButton.java
index 87f54188..bc9e1af8 100644
--- a/app/src/main/java/org/solovyev/android/calculator/CalculatorButton.java
+++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorButton.java
@@ -138,14 +138,15 @@ public enum CalculatorButton {
}
}
- public void onLongClick() {
+ public boolean onLongClick() {
if (onLongClickText != null) {
- Locator.getInstance().getKeyboard().buttonPressed(onLongClickText);
+ return Locator.getInstance().getKeyboard().buttonPressed(onLongClickText);
}
+ return false;
}
- public void onClick() {
- Locator.getInstance().getKeyboard().buttonPressed(onClickText);
+ public boolean onClick() {
+ return Locator.getInstance().getKeyboard().buttonPressed(onClickText);
}
public int getButtonId() {
diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorButtons.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorButtons.java
index 73783e1e..c67e39f4 100644
--- a/app/src/main/java/org/solovyev/android/calculator/CalculatorButtons.java
+++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorButtons.java
@@ -33,8 +33,7 @@ import android.util.TypedValue;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
-import jscl.AngleUnit;
-import jscl.NumeralBase;
+
import org.solovyev.android.Views;
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
import org.solovyev.android.calculator.view.AngleUnitsButton;
@@ -47,6 +46,9 @@ import org.solovyev.android.views.dragbutton.SimpleDragListener;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+import jscl.AngleUnit;
+import jscl.NumeralBase;
+
public final class CalculatorButtons {
private CalculatorButtons() {
@@ -115,18 +117,13 @@ public final class CalculatorButtons {
private final DigitButtonDragProcessor upDownProcessor = new DigitButtonDragProcessor(getKeyboard());
@Override
- public boolean processDragEvent(@Nonnull DragDirection dragDirection, @Nonnull DragButton dragButton, @Nonnull PointF startPoint, @Nonnull MotionEvent motionEvent) {
- final boolean result;
-
- if (dragDirection == DragDirection.left) {
- App.getVibrator().vibrate();
+ public boolean processDragEvent(@Nonnull DragDirection direction, @Nonnull DragButton button, @Nonnull PointF startPoint, @Nonnull MotionEvent motionEvent) {
+ if (direction == DragDirection.left) {
getKeyboard().roundBracketsButtonPressed();
- result = true;
- } else {
- result = upDownProcessor.processDragEvent(dragDirection, dragButton, startPoint, motionEvent);
+ return true;
}
- return result;
+ return upDownProcessor.processDragEvent(direction, button, startPoint, motionEvent);
}
}
@@ -144,18 +141,12 @@ public final class CalculatorButtons {
@Nonnull DragButton dragButton,
@Nonnull PointF startPoint,
@Nonnull MotionEvent motionEvent) {
- 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) {
- Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_create_matrix_dialog, null, context);
- result = true;
- }*/
+ return true;
+ }
- return result;
+ return false;
}
}
@@ -177,8 +168,6 @@ public final class CalculatorButtons {
@Nonnull DragButton dragButton,
@Nonnull PointF startPoint,
@Nonnull MotionEvent motionEvent) {
- boolean result = false;
-
if (dragButton instanceof AngleUnitsButton) {
if (dragDirection != DragDirection.left) {
final String directionText = ((AngleUnitsButton) dragButton).getText(dragDirection);
@@ -191,21 +180,19 @@ public final class CalculatorButtons {
final AngleUnit oldAngleUnits = AndroidCalculatorEngine.Preferences.angleUnit.getPreference(preferences);
if (oldAngleUnits != angleUnits) {
- App.getVibrator().vibrate();
Locator.getInstance().getPreferenceService().setAngleUnits(angleUnits);
}
-
- result = true;
} catch (IllegalArgumentException e) {
Log.d(this.getClass().getName(), "Unsupported angle units: " + directionText);
}
+ return true;
}
} else if (dragDirection == DragDirection.left) {
- result = processor.processDragEvent(dragDirection, dragButton, startPoint, motionEvent);
+ return processor.processDragEvent(dragDirection, dragButton, startPoint, motionEvent);
}
}
- return result;
+ return false;
}
}
@@ -223,31 +210,26 @@ public final class CalculatorButtons {
@Nonnull DragButton dragButton,
@Nonnull PointF startPoint,
@Nonnull MotionEvent motionEvent) {
- boolean result = false;
-
if (dragButton instanceof NumeralBasesButton) {
final String directionText = ((NumeralBasesButton) dragButton).getText(dragDirection);
if (directionText != null) {
try {
-
final NumeralBase numeralBase = NumeralBase.valueOf(directionText);
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
final NumeralBase oldNumeralBase = AndroidCalculatorEngine.Preferences.numeralBase.getPreference(preferences);
if (oldNumeralBase != numeralBase) {
- App.getVibrator().vibrate();
Locator.getInstance().getPreferenceService().setNumeralBase(numeralBase);
}
-
- result = true;
} catch (IllegalArgumentException e) {
Log.d(this.getClass().getName(), "Unsupported numeral base: " + directionText);
}
+ return true;
}
}
- return result;
+ return false;
}
}
@@ -265,15 +247,11 @@ public final class CalculatorButtons {
@Nonnull DragButton dragButton,
@Nonnull PointF startPoint,
@Nonnull MotionEvent motionEvent) {
- boolean result = false;
-
if (dragDirection == DragDirection.up) {
- App.getVibrator().vibrate();
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_create_function_dialog, null, context);
- result = true;
+ return true;
}
-
- return result;
+ return false;
}
}
}
diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorKeyboard.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorKeyboard.java
index 45fc7a1f..11538532 100644
--- a/app/src/main/java/org/solovyev/android/calculator/CalculatorKeyboard.java
+++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorKeyboard.java
@@ -22,26 +22,115 @@
package org.solovyev.android.calculator;
+import org.solovyev.android.calculator.math.MathType;
+import org.solovyev.common.text.Strings;
+
+import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-/**
- * User: serso
- * Date: 9/22/12
- * Time: 1:08 PM
- */
-public interface CalculatorKeyboard {
+public class CalculatorKeyboard {
- boolean buttonPressed(@Nullable String text);
+ public boolean buttonPressed(@Nullable final String text) {
+ App.getGa().onButtonPressed(text);
+ if (!Strings.isEmpty(text)) {
+ // process special buttons
+ boolean processed = processSpecialButtons(text);
- void roundBracketsButtonPressed();
+ if (!processed) {
+ processText(prepareText(text));
+ }
+ return true;
+ }
+ return false;
+ }
- void pasteButtonPressed();
+ private void processText(@Nonnull String text) {
+ int cursorPositionOffset = 0;
+ final StringBuilder textToBeInserted = new StringBuilder(text);
- void clearButtonPressed();
+ final MathType.Result mathType = MathType.getType(text, 0, false);
+ switch (mathType.type) {
+ case function:
+ textToBeInserted.append("()");
+ cursorPositionOffset = -1;
+ break;
+ case operator:
+ textToBeInserted.append("()");
+ cursorPositionOffset = -1;
+ break;
+ case comma:
+ textToBeInserted.append(" ");
+ break;
+ }
- void copyButtonPressed();
+ if (cursorPositionOffset == 0) {
+ if (MathType.groupSymbols.contains(text)) {
+ cursorPositionOffset = -1;
+ }
+ }
- void moveCursorLeft();
+ final Editor editor = Locator.getInstance().getEditor();
+ editor.insert(textToBeInserted.toString(), cursorPositionOffset);
+ }
- void moveCursorRight();
+ @Nonnull
+ private String prepareText(@Nonnull String text) {
+ if ("( )".equals(text) || "( )".equals(text)) {
+ return "()";
+ } else {
+ return text;
+ }
+ }
+
+ private boolean processSpecialButtons(@Nonnull String text) {
+ boolean result = false;
+
+ final CalculatorSpecialButton button = CalculatorSpecialButton.getByActionCode(text);
+ if (button != null) {
+ button.onClick(this);
+ result = true;
+ }
+
+ return result;
+ }
+
+ public void roundBracketsButtonPressed() {
+ final Editor editor = Locator.getInstance().getEditor();
+ EditorState viewState = editor.getState();
+
+ final int cursorPosition = viewState.selection;
+ final CharSequence oldText = viewState.text;
+
+ editor.setText("(" + oldText.subSequence(0, cursorPosition) + ")" + oldText.subSequence(cursorPosition, oldText.length()), cursorPosition + 2);
+ }
+
+ public void pasteButtonPressed() {
+ final String text = Locator.getInstance().getClipboard().getText();
+ if (text != null) {
+ Locator.getInstance().getEditor().insert(text);
+ }
+ }
+
+ public void clearButtonPressed() {
+ Locator.getInstance().getEditor().clear();
+ }
+
+ public void copyButtonPressed() {
+ final DisplayState displayViewState = Locator.getInstance().getDisplay().getViewState();
+ if (displayViewState.isValid()) {
+ final CharSequence text = displayViewState.getText();
+ if (!Strings.isEmpty(text)) {
+ Locator.getInstance().getClipboard().setText(text);
+ Locator.getInstance().getNotifier().showMessage(CalculatorMessage.newInfoMessage(CalculatorMessages.result_copied));
+ }
+ }
+ }
+
+ public void moveCursorLeft() {
+ Locator.getInstance().getEditor().moveCursorLeft();
+ }
+
+ public void moveCursorRight() {
+ Locator.getInstance().getEditor().moveCursorRight();
+ }
}
diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorKeyboardImpl.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorKeyboardImpl.java
deleted file mode 100644
index 4271660b..00000000
--- a/app/src/main/java/org/solovyev/android/calculator/CalculatorKeyboardImpl.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Copyright 2013 serso aka se.solovyev
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- * Contact details
- *
- * Email: se.solovyev@gmail.com
- * Site: http://se.solovyev.org
- */
-
-package org.solovyev.android.calculator;
-
-import org.solovyev.android.calculator.math.MathType;
-import org.solovyev.common.text.Strings;
-
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
-public class CalculatorKeyboardImpl implements CalculatorKeyboard {
-
- @Override
- public boolean buttonPressed(@Nullable final String text) {
- if (!Strings.isEmpty(text)) {
- // process special buttons
- boolean processed = processSpecialButtons(text);
-
- if (!processed) {
- processText(prepareText(text));
- }
- return true;
- }
- return false;
- }
-
- private void processText(@Nonnull String text) {
- int cursorPositionOffset = 0;
- final StringBuilder textToBeInserted = new StringBuilder(text);
-
- final MathType.Result mathType = MathType.getType(text, 0, false);
- switch (mathType.type) {
- case function:
- textToBeInserted.append("()");
- cursorPositionOffset = -1;
- break;
- case operator:
- textToBeInserted.append("()");
- cursorPositionOffset = -1;
- break;
- case comma:
- textToBeInserted.append(" ");
- break;
- }
-
- if (cursorPositionOffset == 0) {
- if (MathType.groupSymbols.contains(text)) {
- cursorPositionOffset = -1;
- }
- }
-
- final Editor editor = Locator.getInstance().getEditor();
- editor.insert(textToBeInserted.toString(), cursorPositionOffset);
- }
-
- @Nonnull
- private String prepareText(@Nonnull String text) {
- if ("( )".equals(text) || "( )".equals(text)) {
- return "()";
- } else {
- return text;
- }
- }
-
- private boolean processSpecialButtons(@Nonnull String text) {
- boolean result = false;
-
- final CalculatorSpecialButton button = CalculatorSpecialButton.getByActionCode(text);
- if (button != null) {
- button.onClick(this);
- result = true;
- }
-
- return result;
- }
-
- @Override
- public void roundBracketsButtonPressed() {
- final Editor editor = Locator.getInstance().getEditor();
- EditorState viewState = editor.getState();
-
- final int cursorPosition = viewState.selection;
- final CharSequence oldText = viewState.text;
-
- editor.setText("(" + oldText.subSequence(0, cursorPosition) + ")" + oldText.subSequence(cursorPosition, oldText.length()), cursorPosition + 2);
- }
-
- @Override
- public void pasteButtonPressed() {
- final String text = Locator.getInstance().getClipboard().getText();
- if (text != null) {
- Locator.getInstance().getEditor().insert(text);
- }
- }
-
- @Override
- public void clearButtonPressed() {
- Locator.getInstance().getEditor().clear();
- }
-
- @Override
- public void copyButtonPressed() {
- final DisplayState displayViewState = Locator.getInstance().getDisplay().getViewState();
- if (displayViewState.isValid()) {
- final CharSequence text = displayViewState.getText();
- if (!Strings.isEmpty(text)) {
- Locator.getInstance().getClipboard().setText(text);
- Locator.getInstance().getNotifier().showMessage(CalculatorMessage.newInfoMessage(CalculatorMessages.result_copied));
- }
- }
- }
-
- @Override
- public void moveCursorLeft() {
- Locator.getInstance().getEditor().moveCursorLeft();
- }
-
- @Override
- public void moveCursorRight() {
- Locator.getInstance().getEditor().moveCursorRight();
- }
-}
diff --git a/app/src/main/java/org/solovyev/android/calculator/CursorDragProcessor.java b/app/src/main/java/org/solovyev/android/calculator/CursorDragProcessor.java
index 36675f24..0b495efc 100644
--- a/app/src/main/java/org/solovyev/android/calculator/CursorDragProcessor.java
+++ b/app/src/main/java/org/solovyev/android/calculator/CursorDragProcessor.java
@@ -24,6 +24,7 @@ package org.solovyev.android.calculator;
import android.graphics.PointF;
import android.view.MotionEvent;
+
import org.solovyev.android.views.dragbutton.DirectionDragButton;
import org.solovyev.android.views.dragbutton.DragButton;
import org.solovyev.android.views.dragbutton.DragDirection;
@@ -31,33 +32,21 @@ import org.solovyev.android.views.dragbutton.SimpleDragListener;
import javax.annotation.Nonnull;
-/**
- * User: serso
- * Date: 9/16/11
- * Time: 11:45 PM
- */
public class CursorDragProcessor implements SimpleDragListener.DragProcessor {
- public CursorDragProcessor() {
- }
-
@Override
public boolean processDragEvent(@Nonnull DragDirection dragDirection, @Nonnull DragButton dragButton, @Nonnull PointF startPoint, @Nonnull MotionEvent motionEvent) {
- boolean result = false;
-
if (dragButton instanceof DirectionDragButton) {
- String text = ((DirectionDragButton) dragButton).getText(dragDirection);
+ final String text = ((DirectionDragButton) dragButton).getText(dragDirection);
if ("◁◁".equals(text)) {
- App.getVibrator().vibrate();
Locator.getInstance().getEditor().setCursorOnStart();
- result = true;
+ return true;
} else if ("▷▷".equals(text)) {
- App.getVibrator().vibrate();
Locator.getInstance().getEditor().setCursorOnEnd();
- result = true;
+ return true;
}
}
- return result;
+ return false;
}
}
diff --git a/app/src/main/java/org/solovyev/android/calculator/DigitButtonDragProcessor.java b/app/src/main/java/org/solovyev/android/calculator/DigitButtonDragProcessor.java
index d57caf6e..8bfafce1 100644
--- a/app/src/main/java/org/solovyev/android/calculator/DigitButtonDragProcessor.java
+++ b/app/src/main/java/org/solovyev/android/calculator/DigitButtonDragProcessor.java
@@ -31,11 +31,6 @@ import org.solovyev.android.views.dragbutton.SimpleDragListener;
import javax.annotation.Nonnull;
-/**
- * User: serso
- * Date: 9/16/11
- * Time: 11:48 PM
- */
public class DigitButtonDragProcessor implements SimpleDragListener.DragProcessor {
@Nonnull
@@ -46,11 +41,8 @@ public class DigitButtonDragProcessor implements SimpleDragListener.DragProcesso
}
@Override
- public boolean processDragEvent(@Nonnull DragDirection dragDirection, @Nonnull DragButton dragButton, @Nonnull PointF startPoint, @Nonnull MotionEvent motionEvent) {
- if (!(dragButton instanceof DirectionDragButton)) throw new AssertionError();
- final String text = ((DirectionDragButton) dragButton).getText(dragDirection);
- calculatorKeyboard.buttonPressed(text);
- return true;
+ public boolean processDragEvent(@Nonnull DragDirection direction, @Nonnull DragButton button, @Nonnull PointF startPoint, @Nonnull MotionEvent motionEvent) {
+ final String text = ((DirectionDragButton) button).getText(direction);
+ return calculatorKeyboard.buttonPressed(text);
}
-
}
diff --git a/app/src/main/java/org/solovyev/android/calculator/EqualsDragProcessor.java b/app/src/main/java/org/solovyev/android/calculator/EqualsDragProcessor.java
index 61c84ffb..435857d7 100644
--- a/app/src/main/java/org/solovyev/android/calculator/EqualsDragProcessor.java
+++ b/app/src/main/java/org/solovyev/android/calculator/EqualsDragProcessor.java
@@ -24,6 +24,7 @@ package org.solovyev.android.calculator;
import android.graphics.PointF;
import android.view.MotionEvent;
+
import org.solovyev.android.views.dragbutton.DirectionDragButton;
import org.solovyev.android.views.dragbutton.DragButton;
import org.solovyev.android.views.dragbutton.DragDirection;
@@ -31,35 +32,21 @@ import org.solovyev.android.views.dragbutton.SimpleDragListener;
import javax.annotation.Nonnull;
-/**
- * User: serso
- * Date: 10/24/11
- * Time: 9:52 PM
- */
public class EqualsDragProcessor implements SimpleDragListener.DragProcessor {
- public EqualsDragProcessor() {
- }
-
@Override
- public boolean processDragEvent(@Nonnull DragDirection dragDirection, @Nonnull DragButton dragButton, @Nonnull PointF startPoint, @Nonnull MotionEvent motionEvent) {
- boolean result = false;
-
- 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;
- }
+ public boolean processDragEvent(@Nonnull DragDirection direction, @Nonnull DragButton button, @Nonnull PointF startPoint, @Nonnull MotionEvent motionEvent) {
+ if (direction == DragDirection.down) {
+ CalculatorActivityLauncher.tryPlot();
+ return true;
+ } else if (button instanceof DirectionDragButton) {
+ final String text = ((DirectionDragButton) button).getText(direction);
+ if ("≡".equals(text)) {
+ Locator.getInstance().getCalculator().simplify();
+ return true;
}
}
- return result;
+ return false;
}
}
diff --git a/app/src/main/java/org/solovyev/android/calculator/Preferences.java b/app/src/main/java/org/solovyev/android/calculator/Preferences.java
index 2024b568..5536ad4c 100644
--- a/app/src/main/java/org/solovyev/android/calculator/Preferences.java
+++ b/app/src/main/java/org/solovyev/android/calculator/Preferences.java
@@ -31,23 +31,31 @@ import android.support.annotation.LayoutRes;
import android.support.annotation.StyleRes;
import android.util.SparseArray;
import android.view.ContextThemeWrapper;
-import jscl.AngleUnit;
-import jscl.NumeralBase;
+
import org.solovyev.android.Check;
import org.solovyev.android.calculator.language.Languages;
import org.solovyev.android.calculator.math.MathType;
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
import org.solovyev.android.calculator.preferences.PurchaseDialogActivity;
import org.solovyev.android.calculator.wizard.WizardActivity;
-import org.solovyev.android.prefs.*;
+import org.solovyev.android.prefs.BooleanPreference;
+import org.solovyev.android.prefs.IntegerPreference;
+import org.solovyev.android.prefs.LongPreference;
+import org.solovyev.android.prefs.NumberToStringPreference;
+import org.solovyev.android.prefs.Preference;
+import org.solovyev.android.prefs.StringPreference;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
import java.text.DecimalFormatSymbols;
import java.util.EnumMap;
import java.util.Locale;
import java.util.Map;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import jscl.AngleUnit;
+import jscl.NumeralBase;
+
import static org.solovyev.android.Android.isPhoneModel;
import static org.solovyev.android.DeviceModel.samsung_galaxy_s;
import static org.solovyev.android.DeviceModel.samsung_galaxy_s_2;
@@ -126,18 +134,6 @@ public final class Preferences {
// renew value after each application start
Calculations.showCalculationMessagesDialog.putDefault(preferences);
Calculations.lastPreferredPreferencesCheck.putDefault(preferences);
-
- 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);
- }
- }
}
private static void applyDefaultPreference(@Nonnull SharedPreferences preferences, @Nonnull Preference> preference) {
@@ -281,9 +277,6 @@ public final class Preferences {
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) {
return theme.getPreferenceNoError(preferences);
diff --git a/app/src/main/java/org/solovyev/android/calculator/Vibrator.java b/app/src/main/java/org/solovyev/android/calculator/Vibrator.java
deleted file mode 100644
index 8ae957d3..00000000
--- a/app/src/main/java/org/solovyev/android/calculator/Vibrator.java
+++ /dev/null
@@ -1,42 +0,0 @@
-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/app/src/main/java/org/solovyev/android/calculator/history/BaseHistoryFragment.java b/app/src/main/java/org/solovyev/android/calculator/history/BaseHistoryFragment.java
index d1513d99..99018e25 100644
--- a/app/src/main/java/org/solovyev/android/calculator/history/BaseHistoryFragment.java
+++ b/app/src/main/java/org/solovyev/android/calculator/history/BaseHistoryFragment.java
@@ -44,7 +44,6 @@ import android.widget.ListView;
import com.melnykov.fab.FloatingActionButton;
-import org.solovyev.android.calculator.App;
import org.solovyev.android.calculator.CalculatorApplication;
import org.solovyev.android.calculator.CalculatorEventData;
import org.solovyev.android.calculator.CalculatorEventListener;
@@ -105,13 +104,6 @@ public abstract class BaseHistoryFragment extends ListFragment implements Calcul
@Nonnull
private static final String TAG = "CalculatorHistoryFragment";
- /*
- **********************************************************************
- *
- * FIELDS
- *
- **********************************************************************
- */
private final ActivityMenu