project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/TeamCreatorActivity.java
changeset 6432 ffb18b44415d
parent 6350 41b0a9955c47
child 6447 0bb16bc5c8b4
equal deleted inserted replaced
6431:f0a7c5415119 6432:ffb18b44415d
    62 	private ImageButton back, save, voiceButton;
    62 	private ImageButton back, save, voiceButton;
    63 	private ScrollView scroller;
    63 	private ScrollView scroller;
    64 	private MediaPlayer mp = null;
    64 	private MediaPlayer mp = null;
    65 	private boolean settingsChanged = false;
    65 	private boolean settingsChanged = false;
    66 	private boolean saved = false;
    66 	private boolean saved = false;
       
    67 	private String fileName = null;
    67 
    68 
    68 	public void onCreate(Bundle savedInstanceState) {
    69 	public void onCreate(Bundle savedInstanceState) {
    69 		super.onCreate(savedInstanceState);
    70 		super.onCreate(savedInstanceState);
    70 		setContentView(R.layout.team_creation);
    71 		setContentView(R.layout.team_creation);
    71 
    72 
   195 					}
   196 					}
   196 				}
   197 				}
   197 
   198 
   198 				hogName.get(i).setText(t.hogNames[i]);
   199 				hogName.get(i).setText(t.hogNames[i]);
   199 			}
   200 			}
       
   201 			this.fileName = t.file;
   200 		}
   202 		}
   201 	}
   203 	}
   202 
   204 
   203 	public void onDestroy() {
   205 	public void onDestroy() {
   204 		super.onDestroy();
   206 		super.onDestroy();
   240 		public void onClick(View v) {
   242 		public void onClick(View v) {
   241 			Toast.makeText(TeamCreatorActivity.this, R.string.saved, Toast.LENGTH_SHORT).show();
   243 			Toast.makeText(TeamCreatorActivity.this, R.string.saved, Toast.LENGTH_SHORT).show();
   242 			saved = true;
   244 			saved = true;
   243 			Team team = new Team();
   245 			Team team = new Team();
   244 			team.name = name.getText().toString();
   246 			team.name = name.getText().toString();
   245 			HashMap<String, Object> hashmap = (HashMap<String, Object>) flag
   247 			HashMap<String, Object> hashmap = (HashMap<String, Object>) flag.getSelectedItem();
   246 					.getSelectedItem();
       
   247 
   248 
   248 			team.flag = (String) hashmap.get("txt");
   249 			team.flag = (String) hashmap.get("txt");
   249 			team.fort = fort.getSelectedItem().toString();
   250 			team.fort = fort.getSelectedItem().toString();
   250 			hashmap = (HashMap<String, Object>) grave.getSelectedItem();
   251 			hashmap = (HashMap<String, Object>) grave.getSelectedItem();
   251 			team.grave = hashmap.get("txt").toString();
   252 			team.grave = hashmap.get("txt").toString();
   252 			team.hash = "0";
   253 			team.hash = "0";
   253 			team.voice = voice.getSelectedItem().toString();
   254 			team.voice = voice.getSelectedItem().toString();
       
   255 			team.file = fileName;
   254 
   256 
   255 			hashmap = ((HashMap<String, Object>) difficulty.getSelectedItem());
   257 			hashmap = ((HashMap<String, Object>) difficulty.getSelectedItem());
   256 			String levelString = hashmap.get("txt").toString();
   258 			String levelString = hashmap.get("txt").toString();
   257 			int levelInt;
   259 			int levelInt;
   258 			if (levelString.equals(getString(R.string.human))) {
   260 			if (levelString.equals(getString(R.string.human))) {
   269 				levelInt = 5;
   271 				levelInt = 5;
   270 			}
   272 			}
   271 
   273 
   272 			for (int i = 0; i < hogName.size(); i++) {
   274 			for (int i = 0; i < hogName.size(); i++) {
   273 				team.hogNames[i] = hogName.get(i).getText().toString();
   275 				team.hogNames[i] = hogName.get(i).getText().toString();
   274 				hashmap = (HashMap<String, Object>) hogHat.get(i)
   276 				hashmap = (HashMap<String, Object>) hogHat.get(i).getSelectedItem();
   275 						.getSelectedItem();
       
   276 				team.hats[i] = hashmap.get("txt").toString();
   277 				team.hats[i] = hashmap.get("txt").toString();
   277 				team.levels[i] = levelInt;
   278 				team.levels[i] = levelInt;
   278 			}
   279 			}
   279 			try {
   280 			try {
   280 				File teamsDir = new File(getFilesDir().getAbsolutePath() + '/'
   281 				File teamsDir = new File(getFilesDir().getAbsolutePath() + '/' + Team.DIRECTORY_TEAMS);
   281 						+ Team.DIRECTORY_TEAMS);
   282 				if (!teamsDir.exists()) teamsDir.mkdir();
   282 				if (!teamsDir.exists())
   283 				if(team.file == null){
   283 					teamsDir.mkdir();
   284 					team.setFileName(TeamCreatorActivity.this);
   284 				FileOutputStream fos = new FileOutputStream(String.format(
   285 				}
   285 						"%s/%s.xml", teamsDir.getAbsolutePath(), team.name));
   286 				FileOutputStream fos = new FileOutputStream(String.format("%s/%s", teamsDir.getAbsolutePath(), team.file));
   286 				team.writeToXml(fos);
   287 				team.writeToXml(fos);
   287 			} catch (FileNotFoundException e) {
   288 			} catch (FileNotFoundException e) {
   288 				e.printStackTrace();
   289 				e.printStackTrace();
   289 			}
   290 			}
   290 		}
   291 		}