This commit is contained in:
Sergey Solovyev 2012-10-11 00:54:02 +04:00
parent 6517293359
commit 64f5f0c44a
23 changed files with 458 additions and 352 deletions

View File

@ -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 +
'}';
}
} }

View File

@ -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();
} }

View File

@ -1,113 +1,124 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.history.CalculatorHistory; import org.solovyev.android.calculator.history.CalculatorHistory;
/** /**
* User: Solovyev_S * User: Solovyev_S
* Date: 20.09.12 * Date: 20.09.12
* Time: 12:45 * Time: 12:45
*/ */
public class CalculatorLocatorImpl implements CalculatorLocator { public class CalculatorLocatorImpl implements CalculatorLocator {
@NotNull @NotNull
private CalculatorEngine calculatorEngine; private CalculatorEngine calculatorEngine;
@NotNull @NotNull
private Calculator calculator; private Calculator calculator;
@NotNull @NotNull
private CalculatorEditor calculatorEditor; private CalculatorEditor calculatorEditor;
@NotNull @NotNull
private CalculatorDisplay calculatorDisplay; private CalculatorDisplay calculatorDisplay;
@NotNull @NotNull
private CalculatorKeyboard calculatorKeyboard; private CalculatorKeyboard calculatorKeyboard;
@NotNull @NotNull
private CalculatorHistory calculatorHistory; private CalculatorHistory calculatorHistory;
@NotNull @NotNull
private CalculatorNotifier calculatorNotifier = new DummyCalculatorNotifier(); private CalculatorNotifier calculatorNotifier = new DummyCalculatorNotifier();
@NotNull @NotNull
private CalculatorClipboard calculatorClipboard = new DummyCalculatorClipboard(); private CalculatorLogger calculatorLogger = new SystemOutCalculatorLogger();
@NotNull @NotNull
private static final CalculatorLocator instance = new CalculatorLocatorImpl(); private CalculatorClipboard calculatorClipboard = new DummyCalculatorClipboard();
public CalculatorLocatorImpl() { @NotNull
} private static final CalculatorLocator instance = new CalculatorLocatorImpl();
@Override public CalculatorLocatorImpl() {
public void init(@NotNull Calculator calculator, }
@NotNull CalculatorEngine engine,
@NotNull CalculatorClipboard clipboard, @Override
@NotNull CalculatorNotifier notifier, public void init(@NotNull Calculator calculator,
@NotNull CalculatorHistory history) { @NotNull CalculatorEngine engine,
@NotNull CalculatorClipboard clipboard,
this.calculator = calculator; @NotNull CalculatorNotifier notifier,
this.calculatorEngine = engine; @NotNull CalculatorHistory history,
this.calculatorClipboard = clipboard; @NotNull CalculatorLogger logger) {
this.calculatorNotifier = notifier;
this.calculatorHistory = history; this.calculator = calculator;
this.calculatorEngine = engine;
calculatorEditor = new CalculatorEditorImpl(this.calculator); this.calculatorClipboard = clipboard;
calculatorDisplay = new CalculatorDisplayImpl(this.calculator); this.calculatorNotifier = notifier;
calculatorKeyboard = new CalculatorKeyboardImpl(this.calculator); this.calculatorHistory = history;
} this.calculatorLogger = logger;
@NotNull calculatorEditor = new CalculatorEditorImpl(this.calculator);
public static CalculatorLocator getInstance() { calculatorDisplay = new CalculatorDisplayImpl(this.calculator);
return instance; calculatorKeyboard = new CalculatorKeyboardImpl(this.calculator);
} }
@NotNull @NotNull
@Override public static CalculatorLocator getInstance() {
public CalculatorEngine getEngine() { return instance;
return calculatorEngine; }
}
@NotNull
@NotNull @Override
@Override public CalculatorEngine getEngine() {
public Calculator getCalculator() { return calculatorEngine;
return this.calculator; }
}
@NotNull
@Override @Override
@NotNull public Calculator getCalculator() {
public CalculatorDisplay getDisplay() { return this.calculator;
return calculatorDisplay; }
}
@Override
@NotNull @NotNull
@Override public CalculatorDisplay getDisplay() {
public CalculatorEditor getEditor() { return calculatorDisplay;
return calculatorEditor; }
}
@NotNull
@Override @Override
@NotNull public CalculatorEditor getEditor() {
public CalculatorKeyboard getKeyboard() { return calculatorEditor;
return calculatorKeyboard; }
}
@Override
@Override @NotNull
@NotNull public CalculatorKeyboard getKeyboard() {
public CalculatorClipboard getClipboard() { return calculatorKeyboard;
return calculatorClipboard; }
}
@Override
@Override @NotNull
@NotNull public CalculatorClipboard getClipboard() {
public CalculatorNotifier getNotifier() { return calculatorClipboard;
return calculatorNotifier; }
}
@Override
@Override @NotNull
@NotNull public CalculatorNotifier getNotifier() {
public CalculatorHistory getHistory() { return calculatorNotifier;
return calculatorHistory; }
}
} @Override
@NotNull
public CalculatorHistory getHistory() {
return calculatorHistory;
}
@Override
@NotNull
public CalculatorLogger getLogger() {
return calculatorLogger;
}
}

