diff --git a/android-app-core/res/values-ru/text_strings.xml b/android-app-core/res/values-ru/text_strings.xml
index f6024a5a..7f2b1e3e 100644
--- a/android-app-core/res/values-ru/text_strings.xml
+++ b/android-app-core/res/values-ru/text_strings.xml
@@ -130,8 +130,9 @@
Раскладка
Научная (телефон)
Научная
- Научная (большие кнопкм)
+ Научная (большие кнопки)
Простая
+ Простая (большие кнопки)
Устанавливает раскладку кнопок
Отклик на нажатие
diff --git a/android-app-core/res/values/text_strings.xml b/android-app-core/res/values/text_strings.xml
index 039bd252..48ce605d 100644
--- a/android-app-core/res/values/text_strings.xml
+++ b/android-app-core/res/values/text_strings.xml
@@ -128,6 +128,7 @@
Scientific
Scientific (Big buttons)
Simple
+ Simple (Big buttons)
Sets layout of buttons
Haptic feedback
diff --git a/android-app-core/src/main/java/org/solovyev/android/calculator/CalculatorPreferences.java b/android-app-core/src/main/java/org/solovyev/android/calculator/CalculatorPreferences.java
index 0ea48ae2..4dffc9bc 100644
--- a/android-app-core/src/main/java/org/solovyev/android/calculator/CalculatorPreferences.java
+++ b/android-app-core/src/main/java/org/solovyev/android/calculator/CalculatorPreferences.java
@@ -106,21 +106,25 @@ public final class CalculatorPreferences {
}
public static enum Layout {
- main_calculator(R.layout.main_calculator, R.string.p_layout_calculator),
- main_calculator_mobile(R.layout.main_calculator_mobile, R.string.p_layout_calculator_mobile),
+ main_calculator(R.layout.main_calculator, R.string.p_layout_calculator, true),
+ main_calculator_mobile(R.layout.main_calculator_mobile, R.string.p_layout_calculator_mobile, false),
// not used anymore
@Deprecated
- main_cellphone(R.layout.main_calculator, 0),
+ main_cellphone(R.layout.main_calculator, 0, true),
- simple(R.layout.main_calculator, R.string.p_layout_simple);
+ simple(R.layout.main_calculator, R.string.p_layout_simple, true),
+ simple_mobile(R.layout.main_calculator_mobile, R.string.p_layout_simple_mobile, false)
+ ;
private final int layoutId;
private final int nameResId;
+ private final boolean optimized;
- Layout(int layoutId, int nameResId) {
+ Layout(int layoutId, int nameResId, boolean optimized) {
this.layoutId = layoutId;
this.nameResId = nameResId;
+ this.optimized = optimized;
}
public int getLayoutId() {
@@ -130,6 +134,10 @@ public final class CalculatorPreferences {
public int getNameResId() {
return nameResId;
}
+
+ public boolean isOptimized() {
+ return optimized;
+ }
}
}
diff --git a/android-app/res/layout/cpp_wizard_step_tablet.xml b/android-app/res/layout/cpp_wizard_step_tablet.xml
index 438c8930..b2d3ff06 100644
--- a/android-app/res/layout/cpp_wizard_step_tablet.xml
+++ b/android-app/res/layout/cpp_wizard_step_tablet.xml
@@ -1,18 +1,57 @@
+ a:layout_width="match_parent"
+ a:layout_height="match_parent"
+ a:orientation="vertical">
+ a:text="Do you want to use optimized layout for large screens or just big buttons?"
+ a:layout_height="wrap_content"
+ a:layout_width="match_parent"/>
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/android-app/res/values/arrays.xml b/android-app/res/values/arrays.xml
index 63f8345c..6437c0a8 100644
--- a/android-app/res/values/arrays.xml
+++ b/android-app/res/values/arrays.xml
@@ -43,11 +43,13 @@
- @string/p_layout_calculator
- @string/p_layout_calculator_mobile
- @string/p_layout_simple
+ - @string/p_layout_simple_mobile
- main_calculator
- main_calculator_mobile
- simple
+ - simple_mobile
diff --git a/android-app/src/main/java/org/solovyev/android/calculator/AbstractCalculatorHelper.java b/android-app/src/main/java/org/solovyev/android/calculator/AbstractCalculatorHelper.java
index aca8589d..f1ed3577 100644
--- a/android-app/src/main/java/org/solovyev/android/calculator/AbstractCalculatorHelper.java
+++ b/android-app/src/main/java/org/solovyev/android/calculator/AbstractCalculatorHelper.java
@@ -26,6 +26,9 @@ import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
+import static org.solovyev.android.calculator.CalculatorPreferences.Gui.Layout.simple;
+import static org.solovyev.android.calculator.CalculatorPreferences.Gui.Layout.simple_mobile;
+
/**
* User: serso
* Date: 9/28/12
@@ -149,7 +152,7 @@ public abstract class AbstractCalculatorHelper implements SharedPreferences.OnSh
roundBracketsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new CalculatorButtons.RoundBracketsDragProcessor(), dragPreferences), vibrator, preferences));
}
- if (layout == CalculatorPreferences.Gui.Layout.simple) {
+ if (layout == simple || layout == simple_mobile) {
toggleButtonDirectionText(root, R.id.cpp_button_1, false, DragDirection.up, DragDirection.down);
toggleButtonDirectionText(root, R.id.cpp_button_2, false, DragDirection.up, DragDirection.down);
toggleButtonDirectionText(root, R.id.cpp_button_3, false, DragDirection.up, DragDirection.down);
diff --git a/android-app/src/main/java/org/solovyev/android/calculator/wizard/CalculatorLayout.java b/android-app/src/main/java/org/solovyev/android/calculator/wizard/CalculatorLayout.java
index d6d24caf..cbca4125 100644
--- a/android-app/src/main/java/org/solovyev/android/calculator/wizard/CalculatorLayout.java
+++ b/android-app/src/main/java/org/solovyev/android/calculator/wizard/CalculatorLayout.java
@@ -43,7 +43,22 @@ enum CalculatorLayout {
protected abstract void apply(@Nonnull SharedPreferences preferences);
@Nonnull
- static CalculatorLayout getDefaultMode(){
+ static CalculatorLayout getDefaultLayout(){
return big_buttons;
}
+
+ @Nonnull
+ static CalculatorLayout fromGuiLayout(@Nonnull CalculatorPreferences.Gui.Layout layout) {
+ switch (layout) {
+ case main_calculator:
+ case main_cellphone:
+ case simple:
+ return optimized;
+ case main_calculator_mobile:
+ case simple_mobile:
+ return big_buttons;
+ default:
+ return getDefaultLayout();
+ }
+ }
}
diff --git a/android-app/src/main/java/org/solovyev/android/calculator/wizard/CalculatorMode.java b/android-app/src/main/java/org/solovyev/android/calculator/wizard/CalculatorMode.java
index 083db33f..0c95a00c 100644
--- a/android-app/src/main/java/org/solovyev/android/calculator/wizard/CalculatorMode.java
+++ b/android-app/src/main/java/org/solovyev/android/calculator/wizard/CalculatorMode.java
@@ -9,6 +9,7 @@ import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
import javax.annotation.Nonnull;
import static org.solovyev.android.calculator.CalculatorPreferences.Gui.Layout.main_calculator;
+import static org.solovyev.android.calculator.CalculatorPreferences.Gui.Layout.main_calculator_mobile;
/**
* User: serso
@@ -20,7 +21,12 @@ enum CalculatorMode {
simple(R.string.cpp_wizard_mode_simple) {
@Override
protected void apply(@Nonnull SharedPreferences preferences) {
- CalculatorPreferences.Gui.layout.putPreference(preferences, CalculatorPreferences.Gui.Layout.simple);
+ final CalculatorPreferences.Gui.Layout layout = CalculatorPreferences.Gui.layout.getPreference(preferences);
+ if (layout.isOptimized()) {
+ CalculatorPreferences.Gui.layout.putPreference(preferences, CalculatorPreferences.Gui.Layout.simple);
+ } else {
+ CalculatorPreferences.Gui.layout.putPreference(preferences, CalculatorPreferences.Gui.Layout.simple_mobile);
+ }
CalculatorPreferences.Calculations.preferredAngleUnits.putPreference(preferences, AngleUnit.deg);
AndroidCalculatorEngine.Preferences.angleUnit.putPreference(preferences, AngleUnit.deg);
AndroidCalculatorEngine.Preferences.scienceNotation.putPreference(preferences, false);
@@ -31,7 +37,12 @@ enum CalculatorMode {
engineer(R.string.cpp_wizard_mode_engineer) {
@Override
protected void apply(@Nonnull SharedPreferences preferences) {
- CalculatorPreferences.Gui.layout.putPreference(preferences, main_calculator);
+ final CalculatorPreferences.Gui.Layout layout = CalculatorPreferences.Gui.layout.getPreference(preferences);
+ if (layout.isOptimized()) {
+ CalculatorPreferences.Gui.layout.putPreference(preferences, main_calculator);
+ } else {
+ CalculatorPreferences.Gui.layout.putPreference(preferences, main_calculator_mobile);
+ }
CalculatorPreferences.Calculations.preferredAngleUnits.putPreference(preferences, AngleUnit.rad);
AndroidCalculatorEngine.Preferences.angleUnit.putPreference(preferences, AngleUnit.rad);
AndroidCalculatorEngine.Preferences.scienceNotation.putPreference(preferences, true);
@@ -55,4 +66,19 @@ enum CalculatorMode {
static CalculatorMode getDefaultMode(){
return engineer;
}
+
+ @Nonnull
+ static CalculatorMode fromGuiLayout(@Nonnull CalculatorPreferences.Gui.Layout layout) {
+ switch (layout) {
+ case main_calculator:
+ case main_cellphone:
+ case main_calculator_mobile:
+ return engineer;
+ case simple:
+ case simple_mobile:
+ return simple;
+ default:
+ return getDefaultMode();
+ }
+ }
}
diff --git a/android-app/src/main/java/org/solovyev/android/calculator/wizard/ChooseLayoutWizardStep.java b/android-app/src/main/java/org/solovyev/android/calculator/wizard/ChooseLayoutWizardStep.java
new file mode 100644
index 00000000..091a2ef8
--- /dev/null
+++ b/android-app/src/main/java/org/solovyev/android/calculator/wizard/ChooseLayoutWizardStep.java
@@ -0,0 +1,111 @@
+package org.solovyev.android.calculator.wizard;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.RadioButton;
+import android.widget.TextView;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.solovyev.android.calculator.R;
+
+import com.actionbarsherlock.app.SherlockFragment;
+
+import static org.solovyev.android.calculator.wizard.CalculatorLayout.big_buttons;
+import static org.solovyev.android.calculator.wizard.CalculatorLayout.getDefaultLayout;
+import static org.solovyev.android.calculator.wizard.CalculatorLayout.optimized;
+
+/**
+ * User: serso
+ * Date: 6/19/13
+ * Time: 12:33 AM
+ */
+public class ChooseLayoutWizardStep extends SherlockFragment {
+
+ /*
+ **********************************************************************
+ *
+ * CONSTANTS
+ *
+ **********************************************************************
+ */
+
+ static final String LAYOUT = "layout";
+
+ /*
+ **********************************************************************
+ *
+ * FIELDS
+ *
+ **********************************************************************
+ */
+
+ @Nullable
+ private RadioButton optimizedRadioButton;
+
+ @Nullable
+ private RadioButton bigButtonsRadioButton;
+
+ private CalculatorLayout layout;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ if(savedInstanceState != null) {
+ layout = (CalculatorLayout) savedInstanceState.getSerializable(LAYOUT);
+ }
+
+ if (layout == null) {
+ layout = (CalculatorLayout) getArguments().getSerializable(LAYOUT);
+ }
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ return inflater.inflate(R.layout.cpp_wizard_step_tablet, null);
+ }
+
+ @Override
+ public void onViewCreated(View root, Bundle savedInstanceState) {
+ super.onViewCreated(root, savedInstanceState);
+
+ optimizedRadioButton = (RadioButton) root.findViewById(R.id.wizard_optimized_radiobutton);
+ bigButtonsRadioButton = (RadioButton) root.findViewById(R.id.wizard_big_buttons_radiobutton);
+
+ switch (layout) {
+ case big_buttons:
+ bigButtonsRadioButton.setChecked(true);
+ optimizedRadioButton.setChecked(false);
+ break;
+ case optimized:
+ bigButtonsRadioButton.setChecked(false);
+ optimizedRadioButton.setChecked(true);
+ break;
+ }
+ }
+
+ @Nonnull
+ CalculatorLayout getSelectedLayout() {
+ CalculatorLayout layout = getDefaultLayout();
+
+ if (bigButtonsRadioButton != null && bigButtonsRadioButton.isChecked()) {
+ layout = big_buttons;
+ } else if (optimizedRadioButton != null && optimizedRadioButton.isChecked()) {
+ layout = optimized;
+ }
+
+ return layout;
+ }
+
+ @Override
+ public void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+
+ outState.putSerializable(LAYOUT, layout);
+ }
+}
diff --git a/android-app/src/main/java/org/solovyev/android/calculator/wizard/ChooseModeWizardStep.java b/android-app/src/main/java/org/solovyev/android/calculator/wizard/ChooseModeWizardStep.java
index 94497a98..538a40da 100644
--- a/android-app/src/main/java/org/solovyev/android/calculator/wizard/ChooseModeWizardStep.java
+++ b/android-app/src/main/java/org/solovyev/android/calculator/wizard/ChooseModeWizardStep.java
@@ -25,7 +25,7 @@ import static org.solovyev.android.calculator.wizard.CalculatorMode.getDefaultMo
* Date: 6/16/13
* Time: 9:59 PM
*/
-public final class ChooseModeWizardStep extends SherlockFragment {
+public class ChooseModeWizardStep extends SherlockFragment {
/*
**********************************************************************
diff --git a/android-app/src/main/java/org/solovyev/android/calculator/wizard/TabletWizardStep.java b/android-app/src/main/java/org/solovyev/android/calculator/wizard/TabletWizardStep.java
deleted file mode 100644
index 9ee551ec..00000000
--- a/android-app/src/main/java/org/solovyev/android/calculator/wizard/TabletWizardStep.java
+++ /dev/null
@@ -1,156 +0,0 @@
-package org.solovyev.android.calculator.wizard;
-
-import android.content.Context;
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.Spinner;
-import android.widget.TextView;
-import com.actionbarsherlock.app.SherlockFragment;
-import org.solovyev.android.calculator.R;
-import org.solovyev.android.list.ListItem;
-import org.solovyev.android.list.ListItemAdapter;
-
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import static org.solovyev.android.calculator.wizard.CalculatorLayout.getDefaultMode;
-
-/**
- * User: serso
- * Date: 6/19/13
- * Time: 12:33 AM
- */
-final class TabletWizardStep extends SherlockFragment {
-
- /*
- **********************************************************************
- *
- * CONSTANTS
- *
- **********************************************************************
- */
-
- static final String LAYOUT = "layout";
-
- /*
- **********************************************************************
- *
- * FIELDS
- *
- **********************************************************************
- */
-
- @Nullable
- private Spinner layoutSpinner;
-
- private CalculatorLayout layout;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- if(savedInstanceState != null) {
- layout = (CalculatorLayout) savedInstanceState.getSerializable(LAYOUT);
- }
-
- if (layout == null) {
- layout = (CalculatorLayout) getArguments().getSerializable(LAYOUT);
- }
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- return inflater.inflate(R.layout.cpp_wizard_step_tablet, null);
- }
-
- @Override
- public void onViewCreated(View root, Bundle savedInstanceState) {
- super.onViewCreated(root, savedInstanceState);
-
- layoutSpinner = (Spinner) root.findViewById(R.id.wizard_layout_spinner);
-
- final List listItems = new ArrayList();
- for (CalculatorLayout layout : CalculatorLayout.values()) {
- listItems.add(new LayoutListItem(layout));
- }
- layoutSpinner.setAdapter(ListItemAdapter.newInstance(getActivity(), listItems));
-
- final int position = Arrays.binarySearch(CalculatorMode.values(), layout);
- if (position >= 0) {
- layoutSpinner.setSelection(position);
- }
- }
-
- @Nonnull
- CalculatorLayout getSelectedLayout() {
- CalculatorLayout layout = getDefaultMode();
-
- if (layoutSpinner != null) {
- final int position = layoutSpinner.getSelectedItemPosition();
-
- if (position >= 0 && position < CalculatorLayout.values().length) {
- layout = CalculatorLayout.values()[position];
- }
- }
-
- return layout;
- }
-
- @Override
- public void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
-
- outState.putSerializable(LAYOUT, layout);
- }
-
- /*
- **********************************************************************
- *
- * STATIC/INNER
- *
- **********************************************************************
- */
-
- private static final class LayoutListItem implements ListItem {
-
- @Nonnull
- private final CalculatorLayout layout;
-
- private LayoutListItem(@Nonnull CalculatorLayout layout) {
- this.layout = layout;
- }
-
- @Nullable
- @Override
- public OnClickAction getOnClickAction() {
- return null;
- }
-
- @Nullable
- @Override
- public OnClickAction getOnLongClickAction() {
- return null;
- }
-
- @Nonnull
- @Override
- public View updateView(@Nonnull Context context, @Nonnull View view) {
- return build(context);
- }
-
- @Nonnull
- @Override
- public View build(@Nonnull Context context) {
- final TextView textView = new TextView(context);
- textView.setText(layout.getNameResId());
- return textView;
- }
- }
-
-
-}
diff --git a/android-app/src/main/java/org/solovyev/android/calculator/wizard/Wizard.java b/android-app/src/main/java/org/solovyev/android/calculator/wizard/Wizard.java
index 81d20e3a..63e7c1a0 100644
--- a/android-app/src/main/java/org/solovyev/android/calculator/wizard/Wizard.java
+++ b/android-app/src/main/java/org/solovyev/android/calculator/wizard/Wizard.java
@@ -32,17 +32,4 @@ public final class Wizard {
throw new IllegalArgumentException("Wizard flow " + name + " is not supported");
}
}
-
- /*
- **********************************************************************
- *
- * STATIC/INNER
- *
- **********************************************************************
- */
-
- static final class Preferences {
- static final Preference mode = ofEnum("mode", CalculatorMode.getDefaultMode(), CalculatorMode.class);
- static final Preference layout = ofEnum("layout", CalculatorLayout.getDefaultMode(), CalculatorLayout.class);
- }
}
diff --git a/android-app/src/main/java/org/solovyev/android/calculator/wizard/WizardStep.java b/android-app/src/main/java/org/solovyev/android/calculator/wizard/WizardStep.java
index 83e6e33a..3a36debf 100644
--- a/android-app/src/main/java/org/solovyev/android/calculator/wizard/WizardStep.java
+++ b/android-app/src/main/java/org/solovyev/android/calculator/wizard/WizardStep.java
@@ -1,17 +1,22 @@
package org.solovyev.android.calculator.wizard;
import android.content.SharedPreferences;
+import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
+
+import org.solovyev.android.App;
+import org.solovyev.android.Views;
import org.solovyev.android.calculator.CalculatorApplication;
+import org.solovyev.android.calculator.CalculatorLocator;
+import org.solovyev.android.calculator.CalculatorPreferences;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static org.solovyev.android.calculator.wizard.ChooseModeWizardStep.MODE;
-import static org.solovyev.android.calculator.wizard.TabletWizardStep.LAYOUT;
-import static org.solovyev.android.calculator.wizard.Wizard.Preferences;
+import static org.solovyev.android.calculator.wizard.ChooseLayoutWizardStep.LAYOUT;
/**
* User: serso
@@ -38,6 +43,40 @@ enum WizardStep {
}
},
+ choose_layout(ChooseLayoutWizardStep.class) {
+ @Override
+ boolean onNext(@Nonnull Fragment f) {
+ final ChooseLayoutWizardStep fragment = (ChooseLayoutWizardStep) f;
+
+ final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(f.getActivity());
+
+ final CalculatorLayout layout = fragment.getSelectedLayout();
+ layout.apply(preferences);
+
+ return true;
+ }
+
+ @Override
+ boolean onPrev(@Nonnull Fragment fragment) {
+ return true;
+ }
+
+ @Nullable
+ @Override
+ Bundle getFragmentArgs() {
+ final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(CalculatorApplication.getInstance());
+
+ final Bundle bundle = new Bundle();
+ bundle.putSerializable(LAYOUT, CalculatorLayout.fromGuiLayout(CalculatorPreferences.Gui.layout.getPreference(preferences)));
+ return bundle;
+ }
+
+ @Override
+ public boolean isVisible() {
+ return Views.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE, App.getApplication().getResources().getConfiguration());
+ }
+ },
+
choose_mode(ChooseModeWizardStep.class) {
@Override
boolean onNext(@Nonnull Fragment f) {
@@ -47,7 +86,6 @@ enum WizardStep {
final CalculatorMode mode = fragment.getSelectedMode();
mode.apply(preferences);
- Preferences.mode.putPreference(preferences, mode);
return true;
}
@@ -63,37 +101,7 @@ enum WizardStep {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(CalculatorApplication.getInstance());
final Bundle bundle = new Bundle();
- bundle.putSerializable(MODE, Preferences.mode.getPreference(preferences));
- return bundle;
- }
- },
-
- tablet(TabletWizardStep.class) {
- @Override
- boolean onNext(@Nonnull Fragment f) {
- final TabletWizardStep fragment = (TabletWizardStep) f;
-
- final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(f.getActivity());
-
- final CalculatorLayout layout = fragment.getSelectedLayout();
- layout.apply(preferences);
- Preferences.layout.putPreference(preferences, layout);
-
- return true;
- }
-
- @Override
- boolean onPrev(@Nonnull Fragment fragment) {
- return true;
- }
-
- @Nullable
- @Override
- Bundle getFragmentArgs() {
- final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(CalculatorApplication.getInstance());
-
- final Bundle bundle = new Bundle();
- bundle.putSerializable(LAYOUT, Preferences.layout.getPreference(preferences));
+ bundle.putSerializable(MODE, CalculatorMode.fromGuiLayout(CalculatorPreferences.Gui.layout.getPreference(preferences)));
return bundle;
}
};
diff --git a/android-app/src/test/java/org/solovyev/android/calculator/wizard/WizardStepTest.java b/android-app/src/test/java/org/solovyev/android/calculator/wizard/WizardStepTest.java
new file mode 100644
index 00000000..3f294fd1
--- /dev/null
+++ b/android-app/src/test/java/org/solovyev/android/calculator/wizard/WizardStepTest.java
@@ -0,0 +1,107 @@
+package org.solovyev.android.calculator.wizard;
+
+import android.app.Activity;
+import android.preference.PreferenceManager;
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentActivity;
+import android.view.Display;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.Robolectric;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.annotation.Config;
+import org.solovyev.android.calculator.CalculatorPreferences;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.solovyev.android.calculator.CalculatorPreferences.Gui.Layout.main_calculator;
+import static org.solovyev.android.calculator.CalculatorPreferences.Gui.Layout.main_calculator_mobile;
+import static org.solovyev.android.calculator.wizard.CalculatorLayout.big_buttons;
+import static org.solovyev.android.calculator.wizard.CalculatorLayout.optimized;
+import static org.solovyev.android.calculator.wizard.CalculatorMode.engineer;
+import static org.solovyev.android.calculator.wizard.CalculatorMode.simple;
+
+@RunWith(RobolectricTestRunner.class)
+public class WizardStepTest {
+
+ private FragmentActivity activity;
+
+ @Before
+ public void setUp() throws Exception {
+ activity = Robolectric.buildActivity(FragmentActivity.class).create().get();
+ }
+
+ @Test
+ public void testFragmentsShouldBeInstantiated() throws Exception {
+ for (WizardStep wizardStep : WizardStep.values()) {
+ Fragment.instantiate(Robolectric.application, wizardStep.getFragmentClass().getName());
+ }
+ }
+
+ @Test
+ public void testShouldBeMainMobileLayout() throws Exception {
+ chooseLayout(big_buttons);
+ chooseMode(engineer);
+
+ assertUiLayoutEquals(main_calculator_mobile);
+ }
+
+ @Test
+ public void testShouldBeMainLayout() throws Exception {
+ chooseLayout(optimized);
+ chooseMode(engineer);
+
+ assertUiLayoutEquals(main_calculator);
+ }
+
+ @Test
+ public void testShouldBeSimpleLayout() throws Exception {
+ chooseLayout(optimized);
+ chooseMode(simple);
+
+ assertUiLayoutEquals(CalculatorPreferences.Gui.Layout.simple);
+ }
+
+ @Test
+ public void testShouldBeSimpleMobileLayout() throws Exception {
+ chooseLayout(big_buttons);
+ chooseMode(simple);
+
+ assertUiLayoutEquals(CalculatorPreferences.Gui.Layout.simple_mobile);
+ }
+
+ private void assertUiLayoutEquals(CalculatorPreferences.Gui.Layout uiLayout) {
+ Assert.assertEquals(uiLayout, CalculatorPreferences.Gui.layout.getPreference(PreferenceManager.getDefaultSharedPreferences(Robolectric.application)));
+ }
+
+ private void chooseMode(CalculatorMode mode) {
+ final ChooseModeWizardStep modeFragment = mock(ChooseModeWizardStep.class);
+ when(modeFragment.getSelectedMode()).thenReturn(mode);
+ when(modeFragment.getActivity()).thenReturn(activity);
+ WizardStep.choose_mode.onNext(modeFragment);
+ }
+
+ private void chooseLayout(CalculatorLayout layout) {
+ final ChooseLayoutWizardStep layoutFragment = mock(ChooseLayoutWizardStep.class);
+ when(layoutFragment.getSelectedLayout()).thenReturn(layout);
+ when(layoutFragment.getActivity()).thenReturn(activity);
+ WizardStep.choose_layout.onNext(layoutFragment);
+ }
+
+ @Config(qualifiers = "large")
+ @Test
+ public void testChooseLayoutShouldBeVisibleForTablet() throws Exception {
+ assertTrue(WizardStep.choose_layout.isVisible());
+ }
+
+ @Config(qualifiers = "normal")
+ @Test
+ public void testChooseLayoutShouldNotBeVisibleForMobile() throws Exception {
+ assertFalse(WizardStep.choose_layout.isVisible());
+ }
+}