project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/TeamCreatorActivity.java
author Xeli
Fri, 19 Aug 2011 03:33:25 +0200
branchhedgeroid
changeset 5607 d3a3e80ad1da
parent 5542 141c12a23787
child 5613 a7e40b20ce44
permissions -rw-r--r--
Added several graphics
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.io.FileNotFoundException;
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.io.FileOutputStream;
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
import java.io.IOException;
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 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
     8
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
     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 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
    11
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
    12
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.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
    14
import android.graphics.Bitmap;
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.graphics.drawable.Drawable;
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.media.MediaPlayer;
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.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
    18
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
    19
import android.view.View.OnClickListener;
5542
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
    20
import android.view.View.OnFocusChangeListener;
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
    21
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
    22
import android.widget.AdapterView.OnItemSelectedListener;
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.ArrayAdapter;
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
    24
import android.widget.EditText;
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.ImageButton;
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
    26
import android.widget.ImageView;
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
import android.widget.LinearLayout;
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
import android.widget.RelativeLayout;
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
import android.widget.ScrollView;
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
import android.widget.SimpleAdapter;
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
import android.widget.Spinner;
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
import android.widget.TextView;
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
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
public class TeamCreatorActivity 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
    35
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
	private TextView name;
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
	private Spinner difficulty, grave, flag, voice, fort;
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
	private ImageView imgFort;
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
	private ArrayList<ImageButton> hogDice = new ArrayList<ImageButton>();
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
	private ArrayList<Spinner> hogHat = new ArrayList<Spinner>();
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
	private ArrayList<EditText> hogName = new ArrayList<EditText>();
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
    42
	private ImageButton back, save, voiceButton;
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
	private ScrollView scroller;
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
	private MediaPlayer mp = null;
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
	private ArrayList<RelativeLayout> hogs;
5542
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
    46
	private boolean settingsChanged = false;
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
    47
	private boolean saved = false;
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
    48
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
	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
    50
		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
    51
		setContentView(R.layout.team_creation);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
    52
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
		name = (TextView) findViewById(R.id.txtName);
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
		difficulty = (Spinner) findViewById(R.id.spinType);
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
		grave = (Spinner) findViewById(R.id.spinGrave);
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
		flag = (Spinner) findViewById(R.id.spinFlag);
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
		voice = (Spinner) findViewById(R.id.spinVoice);
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
		fort = (Spinner) findViewById(R.id.spinFort);
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
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
		imgFort = (ImageView) findViewById(R.id.imgFort);
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
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
		back = (ImageButton) findViewById(R.id.btnBack);
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
		save = (ImageButton) findViewById(R.id.btnSave);
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
		voiceButton = (ImageButton) findViewById(R.id.btnPlay);
5542
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
    65
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
    66
		scroller = (ScrollView) findViewById(R.id.scroller);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
    67
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
    68
		save.setOnClickListener(saveClicker);
5542
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
    69
		back.setOnClickListener(backClicker);
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
    70
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
    71
		LinearLayout ll = (LinearLayout) findViewById(R.id.HogsContainer);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
    72
		hogs = new ArrayList<RelativeLayout>(ll.getChildCount());
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
    73
		for(int i = 0; i < ll.getChildCount(); 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
    74
			RelativeLayout team_creation_entry = (RelativeLayout) ll.getChildAt(i);
5542
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
    75
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
    76
			hogHat.add((Spinner)team_creation_entry.findViewById(R.id.spinTeam1));
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
    77
			hogDice.add((ImageButton)team_creation_entry.findViewById(R.id.btnTeam1));
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
    78
			hogName.add((EditText)team_creation_entry.findViewById(R.id.txtTeam1));
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
    79
		}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
    80
		ArrayList<HashMap<String, ?>> gravesData = FrontendDataUtils.getGraves(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
    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});
5607
d3a3e80ad1da Added several graphics
Xeli
parents: 5542
diff changeset
    82
		
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
    83
		sa.setViewBinder(viewBinder);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
    84
		grave.setAdapter(sa);
