Mode menu setting

This commit is contained in:
serso 2016-03-23 00:15:03 +01:00
parent 4b413022a1
commit d6ea6c742f
16 changed files with 105 additions and 215 deletions

View File

@ -66,7 +66,7 @@ public class BaseActivity extends AppCompatActivity {
@Nonnull @Nonnull
private Preferences.Gui.Theme theme = Preferences.Gui.Theme.material_theme; private Preferences.Gui.Theme theme = Preferences.Gui.Theme.material_theme;
@Nonnull @Nonnull
private Preferences.Gui.Layout layout = Preferences.Gui.Layout.main_calculator; private Preferences.Gui.Mode mode = Preferences.Gui.Mode.engineer;
@Nonnull @Nonnull
private Language language = Languages.SYSTEM_LANGUAGE; private Language language = Languages.SYSTEM_LANGUAGE;
@ -96,6 +96,16 @@ public class BaseActivity extends AppCompatActivity {
} }
} }
@Nonnull
public Preferences.Gui.Theme getActivityTheme() {
return theme;
}
@Nonnull
public Preferences.Gui.Mode getActivityMode() {
return mode;
}
public static void setFont(@Nonnull TextView view, @Nonnull Typeface newTypeface) { public static void setFont(@Nonnull TextView view, @Nonnull Typeface newTypeface) {
final Typeface oldTypeface = view.getTypeface(); final Typeface oldTypeface = view.getTypeface();
if (oldTypeface == newTypeface) { if (oldTypeface == newTypeface) {
@ -105,9 +115,9 @@ public class BaseActivity extends AppCompatActivity {
view.setTypeface(newTypeface, style); view.setTypeface(newTypeface, style);
} }
public boolean restartIfLayoutChanged() { public boolean restartIfModeChanged() {
final Preferences.Gui.Layout newLayout = Preferences.Gui.layout.getPreference(preferences); final Preferences.Gui.Mode newMode = Preferences.Gui.mode.getPreference(preferences);
if (newLayout != layout) { if (newMode != mode) {
App.restartActivity(this); App.restartActivity(this);
return true; return true;
} }
@ -188,7 +198,7 @@ public class BaseActivity extends AppCompatActivity {
theme = Preferences.Gui.getTheme(preferences); theme = Preferences.Gui.getTheme(preferences);
setTheme(theme.getThemeFor(this)); setTheme(theme.getThemeFor(this));
layout = Preferences.Gui.getLayout(preferences); mode = Preferences.Gui.getMode(preferences);
language = languages.getCurrent(); language = languages.getCurrent();
} }

View File

@ -27,10 +27,7 @@ import android.os.Bundle;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.view.KeyEvent; import android.view.*;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import butterknife.Bind; import butterknife.Bind;
import butterknife.ButterKnife; import butterknife.ButterKnife;
@ -97,6 +94,7 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference
toolbar.inflateMenu(R.menu.main); toolbar.inflateMenu(R.menu.main);
toolbar.setOnMenuItemClickListener(this); toolbar.setOnMenuItemClickListener(this);
updateModeMenuItem();
useBackAsPrevious = Preferences.Gui.useBackAsPrevious.getPreference(preferences); useBackAsPrevious = Preferences.Gui.useBackAsPrevious.getPreference(preferences);
if (savedInstanceState == null) { if (savedInstanceState == null) {
@ -109,6 +107,12 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference
preferredPreferences.check(this, false); preferredPreferences.check(this, false);
} }
private void updateModeMenuItem() {
final Menu menu = toolbar.getMenu();
final MenuItem modeMenuItem = menu.findItem(R.id.menu_mode);
modeMenuItem.setTitle(getString(R.string.cpp_mode_status, getString(getActivityMode().menuName)));
}
@Override @Override
protected void inject(@Nonnull AppComponent component) { protected void inject(@Nonnull AppComponent component) {
super.inject(component); super.inject(component);
@ -128,7 +132,7 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
launcher.setActivity(this); launcher.setActivity(this);
if (restartIfLayoutChanged()) { if (restartIfModeChanged()) {
return; return;
} }
@ -156,12 +160,12 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference
} }
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences preferences, @Nullable String key) { public void onSharedPreferenceChanged(SharedPreferences preferences, @Nonnull String key) {
if (Preferences.Gui.useBackAsPrevious.getKey().equals(key)) { if (Preferences.Gui.useBackAsPrevious.isSameKey(key)) {
useBackAsPrevious = Preferences.Gui.useBackAsPrevious.getPreference(preferences); useBackAsPrevious = Preferences.Gui.useBackAsPrevious.getPreference(preferences);
} }
if (Preferences.Gui.rotateScreen.getKey().equals(key)) { if (Preferences.Gui.rotateScreen.isSameKey(key)) {
updateOrientation(); updateOrientation();
} }
} }
@ -192,6 +196,14 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference
case R.id.menu_about: case R.id.menu_about:
launcher.showAbout(); launcher.showAbout();
return true; return true;
case R.id.menu_mode_engineer:
Preferences.Gui.mode.putPreference(preferences, Preferences.Gui.Mode.engineer);
restartIfModeChanged();
return true;
case R.id.menu_mode_simple:
Preferences.Gui.mode.putPreference(preferences, Preferences.Gui.Mode.simple);
restartIfModeChanged();
return true;
} }
return false; return false;
} }

