project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/TeamCreatorActivity.java
author Xeli
Thu, 11 Aug 2011 14:59:14 +0200
branchhedgeroid
changeset 5542 141c12a23787
parent 5467 88e25840f532
child 5607 d3a3e80ad1da
permissions -rw-r--r--
start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
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});
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
    82
		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
    83
		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
    84
		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
    85
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
		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
    87
		sa = new SimpleAdapter(this, flagsData, R.layout.spinner_textimg_entry, new String[]{"txt", "img"}, new int[]{R.id.spinner_txt, R.id.spinner_img});
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.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
    89
		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
    90
		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
    91
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
    92
		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
    93
		sa = new SimpleAdapter(this, typesData, R.layout.spinner_textimg_entry, new String[]{"txt", "img"}, new int[]{R.id.spinner_txt, R.id.spinner_img});
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
		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
    95
		difficulty.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
    96
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
    97
		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
    98
		sa = new SimpleAdapter(this, hatsData, R.layout.spinner_textimg_entry, new String[]{"txt", "img"}, new int[]{R.id.spinner_txt, R.id.spinner_img});
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.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
   100
		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
   101
			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
   102
		}
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
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, FrontendDataUtils.getVoices(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
   105
		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
   106
		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
   107
		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
   108
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
   109
		adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, FrontendDataUtils.getForts(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
   110
		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
   111
		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
   112
		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
   113
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
   114
		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
   115
		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
   116
			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
   117
			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
   118
			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
   119
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
   120
			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
   121
			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
   122
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
   123
			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
   124
			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
   125
				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
   126
					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
   127
					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
   128
				}
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
			}
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
   130
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
   131
			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
   132
			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
   133
				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
   134
					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
   135
					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
   136
				}
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
			}
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
   138
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
   139
			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
   140
			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
   141
				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
   142
					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
   143
					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
   144
				}
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
			}
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
   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
			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
   148
				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
   149
				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
   150
					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
   151
						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
   152
					}
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
				}
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
   154
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
   155
				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
   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
		}
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
	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
   161
		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
   162
		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
   163
			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
   164
			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
   165
		}
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
	}
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
   167
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
	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
   169
		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
   170
			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
   171
		}
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
	};
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
   174
	
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
   175
	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
   176
		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
   177
		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
   178
		
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
	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
   182
		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
   183
			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
   184
			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
   185
		}
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
	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
   189
		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
   190
			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
   191
		}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
   192
			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
   193
		}
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
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
   196
	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
   197
		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
   198
			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
   199
			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
   200
			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
   201
			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
   202
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
   203
			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
   204
			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
   205
			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
   206
			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
   207
			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
   208
			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
   209
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
   210
			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
   211
			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
   212
			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
   213
			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
   214
				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
   215
			}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
   216
				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
   217
			}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
   218
				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
   219
			}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
   220
				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
   221
			}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
   222
				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
   223
			}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
   224
				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
   225
			}
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
   226
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
   227
			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
   228
				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
   229
				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
   230
				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
   231
				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
   232
			}
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
			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
   234
				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
   235
				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
   236
				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
   237
				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
   238
			} 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
   239
				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
   240
			}
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
		}
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
   242
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
   243
	};
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
   244
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
   245
	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
   246
		@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
   247
		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
   248
			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
   249
			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
   250
			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
   251
			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
   252
			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
   253
		}
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
		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
   256
		}
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
	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
   261
		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
   262
			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
   263
				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
   264
				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
   265
				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
   266
				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
   267
				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
   268
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
   269
				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
   270
				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
   271
				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
   272
				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
   273
				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
   274
			} 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
   275
				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
   276
			} 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
   277
				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
   278
			} 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
   279
				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
   280
			}
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
	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
   285
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
		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
   287
			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
   288
				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
   289
				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
   290
				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
   291
			}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
   292
				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
   293
			}
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
}