From 87254f5335e1eda517f82872ae4f6e42295d0571 Mon Sep 17 00:00:00 2001 From: Sergey Solovyev Date: Sat, 1 Dec 2012 21:51:40 +0400 Subject: [PATCH] merging --- .../android/calculator/CalculatorButtons.java | 4 +--- .../res/layout/matrix_edit_fragment.xml | 4 ++-- .../CalculatorActivityLauncher.java | 24 +++++++++++++++---- .../calculator/CalculatorApplication.java | 20 ++++++++++++++++ .../function/FunctionEditDialogFragment.java | 1 + .../calculator/CalculatorEventType.java | 1 + 6 files changed, 45 insertions(+), 9 deletions(-) diff --git a/android-app-core/src/main/java/org/solovyev/android/calculator/CalculatorButtons.java b/android-app-core/src/main/java/org/solovyev/android/calculator/CalculatorButtons.java index 449fc02f..9780d261 100644 --- a/android-app-core/src/main/java/org/solovyev/android/calculator/CalculatorButtons.java +++ b/android-app-core/src/main/java/org/solovyev/android/calculator/CalculatorButtons.java @@ -2,7 +2,6 @@ package org.solovyev.android.calculator; import android.app.Activity; import android.content.Context; -import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Configuration; import android.preference.PreferenceManager; @@ -18,7 +17,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.solovyev.android.AndroidUtils; import org.solovyev.android.calculator.core.R; -import org.solovyev.android.calculator.matrix.CalculatorMatrixActivity; import org.solovyev.android.calculator.model.AndroidCalculatorEngine; import org.solovyev.android.calculator.view.AngleUnitsButton; import org.solovyev.android.calculator.view.NumeralBasesButton; @@ -138,7 +136,7 @@ public final class CalculatorButtons { Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_create_var_dialog, null); result = true; } else if ( dragDirection == DragDirection.down ) { - context.startActivity(new Intent(context, CalculatorMatrixActivity.class)); + Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_create_matrix_dialog, null); result = true; } diff --git a/android-app/res/layout/matrix_edit_fragment.xml b/android-app/res/layout/matrix_edit_fragment.xml index d3133f42..7f2d115b 100644 --- a/android-app/res/layout/matrix_edit_fragment.xml +++ b/android-app/res/layout/matrix_edit_fragment.xml @@ -4,14 +4,14 @@ + style="?cpp_fragment_title_style"/> diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivityLauncher.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivityLauncher.java index dd2d2cfe..39b5067f 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivityLauncher.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivityLauncher.java @@ -2,6 +2,7 @@ package org.solovyev.android.calculator; import android.app.Activity; import android.app.AlertDialog; +import android.app.Application; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -21,6 +22,7 @@ import org.solovyev.android.calculator.function.FunctionEditDialogFragment; import org.solovyev.android.calculator.help.CalculatorHelpActivity; import org.solovyev.android.calculator.history.CalculatorHistoryActivity; import org.solovyev.android.calculator.math.edit.*; +import org.solovyev.android.calculator.matrix.CalculatorMatrixActivity; import org.solovyev.android.calculator.plot.CalculatorPlotActivity; import org.solovyev.android.calculator.plot.CalculatorPlotFragment; import org.solovyev.android.calculator.plot.PlotInput; @@ -113,6 +115,7 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener intent.putExtra(ChartFactory.TITLE, context.getString(R.string.c_graph)); intent.putExtra(CalculatorPlotFragment.INPUT, new CalculatorPlotFragment.Input(generic.toString(), constant.getName())); intent.setClass(context, CalculatorPlotActivity.class); + addFlags(intent, false); context.startActivity(intent); } @@ -127,6 +130,7 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener } else { final Intent intent = new Intent(context, CalculatorVarsActivity.class); intent.putExtra(CalculatorVarsFragment.CREATE_VAR_EXTRA_STRING, varValue); + addFlags(intent, false); context.startActivity(intent); } } else { @@ -179,12 +183,24 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener @Override public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) { + final Application application = App.getInstance().getApplication(); + switch (calculatorEventType){ + case show_create_matrix_dialog: + App.getInstance().getUiThreadExecutor().execute(new Runnable() { + @Override + public void run() { + final Intent intent = new Intent(application, CalculatorMatrixActivity.class); + addFlags(intent, false); + application.startActivity(intent); + } + }); + break; case show_create_var_dialog: App.getInstance().getUiThreadExecutor().execute(new Runnable() { @Override public void run() { - CalculatorActivityLauncher.createVar(App.getInstance().getApplication(), Locator.getInstance().getDisplay()); + CalculatorActivityLauncher.createVar(application, Locator.getInstance().getDisplay()); } }); break; @@ -192,7 +208,7 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener App.getInstance().getUiThreadExecutor().execute(new Runnable() { @Override public void run() { - CalculatorActivityLauncher.createFunction(App.getInstance().getApplication(), Locator.getInstance().getDisplay()); + CalculatorActivityLauncher.createFunction(application, Locator.getInstance().getDisplay()); } }); break; @@ -202,7 +218,7 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener App.getInstance().getUiThreadExecutor().execute(new Runnable() { @Override public void run() { - plotGraph(App.getInstance().getApplication(), plotInput.getFunction(), plotInput.getConstant()); + plotGraph(application, plotInput.getFunction(), plotInput.getConstant()); } }); break; @@ -212,7 +228,7 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener App.getInstance().getUiThreadExecutor().execute(new Runnable() { @Override public void run() { - showEvaluationError(App.getInstance().getApplication(), errorMessage); + showEvaluationError(application, errorMessage); } }); } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java index 97420fa0..09996999 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java @@ -17,6 +17,9 @@ import org.solovyev.android.calculator.external.AndroidExternalListenersContaine import org.solovyev.android.calculator.history.AndroidCalculatorHistory; import org.solovyev.android.calculator.model.AndroidCalculatorEngine; +import java.util.ArrayList; +import java.util.List; + /** * User: serso * Date: 12/1/11 @@ -50,6 +53,17 @@ public class CalculatorApplication extends android.app.Application { @NotNull private static CalculatorApplication instance; + + /* + ********************************************************************** + * + * FIELDS + * + ********************************************************************** + */ + + private final List listeners = new ArrayList(); + /* ********************************************************************** * @@ -133,6 +147,12 @@ public class CalculatorApplication extends android.app.Application { } }).start(); + listeners.add(new CalculatorActivityLauncher()); + + for (CalculatorEventListener listener : listeners) { + calculator.addCalculatorEventListener(listener); + } + Locator.getInstance().getLogger().debug(TAG, "Application started!"); Locator.getInstance().getNotifier().showDebugMessage(TAG, "Application started!"); } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/function/FunctionEditDialogFragment.java b/android-app/src/main/java/org/solovyev/android/calculator/function/FunctionEditDialogFragment.java index 13045002..3b230fda 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/function/FunctionEditDialogFragment.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/function/FunctionEditDialogFragment.java @@ -167,6 +167,7 @@ public class FunctionEditDialogFragment extends DialogFragment implements Calcul FunctionEditDialogFragment.showDialog(input, ((SherlockFragmentActivity) context).getSupportFragmentManager()); } else { final Intent intent = new Intent(context, CalculatorFunctionsActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(CalculatorFunctionsFragment.CREATE_FUNCTION_EXTRA, input); context.startActivity(intent); } diff --git a/core/src/main/java/org/solovyev/android/calculator/CalculatorEventType.java b/core/src/main/java/org/solovyev/android/calculator/CalculatorEventType.java index 306e0ad2..0d133286 100644 --- a/core/src/main/java/org/solovyev/android/calculator/CalculatorEventType.java +++ b/core/src/main/java/org/solovyev/android/calculator/CalculatorEventType.java @@ -156,6 +156,7 @@ public enum CalculatorEventType { show_like_dialog, show_create_var_dialog, + show_create_matrix_dialog, show_create_function_dialog, //org.solovyev.android.calculator.plot.PlotInput