history changes
This commit is contained in:
parent
4fdab42521
commit
e26fe15fe7
@ -11,7 +11,7 @@
|
|||||||
a:text="@string/c_history_button"
|
a:text="@string/c_history_button"
|
||||||
calc:textUp="@string/c_undo"
|
calc:textUp="@string/c_undo"
|
||||||
calc:textDown="@string/c_redo"
|
calc:textDown="@string/c_redo"
|
||||||
calc:hTextPosition="0.33"
|
calc:hTextPosition="0.25"
|
||||||
style="?controlButtonStyle"
|
style="?controlButtonStyle"
|
||||||
a:textStyle="bold"
|
a:textStyle="bold"
|
||||||
a:onClick="historyButtonClickHandler"/>
|
a:onClick="historyButtonClickHandler"/>
|
@ -27,7 +27,7 @@
|
|||||||
За подробной информацией, пожалуйста,\nобращайтесь на почту\n<a href="mailto:se.solovyev@gmail.com">se.solovyev@gmail.com</a>\n
|
За подробной информацией, пожалуйста,\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<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&business=se%2esolovyev%40gmail%2ecom&lc=RU&item_name=Android%20Calculator&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted">http://paypal.com</a>\n\n
|
Если вы хотите поддержать проект материально\nвы можете сделать это через \n<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=se%2esolovyev%40gmail%2ecom&lc=RU&item_name=Android%20Calculator&currency_code=USD&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>
|
||||||
|
|
||||||
<string name="c_undo">назад</string>
|
<string name="c_undo">назад</string>
|
||||||
@ -78,7 +78,7 @@
|
|||||||
пожертвовать денег через\n\n
|
пожертвовать денег через\n\n
|
||||||
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=se%2esolovyev%40gmail%2ecom&lc=RU&item_name=Android%20Calculator&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted">
|
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=se%2esolovyev%40gmail%2ecom&lc=RU&item_name=Android%20Calculator&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted">
|
||||||
http://paypal.com</a>\n\n
|
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>
|
||||||
|
|
||||||
<string name="c_history">История</string>
|
<string name="c_history">История</string>
|
||||||
|
@ -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>
|
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
|
\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&business=se%2esolovyev%40gmail%2ecom&lc=RU&item_name=Android%20Calculator&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted">http://paypal.com</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&business=se%2esolovyev%40gmail%2ecom&lc=RU&item_name=Android%20Calculator&currency_code=USD&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>
|
||||||
|
|
||||||
<string name="c_undo">undo</string>
|
<string name="c_undo">undo</string>
|
||||||
@ -79,8 +79,8 @@
|
|||||||
<string name="c_donate">Donate</string>
|
<string name="c_donate">Donate</string>
|
||||||
<string name="c_donate_text">You can thank the author of this program by email\n\n
|
<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
|
<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&business=se%2esolovyev%40gmail%2ecom&lc=RU&item_name=Android%20Calculator&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted">http://paypal.com</a>\n
|
donating money via\n\n<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=se%2esolovyev%40gmail%2ecom&lc=RU&item_name=Android%20Calculator&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted">http://paypal.com</a>\n\n
|
||||||
or setting 5 stars in <a href="https://market.android.com/details?id=org.solovyev.android.calculator">android.market</a>
|
or setting 5 stars in\n\n<a href="https://market.android.com/details?id=org.solovyev.android.calculator">android.market</a>
|
||||||
</string>
|
</string>
|
||||||
<string name="c_history">History</string>
|
<string name="c_history">History</string>
|
||||||
<string name="c_history_button">M</string>
|
<string name="c_history_button">M</string>
|
||||||
|
@ -135,15 +135,20 @@ public enum CalculatorModel implements CursorControl, HistoryControl<CalculatorH
|
|||||||
|
|
||||||
editor.redraw();
|
editor.redraw();
|
||||||
|
|
||||||
evaluate(delayEvaluate, editorStateAfter, jsclOperation);
|
evaluate(delayEvaluate, editorStateAfter, jsclOperation, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final static MutableObject<Runnable> pendingOperation = new MutableObject<Runnable>();
|
private final static MutableObject<Runnable> pendingOperation = new MutableObject<Runnable>();
|
||||||
|
|
||||||
private void evaluate(boolean delayEvaluate, @NotNull final String expression, @NotNull final JsclOperation operation) {
|
private void evaluate(boolean delayEvaluate, @NotNull final String expression, @NotNull final JsclOperation operation, @Nullable CalculatorHistoryState historyState) {
|
||||||
final CalculatorHistoryState historyState = getCurrentHistoryState();
|
final CalculatorHistoryState localHistoryState;
|
||||||
|
if (historyState == null) {
|
||||||
|
localHistoryState = getCurrentHistoryState();
|
||||||
|
} else {
|
||||||
|
localHistoryState = historyState;
|
||||||
|
}
|
||||||
|
|
||||||
pendingOperation.setObject(new Runnable() {
|
pendingOperation.setObject(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
@ -155,7 +160,7 @@ public enum CalculatorModel implements CursorControl, HistoryControl<CalculatorH
|
|||||||
// actually nothing shall be logged while text operations are done
|
// actually nothing shall be logged while text operations are done
|
||||||
evaluate(expression, operation, this);
|
evaluate(expression, operation, this);
|
||||||
|
|
||||||
historyState.setDisplayState(getCurrentHistoryState().getDisplayState());
|
localHistoryState.setDisplayState(getCurrentHistoryState().getDisplayState());
|
||||||
|
|
||||||
if (pendingOperation.getObject() == this) {
|
if (pendingOperation.getObject() == this) {
|
||||||
// todo serso: of course there is small probability that someone will set pendingOperation after if statement but before .setObject(null)
|
// 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) {
|
if (delayEvaluate) {
|
||||||
CalculatorHistory.instance.addState(historyState);
|
if (historyState == null) {
|
||||||
|
CalculatorHistory.instance.addState(localHistoryState);
|
||||||
|
}
|
||||||
new Handler().postDelayed(pendingOperation.getObject(), EVAL_DELAY_MILLIS);
|
new Handler().postDelayed(pendingOperation.getObject(), EVAL_DELAY_MILLIS);
|
||||||
} else {
|
} else {
|
||||||
pendingOperation.getObject().run();
|
pendingOperation.getObject().run();
|
||||||
CalculatorHistory.instance.addState(historyState);
|
if (historyState == null) {
|
||||||
|
CalculatorHistory.instance.addState(localHistoryState);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void evaluate() {
|
public void evaluate() {
|
||||||
evaluate(false, this.editor.getText().toString(), JsclOperation.numeric);
|
evaluate(false, this.editor.getText().toString(), JsclOperation.numeric, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void simplify() {
|
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,
|
private void evaluate(@Nullable final String expression,
|
||||||
@ -193,8 +202,7 @@ public enum CalculatorModel implements CursorControl, HistoryControl<CalculatorH
|
|||||||
try {
|
try {
|
||||||
Log.d(CalculatorModel.class.getName(), "Trying to evaluate '" + operation + "': " + expression /*+ StringUtils.fromStackTrace(Thread.currentThread().getStackTrace())*/);
|
Log.d(CalculatorModel.class.getName(), "Trying to evaluate '" + operation + "': " + expression /*+ StringUtils.fromStackTrace(Thread.currentThread().getStackTrace())*/);
|
||||||
final CalculatorEngine.Result result = calculatorEngine.evaluate(operation, expression);
|
final CalculatorEngine.Result result = calculatorEngine.evaluate(operation, expression);
|
||||||
if (currentRunner == pendingOperation.getObject()
|
if (currentRunner == pendingOperation.getObject()) {
|
||||||
&& expression.equals(this.editor.getText().toString())) {
|
|
||||||
display.setText(result.getResult());
|
display.setText(result.getResult());
|
||||||
display.setJsclOperation(result.getUserOperation());
|
display.setJsclOperation(result.getUserOperation());
|
||||||
} else {
|
} else {
|
||||||
@ -289,6 +297,13 @@ public enum CalculatorModel implements CursorControl, HistoryControl<CalculatorH
|
|||||||
setValuesFromHistory(this.editor, editorHistoryState.getEditorState());
|
setValuesFromHistory(this.editor, editorHistoryState.getEditorState());
|
||||||
setValuesFromHistory(this.display, editorHistoryState.getDisplayState());
|
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();
|
editor.redraw();
|
||||||
display.redraw();
|
display.redraw();
|
||||||
}
|
}
|
||||||
|
@ -60,6 +60,8 @@ public class ColorButton extends Button {
|
|||||||
private final OnClickListenerVibrator onClickListener;
|
private final OnClickListenerVibrator onClickListener;
|
||||||
|
|
||||||
private static final float H_TEXT_POSITION_DEFAULT_VALUE = 0.5f;
|
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;
|
private float hTextPosition = H_TEXT_POSITION_DEFAULT_VALUE;
|
||||||
|
|
||||||
public ColorButton(Context context, AttributeSet attrs) {
|
public ColorButton(Context context, AttributeSet attrs) {
|
||||||
@ -206,6 +208,14 @@ public class ColorButton extends Button {
|
|||||||
this.onClickListener.onClick(this);
|
this.onClickListener.onClick(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getHTextPosition() {
|
||||||
|
return hTextPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHTextPosition(float hTextPosition) {
|
||||||
|
this.hTextPosition = hTextPosition;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouchEvent(MotionEvent event) {
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
boolean result = super.onTouchEvent(event);
|
boolean result = super.onTouchEvent(event);
|
||||||
|
Loading…
Reference in New Issue
Block a user