diff --git a/calculatorpp-core/src/main/java/org/solovyev/android/calculator/CalculatorImpl.java b/calculatorpp-core/src/main/java/org/solovyev/android/calculator/CalculatorImpl.java index ae034819..bba408d4 100644 --- a/calculatorpp-core/src/main/java/org/solovyev/android/calculator/CalculatorImpl.java +++ b/calculatorpp-core/src/main/java/org/solovyev/android/calculator/CalculatorImpl.java @@ -3,7 +3,6 @@ package org.solovyev.android.calculator; import jscl.AbstractJsclArithmeticException; import jscl.NumeralBase; import jscl.NumeralBaseException; -import jscl.math.Expression; import jscl.math.Generic; import jscl.text.ParseInterruptedException; import org.jetbrains.annotations.NotNull; @@ -238,8 +237,7 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener { expression = expression.trim(); if (StringUtils.isEmpty(expression)) { - final CalculatorOutputImpl data = new CalculatorOutputImpl("", operation, Expression.valueOf("")); - fireCalculatorEvent(newCalculationEventData(operation, expression, sequenceId), CalculatorEventType.calculation_result, data); + fireCalculatorEvent(newCalculationEventData(operation, expression, sequenceId), CalculatorEventType.calculation_result, CalculatorOutputImpl.newEmptyOutput(operation)); } else { preparedExpression = preprocessor.process(expression); @@ -252,7 +250,7 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener { // NOTE: toString() method must be called here as ArithmeticOperationException may occur in it (just to avoid later check!) result.toString(); - final CalculatorOutputImpl data = new CalculatorOutputImpl(operation.getFromProcessor().process(result), operation, result); + final CalculatorOutput data = CalculatorOutputImpl.newOutput(operation.getFromProcessor().process(result), operation, result); fireCalculatorEvent(newCalculationEventData(operation, expression, sequenceId), CalculatorEventType.calculation_result, data); } catch (AbstractJsclArithmeticException e) { diff --git a/calculatorpp-core/src/main/java/org/solovyev/android/calculator/CalculatorOutput.java b/calculatorpp-core/src/main/java/org/solovyev/android/calculator/CalculatorOutput.java index bac56104..2dc6843f 100644 --- a/calculatorpp-core/src/main/java/org/solovyev/android/calculator/CalculatorOutput.java +++ b/calculatorpp-core/src/main/java/org/solovyev/android/calculator/CalculatorOutput.java @@ -2,6 +2,7 @@ package org.solovyev.android.calculator; import jscl.math.Generic; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.solovyev.android.calculator.jscl.JsclOperation; /** @@ -17,6 +18,8 @@ public interface CalculatorOutput { @NotNull JsclOperation getOperation(); - @NotNull + + // null in case of empty expression + @Nullable Generic getResult(); } diff --git a/calculatorpp-core/src/main/java/org/solovyev/android/calculator/CalculatorOutputImpl.java b/calculatorpp-core/src/main/java/org/solovyev/android/calculator/CalculatorOutputImpl.java index 0ca7e1fe..2a2db29b 100644 --- a/calculatorpp-core/src/main/java/org/solovyev/android/calculator/CalculatorOutputImpl.java +++ b/calculatorpp-core/src/main/java/org/solovyev/android/calculator/CalculatorOutputImpl.java @@ -2,6 +2,7 @@ package org.solovyev.android.calculator; import jscl.math.Generic; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.solovyev.android.calculator.jscl.JsclOperation; /** @@ -11,7 +12,7 @@ import org.solovyev.android.calculator.jscl.JsclOperation; */ public class CalculatorOutputImpl implements CalculatorOutput { - @NotNull + @Nullable private Generic result; @NotNull @@ -20,12 +21,26 @@ public class CalculatorOutputImpl implements CalculatorOutput { @NotNull private JsclOperation operation; - public CalculatorOutputImpl(@NotNull String stringResult, @NotNull JsclOperation operation, @NotNull Generic result) { + private CalculatorOutputImpl(@NotNull String stringResult, + @NotNull JsclOperation operation, + @Nullable Generic result) { this.stringResult = stringResult; this.operation = operation; this.result = result; } + @NotNull + public static CalculatorOutput newOutput(@NotNull String stringResult, + @NotNull JsclOperation operation, + @NotNull Generic result) { + return new CalculatorOutputImpl(stringResult, operation, result); + } + + @NotNull + public static CalculatorOutput newEmptyOutput(@NotNull JsclOperation operation) { + return new CalculatorOutputImpl("", operation, null); + } + @Override @NotNull public String getStringResult() { @@ -39,7 +54,7 @@ public class CalculatorOutputImpl implements CalculatorOutput { } @Override - @NotNull + @Nullable public Generic getResult() { return result; } diff --git a/calculatorpp-service/AndroidManifest.xml b/calculatorpp-service/AndroidManifest.xml deleted file mode 100644 index 7c364aa4..00000000 --- a/calculatorpp-service/AndroidManifest.xml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/calculatorpp-service/pom.xml b/calculatorpp-service/pom.xml deleted file mode 100644 index e51d5896..00000000 --- a/calculatorpp-service/pom.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - org.solovyev.android - calculatorpp-parent - 1.3.2 - - - 4.0.0 - - org.solovyev.android - calculatorpp-service - 1.3.2 - apklib - Calculator++ Service - - - - - com.intellij - annotations - - - - com.google.android - android - provided - - - - - - - - com.jayway.maven.plugins.android.generation2 - android-maven-plugin - - - - - \ No newline at end of file diff --git a/calculatorpp-service/res/values/dummy.xml b/calculatorpp-service/res/values/dummy.xml deleted file mode 100644 index dee82b37..00000000 --- a/calculatorpp-service/res/values/dummy.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/calculatorpp-service/src/main/java/org/solovyev/android/LocalBinder.java b/calculatorpp-service/src/main/java/org/solovyev/android/LocalBinder.java deleted file mode 100644 index 5ab791ac..00000000 --- a/calculatorpp-service/src/main/java/org/solovyev/android/LocalBinder.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.solovyev.android; - -import android.os.Binder; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.ref.WeakReference; - -/** - * A generic implementation of Binder to be used for local services - * - * @param The type of the service being bound - * @author Geoff Bruckner 12th December 2009 - */ - -public class LocalBinder extends Binder { - - @NotNull - private static String TAG = "LocalBinder"; - - @NotNull - private WeakReference serviceReference; - - - public LocalBinder(@NotNull S service) { - serviceReference = new WeakReference(service); - } - - @Nullable - public S getService() { - return serviceReference.get(); - } -} \ No newline at end of file diff --git a/calculatorpp-service/src/main/java/org/solovyev/android/calculator/CalculationServiceImpl.java b/calculatorpp-service/src/main/java/org/solovyev/android/calculator/CalculationServiceImpl.java deleted file mode 100644 index d3f35ae9..00000000 --- a/calculatorpp-service/src/main/java/org/solovyev/android/calculator/CalculationServiceImpl.java +++ /dev/null @@ -1,78 +0,0 @@ -package org.solovyev.android.calculator; - -import android.app.Service; -import android.content.Intent; -import android.os.*; -import android.os.Process; -import android.widget.Toast; -import org.jetbrains.annotations.NotNull; -import org.solovyev.android.LocalBinder; - -/** - * User: serso - * Date: 3/5/12 - * Time: 10:23 PM - */ -public class CalculationServiceImpl extends Service implements ICalculationService { - - @NotNull - private ServiceHandler handler; - - public CalculationServiceImpl() { - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - //Toast.makeText(this, ".CalculationService.onStartCommand", Toast.LENGTH_SHORT).show(); - - // For each start request, send a message to start a job and deliver the - // start ID so we know which request we're stopping when we finish the job - final Message msg = handler.obtainMessage(); - msg.arg1 = startId; - handler.sendMessage(msg); - - // If we get killed, after returning from here, restart - return START_STICKY; - } - - - @Override - public void onCreate() { - //Toast.makeText(this, ".CalculationService.onCreate", Toast.LENGTH_SHORT).show(); - // first time initialization - - // Start up the thread running the service. Note that we create a - // separate thread because the service normally runs in the process's - // main thread, which we don't want to block. We also make it - // background priority so CPU-intensive work will not disrupt our UI. - final HandlerThread thread = new HandlerThread("ServiceStartArguments", Process.THREAD_PRIORITY_BACKGROUND); - thread.start(); - - handler = new ServiceHandler(thread.getLooper()); - - } - - @Override - public void onDestroy() { - // last time call - //Toast.makeText(this, ".CalculationService.onDestroy", Toast.LENGTH_SHORT).show(); - } - - @Override - public IBinder onBind(Intent intent) { - return new LocalBinder(this); - } - - private final class ServiceHandler extends Handler { - - private ServiceHandler(@NotNull Looper looper) { - super(looper); - } - - @Override - public void handleMessage(@NotNull Message msg) { - //Toast.makeText(CalculationServiceImpl.this, "Doing job!", Toast.LENGTH_SHORT).show(); - stopSelf(msg.arg1); - } - } -} diff --git a/calculatorpp-service/src/main/java/org/solovyev/android/calculator/ICalculationService.java b/calculatorpp-service/src/main/java/org/solovyev/android/calculator/ICalculationService.java deleted file mode 100644 index 0e79e485..00000000 --- a/calculatorpp-service/src/main/java/org/solovyev/android/calculator/ICalculationService.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.solovyev.android.calculator; - -/** - * User: serso - * Date: 3/5/12 - * Time: 10:23 PM - */ -public interface ICalculationService { -} diff --git a/calculatorpp/pom.xml b/calculatorpp/pom.xml index a0b1535d..81d2b234 100644 --- a/calculatorpp/pom.xml +++ b/calculatorpp/pom.xml @@ -26,13 +26,6 @@ 1.3.2 - - org.solovyev.android - calculatorpp-service - 1.3.2 - apklib - - org.solovyev common-core @@ -79,13 +72,6 @@ apklib - - org.solovyev.android - calculatorpp-service - 0.1 - apklib - - org.solovyev jscl diff --git a/calculatorpp/project.properties b/calculatorpp/project.properties index 69b50958..1b733b09 100644 --- a/calculatorpp/project.properties +++ b/calculatorpp/project.properties @@ -9,12 +9,11 @@ # Project target. target=android-15 -android.library.reference.1=gen-external-apklibs/org.solovyev.android_calculatorpp-service_0.1 -android.library.reference.2=gen-external-apklibs/org.solovyev.android_android-common-core_1.0.0 -android.library.reference.3=gen-external-apklibs/org.solovyev.android_android-common-ads_1.0.0 -android.library.reference.4=gen-external-apklibs/org.solovyev.android_android-common-view_1.0.0 -android.library.reference.5=gen-external-apklibs/org.solovyev.android_android-common-preferences_1.0.0 -android.library.reference.6=gen-external-apklibs/org.solovyev.android_android-common-other_1.0.0 -android.library.reference.7=gen-external-apklibs/org.solovyev.android_android-common-menu_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.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 diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/AndroidCalculatorDisplayView.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/AndroidCalculatorDisplayView.java index d04fc39f..87b6b714 100644 --- a/calculatorpp/src/main/java/org/solovyev/android/calculator/AndroidCalculatorDisplayView.java +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/AndroidCalculatorDisplayView.java @@ -95,8 +95,10 @@ public class AndroidCalculatorDisplayView extends AutoResizeTextView implements redraw(); } else { setTextColor(getResources().getColor(R.color.display_error_text_color)); - setText(state.getErrorMessage()); - redraw(); + + // error messages are never shown -> just greyed out text (error message will be shown on click) + //setText(state.getErrorMessage()); + //redraw(); } } } diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java index 795e4b03..a99e7a4a 100644 --- a/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java @@ -7,11 +7,10 @@ package org.solovyev.android.calculator; import android.app.Activity; import android.app.AlertDialog; -import android.content.*; +import android.content.SharedPreferences; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.os.Bundle; -import android.os.IBinder; import android.os.Vibrator; import android.preference.PreferenceManager; import android.text.Html; @@ -32,7 +31,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.solovyev.android.AndroidUtils; import org.solovyev.android.FontSizeAdjuster; -import org.solovyev.android.LocalBinder; import org.solovyev.android.calculator.about.CalculatorReleaseNotesActivity; import org.solovyev.android.calculator.history.CalculatorHistoryState; import org.solovyev.android.calculator.model.AndroidCalculatorEngine; @@ -57,7 +55,7 @@ import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.List; -public class CalculatorActivity extends Activity implements FontSizeAdjuster, SharedPreferences.OnSharedPreferenceChangeListener, ServiceConnection { +public class CalculatorActivity extends Activity implements FontSizeAdjuster, SharedPreferences.OnSharedPreferenceChangeListener { @NotNull public static final String TAG = "Calculator++"; @@ -67,9 +65,6 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh @Nullable private IBillingObserver billingObserver; - @Nullable - private ICalculationService calculationService; - @NotNull private final Announcer dpclRegister = new Announcer(DragPreferencesChangeListener.class); @@ -110,8 +105,6 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh super.onCreate(savedInstanceState); setLayout(preferences); - bindService(new Intent(this, CalculationServiceImpl.class), this, Context.BIND_AUTO_CREATE); - if (customTitleSupported) { try { getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.calc_title); @@ -421,17 +414,6 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh return onDragListener; } - @Override - public void onServiceConnected(ComponentName componentName, IBinder binder) { - if (binder instanceof LocalBinder) { - calculationService = (ICalculationService)((LocalBinder) binder).getService(); - } - } - - @Override - public void onServiceDisconnected(ComponentName componentName) { - } - private synchronized void setLayout(@NotNull SharedPreferences preferences) { layout = CalculatorPreferences.Gui.layout.getPreferenceNoError(preferences); diff --git a/pom.xml b/pom.xml index f8cef3f0..eff76609 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,6 @@ calculatorpp - calculatorpp-service calculatorpp-test calculatorpp-core