preferences + asyn result calculation

This commit is contained in:
Sergey Solovyev 2011-09-13 15:15:21 +04:00
parent 327e2ddb12
commit d00d1ef52a
5 changed files with 52 additions and 17 deletions

View File

@ -37,6 +37,9 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster {
@NotNull @NotNull
private CalculatorModel calculator; private CalculatorModel calculator;
@NotNull
private BroadcastReceiver preferencesChangesReceiver;
/** /**
* Called when the activity is first created. * Called when the activity is first created.
*/ */
@ -112,7 +115,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster {
onDragListeners.add(toPositionOnDragListener); onDragListeners.add(toPositionOnDragListener);
final BroadcastReceiver preferencesChangesReceiver = new BroadcastReceiver() { preferencesChangesReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { 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)); registerReceiver(preferencesChangesReceiver, new IntentFilter(DragButtonCalibrationActivity.INTENT_ACTION));
} }
@Override
protected void onDestroy() {
unregisterReceiver(preferencesChangesReceiver);
super.onDestroy();
}
@SuppressWarnings({"UnusedDeclaration"}) @SuppressWarnings({"UnusedDeclaration"})
public void elementaryButtonClickHandler(@NotNull View v) { public void elementaryButtonClickHandler(@NotNull View v) {
throw new UnsupportedOperationException("Not implemented yet!"); throw new UnsupportedOperationException("Not implemented yet!");

View File

@ -2,6 +2,7 @@ package org.solovyev.android.calculator;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.os.Handler;
import android.text.ClipboardManager; import android.text.ClipboardManager;
import android.text.InputType; import android.text.InputType;
import android.view.View; import android.view.View;
@ -15,6 +16,8 @@ import org.jetbrains.annotations.Nullable;
import org.solovyev.util.StringUtils; import org.solovyev.util.StringUtils;
import org.solovyev.util.math.MathEntityType; import org.solovyev.util.math.MathEntityType;
import java.util.Date;
/** /**
* User: serso * User: serso
* Date: 9/12/11 * Date: 9/12/11
@ -96,19 +99,31 @@ public class CalculatorView implements CursorControl{
final String editorStateAfter = this.editor.getText().toString(); final String editorStateAfter = this.editor.getText().toString();
if (!editorStateBefore.equals(editorStateAfter)) { if (!editorStateBefore.equals(editorStateAfter)) {
try {
evaluate(editorStateAfter);
} catch (EvalError evalError) {
// actually nothing shall be logged while text operations are done // actually nothing shall be logged while text operations are done
} evaluate(editorStateAfter, false);
saveHistoryState(); saveHistoryState();
} }
} }
private void evaluate(@Nullable String expression) throws EvalError { private void evaluate(@Nullable final String expression, final boolean showError) {
if (!StringUtils.isEmpty(expression)) { 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() { public void evaluate() {
try { evaluate(editor.getText().toString(), true);
evaluate(editor.getText().toString());
} catch (EvalError evalError) {
Toast.makeText(this.activity, R.string.syntax_error, Toast.LENGTH_SHORT).show();
}
} }
public void processButtonAction(@Nullable final String text) { public void processButtonAction(@Nullable final String text) {

View File

@ -216,12 +216,12 @@ public class DragButtonCalibrationActivity extends Activity {
} }
break; break;
case distance: case distance:
defaultMin = 60f; defaultMin = 50f;
defaultMax = 140f; defaultMax = 150f;
break; break;
case duration: case duration:
defaultMin = 100f; defaultMin = 40f;
defaultMax = 300f; defaultMax = 1000f;
break; break;
default: default:
defaultMin = DEFAULT_VALUE; defaultMin = DEFAULT_VALUE;

View File

@ -1,5 +1,7 @@
package org.solovyev.android.view; package org.solovyev.android.view;
import android.os.Handler;
import android.widget.Button;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.solovyev.util.math.Point2d; import org.solovyev.util.math.Point2d;
@ -76,6 +78,19 @@ public class DragButton extends ColorButton {
// prevent on click action // prevent on click action
setPressed(false); 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; startPoint = null;

BIN
src/misc/stats.ods Normal file

Binary file not shown.