project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/TeamCreatorActivity.java
author Xeli
Sun, 21 Aug 2011 19:40:01 +0200
branchhedgeroid
changeset 5627 ce2d92589cbc
parent 5621 ea796c83ea47
permissions -rw-r--r--
Added a visual imageview to show how many teams have been selected, plus feedback when creating a new team:
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;
5542
141c12a23787 start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents: 5467
diff changeset
    65
	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
    66
	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
    67
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    68
	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
    69
		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
    70
		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
    71
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
		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
    73
		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
    74
		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
    75
		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
    76
		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
    77
		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
    78
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
		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
    80
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
		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
    82
		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
    83
		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
    84
5467
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
    85
		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
    86
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
    87
		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
    88
		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
    89
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
    90
		LinearLayout ll = (LinearLayout) findViewById(R.id.HogsContainer);
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    91
		for (int i = 0; i < ll.getChildCount(); i++) {
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    92
			RelativeLayout team_creation_entry = (RelativeLayout) ll
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    93
					.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
    94
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    95
			hogHat.add((Spinner) team_creation_entry
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    96
					.findViewById(R.id.spinTeam1));
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    97
			hogDice.add((ImageButton) team_creation_entry
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    98
					.findViewById(R.id.btnTeam1));
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
    99
			hogName.add((EditText) team_creation_entry
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   100
					.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
   101
		}
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   102
		ArrayList<HashMap<String, ?>> gravesData = FrontendDataUtils
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   103
				.getGraves(this);
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   104
		SimpleAdapter sa = new SimpleAdapter(this, gravesData,
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   105
				R.layout.spinner_textimg_entry, new String[] { "txt", "img" },
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   106
				new int[] { R.id.spinner_txt, R.id.spinner_img });
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   107
5467
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   108
		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
   109
		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
   110
		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
   111
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   112
		ArrayList<HashMap<String, ?>> flagsData = FrontendDataUtils
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   113
				.getFlags(this);
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   114
		sa = new SimpleAdapter(this, flagsData, 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);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   118
		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
   119
		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
   120
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   121
		ArrayList<HashMap<String, ?>> typesData = FrontendDataUtils
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   122
				.getTypes(this);
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   123
		sa = new SimpleAdapter(this, typesData, R.layout.spinner_textimg_entry,
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   124
				new String[] { "txt", "img" }, new int[] { R.id.spinner_txt,
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   125
						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
   126
		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
   127
		difficulty.setOnFocusChangeListener(focusser);
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   128
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   129
		ArrayList<HashMap<String, ?>> hatsData = FrontendDataUtils
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   130
				.getHats(this);
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   131
		sa = new SimpleAdapter(this, hatsData, R.layout.spinner_textimg_entry,
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   132
				new String[] { "txt", "img" }, new int[] { R.id.spinner_txt,
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   133
						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
   134
		sa.setViewBinder(viewBinder);
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   135
		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
   136
			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
   137
		}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   138
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   139
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   140
				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
   141
		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
   142
		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
   143
		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
   144
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   145
		adapter = new ArrayAdapter<String>(this, R.layout.listview_item,
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   146
				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
   147
		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
   148
		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
   149
		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
   150
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
   151
		Team t = this.getIntent().getParcelableExtra("team");
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   152
		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
   153
			name.setText(t.name);
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   154
			int position = ((ArrayAdapter<String>) voice.getAdapter())
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   155
					.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
   156
			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
   157
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   158
			position = ((ArrayAdapter<String>) fort.getAdapter())
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   159
					.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
   160
			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
   161
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
			position = 0;
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   163
			for (HashMap<String, ?> hashmap : typesData) {
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   164
				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
   165
					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
   166
					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
   167
				}
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
			}
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
   169
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 : gravesData) {
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   172
				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
   173
					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
   174
					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
   175
				}
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
			}
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
   177
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
   178
			position = 0;
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   179
			for (HashMap<String, ?> hashmap : typesData) {
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   180
				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
   181
					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
   182
					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
   183
				}
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
			}
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
   185
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   186
			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
   187
				position = 0;
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   188
				for (HashMap<String, ?> hashmap : hatsData) {
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   189
					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
   190
						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
   191
					}
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
				}
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
   193
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
   194
				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
   195
			}
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
		}
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
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   199
	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
   200
		super.onDestroy();
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   201
		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
   202
			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
   203
			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
   204
		}
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
	}
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
   206
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   207
	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
   208
		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
   209
			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
   210
		}
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   211
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
	};
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   213
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   214
	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
   215
		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
   216
		super.onBackPressed();
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   217
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
   218
	}
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   219
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   220
	private OnClickListener backClicker = new OnClickListener() {
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   221
		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
   222
			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
   223
			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
   224
		}
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
	};
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
	private void onFinishing() {
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   228
		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
   229
			setResult(RESULT_OK);
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   230
		} 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
   231
			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
   232
		}
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
	}
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
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   235
	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
   236
		public void onClick(View v) {
5627
ce2d92589cbc Added a visual imageview to show how many teams have been selected, plus feedback when creating a new team:
Xeli
parents: 5621
diff changeset
   237
			Toast.makeText(TeamCreatorActivity.this, R.string.saved, Toast.LENGTH_SHORT).show();
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
   238
			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
   239
			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
   240
			team.name = name.getText().toString();
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   241
			HashMap<String, Object> hashmap = (HashMap<String, Object>) flag
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   242
					.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
   243
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   244
			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
   245
			team.fort = fort.getSelectedItem().toString();
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   246
			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
   247
			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
   248
			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
   249
			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
   250
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   251
			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
   252
			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
   253
			int levelInt;
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   254
			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
   255
				levelInt = 0;
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   256
			} 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
   257
				levelInt = 1;
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   258
			} 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
   259
				levelInt = 2;
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   260
			} 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
   261
				levelInt = 3;
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   262
			} 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
   263
				levelInt = 4;
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   264
			} 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
   265
				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
   266
			}
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
   267
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   268
			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
   269
				team.hogNames[i] = hogName.get(i).getText().toString();
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   270
				hashmap = (HashMap<String, Object>) hogHat.get(i)
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   271
						.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
   272
				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
   273
				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
   274
			}
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
			try {
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   276
				File teamsDir = new File(getFilesDir().getAbsolutePath() + '/'
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   277
						+ Team.DIRECTORY_TEAMS);
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   278
				if (!teamsDir.exists())
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   279
					teamsDir.mkdir();
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   280
				FileOutputStream fos = new FileOutputStream(String.format(
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   281
						"%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
   282
				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
   283
			} 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
   284
				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
   285
			}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   286
		}
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
   287
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
   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
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   290
	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
   291
		@SuppressWarnings("unchecked")
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   292
		public void onItemSelected(AdapterView<?> arg0, View arg1,
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   293
				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
   294
			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
   295
			String fortName = (String) arg0.getAdapter().getItem(position);
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   296
			Drawable fortIconDrawable = Drawable.createFromPath(Utils
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   297
					.getDownloadPath(TeamCreatorActivity.this)
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   298
					+ "Forts/"
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   299
					+ 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
   300
			imgFort.setImageDrawable(fortIconDrawable);
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   301
			scroller.fullScroll(ScrollView.FOCUS_DOWN);// Scroll the scrollview
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   302
														// to the bottom, work
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   303
														// around for scollview
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   304
														// invalidation (scrolls
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   305
														// 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
   306
		}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff changeset
   307
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
		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
   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
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
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   313
	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
   314
		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
   315
			try {
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   316
				File dir = new File(String.format("%sSounds/voices/%s",
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   317
						Utils.getDownloadPath(TeamCreatorActivity.this),
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   318
						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
   319
				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
   320
				File[] dirs = dir.listFiles();
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   321
				File f = dirs[(int) Math.round(Math.random() * dirs.length)];
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   322
				if (f.getName().endsWith(".ogg"))
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   323
					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
   324
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   325
				if (mp == null)
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   326
					mp = new MediaPlayer();
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   327
				else
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   328
					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
   329
				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
   330
				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
   331
				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
   332
			} 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
   333
				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
   334
			} 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
   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 (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
   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
			}
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
		}
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
	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
   343
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   344
		public boolean setViewValue(View view, Object data,
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   345
				String textRepresentation) {
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   346
			if (view instanceof ImageView && data instanceof Bitmap) {
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   347
				ImageView v = (ImageView) view;
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   348
				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
   349
				return true;
5613
a7e40b20ce44 small cosmetic change
Xeli
parents: 5607
diff changeset
   350
			} 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
   351
				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
   352
			}
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
		}
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
}