View File

@ -29,14 +29,12 @@ import android.content.SharedPreferences;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.Color; import android.graphics.Color;
import android.provider.Settings; import android.provider.Settings;
import android.support.annotation.ColorRes; import android.support.annotation.*;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
import android.support.annotation.StyleRes;
import android.support.v7.view.ContextThemeWrapper; import android.support.v7.view.ContextThemeWrapper;
import android.text.TextUtils;
import android.util.SparseArray; import android.util.SparseArray;
import jscl.AngleUnit;
import jscl.NumeralBase;
import org.solovyev.android.Check; import org.solovyev.android.Check;
import org.solovyev.android.calculator.about.AboutActivity; import org.solovyev.android.calculator.about.AboutActivity;
import org.solovyev.android.calculator.functions.FunctionsActivity; import org.solovyev.android.calculator.functions.FunctionsActivity;
@ -47,23 +45,15 @@ import org.solovyev.android.calculator.operators.OperatorsActivity;
import org.solovyev.android.calculator.preferences.PreferencesActivity; import org.solovyev.android.calculator.preferences.PreferencesActivity;
import org.solovyev.android.calculator.variables.VariablesActivity; import org.solovyev.android.calculator.variables.VariablesActivity;
import org.solovyev.android.calculator.wizard.WizardActivity; import org.solovyev.android.calculator.wizard.WizardActivity;
import org.solovyev.android.prefs.BooleanPreference; import org.solovyev.android.prefs.*;
import org.solovyev.android.prefs.IntegerPreference;
import org.solovyev.android.prefs.NumberToStringPreference;
import org.solovyev.android.prefs.Preference;
import org.solovyev.android.prefs.StringPreference;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.text.DecimalFormatSymbols; import java.text.DecimalFormatSymbols;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import jscl.AngleUnit;
import jscl.NumeralBase;
import static org.solovyev.android.prefs.IntegerPreference.DEF_VALUE; import static org.solovyev.android.prefs.IntegerPreference.DEF_VALUE;
public final class Preferences { public final class Preferences {
@ -87,17 +77,16 @@ public final class Preferences {
} }
migratePreference(preferences, editor, Gui.keepScreenOn, Deleted.preventScreenFromFading); migratePreference(preferences, editor, Gui.keepScreenOn, Deleted.preventScreenFromFading);
migratePreference(preferences, editor, Gui.theme, Deleted.theme); migratePreference(preferences, editor, Gui.theme, Deleted.theme);
migratePreference(preferences, editor, Gui.layout, Deleted.layout);
migratePreference(preferences, editor, Gui.useBackAsPrevious, Deleted.usePrevAsBack); migratePreference(preferences, editor, Gui.useBackAsPrevious, Deleted.usePrevAsBack);
migratePreference(preferences, editor, Gui.showReleaseNotes, Deleted.showReleaseNotes); migratePreference(preferences, editor, Gui.showReleaseNotes, Deleted.showReleaseNotes);
migratePreference(preferences, editor, Gui.rotateScreen, Deleted.autoOrientation); migratePreference(preferences, editor, Gui.rotateScreen, Deleted.autoOrientation);
final Gui.Layout layout = Deleted.layout.getPreference(preferences); final String layout = Deleted.layout.getPreference(preferences);
if (layout == Gui.Layout.main_cellphone) { if (TextUtils.equals(layout, "main_calculator")) {
Gui.layout.putDefault(editor); Gui.mode.putPreference(editor, Gui.Mode.engineer);
} else if (layout == Gui.Layout.main_calculator_mobile) { } else if (TextUtils.equals(layout, "simple")) {
Gui.layout.putPreference(editor, Gui.Layout.main_calculator); Gui.mode.putPreference(editor, Gui.Mode.simple);
} else if (layout == Gui.Layout.simple_mobile) { } else if (!Gui.mode.isSet(preferences)) {
Gui.layout.putPreference(editor, Gui.Layout.simple); Gui.mode.putDefault(editor);
} }
version.putDefault(editor); version.putDefault(editor);
editor.apply(); editor.apply();
@ -140,7 +129,7 @@ public final class Preferences {
Engine.Preferences.numeralBase.tryPutDefault(preferences, editor); Engine.Preferences.numeralBase.tryPutDefault(preferences, editor);
Gui.theme.tryPutDefault(preferences, editor); Gui.theme.tryPutDefault(preferences, editor);
Gui.layout.tryPutDefault(preferences, editor); Gui.mode.tryPutDefault(preferences, editor);
Gui.showReleaseNotes.tryPutDefault(preferences, editor); Gui.showReleaseNotes.tryPutDefault(preferences, editor);
Gui.useBackAsPrevious.tryPutDefault(preferences, editor); Gui.useBackAsPrevious.tryPutDefault(preferences, editor);
Gui.rotateScreen.tryPutDefault(preferences, editor); Gui.rotateScreen.tryPutDefault(preferences, editor);
@ -285,7 +274,7 @@ public final class Preferences {
public static class Gui { public static class Gui {
public static final Preference<Theme> theme = StringPreference.ofEnum("gui.theme", Theme.material_theme, Theme.class); public static final Preference<Theme> theme = StringPreference.ofEnum("gui.theme", Theme.material_theme, Theme.class);
public static final Preference<Layout> layout = StringPreference.ofEnum("gui.layout", Layout.simple, Layout.class); public static final Preference<Mode> mode = StringPreference.ofEnum("gui.mode", Mode.simple, Mode.class);
public static final Preference<String> language = StringPreference.of("gui.language", Languages.SYSTEM_LANGUAGE_CODE); public static final Preference<String> language = StringPreference.of("gui.language", Languages.SYSTEM_LANGUAGE_CODE);
public static final Preference<Boolean> showReleaseNotes = BooleanPreference.of("gui.showReleaseNotes", true); public static final Preference<Boolean> showReleaseNotes = BooleanPreference.of("gui.showReleaseNotes", true);
public static final Preference<Boolean> useBackAsPrevious = BooleanPreference.of("gui.useBackAsPrevious", false); public static final Preference<Boolean> useBackAsPrevious = BooleanPreference.of("gui.useBackAsPrevious", false);
@ -299,8 +288,8 @@ public final class Preferences {
} }
@Nonnull @Nonnull
public static Layout getLayout(@Nonnull SharedPreferences preferences) { public static Mode getMode(@Nonnull SharedPreferences preferences) {
return layout.getPreferenceNoError(preferences); return mode.getPreferenceNoError(preferences);
} }
public enum Theme { public enum Theme {
@ -393,25 +382,18 @@ public final class Preferences {
} }
} }
public enum Layout { public enum Mode {
main_calculator(R.string.p_layout_calculator), engineer(R.string.p_layout_calculator, R.string.cpp_wizard_mode_engineer),
simple(R.string.p_layout_simple), simple(R.string.p_layout_simple, R.string.cpp_wizard_mode_simple);
// not used anymore
@Deprecated
main_cellphone(R.string.p_layout_simple),
// not used anymore
@Deprecated
main_calculator_mobile(R.string.p_layout_simple),
// not used anymore
@Deprecated
simple_mobile(R.string.p_layout_simple);
@StringRes @StringRes
public final int name; public final int name;
@StringRes
public final int menuName;
Layout(@StringRes int name) { Mode(@StringRes int name, @StringRes int menuName) {
this.name = name; this.name = name;
this.menuName = menuName;
} }
} }
@ -438,7 +420,7 @@ public final class Preferences {
static final Preference<Boolean> colorDisplay = BooleanPreference.of("org.solovyev.android.calculator.CalculatorModel_color_display", true); static final Preference<Boolean> colorDisplay = BooleanPreference.of("org.solovyev.android.calculator.CalculatorModel_color_display", true);
static final Preference<Boolean> preventScreenFromFading = BooleanPreference.of("preventScreenFromFading", true); static final Preference<Boolean> preventScreenFromFading = BooleanPreference.of("preventScreenFromFading", true);
static final Preference<Gui.Theme> theme = StringPreference.ofEnum("org.solovyev.android.calculator.CalculatorActivity_calc_theme", Gui.Theme.material_theme, Gui.Theme.class); static final Preference<Gui.Theme> theme = StringPreference.ofEnum("org.solovyev.android.calculator.CalculatorActivity_calc_theme", Gui.Theme.material_theme, Gui.Theme.class);
static final Preference<Gui.Layout> layout = StringPreference.ofEnum("org.solovyev.android.calculator.CalculatorActivity_calc_layout", Gui.Layout.simple, Gui.Layout.class); static final StringPreference<String> layout = StringPreference.of("org.solovyev.android.calculator.CalculatorActivity_calc_layout", "simple");
static final Preference<Boolean> showReleaseNotes = BooleanPreference.of("org.solovyev.android.calculator.CalculatorActivity_show_release_notes", true); static final Preference<Boolean> showReleaseNotes = BooleanPreference.of("org.solovyev.android.calculator.CalculatorActivity_show_release_notes", true);
static final Preference<Boolean> usePrevAsBack = BooleanPreference.of("org.solovyev.android.calculator.CalculatorActivity_use_back_button_as_prev", false); static final Preference<Boolean> usePrevAsBack = BooleanPreference.of("org.solovyev.android.calculator.CalculatorActivity_use_back_button_as_prev", false);
static final Preference<Boolean> showEqualsButton = BooleanPreference.of("showEqualsButton", true); static final Preference<Boolean> showEqualsButton = BooleanPreference.of("showEqualsButton", true);

View File

@ -33,8 +33,8 @@ public final class Ga implements SharedPreferences.OnSharedPreferenceChangeListe
preferences.registerOnSharedPreferenceChangeListener(this); preferences.registerOnSharedPreferenceChangeListener(this);
} }
private void reportLayout(@Nonnull Preferences.Gui.Layout layout) { private void reportLayout(@Nonnull Preferences.Gui.Mode mode) {
tracker.send(new HitBuilders.EventBuilder().setCustomDimension(LAYOUT, layout.name()).build()); tracker.send(new HitBuilders.EventBuilder().setCustomDimension(LAYOUT, mode.name()).build());
} }
private void reportTheme(@Nonnull Preferences.Gui.Theme theme) { private void reportTheme(@Nonnull Preferences.Gui.Theme theme) {
@ -60,15 +60,15 @@ public final class Ga implements SharedPreferences.OnSharedPreferenceChangeListe
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) { public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
if (TextUtils.equals(key, Preferences.Gui.layout.getKey())) { if (TextUtils.equals(key, Preferences.Gui.mode.getKey())) {
reportLayout(Preferences.Gui.layout.getPreferenceNoError(preferences)); reportLayout(Preferences.Gui.mode.getPreferenceNoError(preferences));
} else if (TextUtils.equals(key, Preferences.Gui.theme.getKey())) { } else if (TextUtils.equals(key, Preferences.Gui.theme.getKey())) {
reportTheme(Preferences.Gui.theme.getPreferenceNoError(preferences)); reportTheme(Preferences.Gui.theme.getPreferenceNoError(preferences));
} }
} }
public void reportInitially(@Nonnull SharedPreferences preferences) { public void reportInitially(@Nonnull SharedPreferences preferences) {
reportLayout(Preferences.Gui.layout.getPreferenceNoError(preferences)); reportLayout(Preferences.Gui.mode.getPreferenceNoError(preferences));
reportTheme(Preferences.Gui.theme.getPreferenceNoError(preferences)); reportTheme(Preferences.Gui.theme.getPreferenceNoError(preferences));
} }

View File

@ -1,73 +0,0 @@
/*
* Copyright 2013 serso aka se.solovyev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Contact details
*
* Email: se.solovyev@gmail.com
* Site: http://se.solovyev.org
*/
package org.solovyev.android.calculator.history;
import android.content.Context;
import android.text.format.DateUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import org.solovyev.android.calculator.R;
import org.solovyev.common.text.Strings;
import javax.annotation.Nonnull;
import java.util.List;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
public class HistoryArrayAdapter extends ArrayAdapter<HistoryState> {
private static final int DATETIME_FORMAT = DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_ABBREV_TIME;
HistoryArrayAdapter(Context context, int resource, int textViewResourceId, @Nonnull List<HistoryState> historyList) {
super(context, resource, textViewResourceId, historyList);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewGroup result = (ViewGroup) super.getView(position, convertView, parent);
final HistoryState state = getItem(position);
final TextView time = (TextView) result.findViewById(R.id.history_item_time);
time.setText(DateUtils.formatDateTime(getContext(), state.getTime(), DATETIME_FORMAT));
final TextView editor = (TextView) result.findViewById(R.id.history_item_value);
editor.setText(BaseHistoryFragment.getHistoryText(state));
final TextView commentView = (TextView) result.findViewById(R.id.history_item_comment);
if (commentView != null) {
final String comment = state.getComment();
if (!Strings.isEmpty(comment)) {
commentView.setText(comment);
commentView.setVisibility(VISIBLE);
} else {
commentView.setText(null);
commentView.setVisibility(GONE);
}
}
return result;
}
}

View File

@ -27,8 +27,7 @@ import java.util.List;
import static android.content.res.Configuration.ORIENTATION_PORTRAIT; import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
import static android.view.HapticFeedbackConstants.*; import static android.view.HapticFeedbackConstants.*;
import static org.solovyev.android.calculator.App.cast; import static org.solovyev.android.calculator.App.cast;
import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple; import static org.solovyev.android.calculator.Preferences.Gui.Mode.simple;
import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple_mobile;
public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPreferenceChangeListener, View.OnClickListener { public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPreferenceChangeListener, View.OnClickListener {
@ -61,7 +60,7 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer
PreferredPreferences preferredPreferences; PreferredPreferences preferredPreferences;
protected int orientation = ORIENTATION_PORTRAIT; protected int orientation = ORIENTATION_PORTRAIT;
private int textSize; private int textSize;
private Preferences.Gui.Layout layout; private Preferences.Gui.Mode mode;
private final float textScale; private final float textScale;
public BaseKeyboardUi(@NonNull Application application) { public BaseKeyboardUi(@NonNull Application application) {
@ -92,7 +91,7 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer
preferences.registerOnSharedPreferenceChangeListener(this); preferences.registerOnSharedPreferenceChangeListener(this);
orientation = App.getScreenOrientation(activity); orientation = App.getScreenOrientation(activity);
layout = Preferences.Gui.layout.getPreferenceNoError(preferences); mode = Preferences.Gui.mode.getPreferenceNoError(preferences);
textSize = calculateTextSize(activity); textSize = calculateTextSize(activity);
} }
@ -183,8 +182,8 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer
} }
} }
protected boolean isSimpleLayout() { protected boolean isSimpleMode() {
return layout == simple || layout == simple_mobile; return mode == simple;
} }
protected final void onClick(@Nonnull View v, @Nonnull String s) { protected final void onClick(@Nonnull View v, @Nonnull String s) {

View File

@ -151,7 +151,7 @@ public class KeyboardUi extends BaseKeyboardUi {
prepareButton(likeButton); prepareButton(likeButton);
prepareButton(memoryButton); prepareButton(memoryButton);
if (isSimpleLayout()) { if (isSimpleMode()) {
hideText(button1, down); hideText(button1, down);
hideText(button2, down); hideText(button2, down);
hideText(button3, down); hideText(button3, down);

View File

@ -61,7 +61,7 @@ public class PartialKeyboardUi extends BaseKeyboardUi {
prepareButton(eraseButton, IMAGE_SCALE_ERASE); prepareButton(eraseButton, IMAGE_SCALE_ERASE);
longClickEraser = EditorLongClickEraser.attachTo(eraseButton, keyboard.isVibrateOnKeypress(), editor, calculator); longClickEraser = EditorLongClickEraser.attachTo(eraseButton, keyboard.isVibrateOnKeypress(), editor, calculator);
} }
if(isSimpleLayout()) { if(isSimpleMode()) {
hideText(equalsButton, down); hideText(equalsButton, down);
} }
} }

View File

@ -138,12 +138,12 @@ public class PreferencesFragment extends org.solovyev.android.material.preferenc
if (preference != R.xml.preferences_appearance) { if (preference != R.xml.preferences_appearance) {
return; return;
} }
final ListPreference layout = (ListPreference) preferenceManager.findPreference(Preferences.Gui.layout.getKey()); final ListPreference layout = (ListPreference) preferenceManager.findPreference(Preferences.Gui.mode.getKey());
layout.setSummary(Preferences.Gui.getLayout(preferences).name); layout.setSummary(Preferences.Gui.getMode(preferences).name);
layout.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { layout.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override @Override
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
layout.setSummary(Preferences.Gui.Layout.valueOf((String) newValue).name); layout.setSummary(Preferences.Gui.Mode.valueOf((String) newValue).name);
return true; return true;
} }
}); });

