Choose mode wizard fragment
This commit is contained in:
parent
09f2f1307d
commit
e0eabca868
@ -22,15 +22,18 @@
|
|||||||
|
|
||||||
package org.solovyev.android.calculator.wizard;
|
package org.solovyev.android.calculator.wizard;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
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 org.solovyev.android.calculator.R;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import static org.solovyev.android.calculator.wizard.CalculatorMode.*;
|
import static org.solovyev.android.calculator.wizard.CalculatorMode.*;
|
||||||
|
|
||||||
@ -39,7 +42,7 @@ import static org.solovyev.android.calculator.wizard.CalculatorMode.*;
|
|||||||
* Date: 6/16/13
|
* Date: 6/16/13
|
||||||
* Time: 9:59 PM
|
* 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 Spinner spinner;
|
||||||
private RadioButton simpleModeRadioButton;
|
private TextView description;
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private RadioButton engineerModeRadioButton;
|
|
||||||
|
|
||||||
private CalculatorMode mode;
|
private CalculatorMode mode;
|
||||||
|
|
||||||
@ -97,40 +97,59 @@ public class ChooseModeWizardStep extends WizardFragment {
|
|||||||
public void onViewCreated(View root, Bundle savedInstanceState) {
|
public void onViewCreated(View root, Bundle savedInstanceState) {
|
||||||
super.onViewCreated(root, savedInstanceState);
|
super.onViewCreated(root, savedInstanceState);
|
||||||
|
|
||||||
simpleModeRadioButton = (RadioButton) root.findViewById(R.id.wizard_simple_mode_radiobutton);
|
spinner = (Spinner) root.findViewById(R.id.wizard_mode_spinner);
|
||||||
engineerModeRadioButton = (RadioButton) root.findViewById(R.id.wizard_engineer_mode_radiobutton);
|
spinner.setAdapter(new MyArrayAdapter(getActivity()));
|
||||||
|
spinner.setOnItemSelectedListener(this);
|
||||||
|
|
||||||
switch (mode) {
|
description = (TextView) root.findViewById(R.id.wizard_mode_description);
|
||||||
case simple:
|
updateDescription();
|
||||||
simpleModeRadioButton.setChecked(true);
|
|
||||||
engineerModeRadioButton.setChecked(false);
|
|
||||||
break;
|
|
||||||
case engineer:
|
|
||||||
simpleModeRadioButton.setChecked(false);
|
|
||||||
engineerModeRadioButton.setChecked(true);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateDescription() {
|
||||||
|
description.setText(mode == simple ? R.string.cpp_wizard_mode_simple_description : R.string.cpp_wizard_mode_engineer_description);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
CalculatorMode getSelectedMode() {
|
CalculatorMode getSelectedMode() {
|
||||||
CalculatorMode mode = getDefaultMode();
|
if (spinner != null) {
|
||||||
|
|
||||||
if (simpleModeRadioButton != null && simpleModeRadioButton.isChecked()) {
|
|
||||||
mode = simple;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (engineerModeRadioButton != null && engineerModeRadioButton.isChecked()) {
|
|
||||||
mode = engineer;
|
|
||||||
}
|
|
||||||
|
|
||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return getDefaultMode();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSaveInstanceState(Bundle outState) {
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
|
|
||||||
outState.putSerializable(MODE, mode);
|
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"
|
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:layout_width="wrap_content"
|
|
||||||
a:layout_height="match_parent"
|
|
||||||
a:orientation="vertical">
|
|
||||||
|
|
||||||
<RadioGroup
|
|
||||||
a:orientation="horizontal"
|
|
||||||
a:layout_width="match_parent"
|
a:layout_width="match_parent"
|
||||||
a:layout_height="wrap_content"
|
a:layout_height="match_parent"
|
||||||
a:gravity="center_vertical|top">
|
a:orientation="vertical"
|
||||||
|
a:gravity="center">
|
||||||
<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"/>
|
|
||||||
|
|
||||||
<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
|
<TextView
|
||||||
a:layout_width="0dp"
|
a:layout_width="wrap_content"
|
||||||
a:layout_weight="1"
|
|
||||||
a:layout_height="wrap_content"
|
a:layout_height="wrap_content"
|
||||||
a:padding="6dp"
|
a:textAppearance="@android:style/TextAppearance.Large"
|
||||||
a:text="@string/cpp_wizard_mode_simple_description"/>
|
style="@style/WizardLabel"
|
||||||
|
a:text="Choose mode"
|
||||||
|
a:layout_marginBottom="40dp" />
|
||||||
|
|
||||||
|
<Spinner
|
||||||
|
a:id="@+id/wizard_mode_spinner"
|
||||||
|
a:layout_width="wrap_content"
|
||||||
|
a:layout_height="wrap_content"
|
||||||
|
style="@style/WizardLabel"
|
||||||
|
a:layout_marginBottom="40dp" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
a:layout_width="0dp"
|
a:id="@+id/wizard_mode_description"
|
||||||
a:layout_weight="1"
|
a:layout_width="wrap_content"
|
||||||
a:layout_height="wrap_content"
|
a:layout_height="wrap_content"
|
||||||
a:padding="6dp"
|
style="@style/WizardLabel"
|
||||||
a:text="@string/cpp_wizard_mode_engineer_description"/>
|
a:text="Choose mode" />
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
@ -133,4 +133,9 @@
|
|||||||
<item>green</item>
|
<item>green</item>
|
||||||
<item>grey</item>
|
<item>grey</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="cpp_modes">
|
||||||
|
<item>@string/cpp_wizard_mode_simple</item>
|
||||||
|
<item>@string/cpp_wizard_mode_engineer</item>
|
||||||
|
</string-array>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in New Issue
Block a user