5542
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
    85
		grave.setOnFocusChangeListener(focusser);
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
    86
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
    87
		ArrayList<HashMap<String, ?>> flagsData = FrontendDataUtils.getFlags(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
    88
		sa = new SimpleAdapter(this, flagsData, R.layout.spinner_textimg_entry, new String[]{"txt", "img"}, new int[]{R.id.spinner_txt, R.id.spinner_img});
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
    89
		sa.setViewBinder(viewBinder);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
    90
		flag.setAdapter(sa);
5542
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
    91
		flag.setOnFocusChangeListener(focusser);
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
    92
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
    93
		ArrayList<HashMap<String, ?>> typesData = FrontendDataUtils.getTypes(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
    94
		sa = new SimpleAdapter(this, typesData, R.layout.spinner_textimg_entry, new String[]{"txt", "img"}, new int[]{R.id.spinner_txt, R.id.spinner_img});
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
    95
		difficulty.setAdapter(sa);
5542
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
    96
		difficulty.setOnFocusChangeListener(focusser);
5607
d3a3e80ad1da Added several graphics
Xeli
parents: 5542
diff changeset
    97
		
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
    98
		ArrayList<HashMap<String, ?>> hatsData = FrontendDataUtils.getHats(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
    99
		sa = new SimpleAdapter(this, hatsData, R.layout.spinner_textimg_entry, new String[]{"txt", "img"}, new int[]{R.id.spinner_txt, R.id.spinner_img});
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
		sa.setViewBinder(viewBinder);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   101
		for(Spinner spin : hogHat){
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   102
			spin.setAdapter(sa);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   103
		}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   104
5607
d3a3e80ad1da Added several graphics
Xeli
parents: 5542
diff changeset
   105
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.listview_item, FrontendDataUtils.getVoices(this));
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
   106
		voice.setAdapter(adapter);
5542
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   107
		voice.setOnFocusChangeListener(focusser);
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
   108
		voiceButton.setOnClickListener(voiceClicker);
5542
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   109
5607
d3a3e80ad1da Added several graphics
Xeli
parents: 5542
diff changeset
   110
		adapter = new ArrayAdapter<String>(this, R.layout.listview_item, FrontendDataUtils.getForts(this));
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
   111
		fort.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
   112
		fort.setOnItemSelectedListener(fortSelector);
5542
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   113
		fort.setOnFocusChangeListener(focusser);
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   114
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
   115
		Team t = this.getIntent().getParcelableExtra("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
   116
		if(t != null){
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   117
			name.setText(t.name);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   118
			int position = ((ArrayAdapter<String>)voice.getAdapter()).getPosition(t.voice);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   119
			voice.setSelection(position);
5542
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   120
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
   121
			position = ((ArrayAdapter<String>)fort.getAdapter()).getPosition(t.fort);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   122
			fort.setSelection(position);
5542
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   123
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
   124
			position = 0;
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   125
			for(HashMap<String, ?> hashmap : typesData){
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   126
				if(hashmap.get("txt").equals(t.levels[0])){
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   127
					difficulty.setSelection(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
   128
					break;
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   129
				}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   130
			}
5542
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   131
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
   132
			position = 0;
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   133
			for(HashMap<String, ?> hashmap : gravesData){
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   134
				if(hashmap.get("txt").equals(t.grave)){
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   135
					grave.setSelection(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
   136
					break;
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   137
				}
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
			}
5542
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   139
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
   140
			position = 0;
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
			for(HashMap<String, ?> hashmap : typesData){
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   142
				if(hashmap.get("txt").equals(t.flag)){
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
					flag.setSelection(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
   144
					break;
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
				}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   146
			}
5542
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   147
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
   148
			for(int i = 0; i < Team.maxNumberOfHogs; 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
   149
				position = 0;
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
				for(HashMap<String, ?> hashmap : hatsData){
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
					if(hashmap.get("txt").equals(t.hats[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
   152
						hogHat.get(i).setSelection(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
   153
					}
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
				}
5542
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   155
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
   156
				hogName.get(i).setText(t.hogNames[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
   157
			}
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
		}
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
	}
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
	public void onDestroy(){
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
		super.onDestroy();
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
		if(mp != null){
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
			mp.release();
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
			mp = null;
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
		}
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
	}
5542
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   168
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   169
	private OnFocusChangeListener focusser = new OnFocusChangeListener(){
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   170
		public void onFocusChange(View v, boolean hasFocus) {
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   171
			settingsChanged = true;
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   172
		}
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   173
		
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   174
	};
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
   175
	
5542
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   176
	public void onBackPressed(){
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   177
		onFinishing();
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   178
		super.onBackPressed();
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   179
		
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   180
	}
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   181
	
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   182
	private OnClickListener backClicker = new OnClickListener(){
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   183
		public void onClick(View v){
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   184
			onFinishing();
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   185
			finish();
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   186
		}
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   187
	};
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   188
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   189
	private void onFinishing(){
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   190
		if(settingsChanged){
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   191
			setResult(RESULT_OK);
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   192
		}else{
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   193
			setResult(RESULT_CANCELED);
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   194
		}
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   195
	}
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   196
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
   197
	private OnClickListener saveClicker = 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
   198
		public void onClick(View v) {
5542
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   199
			saved = true;
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
   200
			Team team = new 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
   201
			team.name = name.getText().toString();
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   202
			HashMap<String, Object> hashmap = (HashMap<String, Object>) flag.getSelectedItem();
5542
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   203
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
   204
			team.flag = (String)hashmap.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
   205
			team.fort = fort.getSelectedItem().toString();
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   206
			hashmap = (HashMap<String, Object>)grave.getSelectedItem();
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   207
			team.grave = hashmap.get("txt").toString();
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   208
			team.hash = "0";
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   209
			team.voice = voice.getSelectedItem().toString();
5542
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   210
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
   211
			hashmap =  ((HashMap<String, Object>)difficulty.getSelectedItem());
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   212
			String levelString = hashmap.get("txt").toString();
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
			int levelInt;
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
			if(levelString.equals(getString(R.string.human))){
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
				levelInt = 0;
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
			}else if(levelString.equals(getString(R.string.bot5))){
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
				levelInt = 1;
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
			}else if(levelString.equals(getString(R.string.bot4))){
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
				levelInt = 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
   220
			}else if(levelString.equals(getString(R.string.bot3))){
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
				levelInt = 3;
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
			}else if(levelString.equals(getString(R.string.bot2))){
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
				levelInt = 4;
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
			}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
   225
				levelInt = 5;
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
			}
5542
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   227
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
   228
			for(int i = 0; i < hogName.size(); 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
   229
				team.hogNames[i] = hogName.get(i).getText().toString();
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
				hashmap = (HashMap<String, Object>)hogHat.get(i).getSelectedItem();
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
				team.hats[i] = hashmap.get("txt").toString();
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
				team.levels[i] = levelInt;
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   233
			}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   234
			try {
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   235
				File teamsDir = new File(getFilesDir().getAbsolutePath() + '/' + Team.DIRECTORY_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
   236
				if(!teamsDir.exists()) teamsDir.mkdir();
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   237
				FileOutputStream fos = new FileOutputStream(String.format("%s/%s.xml", teamsDir.getAbsolutePath(), team.name));
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   238
				team.writeToXml(fos);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   239
			} catch (FileNotFoundException e) {
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   240
				e.printStackTrace();
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   241
			}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   242
		}
5542
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   243
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
   244
	};
5542
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   245
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
   246
	private OnItemSelectedListener fortSelector = new OnItemSelectedListener(){
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   247
		@SuppressWarnings("unchecked")
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   248
		public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long arg3) {
5542
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   249
			settingsChanged = true;
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
   250
			String fortName = (String) arg0.getAdapter().getItem(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
   251
			Drawable fortIconDrawable = Drawable.createFromPath(Utils.getDownloadPath(TeamCreatorActivity.this) + "Forts/" + fortName + "L.png");
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   252
			imgFort.setImageDrawable(fortIconDrawable);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   253
			scroller.fullScroll(ScrollView.FOCUS_DOWN);//Scroll the scrollview to the bottom, work around for scollview invalidation (scrolls back to top)
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   254
		}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   255
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   256
		public void onNothingSelected(AdapterView<?> arg0) {
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   257
		}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   258
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   259
	};
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   260
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   261
	private OnClickListener voiceClicker = 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
   262
		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
   263
			try {
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   264
				File dir = new File(String.format("%sSounds/voices/%s", Utils.getDownloadPath(TeamCreatorActivity.this), voice.getSelectedItem()));
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   265
				String 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
   266
				File[] dirs = dir.listFiles();
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   267
				File f = dirs[(int)Math.round(Math.random()*dirs.length)];
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   268
				if(f.getName().endsWith(".ogg"))file = f.getAbsolutePath();
5542
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   269
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
   270
				if(mp == null) mp = new MediaPlayer();
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   271
				else mp.reset();
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   272
				mp.setDataSource(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
   273
				mp.prepare();
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   274
				mp.start();
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   275
			} catch (IllegalArgumentException e) {
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   276
				e.printStackTrace();
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   277
			} catch (IllegalStateException e) {
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   278
				e.printStackTrace();
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   279
			} catch (IOException e) {
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   280
				e.printStackTrace();
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   281
			}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   282
		}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   283
	};
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   284
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   285
	private SimpleAdapter.ViewBinder viewBinder = new SimpleAdapter.ViewBinder() {
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   286
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   287
		public boolean setViewValue(View view, Object data,	String textRepresentation) {
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   288
			if(view instanceof ImageView && data instanceof Bitmap){
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   289
				ImageView v = (ImageView)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
   290
				v.setImageBitmap((Bitmap)data);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   291
				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
   292
			}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
   293
				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
   294
			}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   295
		}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   296
	};
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   297
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   298
}