history changes

This commit is contained in:
serso 2011-10-27 11:35:35 +04:00
parent 4fdab42521
commit e26fe15fe7
5 changed files with 41 additions and 16 deletions

View File

@ -11,7 +11,7 @@
a:text="@string/c_history_button"
calc:textUp="@string/c_undo"
calc:textDown="@string/c_redo"
calc:hTextPosition="0.33"
calc:hTextPosition="0.25"
style="?controlButtonStyle"
a:textStyle="bold"
a:onClick="historyButtonClickHandler"/>

View File

@ -27,7 +27,7 @@
За подробной информацией, пожалуйста,\nобращайтесь на почту\n<a href="mailto:se.solovyev@gmail.com">se.solovyev@gmail.com</a>\n
или посетите сайт \n<a href="http://se.solovyev.org">http://se.solovyev.org</a>\n\n
Если вы хотите поддержать проект материально\nвы можете сделать это через \n<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&amp;business=se%2esolovyev%40gmail%2ecom&amp;lc=RU&amp;item_name=Android%20Calculator&amp;currency_code=USD&amp;bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted">http://paypal.com</a>\n\n
Если вам понравилось приложение - поставте 5 звёздочек в <a href="https://market.android.com/details?id=org.solovyev.android.calculator">андроид.маркете</a>
Если вам понравилось приложение -\nпоставте 5 звёздочек в\n<a href="https://market.android.com/details?id=org.solovyev.android.calculator">андроид.маркете</a>
</string>
<string name="c_undo">назад</string>
@ -78,7 +78,7 @@
пожертвовать денег через\n\n
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&amp;business=se%2esolovyev%40gmail%2ecom&amp;lc=RU&amp;item_name=Android%20Calculator&amp;currency_code=USD&amp;bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted">
http://paypal.com</a>\n\n
или поставить 5 звёздочек в <a href="https://market.android.com/details?id=org.solovyev.android.calculator">андроид.маркете</a>
или поставить 5 звёздочек в\n\n<a href="https://market.android.com/details?id=org.solovyev.android.calculator">андроид.маркете</a>
</string>
<string name="c_history">История</string>

View File

@ -28,7 +28,7 @@
For more information please\ncontact the author by email\n<a href="mailto:se.solovyev@gmail.com">se.solovyev@gmail.com</a>
\nor visit\n<a href="http://se.solovyev.org">http://se.solovyev.org</a>\n\n
If you want to support the project\nyou can donate money via\n<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&amp;business=se%2esolovyev%40gmail%2ecom&amp;lc=RU&amp;item_name=Android%20Calculator&amp;currency_code=USD&amp;bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted">http://paypal.com</a>\n\n
If you like the application rank it with 5 stars in <a href="https://market.android.com/details?id=org.solovyev.android.calculator">android.market</a>
If you like the application\nrank it with 5 stars in\n<a href="https://market.android.com/details?id=org.solovyev.android.calculator">android.market</a>
</string>
<string name="c_undo">undo</string>
@ -79,8 +79,8 @@
<string name="c_donate">Donate</string>
<string name="c_donate_text">You can thank the author of this program by email\n\n
<a href="mailto:se.solovyev@gmail.com">se.solovyev@gmail.com</a>\n\n
donating money via\n\n<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&amp;business=se%2esolovyev%40gmail%2ecom&amp;lc=RU&amp;item_name=Android%20Calculator&amp;currency_code=USD&amp;bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted">http://paypal.com</a>\n
or setting 5 stars in <a href="https://market.android.com/details?id=org.solovyev.android.calculator">android.market</a>
donating money via\n\n<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&amp;business=se%2esolovyev%40gmail%2ecom&amp;lc=RU&amp;item_name=Android%20Calculator&amp;currency_code=USD&amp;bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted">http://paypal.com</a>\n\n
or setting 5 stars in\n\n<a href="https://market.android.com/details?id=org.solovyev.android.calculator">android.market</a>
</string>
<string name="c_history">History</string>
<string name="c_history_button">M</string>

View File

