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() {
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 CalculatorClipboard clipboard,
@NotNull CalculatorNotifier notifier,
@NotNull CalculatorHistory history);
@NotNull CalculatorHistory history,
@NotNull CalculatorLogger logger);
@NotNull
Calculator getCalculator();
@ -39,4 +40,7 @@ public interface CalculatorLocator {
@NotNull
CalculatorHistory getHistory();
@NotNull
CalculatorLogger getLogger();
}

View File

@ -31,6 +31,9 @@ public class CalculatorLocatorImpl implements CalculatorLocator {
@NotNull
private CalculatorNotifier calculatorNotifier = new DummyCalculatorNotifier();
@NotNull
private CalculatorLogger calculatorLogger = new SystemOutCalculatorLogger();
@NotNull
private CalculatorClipboard calculatorClipboard = new DummyCalculatorClipboard();
@ -45,13 +48,15 @@ public class CalculatorLocatorImpl implements CalculatorLocator {
@NotNull CalculatorEngine engine,
@NotNull CalculatorClipboard clipboard,
@NotNull CalculatorNotifier notifier,
@NotNull CalculatorHistory history) {
@NotNull CalculatorHistory history,
@NotNull CalculatorLogger logger) {
this.calculator = calculator;
this.calculatorEngine = engine;
this.calculatorClipboard = clipboard;
this.calculatorNotifier = notifier;
this.calculatorHistory = history;
this.calculatorLogger = logger;
calculatorEditor = new CalculatorEditorImpl(this.calculator);
calculatorDisplay = new CalculatorDisplayImpl(this.calculator);
@ -110,4 +115,10 @@ public class CalculatorLocatorImpl implements CalculatorLocator {
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) {
final List<CalculatorEventListener> listeners = this.listeners.getListeners();
final CalculatorLogger logger = CalculatorLocatorImpl.getInstance().getLogger();
for (CalculatorEvent e : calculatorEvents) {
//Log.d(TAG, "Event: " + e.getCalculatorEventType() + " with data: " + e.getData());
for (CalculatorEventListener listener : listeners) {
long startTime = System.currentTimeMillis();
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 {
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();
}

View File

@ -22,7 +22,7 @@ public class CalculatorTestUtils {
public static final int TIMEOUT = 1;
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();
}

View File

@ -11,14 +11,14 @@
target=android-15
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.3=gen-external-apklibs/org.solovyev.android_android-common-view_1.0.0
android.library.reference.4=gen-external-apklibs/org.solovyev.android_android-common-preferences_1.0.0
android.library.reference.5=gen-external-apklibs/org.solovyev.android_android-common-other_1.0.0
android.library.reference.6=gen-external-apklibs/org.solovyev.android_android-common-menu_1.0.0
android.library.reference.7=gen-external-apklibs/org.solovyev.android_android-common-sherlock_1.0.0
android.library.reference.8=gen-external-apklibs/com.actionbarsherlock_library_4.1.0
android.library.reference.9=gen-external-apklibs/org.solovyev.android_android-common-list_1.0.0
android.library.reference.10=gen-external-apklibs/org.solovyev.android_billing_0.2
android.library.reference.11=gen-external-apklibs/org.solovyev.android_android-common-db_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-db_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-preferences_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/org.solovyev.android_android-common-menu_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/com.actionbarsherlock_library_4.1.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();
@NotNull
private final Handler handler = new Handler();
private final Handler uiHandler = new Handler();
private volatile boolean initialized = false;
@ -88,7 +88,7 @@ public class AndroidCalculatorDisplayView extends AutoResizeTextView implements
@Override
public void setState(@NotNull final CalculatorDisplayViewState state) {
handler.post(new Runnable() {
uiHandler.post(new Runnable() {
@Override
public void run() {
@ -96,7 +96,12 @@ public class AndroidCalculatorDisplayView extends AutoResizeTextView implements
try {
viewStateChange = true;
long startTime = System.currentTimeMillis();
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;
if (state.isValid()) {

View File

@ -22,6 +22,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.text.TextProcessor;
import org.solovyev.android.calculator.view.TextHighlighter;
import org.solovyev.android.prefs.BooleanPreference;
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 {
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;
@ -51,7 +52,7 @@ public class AndroidCalculatorEditorView extends EditText implements SharedPrefe
private static final Object lock = new Object();
@NotNull
private final Handler handler = new Handler();
private final Handler uiHandler = new Handler();
public AndroidCalculatorEditorView(Context context) {
super(context);
@ -132,8 +133,8 @@ public class AndroidCalculatorEditorView extends EditText implements SharedPrefe
@Override
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
if (CALC_COLOR_DISPLAY_KEY.equals(key)) {
this.setHighlightText(preferences.getBoolean(CALC_COLOR_DISPLAY_KEY, CALC_COLOR_DISPLAY_DEFAULT));
if (colorDisplay.getKey().equals(key)) {
this.setHighlightText(colorDisplay.getPreference(preferences));
}
}
@ -145,7 +146,7 @@ public class AndroidCalculatorEditorView extends EditText implements SharedPrefe
this.addTextChangedListener(new TextWatcherImpl());
onSharedPreferenceChanged(preferences, CALC_COLOR_DISPLAY_KEY);
onSharedPreferenceChanged(preferences, colorDisplay.getKey());
initialized = true;
}
@ -156,7 +157,7 @@ public class AndroidCalculatorEditorView extends EditText implements SharedPrefe
final CharSequence text = prepareText(viewState.getText(), highlightText);
handler.post(new Runnable() {
uiHandler.post(new Runnable() {
@Override
public void run() {
final AndroidCalculatorEditorView editorView = AndroidCalculatorEditorView.this;

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 AndroidCalculatorClipboard(this),
new AndroidCalculatorNotifier(this),
new AndroidCalculatorHistory(this, calculator));
new AndroidCalculatorHistory(this, calculator),
new AndroidCalculatorLogger());
CalculatorLocatorImpl.getInstance().getCalculator().init();

View File

@ -75,17 +75,8 @@ public final class CalculatorButtons {
if (equalsButton != null) {
if (CalculatorPreferences.Gui.showEqualsButton.getPreference(preferences)) {
equalsButton.setVisibility(View.VISIBLE);
final AndroidCalculatorDisplayView calculatorDisplayView = getCalculatorDisplayView();
if (calculatorDisplayView != null) {
calculatorDisplayView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
}
} else {
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 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();
}