1 package net.sf.openrocket.android.rocket;
\r
3 import net.sf.openrocket.rocketcomponent.Rocket;
\r
4 import android.content.Context;
\r
5 import android.util.AttributeSet;
\r
6 import android.widget.ArrayAdapter;
\r
7 import android.widget.Spinner;
\r
9 public class MotorConfigSpinner extends Spinner {
\r
11 public MotorConfigSpinner(Context context, AttributeSet attrs,
\r
12 int defStyle, int mode) {
\r
13 super(context, attrs, defStyle, mode);
\r
16 public MotorConfigSpinner(Context context, AttributeSet attrs, int defStyle) {
\r
17 super(context, attrs, defStyle);
\r
20 public MotorConfigSpinner(Context context, AttributeSet attrs) {
\r
21 super(context, attrs);
\r
24 public MotorConfigSpinner(Context context, int mode) {
\r
25 super(context, mode);
\r
28 public MotorConfigSpinner(Context context) {
\r
32 public void createAdapter(Rocket rocket ) {
\r
34 setAdapter(new MotorConfigSpinnerAdapter(this.getContext(), rocket) );
\r
38 public void setSelectedConfiguration( String configId ) {
\r
39 this.setSelection( ((MotorConfigSpinnerAdapter)getAdapter()).getConfigurationPosition( configId ));
\r
42 public String getSelectedConfiguration() {
\r
43 return ((MotorConfigSpinnerAdapter)getAdapter()).getConfiguration( this.getSelectedItemPosition() );
\r
46 public class MotorConfigSpinnerAdapter extends ArrayAdapter<String> {
\r
48 private String[] motorConfigs;
\r
50 public MotorConfigSpinnerAdapter(Context context, Rocket rocket) {
\r
51 super(context, android.R.layout.simple_spinner_item);
\r
52 setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
\r
53 motorConfigs = rocket.getMotorConfigurationIDs();
\r
55 for( String config: motorConfigs ) {
\r
56 this.add(rocket.getMotorConfigurationNameOrDescription(config));
\r
61 public int getConfigurationPosition(String configId) {
\r
63 int selectedIndex = 0;
\r
65 if ( configId == null ) {
\r
66 return selectedIndex;
\r
69 for( String s : motorConfigs ) {
\r
70 // Note - s may be null since it is a valid id.
\r
71 if ( configId.equals(s) ) {
\r
76 if( selectedIndex >= motorConfigs.length ) {
\r
80 return selectedIndex;
\r
83 public String getConfiguration( int position ) {
\r
84 return motorConfigs[position];
\r