project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/TeamCreatorActivity.java
author Wuzzy <Wuzzy2@mail.ru>
Thu, 15 Feb 2018 18:32:28 +0100
changeset 13009 67cc3cac4c8e
parent 10017 de822cd3df3a
permissions -rw-r--r--
TrophyRace: Show fastest team times (instead of clan times)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
     1
/*
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
     2
 * Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game
6700
e04da46ee43c the most important commit of the year
koda
parents: 6567
diff changeset
     3
 * Copyright (c) 2011-2012 Richard Deurwaarder <xeli@xelification.com>
7584
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
     4
 * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
     5
 *
7584
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
     6
 * This program is free software; you can redistribute it and/or
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
     7
 * modify it under the terms of the GNU General Public License
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
     8
 * as published by the Free Software Foundation; either version 2
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
     9
 * of the License, or (at your option) any later version.
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    10
 *
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    11
 * This program is distributed in the hope that it will be useful,
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    14
 * GNU General Public License for more details.
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    15
 *
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    17
 * along with this program; if not, write to the Free Software
7584
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    19
 */
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    20
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    21
package org.hedgewars.hedgeroid;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    22
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    23
import java.io.File;
7485
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents: 7476
diff changeset
    24
import java.io.FileNotFoundException;
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    25
import java.io.IOException;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    26
import java.util.ArrayList;
6447
0bb16bc5c8b4 android: load graphics multithreaded for superduper loadtimes
Xeli
parents: 6432
diff changeset
    27
import java.util.List;
7476
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents: 6842
diff changeset
    28
import java.util.Map;
7485
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents: 7476
diff changeset
    29
import java.util.NoSuchElementException;
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    30
6488
c356ddebab84 android: moved the different objects representing the different game parameters to a different package
Xeli
parents: 6448
diff changeset
    31
import org.hedgewars.hedgeroid.Datastructures.FrontendDataUtils;
7476
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents: 6842
diff changeset
    32
import org.hedgewars.hedgeroid.Datastructures.Hog;
6488
c356ddebab84 android: moved the different objects representing the different game parameters to a different package
Xeli
parents: 6448
diff changeset
    33
import org.hedgewars.hedgeroid.Datastructures.Team;
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
    34
import org.hedgewars.hedgeroid.util.FileUtils;
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    35
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    36
import android.app.Activity;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    37
import android.graphics.Bitmap;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    38
import android.graphics.drawable.Drawable;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    39
import android.media.MediaPlayer;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    40
import android.os.Bundle;
7586
33924ff4af50 Hedgeroid: Some code cleanup, adding a forgotten file
Medo <smaxein@googlemail.com>
parents: 7584
diff changeset
    41
import android.util.Log;
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    42
import android.view.View;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    43
import android.view.View.OnClickListener;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    44
import android.widget.AdapterView;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    45
import android.widget.AdapterView.OnItemSelectedListener;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    46
import android.widget.ArrayAdapter;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    47
import android.widget.EditText;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    48
import android.widget.ImageButton;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    49
import android.widget.ImageView;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    50
import android.widget.LinearLayout;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    51
import android.widget.RelativeLayout;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    52
import android.widget.ScrollView;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    53
import android.widget.SimpleAdapter;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    54
import android.widget.Spinner;
7485
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents: 7476
diff changeset
    55
import android.widget.SpinnerAdapter;
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    56
import android.widget.TextView;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    57
import android.widget.Toast;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    58
7485
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents: 7476
diff changeset
    59
/**
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents: 7476
diff changeset
    60
 * Edit or create a team. If a team should be edited, it is supplied in the extras
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents: 7476
diff changeset
    61
 * as parameter oldTeamName.
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents: 7476
diff changeset
    62
 */
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents: 7476
diff changeset
    63
