preferences + asyn result calculation
This commit is contained in:
parent
43732f1632
commit
22cec09802
@ -14,6 +14,7 @@ import bsh.EvalError;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.util.StringUtils;
|
||||
import org.solovyev.util.date.MutableObject;
|
||||
import org.solovyev.util.math.MathEntityType;
|
||||
|
||||
import java.util.Date;
|
||||
@ -92,6 +93,9 @@ public class CalculatorView implements CursorControl{
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private final MutableObject<Runnable> currentRunner = new MutableObject<Runnable>();
|
||||
|
||||
public void doTextOperation(@NotNull TextOperation operation) {
|
||||
final String editorStateBefore = this.editor.getText().toString();
|
||||
|
||||
@ -99,9 +103,27 @@ public class CalculatorView implements CursorControl{
|
||||
|
||||
final String editorStateAfter = this.editor.getText().toString();
|
||||
if (!editorStateBefore.equals(editorStateAfter)) {
|
||||
|
||||
currentRunner.setObject(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (currentRunner) {
|
||||
// do only if nothing was post delayed before current instance was posted
|
||||
if (currentRunner.getObject() == this) {
|
||||
// actually nothing shall be logged while text operations are done
|
||||
evaluate(editorStateAfter, false);
|
||||
|
||||
if (history.isRedoAvailable()) {
|
||||
history.redo(getCurrentHistoryState());
|
||||
}
|
||||
saveHistoryState();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
new Handler().postDelayed(currentRunner.getObject(), 500);
|
||||
|
||||
saveHistoryState();
|
||||
}
|
||||
}
|
||||
@ -112,9 +134,6 @@ public class CalculatorView implements CursorControl{
|
||||
final TextView localDisplay = display;
|
||||
final Activity localActivity = activity;
|
||||
|
||||
new Handler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
localDisplay.setText(calculator.evaluate(JsclOperation.numeric, expression));
|
||||
} catch (EvalError evalError) {
|
||||
@ -123,8 +142,6 @@ public class CalculatorView implements CursorControl{
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
|
26
src/main/java/org/solovyev/util/date/MutableObject.java
Normal file
26
src/main/java/org/solovyev/util/date/MutableObject.java
Normal file
@ -0,0 +1,26 @@
|
||||
package org.solovyev.util.date;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 9/13/11
|
||||
* Time: 6:46 PM
|
||||
*/
|
||||
public class MutableObject<T> {
|
||||
|
||||
private T object;
|
||||
|
||||
public MutableObject() {
|
||||
}
|
||||
|
||||
public MutableObject(T object) {
|
||||
this.object = object;
|
||||
}
|
||||
|
||||
public T getObject() {
|
||||
return object;
|
||||
}
|
||||
|
||||
public void setObject(T object) {
|
||||
this.object = object;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user