FUCK THE INTENTS
This commit is contained in:
parent
c718380912
commit
7f33ffd9a1
@ -16,7 +16,6 @@
|
||||
<intent-filter>
|
||||
<action a:name="android.intent.action.MAIN"/>
|
||||
<category a:name="android.intent.category.LAUNCHER"/>
|
||||
<action a:name="org.solovyev.android.calculator.CalculatorActivity.insertText"/>
|
||||
</intent-filter>
|
||||
|
||||
</activity>
|
||||
|
@ -26,6 +26,8 @@
|
||||
a:layout_width="match_parent"
|
||||
a:layout_gravity="top|center_horizontal"
|
||||
a:layout_weight="1"
|
||||
a:scrollbars="vertical"
|
||||
a:scrollbarFadeDuration="0"
|
||||
style="@style/about_style"/>
|
||||
|
||||
</LinearLayout>
|
@ -7,7 +7,9 @@ package org.solovyev.android.calculator;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.*;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
@ -26,7 +28,6 @@ import org.solovyev.android.view.FontSizeAdjuster;
|
||||
import org.solovyev.android.view.widgets.*;
|
||||
import org.solovyev.common.BooleanMapper;
|
||||
import org.solovyev.common.utils.Announcer;
|
||||
import org.solovyev.common.utils.StringUtils;
|
||||
import org.solovyev.common.utils.history.HistoryAction;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
@ -38,13 +39,6 @@ import java.util.Map;
|
||||
|
||||
public class CalculatorActivity extends Activity implements FontSizeAdjuster, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
public static final String INSERT_TEXT_INTENT = "org.solovyev.android.calculator.CalculatorActivity.insertText";
|
||||
public static final String INSERT_TEXT_INTENT_EXTRA_STRING = "org.solovyev.android.calculator.CalculatorActivity.insertText.extraString";
|
||||
|
||||
public static final String SET_TEXT_INTENT = "org.solovyev.android.calculator.CalculatorActivity.setText";
|
||||
public static final String SET_TEXT_INTENT_EXTRA_STRING = "org.solovyev.android.calculator.CalculatorActivity.settText.extraString";
|
||||
|
||||
|
||||
private static final int HVGA_WIDTH_PIXELS = 320;
|
||||
|
||||
@NotNull
|
||||
@ -53,9 +47,6 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
||||
@NotNull
|
||||
private CalculatorView calculatorView;
|
||||
|
||||
@NotNull
|
||||
private BroadcastReceiver textReceiver;
|
||||
|
||||
private volatile boolean initialized;
|
||||
|
||||
@NotNull
|
||||
@ -67,9 +58,6 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
||||
// ids of drag buttons in R.class
|
||||
private List<Integer> dragButtonIds = null;
|
||||
|
||||
@NotNull
|
||||
private final static Object broadcastReceiverLock = new Object();
|
||||
|
||||
/**
|
||||
* Called when the activity is first created.
|
||||
*/
|
||||
@ -85,7 +73,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
||||
|
||||
firstTimeInit();
|
||||
|
||||
init(preferences);
|
||||
calculatorView = CalculatorView.instance.init(this, preferences, CalculatorModel.instance);
|
||||
|
||||
dpclRegister.clear();
|
||||
|
||||
@ -166,49 +154,6 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
||||
setTheme(styleId);
|
||||
}
|
||||
|
||||
private void init(@NotNull SharedPreferences preferences) {
|
||||
|
||||
synchronized (broadcastReceiverLock) {
|
||||
calculatorView = new CalculatorView(this, preferences, CalculatorModel.instance);
|
||||
}
|
||||
|
||||
textReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
synchronized (broadcastReceiverLock) {
|
||||
Log.d(this.getClass().getName(), "Intent received: " + intent.getAction());
|
||||
if (INSERT_TEXT_INTENT.equals(intent.getAction())) {
|
||||
final String s = intent.getStringExtra(INSERT_TEXT_INTENT_EXTRA_STRING);
|
||||
Log.d(this.getClass().getName(), "Extra data: " + s);
|
||||
if (!StringUtils.isEmpty(s)) {
|
||||
calculatorView.doTextOperation(new CalculatorView.TextOperation() {
|
||||
@Override
|
||||
public void doOperation(@NotNull EditText editor) {
|
||||
editor.getText().insert(editor.getSelectionStart(), s);
|
||||
}
|
||||
}, false);
|
||||
}
|
||||
} else if (SET_TEXT_INTENT.equals(intent.getAction())) {
|
||||
final String s = intent.getStringExtra(SET_TEXT_INTENT_EXTRA_STRING);
|
||||
Log.d(this.getClass().getName(), "Extra data: " + s);
|
||||
if (!StringUtils.isEmpty(s)) {
|
||||
calculatorView.doTextOperation(new CalculatorView.TextOperation() {
|
||||
@Override
|
||||
public void doOperation(@NotNull EditText editor) {
|
||||
editor.setText(s);
|
||||
calculatorView.setCursorOnEnd();
|
||||
}
|
||||
}, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
registerReceiver(textReceiver, new IntentFilter(INSERT_TEXT_INTENT));
|
||||
registerReceiver(textReceiver, new IntentFilter(SET_TEXT_INTENT));
|
||||
}
|
||||
|
||||
private synchronized void firstTimeInit() {
|
||||
if (!initialized) {
|
||||
try {
|
||||
@ -220,13 +165,6 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
unregisterReceiver(textReceiver);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@SuppressWarnings({"UnusedDeclaration"})
|
||||
public void elementaryButtonClickHandler(@NotNull View v) {
|
||||
throw new UnsupportedOperationException("Not implemented yet!");
|
||||
@ -424,9 +362,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
||||
restart();
|
||||
}
|
||||
|
||||
synchronized (broadcastReceiverLock) {
|
||||
calculatorView = new CalculatorView(this, preferences, CalculatorModel.instance);
|
||||
}
|
||||
calculatorView = CalculatorView.instance.init(this, preferences, CalculatorModel.instance);
|
||||
|
||||
this.calculatorView.evaluate();
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ package org.solovyev.android.calculator;
|
||||
|
||||
import android.app.ListActivity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.*;
|
||||
import android.widget.*;
|
||||
@ -49,11 +48,21 @@ public class CalculatorHistoryActivity extends ListActivity {
|
||||
lv.setTextFilterEnabled(true);
|
||||
|
||||
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
public void onItemClick(AdapterView<?> parent, View view,
|
||||
int position, long id) {
|
||||
final Intent intent = new Intent(CalculatorActivity.SET_TEXT_INTENT);
|
||||
intent.putExtra(CalculatorActivity.SET_TEXT_INTENT_EXTRA_STRING, ((CalculatorHistoryState) parent.getItemAtPosition(position)).getEditorState().getText());
|
||||
sendOrderedBroadcast(intent, null);
|
||||
public void onItemClick(final AdapterView<?> parent,
|
||||
final View view,
|
||||
final int position,
|
||||
final long id) {
|
||||
|
||||
CalculatorView.instance.doTextOperation(new CalculatorView.TextOperation() {
|
||||
@Override
|
||||
public void doOperation(@NotNull EditText editor) {
|
||||
final EditorHistoryState editorState = ((CalculatorHistoryState) parent.getItemAtPosition(position)).getEditorState();
|
||||
editor.setText(editorState.getText());
|
||||
editor.setSelection(editorState.getCursorPosition());
|
||||
}
|
||||
}, false);
|
||||
|
||||
CalculatorView.instance.setCursorOnEnd();
|
||||
|
||||
CalculatorHistoryActivity.this.finish();
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ import android.app.AlertDialog;
|
||||
import android.app.ListActivity;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
@ -63,11 +62,17 @@ public class CalculatorVarsActivity extends ListActivity {
|
||||
});
|
||||
|
||||
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
public void onItemClick(AdapterView<?> parent, View view,
|
||||
int position, long id) {
|
||||
final Intent intent = new Intent(CalculatorActivity.INSERT_TEXT_INTENT);
|
||||
intent.putExtra(CalculatorActivity.INSERT_TEXT_INTENT_EXTRA_STRING, ((Var) parent.getItemAtPosition(position)).getName());
|
||||
sendOrderedBroadcast(intent, null);
|
||||
public void onItemClick(final AdapterView<?> parent,
|
||||
final View view,
|
||||
final int position,
|
||||
final long id) {
|
||||
|
||||
CalculatorView.instance.doTextOperation(new CalculatorView.TextOperation() {
|
||||
@Override
|
||||
public void doOperation(@NotNull EditText editor) {
|
||||
editor.getText().insert(editor.getSelectionStart(), ((Var) parent.getItemAtPosition(position)).getName());
|
||||
}
|
||||
}, false);
|
||||
|
||||
CalculatorVarsActivity.this.finish();
|
||||
}
|
||||
|
@ -33,21 +33,23 @@ import org.solovyev.common.utils.history.HistoryAction;
|
||||
* Date: 9/12/11
|
||||
* Time: 11:15 PM
|
||||
*/
|
||||
public class CalculatorView implements CursorControl, HistoryControl<CalculatorHistoryState> {
|
||||
public enum CalculatorView implements CursorControl, HistoryControl<CalculatorHistoryState> {
|
||||
|
||||
instance;
|
||||
|
||||
// millis to wait before evaluation after user edit action
|
||||
public static final int EVAL_DELAY_MILLIS = 1000;
|
||||
|
||||
@NotNull
|
||||
private final CalculatorEditor editor;
|
||||
private CalculatorEditor editor;
|
||||
|
||||
@NotNull
|
||||
private final CalculatorDisplay display;
|
||||
private CalculatorDisplay display;
|
||||
|
||||
@NotNull
|
||||
private final CalculatorModel calculatorModel;
|
||||
private CalculatorModel calculatorModel;
|
||||
|
||||
public CalculatorView(@NotNull final Activity activity, @NotNull SharedPreferences preferences, @NotNull CalculatorModel calculator) {
|
||||
public CalculatorView init(@NotNull final Activity activity, @NotNull SharedPreferences preferences, @NotNull CalculatorModel calculator) {
|
||||
this.calculatorModel = calculator;
|
||||
|
||||
this.editor = (CalculatorEditor) activity.findViewById(R.id.calculatorEditor);
|
||||
@ -72,6 +74,8 @@ public class CalculatorView implements CursorControl, HistoryControl<CalculatorH
|
||||
setCurrentHistoryState(lastState);
|
||||
}
|
||||
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public void copyResult(@NotNull Context context) {
|
||||
|
@ -29,6 +29,7 @@ class FromJsclTextProcessor implements TextProcessor {
|
||||
result = String.valueOf(roundedValue);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
result = result.replace(MathType.INFINITY_DEF, MathType.INFINITY);
|
||||
if (result.contains(MathType.IMAGINARY_NUMBER_DEF)) {
|
||||
try {
|
||||
result = createResultForComplexNumber(result.replace(MathType.IMAGINARY_NUMBER_DEF, MathType.IMAGINARY_NUMBER));
|
||||
|
Loading…
Reference in New Issue
Block a user