project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/TeamCreatorActivity.java
author Xeli
Fri, 19 Aug 2011 22:31:59 +0200
branchhedgeroid
changeset 5613 a7e40b20ce44
parent 5607 d3a3e80ad1da
child 5621 ea796c83ea47
permissions -rw-r--r--
small cosmetic change
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;
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    33
import android.widget.Toast;
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
    34
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
    35
public 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
    36
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 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
    38
	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
    39
	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
    40
	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
    41
	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
    42
	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
    43
	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
    44
	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
    45
	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
    46
	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
    47
	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
    48
	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
    49
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    50
	public void onCreate(Bundle savedInstanceState) {
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
    51
		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
    52
		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
    53
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
		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
    55
		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
    56
		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
    57
		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
    58
		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
    59
		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
    60
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
		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
    62
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
    63
		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
    64
		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
    65
		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
    66
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
    67
		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
    68
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
    69
		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
    70
		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
    71
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
    72
		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
    73
		hogs = new ArrayList<RelativeLayout>(ll.getChildCount());
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    74
		for (int i = 0; i < ll.getChildCount(); i++) {
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    75
			RelativeLayout team_creation_entry = (RelativeLayout) ll
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    76
					.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
    77
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    78
			hogHat.add((Spinner) team_creation_entry
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    79
					.findViewById(R.id.spinTeam1));
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    80
			hogDice.add((ImageButton) team_creation_entry
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    81
					.findViewById(R.id.btnTeam1));
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    82
			hogName.add((EditText) team_creation_entry
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    83
					.findViewById(R.id.txtTeam1));
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
    84
		}
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    85
		ArrayList<HashMap<String, ?>> gravesData = FrontendDataUtils
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    86
				.getGraves(this);
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    87
		SimpleAdapter sa = new SimpleAdapter(this, gravesData,
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    88
				R.layout.spinner_textimg_entry, new String[] { "txt", "img" },
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    89
				new int[] { R.id.spinner_txt, R.id.spinner_img });
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    90
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
    91
		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
    92
		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
    93
		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
    94
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    95
		ArrayList<HashMap<String, ?>> flagsData = FrontendDataUtils
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    96
				.getFlags(this);
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    97
		sa = new SimpleAdapter(this, flagsData, R.layout.spinner_textimg_entry,
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    98
				new String[] { "txt", "img" }, new int[] { R.id.spinner_txt,
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    99
						R.id.spinner_img });
5467
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   100
		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
		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
   102
		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
   103
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   104
		ArrayList<HashMap<String, ?>> typesData = FrontendDataUtils
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   105
				.getTypes(this);
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   106
		sa = new SimpleAdapter(this, typesData, R.layout.spinner_textimg_entry,
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   107
				new String[] { "txt", "img" }, new int[] { R.id.spinner_txt,
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   108
						R.id.spinner_img });
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
		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
   110
		difficulty.setOnFocusChangeListener(focusser);
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   111
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   112
		ArrayList<HashMap<String, ?>> hatsData = FrontendDataUtils
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   113
				.getHats(this);
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   114
		sa = new SimpleAdapter(this, hatsData, R.layout.spinner_textimg_entry,
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   115
				new String[] { "txt", "img" }, new int[] { R.id.spinner_txt,
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   116
						R.id.spinner_img });
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
   117
		sa.setViewBinder(viewBinder);
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   118
		for (Spinner spin : hogHat) {
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
   119
			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
   120
		}
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
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   122
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   123
				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
   124
		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
   125
		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
   126
		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
   127
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   128
		adapter = new ArrayAdapter<String>(this, R.layout.listview_item,
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   129
				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
   130
		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
   131
		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
   132
		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
   133
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
   134
		Team t = this.getIntent().getParcelableExtra("team");
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   135
		if (t != null) {
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
   136
			name.setText(t.name);
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   137
			int position = ((ArrayAdapter<String>) voice.getAdapter())
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   138
					.getPosition(t.voice);
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
			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
   140
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   141
			position = ((ArrayAdapter<String>) fort.getAdapter())
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   142
					.getPosition(t.fort);
5467
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   143
			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
   144
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
   145
			position = 0;
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   146
			for (HashMap<String, ?> hashmap : typesData) {
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   147
				if (hashmap.get("txt").equals(t.levels[0])) {
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
					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
   149
					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
   150
				}
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
			}
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
   152
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
   153
			position = 0;
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   154
			for (HashMap<String, ?> hashmap : gravesData) {
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   155
				if (hashmap.get("txt").equals(t.grave)) {
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
					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
   157
					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
   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
			}
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
   160
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
   161
			position = 0;
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   162
			for (HashMap<String, ?> hashmap : typesData) {
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   163
				if (hashmap.get("txt").equals(t.flag)) {
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
   164
					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
   165
					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
   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
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   169
			for (int i = 0; i < Team.maxNumberOfHogs; i++) {
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
   170
				position = 0;
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   171
				for (HashMap<String, ?> hashmap : hatsData) {
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   172
					if (hashmap.get("txt").equals(t.hats[i])) {
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
   173
						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
   174
					}
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
5467
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   177
				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
   178
			}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   179
		}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   180
	}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   181
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   182
	public void onDestroy() {
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
   183
		super.onDestroy();
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   184
		if (mp != null) {
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
   185
			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
   186
			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
   187
		}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   188
	}
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
   189
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   190
	private OnFocusChangeListener focusser = new OnFocusChangeListener() {
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
   191
		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
   192
			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
   193
		}
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   194
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
   195
	};
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   196
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   197
	public void onBackPressed() {
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
		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
   199
		super.onBackPressed();
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   200
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
   201
	}
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   202
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   203
	private OnClickListener backClicker = new OnClickListener() {
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   204
		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
   205
			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
   206
			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
   207
		}
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
   208
	};
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
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   210
	private void onFinishing() {
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   211
		if (settingsChanged) {
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
   212
			setResult(RESULT_OK);
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   213
		} else {
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
   214
			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
   215
		}
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
   216
	}
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
   217
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   218
	private OnClickListener saveClicker = new OnClickListener() {
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
   219
		public void onClick(View v) {
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   220
			Toast.makeText(TeamCreatorActivity.this, R.string.saved, Toast.LENGTH_SHORT);
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
   221
			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
   222
			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
   223
			team.name = name.getText().toString();
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   224
			HashMap<String, Object> hashmap = (HashMap<String, Object>) flag
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   225
					.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
   226
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   227
			team.flag = (String) hashmap.get("txt");
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
			team.fort = fort.getSelectedItem().toString();
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   229
			hashmap = (HashMap<String, Object>) grave.getSelectedItem();
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
   230
			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
   231
			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
   232
			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
   233
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   234
			hashmap = ((HashMap<String, Object>) difficulty.getSelectedItem());
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
   235
			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
   236
			int levelInt;
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   237
			if (levelString.equals(getString(R.string.human))) {
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
   238
				levelInt = 0;
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   239
			} else if (levelString.equals(getString(R.string.bot5))) {
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
   240
				levelInt = 1;
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   241
			} else if (levelString.equals(getString(R.string.bot4))) {
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
   242
				levelInt = 2;
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   243
			} else if (levelString.equals(getString(R.string.bot3))) {
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
				levelInt = 3;
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   245
			} else if (levelString.equals(getString(R.string.bot2))) {
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
				levelInt = 4;
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   247
			} else {
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
   248
				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
   249
			}
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
   250
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   251
			for (int i = 0; i < hogName.size(); i++) {
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
   252
				team.hogNames[i] = hogName.get(i).getText().toString();
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   253
				hashmap = (HashMap<String, Object>) hogHat.get(i)
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   254
						.getSelectedItem();
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
   255
				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
   256
				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
   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
			try {
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   259
				File teamsDir = new File(getFilesDir().getAbsolutePath() + '/'
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   260
						+ Team.DIRECTORY_TEAMS);
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   261
				if (!teamsDir.exists())
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   262
					teamsDir.mkdir();
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   263
				FileOutputStream fos = new FileOutputStream(String.format(
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   264
						"%s/%s.xml", teamsDir.getAbsolutePath(), team.name));
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
   265
				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
   266
			} 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
   267
				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
   268
			}
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
		}
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
   270
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
   271
	};
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
   272
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   273
	private OnItemSelectedListener fortSelector = new OnItemSelectedListener() {
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
   274
		@SuppressWarnings("unchecked")
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   275
		public void onItemSelected(AdapterView<?> arg0, View arg1,
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   276
				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
   277
			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
   278
			String fortName = (String) arg0.getAdapter().getItem(position);
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   279
			Drawable fortIconDrawable = Drawable.createFromPath(Utils
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   280
					.getDownloadPath(TeamCreatorActivity.this)
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   281
					+ "Forts/"
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   282
					+ fortName + "L.png");
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
   283
			imgFort.setImageDrawable(fortIconDrawable);
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   284
			scroller.fullScroll(ScrollView.FOCUS_DOWN);// Scroll the scrollview
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   285
														// to the bottom, work
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   286
														// around for scollview
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   287
														// invalidation (scrolls
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   288
														// back to top)
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
   289
		}
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
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
		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
   292
		}
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
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   296
	private OnClickListener voiceClicker = new OnClickListener() {
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
   297
		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
   298
			try {
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   299
				File dir = new File(String.format("%sSounds/voices/%s",
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   300
						Utils.getDownloadPath(TeamCreatorActivity.this),
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   301
						voice.getSelectedItem()));
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
   302
				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
   303
				File[] dirs = dir.listFiles();
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   304
				File f = dirs[(int) Math.round(Math.random() * dirs.length)];
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   305
				if (f.getName().endsWith(".ogg"))
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   306
					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
   307
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   308
				if (mp == null)
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   309
					mp = new MediaPlayer();
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   310
				else
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   311
					mp.reset();
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
   312
				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
   313
				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
   314
				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
   315
			} 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
   316
				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
   317
			} 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
   318
				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
   319
			} 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
   320
				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
   321
			}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   322
		}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   323
	};
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   324
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   325
	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
   326
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   327
		public boolean setViewValue(View view, Object data,
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   328
				String textRepresentation) {
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   329
			if (view instanceof ImageView && data instanceof Bitmap) {
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   330
				ImageView v = (ImageView) view;
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   331
				v.setImageBitmap((Bitmap) data);
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
   332
				return true;
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   333
			} else {
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
   334
				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
   335
			}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   336
		}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   337
	};
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   338
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   339
}