changes
@ -31,4 +31,11 @@ public class CalculatorFailureImpl implements CalculatorFailure {
|
|||||||
public CalculatorEvalException getCalculationEvalException() {
|
public CalculatorEvalException getCalculationEvalException() {
|
||||||
return exception instanceof CalculatorEvalException ? (CalculatorEvalException)exception : null;
|
return exception instanceof CalculatorEvalException ? (CalculatorEvalException)exception : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "CalculatorFailureImpl{" +
|
||||||
|
"exception=" + exception +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,8 @@ public interface CalculatorLocator {
|
|||||||
@NotNull CalculatorEngine engine,
|
@NotNull CalculatorEngine engine,
|
||||||
@NotNull CalculatorClipboard clipboard,
|
@NotNull CalculatorClipboard clipboard,
|
||||||
@NotNull CalculatorNotifier notifier,
|
@NotNull CalculatorNotifier notifier,
|
||||||
@NotNull CalculatorHistory history);
|
@NotNull CalculatorHistory history,
|
||||||
|
@NotNull CalculatorLogger logger);
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
Calculator getCalculator();
|
Calculator getCalculator();
|
||||||
@ -39,4 +40,7 @@ public interface CalculatorLocator {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
CalculatorHistory getHistory();
|
CalculatorHistory getHistory();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
CalculatorLogger getLogger();
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,9 @@ public class CalculatorLocatorImpl implements CalculatorLocator {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private CalculatorNotifier calculatorNotifier = new DummyCalculatorNotifier();
|
private CalculatorNotifier calculatorNotifier = new DummyCalculatorNotifier();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private CalculatorLogger calculatorLogger = new SystemOutCalculatorLogger();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private CalculatorClipboard calculatorClipboard = new DummyCalculatorClipboard();
|
private CalculatorClipboard calculatorClipboard = new DummyCalculatorClipboard();
|
||||||
|
|
||||||
@ -45,13 +48,15 @@ public class CalculatorLocatorImpl implements CalculatorLocator {
|
|||||||
@NotNull CalculatorEngine engine,
|
@NotNull CalculatorEngine engine,
|
||||||
@NotNull CalculatorClipboard clipboard,
|
@NotNull CalculatorClipboard clipboard,
|
||||||
@NotNull CalculatorNotifier notifier,
|
@NotNull CalculatorNotifier notifier,
|
||||||
@NotNull CalculatorHistory history) {
|
@NotNull CalculatorHistory history,
|
||||||
|
@NotNull CalculatorLogger logger) {
|
||||||
|
|
||||||
this.calculator = calculator;
|
this.calculator = calculator;
|
||||||
this.calculatorEngine = engine;
|
this.calculatorEngine = engine;
|
||||||
this.calculatorClipboard = clipboard;
|
this.calculatorClipboard = clipboard;
|
||||||
this.calculatorNotifier = notifier;
|
this.calculatorNotifier = notifier;
|
||||||
this.calculatorHistory = history;
|
this.calculatorHistory = history;
|
||||||
|
this.calculatorLogger = logger;
|
||||||
|
|
||||||
calculatorEditor = new CalculatorEditorImpl(this.calculator);
|
calculatorEditor = new CalculatorEditorImpl(this.calculator);
|
||||||
calculatorDisplay = new CalculatorDisplayImpl(this.calculator);
|
calculatorDisplay = new CalculatorDisplayImpl(this.calculator);
|
||||||
@ -110,4 +115,10 @@ public class CalculatorLocatorImpl implements CalculatorLocator {
|
|||||||
public CalculatorHistory getHistory() {
|
public CalculatorHistory getHistory() {
|
||||||
return calculatorHistory;
|
return calculatorHistory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public CalculatorLogger getLogger() {
|
||||||
|
return calculatorLogger;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User: serso
|
||||||
|
* Date: 10/11/12
|
||||||
|
* Time: 12:11 AM
|
||||||
|
*/
|
||||||
|
public interface CalculatorLogger {
|
||||||
|
|
||||||
|
void debug(@Nullable String tag, @NotNull String message);
|
||||||
|
|
||||||
|
void debug(@Nullable String tag, @NotNull String message, @NotNull Throwable e);
|
||||||
|
}
|
@ -39,10 +39,18 @@ public class ListCalculatorEventContainer implements CalculatorEventContainer {
|
|||||||
public void fireCalculatorEvents(@NotNull List<CalculatorEvent> calculatorEvents) {
|
public void fireCalculatorEvents(@NotNull List<CalculatorEvent> calculatorEvents) {
|
||||||
final List<CalculatorEventListener> listeners = this.listeners.getListeners();
|
final List<CalculatorEventListener> listeners = this.listeners.getListeners();
|
||||||
|
|
||||||
|
final CalculatorLogger logger = CalculatorLocatorImpl.getInstance().getLogger();
|
||||||
|
|
||||||
for (CalculatorEvent e : calculatorEvents) {
|
for (CalculatorEvent e : calculatorEvents) {
|
||||||
//Log.d(TAG, "Event: " + e.getCalculatorEventType() + " with data: " + e.getData());
|
|
||||||
for (CalculatorEventListener listener : listeners) {
|
for (CalculatorEventListener listener : listeners) {
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
listener.onCalculatorEvent(e.getCalculatorEventData(), e.getCalculatorEventType(), e.getData());
|
listener.onCalculatorEvent(e.getCalculatorEventData(), e.getCalculatorEventType(), e.getData());
|
||||||
|
long endTime = System.currentTimeMillis();
|
||||||
|
long totalTime = (endTime - startTime);
|
||||||
|
if ( totalTime > 300 ) {
|
||||||
|
logger.debug(TAG + "_" + e.getCalculatorEventData().getEventId(), "Started event: " + e.getCalculatorEventType() + " with data: " + e.getData() + " for: " + listener.getClass().getSimpleName());
|
||||||
|
logger.debug(TAG + "_" + e.getCalculatorEventData().getEventId(), "Total time, ms: " + totalTime);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User: serso
|
||||||
|
* Date: 10/11/12
|
||||||
|
* Time: 12:12 AM
|
||||||
|
*/
|
||||||
|
public class SystemOutCalculatorLogger implements CalculatorLogger {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static final String TAG = SystemOutCalculatorLogger.class.getSimpleName();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void debug(@Nullable String tag, @NotNull String message) {
|
||||||
|
System.out.println(getTag(tag) + ": " + message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String getTag(@Nullable String tag) {
|
||||||
|
return tag != null ? tag : TAG;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void debug(@Nullable String tag, @NotNull String message, @NotNull Throwable e) {
|
||||||
|
debug(tag, message);
|
||||||
|
e.printStackTrace(System.out);
|
||||||
|
}
|
||||||
|
}
|
@ -11,7 +11,7 @@ import org.solovyev.android.calculator.history.CalculatorHistory;
|
|||||||
public class AbstractCalculatorTest {
|
public class AbstractCalculatorTest {
|
||||||
|
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
CalculatorLocatorImpl.getInstance().init(new CalculatorImpl(), CalculatorTestUtils.newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(CalculatorHistory.class));
|
CalculatorLocatorImpl.getInstance().init(new CalculatorImpl(), CalculatorTestUtils.newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(CalculatorHistory.class), null);
|
||||||
CalculatorLocatorImpl.getInstance().getEngine().init();
|
CalculatorLocatorImpl.getInstance().getEngine().init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ public class CalculatorTestUtils {
|
|||||||
public static final int TIMEOUT = 1;
|
public static final int TIMEOUT = 1;
|
||||||
|
|
||||||
public static void staticSetUp() throws Exception {
|
public static void staticSetUp() throws Exception {
|
||||||
CalculatorLocatorImpl.getInstance().init(new CalculatorImpl(), newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(CalculatorHistory.class));
|
CalculatorLocatorImpl.getInstance().init(new CalculatorImpl(), newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(CalculatorHistory.class), null);
|
||||||
CalculatorLocatorImpl.getInstance().getEngine().init();
|
CalculatorLocatorImpl.getInstance().getEngine().init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,14 +11,14 @@
|
|||||||
target=android-15
|
target=android-15
|
||||||
android.library.reference.1=gen-external-apklibs/org.solovyev.android_android-common-core_1.0.0
|
android.library.reference.1=gen-external-apklibs/org.solovyev.android_android-common-core_1.0.0
|
||||||
android.library.reference.2=gen-external-apklibs/org.solovyev.android_android-common-ads_1.0.0
|
android.library.reference.2=gen-external-apklibs/org.solovyev.android_android-common-ads_1.0.0
|
||||||
android.library.reference.3=gen-external-apklibs/org.solovyev.android_android-common-view_1.0.0
|
android.library.reference.3=gen-external-apklibs/org.solovyev.android_billing_0.2
|
||||||
android.library.reference.4=gen-external-apklibs/org.solovyev.android_android-common-preferences_1.0.0
|
android.library.reference.4=gen-external-apklibs/org.solovyev.android_android-common-db_1.0.0
|
||||||
android.library.reference.5=gen-external-apklibs/org.solovyev.android_android-common-other_1.0.0
|
android.library.reference.5=gen-external-apklibs/org.solovyev.android_android-common-view_1.0.0
|
||||||
android.library.reference.6=gen-external-apklibs/org.solovyev.android_android-common-menu_1.0.0
|
android.library.reference.6=gen-external-apklibs/org.solovyev.android_android-common-preferences_1.0.0
|
||||||
android.library.reference.7=gen-external-apklibs/org.solovyev.android_android-common-sherlock_1.0.0
|
android.library.reference.7=gen-external-apklibs/org.solovyev.android_android-common-other_1.0.0
|
||||||
android.library.reference.8=gen-external-apklibs/com.actionbarsherlock_library_4.1.0
|
android.library.reference.8=gen-external-apklibs/org.solovyev.android_android-common-menu_1.0.0
|
||||||
android.library.reference.9=gen-external-apklibs/org.solovyev.android_android-common-list_1.0.0
|
android.library.reference.9=gen-external-apklibs/org.solovyev.android_android-common-sherlock_1.0.0
|
||||||
android.library.reference.10=gen-external-apklibs/org.solovyev.android_billing_0.2
|
android.library.reference.10=gen-external-apklibs/com.actionbarsherlock_library_4.1.0
|
||||||
android.library.reference.11=gen-external-apklibs/org.solovyev.android_android-common-db_1.0.0
|
android.library.reference.11=gen-external-apklibs/org.solovyev.android_android-common-list_1.0.0
|
||||||
|
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 344 B |
Before Width: | Height: | Size: 223 B |
Before Width: | Height: | Size: 347 B |
Before Width: | Height: | Size: 211 B |
Before Width: | Height: | Size: 321 B |
Before Width: | Height: | Size: 199 B |
Before Width: | Height: | Size: 239 B |
Before Width: | Height: | Size: 185 B |
@ -51,7 +51,7 @@ public class AndroidCalculatorDisplayView extends AutoResizeTextView implements
|
|||||||
private final Object lock = new Object();
|
private final Object lock = new Object();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final Handler handler = new Handler();
|
private final Handler uiHandler = new Handler();
|
||||||
|
|
||||||
private volatile boolean initialized = false;
|
private volatile boolean initialized = false;
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ public class AndroidCalculatorDisplayView extends AutoResizeTextView implements
|
|||||||
@Override
|
@Override
|
||||||
public void setState(@NotNull final CalculatorDisplayViewState state) {
|
public void setState(@NotNull final CalculatorDisplayViewState state) {
|
||||||
|
|
||||||
handler.post(new Runnable() {
|
uiHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
@ -96,7 +96,12 @@ public class AndroidCalculatorDisplayView extends AutoResizeTextView implements
|
|||||||
try {
|
try {
|
||||||
viewStateChange = true;
|
viewStateChange = true;
|
||||||
|
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
final CharSequence text = prepareText(state.getStringResult(), state.isValid());
|
final CharSequence text = prepareText(state.getStringResult(), state.isValid());
|
||||||
|
long endTime = System.currentTimeMillis();
|
||||||
|
long totalTime = (endTime - startTime);
|
||||||
|
CalculatorLocatorImpl.getInstance().getLogger().debug("CalculatorDisplayView", "Total time, ms: " + totalTime);
|
||||||
|
|
||||||
|
|
||||||
AndroidCalculatorDisplayView.this.state = state;
|
AndroidCalculatorDisplayView.this.state = state;
|
||||||
if (state.isValid()) {
|
if (state.isValid()) {
|
||||||
|
@ -22,6 +22,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.calculator.text.TextProcessor;
|
import org.solovyev.android.calculator.text.TextProcessor;
|
||||||
import org.solovyev.android.calculator.view.TextHighlighter;
|
import org.solovyev.android.calculator.view.TextHighlighter;
|
||||||
|
import org.solovyev.android.prefs.BooleanPreference;
|
||||||
import org.solovyev.common.collections.CollectionsUtils;
|
import org.solovyev.common.collections.CollectionsUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,8 +32,8 @@ import org.solovyev.common.collections.CollectionsUtils;
|
|||||||
*/
|
*/
|
||||||
public class AndroidCalculatorEditorView extends EditText implements SharedPreferences.OnSharedPreferenceChangeListener, CalculatorEditorView {
|
public class AndroidCalculatorEditorView extends EditText implements SharedPreferences.OnSharedPreferenceChangeListener, CalculatorEditorView {
|
||||||
|
|
||||||
private static final String CALC_COLOR_DISPLAY_KEY = "org.solovyev.android.calculator.CalculatorModel_color_display";
|
@NotNull
|
||||||
private static final boolean CALC_COLOR_DISPLAY_DEFAULT = true;
|
private static final BooleanPreference colorDisplay = new BooleanPreference("org.solovyev.android.calculator.CalculatorModel_color_display", true);
|
||||||
|
|
||||||
private volatile boolean initialized = false;
|
private volatile boolean initialized = false;
|
||||||
|
|
||||||
@ -51,7 +52,7 @@ public class AndroidCalculatorEditorView extends EditText implements SharedPrefe
|
|||||||
private static final Object lock = new Object();
|
private static final Object lock = new Object();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final Handler handler = new Handler();
|
private final Handler uiHandler = new Handler();
|
||||||
|
|
||||||
public AndroidCalculatorEditorView(Context context) {
|
public AndroidCalculatorEditorView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
@ -132,8 +133,8 @@ public class AndroidCalculatorEditorView extends EditText implements SharedPrefe
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||||
if (CALC_COLOR_DISPLAY_KEY.equals(key)) {
|
if (colorDisplay.getKey().equals(key)) {
|
||||||
this.setHighlightText(preferences.getBoolean(CALC_COLOR_DISPLAY_KEY, CALC_COLOR_DISPLAY_DEFAULT));
|
this.setHighlightText(colorDisplay.getPreference(preferences));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,7 +146,7 @@ public class AndroidCalculatorEditorView extends EditText implements SharedPrefe
|
|||||||
|
|
||||||
this.addTextChangedListener(new TextWatcherImpl());
|
this.addTextChangedListener(new TextWatcherImpl());
|
||||||
|
|
||||||
onSharedPreferenceChanged(preferences, CALC_COLOR_DISPLAY_KEY);
|
onSharedPreferenceChanged(preferences, colorDisplay.getKey());
|
||||||
|
|
||||||
initialized = true;
|
initialized = true;
|
||||||
}
|
}
|
||||||
@ -156,7 +157,7 @@ public class AndroidCalculatorEditorView extends EditText implements SharedPrefe
|
|||||||
|
|
||||||
final CharSequence text = prepareText(viewState.getText(), highlightText);
|
final CharSequence text = prepareText(viewState.getText(), highlightText);
|
||||||
|
|
||||||
handler.post(new Runnable() {
|
uiHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final AndroidCalculatorEditorView editorView = AndroidCalculatorEditorView.this;
|
final AndroidCalculatorEditorView editorView = AndroidCalculatorEditorView.this;
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User: serso
|
||||||
|
* Date: 10/11/12
|
||||||
|
* Time: 12:15 AM
|
||||||
|
*/
|
||||||
|
public class AndroidCalculatorLogger implements CalculatorLogger {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static final String TAG = AndroidCalculatorLogger.class.getSimpleName();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void debug(@Nullable String tag, @NotNull String message) {
|
||||||
|
Log.d(getTag(tag), message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String getTag(@Nullable String tag) {
|
||||||
|
return tag != null ? tag : TAG;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void debug(@Nullable String tag, @NotNull String message, @NotNull Throwable e) {
|
||||||
|
Log.d(getTag(tag), message, e);
|
||||||
|
}
|
||||||
|
}
|
@ -86,7 +86,8 @@ public class CalculatorApplication extends android.app.Application {
|
|||||||
new AndroidCalculatorEngine(this),
|
new AndroidCalculatorEngine(this),
|
||||||
new AndroidCalculatorClipboard(this),
|
new AndroidCalculatorClipboard(this),
|
||||||
new AndroidCalculatorNotifier(this),
|
new AndroidCalculatorNotifier(this),
|
||||||
new AndroidCalculatorHistory(this, calculator));
|
new AndroidCalculatorHistory(this, calculator),
|
||||||
|
new AndroidCalculatorLogger());
|
||||||
|
|
||||||
CalculatorLocatorImpl.getInstance().getCalculator().init();
|
CalculatorLocatorImpl.getInstance().getCalculator().init();
|
||||||
|
|
||||||
|
@ -75,17 +75,8 @@ public final class CalculatorButtons {
|
|||||||
if (equalsButton != null) {
|
if (equalsButton != null) {
|
||||||
if (CalculatorPreferences.Gui.showEqualsButton.getPreference(preferences)) {
|
if (CalculatorPreferences.Gui.showEqualsButton.getPreference(preferences)) {
|
||||||
equalsButton.setVisibility(View.VISIBLE);
|
equalsButton.setVisibility(View.VISIBLE);
|
||||||
final AndroidCalculatorDisplayView calculatorDisplayView = getCalculatorDisplayView();
|
|
||||||
if (calculatorDisplayView != null) {
|
|
||||||
calculatorDisplayView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
equalsButton.setVisibility(View.GONE);
|
equalsButton.setVisibility(View.GONE);
|
||||||
// mobile phones
|
|
||||||
final AndroidCalculatorDisplayView calculatorDisplayView = getCalculatorDisplayView();
|
|
||||||
if (calculatorDisplayView != null) {
|
|
||||||
calculatorDisplayView.setCompoundDrawablesWithIntrinsicBounds(activity.getResources().getDrawable(R.drawable.equals9), null, null, null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import org.solovyev.android.calculator.history.CalculatorHistory;
|
|||||||
public class CalculatorTestUtils {
|
public class CalculatorTestUtils {
|
||||||
|
|
||||||
public static void staticSetUp() throws Exception {
|
public static void staticSetUp() throws Exception {
|
||||||
CalculatorLocatorImpl.getInstance().init(new CalculatorImpl(), newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(CalculatorHistory.class));
|
CalculatorLocatorImpl.getInstance().init(new CalculatorImpl(), newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(CalculatorHistory.class), null);
|
||||||
CalculatorLocatorImpl.getInstance().getEngine().init();
|
CalculatorLocatorImpl.getInstance().getEngine().init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|