Error in case of loading user data (functions, vars etc)
This commit is contained in:
@@ -33,4 +33,9 @@ public class AndroidCalculatorLogger implements CalculatorLogger {
|
||||
public void error(@Nullable String tag, @Nullable String message, @NotNull Throwable e) {
|
||||
Log.e(getTag(tag), message, e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(@Nullable String tag, @Nullable String message) {
|
||||
Log.e(getTag(tag), message);
|
||||
}
|
||||
}
|
||||
|
@@ -244,6 +244,18 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener
|
||||
});
|
||||
}
|
||||
break;
|
||||
case show_message_dialog:
|
||||
final DialogData dialogData = (DialogData) data;
|
||||
if (dialogData != null) {
|
||||
App.getInstance().getUiThreadExecutor().execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
CalculatorDialogActivity.showDialog(context, dialogData);
|
||||
}
|
||||
});
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -124,6 +124,11 @@ public class CalculatorApplication extends android.app.Application implements Sh
|
||||
new AndroidExternalListenersContainer(calculator),
|
||||
new AndroidCalculatorPlotter(this, new CalculatorPlotterImpl(calculator)));
|
||||
|
||||
listeners.add(new CalculatorActivityLauncher());
|
||||
for (CalculatorEventListener listener : listeners) {
|
||||
calculator.addCalculatorEventListener(listener);
|
||||
}
|
||||
|
||||
Locator.getInstance().getCalculator().init();
|
||||
|
||||
BillingDB.init(CalculatorApplication.this);
|
||||
@@ -161,12 +166,6 @@ public class CalculatorApplication extends android.app.Application implements Sh
|
||||
}
|
||||
}).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!");
|
||||
}
|
||||
|
@@ -0,0 +1,126 @@
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.AndroidUtils2;
|
||||
import org.solovyev.android.fragments.FragmentUtils;
|
||||
import org.solovyev.common.msg.MessageType;
|
||||
import org.solovyev.common.text.StringUtils;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 1/20/13
|
||||
* Time: 12:50 PM
|
||||
*/
|
||||
public class CalculatorDialogActivity extends SherlockFragmentActivity {
|
||||
|
||||
@NotNull
|
||||
private static final String TAG = CalculatorDialogActivity.class.getSimpleName();
|
||||
|
||||
@NotNull
|
||||
private static final String DIALOG_DATA_EXTRA = "dialog_data";
|
||||
|
||||
public static void showDialog(@NotNull Context context, @NotNull DialogData dialogData) {
|
||||
final Intent intent = new Intent();
|
||||
intent.setClass(context, CalculatorDialogActivity.class);
|
||||
intent.putExtra(DIALOG_DATA_EXTRA, ParcelableDialogData.wrap(dialogData));
|
||||
AndroidUtils2.addFlags(intent, false, context);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle in) {
|
||||
super.onCreate(in);
|
||||
|
||||
final DialogData dialogData = readDialogData(getIntent());
|
||||
if ( dialogData == null ) {
|
||||
Locator.getInstance().getLogger().error(TAG, "Dialog data is null!");
|
||||
this.finish();
|
||||
} else {
|
||||
setContentView(R.layout.cpp_dialog);
|
||||
|
||||
final String title = dialogData.getTitle();
|
||||
if (!StringUtils.isEmpty(title)) {
|
||||
setTitle(title);
|
||||
}
|
||||
|
||||
|
||||
final Bundle args = new Bundle();
|
||||
args.putParcelable(DIALOG_DATA_EXTRA, ParcelableDialogData.wrap(dialogData));
|
||||
FragmentUtils.createFragment(this, CalculatorDialogFragment.class, R.id.dialog_layout, "dialog", args);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static DialogData readDialogData(@Nullable Intent in) {
|
||||
if ( in != null ) {
|
||||
final Parcelable parcelable = in.getParcelableExtra(DIALOG_DATA_EXTRA);
|
||||
if ( parcelable instanceof DialogData ) {
|
||||
return (DialogData) parcelable;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static DialogData readDialogData(@Nullable Bundle in) {
|
||||
if ( in != null ) {
|
||||
final Parcelable parcelable = in.getParcelable(DIALOG_DATA_EXTRA);
|
||||
if ( parcelable instanceof DialogData ) {
|
||||
return (DialogData) parcelable;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class CalculatorDialogFragment extends CalculatorFragment {
|
||||
|
||||
public CalculatorDialogFragment() {
|
||||
super(CalculatorFragmentType.dialog);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NotNull View root, Bundle savedInstanceState) {
|
||||
super.onViewCreated(root, savedInstanceState);
|
||||
|
||||
final DialogData dialogData = readDialogData(getArguments());
|
||||
|
||||
if (dialogData != null) {
|
||||
final TextView messageTextView = (TextView) root.findViewById(R.id.cpp_dialog_message_textview);
|
||||
messageTextView.setText(dialogData.getMessage());
|
||||
|
||||
if ( dialogData.getMessageType() == MessageType.error || dialogData.getMessageType() == MessageType.warning ) {
|
||||
final Button copyButton = (Button) root.findViewById(R.id.cpp_copy_button);
|
||||
copyButton.setVisibility(View.VISIBLE);
|
||||
copyButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Locator.getInstance().getClipboard().setText(dialogData.getMessage());
|
||||
Locator.getInstance().getNotifier().showMessage(CalculatorMessage.newInfoMessage(CalculatorMessages.text_copied));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
root.findViewById(R.id.cpp_ok_button).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
getActivity().finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -13,10 +13,7 @@ import org.solovyev.android.calculator.math.edit.CalculatorFunctionsFragment;
|
||||
import org.solovyev.android.calculator.math.edit.CalculatorOperatorsFragment;
|
||||
import org.solovyev.android.calculator.math.edit.CalculatorVarsFragment;
|
||||
import org.solovyev.android.calculator.matrix.CalculatorMatrixEditFragment;
|
||||
import org.solovyev.android.calculator.plot.CalculatorPlotFragment;
|
||||
import org.solovyev.android.calculator.plot.CalculatorPlotFunctionSettingsActivity;
|
||||
import org.solovyev.android.calculator.plot.CalculatorPlotFunctionsActivity;
|
||||
import org.solovyev.android.calculator.plot.CalculatorPlotRangeActivity;
|
||||
import org.solovyev.android.calculator.plot.*;
|
||||
|
||||
/**
|
||||
* User: Solovyev_S
|
||||
@@ -38,6 +35,8 @@ public enum CalculatorFragmentType {
|
||||
plotter_function_settings(CalculatorPlotFunctionSettingsActivity.CalculatorPlotFunctionSettingsFragment.class, R.layout.cpp_plot_function_settings_fragment, R.string.cpp_plot_function_settings),
|
||||
plotter_range(CalculatorPlotRangeActivity.CalculatorPlotRangeFragment.class, R.layout.cpp_plot_range_fragment, R.string.cpp_plot_range),
|
||||
|
||||
dialog(CalculatorDialogActivity.CalculatorDialogFragment.class, R.layout.cpp_dialog_fragment, R.string.cpp_message),
|
||||
|
||||
about(CalculatorAboutFragment.class, R.layout.about_fragment, R.string.c_about),
|
||||
faq(CalculatorHelpFaqFragment.class, R.layout.help_faq_fragment, R.string.c_faq),
|
||||
hints(CalculatorHelpHintsFragment.class, R.layout.help_hints_fragment, R.string.c_hints),
|
||||
|
@@ -3,7 +3,6 @@ package org.solovyev.android.calculator.function;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import jscl.CustomFunctionCalculationException;
|
||||
import jscl.math.function.CustomFunction;
|
||||
import jscl.math.function.Function;
|
||||
import jscl.math.function.IFunction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -14,7 +13,6 @@ import org.solovyev.android.calculator.CalculatorMathRegistry;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.math.edit.VarEditorSaver;
|
||||
import org.solovyev.android.calculator.model.AFunction;
|
||||
import org.solovyev.android.calculator.model.MathEntityBuilder;
|
||||
import org.solovyev.common.msg.MessageType;
|
||||
import org.solovyev.common.text.StringUtils;
|
||||
|
||||
@@ -104,7 +102,7 @@ public class FunctionEditorSaver implements View.OnClickListener {
|
||||
Locator.getInstance().getNotifier().showMessage(error, MessageType.error);
|
||||
} else {
|
||||
try {
|
||||
CalculatorFunctionsMathRegistry.saveFunction(mathRegistry, new BuilderAdapter(builder), editedInstance, source, true);
|
||||
CalculatorFunctionsMathRegistry.saveFunction(mathRegistry, new FunctionBuilderAdapter(builder), editedInstance, source, true);
|
||||
} catch (CustomFunctionCalculationException e) {
|
||||
Locator.getInstance().getNotifier().showMessage(e);
|
||||
} catch (AFunction.Builder.CreationException e) {
|
||||
@@ -140,41 +138,4 @@ public class FunctionEditorSaver implements View.OnClickListener {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static final class BuilderAdapter implements MathEntityBuilder<Function> {
|
||||
|
||||
@NotNull
|
||||
private final AFunction.Builder nestedBuilder;
|
||||
|
||||
public BuilderAdapter(@NotNull AFunction.Builder nestedBuilder) {
|
||||
this.nestedBuilder = nestedBuilder;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public MathEntityBuilder<Function> setName(@NotNull String name) {
|
||||
nestedBuilder.setName(name);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public MathEntityBuilder<Function> setDescription(@Nullable String description) {
|
||||
nestedBuilder.setDescription(description);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public MathEntityBuilder<Function> setValue(@Nullable String value) {
|
||||
nestedBuilder.setValue(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Function create() {
|
||||
final AFunction function = nestedBuilder.create();
|
||||
return new CustomFunction.Builder(function).create();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,34 +0,0 @@
|
||||
package org.solovyev.android.calculator.model;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 11/25/11
|
||||
* Time: 1:40 PM
|
||||
*/
|
||||
public final class Messages {
|
||||
|
||||
|
||||
// not intended for instantiation
|
||||
private Messages() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
/** Arithmetic error occurred: {0} */
|
||||
public static final String msg_1 = "msg_1";
|
||||
|
||||
/** Too complex expression */
|
||||
public static final String msg_2 = "msg_2";
|
||||
|
||||
/** Too long execution time - check the expression */
|
||||
public static final String msg_3 = "msg_3";
|
||||
|
||||
/** Evaluation was cancelled */
|
||||
public static final String msg_4 = "msg_4";
|
||||
|
||||
/** No parameters are specified for function: {0} */
|
||||
public static final String msg_5 = "msg_5";
|
||||
|
||||
/** Infinite loop is detected in expression */
|
||||
public static final String msg_6 = "msg_6";
|
||||
|
||||
}
|
Reference in New Issue
Block a user