author | Xeli |
Tue, 09 Aug 2011 20:53:37 +0200 | |
branch | hedgeroid |
changeset 5506 | 2b0c4fcde4c6 |
parent 5467 | 88e25840f532 |
child 5532 | 3d7ac2b3b703 |
permissions | -rw-r--r-- |
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
1 |
package org.hedgewars.mobile; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
2 |
|
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
3 |
import java.io.File; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
4 |
import java.util.ArrayList; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
5 |
import java.util.HashMap; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
6 |
|
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
7 |
import org.hedgewars.mobile.EngineProtocol.FrontendDataUtils; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
8 |
import org.hedgewars.mobile.EngineProtocol.Team; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
9 |
|
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
10 |
import android.app.Activity; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
11 |
import android.content.Intent; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
12 |
import android.os.Bundle; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
13 |
import android.os.Parcelable; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
14 |
import android.view.ContextMenu; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
15 |
import android.view.MenuItem; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
16 |
import android.view.View; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
17 |
import android.view.View.OnClickListener; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
18 |
import android.widget.AdapterView; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
19 |
import android.widget.AdapterView.AdapterContextMenuInfo; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
20 |
import android.widget.AdapterView.OnItemClickListener; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
21 |
import android.widget.ImageButton; |
5506 | 22 |
import android.widget.ImageView; |
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
23 |
import android.widget.ListView; |
5506 | 24 |
import android.widget.RelativeLayout; |
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
25 |
import android.widget.SimpleAdapter; |
5506 | 26 |
import android.widget.SimpleAdapter.ViewBinder; |
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
27 |
|
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
28 |
public class TeamSelectionActivity extends Activity{ |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
29 |
|
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
30 |
private ImageButton addTeam, back; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
31 |
private ListView availableTeams, selectedTeams; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
32 |
private ArrayList<HashMap<String, ?>> availableTeamsList, selectedTeamsList; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
33 |
private int minTeams = 2; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
34 |
|
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
35 |
public void onCreate(Bundle savedInstanceState){ |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
36 |
super.onCreate(savedInstanceState); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
37 |
|
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
38 |
setContentView(R.layout.team_selector); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
39 |
|
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
40 |
addTeam = (ImageButton) findViewById(R.id.btnAdd); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
41 |
back = (ImageButton) findViewById(R.id.btnBack); |
5506 | 42 |
|
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
43 |
addTeam.setOnClickListener(addTeamClicker); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
44 |
back.setOnClickListener(backClicker); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
45 |
|
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
46 |
availableTeams = (ListView) findViewById(R.id.availableTeams); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
47 |
availableTeamsList = FrontendDataUtils.getTeams(this); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
48 |
SimpleAdapter adapter = new SimpleAdapter(this, availableTeamsList, R.layout.team_selection_entry, new String[]{"txt", "img"}, new int[]{R.id.txtName, R.id.imgDifficulty}); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
49 |
availableTeams.setAdapter(adapter); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
50 |
registerForContextMenu(availableTeams); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
51 |
availableTeams.setOnItemClickListener(availableClicker); |
5506 | 52 |
|
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
53 |
selectedTeams = (ListView) findViewById(R.id.selectedTeams); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
54 |
selectedTeamsList = new ArrayList<HashMap<String, ?>>(); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
55 |
ArrayList<HashMap<String, ?>> toBeRemoved = new ArrayList<HashMap<String, ?>>(); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
56 |
ArrayList<Team> teamsStartGame = getIntent().getParcelableArrayListExtra("teams"); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
57 |
for(HashMap<String, ?> hashmap : availableTeamsList){ |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
58 |
for(Team t : teamsStartGame){ |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
59 |
if(((Team)hashmap.get("team")).equals(t)){ |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
60 |
toBeRemoved.add(hashmap); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
61 |
selectedTeamsList.add(hashmap); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
62 |
} |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
63 |
} |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
64 |
} |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
65 |
for(HashMap<String, ?> hashmap : toBeRemoved) availableTeamsList.remove(hashmap); |
5506 | 66 |
|
67 |
adapter = new SimpleAdapter(this, selectedTeamsList, R.layout.team_selection_entry, new String[]{"txt", "img", "color", "count"}, new int[]{R.id.txtName, R.id.imgDifficulty, R.id.teamColor, R.id.teamCount}); |
|
68 |
adapter.setViewBinder(viewBinder); |
|
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
69 |
selectedTeams.setAdapter(adapter); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
70 |
selectedTeams.setOnItemClickListener(selectedClicker); |
5506 | 71 |
|
72 |
} |
|
73 |
||
74 |
private ViewBinder viewBinder = new ViewBinder(){ |
|
75 |
public boolean setViewValue(View view, Object data, String textRepresentation) { |
|
76 |
switch(view.getId()){ |
|
77 |
case R.id.teamColor: |
|
78 |
setTeamColor(view, (Integer)data); |
|
79 |
return true; |
|
80 |
case R.id.teamCount: |
|
81 |
setTeamHogCount((ImageView)view, (Integer)data); |
|
82 |
return true; |
|
83 |
default: |
|
84 |
return false; |
|
85 |
} |
|
86 |
} |
|
87 |
}; |
|
88 |
||
89 |
private void setTeamColor(int position, int color){ |
|
90 |
View iv = ((RelativeLayout)selectedTeams.getChildAt(position)).findViewById(R.id.teamCount); |
|
91 |
setTeamColor(iv, color); |
|
92 |
} |
|
93 |
private void setTeamColor(View iv, int color){ |
|
94 |
iv.setBackgroundColor(color); |
|
95 |
} |
|
96 |
||
97 |
private void setTeamHogCount(int position, int count){ |
|
98 |
ImageView iv = (ImageView)((RelativeLayout)selectedTeams.getChildAt(position)).findViewById(R.id.teamCount); |
|
99 |
setTeamHogCount(iv, count); |
|
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
100 |
} |
5506 | 101 |
|
102 |
private void setTeamHogCount(ImageView iv, int count){ |
|
103 |
||
104 |
switch(count){ |
|
105 |
case 0: |
|
106 |
iv.setImageResource(R.drawable.teamcount0); |
|
107 |
break; |
|
108 |
case 1: |
|
109 |
iv.setImageResource(R.drawable.teamcount1); |
|
110 |
break; |
|
111 |
case 2: |
|
112 |
iv.setImageResource(R.drawable.teamcount2); |
|
113 |
break; |
|
114 |
case 3: |
|
115 |
iv.setImageResource(R.drawable.teamcount3); |
|
116 |
break; |
|
117 |
case 4: |
|
118 |
iv.setImageResource(R.drawable.teamcount4); |
|
119 |
break; |
|
120 |
case 5: |
|
121 |
iv.setImageResource(R.drawable.teamcount5); |
|
122 |
break; |
|
123 |
case 6: |
|
124 |
iv.setImageResource(R.drawable.teamcount6); |
|
125 |
break; |
|
126 |
case 7: |
|
127 |
iv.setImageResource(R.drawable.teamcount7); |
|
128 |
break; |
|
129 |
case 8: |
|
130 |
iv.setImageResource(R.drawable.teamcount8); |
|
131 |
break; |
|
132 |
case 9: |
|
133 |
iv.setImageResource(R.drawable.teamcount9); |
|
134 |
break; |
|
135 |
} |
|
136 |
} |
|
137 |
||
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
138 |
public void onBackPressed(){ |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
139 |
returnTeams(); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
140 |
super.onBackPressed(); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
141 |
} |
5506 | 142 |
|
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
143 |
private OnClickListener addTeamClicker = new OnClickListener(){ |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
144 |
public void onClick(View v) { |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
145 |
startActivity(new Intent(TeamSelectionActivity.this, TeamCreatorActivity.class)); |
5506 | 146 |
|
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
147 |
} |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
148 |
}; |
5506 | 149 |
|
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
150 |
private OnClickListener backClicker = new OnClickListener(){ |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
151 |
public void onClick(View v){ |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
152 |
returnTeams(); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
153 |
finish(); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
154 |
} |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
155 |
}; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
156 |
|
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
157 |
private OnItemClickListener availableClicker = new OnItemClickListener(){ |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
158 |
public void onItemClick(AdapterView<?> arg0, View arg1, int position,long arg3) { |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
159 |
selectAvailableTeamsItem(position); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
160 |
} |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
161 |
}; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
162 |
private OnItemClickListener selectedClicker = new OnItemClickListener(){ |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
163 |
public void onItemClick(AdapterView<?> arg0, View arg1, int position,long arg3) { |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
164 |
availableTeamsList.add((HashMap<String, ?>) selectedTeamsList.get(position)); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
165 |
selectedTeamsList.remove(position); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
166 |
((SimpleAdapter)availableTeams.getAdapter()).notifyDataSetChanged(); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
167 |
((SimpleAdapter)selectedTeams.getAdapter()).notifyDataSetChanged(); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
168 |
} |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
169 |
|
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
170 |
}; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
171 |
|
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
172 |
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuinfo){ |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
173 |
menu.add(ContextMenu.NONE, 0, ContextMenu.NONE, R.string.select); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
174 |
menu.add(ContextMenu.NONE, 2, ContextMenu.NONE, R.string.edit); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
175 |
menu.add(ContextMenu.NONE, 1, ContextMenu.NONE, R.string.delete); |
5506 | 176 |
|
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
177 |
} |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
178 |
public boolean onContextItemSelected(MenuItem item){ |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
179 |
AdapterView.AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo(); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
180 |
int position = menuInfo.position; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
181 |
switch(item.getItemId()){ |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
182 |
case 0://select |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
183 |
selectAvailableTeamsItem(position); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
184 |
return true; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
185 |
case 1://delete |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
186 |
availableTeamsList.remove(position); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
187 |
((SimpleAdapter)availableTeams.getAdapter()).notifyDataSetChanged(); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
188 |
File f = new File(String.format("%s/%s/%s.xml", TeamSelectionActivity.this.getFilesDir(), Team.DIRECTORY_TEAMS, availableTeamsList.get(position).get("txt"))); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
189 |
f.delete(); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
190 |
return true; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
191 |
case 2://edit |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
192 |
Intent i = new Intent(TeamSelectionActivity.this, TeamCreatorActivity.class); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
193 |
Team t = (Team)availableTeamsList.get(position).get("team"); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
194 |
i.putExtra("team", t); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
195 |
startActivity(i); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
196 |
return true; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
197 |
} |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
198 |
return false; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
199 |
} |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
200 |
|
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
201 |
private void selectAvailableTeamsItem(int position){ |
5506 | 202 |
HashMap<String, Object> hash = (HashMap<String, Object>) availableTeamsList.get(position); |
203 |
Team t = (Team)hash.get("team"); |
|
204 |
int[] illegalcolors = new int[selectedTeamsList.size()]; |
|
205 |
for(int i = 0; i < selectedTeamsList.size(); i++){ |
|
206 |
illegalcolors[i] = ((Team)selectedTeamsList.get(i).get("team")).color; |
|
207 |
} |
|
208 |
t.setRandomColor(illegalcolors); |
|
209 |
hash.put("color", t.color); |
|
210 |
hash.put("count", t.hogCount); |
|
211 |
||
212 |
selectedTeamsList.add(hash); |
|
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
213 |
availableTeamsList.remove(position); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
214 |
((SimpleAdapter)availableTeams.getAdapter()).notifyDataSetChanged(); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
215 |
((SimpleAdapter)selectedTeams.getAdapter()).notifyDataSetChanged(); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
216 |
} |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
217 |
|
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
218 |
private void returnTeams(){ |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
219 |
int teamsCount = selectedTeamsList.size(); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
220 |
if(teamsCount >= minTeams){ |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
221 |
Intent i = new Intent(); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
222 |
Parcelable[] teams = new Parcelable[teamsCount]; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
223 |
for(int x = 0 ; x < teamsCount; x++){ |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
224 |
teams[x] = (Team)selectedTeamsList.get(x).get("team"); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
225 |
} |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
226 |
i.putExtra("teams", teams); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
227 |
setResult(Activity.RESULT_OK, i); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
228 |
}else{ |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
229 |
setResult(Activity.RESULT_CANCELED); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
230 |
} |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
231 |
} |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
232 |
} |