View File

@ -29,8 +29,6 @@ import org.solovyev.android.calculator.Preferences;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import static org.solovyev.android.calculator.Preferences.Gui.Layout.main_calculator;
enum CalculatorMode { enum CalculatorMode {
simple() { simple() {
@ -38,7 +36,7 @@ enum CalculatorMode {
protected void apply(@Nonnull SharedPreferences preferences) { protected void apply(@Nonnull SharedPreferences preferences) {
final SharedPreferences.Editor editor = preferences.edit(); final SharedPreferences.Editor editor = preferences.edit();
Preferences.Gui.layout.putPreference(editor, Preferences.Gui.Layout.simple); Preferences.Gui.mode.putPreference(editor, Preferences.Gui.Mode.simple);
Preferences.Calculations.preferredAngleUnits.putPreference(editor, AngleUnit.deg); Preferences.Calculations.preferredAngleUnits.putPreference(editor, AngleUnit.deg);
Engine.Preferences.angleUnit.putPreference(editor, AngleUnit.deg); Engine.Preferences.angleUnit.putPreference(editor, AngleUnit.deg);
Engine.Preferences.Output.scientificNotation.putPreference(editor, false); Engine.Preferences.Output.scientificNotation.putPreference(editor, false);
@ -53,7 +51,7 @@ enum CalculatorMode {
protected void apply(@Nonnull SharedPreferences preferences) { protected void apply(@Nonnull SharedPreferences preferences) {
final SharedPreferences.Editor editor = preferences.edit(); final SharedPreferences.Editor editor = preferences.edit();
Preferences.Gui.layout.putPreference(editor, main_calculator); Preferences.Gui.mode.putPreference(editor, Preferences.Gui.Mode.engineer);
Preferences.Calculations.preferredAngleUnits.putPreference(editor, AngleUnit.rad); Preferences.Calculations.preferredAngleUnits.putPreference(editor, AngleUnit.rad);
Engine.Preferences.angleUnit.putPreference(editor, AngleUnit.rad); Engine.Preferences.angleUnit.putPreference(editor, AngleUnit.rad);
Engine.Preferences.Output.scientificNotation.putPreference(editor, true); Engine.Preferences.Output.scientificNotation.putPreference(editor, true);
@ -69,14 +67,11 @@ enum CalculatorMode {
} }
@Nonnull @Nonnull
static CalculatorMode fromGuiLayout(@Nonnull Preferences.Gui.Layout layout) { static CalculatorMode fromGuiLayout(@Nonnull Preferences.Gui.Mode mode) {
switch (layout) { switch (mode) {
case main_calculator: case engineer:
case main_cellphone:
case main_calculator_mobile:
return engineer; return engineer;
case simple: case simple:
case simple_mobile:
return simple; return simple;
default: default:
return getDefaultMode(); return getDefaultMode();

View File

@ -66,7 +66,7 @@ public class ChooseModeWizardStep extends WizardFragment implements AdapterView.
public void onViewCreated(View root, Bundle savedInstanceState) { public void onViewCreated(View root, Bundle savedInstanceState) {
super.onViewCreated(root, savedInstanceState); super.onViewCreated(root, savedInstanceState);
final CalculatorMode mode = CalculatorMode.fromGuiLayout(Preferences.Gui.layout.getPreference(preferences)); final CalculatorMode mode = CalculatorMode.fromGuiLayout(Preferences.Gui.mode.getPreference(preferences));
final Spinner spinner = (Spinner) root.findViewById(R.id.wizard_mode_spinner); final Spinner spinner = (Spinner) root.findViewById(R.id.wizard_mode_spinner);
spinner.setAdapter(WizardArrayAdapter.create(getActivity(), R.array.cpp_modes)); spinner.setAdapter(WizardArrayAdapter.create(getActivity(), R.array.cpp_modes));
spinner.setSelection(mode == simple ? 0 : 1); spinner.setSelection(mode == simple ? 0 : 1);

View File

@ -1,50 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2013 serso aka se.solovyev
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ Contact details
~
~ Email: se.solovyev@gmail.com
~ Site: http://se.solovyev.org
-->
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:layout_width="match_parent"
a:layout_height="match_parent"
a:gravity="center"
a:orientation="vertical">
<TextView
style="@style/WizardLabel"
a:layout_width="wrap_content"
a:layout_height="wrap_content"
a:text="@string/cpp_wizard_layout_title"
a:textAppearance="@android:style/TextAppearance.Large" />
<Spinner
a:id="@+id/wizard_layout_spinner"
style="@style/WizardLabel"
a:layout_width="wrap_content"
a:layout_height="wrap_content" />
<ImageView
a:id="@+id/wizard_layout_image"
style="@style/WizardLabel.Last"
a:layout_width="wrap_content"
a:layout_height="wrap_content" />
</LinearLayout>

View File

@ -2,6 +2,20 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" <menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_mode"
android:title="@string/cpp_mode"
app:showAsAction="never">
<menu>
<item
android:id="@+id/menu_mode_engineer"
android:title="@string/cpp_wizard_mode_engineer" />
<item
android:id="@+id/menu_mode_simple"
android:title="@string/cpp_wizard_mode_simple" />
</menu>
</item>
<item <item
android:id="@+id/menu_settings" android:id="@+id/menu_settings"
android:title="@string/cpp_settings" android:title="@string/cpp_settings"

View File

@ -66,12 +66,12 @@
<item>"∙"</item> <item>"∙"</item>
</string-array> </string-array>
<string-array name="p_layout_names" tools:ignore="InconsistentArrays"> <string-array name="p_layout_names">
<item>@string/p_layout_calculator</item> <item>@string/cpp_wizard_mode_engineer</item>
<item>@string/p_layout_simple</item> <item>@string/cpp_wizard_mode_simple</item>
</string-array> </string-array>
<string-array name="p_layout_values" translatable="false" tools:ignore="InconsistentArrays"> <string-array name="p_layout_values" translatable="false">
<item>main_calculator</item> <item>engineer</item>
<item>simple</item> <item>simple</item>
</string-array> </string-array>

View File

@ -241,4 +241,6 @@
<string name="cpp_missing_permission_msg">Please enable \"%1$s\" permission in system settings</string> <string name="cpp_missing_permission_msg">Please enable \"%1$s\" permission in system settings</string>
<string name="fn_line_width">Line width</string> <string name="fn_line_width">Line width</string>
<string name="fn_line_color">Line color</string> <string name="fn_line_color">Line color</string>
<string name="cpp_mode">Mode</string>
<string name="cpp_mode_status">Mode: %1$s</string>
</resources> </resources>

View File

@ -43,9 +43,8 @@
<ListPreference <ListPreference
a:entries="@array/p_layout_names" a:entries="@array/p_layout_names"
a:entryValues="@array/p_layout_values" a:entryValues="@array/p_layout_values"
a:key="gui.layout" a:key="gui.mode"
a:summary="@string/c_calc_layout_summary" a:title="@string/cpp_mode" />
a:title="@string/c_calc_layout" />
<android.preference.CheckBoxPreference <android.preference.CheckBoxPreference
a:defaultValue="true" a:defaultValue="true"