From 07a1608a80caa536e9e8557ba5664e6e62b545b2 Mon Sep 17 00:00:00 2001 From: serso Date: Thu, 4 Feb 2016 17:05:25 +0100 Subject: [PATCH] ActivityLauncher --- app/src/main/AndroidManifest.xml | 4 +- .../android/calculator/ActivityLauncher.java | 170 +++++++++--------- .../solovyev/android/calculator/BaseUi.java | 6 +- .../android/calculator/Calculator.java | 81 +++------ .../calculator/CalculatorActivity.java | 10 ++ .../calculator/CalculatorApplication.java | 23 ++- .../calculator/CalculatorEventType.java | 41 +---- .../solovyev/android/calculator/Display.java | 22 ++- .../solovyev/android/calculator/Keyboard.java | 33 ++-- ...rAboutActivity.java => AboutActivity.java} | 2 +- .../android/calculator/buttons/CppButton.java | 19 +- .../calculator/buttons/CppSpecialButton.java | 7 +- ...toryActivity.java => HistoryActivity.java} | 7 +- 13 files changed, 180 insertions(+), 245 deletions(-) rename app/src/main/java/org/solovyev/android/calculator/about/{CalculatorAboutActivity.java => AboutActivity.java} (95%) rename app/src/main/java/org/solovyev/android/calculator/history/{CalculatorHistoryActivity.java => HistoryActivity.java} (88%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 673797b4..fdc6a626 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -67,7 +67,7 @@ android:label="@string/c_app_settings" /> activity) { + showActivity(context, new Intent(context, activity)); } - public static void showHistory(@Nonnull final Context context, boolean detached) { - final Intent intent = new Intent(context, CalculatorHistoryActivity.class); + private static void showActivity(@Nonnull Context context, @NonNull Intent intent) { + final boolean detached = !(context instanceof Activity); Activities.addIntentFlags(intent, detached, context); context.startActivity(intent); } + public void showHistory() { + showHistory(getContext()); + } + + public void showSettings() { + showSettings(getContext()); + } + + public void showWidgetSettings() { + final Context context = getContext(); + showActivity(context, PreferencesActivity.makeIntent(context, R.xml.preferences_widget, R.string.prefs_widget_title)); + } + + public static void showHistory(@Nonnull final Context context) { + show(context, HistoryActivity.class); + } + + private static void show(@Nonnull Context context, Class activity) { + showActivity(context, activity); + } + + public void showOperators() { + showActivity(getContext(), OperatorsActivity.class); + } + public static void showSettings(@Nonnull final Context context) { - showSettings(context, false); - } - - public static void showWidgetSettings(@Nonnull final Context context, boolean detached) { - final Intent intent = PreferencesActivity.makeIntent(context, R.xml.preferences_widget, R.string.prefs_widget_title); - Activities.addIntentFlags(intent, detached, context); - context.startActivity(intent); - } - - public static void showSettings(@Nonnull final Context context, boolean detached) { - final Intent intent = new Intent(context, PreferencesActivity.class); - Activities.addIntentFlags(intent, detached, context); - context.startActivity(intent); + showActivity(context, PreferencesActivity.class); } public static void showAbout(@Nonnull final Context context) { - context.startActivity(new Intent(context, CalculatorAboutActivity.class)); + context.startActivity(new Intent(context, AboutActivity.class)); } public static void showFunctions(@Nonnull final Context context) { - showFunctions(context, false); + showActivity(context, FunctionsActivity.class); } - public static void showFunctions(@Nonnull final Context context, boolean detached) { - final Intent intent = new Intent(context, FunctionsActivity.class); - Activities.addIntentFlags(intent, detached, context); - context.startActivity(intent); - } - - public static void showOperators(@Nonnull final Context context) { - showOperators(context, false); - } - - public static void showOperators(@Nonnull final Context context, boolean detached) { - final Intent intent = new Intent(context, OperatorsActivity.class); - Activities.addIntentFlags(intent, detached, context); - context.startActivity(intent); - } - - public static void showVars(@Nonnull final Context context) { - showVars(context, false); - } - - public static void showVars(@Nonnull final Context context, boolean detached) { - final Intent intent = new Intent(context, VariablesActivity.class); - Activities.addIntentFlags(intent, detached, context); - context.startActivity(intent); + public static void showVariables(@Nonnull final Context context) { + showActivity(context, VariablesActivity.class); } public static void tryCreateVar(@Nonnull final Context context) { @@ -188,29 +190,31 @@ public final class ActivityLauncher implements CalculatorEventListener { } } - public static void openApp(@Nonnull Context context) { - final Intent intent = new Intent(context, CalculatorActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); - context.startActivity(intent); + public void openFacebook() { + final Uri uri = Uri.parse(application.getString(R.string.cpp_share_link)); + final Intent intent = new Intent(Intent.ACTION_VIEW, uri); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + application.startActivity(intent); } - public static void likeButtonPressed(@Nonnull final Context context) { - final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(context.getString(R.string.cpp_share_link))); - Activities.addIntentFlags(intent, false, context); - context.startActivity(intent); + public void setActivity(@Nullable CalculatorActivity activity) { + Check.isNull(this.activity); + this.activity = activity; } - public static void showEvaluationError(@Nonnull Context context, @Nonnull final String errorMessage) { - final LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); + public void clearActivity(@Nullable CalculatorActivity activity) { + Check.isNotNull(this.activity); + Check.equals(this.activity, activity); + this.activity = null; + } - final View errorMessageView = layoutInflater.inflate(R.layout.display_error_message, null); - ((TextView) errorMessageView.findViewById(R.id.error_message_text_view)).setText(errorMessage); + public void show(@NonNull Class activity) { + showActivity(getContext(), activity); + } - final AlertDialog.Builder builder = new AlertDialog.Builder(context) - .setPositiveButton(R.string.c_cancel, null) - .setView(errorMessageView); - - builder.create().show(); + @NonNull + private Context getContext() { + return activity == null ? application : activity; } @Override @@ -251,17 +255,21 @@ public final class ActivityLauncher implements CalculatorEventListener { } }); break; - case show_evaluation_error: - final String errorMessage = (String) data; - if (errorMessage != null) { - App.getUiThreadExecutor().execute(new Runnable() { - @Override - public void run() { - showEvaluationError(context, errorMessage); - } - }); - } - break; } } + + public void showFunctions() { + showFunctions(getContext()); + } + + public void showVariables() { + showVariables(getContext()); + } + + public void openApp() { + final Context context = getContext(); + final Intent intent = new Intent(context, CalculatorActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); + context.startActivity(intent); + } } diff --git a/app/src/main/java/org/solovyev/android/calculator/BaseUi.java b/app/src/main/java/org/solovyev/android/calculator/BaseUi.java index 38d8238a..b6b622f9 100644 --- a/app/src/main/java/org/solovyev/android/calculator/BaseUi.java +++ b/app/src/main/java/org/solovyev/android/calculator/BaseUi.java @@ -128,6 +128,8 @@ public abstract class BaseUi implements SharedPreferences.OnSharedPreferenceChan Calculator calculator; @Inject PreferredPreferences preferredPreferences; + @Inject + ActivityLauncher launcher; protected void onCreate(@Nonnull Activity activity) { cast(activity.getApplication()).getComponent().inject(this); @@ -315,11 +317,11 @@ public abstract class BaseUi implements SharedPreferences.OnSharedPreferenceChan } } - private static class OperatorsDragProcessor implements SimpleDragListener.DragProcessor { + private class OperatorsDragProcessor implements SimpleDragListener.DragProcessor { @Override public boolean processDragEvent(@Nonnull DragDirection dragDirection, @Nonnull DragButton dragButton, @Nonnull PointF startPoint, @Nonnull MotionEvent motionEvent) { if (dragDirection == DragDirection.down) { - Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_operators, null); + launcher.showOperators(); return true; } return false; diff --git a/app/src/main/java/org/solovyev/android/calculator/Calculator.java b/app/src/main/java/org/solovyev/android/calculator/Calculator.java index 6d490a62..e80597c2 100644 --- a/app/src/main/java/org/solovyev/android/calculator/Calculator.java +++ b/app/src/main/java/org/solovyev/android/calculator/Calculator.java @@ -26,13 +26,10 @@ import android.content.SharedPreferences; import android.support.annotation.NonNull; import android.text.TextUtils; import android.util.Log; + import com.squareup.otto.Bus; import com.squareup.otto.Subscribe; -import jscl.*; -import jscl.math.Generic; -import jscl.math.function.Constants; -import jscl.math.function.IConstant; -import jscl.text.ParseInterruptedException; + import org.solovyev.android.calculator.calculations.CalculationCancelledEvent; import org.solovyev.android.calculator.calculations.CalculationFailedEvent; import org.solovyev.android.calculator.calculations.CalculationFinishedEvent; @@ -48,11 +45,6 @@ import org.solovyev.common.text.Strings; import org.solovyev.common.units.ConversionException; import org.solovyev.common.units.Conversions; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -60,8 +52,23 @@ import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import jscl.JsclArithmeticException; +import jscl.JsclMathEngine; +import jscl.NumeralBase; +import jscl.NumeralBaseException; +import jscl.math.Generic; +import jscl.math.function.Constants; +import jscl.math.function.IConstant; +import jscl.text.ParseInterruptedException; + @Singleton -public class Calculator implements CalculatorEventListener, SharedPreferences.OnSharedPreferenceChangeListener { +public class Calculator implements SharedPreferences.OnSharedPreferenceChangeListener { public static final long NO_SEQUENCE = -1; private static final long PREFERENCE_CHECK_INTERVAL = TimeUnit.MINUTES.toMillis(15); @@ -99,7 +106,6 @@ public class Calculator implements CalculatorEventListener, SharedPreferences.On this.ui = ui; this.background = background; bus.register(this); - addCalculatorEventListener(this); preferences.registerOnSharedPreferenceChangeListener(this); } @@ -149,14 +155,12 @@ public class Calculator implements CalculatorEventListener, SharedPreferences.On public void evaluate() { final EditorState state = editor.getState(); - final CalculatorEventData eventData = fireCalculatorEvent(CalculatorEventType.manual_calculation_requested, state); - evaluate(JsclOperation.numeric, state.getTextString(), eventData.getSequenceId()); + evaluate(JsclOperation.numeric, state.getTextString()); } public void simplify() { final EditorState state = editor.getState(); - final CalculatorEventData eventData = fireCalculatorEvent(CalculatorEventType.manual_calculation_requested, state); - evaluate(JsclOperation.simplify, state.getTextString(), eventData.getSequenceId()); + evaluate(JsclOperation.simplify, state.getTextString()); } @Nonnull @@ -462,51 +466,6 @@ public class Calculator implements CalculatorEventListener, SharedPreferences.On } } - @Override - public void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data) { - switch (calculatorEventType) { - case show_history: - ActivityLauncher.showHistory(App.getApplication()); - break; - case show_history_detached: - ActivityLauncher.showHistory(App.getApplication(), true); - break; - case show_functions: - ActivityLauncher.showFunctions(App.getApplication()); - break; - case show_functions_detached: - ActivityLauncher.showFunctions(App.getApplication(), true); - break; - case show_operators: - ActivityLauncher.showOperators(App.getApplication()); - break; - case show_operators_detached: - ActivityLauncher.showOperators(App.getApplication(), true); - break; - case show_vars: - ActivityLauncher.showVars(App.getApplication()); - break; - case show_vars_detached: - ActivityLauncher.showVars(App.getApplication(), true); - break; - case show_settings: - ActivityLauncher.showSettings(App.getApplication()); - break; - case show_settings_detached: - ActivityLauncher.showSettings(App.getApplication(), true); - break; - case show_settings_widget: - ActivityLauncher.showWidgetSettings(App.getApplication(), true); - break; - case show_like_dialog: - ActivityLauncher.likeButtonPressed(App.getApplication()); - break; - case open_app: - ActivityLauncher.openApp(App.getApplication()); - break; - } - } - @Override public void onSharedPreferenceChanged(@Nonnull SharedPreferences prefs, @Nonnull String key) { if (Preferences.Calculations.calculateOnFly.getKey().equals(key)) { diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java index 9330b7f3..8a86249c 100644 --- a/app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java @@ -143,6 +143,9 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference @Inject History history; + @Inject + ActivityLauncher launcher; + /** * Called when the activity is first created. */ @@ -221,6 +224,7 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference @Override protected void onResume() { super.onResume(); + launcher.setActivity(this); final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); final Preferences.Gui.Layout newLayout = Preferences.Gui.layout.getPreference(preferences); @@ -236,6 +240,12 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference } } + @Override + protected void onPause() { + launcher.clearActivity(this); + super.onPause(); + } + @Override protected void onDestroy() { PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(this); diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java index 4671e603..78277aab 100644 --- a/app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java +++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java @@ -26,9 +26,10 @@ import android.content.SharedPreferences; import android.os.Handler; import android.preference.PreferenceManager; import android.util.Log; + import com.squareup.leakcanary.LeakCanary; import com.squareup.otto.Bus; -import jscl.MathEngine; + import org.acra.ACRA; import org.acra.ACRAConfiguration; import org.acra.sender.HttpSender; @@ -41,13 +42,14 @@ import org.solovyev.android.calculator.plot.AndroidCalculatorPlotter; import org.solovyev.android.calculator.plot.CalculatorPlotterImpl; import org.solovyev.common.msg.MessageType; +import java.util.Locale; +import java.util.concurrent.Executor; + import javax.annotation.Nonnull; import javax.inject.Inject; import javax.inject.Named; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; -import java.util.concurrent.Executor; + +import jscl.MathEngine; public class CalculatorApplication extends android.app.Application implements SharedPreferences.OnSharedPreferenceChangeListener { @@ -62,9 +64,6 @@ public class CalculatorApplication extends android.app.Application implements Sh @Inject Handler handler; - @Nonnull - private final List listeners = new ArrayList<>(); - private AppComponent component; @Inject @@ -100,6 +99,9 @@ public class CalculatorApplication extends android.app.Application implements Sh @Inject PreferredPreferences preferredPreferences; + @Inject + ActivityLauncher launcher; + @Override public void onCreate() { final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); @@ -131,11 +133,6 @@ public class CalculatorApplication extends android.app.Application implements Sh new AndroidCalculatorPlotter(this, new CalculatorPlotterImpl(calculator)) ); - listeners.add(new ActivityLauncher()); - for (CalculatorEventListener listener : listeners) { - calculator.addCalculatorEventListener(listener); - } - calculator.init(initThread); initThread.execute(new Runnable() { diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorEventType.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorEventType.java index 6d66f130..a4ba8362 100644 --- a/app/src/main/java/org/solovyev/android/calculator/CalculatorEventType.java +++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorEventType.java @@ -31,22 +31,6 @@ import javax.annotation.Nonnull; */ public enum CalculatorEventType { - /* - ********************************************************************** - * - * CALCULATION - * org.solovyev.android.calculator.CalculatorEvaluationEventData - * - ********************************************************************** - */ - - - // @Nonnull CalculatorEditorViewState - manual_calculation_requested, - - // @Nonnull org.solovyev.android.calculator.CalculatorFailure - calculation_failed, - /* ********************************************************************** * @@ -76,26 +60,6 @@ public enum CalculatorEventType { // List calculation_messages, - show_history, - show_history_detached, - - show_functions, - show_functions_detached, - - show_vars, - show_vars_detached, - - open_app, - - show_operators, - show_operators_detached, - - show_settings, - show_settings_detached, - show_settings_widget, - - show_like_dialog, - show_create_var_dialog, show_create_matrix_dialog, show_create_function_dialog, @@ -105,10 +69,7 @@ public enum CalculatorEventType { /** * {@link org.solovyev.android.calculator.plot.PlotData} */ - plot_data_changed, - - //String - show_evaluation_error; + plot_data_changed; public boolean isOfType(@Nonnull CalculatorEventType... types) { for (CalculatorEventType type : types) { diff --git a/app/src/main/java/org/solovyev/android/calculator/Display.java b/app/src/main/java/org/solovyev/android/calculator/Display.java index 67035194..57b985dc 100644 --- a/app/src/main/java/org/solovyev/android/calculator/Display.java +++ b/app/src/main/java/org/solovyev/android/calculator/Display.java @@ -22,11 +22,15 @@ package org.solovyev.android.calculator; +import android.app.Activity; +import android.app.AlertDialog; import android.app.Application; import android.content.Context; import android.view.ContextMenu; +import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; +import android.widget.TextView; import com.squareup.otto.Bus; import com.squareup.otto.Subscribe; @@ -64,6 +68,8 @@ public class Display implements CalculatorEventListener, View.OnClickListener, V Lazy clipboard; @Inject Lazy notifier; + @Inject + ActivityLauncher launcher; @Nullable private DisplayView view; @Nonnull @@ -194,10 +200,24 @@ public class Display implements CalculatorEventListener, View.OnClickListener, V v.showContextMenu(); v.setOnCreateContextMenuListener(null); } else { - Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_evaluation_error, state.text); + showEvaluationError(v.getContext(), state.text); } } + public static void showEvaluationError(@Nonnull Context context, @Nonnull final String errorMessage) { + final LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); + + final View errorMessageView = layoutInflater.inflate(R.layout.display_error_message, null); + ((TextView) errorMessageView.findViewById(R.id.error_message_text_view)).setText(errorMessage); + + final AlertDialog.Builder builder = new AlertDialog.Builder(context) + .setPositiveButton(R.string.c_cancel, null) + .setView(errorMessageView); + + builder.create().show(); + } + + @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { if (!state.valid) { diff --git a/app/src/main/java/org/solovyev/android/calculator/Keyboard.java b/app/src/main/java/org/solovyev/android/calculator/Keyboard.java index 9855dca8..eca096f7 100644 --- a/app/src/main/java/org/solovyev/android/calculator/Keyboard.java +++ b/app/src/main/java/org/solovyev/android/calculator/Keyboard.java @@ -54,6 +54,8 @@ public class Keyboard { Lazy clipboard; @Inject Lazy bus; + @Inject + ActivityLauncher launcher; @Inject public Keyboard() { @@ -119,10 +121,7 @@ public class Keyboard { private void onSpecialButtonPressed(@NonNull CppSpecialButton button) { switch (button) { case history: - calculator.fireCalculatorEvent(CalculatorEventType.show_history, null); - break; - case history_detached: - calculator.fireCalculatorEvent(CalculatorEventType.show_history_detached, null); + launcher.showHistory(); break; case cursor_right: moveCursorRight(); @@ -131,16 +130,13 @@ public class Keyboard { moveCursorLeft(); break; case settings: - calculator.fireCalculatorEvent(CalculatorEventType.show_settings, null); - break; - case settings_detached: - calculator.fireCalculatorEvent(CalculatorEventType.show_settings_detached, null); + launcher.showSettings(); break; case settings_widget: - calculator.fireCalculatorEvent(CalculatorEventType.show_settings_widget, null); + launcher.showWidgetSettings(); break; case like: - calculator.fireCalculatorEvent(CalculatorEventType.show_like_dialog, null); + launcher.openFacebook(); break; case erase: editor.erase(); @@ -158,25 +154,16 @@ public class Keyboard { clearButtonPressed(); break; case functions: - calculator.fireCalculatorEvent(CalculatorEventType.show_functions, null); - break; - case functions_detached: - calculator.fireCalculatorEvent(CalculatorEventType.show_functions_detached, null); + launcher.showFunctions(); break; case open_app: - calculator.fireCalculatorEvent(CalculatorEventType.open_app, null); + launcher.openApp(); break; case vars: - calculator.fireCalculatorEvent(CalculatorEventType.show_vars, null); - break; - case vars_detached: - calculator.fireCalculatorEvent(CalculatorEventType.show_vars_detached, null); + launcher.showVariables(); break; case operators: - calculator.fireCalculatorEvent(CalculatorEventType.show_operators, null); - break; - case operators_detached: - calculator.fireCalculatorEvent(CalculatorEventType.show_operators_detached, null); + launcher.showOperators(); break; default: Check.shouldNotHappen(); diff --git a/app/src/main/java/org/solovyev/android/calculator/about/CalculatorAboutActivity.java b/app/src/main/java/org/solovyev/android/calculator/about/AboutActivity.java similarity index 95% rename from app/src/main/java/org/solovyev/android/calculator/about/CalculatorAboutActivity.java rename to app/src/main/java/org/solovyev/android/calculator/about/AboutActivity.java index 8e828e3a..7b6fd704 100644 --- a/app/src/main/java/org/solovyev/android/calculator/about/CalculatorAboutActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/about/AboutActivity.java @@ -35,7 +35,7 @@ import javax.annotation.Nullable; * Date: 9/16/11 * Time: 11:52 PM */ -public class CalculatorAboutActivity extends EmptyActivity { +public class AboutActivity extends EmptyActivity { @Override public void onCreate(@Nullable Bundle savedInstanceState) { diff --git a/app/src/main/java/org/solovyev/android/calculator/buttons/CppButton.java b/app/src/main/java/org/solovyev/android/calculator/buttons/CppButton.java index 2db37351..2a5c9cef 100644 --- a/app/src/main/java/org/solovyev/android/calculator/buttons/CppButton.java +++ b/app/src/main/java/org/solovyev/android/calculator/buttons/CppButton.java @@ -32,12 +32,7 @@ import javax.annotation.Nullable; import static org.solovyev.android.calculator.buttons.CppSpecialButton.cursor_left; import static org.solovyev.android.calculator.buttons.CppSpecialButton.cursor_right; -import static org.solovyev.android.calculator.buttons.CppSpecialButton.functions_detached; -import static org.solovyev.android.calculator.buttons.CppSpecialButton.history_detached; import static org.solovyev.android.calculator.buttons.CppSpecialButton.open_app; -import static org.solovyev.android.calculator.buttons.CppSpecialButton.operators_detached; -import static org.solovyev.android.calculator.buttons.CppSpecialButton.settings_detached; -import static org.solovyev.android.calculator.buttons.CppSpecialButton.vars_detached; public enum CppButton { @@ -56,18 +51,18 @@ public enum CppButton { period(R.id.cpp_button_period, "."), brackets(R.id.cpp_button_round_brackets, "()"), - settings(R.id.cpp_button_settings, settings_detached), + settings(R.id.cpp_button_settings, CppSpecialButton.settings), settings_widget(R.id.cpp_button_settings_widget, CppSpecialButton.settings_widget), like(R.id.cpp_button_like, CppSpecialButton.like), /*last row*/ left(R.id.cpp_button_left, cursor_left), right(R.id.cpp_button_right, cursor_right), - vars(R.id.cpp_button_vars, vars_detached), - functions(R.id.cpp_button_functions, functions_detached), - operators(R.id.cpp_button_operators, operators_detached), + vars(R.id.cpp_button_vars, CppSpecialButton.vars), + functions(R.id.cpp_button_functions, CppSpecialButton.functions), + operators(R.id.cpp_button_operators, CppSpecialButton.operators), app(R.id.cpp_button_app, open_app), - history(R.id.cpp_button_history, history_detached), + history(R.id.cpp_button_history, CppSpecialButton.history), /*operations*/ multiplication(R.id.cpp_button_multiplication, "*"), @@ -98,8 +93,8 @@ public enum CppButton { this(id, button.action, buttonLong == null ? null : buttonLong.getAction()); } - CppButton(int id, @Nonnull CppSpecialButton onClickButton) { - this(id, onClickButton, null); + CppButton(int id, @Nonnull CppSpecialButton button) { + this(id, button, null); } CppButton(int id, @Nonnull String action, @Nullable String actionLong) { diff --git a/app/src/main/java/org/solovyev/android/calculator/buttons/CppSpecialButton.java b/app/src/main/java/org/solovyev/android/calculator/buttons/CppSpecialButton.java index 9c0173a6..fd7f9d30 100644 --- a/app/src/main/java/org/solovyev/android/calculator/buttons/CppSpecialButton.java +++ b/app/src/main/java/org/solovyev/android/calculator/buttons/CppSpecialButton.java @@ -33,11 +33,9 @@ import javax.annotation.Nullable; public enum CppSpecialButton { history("history"), - history_detached("history_detached"), cursor_right("▷"), cursor_left("◁"), settings("settings"), - settings_detached("settings_detached"), settings_widget("settings_widget"), like("like"), erase("erase"), @@ -46,12 +44,9 @@ public enum CppSpecialButton { equals("="), clear("clear"), functions("functions"), - functions_detached("functions_detached"), open_app("open_app"), vars("vars"), - vars_detached("vars_detached"), - operators("operators"), - operators_detached("operators_detached"); + operators("operators"); @Nonnull private static Map buttonsByActions = new HashMap<>(); diff --git a/app/src/main/java/org/solovyev/android/calculator/history/CalculatorHistoryActivity.java b/app/src/main/java/org/solovyev/android/calculator/history/HistoryActivity.java similarity index 88% rename from app/src/main/java/org/solovyev/android/calculator/history/CalculatorHistoryActivity.java rename to app/src/main/java/org/solovyev/android/calculator/history/HistoryActivity.java index da47244f..1b89f13e 100644 --- a/app/src/main/java/org/solovyev/android/calculator/history/CalculatorHistoryActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/history/HistoryActivity.java @@ -23,6 +23,7 @@ package org.solovyev.android.calculator.history; import android.os.Bundle; + import org.solovyev.android.calculator.BaseActivity; import org.solovyev.android.calculator.R; @@ -31,10 +32,10 @@ import javax.annotation.Nullable; import static org.solovyev.android.calculator.CalculatorFragmentType.history; import static org.solovyev.android.calculator.CalculatorFragmentType.saved_history; -public class CalculatorHistoryActivity extends BaseActivity { +public class HistoryActivity extends BaseActivity { - public CalculatorHistoryActivity() { - super(R.layout.main_empty, CalculatorHistoryActivity.class.getSimpleName()); + public HistoryActivity() { + super(R.layout.main_empty, HistoryActivity.class.getSimpleName()); } @Override