Fixed team colors in the UI, delete and a nullpointer bug when no teams are created hedgeroid
authorXeli
Wed, 10 Aug 2011 01:22:52 +0200
branchhedgeroid
changeset 5532 3d7ac2b3b703
parent 5530 25d4118056e1
child 5534 7f3a391a66fb
Fixed team colors in the UI, delete and a nullpointer bug when no teams are created
project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/EngineProtocol/FrontendDataUtils.java
project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/EngineProtocol/Team.java
project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/TeamSelectionActivity.java
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/EngineProtocol/FrontendDataUtils.java	Tue Aug 09 21:41:52 2011 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/EngineProtocol/FrontendDataUtils.java	Wed Aug 10 01:22:52 2011 +0200
@@ -118,23 +118,23 @@
 		ArrayList<HashMap<String, ?>> data = new ArrayList<HashMap<String, ?>>(6);
 		String[] levels = {c.getString(R.string.human), c.getString(R.string.bot5), c.getString(R.string.bot4), c.getString(R.string.bot3), c.getString(R.string.bot2), c.getString(R.string.bot1)};
 		int[] images = {R.drawable.human, R.drawable.bot5, R.drawable.bot4, R.drawable.bot3, R.drawable.bot2, R.drawable.bot1};
-		
+
 		for(int i = 0; i < levels.length; i++){
 			HashMap<String, Object> map = new HashMap<String, Object>();
 			map.put("txt", levels[i]);
 			map.put("img", images[i]);
 			data.add(map);
 		}
-		
+
 		return data;
 	}
-	
+
 	public static ArrayList<HashMap<String, ?>> getHats(Context c){
 		ArrayList<String> files = Utils.getFilesFromDirWithSuffix(c, "Graphics/Hats", ".png", true);
 		String pathPrefix = Utils.getDownloadPath(c) + "Graphics/Hats/";
 		int size = files.size();
 		ArrayList<HashMap<String, ?>> data = new ArrayList<HashMap<String, ?>>(size);
-		
+
 		HashMap<String, Object> hashmap; 
 		for(String s : files){
 			hashmap = new HashMap<String, Object>();
@@ -144,25 +144,26 @@
 			hashmap.put("img", b);
 			data.add(hashmap);
 		}
-		
+
 		return data;
 	}
-	
+
 	public static ArrayList<HashMap<String, ?>> getTeams(Context c){
 		ArrayList<HashMap<String, ?>> ret = new ArrayList<HashMap<String, ?>>();
-		
+
 		File teamsDir = new File(c.getFilesDir().getAbsolutePath() + '/' + Team.DIRECTORY_TEAMS);
 		File[] teamFileNames = teamsDir.listFiles();
-		
-		for(File s : teamFileNames){
-			Team t = Team.getTeamFromXml(s.getAbsolutePath());
-			if(t != null){
-				ret.add(teamToHashMap(t));
+		if(teamsDir != null){
+			for(File s : teamFileNames){
+				Team t = Team.getTeamFromXml(s.getAbsolutePath());
+				if(t != null){
+					ret.add(teamToHashMap(t));
+				}
 			}
 		}
 		return ret;
 	}
-	
+
 	public static HashMap<String, Object> teamToHashMap(Team t){
 		HashMap<String, Object> hashmap = new HashMap<String, Object>();
 		hashmap.put("team", t);
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/EngineProtocol/Team.java	Tue Aug 09 21:41:52 2011 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/EngineProtocol/Team.java	Wed Aug 10 01:22:52 2011 +0200
@@ -19,25 +19,25 @@
 public class Team implements Parcelable{
 
 	public static final String DIRECTORY_TEAMS = "teams";
+	private static final Integer[] TEAM_COLORS = {
+		0xd12b42, /* red    */ 
+		0x4980c1, /* blue   */ 
+		0x6ab530, /* green  */ 
+		0xbc64c4, /* purple */ 
+		0xe76d14, /* orange */ 
+		0x3fb6e6, /* cyan   */ 
+		0xe3e90c, /* yellow */ 
+		0x61d4ac, /* mint   */ 
+		0xf1c3e1, /* pink   */ 
+		/* add new colors here */
+	};
+
 //	private static final Integer[] TEAM_COLORS = {
-//		0xffd12b42, /* red    */ 
-//		0xff4980c1, /* blue   */ 
-//		0xff6ab530, /* green  */ 
-//		0xffbc64c4, /* purple */ 
-//		0xffe76d14, /* orange */ 
-//		0xff3fb6e6, /* cyan   */ 
-//		0xffe3e90c, /* yellow */ 
-//		0xff61d4ac, /* mint   */ 
-//		0xfff1c3e1, /* pink   */ 
-//		/* add new colors here */
+//		0xff0000, /* red    */ 
+//		0x00ff00, /* blue   */ 
+//		0x0000ff, /* green  */ 
 //	};
 
-	private static final Integer[] TEAM_COLORS = {
-		0xff0000, /* red    */ 
-		0x00ff00, /* blue   */ 
-		0x0000ff, /* green  */ 
-	};
-
 	private static final int STATE_START = 0;
 	private static final int STATE_ROOT = 1;
 	private static final int STATE_HOG_ROOT = 2;
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/TeamSelectionActivity.java	Tue Aug 09 21:41:52 2011 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/TeamSelectionActivity.java	Wed Aug 10 01:22:52 2011 +0200
@@ -91,7 +91,7 @@
 		setTeamColor(iv, color);
 	}
 	private void setTeamColor(View iv, int color){
-		iv.setBackgroundColor(color);
+		iv.setBackgroundColor(0xFF000000 + color);
 	}
 
 	private void setTeamHogCount(int position, int count){
@@ -183,10 +183,10 @@
 			selectAvailableTeamsItem(position);
 			return true;
 		case 1://delete
+			File f = new File(String.format("%s/%s/%s.xml", TeamSelectionActivity.this.getFilesDir(), Team.DIRECTORY_TEAMS, availableTeamsList.get(position).get("txt")));
+			f.delete();
 			availableTeamsList.remove(position);
 			((SimpleAdapter)availableTeams.getAdapter()).notifyDataSetChanged();
-			File f = new File(String.format("%s/%s/%s.xml", TeamSelectionActivity.this.getFilesDir(), Team.DIRECTORY_TEAMS, availableTeamsList.get(position).get("txt")));
-			f.delete();
 			return true;
 		case 2://edit
 			Intent i = new Intent(TeamSelectionActivity.this, TeamCreatorActivity.class);