View File

@ -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);
}

View File

@ -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);
}
} }
} }
} }

View File

@ -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);
}
}

View File

@ -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();
} }

View File

@ -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();
} }

View File

@ -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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 344 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 223 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 347 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 211 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 321 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 199 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 239 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 185 B

View File

@ -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()) {

View File

@ -1,213 +1,214 @@
/* /*
* Copyright (c) 2009-2011. Created by serso aka se.solovyev. * Copyright (c) 2009-2011. Created by serso aka se.solovyev.
* For more information, please, contact se.solovyev@gmail.com * For more information, please, contact se.solovyev@gmail.com
*/ */
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Color; import android.graphics.Color;
import android.os.Build; import android.os.Build;
import android.os.Handler; import android.os.Handler;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.text.Editable; import android.text.Editable;
import android.text.Html; import android.text.Html;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log; import android.util.Log;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.widget.EditText; import android.widget.EditText;
import org.jetbrains.annotations.NotNull; 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.common.collections.CollectionsUtils; import org.solovyev.android.prefs.BooleanPreference;
import org.solovyev.common.collections.CollectionsUtils;
/**
* User: serso /**
* Date: 9/17/11 * User: serso
* Time: 12:25 AM * Date: 9/17/11
*/ * Time: 12:25 AM
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";
private static final boolean CALC_COLOR_DISPLAY_DEFAULT = true; @NotNull
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;
private boolean highlightText = true;
private boolean highlightText = true;
@NotNull
private final static TextProcessor<TextHighlighter.Result, String> textHighlighter = new TextHighlighter(Color.WHITE, false); @NotNull
private final static TextProcessor<TextHighlighter.Result, String> textHighlighter = new TextHighlighter(Color.WHITE, false);
@NotNull
private volatile CalculatorEditorViewState viewState = CalculatorEditorViewStateImpl.newDefaultInstance(); @NotNull
private volatile CalculatorEditorViewState viewState = CalculatorEditorViewStateImpl.newDefaultInstance();
private volatile boolean viewStateChange = false;
private volatile boolean viewStateChange = false;
// NOTE: static because super constructor calls some overridden methods (like onSelectionChanged and current lock is not yet created)
@NotNull // NOTE: static because super constructor calls some overridden methods (like onSelectionChanged and current lock is not yet created)
private static final Object lock = new Object(); @NotNull
private static final Object lock = new Object();
@NotNull
private final Handler handler = new Handler(); @NotNull
private final Handler uiHandler = new Handler();
public AndroidCalculatorEditorView(Context context) {
super(context); public AndroidCalculatorEditorView(Context context) {
} super(context);
}
public AndroidCalculatorEditorView(Context context, AttributeSet attrs) {
super(context, attrs); public AndroidCalculatorEditorView(Context context, AttributeSet attrs) {
} super(context, attrs);
}
public AndroidCalculatorEditorView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle); public AndroidCalculatorEditorView(Context context, AttributeSet attrs, int defStyle) {
} super(context, attrs, defStyle);
}
@Override
public boolean onCheckIsTextEditor() { @Override
// NOTE: code below can be used carefully and should not be copied without special intention public boolean onCheckIsTextEditor() {
// The main purpose of code is to disable soft input (virtual keyboard) but leave all the TextEdit functionality, like cursor, scrolling, copy/paste menu etc // NOTE: code below can be used carefully and should not be copied without special intention
// The main purpose of code is to disable soft input (virtual keyboard) but leave all the TextEdit functionality, like cursor, scrolling, copy/paste menu etc
if (Build.VERSION.SDK_INT >= 11) {
// fix for missing cursor in android 3 and higher if (Build.VERSION.SDK_INT >= 11) {
try { // fix for missing cursor in android 3 and higher
// IDEA: return false always except if method was called from TextView.isCursorVisible() method try {
for (StackTraceElement stackTraceElement : CollectionsUtils.asList(Thread.currentThread().getStackTrace())) { // IDEA: return false always except if method was called from TextView.isCursorVisible() method
if ("isCursorVisible".equals(stackTraceElement.getMethodName())) { for (StackTraceElement stackTraceElement : CollectionsUtils.asList(Thread.currentThread().getStackTrace())) {
return true; if ("isCursorVisible".equals(stackTraceElement.getMethodName())) {
} return true;
} }
} catch (RuntimeException e) { }
// just in case... } catch (RuntimeException e) {
} // just in case...
}
return false;
} else { return false;
return false; } else {
} return false;
} }
}
@Override
protected void onCreateContextMenu(ContextMenu menu) { @Override
super.onCreateContextMenu(menu); protected void onCreateContextMenu(ContextMenu menu) {
super.onCreateContextMenu(menu);
menu.removeItem(android.R.id.selectAll);
} menu.removeItem(android.R.id.selectAll);
}
@Nullable
private CharSequence prepareText(@NotNull String text, boolean highlightText) { @Nullable
CharSequence result; private CharSequence prepareText(@NotNull String text, boolean highlightText) {
CharSequence result;
if (highlightText) {
if (highlightText) {
try {
final TextHighlighter.Result processesText = textHighlighter.process(text); try {
final TextHighlighter.Result processesText = textHighlighter.process(text);
assert processesText.getOffset() == 0;
assert processesText.getOffset() == 0;
result = Html.fromHtml(processesText.toString());
} catch (CalculatorParseException e) { result = Html.fromHtml(processesText.toString());
// set raw text } catch (CalculatorParseException e) {
result = text; // set raw text
result = text;
Log.e(this.getClass().getName(), e.getMessage(), e);
} Log.e(this.getClass().getName(), e.getMessage(), e);
} else { }
result = text; } else {
} result = text;
}
return result;
} return result;
}
public boolean isHighlightText() {
return highlightText; public boolean isHighlightText() {
} return highlightText;
}
public void setHighlightText(boolean highlightText) {
this.highlightText = highlightText; public void setHighlightText(boolean highlightText) {
CalculatorLocatorImpl.getInstance().getEditor().updateViewState(); this.highlightText = highlightText;
} CalculatorLocatorImpl.getInstance().getEditor().updateViewState();
}
@Override
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) { @Override
if (CALC_COLOR_DISPLAY_KEY.equals(key)) { public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
this.setHighlightText(preferences.getBoolean(CALC_COLOR_DISPLAY_KEY, CALC_COLOR_DISPLAY_DEFAULT)); if (colorDisplay.getKey().equals(key)) {
} this.setHighlightText(colorDisplay.getPreference(preferences));
} }
}
public synchronized void init(@NotNull Context context) {
if (!initialized) { public synchronized void init(@NotNull Context context) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); if (!initialized) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
preferences.registerOnSharedPreferenceChangeListener(this);
preferences.registerOnSharedPreferenceChangeListener(this);
this.addTextChangedListener(new TextWatcherImpl());
this.addTextChangedListener(new TextWatcherImpl());
onSharedPreferenceChanged(preferences, CALC_COLOR_DISPLAY_KEY);
onSharedPreferenceChanged(preferences, colorDisplay.getKey());
initialized = true;
} initialized = true;
} }
}
@Override
public void setState(@NotNull final CalculatorEditorViewState viewState) { @Override
public void setState(@NotNull final CalculatorEditorViewState viewState) {
final CharSequence text = prepareText(viewState.getText(), highlightText);
final CharSequence text = prepareText(viewState.getText(), highlightText);
handler.post(new Runnable() {
@Override uiHandler.post(new Runnable() {
public void run() { @Override
final AndroidCalculatorEditorView editorView = AndroidCalculatorEditorView.this; public void run() {
synchronized (lock) { final AndroidCalculatorEditorView editorView = AndroidCalculatorEditorView.this;
try { synchronized (lock) {
editorView.viewStateChange = true; try {
editorView.viewState = viewState; editorView.viewStateChange = true;
editorView.setText(text, BufferType.EDITABLE); editorView.viewState = viewState;
editorView.setSelection(viewState.getSelection()); editorView.setText(text, BufferType.EDITABLE);
} finally { editorView.setSelection(viewState.getSelection());
editorView.viewStateChange = false; } finally {
} editorView.viewStateChange = false;
} }
} }
}); }
} });
}
@Override
protected void onSelectionChanged(int selStart, int selEnd) { @Override
synchronized (lock) { protected void onSelectionChanged(int selStart, int selEnd) {
if (!viewStateChange) { synchronized (lock) {
// external text change => need to notify editor if (!viewStateChange) {
super.onSelectionChanged(selStart, selEnd); // external text change => need to notify editor
CalculatorLocatorImpl.getInstance().getEditor().setSelection(selStart); super.onSelectionChanged(selStart, selEnd);
} CalculatorLocatorImpl.getInstance().getEditor().setSelection(selStart);
} }
} }
}
public void handleTextChange(Editable s) {
synchronized (lock) { public void handleTextChange(Editable s) {
if (!viewStateChange) { synchronized (lock) {
// external text change => need to notify editor if (!viewStateChange) {
CalculatorLocatorImpl.getInstance().getEditor().setText(String.valueOf(s)); // external text change => need to notify editor
} CalculatorLocatorImpl.getInstance().getEditor().setText(String.valueOf(s));
} }
} }
}
private final class TextWatcherImpl implements TextWatcher {
private final class TextWatcherImpl implements TextWatcher {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { @Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) { @Override
} public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) { @Override
handleTextChange(s); public void afterTextChanged(Editable s) {
} handleTextChange(s);
} }
} }
}

View File

@ -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);
}
}

View File

@ -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();

View File

@ -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);
}
} }
} }
} }

View File

@ -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();
} }