Error in case of loading user data (functions, vars etc)

This commit is contained in:
Sergey Solovyev 2013-01-20 14:51:36 +04:00
parent 3ef91d7020
commit 373d7d9c16
26 changed files with 559 additions and 125 deletions

View File

@ -320,6 +320,7 @@
<string name="cpp_invalid_number">Invalid number!</string>
<string name="cpp_plot_boundaries_should_differ">Graph boundaries should not be the same!</string>
<string name="cpp_apply">Apply</string>
<string name="cpp_message">Message</string>
</resources>

View File

@ -0,0 +1,105 @@
package org.solovyev.android.calculator;
import android.os.Parcel;
import android.os.Parcelable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.common.msg.MessageType;
/**
* User: serso
* Date: 1/20/13
* Time: 1:04 PM
*/
public final class ParcelableDialogData implements DialogData, Parcelable {
/*
**********************************************************************
*
* STATIC
*
**********************************************************************
*/
public final static Creator<ParcelableDialogData> CREATOR = new Creator<ParcelableDialogData>() {
@Override
public ParcelableDialogData createFromParcel(@NotNull Parcel in) {
return fromParcel(in);
}
@Override
public ParcelableDialogData[] newArray(int size) {
return new ParcelableDialogData[size];
}
};
/*
**********************************************************************
*
* FIELDS
*
**********************************************************************
*/
@NotNull
private DialogData nestedData;
/*
**********************************************************************
*
* CONSTRUCTORS
*
**********************************************************************
*/
public ParcelableDialogData(@NotNull DialogData nestedData) {
this.nestedData = nestedData;
}
@NotNull
public static ParcelableDialogData wrap(@NotNull DialogData nestedData) {
if (nestedData instanceof ParcelableDialogData) {
return ((ParcelableDialogData) nestedData);
} else {
return new ParcelableDialogData(nestedData);
}
}
@NotNull
public static ParcelableDialogData fromParcel(@NotNull Parcel in) {
final String message = in.readString();
final MessageType messageType = MessageType.values()[in.readInt()];
final String title = in.readString();
return wrap(StringDialogData.newInstance(message, messageType, title));
}
@NotNull
@Override
public String getMessage() {
return nestedData.getMessage();
}
@NotNull
@Override
public MessageType getMessageType() {
return nestedData.getMessageType();
}
@Nullable
@Override
public String getTitle() {
return nestedData.getTitle();
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(@NotNull Parcel out, int flags) {
out.writeString(this.getMessage());
out.writeInt(this.getMessageType().ordinal());
out.writeString(this.getTitle());
}
}

View File

@ -57,6 +57,8 @@
<activity android:launchMode="singleTop" android:label="@string/cpp_plot_function_settings" android:name=".plot.CalculatorPlotFunctionSettingsActivity" android:theme="@style/cpp_gray_dialog_theme"/>
<activity android:launchMode="singleTop" android:label="@string/cpp_plot_range" android:name=".plot.CalculatorPlotRangeActivity" android:theme="@style/cpp_gray_dialog_theme"/>
<activity android:launchMode="singleTop" android:name=".CalculatorDialogActivity" android:theme="@style/cpp_gray_dialog_theme"/>
<!-- todo serso: strings-->
<activity android:label="@string/c_plot_graph" android:name=".matrix.CalculatorMatrixActivity"/>

View File

@ -12,19 +12,19 @@ target=android-15
android.library.reference.1=../android-app-core
android.library.reference.2=../android-app-widget
android.library.reference.3=../android-app-onscreen
android.library.reference.4=../android-app-core/gen-external-apklibs/org.solovyev.android_android-common-all_1.0.6
android.library.reference.5=../android-app-core/gen-external-apklibs/org.solovyev.android_android-common-ads_1.0.6
android.library.reference.6=../android-app-core/gen-external-apklibs/org.solovyev.android_android-common-core_1.0.6
android.library.reference.7=../android-app-core/gen-external-apklibs/org.solovyev.android_android-common-billing_1.0.6
android.library.reference.8=../android-app-core/gen-external-apklibs/org.solovyev.android_android-common-db_1.0.6
android.library.reference.9=../android-app-core/gen-external-apklibs/org.solovyev.android_android-common-http_1.0.6
android.library.reference.10=../android-app-core/gen-external-apklibs/org.solovyev.android_android-common-list_1.0.6
android.library.reference.11=../android-app-core/gen-external-apklibs/org.solovyev.android_android-common-view_1.0.6
android.library.reference.12=../android-app-core/gen-external-apklibs/org.solovyev.android_android-common-preferences_1.0.6
android.library.reference.13=../android-app-core/gen-external-apklibs/org.solovyev.android_android-common-menu_1.0.6
android.library.reference.14=../android-app-core/gen-external-apklibs/org.solovyev.android_android-common-other_1.0.6
android.library.reference.15=../android-app-core/gen-external-apklibs/org.solovyev.android_android-common-sherlock_1.0.6
android.library.reference.16=../android-app-core/gen-external-apklibs/com.actionbarsherlock_actionbarsherlock_4.2.0
android.library.reference.17=../android-app-core/gen-external-apklibs/org.solovyev.android_android-common-keyboard_1.0.6
android.library.reference.4=gen-external-apklibs/org.solovyev.android_android-common-all_1.0.6
android.library.reference.5=gen-external-apklibs/org.solovyev.android_android-common-ads_1.0.6
android.library.reference.6=gen-external-apklibs/org.solovyev.android_android-common-core_1.0.6
android.library.reference.7=gen-external-apklibs/org.solovyev.android_android-common-billing_1.0.6
android.library.reference.8=gen-external-apklibs/org.solovyev.android_android-common-db_1.0.6
android.library.reference.9=gen-external-apklibs/org.solovyev.android_android-common-http_1.0.6
android.library.reference.10=gen-external-apklibs/org.solovyev.android_android-common-list_1.0.6
android.library.reference.11=gen-external-apklibs/org.solovyev.android_android-common-view_1.0.6
android.library.reference.12=gen-external-apklibs/org.solovyev.android_android-common-preferences_1.0.6
android.library.reference.13=gen-external-apklibs/org.solovyev.android_android-common-menu_1.0.6
android.library.reference.14=gen-external-apklibs/org.solovyev.android_android-common-other_1.0.6
android.library.reference.15=gen-external-apklibs/org.solovyev.android_android-common-sherlock_1.0.6
android.library.reference.16=gen-external-apklibs/com.actionbarsherlock_actionbarsherlock_4.2.0
android.library.reference.17=gen-external-apklibs/org.solovyev.android_android-common-keyboard_1.0.6

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/main_fragment_layout"
style="?cpp_fragment_layout_style"
a:layout_width="match_parent"
a:layout_gravity="center_horizontal"
a:layout_height="match_parent"
a:orientation="vertical">
<TextView
a:id="@+id/cpp_dialog_message_textview"
a:layout_width="match_parent"
a:layout_height="wrap_content" />
<LinearLayout
a:layout_width="match_parent"
a:layout_height="wrap_content"
a:orientation="horizontal">
<Button
a:id="@+id/cpp_copy_button"
a:text="@string/c_copy"
a:layout_width="0dp"
a:layout_height="wrap_content"
a:layout_weight="1"
a:visibility="gone" />
<Button
a:id="@+id/cpp_ok_button"
a:text="@string/ok"
a:layout_width="0dp"
a:layout_height="wrap_content"
a:layout_weight="1" />
</LinearLayout>
</LinearLayout>

View File

@ -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);
}
}

