Restructure settings

This commit is contained in:
serso 2016-05-06 16:19:41 +02:00
parent 7bced200ed
commit ba991942b1
6 changed files with 141 additions and 89 deletions

View File

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

View File

@ -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<Integer> precision = StringPreference.ofTypedValue("engine.output.precision", "5", NumberMapper.of(Integer.class));
public static final StringPreference<Notation> notation = StringPreference.ofEnum("engine.output.notation", Notation.dec, Notation.class);

View File

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

View File

@ -31,28 +31,67 @@
a:summary="@string/c_calc_ad_free_summary"
a:title="@string/c_calc_ad_free_title" />
<Preference
a:key="restart_wizard"
a:title="@string/cpp_restart_wizard" />
<PreferenceCategory
a:key="category-basic"
a:title="Basic">
<Preference
a:key="screen-number-format"
a:title="Number format" />
<ListPreference
a:entries="@array/p_layout_names"
a:entryValues="@array/p_layout_values"
a:key="gui.mode"
a:title="@string/cpp_mode" />
<Preference
a:key="screen-calculations"
a:title="@string/c_prefs_calculations_category" />
<Preference
a:key="screen-appearance"
a:title="@string/c_prefs_appearance_category" />
<Preference
a:key="screen-other"
a:title="@string/c_prefs_other_category" />
<Preference
a:key="screen-onscreen"
a:title="@string/prefs_onscreen_title" />
<Preference
a:key="screen-widget"
a:title="@string/prefs_widget_title" />
<ListPreference
a:entries="@array/p_angle_units_names"
a:entryValues="@array/p_angle_units"
a:key="engine.angleUnit"
a:title="@string/cpp_angles" />
<ListPreference
a:entries="@array/p_numeral_bases_names"
a:entryValues="@array/p_numeral_bases"
a:key="engine.numeralBase"
a:title="@string/cpp_radix" />
<Preference
a:key="screen-number-format"
a:title="Number format" />
</PreferenceCategory>
<PreferenceCategory
a:key="category-advanced"
a:title="Advanced">
<Preference
a:key="screen-calculations"
a:title="@string/c_prefs_calculations_category" />
<Preference
a:key="screen-appearance"
a:title="@string/c_prefs_appearance_category" />
<Preference
a:key="screen-other"
a:title="@string/c_prefs_other_category" />
<Preference
a:key="screen-onscreen"
a:title="@string/prefs_onscreen_title" />
<Preference
a:key="screen-widget"
a:title="@string/prefs_widget_title" />
</PreferenceCategory>
<PreferenceCategory
a:key="category-help"
a:title="Help">
<Preference
a:key="restart_wizard"
a:title="@string/cpp_restart_wizard" />
<Preference
a:key="prefs.reportBug"
a:title="Report a problem" />
</PreferenceCategory>
</PreferenceScreen>

View File

@ -38,12 +38,6 @@
a:key="gui.theme"
a:title="@string/cpp_theme" />
<ListPreference
a:entries="@array/p_layout_names"
a:entryValues="@array/p_layout_values"
a:key="gui.mode"
a:title="@string/cpp_mode" />
<android.preference.CheckBoxPreference
a:defaultValue="true"
a:key="gui.rotateScreen"

View File

@ -24,20 +24,6 @@
<PreferenceScreen xmlns:a="http://schemas.android.com/apk/res/android">
<ListPreference
a:entries="@array/p_angle_units_names"
a:entryValues="@array/p_angle_units"
a:key="engine.angleUnit"
a:summary="@string/c_angle_units_summary"
a:title="@string/c_calc_angle_units" />
<ListPreference
a:entries="@array/p_numeral_bases_names"
a:entryValues="@array/p_numeral_bases"
a:key="engine.numeralBase"
a:summary="@string/c_numeral_bases_summary"
a:title="@string/c_calc_numeral_bases" />
<android.preference.CheckBoxPreference
a:key="calculations_calculate_on_fly"
a:summary="@string/p_calculations_calculate_on_fly_summary"