public class TeamCreatorActivity extends Activity implements Runnable {
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    64
    public static final String PARAMETER_EXISTING_TEAMNAME = "existingTeamName";
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    65
    private static final String TAG = TeamCreatorActivity.class.getSimpleName();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    66
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    67
    private TextView name;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    68
    private Spinner difficulty, grave, flag, voice, fort;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    69
    private ImageView imgFort;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    70
    private ArrayList<ImageButton> hogDice = new ArrayList<ImageButton>();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    71
    private ArrayList<Spinner> hogHat = new ArrayList<Spinner>();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    72
    private ArrayList<EditText> hogName = new ArrayList<EditText>();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    73
    private ImageButton voiceButton;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    74
    private ScrollView scroller;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    75
    private MediaPlayer mp = null;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    76
    private boolean initComplete = false;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    77
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    78
    private String existingTeamName = null;
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    79
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    80
    private final List<Map<String, ?>> flagsData = new ArrayList<Map<String, ?>>();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    81
    private final List<Map<String, ?>> typesData = new ArrayList<Map<String, ?>>();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    82
    private final List<Map<String, ?>> gravesData = new ArrayList<Map<String, ?>>();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    83
    private final List<Map<String, ?>> hatsData = new ArrayList<Map<String, ?>>();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    84
    private final List<String> voicesData = new ArrayList<String>();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    85
    private final List<String> fortsData = new ArrayList<String>();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    86
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    87
    public void onCreate(Bundle savedInstanceState) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    88
        super.onCreate(savedInstanceState);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    89
        initComplete = false;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    90
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    91
        // Restore state and read parameters
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    92
        if(savedInstanceState != null) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    93
            existingTeamName = savedInstanceState.getString(PARAMETER_EXISTING_TEAMNAME);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    94
        } else {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    95
            existingTeamName = getIntent().getStringExtra(PARAMETER_EXISTING_TEAMNAME);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    96
        }
6447
0bb16bc5c8b4 android: load graphics multithreaded for superduper loadtimes
Xeli
parents: 6432
diff changeset
    97
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    98
        // Set up view
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    99
        setContentView(R.layout.team_creation);
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
   100
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   101
        name = (TextView) findViewById(R.id.txtName);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   102
        difficulty = (Spinner) findViewById(R.id.spinType);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   103
        grave = (Spinner) findViewById(R.id.spinGrave);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   104
        flag = (Spinner) findViewById(R.id.spinFlag);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   105
        voice = (Spinner) findViewById(R.id.spinVoice);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   106
        fort = (Spinner) findViewById(R.id.spinFort);
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
   107
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   108
        imgFort = (ImageView) findViewById(R.id.imgFort);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   109
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   110
        voiceButton = (ImageButton) findViewById(R.id.btnPlay);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   111
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   112
        scroller = (ScrollView) findViewById(R.id.scroller);
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
   113
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   114
        // Wire view elements
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   115
        LinearLayout ll = (LinearLayout) findViewById(R.id.HogsContainer);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   116
        for (int i = 0; i < ll.getChildCount(); i++) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   117
            RelativeLayout team_creation_entry = (RelativeLayout) ll.getChildAt(i);
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
   118
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   119
            hogHat.add((Spinner) team_creation_entry
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   120
                    .findViewById(R.id.spinTeam1));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   121
            hogDice.add((ImageButton) team_creation_entry
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   122
                    .findViewById(R.id.btnTeam1));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   123
            hogName.add((EditText) team_creation_entry
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   124
                    .findViewById(R.id.txtTeam1));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   125
        }
6447
0bb16bc5c8b4 android: load graphics multithreaded for superduper loadtimes
Xeli
parents: 6432
diff changeset
   126
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   127
        grave.setAdapter(createMapSpinnerAdapter(gravesData));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   128
        flag.setAdapter(createMapSpinnerAdapter(flagsData));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   129
        difficulty.setAdapter(createMapSpinnerAdapter(typesData));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   130
        SpinnerAdapter hatAdapter = createMapSpinnerAdapter(hatsData);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   131
        for (Spinner spin : hogHat) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   132
            spin.setAdapter(hatAdapter);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   133
        }
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
   134
