project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/TeamCreatorActivity.java
author Xeli
Sun, 21 Aug 2011 16:25:18 +0200
branchhedgeroid
changeset 5621 ea796c83ea47
parent 5613 a7e40b20ce44
child 5627 ce2d92589cbc
permissions -rw-r--r--
added licenses
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5621
ea796c83ea47 added licenses
Xeli
parents: 5613
diff changeset
     1
/*
ea796c83ea47 added licenses
Xeli
parents: 5613
diff changeset
     2
 * Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game
ea796c83ea47 added licenses
Xeli
parents: 5613
diff changeset
     3
 * Copyright (c) 2011 Richard Deurwaarder <xeli@xelification.com>
ea796c83ea47 added licenses
Xeli
parents: 5613
diff changeset
     4
 *
ea796c83ea47 added licenses
Xeli
parents: 5613
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
ea796c83ea47 added licenses
Xeli
parents: 5613
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
ea796c83ea47 added licenses
Xeli
parents: 5613
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
ea796c83ea47 added licenses
Xeli
parents: 5613
diff changeset
     8
 *
ea796c83ea47 added licenses
Xeli
parents: 5613
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
ea796c83ea47 added licenses
Xeli
parents: 5613
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ea796c83ea47 added licenses
Xeli
parents: 5613
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ea796c83ea47 added licenses
Xeli
parents: 5613
diff changeset
    12
 * GNU General Public License for more details.
ea796c83ea47 added licenses
Xeli
parents: 5613
diff changeset
    13
 *
ea796c83ea47 added licenses
Xeli
parents: 5613
diff changeset
    14
 * You should have received a copy of the GNU General Public License
ea796c83ea47 added licenses
Xeli
parents: 5613
diff changeset
    15
 * along with this program; if not, write to the Free Software
ea796c83ea47 added licenses
Xeli
parents: 5613
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
ea796c83ea47 added licenses
Xeli
parents: 5613
diff changeset
    17
 */
ea796c83ea47 added licenses
Xeli
parents: 5613
diff changeset
    18
ea796c83ea47 added licenses
Xeli
parents: 5613
diff changeset
    19
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
    20
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
    21
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 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
    23
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
    24
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
    25
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
    26
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
    27
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
    28
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 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
    30
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
    31
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.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
    33
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
    34
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
    35
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
    36
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
    37
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
    38
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
    39
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
    40
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
    41
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
    42
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
    43
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
    44
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
    45
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
    46
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
    47
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
    48
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
    49
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
    50
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
    51
import android.widget.TextView;
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    52
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
    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
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
    55
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
	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
    57
	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
    58
	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
    59
	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
    60
	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
    61
	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
    62
	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
    63
	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
    64
	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
    65
	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
    66
	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
    67
	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
    68
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    69
	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
    70
		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
    71
		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
    72
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
		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
    74
		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
    75
		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
    76
		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
    77
		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
    78
		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
    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
		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
    81
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
		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
    83
		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
    84
		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
    85
