New architecture
This commit is contained in:
parent
bb2bf70cc2
commit
b2fe1d43c9
@ -3,7 +3,6 @@ package org.solovyev.android.calculator;
|
|||||||
import jscl.AbstractJsclArithmeticException;
|
import jscl.AbstractJsclArithmeticException;
|
||||||
import jscl.NumeralBase;
|
import jscl.NumeralBase;
|
||||||
import jscl.NumeralBaseException;
|
import jscl.NumeralBaseException;
|
||||||
import jscl.math.Expression;
|
|
||||||
import jscl.math.Generic;
|
import jscl.math.Generic;
|
||||||
import jscl.text.ParseInterruptedException;
|
import jscl.text.ParseInterruptedException;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -238,8 +237,7 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener {
|
|||||||
expression = expression.trim();
|
expression = expression.trim();
|
||||||
|
|
||||||
if (StringUtils.isEmpty(expression)) {
|
if (StringUtils.isEmpty(expression)) {
|
||||||
final CalculatorOutputImpl data = new CalculatorOutputImpl("", operation, Expression.valueOf(""));
|
fireCalculatorEvent(newCalculationEventData(operation, expression, sequenceId), CalculatorEventType.calculation_result, CalculatorOutputImpl.newEmptyOutput(operation));
|
||||||
fireCalculatorEvent(newCalculationEventData(operation, expression, sequenceId), CalculatorEventType.calculation_result, data);
|
|
||||||
} else {
|
} else {
|
||||||
preparedExpression = preprocessor.process(expression);
|
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!)
|
// NOTE: toString() method must be called here as ArithmeticOperationException may occur in it (just to avoid later check!)
|
||||||
result.toString();
|
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);
|
fireCalculatorEvent(newCalculationEventData(operation, expression, sequenceId), CalculatorEventType.calculation_result, data);
|
||||||
|
|
||||||
} catch (AbstractJsclArithmeticException e) {
|
} catch (AbstractJsclArithmeticException e) {
|
||||||
|
@ -2,6 +2,7 @@ package org.solovyev.android.calculator;
|
|||||||
|
|
||||||
import jscl.math.Generic;
|
import jscl.math.Generic;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.calculator.jscl.JsclOperation;
|
import org.solovyev.android.calculator.jscl.JsclOperation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,6 +18,8 @@ public interface CalculatorOutput {
|
|||||||
@NotNull
|
@NotNull
|
||||||
JsclOperation getOperation();
|
JsclOperation getOperation();
|
||||||
|
|
||||||
@NotNull
|
|
||||||
|
// null in case of empty expression
|
||||||
|
@Nullable
|
||||||
Generic getResult();
|
Generic getResult();
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package org.solovyev.android.calculator;
|
|||||||
|
|
||||||
import jscl.math.Generic;
|
import jscl.math.Generic;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.calculator.jscl.JsclOperation;
|
import org.solovyev.android.calculator.jscl.JsclOperation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -11,7 +12,7 @@ import org.solovyev.android.calculator.jscl.JsclOperation;
|
|||||||
*/
|
*/
|
||||||
public class CalculatorOutputImpl implements CalculatorOutput {
|
public class CalculatorOutputImpl implements CalculatorOutput {
|
||||||
|
|
||||||
@NotNull
|
@Nullable
|
||||||
private Generic result;
|
private Generic result;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -20,12 +21,26 @@ public class CalculatorOutputImpl implements CalculatorOutput {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private JsclOperation operation;
|
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.stringResult = stringResult;
|
||||||
this.operation = operation;
|
this.operation = operation;
|
||||||
this.result = result;
|
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
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public String getStringResult() {
|
public String getStringResult() {
|
||||||
@ -39,7 +54,7 @@ public class CalculatorOutputImpl implements CalculatorOutput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@Nullable
|
||||||
public Generic getResult() {
|
public Generic getResult() {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="0.1" package="org.solovyev.android.calculator"/>
|
|
@ -1,44 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
|
|
||||||
<parent>
|
|
||||||
<groupId>org.solovyev.android</groupId>
|
|
||||||
<artifactId>calculatorpp-parent</artifactId>
|
|
||||||
<version>1.3.2</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<groupId>org.solovyev.android</groupId>
|
|
||||||
<artifactId>calculatorpp-service</artifactId>
|
|
||||||
<version>1.3.2</version>
|
|
||||||
<packaging>apklib</packaging>
|
|
||||||
<name>Calculator++ Service</name>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.intellij</groupId>
|
|
||||||
<artifactId>annotations</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.google.android</groupId>
|
|
||||||
<artifactId>android</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<extensions>
|
|
||||||
<extension>
|
|
||||||
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
|
|
||||||
<artifactId>android-maven-plugin</artifactId>
|
|
||||||
</extension>
|
|
||||||
</extensions>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
</project>
|
|
@ -1,3 +0,0 @@
|
|||||||
<resources>
|
|
||||||
<!--this file is needed only for one purpose - to save res folder as it is needed for build-->
|
|
||||||
</resources>
|
|
@ -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 <S> The type of the service being bound
|
|
||||||
* @author Geoff Bruckner 12th December 2009
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class LocalBinder<S> extends Binder {
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private static String TAG = "LocalBinder";
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private WeakReference<S> serviceReference;
|
|
||||||
|
|
||||||
|
|
||||||
public LocalBinder(@NotNull S service) {
|
|
||||||
serviceReference = new WeakReference<S>(service);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public S getService() {
|
|
||||||
return serviceReference.get();
|
|
||||||
}
|
|
||||||
}
|
|
@ -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<ICalculationService>(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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
package org.solovyev.android.calculator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User: serso
|
|
||||||
* Date: 3/5/12
|
|
||||||
* Time: 10:23 PM
|
|
||||||
*/
|
|
||||||
public interface ICalculationService {
|
|
||||||
}
|
|
@ -26,13 +26,6 @@
|
|||||||
<version>1.3.2</version>
|
<version>1.3.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.solovyev.android</groupId>
|
|
||||||
<artifactId>calculatorpp-service</artifactId>
|
|
||||||
<version>1.3.2</version>
|
|
||||||
<type>apklib</type>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.solovyev</groupId>
|
<groupId>org.solovyev</groupId>
|
||||||
<artifactId>common-core</artifactId>
|
<artifactId>common-core</artifactId>
|
||||||
@ -79,13 +72,6 @@
|
|||||||
<type>apklib</type>
|
<type>apklib</type>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.solovyev.android</groupId>
|
|
||||||
<artifactId>calculatorpp-service</artifactId>
|
|
||||||
<version>0.1</version>
|
|
||||||
<type>apklib</type>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.solovyev</groupId>
|
<groupId>org.solovyev</groupId>
|
||||||
<artifactId>jscl</artifactId>
|
<artifactId>jscl</artifactId>
|
||||||
|
@ -9,12 +9,11 @@
|
|||||||
|
|
||||||
# Project target.
|
# Project target.
|
||||||
target=android-15
|
target=android-15
|
||||||
android.library.reference.1=gen-external-apklibs/org.solovyev.android_calculatorpp-service_0.1
|
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-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-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-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-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-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-menu_1.0.0
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -95,8 +95,10 @@ public class AndroidCalculatorDisplayView extends AutoResizeTextView implements
|
|||||||
redraw();
|
redraw();
|
||||||
} else {
|
} else {
|
||||||
setTextColor(getResources().getColor(R.color.display_error_text_color));
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,11 +7,10 @@ package org.solovyev.android.calculator;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.*;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
@ -32,7 +31,6 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.AndroidUtils;
|
import org.solovyev.android.AndroidUtils;
|
||||||
import org.solovyev.android.FontSizeAdjuster;
|
import org.solovyev.android.FontSizeAdjuster;
|
||||||
import org.solovyev.android.LocalBinder;
|
|
||||||
import org.solovyev.android.calculator.about.CalculatorReleaseNotesActivity;
|
import org.solovyev.android.calculator.about.CalculatorReleaseNotesActivity;
|
||||||
import org.solovyev.android.calculator.history.CalculatorHistoryState;
|
import org.solovyev.android.calculator.history.CalculatorHistoryState;
|
||||||
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
||||||
@ -57,7 +55,7 @@ import java.lang.reflect.Modifier;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CalculatorActivity extends Activity implements FontSizeAdjuster, SharedPreferences.OnSharedPreferenceChangeListener, ServiceConnection {
|
public class CalculatorActivity extends Activity implements FontSizeAdjuster, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static final String TAG = "Calculator++";
|
public static final String TAG = "Calculator++";
|
||||||
@ -67,9 +65,6 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
|||||||
@Nullable
|
@Nullable
|
||||||
private IBillingObserver billingObserver;
|
private IBillingObserver billingObserver;
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private ICalculationService calculationService;
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final Announcer<DragPreferencesChangeListener> dpclRegister = new Announcer<DragPreferencesChangeListener>(DragPreferencesChangeListener.class);
|
private final Announcer<DragPreferencesChangeListener> dpclRegister = new Announcer<DragPreferencesChangeListener>(DragPreferencesChangeListener.class);
|
||||||
|
|
||||||
@ -110,8 +105,6 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setLayout(preferences);
|
setLayout(preferences);
|
||||||
|
|
||||||
bindService(new Intent(this, CalculationServiceImpl.class), this, Context.BIND_AUTO_CREATE);
|
|
||||||
|
|
||||||
if (customTitleSupported) {
|
if (customTitleSupported) {
|
||||||
try {
|
try {
|
||||||
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.calc_title);
|
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.calc_title);
|
||||||
@ -421,17 +414,6 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
|||||||
return onDragListener;
|
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) {
|
private synchronized void setLayout(@NotNull SharedPreferences preferences) {
|
||||||
layout = CalculatorPreferences.Gui.layout.getPreferenceNoError(preferences);
|
layout = CalculatorPreferences.Gui.layout.getPreferenceNoError(preferences);
|
||||||
|
1
pom.xml
1
pom.xml
@ -13,7 +13,6 @@
|
|||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>calculatorpp</module>
|
<module>calculatorpp</module>
|
||||||
<module>calculatorpp-service</module>
|
|
||||||
<module>calculatorpp-test</module>
|
<module>calculatorpp-test</module>
|
||||||
<module>calculatorpp-core</module>
|
<module>calculatorpp-core</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
Loading…
Reference in New Issue
Block a user