From 64f5f0c44a30c7b0ab0edff276e1324418798cb2 Mon Sep 17 00:00:00 2001 From: Sergey Solovyev Date: Thu, 11 Oct 2012 00:54:02 +0400 Subject: [PATCH] changes --- .../calculator/CalculatorFailureImpl.java | 7 + .../android/calculator/CalculatorLocator.java | 6 +- .../calculator/CalculatorLocatorImpl.java | 237 +++++----- .../android/calculator/CalculatorLogger.java | 16 + .../ListCalculatorEventContainer.java | 10 +- .../calculator/SystemOutCalculatorLogger.java | 31 ++ .../calculator/AbstractCalculatorTest.java | 2 +- .../calculator/CalculatorTestUtils.java | 2 +- calculatorpp/project.properties | 18 +- calculatorpp/res/drawable-hdpi/equals.png | Bin 344 -> 0 bytes calculatorpp/res/drawable-hdpi/equals9.9.png | Bin 223 -> 0 bytes calculatorpp/res/drawable-ldpi/equals.png | Bin 347 -> 0 bytes calculatorpp/res/drawable-ldpi/equals9.9.png | Bin 211 -> 0 bytes calculatorpp/res/drawable-mdpi/equals.png | Bin 321 -> 0 bytes calculatorpp/res/drawable-mdpi/equals9.9.png | Bin 199 -> 0 bytes calculatorpp/res/drawable-xhdpi/equals.png | Bin 239 -> 0 bytes calculatorpp/res/drawable-xhdpi/equals9.9.png | Bin 185 -> 0 bytes .../AndroidCalculatorDisplayView.java | 9 +- .../AndroidCalculatorEditorView.java | 427 +++++++++--------- .../calculator/AndroidCalculatorLogger.java | 31 ++ .../calculator/CalculatorApplication.java | 3 +- .../android/calculator/CalculatorButtons.java | 9 - .../calculator/CalculatorTestUtils.java | 2 +- 23 files changed, 458 insertions(+), 352 deletions(-) create mode 100644 calculatorpp-core/src/main/java/org/solovyev/android/calculator/CalculatorLogger.java create mode 100644 calculatorpp-core/src/main/java/org/solovyev/android/calculator/SystemOutCalculatorLogger.java delete mode 100644 calculatorpp/res/drawable-hdpi/equals.png delete mode 100644 calculatorpp/res/drawable-hdpi/equals9.9.png delete mode 100644 calculatorpp/res/drawable-ldpi/equals.png delete mode 100644 calculatorpp/res/drawable-ldpi/equals9.9.png delete mode 100644 calculatorpp/res/drawable-mdpi/equals.png delete mode 100644 calculatorpp/res/drawable-mdpi/equals9.9.png delete mode 100644 calculatorpp/res/drawable-xhdpi/equals.png delete mode 100644 calculatorpp/res/drawable-xhdpi/equals9.9.png create mode 100644 calculatorpp/src/main/java/org/solovyev/android/calculator/AndroidCalculatorLogger.java diff --git a/calculatorpp-core/src/main/java/org/solovyev/android/calculator/CalculatorFailureImpl.java b/calculatorpp-core/src/main/java/org/solovyev/android/calculator/CalculatorFailureImpl.java index 866146b3..2603093c 100644 --- a/calculatorpp-core/src/main/java/org/solovyev/android/calculator/CalculatorFailureImpl.java +++ b/calculatorpp-core/src/main/java/org/solovyev/android/calculator/CalculatorFailureImpl.java @@ -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 + + '}'; + } } diff --git a/calculatorpp-core/src/main/java/org/solovyev/android/calculator/CalculatorLocator.java b/calculatorpp-core/src/main/java/org/solovyev/android/calculator/CalculatorLocator.java index 8fcb7732..04a321a6 100644 --- a/calculatorpp-core/src/main/java/org/solovyev/android/calculator/CalculatorLocator.java +++ b/calculatorpp-core/src/main/java/org/solovyev/android/calculator/CalculatorLocator.java @@ -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(); } diff --git a/calculatorpp-core/src/main/java/org/solovyev/android/calculator/CalculatorLocatorImpl.java b/calculatorpp-core/src/main/java/org/solovyev/android/calculator/CalculatorLocatorImpl.java index 6f65ac48..d1ab0604 100644 --- a/calculatorpp-core/src/main/java/org/solovyev/android/calculator/CalculatorLocatorImpl.java +++ b/calculatorpp-core/src/main/java/org/solovyev/android/calculator/CalculatorLocatorImpl.java @@ -1,113 +1,124 @@ -package org.solovyev.android.calculator; - -import org.jetbrains.annotations.NotNull; -import org.solovyev.android.calculator.history.CalculatorHistory; - -/** - * User: Solovyev_S - * Date: 20.09.12 - * Time: 12:45 - */ -public class CalculatorLocatorImpl implements CalculatorLocator { - - @NotNull - private CalculatorEngine calculatorEngine; - - @NotNull - private Calculator calculator; - - @NotNull - private CalculatorEditor calculatorEditor; - - @NotNull - private CalculatorDisplay calculatorDisplay; - - @NotNull - private CalculatorKeyboard calculatorKeyboard; - - @NotNull - private CalculatorHistory calculatorHistory; - - @NotNull - private CalculatorNotifier calculatorNotifier = new DummyCalculatorNotifier(); - - @NotNull - private CalculatorClipboard calculatorClipboard = new DummyCalculatorClipboard(); - - @NotNull - private static final CalculatorLocator instance = new CalculatorLocatorImpl(); - - public CalculatorLocatorImpl() { - } - - @Override - public void init(@NotNull Calculator calculator, - @NotNull CalculatorEngine engine, - @NotNull CalculatorClipboard clipboard, - @NotNull CalculatorNotifier notifier, - @NotNull CalculatorHistory history) { - - this.calculator = calculator; - this.calculatorEngine = engine; - this.calculatorClipboard = clipboard; - this.calculatorNotifier = notifier; - this.calculatorHistory = history; - - calculatorEditor = new CalculatorEditorImpl(this.calculator); - calculatorDisplay = new CalculatorDisplayImpl(this.calculator); - calculatorKeyboard = new CalculatorKeyboardImpl(this.calculator); - } - - @NotNull - public static CalculatorLocator getInstance() { - return instance; - } - - @NotNull - @Override - public CalculatorEngine getEngine() { - return calculatorEngine; - } - - @NotNull - @Override - public Calculator getCalculator() { - return this.calculator; - } - - @Override - @NotNull - public CalculatorDisplay getDisplay() { - return calculatorDisplay; - } - - @NotNull - @Override - public CalculatorEditor getEditor() { - return calculatorEditor; - } - - @Override - @NotNull - public CalculatorKeyboard getKeyboard() { - return calculatorKeyboard; - } - - @Override - @NotNull - public CalculatorClipboard getClipboard() { - return calculatorClipboard; - } - - @Override - @NotNull - public CalculatorNotifier getNotifier() { - return calculatorNotifier; - } - - @Override - @NotNull - public CalculatorHistory getHistory() { - return calculatorHistory; - } -} +package org.solovyev.android.calculator; + +import org.jetbrains.annotations.NotNull; +import org.solovyev.android.calculator.history.CalculatorHistory; + +/** + * User: Solovyev_S + * Date: 20.09.12 + * Time: 12:45 + */ +public class CalculatorLocatorImpl implements CalculatorLocator { + + @NotNull + private CalculatorEngine calculatorEngine; + + @NotNull + private Calculator calculator; + + @NotNull + private CalculatorEditor calculatorEditor; + + @NotNull + private CalculatorDisplay calculatorDisplay; + + @NotNull + private CalculatorKeyboard calculatorKeyboard; + + @NotNull + private CalculatorHistory calculatorHistory; + + @NotNull + private CalculatorNotifier calculatorNotifier = new DummyCalculatorNotifier(); + + @NotNull + private CalculatorLogger calculatorLogger = new SystemOutCalculatorLogger(); + + @NotNull + private CalculatorClipboard calculatorClipboard = new DummyCalculatorClipboard(); + + @NotNull + private static final CalculatorLocator instance = new CalculatorLocatorImpl(); + + public CalculatorLocatorImpl() { + } + + @Override + public void init(@NotNull Calculator calculator, + @NotNull CalculatorEngine engine, + @NotNull CalculatorClipboard clipboard, + @NotNull CalculatorNotifier notifier, + @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); + calculatorKeyboard = new CalculatorKeyboardImpl(this.calculator); + } + + @NotNull + public static CalculatorLocator getInstance() { + return instance; + } + + @NotNull + @Override + public CalculatorEngine getEngine() { + return calculatorEngine; + } + + @NotNull + @Override + public Calculator getCalculator() { + return this.calculator; + } + + @Override + @NotNull + public CalculatorDisplay getDisplay() { + return calculatorDisplay; + } + + @NotNull + @Override + public CalculatorEditor getEditor() { + return calculatorEditor; + } + + @Override + @NotNull + public CalculatorKeyboard getKeyboard() { + return calculatorKeyboard; + } + + @Override + @NotNull + public CalculatorClipboard getClipboard() { + return calculatorClipboard; + } + + @Override + @NotNull + public CalculatorNotifier getNotifier() { + return calculatorNotifier; + } + + @Override + @NotNull + public CalculatorHistory getHistory() { + return calculatorHistory; + } + + @Override + @NotNull + public CalculatorLogger getLogger() { + return calculatorLogger; + } +} diff --git a/calculatorpp-core/src/main/java/org/solovyev/android/calculator/CalculatorLogger.java b/calculatorpp-core/src/main/java/org/solovyev/android/calculator/CalculatorLogger.java new file mode 100644 index 00000000..60057cf8 --- /dev/null +++ b/calculatorpp-core/src/main/java/org/solovyev/android/calculator/CalculatorLogger.java @@ -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); +} diff --git a/calculatorpp-core/src/main/java/org/solovyev/android/calculator/ListCalculatorEventContainer.java b/calculatorpp-core/src/main/java/org/solovyev/android/calculator/ListCalculatorEventContainer.java index 591e3836..4434e9a0 100644 --- a/calculatorpp-core/src/main/java/org/solovyev/android/calculator/ListCalculatorEventContainer.java +++ b/calculatorpp-core/src/main/java/org/solovyev/android/calculator/ListCalculatorEventContainer.java @@ -39,10 +39,18 @@ public class ListCalculatorEventContainer implements CalculatorEventContainer { public void fireCalculatorEvents(@NotNull List calculatorEvents) { final List 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); + } } } } diff --git a/calculatorpp-core/src/main/java/org/solovyev/android/calculator/SystemOutCalculatorLogger.java b/calculatorpp-core/src/main/java/org/solovyev/android/calculator/SystemOutCalculatorLogger.java new file mode 100644 index 00000000..09656a52 --- /dev/null +++ b/calculatorpp-core/src/main/java/org/solovyev/android/calculator/SystemOutCalculatorLogger.java @@ -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); + } +} diff --git a/calculatorpp-core/src/test/java/org/solovyev/android/calculator/AbstractCalculatorTest.java b/calculatorpp-core/src/test/java/org/solovyev/android/calculator/AbstractCalculatorTest.java index 6fe7698e..0aaf1a93 100644 --- a/calculatorpp-core/src/test/java/org/solovyev/android/calculator/AbstractCalculatorTest.java +++ b/calculatorpp-core/src/test/java/org/solovyev/android/calculator/AbstractCalculatorTest.java @@ -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(); } diff --git a/calculatorpp-core/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java b/calculatorpp-core/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java index 46230c8f..acde331d 100644 --- a/calculatorpp-core/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java +++ b/calculatorpp-core/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java @@ -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(); } diff --git a/calculatorpp/project.properties b/calculatorpp/project.properties index 677898c5..78b254f4 100644 --- a/calculatorpp/project.properties +++ b/calculatorpp/project.properties @@ -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 diff --git a/calculatorpp/res/drawable-hdpi/equals.png b/calculatorpp/res/drawable-hdpi/equals.png deleted file mode 100644 index a764106c73f3ba1058da234f2561dbb7b054358b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 344 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpTC#^NA%Cx&(BWL^R}Y)RhkE)4%c zaKYZ?lYt_f1s;*b3=G`DAk4@xYmNj^kiEpy*OmPaizt_d{(+LjJwPGJ64!_l=ltB< z)VvY~=c3falGGH1^30M91$R&1fbd2>aiF5jo-U3d8TZ~^+sk{%K%nj6_cbCREvycx22TR>oc2eGoBxM-F0;AMdgw~FLV2U>+vjJl9uTycs+Y7N zc)#e+3A@if(%#7YExGv#`?LdQ$0~j<>)m!>S5tf5zcQh4{pn8E>$s+^Yy6$FdjiNt bpBvmemdcfc9%PRLI-kMQ)z4*}Q$iB}{LF*w diff --git a/calculatorpp/res/drawable-hdpi/equals9.9.png b/calculatorpp/res/drawable-hdpi/equals9.9.png deleted file mode 100644 index ee2bc0e4d433672d444d8a01193597a1118907ba..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 223 zcmeAS@N?(olHy`uVBq!ia0vp^Mj*_=1|;R|J2nETWu7jMAr-gY-rCFCpdiqeD9pZL zdqDYuhxxqU3YfjGoA5p0sxT|NCDHuA`%~*NiTMX)#X>^ult&8UrbLTBo$n9*Cut%EoR}E zFyCRx*WOE8!)8uzxjCm;mtAQ>|G!030+qMKL(Kyk?CMzb>&EHsbnDz1^SSzJCMp13 O%;4$j=d#Wzp$P!)wozgL diff --git a/calculatorpp/res/drawable-ldpi/equals.png b/calculatorpp/res/drawable-ldpi/equals.png deleted file mode 100644 index f80d4327d70a3635144e1759aa95ee38dedc7f4e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 347 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x`GjjKx9jP7LeL$-D$|*pj^6T^Rm@ z;DWu&Cj&(|3p^r=85p>QL70(Y)*O%l>?NMQuIzVMM7cC2#jYMr0SZZ$xJHyX=jZ08 z=9Mrw7o{eaq^2m8XO?6rxO@5rgg5eu0~Kxaba4#vIR18uE!Uv{ftLM(f-K%|*Vr_s z7V+~hT)UQi<5!iY&?a_)oHsU&W@eJo!cGPrb#Ly4+fKVX_iki`00#@#Ba3%y!$n+= zMvG2d`F84(Gi8gHP1<0~)R#Fc?$eJAleSOTa-Mrug7x~FOk0`EZ%Zp=XL(mP&)@g8 zve~h+seVD%rV7&&?%{2&FQ=vbFB@-=@UNW&^Z|pXtDnm{r-UW|>0g2K diff --git a/calculatorpp/res/drawable-ldpi/equals9.9.png b/calculatorpp/res/drawable-ldpi/equals9.9.png deleted file mode 100644 index b47362e76c59ce737b12773b2a016c205478fc88..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 211 zcmeAS@N?(olHy`uVBq!ia0vp^QXtI11|(N{`J4k%vpiiKLn>}1CoGWt(ckirX$#wb zcU`Hi8CR5~B2sd4bdnMiCnlz*PEE_p^AlowxpB*uGmM+IazwF&WUw9ifAXLM`=J+3 zi)vj~<$HX)_`#dUA^$YPUVB*yp35hWd~W>pw$qcR?TH%O5|@ddJ^fo6y5=*)e(R9o zx$>LOgTe~DWM4fTb@)g diff --git a/calculatorpp/res/drawable-mdpi/equals.png b/calculatorpp/res/drawable-mdpi/equals.png deleted file mode 100644 index 563125c256d32253fe50e1167a3c05870e29ae98..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 321 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz#^NA%Cx&(BWL^R}Y)RhkE)4%c zaKYZ?lYt_f1s;*b3=G`DAk4@xYmNj^kiEpy*OmPaizt^S^Xu(4azG);64!_l=ltB< z)VvY~=c3falGGH1^30M91$R&1fbd2>aiF3(o-U3d5r^MS-pG5%K*VLf@{}o#A~TP^ z)6iTg*)F(ZM#DTk=^Hmy7A;z8l-s1UbmLTyJFjbgUE2QdZli!xNBv<-^Xl109GGPq zt)4%UNM_|xY$;szUTAam14fymx&so-1#I(z_eR~GbcOZafu&PeSGQk?S}mn_Z3Anb z!|cj(-k81L6E$0S3z&8>vG4fLHG9oN_7~idA8y5Pv0^CX zvbMJN|Ao&dI0~CC-kEm6>d1{7GvsHui7|a-(|VkH?b7IeAAC-93ICl1bQy!EtDnm{r-UW|p4LsH diff --git a/calculatorpp/res/drawable-xhdpi/equals.png b/calculatorpp/res/drawable-xhdpi/equals.png deleted file mode 100644 index 9de8a69679b04b3ecd874714f6aa985784d2ff61..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 239 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=jKx9jP7LeL$-D$|*pj^6T^Rm@ z;DWu&Cj&(|3p^r=85p>QL70(Y)*K0-AbW|YuPgf<7EvxWBioM(uYp36C9V-A&iT2y zsd*&~&PAz-C8;S2<(VZJ3hti10pX2&;y^`So-U3d6}R4AUnt6;z~SInqWz7(XQ^^V z=(|m=|2c#hfl3${E*#lWJ7ebStq)hdvbg_dA0rco0s})s_65@y+ByvkOkg$fw=Irx Uh`*REoeAQ4y85}Sb4q9e0HNSUlmGw# diff --git a/calculatorpp/res/drawable-xhdpi/equals9.9.png b/calculatorpp/res/drawable-xhdpi/equals9.9.png deleted file mode 100644 index 2c002b9aa2b60ae6961befb38c08e1a6c4b7dce2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 185 zcmeAS@N?(olHy`uVBq!ia0vp^P9V&|1|%PcFuVX#4W2HJAr-gY-cjUZP~c#2*njlD zeB0SoXBm&XEiPcySaa3>lcN8_FCGF44h;;9Oe`E2jE-pnf)lR_fo1+Q8Q3{O)ro0= pl|KBn#T|>z6}*NEPrg>} textHighlighter = new TextHighlighter(Color.WHITE, false); - - @NotNull - private volatile CalculatorEditorViewState viewState = CalculatorEditorViewStateImpl.newDefaultInstance(); - - private volatile boolean viewStateChange = false; - - // NOTE: static because super constructor calls some overridden methods (like onSelectionChanged and current lock is not yet created) - @NotNull - private static final Object lock = new Object(); - - @NotNull - private final Handler handler = new Handler(); - - public AndroidCalculatorEditorView(Context context) { - super(context); - } - - public AndroidCalculatorEditorView(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public AndroidCalculatorEditorView(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - } - - @Override - public boolean onCheckIsTextEditor() { - // 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 - try { - // IDEA: return false always except if method was called from TextView.isCursorVisible() method - for (StackTraceElement stackTraceElement : CollectionsUtils.asList(Thread.currentThread().getStackTrace())) { - if ("isCursorVisible".equals(stackTraceElement.getMethodName())) { - return true; - } - } - } catch (RuntimeException e) { - // just in case... - } - - return false; - } else { - return false; - } - } - - @Override - protected void onCreateContextMenu(ContextMenu menu) { - super.onCreateContextMenu(menu); - - menu.removeItem(android.R.id.selectAll); - } - - @Nullable - private CharSequence prepareText(@NotNull String text, boolean highlightText) { - CharSequence result; - - if (highlightText) { - - try { - final TextHighlighter.Result processesText = textHighlighter.process(text); - - assert processesText.getOffset() == 0; - - result = Html.fromHtml(processesText.toString()); - } catch (CalculatorParseException e) { - // set raw text - result = text; - - Log.e(this.getClass().getName(), e.getMessage(), e); - } - } else { - result = text; - } - - return result; - } - - public boolean isHighlightText() { - return highlightText; - } - - public void setHighlightText(boolean highlightText) { - this.highlightText = highlightText; - CalculatorLocatorImpl.getInstance().getEditor().updateViewState(); - } - - @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)); - } - } - - public synchronized void init(@NotNull Context context) { - if (!initialized) { - final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); - - preferences.registerOnSharedPreferenceChangeListener(this); - - this.addTextChangedListener(new TextWatcherImpl()); - - onSharedPreferenceChanged(preferences, CALC_COLOR_DISPLAY_KEY); - - initialized = true; - } - } - - @Override - public void setState(@NotNull final CalculatorEditorViewState viewState) { - - final CharSequence text = prepareText(viewState.getText(), highlightText); - - handler.post(new Runnable() { - @Override - public void run() { - final AndroidCalculatorEditorView editorView = AndroidCalculatorEditorView.this; - synchronized (lock) { - try { - editorView.viewStateChange = true; - editorView.viewState = viewState; - editorView.setText(text, BufferType.EDITABLE); - editorView.setSelection(viewState.getSelection()); - } finally { - editorView.viewStateChange = false; - } - } - } - }); - } - - @Override - protected void onSelectionChanged(int selStart, int selEnd) { - synchronized (lock) { - if (!viewStateChange) { - // external text change => need to notify editor - super.onSelectionChanged(selStart, selEnd); - CalculatorLocatorImpl.getInstance().getEditor().setSelection(selStart); - } - } - } - - public void handleTextChange(Editable s) { - synchronized (lock) { - if (!viewStateChange) { - // external text change => need to notify editor - CalculatorLocatorImpl.getInstance().getEditor().setText(String.valueOf(s)); - } - } - } - - private final class TextWatcherImpl implements TextWatcher { - - @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 afterTextChanged(Editable s) { - handleTextChange(s); - } - } -} +/* + * Copyright (c) 2009-2011. Created by serso aka se.solovyev. + * For more information, please, contact se.solovyev@gmail.com + */ + +package org.solovyev.android.calculator; + +import android.content.Context; +import android.content.SharedPreferences; +import android.graphics.Color; +import android.os.Build; +import android.os.Handler; +import android.preference.PreferenceManager; +import android.text.Editable; +import android.text.Html; +import android.text.TextWatcher; +import android.util.AttributeSet; +import android.util.Log; +import android.view.ContextMenu; +import android.widget.EditText; +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; + +/** + * User: serso + * Date: 9/17/11 + * Time: 12:25 AM + */ +public class AndroidCalculatorEditorView extends EditText implements SharedPreferences.OnSharedPreferenceChangeListener, CalculatorEditorView { + + @NotNull + private static final BooleanPreference colorDisplay = new BooleanPreference("org.solovyev.android.calculator.CalculatorModel_color_display", true); + + private volatile boolean initialized = false; + + private boolean highlightText = true; + + @NotNull + private final static TextProcessor textHighlighter = new TextHighlighter(Color.WHITE, false); + + @NotNull + private volatile CalculatorEditorViewState viewState = CalculatorEditorViewStateImpl.newDefaultInstance(); + + private volatile boolean viewStateChange = false; + + // NOTE: static because super constructor calls some overridden methods (like onSelectionChanged and current lock is not yet created) + @NotNull + private static final Object lock = new Object(); + + @NotNull + private final Handler uiHandler = new Handler(); + + public AndroidCalculatorEditorView(Context context) { + super(context); + } + + public AndroidCalculatorEditorView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public AndroidCalculatorEditorView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + @Override + public boolean onCheckIsTextEditor() { + // 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 + try { + // IDEA: return false always except if method was called from TextView.isCursorVisible() method + for (StackTraceElement stackTraceElement : CollectionsUtils.asList(Thread.currentThread().getStackTrace())) { + if ("isCursorVisible".equals(stackTraceElement.getMethodName())) { + return true; + } + } + } catch (RuntimeException e) { + // just in case... + } + + return false; + } else { + return false; + } + } + + @Override + protected void onCreateContextMenu(ContextMenu menu) { + super.onCreateContextMenu(menu); + + menu.removeItem(android.R.id.selectAll); + } + + @Nullable + private CharSequence prepareText(@NotNull String text, boolean highlightText) { + CharSequence result; + + if (highlightText) { + + try { + final TextHighlighter.Result processesText = textHighlighter.process(text); + + assert processesText.getOffset() == 0; + + result = Html.fromHtml(processesText.toString()); + } catch (CalculatorParseException e) { + // set raw text + result = text; + + Log.e(this.getClass().getName(), e.getMessage(), e); + } + } else { + result = text; + } + + return result; + } + + public boolean isHighlightText() { + return highlightText; + } + + public void setHighlightText(boolean highlightText) { + this.highlightText = highlightText; + CalculatorLocatorImpl.getInstance().getEditor().updateViewState(); + } + + @Override + public void onSharedPreferenceChanged(SharedPreferences preferences, String key) { + if (colorDisplay.getKey().equals(key)) { + this.setHighlightText(colorDisplay.getPreference(preferences)); + } + } + + public synchronized void init(@NotNull Context context) { + if (!initialized) { + final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); + + preferences.registerOnSharedPreferenceChangeListener(this); + + this.addTextChangedListener(new TextWatcherImpl()); + + onSharedPreferenceChanged(preferences, colorDisplay.getKey()); + + initialized = true; + } + } + + @Override + public void setState(@NotNull final CalculatorEditorViewState viewState) { + + final CharSequence text = prepareText(viewState.getText(), highlightText); + + uiHandler.post(new Runnable() { + @Override + public void run() { + final AndroidCalculatorEditorView editorView = AndroidCalculatorEditorView.this; + synchronized (lock) { + try { + editorView.viewStateChange = true; + editorView.viewState = viewState; + editorView.setText(text, BufferType.EDITABLE); + editorView.setSelection(viewState.getSelection()); + } finally { + editorView.viewStateChange = false; + } + } + } + }); + } + + @Override + protected void onSelectionChanged(int selStart, int selEnd) { + synchronized (lock) { + if (!viewStateChange) { + // external text change => need to notify editor + super.onSelectionChanged(selStart, selEnd); + CalculatorLocatorImpl.getInstance().getEditor().setSelection(selStart); + } + } + } + + public void handleTextChange(Editable s) { + synchronized (lock) { + if (!viewStateChange) { + // external text change => need to notify editor + CalculatorLocatorImpl.getInstance().getEditor().setText(String.valueOf(s)); + } + } + } + + private final class TextWatcherImpl implements TextWatcher { + + @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 afterTextChanged(Editable s) { + handleTextChange(s); + } + } +} diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/AndroidCalculatorLogger.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/AndroidCalculatorLogger.java new file mode 100644 index 00000000..3eaa63c0 --- /dev/null +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/AndroidCalculatorLogger.java @@ -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); + } +} diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java index ab76d96f..d4b7ef59 100644 --- a/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java @@ -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(); diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorButtons.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorButtons.java index db0eeaa7..27ae4778 100644 --- a/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorButtons.java +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorButtons.java @@ -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); - } } } } diff --git a/calculatorpp/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java b/calculatorpp/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java index 31fd2bd0..ecc184bf 100644 --- a/calculatorpp/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java +++ b/calculatorpp/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java @@ -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(); }