diff --git a/app/src/main/java/org/solovyev/android/calculator/keyboard/BaseKeyboardUi.java b/app/src/main/java/org/solovyev/android/calculator/keyboard/BaseKeyboardUi.java index 15ad4181..f8f9efb9 100644 --- a/app/src/main/java/org/solovyev/android/calculator/keyboard/BaseKeyboardUi.java +++ b/app/src/main/java/org/solovyev/android/calculator/keyboard/BaseKeyboardUi.java @@ -12,18 +12,35 @@ import android.util.TypedValue; import android.view.View; import android.widget.ImageView; import android.widget.TextView; -import org.solovyev.android.calculator.*; + +import org.solovyev.android.calculator.ActivityLauncher; +import org.solovyev.android.calculator.App; +import org.solovyev.android.calculator.BaseActivity; +import org.solovyev.android.calculator.Calculator; +import org.solovyev.android.calculator.Editor; +import org.solovyev.android.calculator.Keyboard; +import org.solovyev.android.calculator.Preferences; +import org.solovyev.android.calculator.PreferredPreferences; import org.solovyev.android.calculator.buttons.CppSpecialButton; import org.solovyev.android.views.Adjuster; -import org.solovyev.android.views.dragbutton.*; +import org.solovyev.android.views.dragbutton.DirectionDragButton; +import org.solovyev.android.views.dragbutton.DirectionDragImageButton; +import org.solovyev.android.views.dragbutton.DirectionDragListener; +import org.solovyev.android.views.dragbutton.DirectionDragView; +import org.solovyev.android.views.dragbutton.DragDirection; +import org.solovyev.android.views.dragbutton.DragEvent; +import org.solovyev.android.views.dragbutton.DragView; -import javax.annotation.Nonnull; -import javax.inject.Inject; import java.util.ArrayList; import java.util.List; +import javax.annotation.Nonnull; +import javax.inject.Inject; + import static android.content.res.Configuration.ORIENTATION_PORTRAIT; -import static android.view.HapticFeedbackConstants.*; +import static android.view.HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING; +import static android.view.HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING; +import static android.view.HapticFeedbackConstants.KEYBOARD_TAP; import static org.solovyev.android.calculator.App.cast; import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple; import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple_mobile; @@ -134,7 +151,7 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer Adjuster.adjustText(button, textScale); } - protected final void hideText(@Nullable DirectionDragButton button, @Nonnull DragDirection... directions) { + protected final void hideText(@Nullable DirectionDragView button, @Nonnull DragDirection... directions) { if (button == null) { return; } @@ -143,11 +160,11 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer } } - protected final void hideText(@Nullable DirectionDragButton button, @Nonnull DragDirection direction) { + protected final void hideText(@Nullable DirectionDragView button, @Nonnull DragDirection direction) { if (button == null) { return; } - button.setShowDirectionText(direction, false); + button.getText(direction).setVisible(false); } public void onDestroyView() { diff --git a/app/src/main/java/org/solovyev/android/calculator/keyboard/KeyboardUi.java b/app/src/main/java/org/solovyev/android/calculator/keyboard/KeyboardUi.java index 5eb570b8..fb21d9e1 100644 --- a/app/src/main/java/org/solovyev/android/calculator/keyboard/KeyboardUi.java +++ b/app/src/main/java/org/solovyev/android/calculator/keyboard/KeyboardUi.java @@ -10,6 +10,26 @@ import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.ImageButton; + +import org.solovyev.android.calculator.ActivityLauncher; +import org.solovyev.android.calculator.App; +import org.solovyev.android.calculator.Display; +import org.solovyev.android.calculator.DisplayState; +import org.solovyev.android.calculator.Engine; +import org.solovyev.android.calculator.R; +import org.solovyev.android.calculator.buttons.CppSpecialButton; +import org.solovyev.android.calculator.history.History; +import org.solovyev.android.calculator.memory.Memory; +import org.solovyev.android.calculator.view.AngleUnitsButton; +import org.solovyev.android.calculator.view.NumeralBasesButton; +import org.solovyev.android.views.dragbutton.DirectionDragButton; +import org.solovyev.android.views.dragbutton.DirectionDragImageButton; +import org.solovyev.android.views.dragbutton.DirectionDragView; +import org.solovyev.android.views.dragbutton.DragDirection; + +import javax.annotation.Nonnull; +import javax.inject.Inject; + import butterknife.Bind; import butterknife.ButterKnife; import dagger.Lazy; @@ -17,21 +37,13 @@ import jscl.AngleUnit; import jscl.NumeralBase; import jscl.math.Expression; import jscl.math.Generic; -import org.solovyev.android.calculator.*; -import org.solovyev.android.calculator.buttons.CppSpecialButton; -import org.solovyev.android.calculator.history.History; -import org.solovyev.android.calculator.memory.Memory; -import org.solovyev.android.calculator.view.AngleUnitsButton; -import org.solovyev.android.views.dragbutton.DirectionDragButton; -import org.solovyev.android.views.dragbutton.DirectionDragImageButton; -import org.solovyev.android.views.dragbutton.DragButton; -import org.solovyev.android.views.dragbutton.DragDirection; -import javax.annotation.Nonnull; -import javax.inject.Inject; - -import static org.solovyev.android.calculator.Engine.Preferences.*; -import static org.solovyev.android.views.dragbutton.DragDirection.*; +import static org.solovyev.android.calculator.Engine.Preferences.angleUnit; +import static org.solovyev.android.calculator.Engine.Preferences.multiplicationSign; +import static org.solovyev.android.calculator.Engine.Preferences.numeralBase; +import static org.solovyev.android.views.dragbutton.DragDirection.down; +import static org.solovyev.android.views.dragbutton.DragDirection.left; +import static org.solovyev.android.views.dragbutton.DragDirection.up; public class KeyboardUi extends BaseKeyboardUi { @@ -48,7 +60,7 @@ public class KeyboardUi extends BaseKeyboardUi { @Bind(R.id.cpp_button_5) public DirectionDragButton button5; @Bind(R.id.cpp_button_6) - public AngleUnitsButton button6; + public DirectionDragButton button6; @Bind(R.id.cpp_button_7) public DirectionDragButton button7; @Bind(R.id.cpp_button_8) @@ -89,9 +101,9 @@ public class KeyboardUi extends BaseKeyboardUi { @Bind(R.id.cpp_button_round_brackets) DirectionDragButton bracketsButton; @Bind(R.id.cpp_button_copy) - ImageButton copyButton; + NumeralBasesButton copyButton; @Bind(R.id.cpp_button_paste) - ImageButton pasteButton; + AngleUnitsButton pasteButton; @Nullable @Bind(R.id.cpp_button_like) ImageButton likeButton; @@ -139,13 +151,14 @@ public class KeyboardUi extends BaseKeyboardUi { prepareButton(button4); prepareButton(button5); prepareButton(button6); - button6.setAngleUnit(angleUnit.getPreference(preferences)); prepareButton(button7); prepareButton(button8); prepareButton(button9); prepareButton(copyButton); + copyButton.setNumeralBase(numeralBase.getPreference(preferences)); prepareButton(pasteButton); + pasteButton.setAngleUnit(angleUnit.getPreference(preferences)); prepareButton(likeButton); prepareButton(memoryButton); @@ -155,12 +168,13 @@ public class KeyboardUi extends BaseKeyboardUi { hideText(button3, up, down); hideText(button4, down); hideText(button5, down); - hideText(button6, up, down); hideText(button7, left, up, down); hideText(button8, left, up, down); hideText(button9, left); hideText(multiplicationButton, left); hideText(plusButton, up, down); + hideText(copyButton, left, up, down); + hideText(pasteButton, left, up, down); } multiplicationButton.setText(engine.getMultiplicationSign()); toggleNumericDigits(); @@ -176,10 +190,11 @@ public class KeyboardUi extends BaseKeyboardUi { public void onSharedPreferenceChanged(SharedPreferences preferences, String key) { super.onSharedPreferenceChanged(preferences, key); if (angleUnit.isSameKey(key)) { - button6.setAngleUnit(angleUnit.getPreference(preferences)); + pasteButton.setAngleUnit(angleUnit.getPreference(preferences)); } if (numeralBase.isSameKey(key)) { toggleNumericDigits(); + copyButton.setNumeralBase(numeralBase.getPreference(preferences)); } if (multiplicationSign.isSameKey(key)) { multiplicationButton.setText(multiplicationSign.getPreference(preferences)); @@ -263,16 +278,18 @@ public class KeyboardUi extends BaseKeyboardUi { return true; } return false; - case R.id.cpp_button_6: - return processAngleUnitsButton(direction, (DirectionDragButton) view); + case R.id.cpp_button_copy: + return processNumeralBaseButton(direction, (DirectionDragView) view); + case R.id.cpp_button_paste: + return processAngleUnitsButton(direction, (DirectionDragView) view); case R.id.cpp_button_round_brackets: if (direction == left) { keyboard.roundBracketsButtonPressed(); return true; } - return processDefault(direction, (DragButton) view); + return processDefault(direction, (DirectionDragView) view); default: - return processDefault(direction, (DragButton) view); + return processDefault(direction, (DirectionDragView) view); } } @@ -306,11 +323,11 @@ public class KeyboardUi extends BaseKeyboardUi { return false; } - private boolean processAngleUnitsButton(@Nonnull DragDirection direction, @Nonnull DirectionDragButton button) { + private boolean processAngleUnitsButton(@Nonnull DragDirection direction, @Nonnull DirectionDragView button) { if (direction == DragDirection.left) { return processDefault(direction, button); } - final String text = button.getTextValue(direction); + final String text = button.getText(direction).getValue(); if (TextUtils.isEmpty(text)) { return processDefault(direction, button); } @@ -327,8 +344,26 @@ public class KeyboardUi extends BaseKeyboardUi { return false; } - private boolean processDefault(@Nonnull DragDirection direction, @Nonnull DragButton button) { - final String text = ((DirectionDragButton) button).getTextValue(direction); + private boolean processDefault(@Nonnull DragDirection direction, @Nonnull DirectionDragView button) { + final String text = button.getText(direction).getValue(); return keyboard.buttonPressed(text); } + + private boolean processNumeralBaseButton(@Nonnull DragDirection direction, @Nonnull DirectionDragView button) { + final String text = button.getText(direction).getValue(); + if (TextUtils.isEmpty(text)) { + return false; + } + try { + final NumeralBase newNumeralBase = NumeralBase.valueOf(text); + final NumeralBase oldNumeralBase = Engine.Preferences.numeralBase.getPreference(preferences); + if (oldNumeralBase != newNumeralBase) { + preferredPreferences.setNumeralBase(newNumeralBase); + return true; + } + } catch (IllegalArgumentException e) { + Log.d(this.getClass().getName(), "Unsupported numeral base: " + text); + } + return false; + } } \ No newline at end of file diff --git a/app/src/main/java/org/solovyev/android/calculator/keyboard/PartialKeyboardUi.java b/app/src/main/java/org/solovyev/android/calculator/keyboard/PartialKeyboardUi.java index 2c98b27c..1e11a8c6 100644 --- a/app/src/main/java/org/solovyev/android/calculator/keyboard/PartialKeyboardUi.java +++ b/app/src/main/java/org/solovyev/android/calculator/keyboard/PartialKeyboardUi.java @@ -6,19 +6,14 @@ import android.content.SharedPreferences; import android.content.res.Configuration; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.text.TextUtils; -import android.util.Log; import android.view.View; +import android.widget.Button; import android.widget.ImageButton; -import butterknife.Bind; -import butterknife.ButterKnife; -import jscl.NumeralBase; -import org.solovyev.android.calculator.Engine; + import org.solovyev.android.calculator.Preferences; import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.buttons.CppSpecialButton; import org.solovyev.android.calculator.view.EditorLongClickEraser; -import org.solovyev.android.calculator.view.NumeralBasesButton; import org.solovyev.android.views.dragbutton.DirectionDragButton; import org.solovyev.android.views.dragbutton.DirectionDragImageButton; import org.solovyev.android.views.dragbutton.DragDirection; @@ -26,10 +21,13 @@ import org.solovyev.android.views.dragbutton.DragDirection; import javax.annotation.Nonnull; import javax.inject.Inject; -import static org.solovyev.android.calculator.Engine.Preferences.numeralBase; +import butterknife.Bind; +import butterknife.ButterKnife; + import static org.solovyev.android.calculator.Preferences.Gui.showEqualsButton; import static org.solovyev.android.calculator.Preferences.Gui.vibrateOnKeypress; -import static org.solovyev.android.views.dragbutton.DragDirection.*; +import static org.solovyev.android.views.dragbutton.DragDirection.down; +import static org.solovyev.android.views.dragbutton.DragDirection.up; public class PartialKeyboardUi extends BaseKeyboardUi { @@ -41,7 +39,7 @@ public class PartialKeyboardUi extends BaseKeyboardUi { DirectionDragImageButton leftButton; @Nullable @Bind(R.id.cpp_button_clear) - NumeralBasesButton clearButton; + Button clearButton; @Nullable @Bind(R.id.cpp_button_erase) ImageButton eraseButton; @@ -64,17 +62,11 @@ public class PartialKeyboardUi extends BaseKeyboardUi { prepareButton(leftButton); prepareButton(equalsButton); prepareButton(clearButton); - if (clearButton != null) { - clearButton.setNumeralBase(numeralBase.getPreference(preferences)); - } if (eraseButton != null) { // backspace button is too big, scale it more prepareButton(eraseButton, IMAGE_SCALE_ERASE); longClickEraser = EditorLongClickEraser.attachTo(eraseButton, keyboard.isVibrateOnKeypress(), editor, calculator); } - if (isSimpleLayout()) { - hideText(clearButton, left, up, down); - } toggleEqualsButton(); } @@ -96,9 +88,6 @@ public class PartialKeyboardUi extends BaseKeyboardUi { @Override public void onSharedPreferenceChanged(SharedPreferences preferences, String key) { super.onSharedPreferenceChanged(preferences, key); - if (clearButton != null && numeralBase.isSameKey(key)) { - clearButton.setNumeralBase(numeralBase.getPreference(preferences)); - } if (equalsButton != null && showEqualsButton.isSameKey(key)) { toggleEqualsButton(); } @@ -126,8 +115,6 @@ public class PartialKeyboardUi extends BaseKeyboardUi { } return false; - case R.id.cpp_button_clear: - return processNumeralBaseButton(direction, (DirectionDragButton) view); } return false; } @@ -152,22 +139,4 @@ public class PartialKeyboardUi extends BaseKeyboardUi { break; } } - - private boolean processNumeralBaseButton(@Nonnull DragDirection direction, @Nonnull DirectionDragButton button) { - final String text = button.getTextValue(direction); - if (TextUtils.isEmpty(text)) { - return false; - } - try { - final NumeralBase newNumeralBase = NumeralBase.valueOf(text); - final NumeralBase oldNumeralBase = Engine.Preferences.numeralBase.getPreference(preferences); - if (oldNumeralBase != newNumeralBase) { - preferredPreferences.setNumeralBase(newNumeralBase); - return true; - } - } catch (IllegalArgumentException e) { - Log.d(this.getClass().getName(), "Unsupported numeral base: " + text); - } - return false; - } } diff --git a/app/src/main/java/org/solovyev/android/calculator/view/AngleUnitsButton.java b/app/src/main/java/org/solovyev/android/calculator/view/AngleUnitsButton.java index 0d0a15d3..cd2285d6 100644 --- a/app/src/main/java/org/solovyev/android/calculator/view/AngleUnitsButton.java +++ b/app/src/main/java/org/solovyev/android/calculator/view/AngleUnitsButton.java @@ -27,7 +27,7 @@ import android.support.v4.content.ContextCompat; import android.util.AttributeSet; import org.solovyev.android.calculator.R; -import org.solovyev.android.views.dragbutton.DirectionDragButton; +import org.solovyev.android.views.dragbutton.DirectionDragImageButton; import org.solovyev.android.views.dragbutton.DirectionTextView; import org.solovyev.android.views.dragbutton.DragDirection; @@ -35,7 +35,7 @@ import javax.annotation.Nonnull; import jscl.AngleUnit; -public class AngleUnitsButton extends DirectionDragButton { +public class AngleUnitsButton extends DirectionDragImageButton { @Nonnull private AngleUnit angleUnit = AngleUnit.deg; diff --git a/app/src/main/java/org/solovyev/android/calculator/view/NumeralBasesButton.java b/app/src/main/java/org/solovyev/android/calculator/view/NumeralBasesButton.java index 21db2460..23da915e 100644 --- a/app/src/main/java/org/solovyev/android/calculator/view/NumeralBasesButton.java +++ b/app/src/main/java/org/solovyev/android/calculator/view/NumeralBasesButton.java @@ -27,7 +27,7 @@ import android.support.v4.content.ContextCompat; import android.util.AttributeSet; import org.solovyev.android.calculator.R; -import org.solovyev.android.views.dragbutton.DirectionDragButton; +import org.solovyev.android.views.dragbutton.DirectionDragImageButton; import org.solovyev.android.views.dragbutton.DirectionTextView; import org.solovyev.android.views.dragbutton.DragDirection; @@ -35,7 +35,7 @@ import javax.annotation.Nonnull; import jscl.NumeralBase; -public class NumeralBasesButton extends DirectionDragButton { +public class NumeralBasesButton extends DirectionDragImageButton { @Nonnull private NumeralBase numeralBase = NumeralBase.dec; diff --git a/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragButton.java b/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragButton.java index aa22ff0d..75338e8d 100644 --- a/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragButton.java +++ b/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragButton.java @@ -10,7 +10,7 @@ import android.util.AttributeSet; import javax.annotation.Nonnull; -public class DirectionDragButton extends DragButton { +public class DirectionDragButton extends DragButton implements DirectionDragView { private final DirectionTextView textView = new DirectionTextView(); @NonNull private final TextPaint baseTextPaint = new TextPaint(); @@ -69,8 +69,9 @@ public class DirectionDragButton extends DragButton { return this; } + @Override @Nonnull - protected DirectionTextView.Text getText(@NonNull DragDirection direction) { + public DirectionTextView.Text getText(@NonNull DragDirection direction) { return textView.getText(direction); } diff --git a/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragImageButton.java b/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragImageButton.java index 37eb9298..58bda9eb 100644 --- a/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragImageButton.java +++ b/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragImageButton.java @@ -11,7 +11,7 @@ import android.widget.TextView; import javax.annotation.Nonnull; -public class DirectionDragImageButton extends DragImageButton { +public class DirectionDragImageButton extends DragImageButton implements DirectionDragView { private final DirectionTextView textView = new DirectionTextView(); private final TextPaint baseTextPaint = new TextPaint(); @@ -48,7 +48,7 @@ public class DirectionDragImageButton extends DragImageButton { } @Nonnull - protected DirectionTextView.Text getText(@NonNull DragDirection direction) { + public DirectionTextView.Text getText(@NonNull DragDirection direction) { return textView.getText(direction); } diff --git a/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragView.java b/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragView.java new file mode 100644 index 00000000..9ab28fe3 --- /dev/null +++ b/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragView.java @@ -0,0 +1,10 @@ +package org.solovyev.android.views.dragbutton; + +import android.support.annotation.NonNull; + +import javax.annotation.Nonnull; + +public interface DirectionDragView extends DragView { + @Nonnull + DirectionTextView.Text getText(@NonNull DragDirection direction); +} diff --git a/app/src/main/java/org/solovyev/android/views/dragbutton/DragView.java b/app/src/main/java/org/solovyev/android/views/dragbutton/DragView.java index bb2804c3..a7a139d5 100644 --- a/app/src/main/java/org/solovyev/android/views/dragbutton/DragView.java +++ b/app/src/main/java/org/solovyev/android/views/dragbutton/DragView.java @@ -4,6 +4,5 @@ import android.support.annotation.Nullable; public interface DragView { void setOnDragListener(@Nullable DragListener listener); - void setVibrateOnDrag(boolean vibrateOnDrag); } diff --git a/app/src/main/res/layout/cpp_app_button_6.xml b/app/src/main/res/layout/cpp_app_button_6.xml index 9be66957..de56b116 100644 --- a/app/src/main/res/layout/cpp_app_button_6.xml +++ b/app/src/main/res/layout/cpp_app_button_6.xml @@ -22,14 +22,12 @@ ~ Site: http://se.solovyev.org --> - \ No newline at end of file diff --git a/app/src/main/res/layout/cpp_app_button_clear.xml b/app/src/main/res/layout/cpp_app_button_clear.xml index 2aba7467..f274f6c8 100644 --- a/app/src/main/res/layout/cpp_app_button_clear.xml +++ b/app/src/main/res/layout/cpp_app_button_clear.xml @@ -22,13 +22,9 @@ ~ Site: http://se.solovyev.org --> - \ No newline at end of file + a:textStyle="bold"/> \ No newline at end of file diff --git a/app/src/main/res/layout/cpp_app_button_copy.xml b/app/src/main/res/layout/cpp_app_button_copy.xml index e0ab4c8a..c428c99a 100644 --- a/app/src/main/res/layout/cpp_app_button_copy.xml +++ b/app/src/main/res/layout/cpp_app_button_copy.xml @@ -22,8 +22,13 @@ ~ Site: http://se.solovyev.org --> - \ No newline at end of file + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + android:src="@drawable/ic_content_copy_white_48dp" + app:directionTextScale="@dimen/cpp_direction_text_scale_units" + app:directionTextDown="bin" + app:directionTextLeft="hex" + app:directionTextUp="dec"/> \ No newline at end of file diff --git a/app/src/main/res/layout/cpp_app_button_paste.xml b/app/src/main/res/layout/cpp_app_button_paste.xml index 055fe940..ab4e4e1b 100644 --- a/app/src/main/res/layout/cpp_app_button_paste.xml +++ b/app/src/main/res/layout/cpp_app_button_paste.xml @@ -22,8 +22,12 @@ ~ Site: http://se.solovyev.org --> - \ No newline at end of file + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + app:directionTextScale="@dimen/cpp_direction_text_scale_units" + android:src="@drawable/ic_content_paste_white_48dp" + app:directionTextDown="rad" + app:directionTextUp="deg"/> \ No newline at end of file diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 2fc75e09..2f979705 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -11,6 +11,7 @@ 2dp 9dp 0.45 + 0.35 1dp 4dp