Reimplement drag button

This commit is contained in:
serso 2016-03-08 17:23:53 +01:00
parent fe8f99491d
commit 56d1d2b249
55 changed files with 849 additions and 360 deletions

View File

@ -71,7 +71,6 @@ dependencies {
exclude group: 'org.json' exclude group: 'org.json'
} }
compile ':measure:' compile ':measure:'
compile ':drag-button:1.1@aar'
compile ':square-otto:1.3.9-SNAPSHOT' compile ':square-otto:1.3.9-SNAPSHOT'
apt ':square-otto-compiler:1.3.9-SNAPSHOT' apt ':square-otto-compiler:1.3.9-SNAPSHOT'
apt 'com.squareup:javapoet:1.5.1' apt 'com.squareup:javapoet:1.5.1'

Binary file not shown.

View File

@ -1,107 +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.keyboard.KeyboardUi;
import org.solovyev.android.views.dragbutton.DirectionDragButton;
import org.solovyev.android.views.dragbutton.DragDirection;
import jscl.NumeralBase;
import javax.annotation.Nonnull;
public enum CppNumeralBase {
bin(NumeralBase.bin) {
@Override
public void toggleButtons(boolean show, @Nonnull KeyboardUi ui) {
toggleButton(show, ui.button0);
toggleButton(show, ui.button1);
}
},
oct(NumeralBase.oct) {
@Override
public void toggleButtons(boolean show, @Nonnull KeyboardUi ui) {
bin.toggleButtons(show, ui);
toggleButton(show, ui.button2);
toggleButton(show, ui.button3);
toggleButton(show, ui.button4);
toggleButton(show, ui.button5);
toggleButton(show, ui.button6);
toggleButton(show, ui.button7);
}
},
dec(NumeralBase.dec) {
@Override
public void toggleButtons(boolean show, @Nonnull KeyboardUi ui) {
oct.toggleButtons(show, ui);
toggleButton(show, ui.button8);
toggleButton(show, ui.button9);
}
},
hex(NumeralBase.hex) {
@Override
public void toggleButtons(boolean show, @Nonnull KeyboardUi ui) {
dec.toggleButtons(show, ui);
toggleLeftButton(show, ui.button1);
toggleLeftButton(show, ui.button2);
toggleLeftButton(show, ui.button3);
toggleLeftButton(show, ui.button4);
toggleLeftButton(show, ui.button5);
toggleLeftButton(show, ui.button6);
}
protected final void toggleLeftButton(boolean show, @Nonnull DirectionDragButton button) {
button.showDirectionText(show, DragDirection.left);
button.invalidate();
}
};
@Nonnull
public final NumeralBase numeralBase;
CppNumeralBase(@Nonnull NumeralBase numeralBase) {
this.numeralBase = numeralBase;
}
@Nonnull
public static CppNumeralBase valueOf(@Nonnull NumeralBase nb) {
for (CppNumeralBase cppNumeralBase : values()) {
if (cppNumeralBase.numeralBase == nb) {
return cppNumeralBase;
}
}
throw new IllegalArgumentException(nb + " is not supported numeral base!");
}
public abstract void toggleButtons(boolean show, @Nonnull KeyboardUi ui);
protected final void toggleButton(boolean show, @Nonnull DirectionDragButton button) {
button.setShowText(show);
button.invalidate();
}
}

View File

