Choose mode wizard fragment
This commit is contained in:
parent
09f2f1307d
commit
e0eabca868
@ -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<String> {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,50 +23,31 @@
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
a:layout_width="wrap_content"
|
||||
a:layout_height="match_parent"
|
||||
a:orientation="vertical">
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="match_parent"
|
||||
a:orientation="vertical"
|
||||
a:gravity="center">
|
||||
|
||||
<RadioGroup
|
||||
a:orientation="horizontal"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="wrap_content"
|
||||
a:gravity="center_vertical|top">
|
||||
<TextView
|
||||
a:layout_width="wrap_content"
|
||||
a:layout_height="wrap_content"
|
||||
a:textAppearance="@android:style/TextAppearance.Large"
|
||||
style="@style/WizardLabel"
|
||||
a:text="Choose mode"
|
||||
a:layout_marginBottom="40dp" />
|
||||
|
||||
<RadioButton a:layout_width="0dp"
|
||||
a:layout_weight="1"
|
||||
a:layout_margin="6dp"
|
||||
a:id="@+id/wizard_simple_mode_radiobutton"
|
||||
a:text="@string/cpp_wizard_mode_simple"
|
||||
a:layout_height="wrap_content"/>
|
||||
<Spinner
|
||||
a:id="@+id/wizard_mode_spinner"
|
||||
a:layout_width="wrap_content"
|
||||
a:layout_height="wrap_content"
|
||||
style="@style/WizardLabel"
|
||||
a:layout_marginBottom="40dp" />
|
||||
|
||||
<RadioButton a:layout_width="0dp"
|
||||
a:layout_weight="1"
|
||||
a:layout_margin="6dp"
|
||||
a:id="@+id/wizard_engineer_mode_radiobutton"
|
||||
a:text="@string/cpp_wizard_mode_engineer"
|
||||
a:layout_height="wrap_content"/>
|
||||
|
||||
</RadioGroup>
|
||||
|
||||
<LinearLayout a:layout_width="match_parent"
|
||||
a:layout_height="wrap_content"
|
||||
a:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
a:layout_width="0dp"
|
||||
a:layout_weight="1"
|
||||
a:layout_height="wrap_content"
|
||||
a:padding="6dp"
|
||||
a:text="@string/cpp_wizard_mode_simple_description"/>
|
||||
|
||||
<TextView
|
||||
a:layout_width="0dp"
|
||||
a:layout_weight="1"
|
||||
a:layout_height="wrap_content"
|
||||
a:padding="6dp"
|
||||
a:text="@string/cpp_wizard_mode_engineer_description"/>
|
||||
|
||||
</LinearLayout>
|
||||
<TextView
|
||||
a:id="@+id/wizard_mode_description"
|
||||
a:layout_width="wrap_content"
|
||||
a:layout_height="wrap_content"
|
||||
style="@style/WizardLabel"
|
||||
a:text="Choose mode" />
|
||||
|
||||
</LinearLayout>
|
||||
|
@ -133,4 +133,9 @@
|
||||
<item>green</item>
|
||||
<item>grey</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="cpp_modes">
|
||||
<item>@string/cpp_wizard_mode_simple</item>
|
||||
<item>@string/cpp_wizard_mode_engineer</item>
|
||||
</string-array>
|
||||
</resources>
|
Loading…
Reference in New Issue
Block a user