From 7aa505ab7ca666d2540425adccdaecd2a68acf0b Mon Sep 17 00:00:00 2001 From: serso Date: Sun, 16 Oct 2011 20:28:54 +0400 Subject: [PATCH] FUCK THE INTENTS --- AndroidManifest.xml | 1 - res/layout/about.xml | 2 + .../calculator/CalculatorActivity.java | 74 ++----------------- .../calculator/CalculatorHistoryActivity.java | 21 ++++-- .../calculator/CalculatorVarsActivity.java | 17 +++-- .../android/calculator/CalculatorView.java | 14 ++-- .../model/FromJsclTextProcessor.java | 1 + 7 files changed, 43 insertions(+), 87 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 14603c70..78d30e6b 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -16,7 +16,6 @@ - diff --git a/res/layout/about.xml b/res/layout/about.xml index e329cf31..c245c5f9 100644 --- a/res/layout/about.xml +++ b/res/layout/about.xml @@ -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"/> \ No newline at end of file diff --git a/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java b/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java index 4d816ba0..73037f38 100644 --- a/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java +++ b/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java @@ -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 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(); } diff --git a/src/main/java/org/solovyev/android/calculator/CalculatorHistoryActivity.java b/src/main/java/org/solovyev/android/calculator/CalculatorHistoryActivity.java index 32f9975b..ac76fe51 100644 --- a/src/main/java/org/solovyev/android/calculator/CalculatorHistoryActivity.java +++ b/src/main/java/org/solovyev/android/calculator/CalculatorHistoryActivity.java @@ -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(); } diff --git a/src/main/java/org/solovyev/android/calculator/CalculatorVarsActivity.java b/src/main/java/org/solovyev/android/calculator/CalculatorVarsActivity.java index 4b508a35..8d9281ea 100644 --- a/src/main/java/org/solovyev/android/calculator/CalculatorVarsActivity.java +++ b/src/main/java/org/solovyev/android/calculator/CalculatorVarsActivity.java @@ -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(); } diff --git a/src/main/java/org/solovyev/android/calculator/CalculatorView.java b/src/main/java/org/solovyev/android/calculator/CalculatorView.java index 70072f74..eb537210 100644 --- a/src/main/java/org/solovyev/android/calculator/CalculatorView.java +++ b/src/main/java/org/solovyev/android/calculator/CalculatorView.java @@ -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 { +public enum CalculatorView implements CursorControl, HistoryControl { + + 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