diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 8ac9c420..1624bd8a 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -56,7 +56,11 @@
+ android:label="@string/cpp_settings">
+
+
+
+
ArrayAdapter makeSimpleSpinnerAdapter(@NonNull Context context) {
+ return new ArrayAdapter<>(context, R.layout.support_simple_spinner_dropdown_item);
+ }
+
public interface ViewProcessor {
void process(@Nonnull V view);
}
diff --git a/app/src/main/java/org/solovyev/android/calculator/Engine.java b/app/src/main/java/org/solovyev/android/calculator/Engine.java
index 244881f9..36ceb743 100644
--- a/app/src/main/java/org/solovyev/android/calculator/Engine.java
+++ b/app/src/main/java/org/solovyev/android/calculator/Engine.java
@@ -23,15 +23,11 @@
package org.solovyev.android.calculator;
import android.content.SharedPreferences;
+import android.support.annotation.StringRes;
import android.text.TextUtils;
+
import com.squareup.otto.Bus;
-import jscl.AngleUnit;
-import jscl.JsclMathEngine;
-import jscl.MathEngine;
-import jscl.NumeralBase;
-import jscl.math.operator.Operator;
-import jscl.text.Identifier;
-import jscl.text.Parser;
+
import org.solovyev.android.Check;
import org.solovyev.android.calculator.functions.FunctionsRegistry;
import org.solovyev.android.calculator.operators.OperatorsRegistry;
@@ -43,15 +39,25 @@ import org.solovyev.android.prefs.StringPreference;
import org.solovyev.common.text.EnumMapper;
import org.solovyev.common.text.NumberMapper;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import javax.inject.Inject;
-import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Executor;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import jscl.AngleUnit;
+import jscl.JsclMathEngine;
+import jscl.MathEngine;
+import jscl.NumeralBase;
+import jscl.math.operator.Operator;
+import jscl.text.Identifier;
+import jscl.text.Parser;
+import midpcalc.Real;
+
@Singleton
public class Engine implements SharedPreferences.OnSharedPreferenceChangeListener {
@@ -231,8 +237,24 @@ public class Engine implements SharedPreferences.OnSharedPreferenceChangeListene
}
}
+ public enum Notation {
+ simple(Real.NumberFormat.FSE_NONE, R.string.cpp_number_format_simple),
+ eng(Real.NumberFormat.FSE_ENG, R.string.cpp_number_format_eng),
+ sci(Real.NumberFormat.FSE_SCI, R.string.cpp_number_format_sci);
+
+ public final int id;
+ @StringRes
+ public final int name;
+
+ Notation(int id, @StringRes int name) {
+ this.id = id;
+ this.name = name;
+ }
+ }
+
public static class ChangedEvent {
static final ChangedEvent INSTANCE = new ChangedEvent();
+
private ChangedEvent() {
}
}
@@ -264,6 +286,7 @@ public class Engine implements SharedPreferences.OnSharedPreferenceChangeListene
public static final StringPreference precision = StringPreference.ofTypedValue("engine.output.precision", "5", NumberMapper.of(Integer.class));
public static final BooleanPreference scientificNotation = BooleanPreference.of("engine.output.scientificNotation", false);
public static final BooleanPreference round = BooleanPreference.of("engine.output.round", true);
+ public static final StringPreference notation = StringPreference.ofEnum("engine.output.notation", Notation.simple, Notation.class);
}
}
}
diff --git a/app/src/main/java/org/solovyev/android/calculator/converter/ConverterFragment.java b/app/src/main/java/org/solovyev/android/calculator/converter/ConverterFragment.java
index c69ec60b..448a6b8d 100644
--- a/app/src/main/java/org/solovyev/android/calculator/converter/ConverterFragment.java
+++ b/app/src/main/java/org/solovyev/android/calculator/converter/ConverterFragment.java
@@ -21,21 +21,38 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
-import android.widget.*;
-import butterknife.Bind;
-import butterknife.ButterKnife;
-import org.solovyev.android.calculator.*;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.EditText;
+import android.widget.ImageButton;
+import android.widget.Spinner;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import org.solovyev.android.calculator.App;
+import org.solovyev.android.calculator.AppComponent;
+import org.solovyev.android.calculator.AppModule;
+import org.solovyev.android.calculator.BaseDialogFragment;
+import org.solovyev.android.calculator.Clipboard;
+import org.solovyev.android.calculator.Editor;
+import org.solovyev.android.calculator.Keyboard;
+import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.keyboard.FloatingKeyboard;
import org.solovyev.android.calculator.keyboard.FloatingKeyboardWindow;
import org.solovyev.android.calculator.keyboard.FloatingNumberKeyboard;
import org.solovyev.android.calculator.math.MathUtils;
+import org.solovyev.android.calculator.text.NaturalComparator;
import org.solovyev.android.calculator.view.EditTextCompat;
import javax.annotation.Nonnull;
import javax.inject.Inject;
-import java.util.Comparator;
-import static org.solovyev.android.calculator.UiPreferences.Converter.*;
+import butterknife.Bind;
+import butterknife.ButterKnife;
+
+import static org.solovyev.android.calculator.UiPreferences.Converter.lastDimension;
+import static org.solovyev.android.calculator.UiPreferences.Converter.lastUnitsFrom;
+import static org.solovyev.android.calculator.UiPreferences.Converter.lastUnitsTo;
public class ConverterFragment extends BaseDialogFragment
implements AdapterView.OnItemSelectedListener, View.OnFocusChangeListener, TextView.OnEditorActionListener, View.OnClickListener, TextWatcher {
@@ -44,7 +61,6 @@ public class ConverterFragment extends BaseDialogFragment
private static final String STATE_SELECTION_FROM = "selection.from";
private static final String STATE_SELECTION_TO = "selection.to";
private static final String EXTRA_VALUE = "value";
- private static final NamedItemComparator COMPARATOR = new NamedItemComparator();
public static final int NONE = -1;
@NonNull
@@ -96,11 +112,6 @@ public class ConverterFragment extends BaseDialogFragment
App.showDialog(fragment, "converter", activity.getSupportFragmentManager());
}
- @Nonnull
- private static ArrayAdapter makeAdapter(@NonNull Context context) {
- return new ArrayAdapter<>(context, R.layout.support_simple_spinner_dropdown_item);
- }
-
@NonNull
@Override
public AlertDialog onCreateDialog(@Nullable Bundle savedInstanceState) {
@@ -130,13 +141,13 @@ public class ConverterFragment extends BaseDialogFragment
final View view = inflater.inflate(R.layout.cpp_unit_converter, null);
ButterKnife.bind(this, view);
- dimensionsAdapter = makeAdapter(context);
+ dimensionsAdapter = App.makeSimpleSpinnerAdapter(context);
for (ConvertibleDimension dimension : UnitDimension.values()) {
dimensionsAdapter.add(dimension.named(context));
}
dimensionsAdapter.add(NumeralBaseDimension.get().named(context));
- adapterFrom = makeAdapter(context);
- adapterTo = makeAdapter(context);
+ adapterFrom = App.makeSimpleSpinnerAdapter(context);
+ adapterTo = App.makeSimpleSpinnerAdapter(context);
dimensionsSpinner.setAdapter(dimensionsAdapter);
spinnerFrom.setAdapter(adapterFrom);
@@ -235,7 +246,7 @@ public class ConverterFragment extends BaseDialogFragment
for (Convertible unit : dimension.getUnits()) {
adapterFrom.add(unit.named(getActivity()));
}
- adapterFrom.sort(COMPARATOR);
+ adapterFrom.sort(NaturalComparator.INSTANCE);
adapterFrom.setNotifyOnChange(true);
adapterFrom.notifyDataSetChanged();
if (pendingFromSelection != NONE) {
@@ -261,7 +272,7 @@ public class ConverterFragment extends BaseDialogFragment
adapterTo.add(unit.named(getActivity()));
}
}
- adapterTo.sort(COMPARATOR);
+ adapterTo.sort(NaturalComparator.INSTANCE);
adapterTo.setNotifyOnChange(true);
adapterTo.notifyDataSetChanged();
if (selectedUnit != null && !except.equals(selectedUnit)) {
@@ -431,13 +442,6 @@ public class ConverterFragment extends BaseDialogFragment
super.dismiss();
}
- private static class NamedItemComparator implements Comparator> {
- @Override
- public int compare(Named lhs, Named rhs) {
- return lhs.toString().compareTo(rhs.toString());
- }
- }
-
private class KeyboardUser implements FloatingKeyboard.User {
@NonNull
@Override
diff --git a/app/src/main/java/org/solovyev/android/calculator/preferences/NumberFormatPreference.java b/app/src/main/java/org/solovyev/android/calculator/preferences/NumberFormatPreference.java
new file mode 100644
index 00000000..2edb24db
--- /dev/null
+++ b/app/src/main/java/org/solovyev/android/calculator/preferences/NumberFormatPreference.java
@@ -0,0 +1,100 @@
+package org.solovyev.android.calculator.preferences;
+
+import android.annotation.TargetApi;
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.os.Build;
+import android.preference.DialogPreference;
+import android.support.annotation.NonNull;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.ArrayAdapter;
+import android.widget.SeekBar;
+import android.widget.Spinner;
+
+import org.solovyev.android.calculator.App;
+import org.solovyev.android.calculator.Engine;
+import org.solovyev.android.calculator.R;
+import org.solovyev.android.calculator.text.NaturalComparator;
+
+import butterknife.Bind;
+import butterknife.ButterKnife;
+
+public class NumberFormatPreference extends DialogPreference {
+ @Bind(R.id.nf_notation_spinner)
+ Spinner notationSpinner;
+ @Bind(R.id.nf_precision_seekbar)
+ SeekBar precisionSeekBar;
+
+ {
+ setPersistent(false);
+ setDialogLayoutResource(R.layout.preference_number_format);
+ }
+
+ @TargetApi(Build.VERSION_CODES.LOLLIPOP)
+ public NumberFormatPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+ }
+
+ public NumberFormatPreference(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ }
+
+ public NumberFormatPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ @TargetApi(Build.VERSION_CODES.LOLLIPOP)
+ public NumberFormatPreference(Context context) {
+ super(context);
+ }
+
+ @Override
+ protected void onBindDialogView(View view) {
+ super.onBindDialogView(view);
+ ButterKnife.bind(this, view);
+
+ final SharedPreferences preferences = getSharedPreferences();
+ precisionSeekBar.setMax(15);
+ precisionSeekBar.setProgress(Math.max(0, Math.min(15, Engine.Preferences.Output.precision.getPreference(preferences))));
+ final ArrayAdapter adapter = makeNumberFormatAdapter();
+ notationSpinner.setAdapter(adapter);
+ notationSpinner.setSelection(indexOf(adapter, Engine.Preferences.Output.notation.getPreference(preferences)));
+ }
+
+ private int indexOf(ArrayAdapter adapter, Engine.Notation notation) {
+ for (int i = 0; i < adapter.getCount(); i++) {
+ if (adapter.getItem(i).notation == notation) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ @NonNull
+ private ArrayAdapter makeNumberFormatAdapter() {
+ final ArrayAdapter adapter = App.makeSimpleSpinnerAdapter(getContext());
+ for (Engine.Notation format : Engine.Notation.values()) {
+ adapter.add(new NotationItem(format));
+ }
+ adapter.sort(NaturalComparator.INSTANCE);
+ return adapter;
+ }
+
+ private final class NotationItem {
+ @NonNull
+ final Engine.Notation notation;
+ @NonNull
+ final String name;
+
+ private NotationItem(@NonNull Engine.Notation notation) {
+ this.notation = notation;
+ this.name = getContext().getString(notation.name);
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+ }
+}
diff --git a/app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesFragment.java b/app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesFragment.java
index e18bd7cf..b360c9e1 100644
--- a/app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesFragment.java
+++ b/app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesFragment.java
@@ -11,6 +11,7 @@ import android.support.v4.app.FragmentActivity;
import android.util.SparseArray;
import android.view.View;
import android.widget.ListView;
+
import org.solovyev.android.calculator.AdView;
import org.solovyev.android.calculator.Engine;
import org.solovyev.android.calculator.Preferences;
@@ -24,11 +25,12 @@ import org.solovyev.android.checkout.ProductTypes;
import org.solovyev.android.checkout.RequestListener;
import org.solovyev.android.wizard.Wizards;
+import java.util.Arrays;
+import java.util.List;
+
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.inject.Inject;
-import java.util.Arrays;
-import java.util.List;
import static org.solovyev.android.calculator.App.cast;
import static org.solovyev.android.calculator.wizard.CalculatorWizards.DEFAULT_WIZARD_FLOW;
diff --git a/app/src/main/java/org/solovyev/android/calculator/text/NaturalComparator.java b/app/src/main/java/org/solovyev/android/calculator/text/NaturalComparator.java
new file mode 100644
index 00000000..bf219dfe
--- /dev/null
+++ b/app/src/main/java/org/solovyev/android/calculator/text/NaturalComparator.java
@@ -0,0 +1,12 @@
+package org.solovyev.android.calculator.text;
+
+import java.util.Comparator;
+
+public class NaturalComparator implements Comparator