put each player in a game list item in its own line with score at

right end and name at the left.  This will allow e.g. marking in green
a local player whose turn it is.
This commit is contained in:
Andy2 2011-02-03 06:47:20 -08:00
parent 935fe0c7a0
commit 79bd17e59b
5 changed files with 402 additions and 347 deletions

View file

@ -18,10 +18,13 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
> >
<TextView android:id="@+id/players"
android:layout_width="wrap_content" <LinearLayout android:id="@+id/player_list"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
/> >
</LinearLayout>
<TextView android:id="@+id/role" <TextView android:id="@+id/role"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View file

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView android:id="@+id/item_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
/>
<TextView android:id="@+id/item_score"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
/>
</LinearLayout>

View file

@ -72,8 +72,10 @@ public class DBUtils {
cursor.getInt(cursor. cursor.getInt(cursor.
getColumnIndex(DBHelper.NUM_PLAYERS)); getColumnIndex(DBHelper.NUM_PLAYERS));
summary.players = summary.players =
cursor.getString(cursor. parsePlayers( cursor.getString(cursor.
getColumnIndex(DBHelper.PLAYERS)); getColumnIndex(DBHelper.
PLAYERS)),
summary.nPlayers );
summary.dictLang = summary.dictLang =
cursor.getInt(cursor. cursor.getInt(cursor.
getColumnIndex(DBHelper.DICTLANG)); getColumnIndex(DBHelper.DICTLANG));
@ -448,6 +450,31 @@ public class DBUtils {
return al.toArray( new String[al.size()] ); return al.toArray( new String[al.size()] );
} }
private static String[] parsePlayers( final String players, int nPlayers )
{
String[] result = new String[nPlayers];
String sep = "vs. ";
if ( players.contains("\n") ) {
sep = "\n";
}
int ii, nxt;
for ( ii = 0, nxt = 0; ; ++ii ) {
int prev = nxt;
nxt = players.indexOf( sep, nxt );
String name = -1 == nxt ?
players.substring( prev ) : players.substring( prev, nxt );
Utils.logf( "got name[%d]: \"%s\"", ii, name );
result[ii] = name;
if ( -1 == nxt ) {
break;
}
nxt += sep.length();
}
return result;
}
private static void initDB( Context context ) private static void initDB( Context context )
{ {
if ( null == s_dbHelper ) { if ( null == s_dbHelper ) {

View file

@ -28,6 +28,8 @@ import android.database.DataSetObserver;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.util.HashMap; import java.util.HashMap;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.widget.LinearLayout;
import junit.framework.Assert; import junit.framework.Assert;
@ -65,15 +67,21 @@ public class GameListAdapter extends XWListAdapter {
View layout = m_viewsCache.get( path ); View layout = m_viewsCache.get( path );
if ( null == layout ) { if ( null == layout ) {
Utils.logf( "creating new list elem for %s", path ); TextView view;
layout = m_factory.inflate( m_layoutId, null ); layout = m_factory.inflate( m_layoutId, null );
GameSummary summary = DBUtils.getSummary( m_context, path ); GameSummary summary = DBUtils.getSummary( m_context, path );
TextView view = (TextView)layout.findViewById( R.id.players ); LinearLayout list =
String gameName = GameUtils.gameName( m_context, path ); (LinearLayout)layout.findViewById( R.id.player_list );
view.setText( String.format( "%s: %s", gameName, for ( int ii = 0; ii < summary.nPlayers; ++ii ) {
summary.players ) ); View tmp = m_factory.inflate( R.layout.player_list_elem, null );
view = (TextView)tmp.findViewById( R.id.item_name );
view.setText( summary.players[ii] );
view = (TextView)tmp.findViewById( R.id.item_score );
view.setText( String.format( "%d", summary.scores[ii] ) );
list.addView( tmp, ii );
}
view = (TextView)layout.findViewById( R.id.state ); view = (TextView)layout.findViewById( R.id.state );
view.setText( summary.summarizeState( m_context ) ); view.setText( summary.summarizeState( m_context ) );

View file

@ -33,7 +33,7 @@ public class GameSummary {
public int nPlayers; public int nPlayers;
public int[] scores; public int[] scores;
public boolean gameOver; public boolean gameOver;
public String players; public String[] players;
public CommsAddrRec.CommsConnType conType; public CommsAddrRec.CommsConnType conType;
public String smsPhone; public String smsPhone;
// relay-related fields // relay-related fields
@ -67,7 +67,6 @@ public class GameSummary {
public String summarizePlayers( Context context ) public String summarizePlayers( Context context )
{ {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
String vsString = context.getString( R.string.vs );
for ( int ii = 0; ; ) { for ( int ii = 0; ; ) {
int score = 0; int score = 0;
@ -76,11 +75,11 @@ public class GameSummary {
score = scores[ii]; score = scores[ii];
} catch ( Exception ex ){} } catch ( Exception ex ){}
sb.append( String.format( "%s(%d)", m_gi.players[ii].name, score ) ); sb.append( m_gi.players[ii].name );
if ( ++ii >= nPlayers ) { if ( ++ii >= nPlayers ) {
break; break;
} }
sb.append( String.format( " %s ", vsString ) ); sb.append( "\n" );
} }
return sb.toString(); return sb.toString();
} }