some classes moved to common

This commit is contained in:
serso
2011-09-16 14:26:46 +04:00
parent 3a9d5c3643
commit fd01c287df
18 changed files with 30 additions and 350 deletions

View File

@@ -16,8 +16,9 @@ import bsh.EvalError;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.view.*;
import org.solovyev.util.StringUtils;
import org.solovyev.util.math.Point2d;
import org.solovyev.common.utils.Point2d;
import org.solovyev.common.utils.StringUtils;
import org.solovyev.common.utils.history.HistoryAction;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

View File

@@ -1,11 +1,9 @@
package org.solovyev.android.calculator;
import android.util.Log;
import android.widget.Toast;
import bsh.EvalError;
import bsh.Interpreter;
import org.jetbrains.annotations.NotNull;
import org.solovyev.util.math.MathUtils;
import org.solovyev.common.utils.MathUtils;
/**
* User: serso

View File

@@ -13,12 +13,13 @@ import android.widget.Toast;
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.common.utils.MutableObject;
import org.solovyev.common.utils.StringUtils;
import org.solovyev.common.utils.history.HistoryAction;
import org.solovyev.common.utils.history.HistoryHelper;
import org.solovyev.common.utils.history.SimpleHistoryHelper;
import org.solovyev.util.math.MathEntityType;
import java.util.Date;
/**
* User: serso
* Date: 9/12/11
@@ -111,7 +112,7 @@ public class CalculatorView implements CursorControl{
// 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);
evaluate(editorStateAfter, true);
if (history.isRedoAvailable()) {
history.redo(getCurrentHistoryState());

View File

@@ -16,8 +16,8 @@ import org.solovyev.android.view.*;
import org.solovyev.common.collections.ManyValuedHashMap;
import org.solovyev.common.collections.ManyValuedMap;
import org.solovyev.common.utils.Interval;
import org.solovyev.util.math.MathUtils;
import org.solovyev.util.math.Point2d;
import org.solovyev.common.utils.MathUtils;
import org.solovyev.common.utils.Point2d;
import java.util.ArrayList;
import java.util.HashMap;

View File

@@ -1,8 +0,0 @@
package org.solovyev.android.calculator;
public enum HistoryAction {
redo,
undo;
}

View File

@@ -1,24 +0,0 @@
package org.solovyev.android.calculator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public interface HistoryHelper<T> {
boolean isUndoAvailable();
@Nullable
T undo (@Nullable T currentState);
boolean isRedoAvailable();
@Nullable
T redo (@Nullable T currentState);
boolean isActionAvailable(@NotNull HistoryAction historyAction);
@Nullable
T doAction(@NotNull HistoryAction historyAction, @Nullable T currentState);
void addState(@Nullable T currentState);
}

View File

@@ -1,91 +0,0 @@
package org.solovyev.android.calculator;
import java.util.ArrayList;
import java.util.List;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class SimpleHistoryHelper<T> implements HistoryHelper<T> {
private List<T> history = new ArrayList<T>();
private int currentStateIndex = -1;
@Override
public T undo(@Nullable T currentState) {
if ( !isUndoAvailable() ) {
throw new IndexOutOfBoundsException();
}
currentStateIndex--;
return history.get(currentStateIndex);
}
@Override
public T redo(@Nullable T currentState) {
if (!isRedoAvailable()) {
throw new IndexOutOfBoundsException();
}
currentStateIndex++;
return history.get(currentStateIndex);
}
@Override
public void addState(@Nullable T currentState) {
if (currentStateIndex == history.size() - 1) {
currentStateIndex++;
history.add(currentState);
} else {
assert currentStateIndex < history.size() - 1 : "Invalid history state index!";
currentStateIndex++;
history.set(currentStateIndex, currentState);
while( history.size() > currentStateIndex + 1 ) {
history.remove(history.size() - 1);
}
}
}
@Override
public boolean isUndoAvailable() {
return currentStateIndex > 0;
}
@Override
public boolean isRedoAvailable() {
return currentStateIndex < history.size() - 1;
}
@Override
public boolean isActionAvailable(@NotNull HistoryAction historyAction) {
boolean result = false;
switch (historyAction) {
case undo:
result = isUndoAvailable();
break;
case redo:
result = isRedoAvailable();
break;
}
return result;
}
@Override
public T doAction(@NotNull HistoryAction historyAction, @Nullable T currentState) {
T result = null;
switch (historyAction) {
case undo:
result = undo(currentState);
break;
case redo:
result = redo(currentState);
break;
}
return result;
}
}

View File

@@ -17,15 +17,15 @@
package org.solovyev.android.view;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.util.AttributeSet;
import android.widget.Button;
import android.view.MotionEvent;
import android.content.res.Resources;
import android.widget.Button;
import org.jetbrains.annotations.NotNull;
import org.solovyev.util.math.Point2d;
import org.solovyev.common.utils.Point2d;
/**
* NOTE: copied from com.android.calculator2.ColorButton

View File

@@ -8,9 +8,8 @@ import android.text.TextPaint;
import android.util.AttributeSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.R;
import org.solovyev.util.StringUtils;
import org.solovyev.util.math.Point2d;
import org.solovyev.common.utils.Point2d;
import org.solovyev.common.utils.StringUtils;
/**
* User: serso

View File

@@ -1,16 +1,15 @@
package org.solovyev.android.view;
import android.os.Handler;
import android.widget.Button;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.util.math.Point2d;
import android.content.Context;
import android.os.Handler;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.common.utils.Point2d;
public class DragButton extends ColorButton {

View File

@@ -1,9 +1,8 @@
package org.solovyev.android.view;
import org.jetbrains.annotations.NotNull;
import org.solovyev.util.math.Point2d;
import android.view.MotionEvent;
import org.jetbrains.annotations.NotNull;
import org.solovyev.common.utils.Point2d;
public class DragEvent {

View File

@@ -1,13 +1,12 @@
package org.solovyev.android.view;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.DragButtonCalibrationActivity;
import org.solovyev.common.utils.Interval;
import org.solovyev.util.math.MathUtils;
import org.solovyev.util.math.Point2d;
import android.util.Log;
import android.view.MotionEvent;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.DragButtonCalibrationActivity;
import org.solovyev.common.utils.Interval;
import org.solovyev.common.utils.MathUtils;
import org.solovyev.common.utils.Point2d;
import java.util.Map;