mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-18 22:26:30 +01:00
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:
parent
935fe0c7a0
commit
79bd17e59b
5 changed files with 402 additions and 347 deletions
|
@ -18,10 +18,13 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
>
|
||||
<TextView android:id="@+id/players"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
|
||||
<LinearLayout android:id="@+id/player_list"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
>
|
||||
</LinearLayout>
|
||||
|
||||
<TextView android:id="@+id/role"
|
||||
android:layout_width="wrap_content"
|
||||
|
|
18
xwords4/android/XWords4/res/layout/player_list_elem.xml
Normal file
18
xwords4/android/XWords4/res/layout/player_list_elem.xml
Normal 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>
|
|
@ -72,380 +72,407 @@ public class DBUtils {
|
|||
cursor.getInt(cursor.
|
||||
getColumnIndex(DBHelper.NUM_PLAYERS));
|
||||
summary.players =
|
||||
cursor.getString(cursor.
|
||||
getColumnIndex(DBHelper.PLAYERS));
|
||||
summary.dictLang =
|
||||
cursor.getInt(cursor.
|
||||
getColumnIndex(DBHelper.DICTLANG));
|
||||
summary.dictName =
|
||||
cursor.getString(cursor.
|
||||
getColumnIndex(DBHelper.DICTNAME));
|
||||
int tmp = cursor.getInt(cursor.
|
||||
getColumnIndex(DBHelper.GAME_OVER));
|
||||
summary.gameOver = tmp == 0 ? false : true;
|
||||
parsePlayers( cursor.getString(cursor.
|
||||
getColumnIndex(DBHelper.
|
||||
PLAYERS)),
|
||||
summary.nPlayers );
|
||||
summary.dictLang =
|
||||
cursor.getInt(cursor.
|
||||
getColumnIndex(DBHelper.DICTLANG));
|
||||
summary.dictName =
|
||||
cursor.getString(cursor.
|
||||
getColumnIndex(DBHelper.DICTNAME));
|
||||
int tmp = cursor.getInt(cursor.
|
||||
getColumnIndex(DBHelper.GAME_OVER));
|
||||
summary.gameOver = tmp == 0 ? false : true;
|
||||
|
||||
String scoresStr =
|
||||
cursor.getString( cursor.getColumnIndex(DBHelper.SCORES));
|
||||
if ( null != scoresStr ) {
|
||||
StringTokenizer st = new StringTokenizer( scoresStr );
|
||||
int[] scores = new int[st.countTokens()];
|
||||
for ( int ii = 0; ii < scores.length; ++ii ) {
|
||||
Assert.assertTrue( st.hasMoreTokens() );
|
||||
String token = st.nextToken();
|
||||
scores[ii] = Integer.parseInt( token );
|
||||
}
|
||||
summary.scores = scores;
|
||||
}
|
||||
String scoresStr =
|
||||
cursor.getString( cursor.getColumnIndex(DBHelper.SCORES));
|
||||
if ( null != scoresStr ) {
|
||||
StringTokenizer st = new StringTokenizer( scoresStr );
|
||||
int[] scores = new int[st.countTokens()];
|
||||
for ( int ii = 0; ii < scores.length; ++ii ) {
|
||||
Assert.assertTrue( st.hasMoreTokens() );
|
||||
String token = st.nextToken();
|
||||
scores[ii] = Integer.parseInt( token );
|
||||
}
|
||||
summary.scores = scores;
|
||||
}
|
||||
|
||||
int col = cursor.getColumnIndex( DBHelper.CONTYPE );
|
||||
if ( col >= 0 ) {
|
||||
tmp = cursor.getInt( col );
|
||||
summary.conType = CommsAddrRec.CommsConnType.values()[tmp];
|
||||
col = cursor.getColumnIndex( DBHelper.ROOMNAME );
|
||||
if ( col >= 0 ) {
|
||||
summary.roomName = cursor.getString( col );
|
||||
}
|
||||
col = cursor.getColumnIndex( DBHelper.RELAYID );
|
||||
if ( col >= 0 ) {
|
||||
summary.relayID = cursor.getString( col );
|
||||
}
|
||||
col = cursor.getColumnIndex( DBHelper.SEED );
|
||||
if ( col >= 0 ) {
|
||||
summary.seed = cursor.getInt( col );
|
||||
}
|
||||
col = cursor.getColumnIndex( DBHelper.SMSPHONE );
|
||||
if ( col >= 0 ) {
|
||||
summary.smsPhone = cursor.getString( col );
|
||||
}
|
||||
}
|
||||
int col = cursor.getColumnIndex( DBHelper.CONTYPE );
|
||||
if ( col >= 0 ) {
|
||||
tmp = cursor.getInt( col );
|
||||
summary.conType = CommsAddrRec.CommsConnType.values()[tmp];
|
||||
col = cursor.getColumnIndex( DBHelper.ROOMNAME );
|
||||
if ( col >= 0 ) {
|
||||
summary.roomName = cursor.getString( col );
|
||||
}
|
||||
col = cursor.getColumnIndex( DBHelper.RELAYID );
|
||||
if ( col >= 0 ) {
|
||||
summary.relayID = cursor.getString( col );
|
||||
}
|
||||
col = cursor.getColumnIndex( DBHelper.SEED );
|
||||
if ( col >= 0 ) {
|
||||
summary.seed = cursor.getInt( col );
|
||||
}
|
||||
col = cursor.getColumnIndex( DBHelper.SMSPHONE );
|
||||
if ( col >= 0 ) {
|
||||
summary.smsPhone = cursor.getString( col );
|
||||
}
|
||||
}
|
||||
|
||||
col = cursor.getColumnIndex( DBHelper.SERVERROLE );
|
||||
tmp = cursor.getInt( col );
|
||||
summary.serverRole = CurGameInfo.DeviceRole.values()[tmp];
|
||||
|
||||
col = cursor.getColumnIndex( DBHelper.HASMSGS );
|
||||
if ( col >= 0 ) {
|
||||
summary.msgsPending = 0 != cursor.getInt( col );
|
||||
}
|
||||
}
|
||||
cursor.close();
|
||||
db.close();
|
||||
}
|
||||
col = cursor.getColumnIndex( DBHelper.SERVERROLE );
|
||||
tmp = cursor.getInt( col );
|
||||
summary.serverRole = CurGameInfo.DeviceRole.values()[tmp];
|
||||
|
||||
if ( null == summary ) {
|
||||
summary = GameUtils.summarize( context, file );
|
||||
saveSummary( context, file, summary );
|
||||
}
|
||||
return summary;
|
||||
}
|
||||
col = cursor.getColumnIndex( DBHelper.HASMSGS );
|
||||
if ( col >= 0 ) {
|
||||
summary.msgsPending = 0 != cursor.getInt( col );
|
||||
}
|
||||
}
|
||||
cursor.close();
|
||||
db.close();
|
||||
}
|
||||
|
||||
public static void saveSummary( Context context, String path,
|
||||
GameSummary summary )
|
||||
{
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
||||
if ( null == summary ) {
|
||||
summary = GameUtils.summarize( context, file );
|
||||
saveSummary( context, file, summary );
|
||||
}
|
||||
return summary;
|
||||
}
|
||||
|
||||
if ( null == summary ) {
|
||||
String selection = DBHelper.FILE_NAME + "=\"" + path + "\"";
|
||||
db.delete( DBHelper.TABLE_NAME_SUM, selection, null );
|
||||
} else {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put( DBHelper.NUM_MOVES, summary.nMoves );
|
||||
values.put( DBHelper.NUM_PLAYERS, summary.nPlayers );
|
||||
values.put( DBHelper.PLAYERS,
|
||||
summary.summarizePlayers(context) );
|
||||
values.put( DBHelper.DICTLANG, summary.dictLang );
|
||||
values.put( DBHelper.DICTNAME, summary.dictName );
|
||||
values.put( DBHelper.GAME_OVER, summary.gameOver );
|
||||
values.put( DBHelper.HASMSGS, 0 );
|
||||
public static void saveSummary( Context context, String path,
|
||||
GameSummary summary )
|
||||
{
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
||||
|
||||
if ( null != summary.scores ) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for ( int score : summary.scores ) {
|
||||
sb.append( String.format( "%d ", score ) );
|
||||
}
|
||||
values.put( DBHelper.SCORES, sb.toString() );
|
||||
}
|
||||
if ( null == summary ) {
|
||||
String selection = DBHelper.FILE_NAME + "=\"" + path + "\"";
|
||||
db.delete( DBHelper.TABLE_NAME_SUM, selection, null );
|
||||
} else {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put( DBHelper.NUM_MOVES, summary.nMoves );
|
||||
values.put( DBHelper.NUM_PLAYERS, summary.nPlayers );
|
||||
values.put( DBHelper.PLAYERS,
|
||||
summary.summarizePlayers(context) );
|
||||
values.put( DBHelper.DICTLANG, summary.dictLang );
|
||||
values.put( DBHelper.DICTNAME, summary.dictName );
|
||||
values.put( DBHelper.GAME_OVER, summary.gameOver );
|
||||
values.put( DBHelper.HASMSGS, 0 );
|
||||
|
||||
if ( null != summary.conType ) {
|
||||
values.put( DBHelper.CONTYPE, summary.conType.ordinal() );
|
||||
values.put( DBHelper.ROOMNAME, summary.roomName );
|
||||
values.put( DBHelper.RELAYID, summary.relayID );
|
||||
values.put( DBHelper.SEED, summary.seed );
|
||||
values.put( DBHelper.SMSPHONE, summary.smsPhone );
|
||||
}
|
||||
values.put( DBHelper.SERVERROLE, summary.serverRole.ordinal() );
|
||||
if ( null != summary.scores ) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for ( int score : summary.scores ) {
|
||||
sb.append( String.format( "%d ", score ) );
|
||||
}
|
||||
values.put( DBHelper.SCORES, sb.toString() );
|
||||
}
|
||||
|
||||
Utils.logf( "saveSummary: nMoves=%d", summary.nMoves );
|
||||
if ( null != summary.conType ) {
|
||||
values.put( DBHelper.CONTYPE, summary.conType.ordinal() );
|
||||
values.put( DBHelper.ROOMNAME, summary.roomName );
|
||||
values.put( DBHelper.RELAYID, summary.relayID );
|
||||
values.put( DBHelper.SEED, summary.seed );
|
||||
values.put( DBHelper.SMSPHONE, summary.smsPhone );
|
||||
}
|
||||
values.put( DBHelper.SERVERROLE, summary.serverRole.ordinal() );
|
||||
|
||||
String selection = DBHelper.FILE_NAME + "=\"" + path + "\"";
|
||||
long result = db.update( DBHelper.TABLE_NAME_SUM,
|
||||
values, selection, null );
|
||||
Assert.assertTrue( result >= 0 );
|
||||
}
|
||||
db.close();
|
||||
}
|
||||
} // saveSummary
|
||||
Utils.logf( "saveSummary: nMoves=%d", summary.nMoves );
|
||||
|
||||
public static int countGamesUsing( Context context, String dict )
|
||||
{
|
||||
int result = 0;
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
||||
String selection = DBHelper.DICTNAME + " LIKE \'"
|
||||
+ dict + "\'";
|
||||
// null for columns will return whole rows: bad
|
||||
String[] columns = { DBHelper.DICTNAME };
|
||||
Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns,
|
||||
selection, null, null, null, null );
|
||||
String selection = DBHelper.FILE_NAME + "=\"" + path + "\"";
|
||||
long result = db.update( DBHelper.TABLE_NAME_SUM,
|
||||
values, selection, null );
|
||||
Assert.assertTrue( result >= 0 );
|
||||
}
|
||||
db.close();
|
||||
}
|
||||
} // saveSummary
|
||||
|
||||
result = cursor.getCount();
|
||||
cursor.close();
|
||||
db.close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public static int countGamesUsing( Context context, String dict )
|
||||
{
|
||||
int result = 0;
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
||||
String selection = DBHelper.DICTNAME + " LIKE \'"
|
||||
+ dict + "\'";
|
||||
// null for columns will return whole rows: bad
|
||||
String[] columns = { DBHelper.DICTNAME };
|
||||
Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns,
|
||||
selection, null, null, null, null );
|
||||
|
||||
public static void setHasMsgs( String relayID )
|
||||
{
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
||||
|
||||
String selection = DBHelper.RELAYID + "=\'" + relayID + "\'";
|
||||
ContentValues values = new ContentValues();
|
||||
values.put( DBHelper.HASMSGS, 1 );
|
||||
|
||||
int result = db.update( DBHelper.TABLE_NAME_SUM,
|
||||
values, selection, null );
|
||||
Assert.assertTrue( result == 1 );
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
result = cursor.getCount();
|
||||
cursor.close();
|
||||
db.close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String getPathFor( Context context, String relayID )
|
||||
{
|
||||
String result = null;
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
||||
String[] columns = { DBHelper.FILE_NAME };
|
||||
String selection = DBHelper.RELAYID + "='" + relayID + "'";
|
||||
Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns,
|
||||
selection, null, null, null, null );
|
||||
if ( 1 == cursor.getCount() && cursor.moveToFirst() ) {
|
||||
result = cursor.getString( cursor
|
||||
.getColumnIndex(DBHelper.FILE_NAME));
|
||||
public static void setHasMsgs( String relayID )
|
||||
{
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
||||
|
||||
}
|
||||
cursor.close();
|
||||
db.close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
String selection = DBHelper.RELAYID + "=\'" + relayID + "\'";
|
||||
ContentValues values = new ContentValues();
|
||||
values.put( DBHelper.HASMSGS, 1 );
|
||||
|
||||
public static String[] getRelayIDNoMsgs( Context context )
|
||||
{
|
||||
String[] result = null;
|
||||
initDB( context );
|
||||
ArrayList<String> ids = new ArrayList<String>();
|
||||
int result = db.update( DBHelper.TABLE_NAME_SUM,
|
||||
values, selection, null );
|
||||
Assert.assertTrue( result == 1 );
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
||||
String[] columns = { DBHelper.RELAYID };
|
||||
String selection = DBHelper.RELAYID + " NOT null AND "
|
||||
+ "NOT " + DBHelper.HASMSGS;
|
||||
public static String getPathFor( Context context, String relayID )
|
||||
{
|
||||
String result = null;
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
||||
String[] columns = { DBHelper.FILE_NAME };
|
||||
String selection = DBHelper.RELAYID + "='" + relayID + "'";
|
||||
Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns,
|
||||
selection, null, null, null, null );
|
||||
if ( 1 == cursor.getCount() && cursor.moveToFirst() ) {
|
||||
result = cursor.getString( cursor
|
||||
.getColumnIndex(DBHelper.FILE_NAME));
|
||||
|
||||
Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns,
|
||||
selection, null, null, null, null );
|
||||
}
|
||||
cursor.close();
|
||||
db.close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
if ( 0 < cursor.getCount() ) {
|
||||
cursor.moveToFirst();
|
||||
for ( ; ; ) {
|
||||
ids.add( cursor.
|
||||
getString( cursor.
|
||||
getColumnIndex(DBHelper.RELAYID)) );
|
||||
if ( cursor.isLast() ) {
|
||||
break;
|
||||
}
|
||||
cursor.moveToNext();
|
||||
}
|
||||
}
|
||||
cursor.close();
|
||||
db.close();
|
||||
}
|
||||
public static String[] getRelayIDNoMsgs( Context context )
|
||||
{
|
||||
String[] result = null;
|
||||
initDB( context );
|
||||
ArrayList<String> ids = new ArrayList<String>();
|
||||
|
||||
if ( 0 < ids.size() ) {
|
||||
result = ids.toArray( new String[ids.size()] );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
||||
String[] columns = { DBHelper.RELAYID };
|
||||
String selection = DBHelper.RELAYID + " NOT null AND "
|
||||
+ "NOT " + DBHelper.HASMSGS;
|
||||
|
||||
public static void addDeceased( Context context, String relayID,
|
||||
int seed )
|
||||
{
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
||||
Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns,
|
||||
selection, null, null, null, null );
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
values.put( DBHelper.RELAYID, relayID );
|
||||
values.put( DBHelper.SEED, seed );
|
||||
if ( 0 < cursor.getCount() ) {
|
||||
cursor.moveToFirst();
|
||||
for ( ; ; ) {
|
||||
ids.add( cursor.
|
||||
getString( cursor.
|
||||
getColumnIndex(DBHelper.RELAYID)) );
|
||||
if ( cursor.isLast() ) {
|
||||
break;
|
||||
}
|
||||
cursor.moveToNext();
|
||||
}
|
||||
}
|
||||
cursor.close();
|
||||
db.close();
|
||||
}
|
||||
|
||||
try {
|
||||
long result = db.replaceOrThrow( DBHelper.TABLE_NAME_OBITS,
|
||||
"", values );
|
||||
} catch ( Exception ex ) {
|
||||
Utils.logf( "ex: %s", ex.toString() );
|
||||
}
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
if ( 0 < ids.size() ) {
|
||||
result = ids.toArray( new String[ids.size()] );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Obit[] listObits( Context context )
|
||||
{
|
||||
Obit[] result = null;
|
||||
ArrayList<Obit> al = new ArrayList<Obit>();
|
||||
public static void addDeceased( Context context, String relayID,
|
||||
int seed )
|
||||
{
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
||||
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
||||
String[] columns = { DBHelper.RELAYID, DBHelper.SEED };
|
||||
Cursor cursor = db.query( DBHelper.TABLE_NAME_OBITS, columns,
|
||||
null, null, null, null, null );
|
||||
if ( 0 < cursor.getCount() ) {
|
||||
cursor.moveToFirst();
|
||||
for ( ; ; ) {
|
||||
int index = cursor.getColumnIndex( DBHelper.RELAYID );
|
||||
String relayID = cursor.getString( index );
|
||||
index = cursor.getColumnIndex( DBHelper.SEED );
|
||||
int seed = cursor.getInt( index );
|
||||
al.add( new Obit( relayID, seed ) );
|
||||
if ( cursor.isLast() ) {
|
||||
break;
|
||||
}
|
||||
cursor.moveToNext();
|
||||
}
|
||||
}
|
||||
cursor.close();
|
||||
db.close();
|
||||
}
|
||||
ContentValues values = new ContentValues();
|
||||
values.put( DBHelper.RELAYID, relayID );
|
||||
values.put( DBHelper.SEED, seed );
|
||||
|
||||
int siz = al.size();
|
||||
if ( siz > 0 ) {
|
||||
result = al.toArray( new Obit[siz] );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
try {
|
||||
long result = db.replaceOrThrow( DBHelper.TABLE_NAME_OBITS,
|
||||
"", values );
|
||||
} catch ( Exception ex ) {
|
||||
Utils.logf( "ex: %s", ex.toString() );
|
||||
}
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
|
||||
public static void clearObits( Context context, Obit[] obits )
|
||||
{
|
||||
String fmt = DBHelper.RELAYID + "= \"%s\" AND + "
|
||||
+ DBHelper.SEED + " = %d";
|
||||
public static Obit[] listObits( Context context )
|
||||
{
|
||||
Obit[] result = null;
|
||||
ArrayList<Obit> al = new ArrayList<Obit>();
|
||||
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
||||
String[] columns = { DBHelper.RELAYID, DBHelper.SEED };
|
||||
Cursor cursor = db.query( DBHelper.TABLE_NAME_OBITS, columns,
|
||||
null, null, null, null, null );
|
||||
if ( 0 < cursor.getCount() ) {
|
||||
cursor.moveToFirst();
|
||||
for ( ; ; ) {
|
||||
int index = cursor.getColumnIndex( DBHelper.RELAYID );
|
||||
String relayID = cursor.getString( index );
|
||||
index = cursor.getColumnIndex( DBHelper.SEED );
|
||||
int seed = cursor.getInt( index );
|
||||
al.add( new Obit( relayID, seed ) );
|
||||
if ( cursor.isLast() ) {
|
||||
break;
|
||||
}
|
||||
cursor.moveToNext();
|
||||
}
|
||||
}
|
||||
cursor.close();
|
||||
db.close();
|
||||
}
|
||||
|
||||
for ( Obit obit: obits ) {
|
||||
String selection = String.format( fmt, obit.m_relayID,
|
||||
obit.m_seed );
|
||||
db.delete( DBHelper.TABLE_NAME_OBITS, selection, null );
|
||||
}
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
int siz = al.size();
|
||||
if ( siz > 0 ) {
|
||||
result = al.toArray( new Obit[siz] );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void saveGame( Context context, String path, byte[] bytes,
|
||||
boolean setCreate )
|
||||
{
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
||||
public static void clearObits( Context context, Obit[] obits )
|
||||
{
|
||||
String fmt = DBHelper.RELAYID + "= \"%s\" AND + "
|
||||
+ DBHelper.SEED + " = %d";
|
||||
|
||||
String selection = DBHelper.FILE_NAME + "=\"" + path + "\"";
|
||||
ContentValues values = new ContentValues();
|
||||
values.put( DBHelper.SNAPSHOT, bytes );
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
||||
|
||||
long timestamp = new Date().getTime();
|
||||
if ( setCreate ) {
|
||||
values.put( DBHelper.CREATE_TIME, timestamp );
|
||||
}
|
||||
values.put( DBHelper.LASTPLAY_TIME, timestamp );
|
||||
for ( Obit obit: obits ) {
|
||||
String selection = String.format( fmt, obit.m_relayID,
|
||||
obit.m_seed );
|
||||
db.delete( DBHelper.TABLE_NAME_OBITS, selection, null );
|
||||
}
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
|
||||
int result = db.update( DBHelper.TABLE_NAME_SUM,
|
||||
values, selection, null );
|
||||
if ( 0 == result ) {
|
||||
values.put( DBHelper.FILE_NAME, path );
|
||||
long row = db.insert( DBHelper.TABLE_NAME_SUM, null, values );
|
||||
Assert.assertTrue( row >= 0 );
|
||||
}
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
public static void saveGame( Context context, String path, byte[] bytes,
|
||||
boolean setCreate )
|
||||
{
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
||||
|
||||
public static byte[] loadGame( Context context, String path )
|
||||
{
|
||||
Assert.assertNotNull( path );
|
||||
byte[] result = null;
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
||||
String selection = DBHelper.FILE_NAME + "=\"" + path + "\"";
|
||||
ContentValues values = new ContentValues();
|
||||
values.put( DBHelper.SNAPSHOT, bytes );
|
||||
|
||||
String[] columns = { DBHelper.SNAPSHOT };
|
||||
String selection = DBHelper.FILE_NAME + "=\"" + path + "\"";
|
||||
Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns,
|
||||
selection, null, null, null, null );
|
||||
if ( 1 == cursor.getCount() && cursor.moveToFirst() ) {
|
||||
result = cursor.getBlob( cursor
|
||||
.getColumnIndex(DBHelper.SNAPSHOT));
|
||||
}
|
||||
cursor.close();
|
||||
db.close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
long timestamp = new Date().getTime();
|
||||
if ( setCreate ) {
|
||||
values.put( DBHelper.CREATE_TIME, timestamp );
|
||||
}
|
||||
values.put( DBHelper.LASTPLAY_TIME, timestamp );
|
||||
|
||||
public static void deleteGame( Context context, String path )
|
||||
{
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
||||
String selection = DBHelper.FILE_NAME + "=\"" + path + "\"";
|
||||
db.delete( DBHelper.TABLE_NAME_SUM, selection, null );
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
int result = db.update( DBHelper.TABLE_NAME_SUM,
|
||||
values, selection, null );
|
||||
if ( 0 == result ) {
|
||||
values.put( DBHelper.FILE_NAME, path );
|
||||
long row = db.insert( DBHelper.TABLE_NAME_SUM, null, values );
|
||||
Assert.assertTrue( row >= 0 );
|
||||
}
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
|
||||
public static String[] gamesList( Context context )
|
||||
{
|
||||
ArrayList<String> al = new ArrayList<String>();
|
||||
public static byte[] loadGame( Context context, String path )
|
||||
{
|
||||
Assert.assertNotNull( path );
|
||||
byte[] result = null;
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
||||
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
||||
String[] columns = { DBHelper.SNAPSHOT };
|
||||
String selection = DBHelper.FILE_NAME + "=\"" + path + "\"";
|
||||
Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns,
|
||||
selection, null, null, null, null );
|
||||
if ( 1 == cursor.getCount() && cursor.moveToFirst() ) {
|
||||
result = cursor.getBlob( cursor
|
||||
.getColumnIndex(DBHelper.SNAPSHOT));
|
||||
}
|
||||
cursor.close();
|
||||
db.close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
String[] columns = { DBHelper.FILE_NAME };
|
||||
Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns,
|
||||
null, null, null, null, null );
|
||||
if ( 0 < cursor.getCount() ) {
|
||||
cursor.moveToFirst();
|
||||
for ( ; ; ) {
|
||||
int index = cursor.getColumnIndex( DBHelper.FILE_NAME );
|
||||
String name = cursor.getString( index );
|
||||
al.add( cursor.getString( index ) );
|
||||
if ( cursor.isLast() ) {
|
||||
break;
|
||||
}
|
||||
cursor.moveToNext();
|
||||
}
|
||||
}
|
||||
cursor.close();
|
||||
db.close();
|
||||
}
|
||||
public static void deleteGame( Context context, String path )
|
||||
{
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
||||
String selection = DBHelper.FILE_NAME + "=\"" + path + "\"";
|
||||
db.delete( DBHelper.TABLE_NAME_SUM, selection, null );
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
|
||||
return al.toArray( new String[al.size()] );
|
||||
public static String[] gamesList( Context context )
|
||||
{
|
||||
ArrayList<String> al = new ArrayList<String>();
|
||||
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
||||
|
||||
String[] columns = { DBHelper.FILE_NAME };
|
||||
Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns,
|
||||
null, null, null, null, null );
|
||||
if ( 0 < cursor.getCount() ) {
|
||||
cursor.moveToFirst();
|
||||
for ( ; ; ) {
|
||||
int index = cursor.getColumnIndex( DBHelper.FILE_NAME );
|
||||
String name = cursor.getString( index );
|
||||
al.add( cursor.getString( index ) );
|
||||
if ( cursor.isLast() ) {
|
||||
break;
|
||||
}
|
||||
cursor.moveToNext();
|
||||
}
|
||||
}
|
||||
cursor.close();
|
||||
db.close();
|
||||
}
|
||||
|
||||
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 )
|
||||
|
|
|
@ -28,6 +28,8 @@ import android.database.DataSetObserver;
|
|||
import java.io.FileInputStream;
|
||||
import java.util.HashMap;
|
||||
import android.view.LayoutInflater;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
|
||||
|
@ -65,15 +67,21 @@ public class GameListAdapter extends XWListAdapter {
|
|||
View layout = m_viewsCache.get( path );
|
||||
|
||||
if ( null == layout ) {
|
||||
Utils.logf( "creating new list elem for %s", path );
|
||||
TextView view;
|
||||
layout = m_factory.inflate( m_layoutId, null );
|
||||
|
||||
GameSummary summary = DBUtils.getSummary( m_context, path );
|
||||
|
||||
TextView view = (TextView)layout.findViewById( R.id.players );
|
||||
String gameName = GameUtils.gameName( m_context, path );
|
||||
view.setText( String.format( "%s: %s", gameName,
|
||||
summary.players ) );
|
||||
LinearLayout list =
|
||||
(LinearLayout)layout.findViewById( R.id.player_list );
|
||||
for ( int ii = 0; ii < summary.nPlayers; ++ii ) {
|
||||
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.setText( summary.summarizeState( m_context ) );
|
||||
|
|
|
@ -33,7 +33,7 @@ public class GameSummary {
|
|||
public int nPlayers;
|
||||
public int[] scores;
|
||||
public boolean gameOver;
|
||||
public String players;
|
||||
public String[] players;
|
||||
public CommsAddrRec.CommsConnType conType;
|
||||
public String smsPhone;
|
||||
// relay-related fields
|
||||
|
@ -67,7 +67,6 @@ public class GameSummary {
|
|||
public String summarizePlayers( Context context )
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
String vsString = context.getString( R.string.vs );
|
||||
for ( int ii = 0; ; ) {
|
||||
|
||||
int score = 0;
|
||||
|
@ -76,11 +75,11 @@ public class GameSummary {
|
|||
score = scores[ii];
|
||||
} 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 ) {
|
||||
break;
|
||||
}
|
||||
sb.append( String.format( " %s ", vsString ) );
|
||||
sb.append( "\n" );
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue