57 imgFort = (ImageView) findViewById(R.id.imgFort); |
60 imgFort = (ImageView) findViewById(R.id.imgFort); |
58 |
61 |
59 back = (ImageButton) findViewById(R.id.btnBack); |
62 back = (ImageButton) findViewById(R.id.btnBack); |
60 save = (ImageButton) findViewById(R.id.btnSave); |
63 save = (ImageButton) findViewById(R.id.btnSave); |
61 voiceButton = (ImageButton) findViewById(R.id.btnPlay); |
64 voiceButton = (ImageButton) findViewById(R.id.btnPlay); |
62 |
65 |
63 scroller = (ScrollView) findViewById(R.id.scroller); |
66 scroller = (ScrollView) findViewById(R.id.scroller); |
64 |
67 |
65 save.setOnClickListener(saveClicker); |
68 save.setOnClickListener(saveClicker); |
66 |
69 back.setOnClickListener(backClicker); |
|
70 |
67 LinearLayout ll = (LinearLayout) findViewById(R.id.HogsContainer); |
71 LinearLayout ll = (LinearLayout) findViewById(R.id.HogsContainer); |
68 hogs = new ArrayList<RelativeLayout>(ll.getChildCount()); |
72 hogs = new ArrayList<RelativeLayout>(ll.getChildCount()); |
69 for(int i = 0; i < ll.getChildCount(); i++){ |
73 for(int i = 0; i < ll.getChildCount(); i++){ |
70 RelativeLayout team_creation_entry = (RelativeLayout) ll.getChildAt(i); |
74 RelativeLayout team_creation_entry = (RelativeLayout) ll.getChildAt(i); |
71 |
75 |
72 hogHat.add((Spinner)team_creation_entry.findViewById(R.id.spinTeam1)); |
76 hogHat.add((Spinner)team_creation_entry.findViewById(R.id.spinTeam1)); |
73 hogDice.add((ImageButton)team_creation_entry.findViewById(R.id.btnTeam1)); |
77 hogDice.add((ImageButton)team_creation_entry.findViewById(R.id.btnTeam1)); |
74 hogName.add((EditText)team_creation_entry.findViewById(R.id.txtTeam1)); |
78 hogName.add((EditText)team_creation_entry.findViewById(R.id.txtTeam1)); |
75 } |
79 } |
76 ArrayList<HashMap<String, ?>> gravesData = FrontendDataUtils.getGraves(this); |
80 ArrayList<HashMap<String, ?>> gravesData = FrontendDataUtils.getGraves(this); |
77 SimpleAdapter sa = new SimpleAdapter(this, gravesData, R.layout.spinner_textimg_entry, new String[]{"txt", "img"}, new int[]{R.id.spinner_txt, R.id.spinner_img}); |
81 SimpleAdapter sa = new SimpleAdapter(this, gravesData, R.layout.spinner_textimg_entry, new String[]{"txt", "img"}, new int[]{R.id.spinner_txt, R.id.spinner_img}); |
78 sa.setViewBinder(viewBinder); |
82 sa.setViewBinder(viewBinder); |
79 grave.setAdapter(sa); |
83 grave.setAdapter(sa); |
|
84 grave.setOnFocusChangeListener(focusser); |
80 |
85 |
81 ArrayList<HashMap<String, ?>> flagsData = FrontendDataUtils.getFlags(this); |
86 ArrayList<HashMap<String, ?>> flagsData = FrontendDataUtils.getFlags(this); |
82 sa = new SimpleAdapter(this, flagsData, R.layout.spinner_textimg_entry, new String[]{"txt", "img"}, new int[]{R.id.spinner_txt, R.id.spinner_img}); |
87 sa = new SimpleAdapter(this, flagsData, R.layout.spinner_textimg_entry, new String[]{"txt", "img"}, new int[]{R.id.spinner_txt, R.id.spinner_img}); |
83 sa.setViewBinder(viewBinder); |
88 sa.setViewBinder(viewBinder); |
84 flag.setAdapter(sa); |
89 flag.setAdapter(sa); |
85 |
90 flag.setOnFocusChangeListener(focusser); |
|
91 |
86 ArrayList<HashMap<String, ?>> typesData = FrontendDataUtils.getTypes(this); |
92 ArrayList<HashMap<String, ?>> typesData = FrontendDataUtils.getTypes(this); |
87 sa = new SimpleAdapter(this, typesData, R.layout.spinner_textimg_entry, new String[]{"txt", "img"}, new int[]{R.id.spinner_txt, R.id.spinner_img}); |
93 sa = new SimpleAdapter(this, typesData, R.layout.spinner_textimg_entry, new String[]{"txt", "img"}, new int[]{R.id.spinner_txt, R.id.spinner_img}); |
88 difficulty.setAdapter(sa); |
94 difficulty.setAdapter(sa); |
89 |
95 difficulty.setOnFocusChangeListener(focusser); |
|
96 |
90 ArrayList<HashMap<String, ?>> hatsData = FrontendDataUtils.getHats(this); |
97 ArrayList<HashMap<String, ?>> hatsData = FrontendDataUtils.getHats(this); |
91 sa = new SimpleAdapter(this, hatsData, R.layout.spinner_textimg_entry, new String[]{"txt", "img"}, new int[]{R.id.spinner_txt, R.id.spinner_img}); |
98 sa = new SimpleAdapter(this, hatsData, R.layout.spinner_textimg_entry, new String[]{"txt", "img"}, new int[]{R.id.spinner_txt, R.id.spinner_img}); |
92 sa.setViewBinder(viewBinder); |
99 sa.setViewBinder(viewBinder); |
93 for(Spinner spin : hogHat){ |
100 for(Spinner spin : hogHat){ |
94 spin.setAdapter(sa); |
101 spin.setAdapter(sa); |
95 } |
102 } |
96 |
103 |
97 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, FrontendDataUtils.getVoices(this)); |
104 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, FrontendDataUtils.getVoices(this)); |
98 voice.setAdapter(adapter); |
105 voice.setAdapter(adapter); |
|
106 voice.setOnFocusChangeListener(focusser); |
99 voiceButton.setOnClickListener(voiceClicker); |
107 voiceButton.setOnClickListener(voiceClicker); |
100 |
108 |
101 adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, FrontendDataUtils.getForts(this)); |
109 adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, FrontendDataUtils.getForts(this)); |
102 fort.setAdapter(adapter); |
110 fort.setAdapter(adapter); |
103 fort.setOnItemSelectedListener(fortSelector); |
111 fort.setOnItemSelectedListener(fortSelector); |
104 |
112 fort.setOnFocusChangeListener(focusser); |
105 |
113 |
106 Team t = this.getIntent().getParcelableExtra("team"); |
114 Team t = this.getIntent().getParcelableExtra("team"); |
107 if(t != null){ |
115 if(t != null){ |
108 name.setText(t.name); |
116 name.setText(t.name); |
109 int position = ((ArrayAdapter<String>)voice.getAdapter()).getPosition(t.voice); |
117 int position = ((ArrayAdapter<String>)voice.getAdapter()).getPosition(t.voice); |
110 voice.setSelection(position); |
118 voice.setSelection(position); |
|
119 |
111 position = ((ArrayAdapter<String>)fort.getAdapter()).getPosition(t.fort); |
120 position = ((ArrayAdapter<String>)fort.getAdapter()).getPosition(t.fort); |
112 fort.setSelection(position); |
121 fort.setSelection(position); |
113 |
122 |
114 position = 0; |
123 position = 0; |
115 for(HashMap<String, ?> hashmap : typesData){ |
124 for(HashMap<String, ?> hashmap : typesData){ |
116 if(hashmap.get("txt").equals(t.levels[0])){ |
125 if(hashmap.get("txt").equals(t.levels[0])){ |
117 difficulty.setSelection(position); |
126 difficulty.setSelection(position); |
118 break; |
127 break; |
119 } |
128 } |
120 } |
129 } |
121 |
130 |
122 position = 0; |
131 position = 0; |
123 for(HashMap<String, ?> hashmap : gravesData){ |
132 for(HashMap<String, ?> hashmap : gravesData){ |
124 if(hashmap.get("txt").equals(t.grave)){ |
133 if(hashmap.get("txt").equals(t.grave)){ |
125 grave.setSelection(position); |
134 grave.setSelection(position); |
126 break; |
135 break; |
127 } |
136 } |
128 } |
137 } |
129 |
138 |
130 position = 0; |
139 position = 0; |
131 for(HashMap<String, ?> hashmap : typesData){ |
140 for(HashMap<String, ?> hashmap : typesData){ |
132 if(hashmap.get("txt").equals(t.flag)){ |
141 if(hashmap.get("txt").equals(t.flag)){ |
133 flag.setSelection(position); |
142 flag.setSelection(position); |
134 break; |
143 break; |
135 } |
144 } |
136 } |
145 } |
137 |
146 |
138 for(int i = 0; i < Team.maxNumberOfHogs; i++){ |
147 for(int i = 0; i < Team.maxNumberOfHogs; i++){ |
139 position = 0; |
148 position = 0; |
140 for(HashMap<String, ?> hashmap : hatsData){ |
149 for(HashMap<String, ?> hashmap : hatsData){ |
141 if(hashmap.get("txt").equals(t.hats[i])){ |
150 if(hashmap.get("txt").equals(t.hats[i])){ |
142 hogHat.get(i).setSelection(position); |
151 hogHat.get(i).setSelection(position); |
143 } |
152 } |
144 } |
153 } |
145 |
154 |
146 hogName.get(i).setText(t.hogNames[i]); |
155 hogName.get(i).setText(t.hogNames[i]); |
147 } |
156 } |
148 } |
157 } |
149 } |
158 } |
150 |
159 |
153 if(mp != null){ |
162 if(mp != null){ |
154 mp.release(); |
163 mp.release(); |
155 mp = null; |
164 mp = null; |
156 } |
165 } |
157 } |
166 } |
|
167 |
|
168 private OnFocusChangeListener focusser = new OnFocusChangeListener(){ |
|
169 public void onFocusChange(View v, boolean hasFocus) { |
|
170 settingsChanged = true; |
|
171 } |
|
172 |
|
173 }; |
158 |
174 |
|
175 public void onBackPressed(){ |
|
176 onFinishing(); |
|
177 super.onBackPressed(); |
|
178 |
|
179 } |
|
180 |
|
181 private OnClickListener backClicker = new OnClickListener(){ |
|
182 public void onClick(View v){ |
|
183 onFinishing(); |
|
184 finish(); |
|
185 } |
|
186 }; |
|
187 |
|
188 private void onFinishing(){ |
|
189 if(settingsChanged){ |
|
190 setResult(RESULT_OK); |
|
191 }else{ |
|
192 setResult(RESULT_CANCELED); |
|
193 } |
|
194 } |
|
195 |
159 private OnClickListener saveClicker = new OnClickListener(){ |
196 private OnClickListener saveClicker = new OnClickListener(){ |
160 public void onClick(View v) { |
197 public void onClick(View v) { |
|
198 saved = true; |
161 Team team = new Team(); |
199 Team team = new Team(); |
162 team.name = name.getText().toString(); |
200 team.name = name.getText().toString(); |
163 HashMap<String, Object> hashmap = (HashMap<String, Object>) flag.getSelectedItem(); |
201 HashMap<String, Object> hashmap = (HashMap<String, Object>) flag.getSelectedItem(); |
164 |
202 |
165 team.flag = (String)hashmap.get("txt"); |
203 team.flag = (String)hashmap.get("txt"); |
166 team.fort = fort.getSelectedItem().toString(); |
204 team.fort = fort.getSelectedItem().toString(); |
167 hashmap = (HashMap<String, Object>)grave.getSelectedItem(); |
205 hashmap = (HashMap<String, Object>)grave.getSelectedItem(); |
168 team.grave = hashmap.get("txt").toString(); |
206 team.grave = hashmap.get("txt").toString(); |
169 team.hash = "0"; |
207 team.hash = "0"; |
170 team.voice = voice.getSelectedItem().toString(); |
208 team.voice = voice.getSelectedItem().toString(); |
171 |
209 |
172 hashmap = ((HashMap<String, Object>)difficulty.getSelectedItem()); |
210 hashmap = ((HashMap<String, Object>)difficulty.getSelectedItem()); |
173 String levelString = hashmap.get("txt").toString(); |
211 String levelString = hashmap.get("txt").toString(); |
174 int levelInt; |
212 int levelInt; |
175 if(levelString.equals(getString(R.string.human))){ |
213 if(levelString.equals(getString(R.string.human))){ |
176 levelInt = 0; |
214 levelInt = 0; |