project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/TeamSelectionActivity.java
author Xeli
Tue, 09 Aug 2011 20:53:37 +0200
branchhedgeroid
changeset 5506 2b0c4fcde4c6
parent 5467 88e25840f532
child 5532 3d7ac2b3b703
permissions -rw-r--r--
Added color and team hog count
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    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
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    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
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    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
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    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
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    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
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    66
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    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});
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    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
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    71
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    72
	}
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    73
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    74
	private ViewBinder viewBinder = new ViewBinder(){
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    75
		public boolean setViewValue(View view, Object data,	String textRepresentation) {
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    76
			switch(view.getId()){
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    77
			case R.id.teamColor:
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    78
				setTeamColor(view, (Integer)data);
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    79
				return true;
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    80
			case R.id.teamCount:
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    81
				setTeamHogCount((ImageView)view, (Integer)data);
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    82
				return true;
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    83
			default:
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    84
				return false;
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    85
			}
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    86
		}
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    87
	};
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    88
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    89
	private void setTeamColor(int position, int color){
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    90
		View iv = ((RelativeLayout)selectedTeams.getChildAt(position)).findViewById(R.id.teamCount);
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    91
		setTeamColor(iv, color);
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    92
	}
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    93
	private void setTeamColor(View iv, int color){
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    94
		iv.setBackgroundColor(color);
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    95
	}
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    96
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    97
	private void setTeamHogCount(int position, int count){
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    98
		ImageView iv = (ImageView)((RelativeLayout)selectedTeams.getChildAt(position)).findViewById(R.id.teamCount);
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
    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
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   101
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   102
	private void setTeamHogCount(ImageView iv, int count){
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   103
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   104
		switch(count){
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   105
		case 0:
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   106
			iv.setImageResource(R.drawable.teamcount0);
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   107
			break;
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   108
		case 1:
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   109
			iv.setImageResource(R.drawable.teamcount1);
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   110
			break;
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   111
		case 2:
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   112
			iv.setImageResource(R.drawable.teamcount2);
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   113
			break;
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   114
		case 3:
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   115
			iv.setImageResource(R.drawable.teamcount3);
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   116
			break;
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   117
		case 4:
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   118
			iv.setImageResource(R.drawable.teamcount4);
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   119
			break;
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   120
		case 5:
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   121
			iv.setImageResource(R.drawable.teamcount5);
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   122
			break;
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   123
		case 6:
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   124
			iv.setImageResource(R.drawable.teamcount6);
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   125
			break;
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   126
		case 7:
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   127
			iv.setImageResource(R.drawable.teamcount7);
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   128
			break;
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   129
		case 8:
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   130
			iv.setImageResource(R.drawable.teamcount8);
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   131
			break;
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   132
		case 9:
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   133
			iv.setImageResource(R.drawable.teamcount9);
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   134
			break;
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   135
		}
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   136
	}
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   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
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   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
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   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
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   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
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   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
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   202
		HashMap<String, Object> hash = (HashMap<String, Object>) availableTeamsList.get(position);
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   203
		Team t = (Team)hash.get("team");
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   204
		int[] illegalcolors = new int[selectedTeamsList.size()];
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   205
		for(int i = 0; i < selectedTeamsList.size(); i++){
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   206
			illegalcolors[i] = ((Team)selectedTeamsList.get(i).get("team")).color;
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   207
		}
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   208
		t.setRandomColor(illegalcolors);
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   209
		hash.put("color", t.color);
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   210
		hash.put("count", t.hogCount);
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   211
		
2b0c4fcde4c6 Added color and team hog count
Xeli
parents: 5467
diff changeset
   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
}