diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java index 1ee5c6f2..4f9563ac 100644 --- a/app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java @@ -38,9 +38,7 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.FrameLayout; -import butterknife.Bind; -import jscl.AngleUnit; -import jscl.NumeralBase; + import org.solovyev.android.calculator.converter.ConverterFragment; import org.solovyev.android.calculator.history.History; import org.solovyev.android.calculator.keyboard.PartialKeyboardUi; @@ -50,6 +48,10 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.inject.Inject; +import butterknife.Bind; +import jscl.AngleUnit; +import jscl.NumeralBase; + public class CalculatorActivity extends BaseActivity implements View.OnClickListener { @Nonnull @@ -212,7 +214,7 @@ public class CalculatorActivity extends BaseActivity implements View.OnClickList final Menu menu = popup.getMenu(); final MenuItem menuItem = menu.findItem(R.id.menu_angle_units); final AngleUnit angles = Engine.Preferences.angleUnit.getPreference(preferences); - menuItem.setTitle(makeTitle(R.string.cpp_angles, getAngleUnitsName(angles))); + menuItem.setTitle(makeTitle(R.string.cpp_angles, Engine.Preferences.angleUnitName(angles))); } private void updateNumeralBase() { @@ -222,37 +224,7 @@ public class CalculatorActivity extends BaseActivity implements View.OnClickList final Menu menu = popup.getMenu(); final MenuItem menuItem = menu.findItem(R.id.menu_numeral_base); final NumeralBase numeralBase = Engine.Preferences.numeralBase.getPreference(preferences); - menuItem.setTitle(makeTitle(R.string.cpp_radix, getNumeralBaseName(numeralBase))); - } - - @StringRes - private int getAngleUnitsName(AngleUnit angleUnit) { - switch (angleUnit) { - case deg: - return R.string.p_deg; - case rad: - return R.string.p_rad; - case grad: - return R.string.p_grad; - case turns: - return R.string.p_turns; - } - return 0; - } - - @StringRes - private int getNumeralBaseName(NumeralBase numeralBase) { - switch (numeralBase) { - case bin: - return R.string.p_bin; - case oct: - return R.string.p_oct; - case dec: - return R.string.p_dec; - case hex: - return R.string.p_hex; - } - return 0; + menuItem.setTitle(makeTitle(R.string.cpp_radix, Engine.Preferences.numeralBaseName(numeralBase))); } @Override 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 42c12a92..9cf14e82 100644 --- a/app/src/main/java/org/solovyev/android/calculator/Engine.java +++ b/app/src/main/java/org/solovyev/android/calculator/Engine.java @@ -335,6 +335,36 @@ public class Engine implements SharedPreferences.OnSharedPreferenceChangeListene return Collections.unmodifiableList(preferenceKeys); } + @StringRes + public static int angleUnitName(AngleUnit angleUnit) { + switch (angleUnit) { + case deg: + return R.string.p_deg; + case rad: + return R.string.p_rad; + case grad: + return R.string.p_grad; + case turns: + return R.string.p_turns; + } + return 0; + } + + @StringRes + public static int numeralBaseName(NumeralBase numeralBase) { + switch (numeralBase) { + case bin: + return R.string.p_bin; + case oct: + return R.string.p_oct; + case dec: + return R.string.p_dec; + case hex: + return R.string.p_hex; + } + return 0; + } + public static class Output { public static final StringPreference precision = StringPreference.ofTypedValue("engine.output.precision", "5", NumberMapper.of(Integer.class)); public static final StringPreference notation = StringPreference.ofEnum("engine.output.notation", Notation.dec, Notation.class); 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 d46c5751..ee950341 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,9 +11,10 @@ import android.support.v4.app.FragmentActivity; import android.util.SparseArray; import android.view.View; import android.widget.ListView; + import com.squareup.otto.Bus; import com.squareup.otto.Subscribe; -import jscl.JsclMathEngine; + import org.solovyev.android.calculator.AdView; import org.solovyev.android.calculator.Engine; import org.solovyev.android.calculator.Preferences; @@ -29,13 +30,20 @@ import org.solovyev.android.prefs.StringPreference; import org.solovyev.android.wizard.Wizards; import org.solovyev.common.text.CharacterMapper; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import javax.inject.Inject; import java.util.Arrays; import java.util.List; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import javax.inject.Inject; + +import jscl.AngleUnit; +import jscl.JsclMathEngine; +import jscl.NumeralBase; + import static org.solovyev.android.calculator.App.cast; +import static org.solovyev.android.calculator.Engine.Preferences.angleUnitName; +import static org.solovyev.android.calculator.Engine.Preferences.numeralBaseName; import static org.solovyev.android.calculator.wizard.CalculatorWizards.DEFAULT_WIZARD_FLOW; import static org.solovyev.android.wizard.WizardUi.startWizard; @@ -117,6 +125,9 @@ public class PreferencesFragment extends org.solovyev.android.material.preferenc } }); } + prepareModePreference(); + prepareAnglesPreference(); + prepareRadixPreference(); } else if (preference == R.xml.preferences_number_format) { prepareListPreference(Engine.Preferences.Output.notation, Engine.Notation.class); preparePrecisionPreference(); @@ -125,7 +136,6 @@ public class PreferencesFragment extends org.solovyev.android.material.preferenc } prepareLanguagePreference(preference); - prepareLayoutPreference(preference); prepareThemePreference(preference); getCheckout().whenReady(new Checkout.ListenerAdapter() { @@ -217,16 +227,37 @@ public class PreferencesFragment extends org.solovyev.android.material.preferenc }); } - private void prepareLayoutPreference(int preference) { - if (preference != R.xml.preferences_appearance) { - return; - } - final ListPreference layout = (ListPreference) preferenceManager.findPreference(Preferences.Gui.mode.getKey()); - layout.setSummary(Preferences.Gui.getMode(preferences).name); - layout.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + private void prepareModePreference() { + final ListPreference mode = (ListPreference) preferenceManager.findPreference(Preferences.Gui.mode.getKey()); + mode.setSummary(Preferences.Gui.getMode(preferences).name); + mode.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { - layout.setSummary(Preferences.Gui.Mode.valueOf((String) newValue).name); + mode.setSummary(Preferences.Gui.Mode.valueOf((String) newValue).name); + return true; + } + }); + } + + private void prepareAnglesPreference() { + final ListPreference angles = (ListPreference) preferenceManager.findPreference(Engine.Preferences.angleUnit.getKey()); + angles.setSummary(angleUnitName(Engine.Preferences.angleUnit.getPreference(preferences))); + angles.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + angles.setSummary(angleUnitName(AngleUnit.valueOf((String) newValue))); + return true; + } + }); + } + + private void prepareRadixPreference() { + final ListPreference radix = (ListPreference) preferenceManager.findPreference(Engine.Preferences.numeralBase.getKey()); + radix.setSummary(numeralBaseName(Engine.Preferences.numeralBase.getPreference(preferences))); + radix.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + radix.setSummary(numeralBaseName(NumeralBase.valueOf((String) newValue))); return true; } }); diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index fdebae46..83a43637 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -31,28 +31,67 @@ a:summary="@string/c_calc_ad_free_summary" a:title="@string/c_calc_ad_free_title" /> - + - + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/preferences_appearance.xml b/app/src/main/res/xml/preferences_appearance.xml index 687d40cf..b5781f59 100644 --- a/app/src/main/res/xml/preferences_appearance.xml +++ b/app/src/main/res/xml/preferences_appearance.xml @@ -38,12 +38,6 @@ a:key="gui.theme" a:title="@string/cpp_theme" /> - - - - - -