--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/TeamCreatorActivity.java Fri Aug 19 17:22:12 2011 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/TeamCreatorActivity.java Fri Aug 19 22:31:59 2011 +0200
@@ -30,6 +30,7 @@
import android.widget.SimpleAdapter;
import android.widget.Spinner;
import android.widget.TextView;
+import android.widget.Toast;
public class TeamCreatorActivity extends Activity {
@@ -46,7 +47,7 @@
private boolean settingsChanged = false;
private boolean saved = false;
- public void onCreate(Bundle savedInstanceState){
+ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.team_creation);
@@ -70,85 +71,105 @@
LinearLayout ll = (LinearLayout) findViewById(R.id.HogsContainer);
hogs = new ArrayList<RelativeLayout>(ll.getChildCount());
- for(int i = 0; i < ll.getChildCount(); i++){
- RelativeLayout team_creation_entry = (RelativeLayout) ll.getChildAt(i);
+ for (int i = 0; i < ll.getChildCount(); i++) {
+ RelativeLayout team_creation_entry = (RelativeLayout) ll
+ .getChildAt(i);
- hogHat.add((Spinner)team_creation_entry.findViewById(R.id.spinTeam1));
- hogDice.add((ImageButton)team_creation_entry.findViewById(R.id.btnTeam1));
- hogName.add((EditText)team_creation_entry.findViewById(R.id.txtTeam1));
+ hogHat.add((Spinner) team_creation_entry
+ .findViewById(R.id.spinTeam1));
+ hogDice.add((ImageButton) team_creation_entry
+ .findViewById(R.id.btnTeam1));
+ hogName.add((EditText) team_creation_entry
+ .findViewById(R.id.txtTeam1));
}
- ArrayList<HashMap<String, ?>> gravesData = FrontendDataUtils.getGraves(this);
- SimpleAdapter sa = new SimpleAdapter(this, gravesData, R.layout.spinner_textimg_entry, new String[]{"txt", "img"}, new int[]{R.id.spinner_txt, R.id.spinner_img});
-
+ ArrayList<HashMap<String, ?>> gravesData = FrontendDataUtils
+ .getGraves(this);
+ SimpleAdapter sa = new SimpleAdapter(this, gravesData,
+ R.layout.spinner_textimg_entry, new String[] { "txt", "img" },
+ new int[] { R.id.spinner_txt, R.id.spinner_img });
+
sa.setViewBinder(viewBinder);
grave.setAdapter(sa);
grave.setOnFocusChangeListener(focusser);
- ArrayList<HashMap<String, ?>> flagsData = FrontendDataUtils.getFlags(this);
- sa = new SimpleAdapter(this, flagsData, R.layout.spinner_textimg_entry, new String[]{"txt", "img"}, new int[]{R.id.spinner_txt, R.id.spinner_img});
+ ArrayList<HashMap<String, ?>> flagsData = FrontendDataUtils
+ .getFlags(this);
+ sa = new SimpleAdapter(this, flagsData, R.layout.spinner_textimg_entry,
+ new String[] { "txt", "img" }, new int[] { R.id.spinner_txt,
+ R.id.spinner_img });
sa.setViewBinder(viewBinder);
flag.setAdapter(sa);
flag.setOnFocusChangeListener(focusser);
- ArrayList<HashMap<String, ?>> typesData = FrontendDataUtils.getTypes(this);
- sa = new SimpleAdapter(this, typesData, R.layout.spinner_textimg_entry, new String[]{"txt", "img"}, new int[]{R.id.spinner_txt, R.id.spinner_img});
+ ArrayList<HashMap<String, ?>> typesData = FrontendDataUtils
+ .getTypes(this);
+ sa = new SimpleAdapter(this, typesData, R.layout.spinner_textimg_entry,
+ new String[] { "txt", "img" }, new int[] { R.id.spinner_txt,
+ R.id.spinner_img });
difficulty.setAdapter(sa);
difficulty.setOnFocusChangeListener(focusser);
-
- ArrayList<HashMap<String, ?>> hatsData = FrontendDataUtils.getHats(this);
- sa = new SimpleAdapter(this, hatsData, R.layout.spinner_textimg_entry, new String[]{"txt", "img"}, new int[]{R.id.spinner_txt, R.id.spinner_img});
+
+ ArrayList<HashMap<String, ?>> hatsData = FrontendDataUtils
+ .getHats(this);
+ sa = new SimpleAdapter(this, hatsData, R.layout.spinner_textimg_entry,
+ new String[] { "txt", "img" }, new int[] { R.id.spinner_txt,
+ R.id.spinner_img });
sa.setViewBinder(viewBinder);
- for(Spinner spin : hogHat){
+ for (Spinner spin : hogHat) {
spin.setAdapter(sa);
}
- ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.listview_item, FrontendDataUtils.getVoices(this));
+ ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
+ R.layout.listview_item, FrontendDataUtils.getVoices(this));
voice.setAdapter(adapter);
voice.setOnFocusChangeListener(focusser);
voiceButton.setOnClickListener(voiceClicker);
- adapter = new ArrayAdapter<String>(this, R.layout.listview_item, FrontendDataUtils.getForts(this));
+ adapter = new ArrayAdapter<String>(this, R.layout.listview_item,
+ FrontendDataUtils.getForts(this));
fort.setAdapter(adapter);
fort.setOnItemSelectedListener(fortSelector);
fort.setOnFocusChangeListener(focusser);
Team t = this.getIntent().getParcelableExtra("team");
- if(t != null){
+ if (t != null) {
name.setText(t.name);
- int position = ((ArrayAdapter<String>)voice.getAdapter()).getPosition(t.voice);
+ int position = ((ArrayAdapter<String>) voice.getAdapter())
+ .getPosition(t.voice);
voice.setSelection(position);
- position = ((ArrayAdapter<String>)fort.getAdapter()).getPosition(t.fort);
+ position = ((ArrayAdapter<String>) fort.getAdapter())
+ .getPosition(t.fort);
fort.setSelection(position);
position = 0;
- for(HashMap<String, ?> hashmap : typesData){
- if(hashmap.get("txt").equals(t.levels[0])){
+ for (HashMap<String, ?> hashmap : typesData) {
+ if (hashmap.get("txt").equals(t.levels[0])) {
difficulty.setSelection(position);
break;
}
}
position = 0;
- for(HashMap<String, ?> hashmap : gravesData){
- if(hashmap.get("txt").equals(t.grave)){
+ for (HashMap<String, ?> hashmap : gravesData) {
+ if (hashmap.get("txt").equals(t.grave)) {
grave.setSelection(position);
break;
}
}
position = 0;
- for(HashMap<String, ?> hashmap : typesData){
- if(hashmap.get("txt").equals(t.flag)){
+ for (HashMap<String, ?> hashmap : typesData) {
+ if (hashmap.get("txt").equals(t.flag)) {
flag.setSelection(position);
break;
}
}
- for(int i = 0; i < Team.maxNumberOfHogs; i++){
+ for (int i = 0; i < Team.maxNumberOfHogs; i++) {
position = 0;
- for(HashMap<String, ?> hashmap : hatsData){
- if(hashmap.get("txt").equals(t.hats[i])){
+ for (HashMap<String, ?> hashmap : hatsData) {
+ if (hashmap.get("txt").equals(t.hats[i])) {
hogHat.get(i).setSelection(position);
}
}
@@ -158,83 +179,89 @@
}
}
- public void onDestroy(){
+ public void onDestroy() {
super.onDestroy();
- if(mp != null){
+ if (mp != null) {
mp.release();
mp = null;
}
}
- private OnFocusChangeListener focusser = new OnFocusChangeListener(){
+ private OnFocusChangeListener focusser = new OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
settingsChanged = true;
}
-
+
};
-
- public void onBackPressed(){
+
+ public void onBackPressed() {
onFinishing();
super.onBackPressed();
-
+
}
-
- private OnClickListener backClicker = new OnClickListener(){
- public void onClick(View v){
+
+ private OnClickListener backClicker = new OnClickListener() {
+ public void onClick(View v) {
onFinishing();
finish();
}
};
- private void onFinishing(){
- if(settingsChanged){
+ private void onFinishing() {
+ if (settingsChanged) {
setResult(RESULT_OK);
- }else{
+ } else {
setResult(RESULT_CANCELED);
}
}
- private OnClickListener saveClicker = new OnClickListener(){
+ private OnClickListener saveClicker = new OnClickListener() {
public void onClick(View v) {
+ Toast.makeText(TeamCreatorActivity.this, R.string.saved, Toast.LENGTH_SHORT);
saved = true;
Team team = new Team();
team.name = name.getText().toString();
- HashMap<String, Object> hashmap = (HashMap<String, Object>) flag.getSelectedItem();
+ HashMap<String, Object> hashmap = (HashMap<String, Object>) flag
+ .getSelectedItem();
- team.flag = (String)hashmap.get("txt");
+ team.flag = (String) hashmap.get("txt");
team.fort = fort.getSelectedItem().toString();
- hashmap = (HashMap<String, Object>)grave.getSelectedItem();
+ hashmap = (HashMap<String, Object>) grave.getSelectedItem();
team.grave = hashmap.get("txt").toString();
team.hash = "0";
team.voice = voice.getSelectedItem().toString();
- hashmap = ((HashMap<String, Object>)difficulty.getSelectedItem());
+ hashmap = ((HashMap<String, Object>) difficulty.getSelectedItem());
String levelString = hashmap.get("txt").toString();
int levelInt;
- if(levelString.equals(getString(R.string.human))){
+ if (levelString.equals(getString(R.string.human))) {
levelInt = 0;
- }else if(levelString.equals(getString(R.string.bot5))){
+ } else if (levelString.equals(getString(R.string.bot5))) {
levelInt = 1;
- }else if(levelString.equals(getString(R.string.bot4))){
+ } else if (levelString.equals(getString(R.string.bot4))) {
levelInt = 2;
- }else if(levelString.equals(getString(R.string.bot3))){
+ } else if (levelString.equals(getString(R.string.bot3))) {
levelInt = 3;
- }else if(levelString.equals(getString(R.string.bot2))){
+ } else if (levelString.equals(getString(R.string.bot2))) {
levelInt = 4;
- }else {
+ } else {
levelInt = 5;
}
- for(int i = 0; i < hogName.size(); i++){
+ for (int i = 0; i < hogName.size(); i++) {
team.hogNames[i] = hogName.get(i).getText().toString();
- hashmap = (HashMap<String, Object>)hogHat.get(i).getSelectedItem();
+ hashmap = (HashMap<String, Object>) hogHat.get(i)
+ .getSelectedItem();
team.hats[i] = hashmap.get("txt").toString();
team.levels[i] = levelInt;
}
try {
- File teamsDir = new File(getFilesDir().getAbsolutePath() + '/' + Team.DIRECTORY_TEAMS);
- if(!teamsDir.exists()) teamsDir.mkdir();
- FileOutputStream fos = new FileOutputStream(String.format("%s/%s.xml", teamsDir.getAbsolutePath(), team.name));
+ File teamsDir = new File(getFilesDir().getAbsolutePath() + '/'
+ + Team.DIRECTORY_TEAMS);
+ if (!teamsDir.exists())
+ teamsDir.mkdir();
+ FileOutputStream fos = new FileOutputStream(String.format(
+ "%s/%s.xml", teamsDir.getAbsolutePath(), team.name));
team.writeToXml(fos);
} catch (FileNotFoundException e) {
e.printStackTrace();
@@ -243,14 +270,22 @@
};
- private OnItemSelectedListener fortSelector = new OnItemSelectedListener(){
+ private OnItemSelectedListener fortSelector = new OnItemSelectedListener() {
@SuppressWarnings("unchecked")
- public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long arg3) {
+ public void onItemSelected(AdapterView<?> arg0, View arg1,
+ int position, long arg3) {
settingsChanged = true;
String fortName = (String) arg0.getAdapter().getItem(position);
- Drawable fortIconDrawable = Drawable.createFromPath(Utils.getDownloadPath(TeamCreatorActivity.this) + "Forts/" + fortName + "L.png");
+ Drawable fortIconDrawable = Drawable.createFromPath(Utils
+ .getDownloadPath(TeamCreatorActivity.this)
+ + "Forts/"
+ + fortName + "L.png");
imgFort.setImageDrawable(fortIconDrawable);
- scroller.fullScroll(ScrollView.FOCUS_DOWN);//Scroll the scrollview to the bottom, work around for scollview invalidation (scrolls back to top)
+ scroller.fullScroll(ScrollView.FOCUS_DOWN);// Scroll the scrollview
+ // to the bottom, work
+ // around for scollview
+ // invalidation (scrolls
+ // back to top)
}
public void onNothingSelected(AdapterView<?> arg0) {
@@ -258,17 +293,22 @@
};
- private OnClickListener voiceClicker = new OnClickListener(){
+ private OnClickListener voiceClicker = new OnClickListener() {
public void onClick(View v) {
try {
- File dir = new File(String.format("%sSounds/voices/%s", Utils.getDownloadPath(TeamCreatorActivity.this), voice.getSelectedItem()));
+ File dir = new File(String.format("%sSounds/voices/%s",
+ Utils.getDownloadPath(TeamCreatorActivity.this),
+ voice.getSelectedItem()));
String file = "";
File[] dirs = dir.listFiles();
- File f = dirs[(int)Math.round(Math.random()*dirs.length)];
- if(f.getName().endsWith(".ogg"))file = f.getAbsolutePath();
+ File f = dirs[(int) Math.round(Math.random() * dirs.length)];
+ if (f.getName().endsWith(".ogg"))
+ file = f.getAbsolutePath();
- if(mp == null) mp = new MediaPlayer();
- else mp.reset();
+ if (mp == null)
+ mp = new MediaPlayer();
+ else
+ mp.reset();
mp.setDataSource(file);
mp.prepare();
mp.start();
@@ -284,12 +324,13 @@
private SimpleAdapter.ViewBinder viewBinder = new SimpleAdapter.ViewBinder() {
- public boolean setViewValue(View view, Object data, String textRepresentation) {
- if(view instanceof ImageView && data instanceof Bitmap){
- ImageView v = (ImageView)view;
- v.setImageBitmap((Bitmap)data);
+ public boolean setViewValue(View view, Object data,
+ String textRepresentation) {
+ if (view instanceof ImageView && data instanceof Bitmap) {
+ ImageView v = (ImageView) view;
+ v.setImageBitmap((Bitmap) data);
return true;
- }else{
+ } else {
return false;
}
}