@ -135,15 +135,20 @@ public enum CalculatorModel implements CursorControl, HistoryControl<CalculatorH
editor.redraw();
evaluate(delayEvaluate, editorStateAfter, jsclOperation);
evaluate(delayEvaluate, editorStateAfter, jsclOperation, null);
}
}
@NotNull
private final static MutableObject<Runnable> pendingOperation = new MutableObject<Runnable>();
private void evaluate(boolean delayEvaluate, @NotNull final String expression, @NotNull final JsclOperation operation) {
final CalculatorHistoryState historyState = getCurrentHistoryState();
private void evaluate(boolean delayEvaluate, @NotNull final String expression, @NotNull final JsclOperation operation, @Nullable CalculatorHistoryState historyState) {
final CalculatorHistoryState localHistoryState;
if (historyState == null) {
localHistoryState = getCurrentHistoryState();
} else {
localHistoryState = historyState;
}
pendingOperation.setObject(new Runnable() {
@Override
@ -155,7 +160,7 @@ public enum CalculatorModel implements CursorControl, HistoryControl<CalculatorH
// actually nothing shall be logged while text operations are done
evaluate(expression, operation, this);
historyState.setDisplayState(getCurrentHistoryState().getDisplayState());
localHistoryState.setDisplayState(getCurrentHistoryState().getDisplayState());
if (pendingOperation.getObject() == this) {
// todo serso: of course there is small probability that someone will set pendingOperation after if statement but before .setObject(null)
@ -167,22 +172,26 @@ public enum CalculatorModel implements CursorControl, HistoryControl<CalculatorH
});
if (delayEvaluate) {
CalculatorHistory.instance.addState(historyState);
if (historyState == null) {
CalculatorHistory.instance.addState(localHistoryState);
}
new Handler().postDelayed(pendingOperation.getObject(), EVAL_DELAY_MILLIS);
} else {
pendingOperation.getObject().run();
CalculatorHistory.instance.addState(historyState);
if (historyState == null) {
CalculatorHistory.instance.addState(localHistoryState);
}
}
}
@Override
public void evaluate() {
evaluate(false, this.editor.getText().toString(), JsclOperation.numeric);
evaluate(false, this.editor.getText().toString(), JsclOperation.numeric, null);
}
@Override
public void simplify() {
evaluate(false, this.editor.getText().toString(), JsclOperation.simplify);
evaluate(false, this.editor.getText().toString(), JsclOperation.simplify, null);
}
private void evaluate(@Nullable final String expression,
@ -193,8 +202,7 @@ public enum CalculatorModel implements CursorControl, HistoryControl<CalculatorH
try {
Log.d(CalculatorModel.class.getName(), "Trying to evaluate '" + operation + "': " + expression /*+ StringUtils.fromStackTrace(Thread.currentThread().getStackTrace())*/);
final CalculatorEngine.Result result = calculatorEngine.evaluate(operation, expression);
if (currentRunner == pendingOperation.getObject()
&& expression.equals(this.editor.getText().toString())) {
if (currentRunner == pendingOperation.getObject()) {
display.setText(result.getResult());
display.setJsclOperation(result.getUserOperation());
} else {
@ -289,6 +297,13 @@ public enum CalculatorModel implements CursorControl, HistoryControl<CalculatorH
setValuesFromHistory(this.editor, editorHistoryState.getEditorState());
setValuesFromHistory(this.display, editorHistoryState.getDisplayState());
final String expression = this.editor.getText().toString();
if ( !StringUtils.isEmpty(expression) ) {
if ( StringUtils.isEmpty(this.display.getText().toString()) ) {
evaluate(false, expression, JsclOperation.numeric, editorHistoryState);
}
}
editor.redraw();
display.redraw();
}

View File

@ -60,6 +60,8 @@ public class ColorButton extends Button {
private final OnClickListenerVibrator onClickListener;
private static final float H_TEXT_POSITION_DEFAULT_VALUE = 0.5f;
// todo serso: check - currently not worked
private float hTextPosition = H_TEXT_POSITION_DEFAULT_VALUE;
public ColorButton(Context context, AttributeSet attrs) {
@ -206,6 +208,14 @@ public class ColorButton extends Button {
this.onClickListener.onClick(this);
}
public float getHTextPosition() {
return hTextPosition;
}
public void setHTextPosition(float hTextPosition) {
this.hTextPosition = hTextPosition;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
boolean result = super.onTouchEvent(event);