preferences + asyn result calculation
This commit is contained in:
parent
f0a7f8180b
commit
43732f1632
@ -37,6 +37,9 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster {
|
||||
@NotNull
|
||||
private CalculatorModel calculator;
|
||||
|
||||
@NotNull
|
||||
private BroadcastReceiver preferencesChangesReceiver;
|
||||
|
||||
/**
|
||||
* Called when the activity is first created.
|
||||
*/
|
||||
@ -112,7 +115,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster {
|
||||
onDragListeners.add(toPositionOnDragListener);
|
||||
|
||||
|
||||
final BroadcastReceiver preferencesChangesReceiver = new BroadcastReceiver() {
|
||||
preferencesChangesReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
||||
@ -128,6 +131,12 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster {
|
||||
registerReceiver(preferencesChangesReceiver, new IntentFilter(DragButtonCalibrationActivity.INTENT_ACTION));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
unregisterReceiver(preferencesChangesReceiver);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@SuppressWarnings({"UnusedDeclaration"})
|
||||
public void elementaryButtonClickHandler(@NotNull View v) {
|
||||
throw new UnsupportedOperationException("Not implemented yet!");
|
||||
|
@ -2,6 +2,7 @@ package org.solovyev.android.calculator;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.text.ClipboardManager;
|
||||
import android.text.InputType;
|
||||
import android.view.View;
|
||||
@ -15,6 +16,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.util.StringUtils;
|
||||
import org.solovyev.util.math.MathEntityType;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 9/12/11
|
||||
@ -96,19 +99,31 @@ public class CalculatorView implements CursorControl{
|
||||
|
||||
final String editorStateAfter = this.editor.getText().toString();
|
||||
if (!editorStateBefore.equals(editorStateAfter)) {
|
||||
try {
|
||||
evaluate(editorStateAfter);
|
||||
} catch (EvalError evalError) {
|
||||
// actually nothing shall be logged while text operations are done
|
||||
}
|
||||
evaluate(editorStateAfter, false);
|
||||
|
||||
saveHistoryState();
|
||||
}
|
||||
}
|
||||
|
||||
private void evaluate(@Nullable String expression) throws EvalError {
|
||||
private void evaluate(@Nullable final String expression, final boolean showError) {
|
||||
if (!StringUtils.isEmpty(expression)) {
|
||||
display.setText(calculator.evaluate(JsclOperation.numeric, expression));
|
||||
|
||||
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) {
|
||||
if (showError) {
|
||||
Toast.makeText(localActivity, R.string.syntax_error, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,11 +136,7 @@ public class CalculatorView implements CursorControl{
|
||||
}
|
||||
|
||||
public void evaluate() {
|
||||
try {
|
||||
evaluate(editor.getText().toString());
|
||||
} catch (EvalError evalError) {
|
||||
Toast.makeText(this.activity, R.string.syntax_error, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
evaluate(editor.getText().toString(), true);
|
||||
}
|
||||
|
||||
public void processButtonAction(@Nullable final String text) {
|
||||
|
@ -216,12 +216,12 @@ public class DragButtonCalibrationActivity extends Activity {
|
||||
}
|
||||
break;
|
||||
case distance:
|
||||
defaultMin = 60f;
|
||||
defaultMax = 140f;
|
||||
defaultMin = 50f;
|
||||
defaultMax = 150f;
|
||||
break;
|
||||
case duration:
|
||||
defaultMin = 100f;
|
||||
defaultMax = 300f;
|
||||
defaultMin = 40f;
|
||||
defaultMax = 1000f;
|
||||
break;
|
||||
default:
|
||||
defaultMin = DEFAULT_VALUE;
|
||||
|
@ -1,5 +1,7 @@
|
||||
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;
|
||||
@ -76,6 +78,19 @@ public class DragButton extends ColorButton {
|
||||
// prevent on click action
|
||||
setPressed(false);
|
||||
}
|
||||
|
||||
|
||||
if (v instanceof Button) {
|
||||
final Button button = (Button)v;
|
||||
|
||||
button.setEnabled(false);
|
||||
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
public void run() {
|
||||
button.setEnabled(true);
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
}
|
||||
|
||||
startPoint = null;
|
||||
|
BIN
src/misc/stats.ods
Normal file
BIN
src/misc/stats.ods
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user