7485
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents: 7476
diff changeset
   135
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   136
        voice.setAdapter(createListSpinnerAdapter(voicesData));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   137
        voiceButton.setOnClickListener(voiceClicker);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   138
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   139
        fort.setAdapter(createListSpinnerAdapter(fortsData));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   140
        fort.setOnItemSelectedListener(fortSelector);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   141
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   142
        new Thread(this).start();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   143
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   144
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   145
    private SpinnerAdapter createMapSpinnerAdapter(List<? extends Map<String, ?>> data) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   146
        SimpleAdapter sa = new SimpleAdapter(this, data,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   147
                R.layout.spinner_textimg_entry, new String[] { "txt", "img" },
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   148
                new int[] { R.id.spinner_txt, R.id.spinner_img });
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   149
        sa.setDropDownViewResource(R.layout.spinner_textimg_dropdown_entry);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   150
        sa.setViewBinder(viewBinder);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   151
        return sa;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   152
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   153
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   154
    private SpinnerAdapter createListSpinnerAdapter(List<String> data) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   155
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.listview_item, data);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   156
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   157
        return adapter;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   158
    }
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
   159
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   160
    public void run(){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   161
        try {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   162
            final List<Map<String, ?>> gravesDataNew = FrontendDataUtils.getGraves(this);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   163
            runOnUiThread(new Runnable(){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   164
                public void run() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   165
                    gravesData.addAll(gravesDataNew);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   166
                    ((SimpleAdapter)grave.getAdapter()).notifyDataSetChanged();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   167
                }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   168
            });
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
   169
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   170
            final List<Map<String, ?>> flagsDataNew = FrontendDataUtils.getFlags(this);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   171
            runOnUiThread(new Runnable(){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   172
                public void run() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   173
                    flagsData.addAll(flagsDataNew);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   174
                    ((SimpleAdapter)flag.getAdapter()).notifyDataSetChanged();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   175
                }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   176
            });
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   177
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   178
            final List<Map<String, ?>> typesDataNew = FrontendDataUtils.getTypes(this);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   179
            runOnUiThread(new Runnable(){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   180
                public void run() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   181
                    typesData.addAll(typesDataNew);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   182
                    ((SimpleAdapter)difficulty.getAdapter()).notifyDataSetChanged();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   183
                }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   184
            });
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   185
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   186
            final List<Map<String, ?>> hatsDataNew = FrontendDataUtils.getHats(this);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   187
            runOnUiThread(new Runnable(){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   188
                public void run() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   189
                    hatsData.addAll(hatsDataNew);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   190
                    ((SimpleAdapter)hogHat.get(0).getAdapter()).notifyDataSetChanged();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   191
                }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   192
            });
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
   193
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   194
            final List<String> voicesDataNew = FrontendDataUtils.getVoices(this);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   195
            runOnUiThread(new Runnable(){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   196
                public void run() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   197
                    voicesData.addAll(voicesDataNew);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   198
                    ((ArrayAdapter<?>)voice.getAdapter()).notifyDataSetChanged();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   199
                }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   200
            });
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   201
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   202
            final List<String> fortsDataNew = FrontendDataUtils.getForts(this);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   203
            runOnUiThread(new Runnable(){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   204
                public void run() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   205
                    fortsData.addAll(fortsDataNew);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   206
                    ((ArrayAdapter<?>)fort.getAdapter()).notifyDataSetChanged();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   207
                }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   208
            });
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
   209
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   210
            if(existingTeamName!=null) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   211
                final Team loadedTeam = Team.load(Team.getTeamfileByName(getApplicationContext(), existingTeamName));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   212
                if(loadedTeam==null) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   213
                    existingTeamName = null;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   214
                } else {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   215
                    runOnUiThread(new Runnable(){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   216
                        public void run() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   217
                            setTeamValues(loadedTeam);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   218
                        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   219
                    });
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   220
                }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   221
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   222
            runOnUiThread(new Runnable(){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   223
                public void run() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   224
                    initComplete = true;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   225
                }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   226
            });
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   227
        } catch(FileNotFoundException e) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   228
            this.runOnUiThread(new Runnable(){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   229
                public void run() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   230
                    Toast.makeText(getApplicationContext(), R.string.error_missing_sdcard_or_files, Toast.LENGTH_LONG).show();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   231
                    finish();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   232
                }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   233
            });
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   234
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   235
    }
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
   236
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   237
    public void onDestroy() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   238
        super.onDestroy();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   239
        if (mp != null) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   240
            mp.release();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   241
            mp = null;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   242
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   243
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   244
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   245
    @Override
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   246
    protected void onSaveInstanceState(Bundle outState) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   247
        super.onSaveInstanceState(outState);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   248
        outState.putString(PARAMETER_EXISTING_TEAMNAME, existingTeamName);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   249
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   250
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   251
    public void onBackPressed() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   252
        if(initComplete) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   253
            saveTeam();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   254
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   255
        setResult(RESULT_OK);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   256
        super.onBackPressed();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   257
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   258
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   259
    private void saveTeam() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   260
        String teamName = name.getText().toString();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   261
        String teamFlag = (String)((Map<String, Object>) flag.getSelectedItem()).get("txt");
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   262
        String teamFort = fort.getSelectedItem().toString();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   263
        String teamGrave = (String)((Map<String, Object>) grave.getSelectedItem()).get("txt");
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   264
        String teamVoice = voice.getSelectedItem().toString();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   265
        int levelInt = (Integer)((Map<String, Object>) difficulty.getSelectedItem()).get("level");
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
   266
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   267
        List<Hog> hogs = new ArrayList<Hog>();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   268
        for (int i = 0; i < hogName.size(); i++) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   269
            String name = hogName.get(i).getText().toString();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   270
            String hat = ((Map<String, Object>) hogHat.get(i).getSelectedItem()).get("txt").toString();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   271
            hogs.add(new Hog(name, hat, levelInt));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   272
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   273
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   274
        Team team = new Team(teamName, teamGrave, teamFlag, teamVoice, teamFort, hogs);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   275
        File teamsDir = new File(getFilesDir(), Team.DIRECTORY_TEAMS);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   276
        if (!teamsDir.exists()) teamsDir.mkdir();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   277
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   278
        File newFile = Team.getTeamfileByName(this, teamName);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   279
        File oldFile = null;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   280
        if(existingTeamName != null) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   281
            oldFile = Team.getTeamfileByName(this, existingTeamName);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   282
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   283
        try {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   284
            team.save(newFile);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   285
            // If the team was renamed, delete the old file.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   286
            if(oldFile != null && oldFile.isFile() && !oldFile.equals(newFile)) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   287
                oldFile.delete();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   288
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   289
            existingTeamName = teamName;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   290
        } catch(IOException e) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   291
            Toast.makeText(getApplicationContext(), R.string.error_save_failed, Toast.LENGTH_SHORT).show();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   292
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   293
    };
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
   294
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   295
    private OnItemSelectedListener fortSelector = new OnItemSelectedListener() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   296
        public void onItemSelected(AdapterView<?> arg0, View arg1,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   297
                int position, long arg3) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   298
            String fortName = (String) arg0.getAdapter().getItem(position);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   299
            try {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   300
                File fortImage = FileUtils.getDataPathFile(TeamCreatorActivity.this, "Forts", fortName, "L.png");
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   301
                Drawable fortIconDrawable = Drawable.createFromPath(fortImage.getAbsolutePath());
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   302
                imgFort.setImageDrawable(fortIconDrawable);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   303
            } catch(IOException e) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   304
                Log.e(TAG, "Unable to show fort image", e);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   305
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   306
            scroller.fullScroll(ScrollView.FOCUS_DOWN);// Scroll the scrollview
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   307
            // to the bottom, work
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   308
            // around for scrollview
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   309
            // invalidation (scrolls
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   310
            // back to top)
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   311
        }
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
   312
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   313
        public void onNothingSelected(AdapterView<?> arg0) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   314
        }
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
   315
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   316
    };
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
   317
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   318
    private OnClickListener voiceClicker = new OnClickListener() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   319
        public void onClick(View v) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   320
            try {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   321
                File dir = FileUtils.getDataPathFile(TeamCreatorActivity.this, "Sounds", "voices", (String)voice.getSelectedItem());
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   322
                String file = "";
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   323
                File[] dirs = dir.listFiles();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   324
                File f = dirs[(int) Math.round(Math.random() * dirs.length)];
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   325
                if (f.getName().endsWith(".ogg"))
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   326
                    file = f.getAbsolutePath();
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
   327
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   328
                if (mp == null)
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   329
                    mp = new MediaPlayer();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   330
                else
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   331
                    mp.reset();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   332
                mp.setDataSource(file);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   333
                mp.prepare();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   334
                mp.start();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   335
            } catch (IllegalArgumentException e) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   336
                Log.e(TAG, "Unable to play voice sample", e);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   337
            } catch (IllegalStateException e) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   338
                Log.e(TAG, "Unable to play voice sample", e);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   339
            } catch (IOException e) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   340
                Log.e(TAG, "Unable to play voice sample", e);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   341
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   342
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   343
    };
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   344
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   345
    @SuppressWarnings("unchecked")
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   346
    private void setTeamValues(Team t){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   347
        if (t == null) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   348
            return;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   349
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   350
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   351
        try {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   352
            name.setText(t.name);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   353
            voice.setSelection(findPosition((ArrayAdapter<String>) voice.getAdapter(), t.voice));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   354
            fort.setSelection(findPosition((ArrayAdapter<String>) fort.getAdapter(), t.fort));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   355
            difficulty.setSelection(findPosition(typesData, "level", Integer.valueOf(t.hogs.get(0).level)));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   356
            grave.setSelection(findPosition(gravesData, "txt", t.grave));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   357
            flag.setSelection(findPosition(flagsData, "txt", t.flag));
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
   358
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   359
            for (int i = 0; i < Team.HEDGEHOGS_PER_TEAM; i++) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   360
                hogHat.get(i).setSelection(findPosition(hatsData, "txt", t.hogs.get(i).hat));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   361
                hogName.get(i).setText(t.hogs.get(i).name);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   362
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   363
        } catch(NoSuchElementException e) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   364
            Toast.makeText(getApplicationContext(), R.string.error_team_attribute_not_found, Toast.LENGTH_LONG).show();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   365
            finish();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   366
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   367
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   368
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   369
    int findPosition(ArrayAdapter<String> adapter, String value) throws NoSuchElementException {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   370
        int position = adapter.getPosition(value);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   371
        if(position<0) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   372
            throw new NoSuchElementException();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   373
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   374
        return position;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   375
    }
6447
0bb16bc5c8b4 android: load graphics multithreaded for superduper loadtimes
Xeli
parents: 6432
diff changeset
   376
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   377
    int findPosition(List<? extends Map<String, ?>> data, String key, Object value) throws NoSuchElementException {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   378
        int position = 0;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   379
        for (Map<String, ?> map : data) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   380
            if (map.get(key).equals(value)) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   381
                return position;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   382
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   383
            position++;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   384
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   385
        throw new NoSuchElementException();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   386
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   387
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   388
    private SimpleAdapter.ViewBinder viewBinder = new SimpleAdapter.ViewBinder() {
6447
0bb16bc5c8b4 android: load graphics multithreaded for superduper loadtimes
Xeli
parents: 6432
diff changeset
   389
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   390
        public boolean setViewValue(View view, Object data,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   391
                String textRepresentation) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   392
            if (view instanceof ImageView && data instanceof Bitmap) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   393
                ImageView v = (ImageView) view;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   394
                v.setImageBitmap((Bitmap) data);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   395
                return true;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   396
            } else {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   397
                return false;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   398
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   399
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   400
    };
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
   401
}