5467
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
    86
		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
    87
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
		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
    89
		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
    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
		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
    92
		hogs = new ArrayList<RelativeLayout>(ll.getChildCount());
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    93
		for (int i = 0; i < ll.getChildCount(); i++) {
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    94
			RelativeLayout team_creation_entry = (RelativeLayout) ll
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    95
					.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
    96
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    97
			hogHat.add((Spinner) team_creation_entry
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    98
					.findViewById(R.id.spinTeam1));
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    99
			hogDice.add((ImageButton) team_creation_entry
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   100
					.findViewById(R.id.btnTeam1));
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   101
			hogName.add((EditText) team_creation_entry
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   102
					.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
   103
		}
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   104
		ArrayList<HashMap<String, ?>> gravesData = FrontendDataUtils
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   105
				.getGraves(this);
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   106
		SimpleAdapter sa = new SimpleAdapter(this, gravesData,
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   107
				R.layout.spinner_textimg_entry, new String[] { "txt", "img" },
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   108
				new int[] { R.id.spinner_txt, R.id.spinner_img });
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   109
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
   110
		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
   111
		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
   112
		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
   113
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   114
		ArrayList<HashMap<String, ?>> flagsData = FrontendDataUtils
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   115
				.getFlags(this);
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   116
		sa = new SimpleAdapter(this, flagsData, R.layout.spinner_textimg_entry,
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   117
				new String[] { "txt", "img" }, new int[] { R.id.spinner_txt,
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   118
						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
   119
		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
   120
		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
   121
		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
   122
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   123
		ArrayList<HashMap<String, ?>> typesData = FrontendDataUtils
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   124
				.getTypes(this);
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   125
		sa = new SimpleAdapter(this, typesData, R.layout.spinner_textimg_entry,
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   126
				new String[] { "txt", "img" }, new int[] { R.id.spinner_txt,
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   127
						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
   128
		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
   129
		difficulty.setOnFocusChangeListener(focusser);
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   130
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   131
		ArrayList<HashMap<String, ?>> hatsData = FrontendDataUtils
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   132
				.getHats(this);
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   133
		sa = new SimpleAdapter(this, hatsData, R.layout.spinner_textimg_entry,
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   134
				new String[] { "txt", "img" }, new int[] { R.id.spinner_txt,
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   135
						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
   136
		sa.setViewBinder(viewBinder);
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   137
		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
   138
			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
   139
		}
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
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   141
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   142
				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
   143
		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
   144
		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
   145
		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
   146
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   147
		adapter = new ArrayAdapter<String>(this, R.layout.listview_item,
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   148
				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
   149
		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
   150
		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
   151
		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
   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
		Team t = this.getIntent().getParcelableExtra("team");
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   154
		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
   155
			name.setText(t.name);
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   156
			int position = ((ArrayAdapter<String>) voice.getAdapter())
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   157
					.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
   158
			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
   159
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   160
			position = ((ArrayAdapter<String>) fort.getAdapter())
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   161
					.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
   162
			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
   163
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
			position = 0;
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   165
			for (HashMap<String, ?> hashmap : typesData) {
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   166
				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
   167
					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
   168
					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
   169
				}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   170
			}
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
   171
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
   172
			position = 0;
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   173
			for (HashMap<String, ?> hashmap : gravesData) {
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   174
				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
   175
					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
   176
					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
   177
				}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   178
			}
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
   179
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
   180
			position = 0;
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   181
			for (HashMap<String, ?> hashmap : typesData) {
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   182
				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
   183
					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
   184
					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
   185
				}
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
			}
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
   187
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   188
			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
   189
				position = 0;
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   190
				for (HashMap<String, ?> hashmap : hatsData) {
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   191
					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
   192
						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
   193
					}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   194
				}
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
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
				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
   197
			}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   198
		}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   199
	}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   200
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   201
	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
   202
		super.onDestroy();
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   203
		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
   204
			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
   205
			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
   206
		}
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
	}
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
   208
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   209
	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
   210
		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
   211
			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
   212
		}
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   213
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
	};
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   215
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   216
	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
   217
		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
   218
		super.onBackPressed();
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   219
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
   220
	}
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   221
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   222
	private OnClickListener backClicker = new OnClickListener() {
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   223
		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
   224
			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
   225
			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
   226
		}
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   227
	};
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
   228
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   229
	private void onFinishing() {
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   230
		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
   231
			setResult(RESULT_OK);
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   232
		} 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
   233
			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
   234
		}
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
   235
	}
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
   236
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   237
	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
   238
		public void onClick(View v) {
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   239
			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
   240
			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
   241
			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
   242
			team.name = name.getText().toString();
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   243
			HashMap<String, Object> hashmap = (HashMap<String, Object>) flag
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   244
					.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
   245
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   246
			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
   247
			team.fort = fort.getSelectedItem().toString();
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   248
			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
   249
			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
   250
			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
   251
			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
   252
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   253
			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
   254
			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
   255
			int levelInt;
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   256
			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
   257
				levelInt = 0;
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   258
			} 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
   259
				levelInt = 1;
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   260
			} 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
   261
				levelInt = 2;
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   262
			} 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
   263
				levelInt = 3;
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   264
			} 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
   265
				levelInt = 4;
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   266
			} 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
   267
				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
   268
			}
5542
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
   269
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   270
			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
   271
				team.hogNames[i] = hogName.get(i).getText().toString();
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   272
				hashmap = (HashMap<String, Object>) hogHat.get(i)
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   273
						.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
   274
				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
   275
				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
   276
			}
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
			try {
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   278
				File teamsDir = new File(getFilesDir().getAbsolutePath() + '/'
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   279
						+ Team.DIRECTORY_TEAMS);
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   280
				if (!teamsDir.exists())
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   281
					teamsDir.mkdir();
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   282
				FileOutputStream fos = new FileOutputStream(String.format(
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   283
						"%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
   284
				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
   285
			} 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
   286
				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
   287
			}
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
		}
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
   289
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
   290
	};
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
   291
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   292
	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
   293
		@SuppressWarnings("unchecked")
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   294
		public void onItemSelected(AdapterView<?> arg0, View arg1,
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   295
				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
   296
			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
   297
			String fortName = (String) arg0.getAdapter().getItem(position);
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   298
			Drawable fortIconDrawable = Drawable.createFromPath(Utils
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   299
					.getDownloadPath(TeamCreatorActivity.this)
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   300
					+ "Forts/"
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   301
					+ 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
   302
			imgFort.setImageDrawable(fortIconDrawable);
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   303
			scroller.fullScroll(ScrollView.FOCUS_DOWN);// Scroll the scrollview
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   304
														// to the bottom, work
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   305
														// around for scollview
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   306
														// invalidation (scrolls
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   307
														// 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
   308
		}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   309
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   310
		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
   311
		}
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
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
	};
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
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   315
	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
   316
		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
   317
			try {
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   318
				File dir = new File(String.format("%sSounds/voices/%s",
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   319
						Utils.getDownloadPath(TeamCreatorActivity.this),
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   320
						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
   321
				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
   322
				File[] dirs = dir.listFiles();
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   323
				File f = dirs[(int) Math.round(Math.random() * dirs.length)];
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   324
				if (f.getName().endsWith(".ogg"))
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   325
					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
   326
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   327
				if (mp == null)
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   328
					mp = new MediaPlayer();
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   329
				else
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   330
					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
   331
				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
   332
				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
   333
				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
   334
			} 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
   335
				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
   336
			} 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
   337
				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
   338
			} 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
   339
				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
   340
			}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   341
		}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   342
	};
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   343
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   344
	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
   345
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   346
		public boolean setViewValue(View view, Object data,
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   347
				String textRepresentation) {
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   348
			if (view instanceof ImageView && data instanceof Bitmap) {
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   349
				ImageView v = (ImageView) view;
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   350
				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
   351
				return true;
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   352
			} 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
   353
				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
   354
			}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   355
		}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   356
	};
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   357
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   358
}