@ -1,10 +1,8 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import android.graphics.PointF;
import android.support.annotation.IdRes; import android.support.annotation.IdRes;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.LinearLayout; import android.widget.LinearLayout;
@ -12,15 +10,15 @@ import org.solovyev.android.calculator.keyboard.BaseFloatingKeyboard;
import org.solovyev.android.calculator.keyboard.FloatingKeyboard; import org.solovyev.android.calculator.keyboard.FloatingKeyboard;
import org.solovyev.android.calculator.view.EditTextLongClickEraser; import org.solovyev.android.calculator.view.EditTextLongClickEraser;
import org.solovyev.android.views.dragbutton.DirectionDragButton; import org.solovyev.android.views.dragbutton.DirectionDragButton;
import org.solovyev.android.views.dragbutton.DragButton; import org.solovyev.android.views.dragbutton.DirectionDragListener;
import org.solovyev.android.views.dragbutton.DragDirection; import org.solovyev.android.views.dragbutton.DragDirection;
import org.solovyev.android.views.dragbutton.SimpleDragListener; import org.solovyev.android.views.dragbutton.DragEvent;
import java.util.List; import java.util.List;
import static android.view.HapticFeedbackConstants.*; import static android.view.HapticFeedbackConstants.*;
import static org.solovyev.android.views.dragbutton.DirectionDragButton.Direction.down; import static org.solovyev.android.views.dragbutton.DragDirection.down;
import static org.solovyev.android.views.dragbutton.DirectionDragButton.Direction.up; import static org.solovyev.android.views.dragbutton.DragDirection.up;
public class FloatingCalculatorKeyboard extends BaseFloatingKeyboard { public class FloatingCalculatorKeyboard extends BaseFloatingKeyboard {
@ -29,12 +27,17 @@ public class FloatingCalculatorKeyboard extends BaseFloatingKeyboard {
@NonNull @NonNull
private final List<String> parameterNames; private final List<String> parameterNames;
@NonNull @NonNull
private final SimpleDragListener dragListener; private final DirectionDragListener dragListener;
public FloatingCalculatorKeyboard(@NonNull User user, @NonNull List<String> parameterNames) { public FloatingCalculatorKeyboard(@NonNull User user, @NonNull List<String> parameterNames) {
super(user); super(user);
this.parameterNames = parameterNames; this.parameterNames = parameterNames;
this.dragListener = new SimpleDragListener(buttonHandler, user.getContext()); this.dragListener = new DirectionDragListener(user.getContext()) {
@Override
protected boolean onDrag(@NonNull View view, @NonNull DragEvent event, @NonNull DragDirection direction) {
return buttonHandler.onDrag(view, direction);
}
};
} }
public void makeView(boolean landscape) { public void makeView(boolean landscape) {
@ -73,29 +76,29 @@ public class FloatingCalculatorKeyboard extends BaseFloatingKeyboard {
addButton(row, 0, parametersCount > 0 ? parameterNames.get(0) : "x"); addButton(row, 0, parametersCount > 0 ? parameterNames.get(0) : "x");
addButton(row, 0, "7"); addButton(row, 0, "7");
addButton(row, 0, "8"); addButton(row, 0, "8");
addButton(row, 0, "9").setText("π", up).setText("e", down); addButton(row, 0, "9").setText(up, "π").setText(down, "e");
addOperationButton(row, R.id.cpp_kb_button_multiply, "×").setText("^n", up).setText("^2", down); addOperationButton(row, R.id.cpp_kb_button_multiply, "×").setText(up, "^n").setText(down, "^2");
addOperationButton(row, R.id.cpp_kb_button_plus, "+"); addOperationButton(row, R.id.cpp_kb_button_plus, "+");
addButton(row, R.id.cpp_kb_button_clear, "C"); addButton(row, R.id.cpp_kb_button_clear, "C");
row = makeRow(); row = makeRow();
addButton(row, R.id.cpp_kb_button_brackets, "( )").setText("(", up).setText(")", down); addButton(row, R.id.cpp_kb_button_brackets, "( )").setText(up, "(").setText(down, ")");
addButton(row, 0, parametersCount > 1 ? parameterNames.get(1) : "y"); addButton(row, 0, parametersCount > 1 ? parameterNames.get(1) : "y");
addButton(row, 0, "4"); addButton(row, 0, "4");
addButton(row, 0, "5"); addButton(row, 0, "5");
addButton(row, 0, "6"); addButton(row, 0, "6");
addOperationButton(row, R.id.cpp_kb_button_divide, "/").setText("%", up).setText("sqrt", down); addOperationButton(row, R.id.cpp_kb_button_divide, "/").setText(up, "%").setText(down, "sqrt");
addOperationButton(row, R.id.cpp_kb_button_minus, ""); addOperationButton(row, R.id.cpp_kb_button_minus, "");
final View backspace = addImageButton(row, R.id.cpp_kb_button_backspace, R.drawable.ic_backspace_grey300_24dp); final View backspace = addImageButton(row, R.id.cpp_kb_button_backspace, R.drawable.ic_backspace_grey300_24dp);
EditTextLongClickEraser.attachTo(backspace, user.getEditor(), user.isVibrateOnKeypress()); EditTextLongClickEraser.attachTo(backspace, user.getEditor(), user.isVibrateOnKeypress());
row = makeRow(); row = makeRow();
addButton(row, R.id.cpp_kb_button_functions_constants, "f/π"); addButton(row, R.id.cpp_kb_button_functions_constants, "f/π");
addButton(row, 0, ".").setText(",", up); addButton(row, 0, ".").setText(up, ",");
addButton(row, 0, "1"); addButton(row, 0, "1");
addButton(row, 0, "2"); addButton(row, 0, "2");
addButton(row, 0, "3"); addButton(row, 0, "3");
addButton(row, 0, "0").setText("00", up).setText("000", down); addButton(row, 0, "0").setText(up, "00").setText(down, "000");
addImageButton(row, R.id.cpp_kb_button_space, R.drawable.ic_space_bar_grey300_24dp); addImageButton(row, R.id.cpp_kb_button_space, R.drawable.ic_space_bar_grey300_24dp);
addImageButton(row, R.id.cpp_kb_button_close, R.drawable.ic_done_grey300_24dp); addImageButton(row, R.id.cpp_kb_button_close, R.drawable.ic_done_grey300_24dp);
} }
@ -104,15 +107,15 @@ public class FloatingCalculatorKeyboard extends BaseFloatingKeyboard {
LinearLayout row = makeRow(); LinearLayout row = makeRow();
addButton(row, 0, "7"); addButton(row, 0, "7");
addButton(row, 0, "8"); addButton(row, 0, "8");
addButton(row, 0, "9").setText("π", up).setText("e", down); addButton(row, 0, "9").setText(up, "π").setText(down, "e");
addOperationButton(row, R.id.cpp_kb_button_multiply, "×").setText("^n", up).setText("^2", down); addOperationButton(row, R.id.cpp_kb_button_multiply, "×").setText(up, "^n").setText(down, "^2");
addButton(row, R.id.cpp_kb_button_clear, "C"); addButton(row, R.id.cpp_kb_button_clear, "C");
row = makeRow(); row = makeRow();
addButton(row, 0, "4"); addButton(row, 0, "4");
addButton(row, 0, "5"); addButton(row, 0, "5");
addButton(row, 0, "6"); addButton(row, 0, "6");
addOperationButton(row, R.id.cpp_kb_button_divide, "/").setText("%", up).setText("sqrt", down); addOperationButton(row, R.id.cpp_kb_button_divide, "/").setText(up, "%").setText(down, "sqrt");
final View backspace = addImageButton(row, R.id.cpp_kb_button_backspace, R.drawable.ic_backspace_grey300_24dp); final View backspace = addImageButton(row, R.id.cpp_kb_button_backspace, R.drawable.ic_backspace_grey300_24dp);
EditTextLongClickEraser.attachTo(backspace, user.getEditor(), user.isVibrateOnKeypress()); EditTextLongClickEraser.attachTo(backspace, user.getEditor(), user.isVibrateOnKeypress());
@ -124,9 +127,9 @@ public class FloatingCalculatorKeyboard extends BaseFloatingKeyboard {
addImageButton(row, R.id.cpp_kb_button_space, R.drawable.ic_space_bar_grey300_24dp); addImageButton(row, R.id.cpp_kb_button_space, R.drawable.ic_space_bar_grey300_24dp);
row = makeRow(); row = makeRow();
addButton(row, R.id.cpp_kb_button_brackets, "( )").setText("(", up).setText(")", down); addButton(row, R.id.cpp_kb_button_brackets, "( )").setText(up, "(").setText(down, ")");
addButton(row, 0, "0").setText("00", up).setText("000", down); addButton(row, 0, "0").setText(up, "00").setText(down, "000");
addButton(row, 0, ".").setText(",", up); addButton(row, 0, ".").setText(up, ",");
addOperationButton(row, R.id.cpp_kb_button_minus, ""); addOperationButton(row, R.id.cpp_kb_button_minus, "");
addImageButton(row, R.id.cpp_kb_button_keyboard, R.drawable.ic_keyboard_grey300_24dp); addImageButton(row, R.id.cpp_kb_button_keyboard, R.drawable.ic_keyboard_grey300_24dp);
@ -163,7 +166,7 @@ public class FloatingCalculatorKeyboard extends BaseFloatingKeyboard {
} }
private class ButtonHandler implements View.OnClickListener, SimpleDragListener.DragProcessor { private class ButtonHandler implements View.OnClickListener {
@NonNull @NonNull
private final User user = getUser(); private final User user = getUser();
@ -222,16 +225,8 @@ public class FloatingCalculatorKeyboard extends BaseFloatingKeyboard {
user.insertText(((Button) v).getText(), 0); user.insertText(((Button) v).getText(), 0);
} }
@Override private boolean onDrag(@NonNull View button, @NonNull DragDirection direction) {
public boolean processDragEvent(@NonNull DragDirection direction, @NonNull DragButton button, @NonNull PointF startPoint, @NonNull MotionEvent e) { final String text = ((DirectionDragButton) button).getTextValue(direction);
switch (button.getId()) {
default:
return onDefaultDrag(button, direction);
}
}
private boolean onDefaultDrag(@NonNull DragButton button, @NonNull DragDirection direction) {
final String text = ((DirectionDragButton) button).getText(direction);
if (TextUtils.isEmpty(text)) { if (TextUtils.isEmpty(text)) {
return false; return false;
} }

View File

@ -104,7 +104,6 @@ public abstract class BaseFloatingKeyboard implements FloatingKeyboard {
final DirectionDragButton button = addButton(row, id, text); final DirectionDragButton button = addButton(row, id, text);
button.setBackgroundResource(R.drawable.material_button_light_primary); button.setBackgroundResource(R.drawable.material_button_light_primary);
button.setTextColor(Color.WHITE); button.setTextColor(Color.WHITE);
button.setDirectionTextColor(Color.WHITE);
return button; return button;
} }

View File

@ -12,26 +12,38 @@ import android.util.TypedValue;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; 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.calculator.buttons.CppSpecialButton;
import org.solovyev.android.views.Adjuster; import org.solovyev.android.views.Adjuster;
import org.solovyev.android.views.dragbutton.DirectionDragButton; import org.solovyev.android.views.dragbutton.DirectionDragButton;
import org.solovyev.android.views.dragbutton.DirectionDragListener;
import org.solovyev.android.views.dragbutton.DragButton; import org.solovyev.android.views.dragbutton.DragButton;
import org.solovyev.android.views.dragbutton.DragDirection; import org.solovyev.android.views.dragbutton.DragDirection;
import org.solovyev.android.views.dragbutton.SimpleDragListener; import org.solovyev.android.views.dragbutton.DragEvent;
import javax.annotation.Nonnull;
import javax.inject.Inject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.annotation.Nonnull;
import javax.inject.Inject;
import static android.content.res.Configuration.ORIENTATION_PORTRAIT; 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.App.cast;
import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple; import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple;
import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple_mobile; import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple_mobile;
public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPreferenceChangeListener, SimpleDragListener.DragProcessor, View.OnClickListener { public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPreferenceChangeListener, View.OnClickListener {
public static float getTextScale(@NonNull Context context) { public static float getTextScale(@NonNull Context context) {
return App.isTablet(context) ? 0.4f : 0.5f; return App.isTablet(context) ? 0.4f : 0.5f;
@ -43,7 +55,7 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer
@NonNull @NonNull
private final List<DragButton> dragButtons = new ArrayList<>(); private final List<DragButton> dragButtons = new ArrayList<>();
@NonNull @NonNull
protected final SimpleDragListener listener; protected final DirectionDragListener listener;
@Inject @Inject
SharedPreferences preferences; SharedPreferences preferences;
@Inject @Inject
@ -64,7 +76,12 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer
private final float textScale; private final float textScale;
public BaseKeyboardUi(@NonNull Application application) { public BaseKeyboardUi(@NonNull Application application) {
listener = new SimpleDragListener(this, application); listener = new DirectionDragListener(application) {
@Override
protected boolean onDrag(@NonNull View view, @NonNull DragEvent event, @NonNull DragDirection direction) {
return BaseKeyboardUi.this.onDrag(view, direction);
}
};
textScale = getTextScale(application); textScale = getTextScale(application);
} }
@ -76,6 +93,8 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer
} }
} }
protected abstract boolean onDrag(@NonNull View view, @NonNull DragDirection direction);
public void onCreateView(@Nonnull Activity activity, @Nonnull View view) { public void onCreateView(@Nonnull Activity activity, @Nonnull View view) {
cast(activity.getApplication()).getComponent().inject(this); cast(activity.getApplication()).getComponent().inject(this);
preferences.registerOnSharedPreferenceChangeListener(this); preferences.registerOnSharedPreferenceChangeListener(this);
@ -132,7 +151,7 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer
if (button == null) { if (button == null) {
return; return;
} }
button.showDirectionText(false, direction); button.setShowDirectionText(direction, false);
} }
public void onDestroyView() { public void onDestroyView() {

View File

@ -3,20 +3,15 @@ package org.solovyev.android.calculator.keyboard;
import android.app.Activity; import android.app.Activity;
import android.app.Application; import android.app.Application;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.PointF; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageButton; import android.widget.ImageButton;
import butterknife.Bind;
import butterknife.ButterKnife;
import jscl.AngleUnit;
import jscl.NumeralBase;
import org.solovyev.android.calculator.ActivityLauncher; import org.solovyev.android.calculator.ActivityLauncher;
import org.solovyev.android.calculator.CppNumeralBase;
import org.solovyev.android.calculator.Engine; import org.solovyev.android.calculator.Engine;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.buttons.CppSpecialButton; import org.solovyev.android.calculator.buttons.CppSpecialButton;
@ -29,8 +24,17 @@ import org.solovyev.android.views.dragbutton.DragDirection;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.inject.Inject; import javax.inject.Inject;
import static org.solovyev.android.calculator.Engine.Preferences.*; import butterknife.Bind;
import static org.solovyev.android.views.dragbutton.DragDirection.*; import butterknife.ButterKnife;
import jscl.AngleUnit;
import jscl.NumeralBase;
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 { public class KeyboardUi extends BaseKeyboardUi {
@ -97,17 +101,13 @@ public class KeyboardUi extends BaseKeyboardUi {
} }
public void toggleNumericDigits() { public void toggleNumericDigits() {
toggleNumericDigits(numeralBase.getPreference(preferences)); final boolean hex = numeralBase.getPreference(preferences) == NumeralBase.hex;
} button1.setShowDirectionText(left, hex);
button2.setShowDirectionText(left, hex);
public void toggleNumericDigits(@Nonnull NumeralBase currentNumeralBase) { button3.setShowDirectionText(left, hex);
for (NumeralBase numeralBase : NumeralBase.values()) { button4.setShowDirectionText(left, hex);
if (currentNumeralBase != numeralBase) { button5.setShowDirectionText(left, hex);
CppNumeralBase.valueOf(numeralBase).toggleButtons(false, this); button6.setShowDirectionText(left, hex);
}
}
CppNumeralBase.valueOf(currentNumeralBase).toggleButtons(true, this);
} }
public void onCreateView(@Nonnull Activity activity, @Nonnull View view) { public void onCreateView(@Nonnull Activity activity, @Nonnull View view) {
@ -227,8 +227,8 @@ public class KeyboardUi extends BaseKeyboardUi {
} }
@Override @Override
public boolean processDragEvent(@Nonnull DragDirection direction, @Nonnull DragButton button, @Nonnull PointF point, @Nonnull MotionEvent event) { protected boolean onDrag(@NonNull View view, @NonNull DragDirection direction) {
switch (button.getId()) { switch (view.getId()) {
case R.id.cpp_button_vars: case R.id.cpp_button_vars:
launcher.showConstantEditor(); launcher.showConstantEditor();
return true; return true;
@ -254,15 +254,15 @@ public class KeyboardUi extends BaseKeyboardUi {
} }
return false; return false;
case R.id.cpp_button_6: case R.id.cpp_button_6:
return processAngleUnitsButton(direction, (DirectionDragButton) button); return processAngleUnitsButton(direction, (DirectionDragButton) view);
case R.id.cpp_button_round_brackets: case R.id.cpp_button_round_brackets:
if (direction == left) { if (direction == left) {
keyboard.roundBracketsButtonPressed(); keyboard.roundBracketsButtonPressed();
return true; return true;
} }
return processDefault(direction, button); return processDefault(direction, (DragButton) view);
default: default:
return processDefault(direction, button); return processDefault(direction, (DragButton) view);
} }
} }
@ -270,7 +270,7 @@ public class KeyboardUi extends BaseKeyboardUi {
if (direction == DragDirection.left) { if (direction == DragDirection.left) {
return processDefault(direction, button); return processDefault(direction, button);
} }
final String text = button.getText(direction); final String text = button.getTextValue(direction);
if (TextUtils.isEmpty(text)) { if (TextUtils.isEmpty(text)) {
return processDefault(direction, button); return processDefault(direction, button);
} }
@ -288,7 +288,7 @@ public class KeyboardUi extends BaseKeyboardUi {
} }
private boolean processDefault(@Nonnull DragDirection direction, @Nonnull DragButton button) { private boolean processDefault(@Nonnull DragDirection direction, @Nonnull DragButton button) {
final String text = ((DirectionDragButton) button).getText(direction); final String text = ((DirectionDragButton) button).getTextValue(direction);
return keyboard.buttonPressed(text); return keyboard.buttonPressed(text);
} }
} }

View File

@ -4,12 +4,10 @@ import android.app.Activity;
import android.app.Application; import android.app.Application;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.graphics.PointF;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageButton; import android.widget.ImageButton;
@ -21,7 +19,6 @@ import org.solovyev.android.calculator.buttons.CppSpecialButton;
import org.solovyev.android.calculator.view.EditorLongClickEraser; import org.solovyev.android.calculator.view.EditorLongClickEraser;
import org.solovyev.android.calculator.view.NumeralBasesButton; import org.solovyev.android.calculator.view.NumeralBasesButton;
import org.solovyev.android.views.dragbutton.DirectionDragButton; import org.solovyev.android.views.dragbutton.DirectionDragButton;
import org.solovyev.android.views.dragbutton.DragButton;
import org.solovyev.android.views.dragbutton.DragDirection; import org.solovyev.android.views.dragbutton.DragDirection;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -115,8 +112,8 @@ public class PartialKeyboardUi extends BaseKeyboardUi {
} }
@Override @Override
public boolean processDragEvent(@Nonnull DragDirection direction, @Nonnull DragButton button, @Nonnull PointF point, @Nonnull MotionEvent event) { protected boolean onDrag(@NonNull View view, @NonNull DragDirection direction) {
switch (button.getId()) { switch (view.getId()) {
case R.id.cpp_button_right: case R.id.cpp_button_right:
editor.setCursorOnEnd(); editor.setCursorOnEnd();
return true; return true;
@ -134,7 +131,7 @@ public class PartialKeyboardUi extends BaseKeyboardUi {
return false; return false;
case R.id.cpp_button_clear: case R.id.cpp_button_clear:
return processNumeralBaseButton(direction, (DirectionDragButton) button); return processNumeralBaseButton(direction, (DirectionDragButton) view);
} }
return false; return false;
} }
@ -159,7 +156,7 @@ public class PartialKeyboardUi extends BaseKeyboardUi {
} }
private boolean processNumeralBaseButton(@Nonnull DragDirection direction, @Nonnull DirectionDragButton button) { private boolean processNumeralBaseButton(@Nonnull DragDirection direction, @Nonnull DirectionDragButton button) {
final String text = button.getText(direction); final String text = button.getTextValue(direction);
if (TextUtils.isEmpty(text)) { if (TextUtils.isEmpty(text)) {
return false; return false;
} }

View File

@ -23,16 +23,18 @@
package org.solovyev.android.calculator.view; package org.solovyev.android.calculator.view;
import android.content.Context; import android.content.Context;
import android.graphics.Paint;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.text.TextPaint;
import android.util.AttributeSet; import android.util.AttributeSet;
import jscl.AngleUnit;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import org.solovyev.android.views.dragbutton.DirectionDragButton; import org.solovyev.android.views.dragbutton.DirectionDragButton;
import org.solovyev.android.views.dragbutton.DirectionTextView;
import org.solovyev.android.views.dragbutton.DragDirection;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import jscl.AngleUnit;
public class AngleUnitsButton extends DirectionDragButton { public class AngleUnitsButton extends DirectionDragButton {
@Nonnull @Nonnull
@ -40,37 +42,29 @@ public class AngleUnitsButton extends DirectionDragButton {
public AngleUnitsButton(Context context, @Nonnull AttributeSet attrs) { public AngleUnitsButton(Context context, @Nonnull AttributeSet attrs) {
super(context, attrs); super(context, attrs);
} updateDirectionColors();
@Override
protected void initDirectionTextPaint(@Nonnull Paint basePaint, @Nonnull DirectionTextData textData) {
super.initDirectionTextPaint(basePaint, textData);
final String text = textData.getText();
final TextPaint paint = textData.getPaint();
final int color = getDirectionTextColor(text);
paint.setColor(color);
if (!isCurrentAngleUnits(text)) {
paint.setAlpha(directionTextAlpha);
}
}
int getDirectionTextColor(@Nonnull String directionText) {
if (isCurrentAngleUnits(directionText)) {
return ContextCompat.getColor(getContext(), R.color.cpp_selected_angle_unit_text);
}
return ContextCompat.getColor(getContext(), R.color.cpp_text);
} }
boolean isCurrentAngleUnits(@Nonnull String directionText) { boolean isCurrentAngleUnits(@Nonnull String directionText) {
return this.angleUnit.name().equals(directionText); return angleUnit.name().equals(directionText);
} }
public void setAngleUnit(@Nonnull AngleUnit angleUnit) { public void setAngleUnit(@Nonnull AngleUnit angleUnit) {
if (this.angleUnit != angleUnit) { if (this.angleUnit == angleUnit) {
return;
}
this.angleUnit = angleUnit; this.angleUnit = angleUnit;
invalidate(); updateDirectionColors();
}
private void updateDirectionColors() {
for (DragDirection direction : DragDirection.values()) {
final DirectionTextView.Text text = getText(direction);
if (isCurrentAngleUnits(text.getValue())) {
text.setColor(ContextCompat.getColor(getContext(), R.color.cpp_selected_angle_unit_text), 1f);
} else {
text.setColor(ContextCompat.getColor(getContext(), R.color.cpp_text), DirectionTextView.DEF_ALPHA);
}
} }
} }
} }

View File

@ -23,16 +23,18 @@
package org.solovyev.android.calculator.view; package org.solovyev.android.calculator.view;
import android.content.Context; import android.content.Context;
import android.graphics.Paint;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.text.TextPaint;
import android.util.AttributeSet; import android.util.AttributeSet;
import jscl.NumeralBase;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import org.solovyev.android.views.dragbutton.DirectionDragButton; import org.solovyev.android.views.dragbutton.DirectionDragButton;
import org.solovyev.android.views.dragbutton.DirectionTextView;
import org.solovyev.android.views.dragbutton.DragDirection;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import jscl.NumeralBase;
public class NumeralBasesButton extends DirectionDragButton { public class NumeralBasesButton extends DirectionDragButton {
@Nonnull @Nonnull
@ -40,31 +42,11 @@ public class NumeralBasesButton extends DirectionDragButton {
public NumeralBasesButton(Context context, @Nonnull AttributeSet attrs) { public NumeralBasesButton(Context context, @Nonnull AttributeSet attrs) {
super(context, attrs); super(context, attrs);
} updateDirectionColors();
@Override
protected void initDirectionTextPaint(@Nonnull Paint basePaint, @Nonnull DirectionTextData textData) {
super.initDirectionTextPaint(basePaint, textData);
final String text = textData.getText();
final TextPaint paint = textData.getPaint();
final int color = getDirectionTextColor(text);
paint.setColor(color);
if (!isCurrentNumberBase(text)) {
paint.setAlpha(directionTextAlpha);
}
}
int getDirectionTextColor(@Nonnull String directionText) {
if (isCurrentNumberBase(directionText)) {
return ContextCompat.getColor(getContext(), R.color.cpp_selected_angle_unit_text);
}
return ContextCompat.getColor(getContext(), R.color.cpp_text);
} }
boolean isCurrentNumberBase(@Nonnull String directionText) { boolean isCurrentNumberBase(@Nonnull String directionText) {
return this.numeralBase.name().equals(directionText); return numeralBase.name().equals(directionText);
} }
public void setNumeralBase(@Nonnull NumeralBase numeralBase) { public void setNumeralBase(@Nonnull NumeralBase numeralBase) {
@ -72,6 +54,17 @@ public class NumeralBasesButton extends DirectionDragButton {
return; return;
} }
this.numeralBase = numeralBase; this.numeralBase = numeralBase;
invalidate(); updateDirectionColors();
}
private void updateDirectionColors() {
for (DragDirection direction : DragDirection.values()) {
final DirectionTextView.Text text = getText(direction);
if (isCurrentNumberBase(text.getValue())) {
text.setColor(ContextCompat.getColor(getContext(), R.color.cpp_selected_angle_unit_text), 1f);
} else {
text.setColor(ContextCompat.getColor(getContext(), R.color.cpp_text), DirectionTextView.DEF_ALPHA);
}
}
} }
} }

View File

@ -35,7 +35,7 @@ import javax.annotation.Nonnull;
import static org.solovyev.android.calculator.wizard.CalculatorMode.engineer; import static org.solovyev.android.calculator.wizard.CalculatorMode.engineer;
import static org.solovyev.android.calculator.wizard.CalculatorMode.simple; import static org.solovyev.android.calculator.wizard.CalculatorMode.simple;
import static org.solovyev.android.views.dragbutton.DirectionDragButton.Direction.*; import static org.solovyev.android.views.dragbutton.DragDirection.*;
public class ChooseModeWizardStep extends WizardFragment implements AdapterView.OnItemSelectedListener { public class ChooseModeWizardStep extends WizardFragment implements AdapterView.OnItemSelectedListener {
@ -66,13 +66,13 @@ public class ChooseModeWizardStep extends WizardFragment implements AdapterView.
boolean simple = mode == CalculatorMode.simple; boolean simple = mode == CalculatorMode.simple;
description.setText(simple ? R.string.cpp_wizard_mode_simple_description : R.string.cpp_wizard_mode_engineer_description); description.setText(simple ? R.string.cpp_wizard_mode_simple_description : R.string.cpp_wizard_mode_engineer_description);
if (simple) { if (simple) {
button.setText("", up); button.setText(up, "");
button.setText("", down); button.setText(down, "");
button.setText("", left); button.setText(left, "");
} else { } else {
button.setText("sin", up); button.setText(up, "sin");
button.setText("ln", down); button.setText(down, "ln");
button.setText("i", left); button.setText(left, "i");
} }
} }

View File

@ -22,12 +22,9 @@
package org.solovyev.android.calculator.wizard; package org.solovyev.android.calculator.wizard;
import static org.solovyev.android.calculator.App.cast;
import android.graphics.PointF;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.os.Bundle; import android.os.Bundle;
import android.view.MotionEvent; import android.support.annotation.NonNull;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
@ -36,16 +33,17 @@ import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.keyboard.BaseKeyboardUi; import org.solovyev.android.calculator.keyboard.BaseKeyboardUi;
import org.solovyev.android.views.Adjuster; import org.solovyev.android.views.Adjuster;
import org.solovyev.android.views.dragbutton.DirectionDragButton; import org.solovyev.android.views.dragbutton.DirectionDragButton;
import org.solovyev.android.views.dragbutton.DragButton; import org.solovyev.android.views.dragbutton.DirectionDragListener;
import org.solovyev.android.views.dragbutton.DragDirection; import org.solovyev.android.views.dragbutton.DragDirection;
import org.solovyev.android.views.dragbutton.SimpleDragListener; import org.solovyev.android.views.dragbutton.DragEvent;
import java.util.Arrays; import java.util.Arrays;
import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.inject.Inject; import javax.inject.Inject;
import static org.solovyev.android.calculator.App.cast;
public class DragButtonWizardStep extends WizardFragment { public class DragButtonWizardStep extends WizardFragment {
private static final String ACTION = "action"; private static final String ACTION = "action";
@ -75,8 +73,16 @@ public class DragButtonWizardStep extends WizardFragment {
final DirectionDragButton dragButton =(DirectionDragButton) root.findViewById(R.id.wizard_dragbutton); final DirectionDragButton dragButton =(DirectionDragButton) root.findViewById(R.id.wizard_dragbutton);
dragButton.setOnClickListener(this); dragButton.setOnClickListener(this);
dragButton.setOnDragListener( dragButton.setOnDragListener(new DirectionDragListener(getActivity()) {
new SimpleDragListener(new DragButtonProcessor(), getActivity())); @Override
protected boolean onDrag(@NonNull View view, @NonNull DragEvent event, @NonNull DragDirection direction) {
if (action.dragDirection == direction) {
setNextAction();
return true;
}
return false;
}
});
BaseActivity.setFont(dragButton, typeface); BaseActivity.setFont(dragButton, typeface);
Adjuster.adjustText(dragButton, BaseKeyboardUi.getTextScale(getActivity())); Adjuster.adjustText(dragButton, BaseKeyboardUi.getTextScale(getActivity()));
actionTextView = (TextView) root.findViewById(R.id.wizard_dragbutton_action_textview); actionTextView = (TextView) root.findViewById(R.id.wizard_dragbutton_action_textview);
@ -143,18 +149,4 @@ public class DragButtonWizardStep extends WizardFragment {
} }
super.onClick(v); super.onClick(v);
} }
private class DragButtonProcessor implements SimpleDragListener.DragProcessor {
@Override
public boolean processDragEvent(@Nonnull DragDirection dragDirection,
@Nonnull DragButton dragButton,
@Nonnull PointF startPoint,
@Nonnull MotionEvent motionEvent) {
if (action.dragDirection == dragDirection) {
setNextAction();
return true;
}
return false;
}
}
} }

View File

@ -0,0 +1,86 @@
package org.solovyev.android.views.dragbutton;
import android.content.Context;
import android.graphics.Canvas;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextPaint;
import android.util.AttributeSet;
import javax.annotation.Nonnull;
public class DirectionDragButton extends DragButton {
private final DirectionTextView textView = new DirectionTextView();
@NonNull
private final TextPaint baseTextPaint = new TextPaint();
public DirectionDragButton(Context context) {
super(context);
init(null);
}
public DirectionDragButton(Context context, AttributeSet attrs) {
super(context, attrs);
init(attrs);
}
public DirectionDragButton(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(attrs);
}
public DirectionDragButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(attrs);
}
private void init(@Nullable AttributeSet attrs) {
textView.init(this, attrs);
baseTextPaint.set(getPaint());
}
@Override
public boolean onPreDraw() {
final TextPaint paint = getPaint();
if (baseTextPaint.getTextSize() != paint.getTextSize() ||
baseTextPaint.getColor() != paint.getColor() ||
baseTextPaint.getAlpha() != paint.getAlpha()) {
baseTextPaint.set(paint);
textView.setBaseTextPaint(paint);
}
return super.onPreDraw();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
textView.draw(canvas);
}
@NonNull
public String getTextValue(@NonNull DragDirection direction) {
return getText(direction).getValue();
}
@NonNull
public DirectionDragButton setText(@NonNull DragDirection direction, @NonNull String value) {
getText(direction).setValue(value);
return this;
}
@Nonnull
protected DirectionTextView.Text getText(@NonNull DragDirection direction) {
return textView.getText(direction);
}
public void setShowDirectionText(@NonNull DragDirection direction, boolean show) {
getText(direction).setVisible(show);
}
public void setDirectionTextColor(@ColorInt int color) {
for (DragDirection direction : DragDirection.values()) {
getText(direction).setColor(color);
}
}
}

View File

@ -0,0 +1,67 @@
package org.solovyev.android.views.dragbutton;
import android.content.Context;
import android.graphics.PointF;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import org.solovyev.android.calculator.R;
import static java.lang.Math.toDegrees;
import static org.solovyev.android.views.dragbutton.Drag.distance;
import static org.solovyev.android.views.dragbutton.Drag.getAngle;
import static org.solovyev.android.views.dragbutton.Drag.sum;
public abstract class DirectionDragListener implements DragListener {
@NonNull
private static final PointF axis = new PointF(0, 1);
private final float minDistancePxs;
private final boolean[] right = new boolean[1];
public DirectionDragListener(@NonNull Context context) {
this.minDistancePxs = context.getResources().getDimensionPixelSize(R.dimen.drag_min_distance);
}
@Override
public boolean onDrag(@NonNull View view, @NonNull DragEvent e) {
final long duration = e.motionEvent.getEventTime() - e.motionEvent.getDownTime();
if (duration < 40 || duration > 2500) {
return false;
}
final float distance = distance(e.start, e.end);
if (distance < minDistancePxs) {
return false;
}
final double angle = toDegrees(getAngle(e.start, sum(e.start, axis), e.end, right));
final DragDirection direction = getDirection((float) angle, right[0]);
if (direction == null) {
return false;
}
return onDrag(view, e, direction);
}
protected abstract boolean onDrag(@NonNull View view, @NonNull DragEvent event, @NonNull DragDirection direction);
@Nullable
private static DragDirection getDirection(float angle, boolean right) {
for (DragDirection direction : DragDirection.values()) {
if (direction == DragDirection.left && right) {
continue;
}
if (direction == DragDirection.right && !right) {
continue;
}
if (direction.angleFrom <= angle && angle <= direction.angleTo) {
return direction;
}
}
return null;
}
}

View File

@ -0,0 +1,217 @@
package org.solovyev.android.views.dragbutton;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.PointF;
import android.graphics.Rect;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextPaint;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;
import com.google.common.base.Strings;
import org.solovyev.android.Check;
import org.solovyev.android.calculator.R;
import java.util.EnumMap;
import java.util.Map;
public class DirectionTextView {
public static final float DEF_ALPHA = 0.55f;
public static final float DEF_SCALE = 0.4f;
@NonNull
private final Map<DragDirection, Text> texts = new EnumMap<>(DragDirection.class);
public DirectionTextView() {
}
public void init(@NonNull TextView view, @Nullable AttributeSet attrs) {
init(view, attrs, view.getPaint());
}
public void setBaseTextPaint(@NonNull TextPaint baseTextPaint) {
for (Text text : texts.values()) {
text.initPaint(baseTextPaint);
}
}
public void init(@NonNull View view, @Nullable AttributeSet attrs, @NonNull TextPaint baseTextPaint) {
Check.isTrue(texts.isEmpty());
final Context context = view.getContext();
final int defColor = baseTextPaint.getColor();
final int defPadding = context.getResources().getDimensionPixelSize(R.dimen.cpp_direction_text_default_padding);
final float minTextSize = context.getResources().getDimensionPixelSize(R.dimen.cpp_direction_text_min_size);
if (attrs == null) {
for (DragDirection direction : DragDirection.values()) {
final Text text = new Text(direction, view, minTextSize);
text.init(baseTextPaint, null, DEF_SCALE, defColor, DEF_ALPHA, defPadding);
texts.put(direction, text);
}
return;
}
final TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.DirectionText);
final float scale = array.getFloat(R.styleable.DirectionText_directionTextScale, DEF_SCALE);
final float alpha = array.getFloat(R.styleable.DirectionText_directionTextAlpha, DEF_ALPHA);
final int color = array.getColor(R.styleable.DirectionText_directionTextColor, defColor);
final int padding = array.getDimensionPixelSize(R.styleable.DirectionText_directionTextPadding, defPadding);
for (DragDirection direction : DragDirection.values()) {
final Text text = new Text(direction, view, minTextSize);
text.init(baseTextPaint, array, scale, color, alpha, padding);
texts.put(direction, text);
}
array.recycle();
}
public void draw(@NonNull Canvas canvas) {
for (Text text : texts.values()) {
text.draw(canvas);
}
}
@NonNull
public Text getText(@NonNull DragDirection direction) {
return texts.get(direction);
}
public static class Text {
public final Rect bounds = new Rect();
@NonNull
private final TextPaint paint = new TextPaint();
@NonNull
private final DragDirection direction;
@NonNull
private final View view;
private final float minTextSize;
@NonNull
private final PointF position = new PointF(-1, -1);
@NonNull
private String value = "";
private float scale;
private int color;
private float alpha;
private boolean visible = true;
private int padding;
public Text(@NonNull DragDirection direction, @NonNull View view, float minTextSize) {
this.direction = direction;
this.view = view;
this.minTextSize = minTextSize;
}
public void init(@NonNull TextPaint base, @Nullable TypedArray array, float defScale, int defColor, float defAlpha, int defPadding) {
if (array != null) {
if (array.hasValue(direction.textAttr)) {
value = Strings.nullToEmpty(array.getString(direction.textAttr));
}
scale = array.getFloat(direction.scaleAttr, defScale);
} else {
value = "";
scale = defScale;
}
alpha = defAlpha;
color = defColor;
padding = defPadding;
initPaint(base);
}
public void initPaint(@NonNull TextPaint base) {
paint.set(base);
paint.setColor(color);
paint.setAlpha(intAlpha());
paint.setTextSize(Math.max(base.getTextSize() * scale, minTextSize));
invalidate(true);
}
private int intAlpha() {
return (int) (255 * alpha);
}
public void setVisible(boolean visible) {
if (this.visible == visible) {
return;
}
this.visible = visible;
invalidate(false);
}
public void setColor(int color) {
setColor(color, this.alpha);
}
public void setColor(int color, float alpha) {
if (this.color == color && this.alpha == alpha) {
return;
}
this.color = color;
this.alpha = alpha;
paint.setColor(color);
paint.setAlpha(intAlpha());
invalidate(false);
}
private void invalidate(boolean remeasure) {
Check.isNotNull(view);
view.invalidate();
if (remeasure) {
position.set(-1, -1);
}
}
public void draw(@NonNull Canvas canvas) {
if (!visible || TextUtils.isEmpty(value)) {
return;
}
if (position.x < 0 || position.y < 0) {
calculatePosition();
}
canvas.drawText(value, position.x, position.y, paint);
}
private void calculatePosition() {
paint.getTextBounds(value, 0, value.length(), bounds);
switch (direction) {
case up:
case down:
position.x = view.getWidth() - view.getPaddingLeft() - padding - bounds.width();
if (direction == DragDirection.up) {
position.y = view.getPaddingTop() + padding + bounds.height();
} else {
position.y = view.getHeight() - view.getPaddingBottom() - padding;
}
break;
case left:
case right:
if (direction == DragDirection.left) {
position.x = view.getPaddingLeft() + padding;
} else {
position.x = view.getWidth() - view.getPaddingLeft() - padding - bounds.width();
}
final int availableHeight = view.getHeight() - view.getPaddingTop() - view.getPaddingBottom();
position.y = view.getPaddingTop() + padding + availableHeight / 2 + bounds.height() / 2;
break;
}
}
@NonNull
public String getValue() {
return value;
}
public void setValue(@NonNull String value) {
if (TextUtils.equals(this.value, value)) {
return;
}
this.value = value;
invalidate(true);
}
}
}

View File

@ -0,0 +1,56 @@
package org.solovyev.android.views.dragbutton;
import android.graphics.PointF;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
final class Drag {
private Drag() {
}
public static float distance(@NonNull PointF start,
@NonNull PointF end) {
return norm(end.x - start.x, end.y - start.y);
}
@NonNull
public static PointF subtract(@NonNull PointF p1, @NonNull PointF p2) {
return new PointF(p1.x - p2.x, p1.y - p2.y);
}
@NonNull
public static PointF sum(@NonNull PointF p1, @NonNull PointF p2) {
return new PointF(p1.x + p2.x, p1.y + p2.y);
}
public static float norm(@NonNull PointF point) {
return norm(point.x, point.y);
}
private static float norm(float x, float y) {
//noinspection SuspiciousNameCombination
return (float) Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
}
public static float getAngle(@NonNull PointF start,
@NonNull PointF axisEnd,
@NonNull PointF end,
@Nullable boolean[] right) {
final PointF axisVector = subtract(axisEnd, start);
final PointF vector = subtract(end, start);
double a_2 = Math.pow(distance(vector, axisVector), 2);
double b = norm(vector);
double b_2 = Math.pow(b, 2);
double c = norm(axisVector);
double c_2 = Math.pow(c, 2);
if (right != null) {
right[0] = axisVector.x * vector.y - axisVector.y * vector.x < 0;
}
return (float) Math.acos((-a_2 + b_2 + c_2) / (2 * b * c));
}
}

View File

@ -0,0 +1,51 @@
package org.solovyev.android.views.dragbutton;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.Button;
public class DragButton extends Button {
@NonNull
private final DragGestureDetector dragDetector = new DragGestureDetector(this);
public DragButton(Context context) {
super(context);
}
public DragButton(Context context, AttributeSet attrs) {
super(context, attrs);
}
public DragButton(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public DragButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (dragDetector.onTouchEvent(event)) {
final MotionEvent cancelEvent = DragGestureDetector.makeCancelEvent(event);
super.onTouchEvent(cancelEvent);
cancelEvent.recycle();
return true;
}
return super.onTouchEvent(event);
}
public void setOnDragListener(@Nullable DragListener listener) {
dragDetector.setListener(listener);
}
public void setVibrateOnDrag(boolean vibrateOnDrag) {
dragDetector.setVibrateOnDrag(vibrateOnDrag);
}
}

View File

@ -0,0 +1,27 @@
package org.solovyev.android.views.dragbutton;
import android.support.annotation.StyleableRes;
import org.solovyev.android.calculator.R;
public enum DragDirection {
up(180f - 45f, 180f - 0f, R.styleable.DirectionText_directionTextUp, R.styleable.DirectionText_directionTextScaleUp),
down(0f, 45f, R.styleable.DirectionText_directionTextDown, R.styleable.DirectionText_directionTextScaleDown),
left(90f - 45f, 90f + 45f, R.styleable.DirectionText_directionTextLeft, R.styleable.DirectionText_directionTextScaleLeft),
right(90f - 45f, 90f + 45f, R.styleable.DirectionText_directionTextRight, R.styleable.DirectionText_directionTextScaleRight);
final float angleFrom;
final float angleTo;
@StyleableRes
final int textAttr;
@StyleableRes
final int scaleAttr;
DragDirection(float angleFrom, float angleTo, int textAttr, int scaleAttr) {
this.angleFrom = angleFrom;
this.angleTo = angleTo;
this.textAttr = textAttr;
this.scaleAttr = scaleAttr;
}
}

View File

@ -0,0 +1,23 @@
package org.solovyev.android.views.dragbutton;
import android.graphics.PointF;
import android.support.annotation.NonNull;
import android.view.MotionEvent;
public class DragEvent {
@NonNull
public final PointF start;
@NonNull
public final PointF end;
@NonNull
public final MotionEvent motionEvent;
public DragEvent(@NonNull PointF start, @NonNull MotionEvent motionEvent) {
this.start = start;
this.end = new PointF(motionEvent.getX(), motionEvent.getY());
this.motionEvent = motionEvent;
}
}

View File

@ -0,0 +1,77 @@
package org.solovyev.android.views.dragbutton;
import android.graphics.PointF;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.MotionEvent;
import android.view.View;
import org.solovyev.android.Check;
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;
public class DragGestureDetector {
@NonNull
private final View view;
@Nullable
private DragListener listener;
@Nullable
private PointF start;
private boolean vibrateOnDrag = true;
public DragGestureDetector(@NonNull View view) {
this.view = view;
}
@NonNull
static MotionEvent makeCancelEvent(@NonNull MotionEvent original) {
final MotionEvent event = MotionEvent.obtain(original);
event.setAction(MotionEvent.ACTION_CANCEL);
return event;
}
public boolean onTouchEvent(@NonNull MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
startTracking(event);
return false;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
return stopTracking(event);
}
return false;
}
private boolean stopTracking(@NonNull MotionEvent event) {
if (start == null || listener == null) {
start = null;
return false;
}
if (!listener.onDrag(view, new DragEvent(start, event))) {
start = null;
return false;
}
start = null;
if (vibrateOnDrag) {
view.performHapticFeedback(KEYBOARD_TAP, FLAG_IGNORE_GLOBAL_SETTING | FLAG_IGNORE_VIEW_SETTING);
}
return true;
}
public void setVibrateOnDrag(boolean vibrateOnDrag) {
this.vibrateOnDrag = vibrateOnDrag;
}
private void startTracking(@NonNull MotionEvent event) {
Check.isNull(start);
start = new PointF(event.getX(), event.getY());
}
public void setListener(@Nullable DragListener listener) {
this.listener = listener;
}
}

View File

@ -0,0 +1,11 @@
package org.solovyev.android.views.dragbutton;
import android.support.annotation.NonNull;
import android.view.View;
import java.util.EventListener;
public interface DragListener extends EventListener {
boolean onDrag(@NonNull View view, @NonNull DragEvent event);
}

View File

@ -29,6 +29,6 @@
a:id="@id/cpp_button_0" a:id="@id/cpp_button_0"
style="?attr/cpp_button_style_digit" style="?attr/cpp_button_style_digit"
a:text="0" a:text="0"
c:textDown="000" c:directionTextDown="000"
c:textUp="00" c:directionTextUp="00"
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />

View File

@ -29,7 +29,7 @@
a:id="@id/cpp_button_1" a:id="@id/cpp_button_1"
style="?attr/cpp_button_style_digit" style="?attr/cpp_button_style_digit"
a:text="1" a:text="1"
c:textDown="asin" c:directionTextDown="asin"
c:textLeft="A" c:directionTextLeft="A"
c:textUp="sin" c:directionTextUp="sin"
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />

View File

@ -29,7 +29,7 @@
a:id="@id/cpp_button_2" a:id="@id/cpp_button_2"
style="?attr/cpp_button_style_digit" style="?attr/cpp_button_style_digit"
a:text="2" a:text="2"
c:textDown="acos" c:directionTextDown="acos"
c:textLeft="B" c:directionTextLeft="B"
c:textUp="cos" c:directionTextUp="cos"
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />

View File

@ -29,7 +29,7 @@
a:id="@id/cpp_button_3" a:id="@id/cpp_button_3"
style="?attr/cpp_button_style_digit" style="?attr/cpp_button_style_digit"
a:text="3" a:text="3"
c:textDown="atan" c:directionTextDown="atan"
c:textLeft="C" c:directionTextLeft="C"
c:textUp="tan" c:directionTextUp="tan"
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />

View File

@ -28,7 +28,7 @@
a:id="@id/cpp_button_4" a:id="@id/cpp_button_4"
style="?attr/cpp_button_style_digit" style="?attr/cpp_button_style_digit"
a:text="4" a:text="4"
c:textDown="y" c:directionTextDown="y"
c:textLeft="D" c:directionTextLeft="D"
c:textUp="x" c:directionTextUp="x"
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />

View File

@ -28,7 +28,7 @@
a:id="@id/cpp_button_5" a:id="@id/cpp_button_5"
style="?attr/cpp_button_style_digit" style="?attr/cpp_button_style_digit"
a:text="5" a:text="5"
c:textDown="j" c:directionTextDown="j"
c:textLeft="E" c:directionTextLeft="E"
c:textUp="t" c:directionTextUp="t"
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />

View File

@ -29,7 +29,7 @@
a:id="@id/cpp_button_6" a:id="@id/cpp_button_6"
style="?attr/cpp_button_style_digit" style="?attr/cpp_button_style_digit"
a:text="6" a:text="6"
c:textDown="rad" c:directionTextDown="rad"
c:textLeft="F" c:directionTextLeft="F"
c:textUp="deg" c:directionTextUp="deg"
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />

View File

@ -29,7 +29,7 @@
a:id="@id/cpp_button_7" a:id="@id/cpp_button_7"
style="?attr/cpp_button_style_digit" style="?attr/cpp_button_style_digit"
a:text="7" a:text="7"
c:textDown="!" c:directionTextDown="!"
c:textLeft="0b:" c:directionTextLeft="0b:"
c:textUp="i" c:directionTextUp="i"
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />

View File

@ -29,7 +29,7 @@
a:id="@id/cpp_button_8" a:id="@id/cpp_button_8"
style="?attr/cpp_button_style_digit" style="?attr/cpp_button_style_digit"
a:text="8" a:text="8"
c:textDown="lg" c:directionTextDown="lg"
c:textLeft="0d:" c:directionTextLeft="0d:"
c:textUp="ln" c:directionTextUp="ln"
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />

View File

@ -29,7 +29,7 @@
a:id="@id/cpp_button_9" a:id="@id/cpp_button_9"
style="?attr/cpp_button_style_digit" style="?attr/cpp_button_style_digit"
a:text="9" a:text="9"
c:textDown="e" c:directionTextDown="e"
c:textLeft="0x:" c:directionTextLeft="0x:"
c:textUp="π" c:directionTextUp="π"
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />

View File

@ -29,6 +29,6 @@
style="?attr/cpp_button_style_control_image" style="?attr/cpp_button_style_control_image"
a:text="@string/c_clear" a:text="@string/c_clear"
a:textStyle="bold" a:textStyle="bold"
c:textDown="bin" c:directionTextDown="bin"
c:textLeft="hex" c:directionTextLeft="hex"
c:textUp="dec" /> c:directionTextUp="dec" />

View File

@ -29,6 +29,6 @@
a:id="@id/cpp_button_division" a:id="@id/cpp_button_division"
style="?attr/cpp_button_style_operation" style="?attr/cpp_button_style_operation"
a:text="/" a:text="/"
c:textDown="√" c:directionTextDown="√"
c:textUp="%" c:directionTextUp="%"
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />

View File

@ -29,5 +29,5 @@
a:id="@id/cpp_button_period" a:id="@id/cpp_button_period"
style="?attr/cpp_button_style_digit" style="?attr/cpp_button_style_digit"
a:text="." a:text="."
c:textUp="," c:directionTextUp=","
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />

View File

@ -28,6 +28,6 @@
a:id="@id/cpp_button_equals" a:id="@id/cpp_button_equals"
style="?attr/cpp_button_style_control" style="?attr/cpp_button_style_control"
a:text="=" a:text="="
c:textDown="@string/cpp_plot_button_text" c:directionTextDown="@string/cpp_plot_button_text"
c:textUp="≡" c:directionTextUp="≡"
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />

View File

@ -31,6 +31,6 @@
a:text="=" a:text="="
a:textColor="?android:attr/textColorPrimary" a:textColor="?android:attr/textColorPrimary"
c:directionTextColor="?android:attr/textColorPrimary" c:directionTextColor="?android:attr/textColorPrimary"
c:textDown="@string/cpp_plot_button_text" c:directionTextDown="@string/cpp_plot_button_text"
c:textUp="≡" c:directionTextUp="≡"
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />

View File

@ -30,5 +30,5 @@
style="?attr/cpp_button_style_control" style="?attr/cpp_button_style_control"
a:text="@string/cpp_kb_functions" a:text="@string/cpp_kb_functions"
a:textStyle="italic" a:textStyle="italic"
c:textUp="+ƒ" c:directionTextUp="+ƒ"
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />

View File

@ -28,5 +28,5 @@
style="?attr/cpp_button_style_control" style="?attr/cpp_button_style_control"
a:text="@string/c_history_button" a:text="@string/c_history_button"
a:textStyle="bold" a:textStyle="bold"
c:textDown="@string/cpp_kb_redo" c:directionTextDown="@string/cpp_kb_redo"
c:textUp="@string/cpp_kb_undo" /> c:directionTextUp="@string/cpp_kb_undo" />

View File

@ -29,5 +29,5 @@
a:id="@id/cpp_button_left" a:id="@id/cpp_button_left"
style="?attr/cpp_button_style_control" style="?attr/cpp_button_style_control"
a:text="◁" a:text="◁"
c:textUp="◁◁" c:directionTextUp="◁◁"
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />

View File

@ -28,5 +28,5 @@
a:id="@id/cpp_button_subtraction" a:id="@id/cpp_button_subtraction"
style="?attr/cpp_button_style_operation" style="?attr/cpp_button_style_operation"
a:text="" a:text=""
c:textDown="@string/cpp_kb_operators" c:directionTextDown="@string/cpp_kb_operators"
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />

View File

@ -29,7 +29,7 @@
a:id="@id/cpp_button_multiplication" a:id="@id/cpp_button_multiplication"
style="?attr/cpp_button_style_operation" style="?attr/cpp_button_style_operation"
a:text="×" a:text="×"
c:textDown="^2" c:directionTextDown="^2"
c:textLeft="Π" c:directionTextLeft="Π"
c:textUp="^" c:directionTextUp="^"
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />

View File

@ -28,6 +28,6 @@
a:id="@id/cpp_button_plus" a:id="@id/cpp_button_plus"
style="?attr/cpp_button_style_operation" style="?attr/cpp_button_style_operation"
a:text="+" a:text="+"
c:textDown="E" c:directionTextDown="E"
c:textUp="°" c:directionTextUp="°"
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />

View File

@ -29,5 +29,5 @@
a:id="@id/cpp_button_right" a:id="@id/cpp_button_right"
style="?attr/cpp_button_style_control" style="?attr/cpp_button_style_control"
a:text="▷" a:text="▷"
c:textUp="▷▷" c:directionTextUp="▷▷"
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />

View File

@ -29,7 +29,7 @@
a:id="@id/cpp_button_round_brackets" a:id="@id/cpp_button_round_brackets"
style="?attr/cpp_button_style_digit" style="?attr/cpp_button_style_digit"
a:text="( )" a:text="( )"
c:textDown=")" c:directionTextDown=")"
c:textLeft="(…)" c:directionTextLeft="(…)"
c:textUp="(" c:directionTextUp="("
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />

View File

@ -30,5 +30,5 @@
style="?attr/cpp_button_style_control" style="?attr/cpp_button_style_control"
a:text="@string/cpp_kb_variables" a:text="@string/cpp_kb_variables"
a:textStyle="italic" a:textStyle="italic"
c:textUp="+π" c:directionTextUp="+π"
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />

View File

@ -53,7 +53,7 @@
a:minHeight="100dp" a:minHeight="100dp"
a:minWidth="100dp" a:minWidth="100dp"
a:text="9" a:text="9"
c:textDown="^2" c:directionTextDown="^2"
c:textUp="%" /> c:directionTextUp="%" />
</LinearLayout> </LinearLayout>

View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="cpp_direction_text_size" translatable="false">0.4;0.4;0.4;0.4</string>
</resources>

View File

@ -21,8 +21,8 @@
--> -->
<resources> <resources>
<dimen name="cpp_fragment_text_size">15sp</dimen>
<dimen name="cpp_min_editor_text_size">18sp</dimen> <dimen name="cpp_min_editor_text_size">18sp</dimen>
<dimen name="cpp_display_text_size">20sp</dimen> <dimen name="cpp_display_text_size">20sp</dimen>
<dimen name="cpp_clickable_area_size">40dp</dimen> <dimen name="cpp_clickable_area_size">40dp</dimen>
<dimen name="cpp_keyboard_button_direction_text_padding">1dp</dimen>
</resources> </resources>

View File

@ -8,8 +8,12 @@
<dimen name="min_expanded_height_lock_screen">300dp</dimen> <dimen name="min_expanded_height_lock_screen">300dp</dimen>
<dimen name="cpp_text_size">20sp</dimen> <dimen name="cpp_text_size">20sp</dimen>
<dimen name="cpp_button_padding">1px</dimen> <dimen name="cpp_button_padding">1px</dimen>
<dimen name="cpp_direction_text_default_padding">2dp</dimen>
<dimen name="cpp_direction_text_min_size">9dp</dimen>
<item name="cpp_direction_text_scale" format="float" type="dimen">0.3</item>
<dimen name="cpp_button_corner">1dp</dimen> <dimen name="cpp_button_corner">1dp</dimen>
<dimen name="cpp_keyboard_button_direction_text_padding">4dp</dimen>
<dimen name="cpp_keyboard_button_text_size">30dp</dimen> <dimen name="cpp_keyboard_button_text_size">30dp</dimen>
<dimen name="cpp_keyboard_simple_image_button_padding">12dp</dimen> <dimen name="cpp_keyboard_simple_image_button_padding">12dp</dimen>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="DirectionText">
<attr name="directionTextColor" format="color"/>
<attr name="directionTextAlpha" format="float"/>
<attr name="directionTextUp" format="string"/>
<attr name="directionTextDown" format="string"/>
<attr name="directionTextRight" format="string"/>
<attr name="directionTextLeft" format="string"/>
<attr name="directionTextScale" format="float"/>
<attr name="directionTextPadding" format="dimension"/>
<attr name="directionTextScaleUp" format="float"/>
<attr name="directionTextScaleDown" format="float"/>
<attr name="directionTextScaleRight" format="float"/>
<attr name="directionTextScaleLeft" format="float"/>
</declare-styleable>
</resources>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="drag_min_distance">25dp</dimen>
</resources>

View File

@ -39,7 +39,8 @@
<item name="android:textColor">@color/cpp_button_text</item> <item name="android:textColor">@color/cpp_button_text</item>
<item name="android:scaleType">centerInside</item> <item name="android:scaleType">centerInside</item>
<item name="directionTextColor">@color/cpp_button_text</item> <item name="directionTextColor">@color/cpp_button_text</item>
<item name="directionTextScale">@string/cpp_direction_text_size</item> <item name="directionTextScale">@dimen/cpp_direction_text_scale</item>
<item name="directionTextPadding">@dimen/cpp_keyboard_button_direction_text_padding</item>
</style> </style>
<style name="CppText.Editor.Onscreen.Light" parent="CppText.Editor.Onscreen"> <style name="CppText.Editor.Onscreen.Light" parent="CppText.Editor.Onscreen">

View File

@ -5,7 +5,6 @@
<string name="cpp_kb_operators" translatable="false"></string> <string name="cpp_kb_operators" translatable="false"></string>
<string name="cpp_kb_undo" translatable="false"></string> <string name="cpp_kb_undo" translatable="false"></string>
<string name="cpp_kb_redo" translatable="false"></string> <string name="cpp_kb_redo" translatable="false"></string>
<string name="cpp_direction_text_size" translatable="false">0.3;0.3;0.3;0.3</string>
<string name="cpp_plot_add_function" translatable="false">+</string> <string name="cpp_plot_add_function" translatable="false">+</string>
<string name="cpp_plot_zoom_in" translatable="false">+</string> <string name="cpp_plot_zoom_in" translatable="false">+</string>
<string name="cpp_plot_zoom_reset" translatable="false">0</string> <string name="cpp_plot_zoom_reset" translatable="false">0</string>

View File

@ -1,8 +1,8 @@
package org.solovyev.android.calculator.view; package org.solovyev.android.calculator.view;
import android.app.Activity; import android.app.Activity;
import android.os.Build; import android.os.Build;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -20,10 +20,7 @@ import java.util.ArrayList;
import static jscl.AngleUnit.deg; import static jscl.AngleUnit.deg;
import static jscl.AngleUnit.grad; import static jscl.AngleUnit.grad;
import static jscl.AngleUnit.rad; import static jscl.AngleUnit.rad;
import static jscl.AngleUnit.turns;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@ -41,17 +38,6 @@ public class AngleUnitsButtonTest {
button = new AngleUnitsButton(context, activity.createAttributeSet(new ArrayList<Attribute>(), AngleUnitsButton.class)); button = new AngleUnitsButton(context, activity.createAttributeSet(new ArrayList<Attribute>(), AngleUnitsButton.class));
} }
@Test
public void testShouldReturnDifferentColorsForDifferentAngleUnits() throws Exception {
button.setAngleUnit(deg);
assertEquals(button.getDirectionTextColor(deg.name()), button.getDirectionTextColor(deg.name()));
assertEquals(button.getDirectionTextColor(grad.name()), button.getDirectionTextColor(rad.name()));
assertNotSame(button.getDirectionTextColor(deg.name()), button.getDirectionTextColor(rad.name()));
assertNotSame(button.getDirectionTextColor(deg.name()), button.getDirectionTextColor(grad.name()));
assertNotSame(button.getDirectionTextColor(deg.name()), button.getDirectionTextColor(turns.name()));
}
@Test @Test
public void testIsCurrentAngleUnits() throws Exception { public void testIsCurrentAngleUnits() throws Exception {
button.setAngleUnit(rad); button.setAngleUnit(rad);

View File

@ -1,8 +1,8 @@
package org.solovyev.android.calculator.view; package org.solovyev.android.calculator.view;
import android.app.Activity; import android.app.Activity;
import android.os.Build; import android.os.Build;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -20,10 +20,7 @@ import java.util.ArrayList;
import static jscl.NumeralBase.bin; import static jscl.NumeralBase.bin;
import static jscl.NumeralBase.dec; import static jscl.NumeralBase.dec;
import static jscl.NumeralBase.hex; import static jscl.NumeralBase.hex;
import static jscl.NumeralBase.oct;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@ -41,17 +38,6 @@ public class NumeralBasesButtonTest {
button = new NumeralBasesButton(context, activity.createAttributeSet(new ArrayList<Attribute>(), NumeralBasesButton.class)); button = new NumeralBasesButton(context, activity.createAttributeSet(new ArrayList<Attribute>(), NumeralBasesButton.class));
} }
@Test
public void testShouldReturnDifferentColorsForDifferentNumeralBase() throws Exception {
button.setNumeralBase(dec);
assertEquals(button.getDirectionTextColor(dec.name()), button.getDirectionTextColor(dec.name()));
assertEquals(button.getDirectionTextColor(hex.name()), button.getDirectionTextColor(bin.name()));
assertNotSame(button.getDirectionTextColor(dec.name()), button.getDirectionTextColor(bin.name()));
assertNotSame(button.getDirectionTextColor(dec.name()), button.getDirectionTextColor(hex.name()));
assertNotSame(button.getDirectionTextColor(dec.name()), button.getDirectionTextColor(oct.name()));
}
@Test @Test
public void testIsCurrentNumeralBase() throws Exception { public void testIsCurrentNumeralBase() throws Exception {
button.setNumeralBase(dec); button.setNumeralBase(dec);