Added a visual imageview to show how many teams have been selected, plus feedback when creating a new team: hedgeroid
authorXeli
Sun, 21 Aug 2011 19:40:01 +0200
branchhedgeroid
changeset 5627 ce2d92589cbc
parent 5625 9add7b92c5f0
child 5630 a5a338628633
Added a visual imageview to show how many teams have been selected, plus feedback when creating a new team:
project_files/Android-build/SDL-android-project/res/layout/starting_game.xml
project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/StartGameActivity.java
project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/TeamCreatorActivity.java
project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/TeamSelectionActivity.java
--- a/project_files/Android-build/SDL-android-project/res/layout/starting_game.xml	Sun Aug 21 18:14:49 2011 +0200
+++ b/project_files/Android-build/SDL-android-project/res/layout/starting_game.xml	Sun Aug 21 19:40:01 2011 +0200
@@ -125,16 +125,32 @@
        	android:background="@drawable/dropdown"/>
         
 	<include layout="@layout/backbutton"/>
+    
+    <LinearLayout
+    	android:layout_width="wrap_content"
+    	android:layout_height="wrap_content"
+    	android:layout_alignParentBottom="true"
+    	android:layout_centerHorizontal="true"
+    	android:orientation="horizontal">
     <ImageButton
     	android:id="@+id/btnTeams"
     	android:layout_width="120dip"
     	android:layout_height="40dip"
-    	android:layout_alignParentBottom="true"
-    	android:layout_centerHorizontal="true"
     	android:adjustViewBounds="true"
     	android:scaleType="centerInside"
     	android:background="@android:color/transparent"
     	android:src="@drawable/teams"/>
+    <ImageView
+    	android:id="@+id/imgTeamsCount"
+    	android:layout_width="40dip"
+    	android:layout_height="40dip"
+    	android:adjustViewBounds="true"
+    	android:scaleType="centerInside"
+    	android:background="@android:color/transparent"
+    	android:src="@drawable/teamcount"/>
+        
+    </LinearLayout>
+
     <ImageButton
     	android:id="@+id/btnStart"
     	android:layout_width="120dip"
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/StartGameActivity.java	Sun Aug 21 18:14:49 2011 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/StartGameActivity.java	Sun Aug 21 19:40:01 2011 +0200
@@ -48,7 +48,7 @@
 	private GameConfig config = null;
 	private ImageButton start, back, team;
 	private Spinner maps, gameplay, gamescheme, weapons, themes;
-	private ImageView themeIcon, mapPreview;
+	private ImageView themeIcon, mapPreview, teamCount;
 
 	public void onCreate(Bundle savedInstanceState){
 		super.onCreate(savedInstanceState);
@@ -75,7 +75,8 @@
 
 		themeIcon = (ImageView) findViewById(R.id.imgTheme);
 		mapPreview = (ImageView) findViewById(R.id.mapPreview);
-
+		teamCount = (ImageView) findViewById(R.id.imgTeamsCount);
+		
 		start.setOnClickListener(startClicker);
 		back.setOnClickListener(backClicker);
 		team.setOnClickListener(teamClicker);
@@ -122,7 +123,7 @@
 				for(Parcelable t : parcelables){
 					config.teams.add((Team)t);
 				}
-
+                teamCount.getDrawable().setLevel(config.teams.size());
 			}
 			break;
 		}
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/TeamCreatorActivity.java	Sun Aug 21 18:14:49 2011 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/TeamCreatorActivity.java	Sun Aug 21 19:40:01 2011 +0200
@@ -62,7 +62,6 @@
 	private ImageButton back, save, voiceButton;
 	private ScrollView scroller;
 	private MediaPlayer mp = null;
-	private ArrayList<RelativeLayout> hogs;
 	private boolean settingsChanged = false;
 	private boolean saved = false;
 
@@ -89,7 +88,6 @@
 		back.setOnClickListener(backClicker);
 
 		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);