View File

@ -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;
}
}

View File

@ -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!");
}

View File

@ -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();
}
});
}
}
}

View File

@ -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),

View File

@ -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();
}
}
}

View File

@ -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";
}

View File

@ -11,8 +11,8 @@ import org.jetbrains.annotations.Nullable;
import org.solovyev.common.JBuilder;
import org.solovyev.common.math.MathEntity;
import org.solovyev.common.math.MathRegistry;
import org.solovyev.common.msg.Message;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -64,32 +64,40 @@ public abstract class AbstractCalculatorMathRegistry<T extends MathEntity, P ext
public synchronized void load() {
final MathEntityPersistenceContainer<P> persistenceContainer = mathEntityDao.load();
final List<P> notCreatedEntities = new ArrayList<P>();
if (persistenceContainer != null) {
for (P entity : persistenceContainer.getEntities()) {
if (!contains(entity.getName())) {
try {
final JBuilder<? extends T> builder = createBuilder(entity);
add(builder);
} catch (ArithmeticException e) {
} catch (RuntimeException e) {
Locator.getInstance().getLogger().error(null, e.getLocalizedMessage(), e);
if (e instanceof Message) {
Locator.getInstance().getNotifier().showMessage((Message)e);
}
notCreatedEntities.add(entity);
}
}
}
}
/*Log.d(AndroidVarsRegistry.class.getName(), vars.size() + " variables registered!");
for (Var var : vars) {
Log.d(AndroidVarsRegistry.class.getName(), var.toString());
}*/
try {
if (!notCreatedEntities.isEmpty()) {
final StringBuilder errorMessage = new StringBuilder(notCreatedEntities.size() * 100);
for (P notCreatedEntity : notCreatedEntities) {
errorMessage.append(notCreatedEntity).append("\n\n");
}
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_message_dialog, MessageDialogData.newInstance(CalculatorMessages.newErrorMessage(CalculatorMessages.msg_007, errorMessage.toString()), null));
}
} catch (RuntimeException e) {
// just in case
Locator.getInstance().getLogger().error(null, e.getLocalizedMessage(), e);
}
}
@NotNull
protected abstract JBuilder<? extends T> createBuilder(@NotNull P entity);
@Override
public synchronized void save() {
final MathEntityPersistenceContainer<P> container = createPersistenceContainer();

View File

@ -159,6 +159,9 @@ public enum CalculatorEventType {
show_create_matrix_dialog,
show_create_function_dialog,
/** {@link DialogData} */
show_message_dialog,
plot_graph,
/** {@link org.solovyev.android.calculator.plot.PlotData} */

View File

@ -12,6 +12,7 @@ import jscl.math.function.Function;
import jscl.math.function.IFunction;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.function.FunctionBuilderAdapter;
import org.solovyev.android.calculator.model.AFunction;
import org.solovyev.android.calculator.model.Functions;
import org.solovyev.android.calculator.model.MathEntityBuilder;
@ -46,20 +47,20 @@ public class CalculatorFunctionsMathRegistry extends AbstractCalculatorMathRegis
@Override
public void load() {
super.load();
add(new CustomFunction.Builder(true, "log", Arrays.asList("base", "x"), "ln(x)/ln(base)"));
add(new CustomFunction.Builder(true, "√3", Arrays.asList("x"), "x^(1/3)"));
add(new CustomFunction.Builder(true, "√4", Arrays.asList("x"), "x^(1/4)"));
add(new CustomFunction.Builder(true, "√n", Arrays.asList("x", "n"), "x^(1/n)"));
add(new CustomFunction.Builder(true, "re", Arrays.asList("x"), "(x+conjugate(x))/2"));
add(new CustomFunction.Builder(true, "im", Arrays.asList("x"), "(x-conjugate(x))/(2*i)"));
super.load();
}
public static void saveFunction(@NotNull CalculatorMathRegistry<Function> registry,
@NotNull MathEntityBuilder<? extends Function> builder,
@Nullable IFunction editedInstance,
@NotNull Object source, boolean save) throws CustomFunctionCalculationException {
@NotNull Object source, boolean save) throws CustomFunctionCalculationException, AFunction.Builder.CreationException {
final Function addedFunction = registry.add(builder);
if (save) {
@ -111,7 +112,7 @@ public class CalculatorFunctionsMathRegistry extends AbstractCalculatorMathRegis
@NotNull
@Override
protected JBuilder<? extends Function> createBuilder(@NotNull AFunction function) {
return new CustomFunction.Builder(function);
return new FunctionBuilderAdapter(new AFunction.Builder(function));
}
@Override

View File

@ -16,4 +16,6 @@ public interface CalculatorLogger {
void error(@Nullable String tag, @Nullable String message, @NotNull Throwable e);
void error(@Nullable String tag, @Nullable String message);
}

View File

@ -1,6 +1,8 @@
package org.solovyev.android.calculator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.common.msg.MessageType;
import java.util.Locale;
import java.util.ResourceBundle;
@ -45,12 +47,23 @@ public final class CalculatorMessages {
/* Infinite loop is detected in expression*/
public static final String msg_006 = "msg_6";
/** Some data could not be loaded. Contact authors of application with information below.\n\nUnable to load:\n{0} */
public static final String msg_007 = "msg_7";
/* Error */
public static final String syntax_error = "syntax_error";
/* Result copied to clipboard! */
public static final String result_copied = "result_copied";
/* Text copied to clipboard! */
public static final String text_copied = "text_copied";
/* Last calculated value */
public static final String ans_description = "ans_description";
@NotNull
public static CalculatorMessage newErrorMessage(@NotNull String messageCode, @Nullable Object... parameters ) {
return new CalculatorMessage(messageCode, MessageType.error, parameters);
}
}

View File

@ -0,0 +1,22 @@
package org.solovyev.android.calculator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.common.msg.MessageType;
/**
* User: serso
* Date: 1/20/13
* Time: 12:47 PM
*/
public interface DialogData {
@NotNull
String getMessage();
@NotNull
MessageType getMessageType();
@Nullable
String getTitle();
}

View File

@ -0,0 +1,48 @@
package org.solovyev.android.calculator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.common.msg.Message;
import org.solovyev.common.msg.MessageType;
/**
* User: serso
* Date: 1/20/13
* Time: 12:45 PM
*/
public class MessageDialogData implements DialogData {
@NotNull
private Message message;
@Nullable
private String title;
private MessageDialogData(@NotNull Message message, @Nullable String title) {
this.message = message;
this.title = title;
}
@NotNull
public static DialogData newInstance(@NotNull Message message, @Nullable String title) {
return new MessageDialogData(message, title);
}
@Override
@NotNull
public String getMessage() {
return message.getLocalizedMessage();
}
@NotNull
@Override
public MessageType getMessageType() {
return message.getMessageType();
}
@Override
@Nullable
public String getTitle() {
return title;
}
}

View File

@ -0,0 +1,51 @@
package org.solovyev.android.calculator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.common.msg.MessageType;
/**
* User: serso
* Date: 1/20/13
* Time: 1:01 PM
*/
public class StringDialogData implements DialogData {
@NotNull
private final String message;
@NotNull
private final MessageType messageType;
@Nullable
private final String title;
private StringDialogData(@NotNull String message, @NotNull MessageType messageType, @Nullable String title) {
this.message = message;
this.messageType = messageType;
this.title = title;
}
@NotNull
public static DialogData newInstance(@NotNull String message, @NotNull MessageType messageType, @Nullable String title) {
return new StringDialogData(message, messageType, title);
}
@NotNull
@Override
public String getMessage() {
return message;
}
@NotNull
@Override
public MessageType getMessageType() {
return messageType;
}
@Nullable
@Override
public String getTitle() {
return title;
}
}

View File

@ -34,4 +34,9 @@ public class SystemOutCalculatorLogger implements CalculatorLogger {
System.out.println(getTag(tag) + ": " + message);
e.printStackTrace(System.out);
}
@Override
public void error(@Nullable String tag, @Nullable String message) {
System.out.println(getTag(tag) + ": " + message);
}
}

View File

@ -0,0 +1,52 @@
package org.solovyev.android.calculator.function;
import jscl.CustomFunctionCalculationException;
import jscl.math.function.CustomFunction;
import jscl.math.function.Function;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.model.AFunction;
import org.solovyev.android.calculator.model.MathEntityBuilder;
/**
* User: serso
* Date: 1/20/13
* Time: 12:21 PM
*/
public final class FunctionBuilderAdapter implements MathEntityBuilder<Function> {
@NotNull
private final AFunction.Builder nestedBuilder;
public FunctionBuilderAdapter(@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() throws CustomFunctionCalculationException, AFunction.Builder.CreationException{
final AFunction function = nestedBuilder.create();
return new CustomFunction.Builder(function).create();
}
}

View File

@ -13,8 +13,8 @@ import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;
import org.simpleframework.xml.Transient;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.CalculatorParseException;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.MathPersistenceEntity;
import org.solovyev.common.math.MathEntity;
import org.solovyev.common.msg.Message;
@ -122,6 +122,15 @@ public class AFunction implements IFunction, MathPersistenceEntity, Serializable
return String.valueOf(this.content);
}
@Override
public String toString() {
return "AFunction{" +
"name='" + name + '\'' +
", parameterNames=" + parameterNames +
", content='" + content + '\'' +
'}';
}
/*
**********************************************************************
*
@ -258,7 +267,7 @@ public class AFunction implements IFunction, MathPersistenceEntity, Serializable
}
@NotNull
public AFunction create() {
public AFunction create() throws AFunction.Builder.CreationException{
final AFunction result;
if (id != null) {
result = new AFunction(id);

View File

@ -250,4 +250,5 @@ public class Var implements IConstant, MathPersistenceEntity {
public int hashCode() {
return name.hashCode();
}
}

View File

@ -4,7 +4,9 @@ msg_3=Too long execution time - check the expression
msg_4=Evaluation was cancelled
msg_5=No parameters are specified for function: {0}
msg_6=Infinite loop is detected in expression
msg_7=Some user data could not be loaded. Please contact authors of application with information below.\n\nUnable to load:\n{0}
syntax_error=Error
result_copied=Result copied to clipboard!
text_copied=Text copied to clipboard!
ans_description=Last calculated value

View File

@ -4,7 +4,10 @@ msg_3=Вычисление выражения занимает слишком м
msg_4=Вычисление было отменено
msg_5=Для функции {0} не определены параметры
msg_6=В выражении найден Бесконечный цикл - проверьте выражение
msg_7=Некоторые пользовательские данные не могут быть загружены. Пожалуйста, свяжитесь с авторами приложения с информацией ниже.\n\nНевозможно загрузить:\n{0}
syntax_error=Ошибка
result_copied=Результат скопирован в буфер!
text_copied=Текст скопирован в буфер!
ans_description=Последний посчитанный результат