From e0eabca868e88c4a87a64836a5214d3568f7d418 Mon Sep 17 00:00:00 2001 From: serso Date: Thu, 29 Jan 2015 20:17:07 +0100 Subject: [PATCH] Choose mode wizard fragment --- .../wizard/ChooseModeWizardStep.java | 77 ++++++++++++------- .../layout/cpp_wizard_step_choose_mode.xml | 65 ++++++---------- android-app/src/main/res/values/arrays.xml | 5 ++ 3 files changed, 76 insertions(+), 71 deletions(-) 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 4ce824be..7bfd99f5 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 @@ -22,15 +22,18 @@ 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.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Spinner; +import android.widget.TextView; import org.solovyev.android.calculator.R; import javax.annotation.Nonnull; -import javax.annotation.Nullable; import static org.solovyev.android.calculator.wizard.CalculatorMode.*; @@ -39,7 +42,7 @@ import static org.solovyev.android.calculator.wizard.CalculatorMode.*; * Date: 6/16/13 * Time: 9:59 PM */ -public class ChooseModeWizardStep extends WizardFragment { +public class ChooseModeWizardStep extends WizardFragment implements AdapterView.OnItemSelectedListener { /* ********************************************************************** @@ -59,11 +62,8 @@ public class ChooseModeWizardStep extends WizardFragment { ********************************************************************** */ - @Nullable - private RadioButton simpleModeRadioButton; - - @Nullable - private RadioButton engineerModeRadioButton; + private Spinner spinner; + private TextView description; private CalculatorMode mode; @@ -97,34 +97,25 @@ public class ChooseModeWizardStep extends WizardFragment { public void onViewCreated(View root, Bundle savedInstanceState) { super.onViewCreated(root, savedInstanceState); - simpleModeRadioButton = (RadioButton) root.findViewById(R.id.wizard_simple_mode_radiobutton); - engineerModeRadioButton = (RadioButton) root.findViewById(R.id.wizard_engineer_mode_radiobutton); + spinner = (Spinner) root.findViewById(R.id.wizard_mode_spinner); + spinner.setAdapter(new MyArrayAdapter(getActivity())); + spinner.setOnItemSelectedListener(this); - switch (mode) { - case simple: - simpleModeRadioButton.setChecked(true); - engineerModeRadioButton.setChecked(false); - break; - case engineer: - simpleModeRadioButton.setChecked(false); - engineerModeRadioButton.setChecked(true); - break; - } + description = (TextView) root.findViewById(R.id.wizard_mode_description); + updateDescription(); + } + + private void updateDescription() { + description.setText(mode == simple ? R.string.cpp_wizard_mode_simple_description : R.string.cpp_wizard_mode_engineer_description); } @Nonnull CalculatorMode getSelectedMode() { - CalculatorMode mode = getDefaultMode(); - - if (simpleModeRadioButton != null && simpleModeRadioButton.isChecked()) { - mode = simple; + if (spinner != null) { + return mode; } - if (engineerModeRadioButton != null && engineerModeRadioButton.isChecked()) { - mode = engineer; - } - - return mode; + return getDefaultMode(); } @Override @@ -133,4 +124,32 @@ public class ChooseModeWizardStep extends WizardFragment { outState.putSerializable(MODE, mode); } + + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + mode = position == 0 ? simple : engineer; + updateDescription(); + } + + @Override + public void onNothingSelected(AdapterView parent) { + + } + + private static final class MyArrayAdapter extends ArrayAdapter { + + public MyArrayAdapter(Context context) { + super(context, android.R.layout.simple_spinner_item, context.getResources().getStringArray(R.array.cpp_modes)); + setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + final View view = super.getView(position, convertView, parent); + if (view instanceof TextView) { + ((TextView) view).setTextAppearance(getContext(), android.R.style.TextAppearance_Large); + } + return view; + } + } } diff --git a/android-app/src/main/res/layout/cpp_wizard_step_choose_mode.xml b/android-app/src/main/res/layout/cpp_wizard_step_choose_mode.xml index 61364865..e0300a4c 100644 --- a/android-app/src/main/res/layout/cpp_wizard_step_choose_mode.xml +++ b/android-app/src/main/res/layout/cpp_wizard_step_choose_mode.xml @@ -23,50 +23,31 @@ --> + a:layout_width="match_parent" + a:layout_height="match_parent" + a:orientation="vertical" + a:gravity="center"> - + - + - - - - - - - - - - - + diff --git a/android-app/src/main/res/values/arrays.xml b/android-app/src/main/res/values/arrays.xml index f133323a..29da5a3d 100644 --- a/android-app/src/main/res/values/arrays.xml +++ b/android-app/src/main/res/values/arrays.xml @@ -133,4 +133,9 @@ green grey + + + @string/cpp_wizard_mode_simple + @string/cpp_wizard_mode_engineer + \ No newline at end of file