@@ -236,7 +234,7 @@
 
 	private OnClickListener saveClicker = new OnClickListener() {
 		public void onClick(View v) {
-			Toast.makeText(TeamCreatorActivity.this, R.string.saved, Toast.LENGTH_SHORT);
+			Toast.makeText(TeamCreatorActivity.this, R.string.saved, Toast.LENGTH_SHORT).show();
 			saved = true;
 			Team team = new Team();
 			team.name = name.getText().toString();
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/TeamSelectionActivity.java	Sun Aug 21 18:14:49 2011 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/TeamSelectionActivity.java	Sun Aug 21 19:40:01 2011 +0200
@@ -48,12 +48,11 @@
 public class TeamSelectionActivity extends Activity{
 
 	private static final int ACTIVITY_TEAMCREATION = 0;
-	
+
 	private ImageButton addTeam, back;
 	private ListView availableTeams, selectedTeams;
 	private ArrayList<HashMap<String, Object>> availableTeamsList, selectedTeamsList;
 	private TextView txtInfo;
-	private int minTeams = 2;
 
 	public void onCreate(Bundle savedInstanceState){
 		super.onCreate(savedInstanceState);
@@ -62,8 +61,8 @@
 
 		addTeam = (ImageButton) findViewById(R.id.btnAdd);
 		back = (ImageButton) findViewById(R.id.btnBack);
-        txtInfo = (TextView) findViewById(R.id.txtInfo);
-        
+		txtInfo = (TextView) findViewById(R.id.txtInfo);
+
 		addTeam.setOnClickListener(addTeamClicker);
 		back.setOnClickListener(backClicker);
 
@@ -120,14 +119,14 @@
 			super.onActivityResult(requestCode, resultCode, data);
 		}
 	}
-	
+
 	private void updateListViews(){
 		unregisterForContextMenu(availableTeams);
 		availableTeamsList = FrontendDataUtils.getTeams(this);
 		ArrayList<HashMap<String, Object>> toBeRemoved = new ArrayList<HashMap<String, Object>>();
 		for(HashMap<String, Object> hashmap : selectedTeamsList){
 			String name = (String)hashmap.get("txt");
-			
+
 			for(HashMap<String, Object> hash : availableTeamsList){
 				if(name.equals((String)hash.get("txt"))){
 					toBeRemoved.add(hash);
@@ -135,15 +134,15 @@
 			}
 		}
 		for(HashMap<String, Object> hash: toBeRemoved) availableTeamsList.remove(hash);
-		
+
 		SimpleAdapter adapter = new SimpleAdapter(this, availableTeamsList, R.layout.team_selection_entry, new String[]{"txt", "img"}, new int[]{R.id.txtName, R.id.imgDifficulty});
 		availableTeams.setAdapter(adapter);
 		registerForContextMenu(availableTeams);
 		availableTeams.setOnItemClickListener(availableClicker);
-		
-		
+
+
 	}
-	
+
 	private void setTeamColor(int position, int color){
 		View iv = ((RelativeLayout)selectedTeams.getChildAt(position)).findViewById(R.id.teamCount);
 		setTeamColor(iv, color);
@@ -222,7 +221,7 @@
 			selectedTeamsList.remove(position);
 			((SimpleAdapter)availableTeams.getAdapter()).notifyDataSetChanged();
 			((SimpleAdapter)selectedTeams.getAdapter()).notifyDataSetChanged();
-			
+
 			txtInfo.setText(String.format(getResources().getString(R.string.teams_info_template), selectedTeamsList.size()));
 		}
 
@@ -267,27 +266,24 @@
 		t.setRandomColor(illegalcolors);
 		hash.put("color", t.color);
 		hash.put("count", t.hogCount);
-		
+
 		selectedTeamsList.add(hash);
 		availableTeamsList.remove(position);
 		((SimpleAdapter)availableTeams.getAdapter()).notifyDataSetChanged();
 		((SimpleAdapter)selectedTeams.getAdapter()).notifyDataSetChanged();
-		
+
 		txtInfo.setText(String.format(getResources().getString(R.string.teams_info_template), selectedTeamsList.size()));
 	}
 
 	private void returnTeams(){
 		int teamsCount = selectedTeamsList.size();
-		if(teamsCount >= minTeams){
-			Intent i = new Intent();
-			Parcelable[] teams = new Parcelable[teamsCount];
-			for(int x = 0 ; x < teamsCount; x++){
-				teams[x] = (Team)selectedTeamsList.get(x).get("team");
-			}
-			i.putExtra("teams", teams);
-			setResult(Activity.RESULT_OK, i);
-		}else{
-			setResult(Activity.RESULT_CANCELED);
+		Intent i = new Intent();
+		Parcelable[] teams = new Parcelable[teamsCount];
+		for(int x = 0 ; x < teamsCount; x++){
+			teams[x] = (Team)selectedTeamsList.get(x).get("team");
 		}
+		i.putExtra("teams", teams);
+		setResult(Activity.RESULT_OK, i);
+
 	}
 }