ActivityLauncher
This commit is contained in:
parent
ebdfbc328c
commit
07a1608a80
@ -67,7 +67,7 @@
|
|||||||
android:label="@string/c_app_settings" />
|
android:label="@string/c_app_settings" />
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".history.CalculatorHistoryActivity"
|
android:name=".history.HistoryActivity"
|
||||||
android:label="@string/c_history" />
|
android:label="@string/c_history" />
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
@ -78,7 +78,7 @@
|
|||||||
android:theme="@style/Cpp.Theme.Translucent" />
|
android:theme="@style/Cpp.Theme.Translucent" />
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".about.CalculatorAboutActivity"
|
android:name=".about.AboutActivity"
|
||||||
android:label="@string/c_about" />
|
android:label="@string/c_about" />
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
|
@ -23,21 +23,19 @@
|
|||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.Application;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.view.LayoutInflater;
|
import android.support.annotation.NonNull;
|
||||||
import android.view.View;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import jscl.math.Generic;
|
|
||||||
import jscl.math.function.Constant;
|
|
||||||
import org.solovyev.android.Activities;
|
import org.solovyev.android.Activities;
|
||||||
import org.solovyev.android.calculator.about.CalculatorAboutActivity;
|
import org.solovyev.android.Check;
|
||||||
|
import org.solovyev.android.calculator.about.AboutActivity;
|
||||||
import org.solovyev.android.calculator.functions.CppFunction;
|
import org.solovyev.android.calculator.functions.CppFunction;
|
||||||
import org.solovyev.android.calculator.functions.EditFunctionFragment;
|
import org.solovyev.android.calculator.functions.EditFunctionFragment;
|
||||||
import org.solovyev.android.calculator.functions.FunctionsActivity;
|
import org.solovyev.android.calculator.functions.FunctionsActivity;
|
||||||
import org.solovyev.android.calculator.history.CalculatorHistoryActivity;
|
import org.solovyev.android.calculator.history.HistoryActivity;
|
||||||
import org.solovyev.android.calculator.matrix.CalculatorMatrixActivity;
|
import org.solovyev.android.calculator.matrix.CalculatorMatrixActivity;
|
||||||
import org.solovyev.android.calculator.operators.OperatorsActivity;
|
import org.solovyev.android.calculator.operators.OperatorsActivity;
|
||||||
import org.solovyev.android.calculator.plot.CalculatorPlotter;
|
import org.solovyev.android.calculator.plot.CalculatorPlotter;
|
||||||
@ -49,73 +47,77 @@ import org.solovyev.android.calculator.variables.VariablesFragment;
|
|||||||
import org.solovyev.common.msg.MessageType;
|
import org.solovyev.common.msg.MessageType;
|
||||||
import org.solovyev.common.text.Strings;
|
import org.solovyev.common.text.Strings;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import jscl.math.Generic;
|
||||||
|
import jscl.math.function.Constant;
|
||||||
|
|
||||||
|
@Singleton
|
||||||
public final class ActivityLauncher implements CalculatorEventListener {
|
public final class ActivityLauncher implements CalculatorEventListener {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
Application application;
|
||||||
|
@Nullable
|
||||||
|
private CalculatorActivity activity;
|
||||||
|
|
||||||
|
@Inject
|
||||||
public ActivityLauncher() {
|
public ActivityLauncher() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showHistory(@Nonnull final Context context) {
|
private static void showActivity(@Nonnull final Context context, @NonNull Class<? extends Activity> activity) {
|
||||||
showHistory(context, false);
|
showActivity(context, new Intent(context, activity));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showHistory(@Nonnull final Context context, boolean detached) {
|
private static void showActivity(@Nonnull Context context, @NonNull Intent intent) {
|
||||||
final Intent intent = new Intent(context, CalculatorHistoryActivity.class);
|
final boolean detached = !(context instanceof Activity);
|
||||||
Activities.addIntentFlags(intent, detached, context);
|
Activities.addIntentFlags(intent, detached, context);
|
||||||
context.startActivity(intent);
|
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<HistoryActivity> activity) {
|
||||||
|
showActivity(context, activity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showOperators() {
|
||||||
|
showActivity(getContext(), OperatorsActivity.class);
|
||||||
|
}
|
||||||
|
|
||||||
public static void showSettings(@Nonnull final Context context) {
|
public static void showSettings(@Nonnull final Context context) {
|
||||||
showSettings(context, false);
|
showActivity(context, PreferencesActivity.class);
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showAbout(@Nonnull final Context context) {
|
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) {
|
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) {
|
public static void showVariables(@Nonnull final Context context) {
|
||||||
final Intent intent = new Intent(context, FunctionsActivity.class);
|
showActivity(context, VariablesActivity.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 tryCreateVar(@Nonnull final Context context) {
|
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) {
|
public void openFacebook() {
|
||||||
final Intent intent = new Intent(context, CalculatorActivity.class);
|
final Uri uri = Uri.parse(application.getString(R.string.cpp_share_link));
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
||||||
context.startActivity(intent);
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
application.startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void likeButtonPressed(@Nonnull final Context context) {
|
public void setActivity(@Nullable CalculatorActivity activity) {
|
||||||
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(context.getString(R.string.cpp_share_link)));
|
Check.isNull(this.activity);
|
||||||
Activities.addIntentFlags(intent, false, context);
|
this.activity = activity;
|
||||||
context.startActivity(intent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showEvaluationError(@Nonnull Context context, @Nonnull final String errorMessage) {
|
public void clearActivity(@Nullable CalculatorActivity activity) {
|
||||||
final LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
|
Check.isNotNull(this.activity);
|
||||||
|
Check.equals(this.activity, activity);
|
||||||
|
this.activity = null;
|
||||||
|
}
|
||||||
|
|
||||||
final View errorMessageView = layoutInflater.inflate(R.layout.display_error_message, null);
|
public void show(@NonNull Class<HistoryActivity> activity) {
|
||||||
((TextView) errorMessageView.findViewById(R.id.error_message_text_view)).setText(errorMessage);
|
showActivity(getContext(), activity);
|
||||||
|
}
|
||||||
|
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(context)
|
@NonNull
|
||||||
.setPositiveButton(R.string.c_cancel, null)
|
private Context getContext() {
|
||||||
.setView(errorMessageView);
|
return activity == null ? application : activity;
|
||||||
|
|
||||||
builder.create().show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -251,17 +255,21 @@ public final class ActivityLauncher implements CalculatorEventListener {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,6 +128,8 @@ public abstract class BaseUi implements SharedPreferences.OnSharedPreferenceChan
|
|||||||
Calculator calculator;
|
Calculator calculator;
|
||||||
@Inject
|
@Inject
|
||||||
PreferredPreferences preferredPreferences;
|
PreferredPreferences preferredPreferences;
|
||||||
|
@Inject
|
||||||
|
ActivityLauncher launcher;
|
||||||
|
|
||||||
protected void onCreate(@Nonnull Activity activity) {
|
protected void onCreate(@Nonnull Activity activity) {
|
||||||
cast(activity.getApplication()).getComponent().inject(this);
|
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
|
@Override
|
||||||
public boolean processDragEvent(@Nonnull DragDirection dragDirection, @Nonnull DragButton dragButton, @Nonnull PointF startPoint, @Nonnull MotionEvent motionEvent) {
|
public boolean processDragEvent(@Nonnull DragDirection dragDirection, @Nonnull DragButton dragButton, @Nonnull PointF startPoint, @Nonnull MotionEvent motionEvent) {
|
||||||
if (dragDirection == DragDirection.down) {
|
if (dragDirection == DragDirection.down) {
|
||||||
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_operators, null);
|
launcher.showOperators();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -26,13 +26,10 @@ import android.content.SharedPreferences;
|
|||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.squareup.otto.Bus;
|
import com.squareup.otto.Bus;
|
||||||
import com.squareup.otto.Subscribe;
|
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.CalculationCancelledEvent;
|
||||||
import org.solovyev.android.calculator.calculations.CalculationFailedEvent;
|
import org.solovyev.android.calculator.calculations.CalculationFailedEvent;
|
||||||
import org.solovyev.android.calculator.calculations.CalculationFinishedEvent;
|
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.ConversionException;
|
||||||
import org.solovyev.common.units.Conversions;
|
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.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -60,8 +52,23 @@ import java.util.concurrent.Executor;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
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
|
@Singleton
|
||||||
public class Calculator implements CalculatorEventListener, SharedPreferences.OnSharedPreferenceChangeListener {
|
public class Calculator implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
|
|
||||||
public static final long NO_SEQUENCE = -1;
|
public static final long NO_SEQUENCE = -1;
|
||||||
private static final long PREFERENCE_CHECK_INTERVAL = TimeUnit.MINUTES.toMillis(15);
|
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.ui = ui;
|
||||||
this.background = background;
|
this.background = background;
|
||||||
bus.register(this);
|
bus.register(this);
|
||||||
addCalculatorEventListener(this);
|
|
||||||
preferences.registerOnSharedPreferenceChangeListener(this);
|
preferences.registerOnSharedPreferenceChangeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,14 +155,12 @@ public class Calculator implements CalculatorEventListener, SharedPreferences.On
|
|||||||
|
|
||||||
public void evaluate() {
|
public void evaluate() {
|
||||||
final EditorState state = editor.getState();
|
final EditorState state = editor.getState();
|
||||||
final CalculatorEventData eventData = fireCalculatorEvent(CalculatorEventType.manual_calculation_requested, state);
|
evaluate(JsclOperation.numeric, state.getTextString());
|
||||||
evaluate(JsclOperation.numeric, state.getTextString(), eventData.getSequenceId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void simplify() {
|
public void simplify() {
|
||||||
final EditorState state = editor.getState();
|
final EditorState state = editor.getState();
|
||||||
final CalculatorEventData eventData = fireCalculatorEvent(CalculatorEventType.manual_calculation_requested, state);
|
evaluate(JsclOperation.simplify, state.getTextString());
|
||||||
evaluate(JsclOperation.simplify, state.getTextString(), eventData.getSequenceId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@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
|
@Override
|
||||||
public void onSharedPreferenceChanged(@Nonnull SharedPreferences prefs, @Nonnull String key) {
|
public void onSharedPreferenceChanged(@Nonnull SharedPreferences prefs, @Nonnull String key) {
|
||||||
if (Preferences.Calculations.calculateOnFly.getKey().equals(key)) {
|
if (Preferences.Calculations.calculateOnFly.getKey().equals(key)) {
|
||||||
|
@ -143,6 +143,9 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference
|
|||||||
@Inject
|
@Inject
|
||||||
History history;
|
History history;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ActivityLauncher launcher;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the activity is first created.
|
* Called when the activity is first created.
|
||||||
*/
|
*/
|
||||||
@ -221,6 +224,7 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference
|
|||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
launcher.setActivity(this);
|
||||||
|
|
||||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
final Preferences.Gui.Layout newLayout = Preferences.Gui.layout.getPreference(preferences);
|
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
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(this);
|
PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(this);
|
||||||
|
@ -26,9 +26,10 @@ import android.content.SharedPreferences;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.squareup.leakcanary.LeakCanary;
|
import com.squareup.leakcanary.LeakCanary;
|
||||||
import com.squareup.otto.Bus;
|
import com.squareup.otto.Bus;
|
||||||
import jscl.MathEngine;
|
|
||||||
import org.acra.ACRA;
|
import org.acra.ACRA;
|
||||||
import org.acra.ACRAConfiguration;
|
import org.acra.ACRAConfiguration;
|
||||||
import org.acra.sender.HttpSender;
|
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.android.calculator.plot.CalculatorPlotterImpl;
|
||||||
import org.solovyev.common.msg.MessageType;
|
import org.solovyev.common.msg.MessageType;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import jscl.MathEngine;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
|
|
||||||
public class CalculatorApplication extends android.app.Application implements SharedPreferences.OnSharedPreferenceChangeListener {
|
public class CalculatorApplication extends android.app.Application implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
|
|
||||||
@ -62,9 +64,6 @@ public class CalculatorApplication extends android.app.Application implements Sh
|
|||||||
@Inject
|
@Inject
|
||||||
Handler handler;
|
Handler handler;
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
private final List<CalculatorEventListener> listeners = new ArrayList<>();
|
|
||||||
|
|
||||||
private AppComponent component;
|
private AppComponent component;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@ -100,6 +99,9 @@ public class CalculatorApplication extends android.app.Application implements Sh
|
|||||||
@Inject
|
@Inject
|
||||||
PreferredPreferences preferredPreferences;
|
PreferredPreferences preferredPreferences;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ActivityLauncher launcher;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
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))
|
new AndroidCalculatorPlotter(this, new CalculatorPlotterImpl(calculator))
|
||||||
);
|
);
|
||||||
|
|
||||||
listeners.add(new ActivityLauncher());
|
|
||||||
for (CalculatorEventListener listener : listeners) {
|
|
||||||
calculator.addCalculatorEventListener(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
calculator.init(initThread);
|
calculator.init(initThread);
|
||||||
|
|
||||||
initThread.execute(new Runnable() {
|
initThread.execute(new Runnable() {
|
||||||
|
@ -31,22 +31,6 @@ import javax.annotation.Nonnull;
|
|||||||
*/
|
*/
|
||||||
public enum CalculatorEventType {
|
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<Message>
|
// List<Message>
|
||||||
calculation_messages,
|
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_var_dialog,
|
||||||
show_create_matrix_dialog,
|
show_create_matrix_dialog,
|
||||||
show_create_function_dialog,
|
show_create_function_dialog,
|
||||||
@ -105,10 +69,7 @@ public enum CalculatorEventType {
|
|||||||
/**
|
/**
|
||||||
* {@link org.solovyev.android.calculator.plot.PlotData}
|
* {@link org.solovyev.android.calculator.plot.PlotData}
|
||||||
*/
|
*/
|
||||||
plot_data_changed,
|
plot_data_changed;
|
||||||
|
|
||||||
//String
|
|
||||||
show_evaluation_error;
|
|
||||||
|
|
||||||
public boolean isOfType(@Nonnull CalculatorEventType... types) {
|
public boolean isOfType(@Nonnull CalculatorEventType... types) {
|
||||||
for (CalculatorEventType type : types) {
|
for (CalculatorEventType type : types) {
|
||||||
|
@ -22,11 +22,15 @@
|
|||||||
|
|
||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.AlertDialog;
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.view.ContextMenu;
|
import android.view.ContextMenu;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.squareup.otto.Bus;
|
import com.squareup.otto.Bus;
|
||||||
import com.squareup.otto.Subscribe;
|
import com.squareup.otto.Subscribe;
|
||||||
@ -64,6 +68,8 @@ public class Display implements CalculatorEventListener, View.OnClickListener, V
|
|||||||
Lazy<Clipboard> clipboard;
|
Lazy<Clipboard> clipboard;
|
||||||
@Inject
|
@Inject
|
||||||
Lazy<Notifier> notifier;
|
Lazy<Notifier> notifier;
|
||||||
|
@Inject
|
||||||
|
ActivityLauncher launcher;
|
||||||
@Nullable
|
@Nullable
|
||||||
private DisplayView view;
|
private DisplayView view;
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@ -194,10 +200,24 @@ public class Display implements CalculatorEventListener, View.OnClickListener, V
|
|||||||
v.showContextMenu();
|
v.showContextMenu();
|
||||||
v.setOnCreateContextMenuListener(null);
|
v.setOnCreateContextMenuListener(null);
|
||||||
} else {
|
} 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
|
@Override
|
||||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
|
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
|
||||||
if (!state.valid) {
|
if (!state.valid) {
|
||||||
|
@ -54,6 +54,8 @@ public class Keyboard {
|
|||||||
Lazy<Clipboard> clipboard;
|
Lazy<Clipboard> clipboard;
|
||||||
@Inject
|
@Inject
|
||||||
Lazy<Bus> bus;
|
Lazy<Bus> bus;
|
||||||
|
@Inject
|
||||||
|
ActivityLauncher launcher;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public Keyboard() {
|
public Keyboard() {
|
||||||
@ -119,10 +121,7 @@ public class Keyboard {
|
|||||||
private void onSpecialButtonPressed(@NonNull CppSpecialButton button) {
|
private void onSpecialButtonPressed(@NonNull CppSpecialButton button) {
|
||||||
switch (button) {
|
switch (button) {
|
||||||
case history:
|
case history:
|
||||||
calculator.fireCalculatorEvent(CalculatorEventType.show_history, null);
|
launcher.showHistory();
|
||||||
break;
|
|
||||||
case history_detached:
|
|
||||||
calculator.fireCalculatorEvent(CalculatorEventType.show_history_detached, null);
|
|
||||||
break;
|
break;
|
||||||
case cursor_right:
|
case cursor_right:
|
||||||
moveCursorRight();
|
moveCursorRight();
|
||||||
@ -131,16 +130,13 @@ public class Keyboard {
|
|||||||
moveCursorLeft();
|
moveCursorLeft();
|
||||||
break;
|
break;
|
||||||
case settings:
|
case settings:
|
||||||
calculator.fireCalculatorEvent(CalculatorEventType.show_settings, null);
|
launcher.showSettings();
|
||||||
break;
|
|
||||||
case settings_detached:
|
|
||||||
calculator.fireCalculatorEvent(CalculatorEventType.show_settings_detached, null);
|
|
||||||
break;
|
break;
|
||||||
case settings_widget:
|
case settings_widget:
|
||||||
calculator.fireCalculatorEvent(CalculatorEventType.show_settings_widget, null);
|
launcher.showWidgetSettings();
|
||||||
break;
|
break;
|
||||||
case like:
|
case like:
|
||||||
calculator.fireCalculatorEvent(CalculatorEventType.show_like_dialog, null);
|
launcher.openFacebook();
|
||||||
break;
|
break;
|
||||||
case erase:
|
case erase:
|
||||||
editor.erase();
|
editor.erase();
|
||||||
@ -158,25 +154,16 @@ public class Keyboard {
|
|||||||
clearButtonPressed();
|
clearButtonPressed();
|
||||||
break;
|
break;
|
||||||
case functions:
|
case functions:
|
||||||
calculator.fireCalculatorEvent(CalculatorEventType.show_functions, null);
|
launcher.showFunctions();
|
||||||
break;
|
|
||||||
case functions_detached:
|
|
||||||
calculator.fireCalculatorEvent(CalculatorEventType.show_functions_detached, null);
|
|
||||||
break;
|
break;
|
||||||
case open_app:
|
case open_app:
|
||||||
calculator.fireCalculatorEvent(CalculatorEventType.open_app, null);
|
launcher.openApp();
|
||||||
break;
|
break;
|
||||||
case vars:
|
case vars:
|
||||||
calculator.fireCalculatorEvent(CalculatorEventType.show_vars, null);
|
launcher.showVariables();
|
||||||
break;
|
|
||||||
case vars_detached:
|
|
||||||
calculator.fireCalculatorEvent(CalculatorEventType.show_vars_detached, null);
|
|
||||||
break;
|
break;
|
||||||
case operators:
|
case operators:
|
||||||
calculator.fireCalculatorEvent(CalculatorEventType.show_operators, null);
|
launcher.showOperators();
|
||||||
break;
|
|
||||||
case operators_detached:
|
|
||||||
calculator.fireCalculatorEvent(CalculatorEventType.show_operators_detached, null);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Check.shouldNotHappen();
|
Check.shouldNotHappen();
|
||||||
|
@ -35,7 +35,7 @@ import javax.annotation.Nullable;
|
|||||||
* Date: 9/16/11
|
* Date: 9/16/11
|
||||||
* Time: 11:52 PM
|
* Time: 11:52 PM
|
||||||
*/
|
*/
|
||||||
public class CalculatorAboutActivity extends EmptyActivity {
|
public class AboutActivity extends EmptyActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
@ -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_left;
|
||||||
import static org.solovyev.android.calculator.buttons.CppSpecialButton.cursor_right;
|
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.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 {
|
public enum CppButton {
|
||||||
|
|
||||||
@ -56,18 +51,18 @@ public enum CppButton {
|
|||||||
period(R.id.cpp_button_period, "."),
|
period(R.id.cpp_button_period, "."),
|
||||||
brackets(R.id.cpp_button_round_brackets, "()"),
|
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),
|
settings_widget(R.id.cpp_button_settings_widget, CppSpecialButton.settings_widget),
|
||||||
like(R.id.cpp_button_like, CppSpecialButton.like),
|
like(R.id.cpp_button_like, CppSpecialButton.like),
|
||||||
|
|
||||||
/*last row*/
|
/*last row*/
|
||||||
left(R.id.cpp_button_left, cursor_left),
|
left(R.id.cpp_button_left, cursor_left),
|
||||||
right(R.id.cpp_button_right, cursor_right),
|
right(R.id.cpp_button_right, cursor_right),
|
||||||
vars(R.id.cpp_button_vars, vars_detached),
|
vars(R.id.cpp_button_vars, CppSpecialButton.vars),
|
||||||
functions(R.id.cpp_button_functions, functions_detached),
|
functions(R.id.cpp_button_functions, CppSpecialButton.functions),
|
||||||
operators(R.id.cpp_button_operators, operators_detached),
|
operators(R.id.cpp_button_operators, CppSpecialButton.operators),
|
||||||
app(R.id.cpp_button_app, open_app),
|
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*/
|
/*operations*/
|
||||||
multiplication(R.id.cpp_button_multiplication, "*"),
|
multiplication(R.id.cpp_button_multiplication, "*"),
|
||||||
@ -98,8 +93,8 @@ public enum CppButton {
|
|||||||
this(id, button.action, buttonLong == null ? null : buttonLong.getAction());
|
this(id, button.action, buttonLong == null ? null : buttonLong.getAction());
|
||||||
}
|
}
|
||||||
|
|
||||||
CppButton(int id, @Nonnull CppSpecialButton onClickButton) {
|
CppButton(int id, @Nonnull CppSpecialButton button) {
|
||||||
this(id, onClickButton, null);
|
this(id, button, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
CppButton(int id, @Nonnull String action, @Nullable String actionLong) {
|
CppButton(int id, @Nonnull String action, @Nullable String actionLong) {
|
||||||
|
@ -33,11 +33,9 @@ import javax.annotation.Nullable;
|
|||||||
public enum CppSpecialButton {
|
public enum CppSpecialButton {
|
||||||
|
|
||||||
history("history"),
|
history("history"),
|
||||||
history_detached("history_detached"),
|
|
||||||
cursor_right("▷"),
|
cursor_right("▷"),
|
||||||
cursor_left("◁"),
|
cursor_left("◁"),
|
||||||
settings("settings"),
|
settings("settings"),
|
||||||
settings_detached("settings_detached"),
|
|
||||||
settings_widget("settings_widget"),
|
settings_widget("settings_widget"),
|
||||||
like("like"),
|
like("like"),
|
||||||
erase("erase"),
|
erase("erase"),
|
||||||
@ -46,12 +44,9 @@ public enum CppSpecialButton {
|
|||||||
equals("="),
|
equals("="),
|
||||||
clear("clear"),
|
clear("clear"),
|
||||||
functions("functions"),
|
functions("functions"),
|
||||||
functions_detached("functions_detached"),
|
|
||||||
open_app("open_app"),
|
open_app("open_app"),
|
||||||
vars("vars"),
|
vars("vars"),
|
||||||
vars_detached("vars_detached"),
|
operators("operators");
|
||||||
operators("operators"),
|
|
||||||
operators_detached("operators_detached");
|
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private static Map<String, CppSpecialButton> buttonsByActions = new HashMap<>();
|
private static Map<String, CppSpecialButton> buttonsByActions = new HashMap<>();
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
package org.solovyev.android.calculator.history;
|
package org.solovyev.android.calculator.history;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import org.solovyev.android.calculator.BaseActivity;
|
import org.solovyev.android.calculator.BaseActivity;
|
||||||
import org.solovyev.android.calculator.R;
|
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.history;
|
||||||
import static org.solovyev.android.calculator.CalculatorFragmentType.saved_history;
|
import static org.solovyev.android.calculator.CalculatorFragmentType.saved_history;
|
||||||
|
|
||||||
public class CalculatorHistoryActivity extends BaseActivity {
|
public class HistoryActivity extends BaseActivity {
|
||||||
|
|
||||||
public CalculatorHistoryActivity() {
|
public HistoryActivity() {
|
||||||
super(R.layout.main_empty, CalculatorHistoryActivity.class.getSimpleName());
|
super(R.layout.main_empty, HistoryActivity.class.getSimpleName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
Loading…
Reference in New Issue
Block a user