mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-30 08:34:16 +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_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:layout_height="wrap_content"
|
android:orientation="vertical"
|
||||||
/>
|
android:layout_width="fill_parent"
|
||||||
|
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"
|
||||||
|
|
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.
|
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.
|
||||||
summary.dictLang =
|
PLAYERS)),
|
||||||
cursor.getInt(cursor.
|
summary.nPlayers );
|
||||||
getColumnIndex(DBHelper.DICTLANG));
|
summary.dictLang =
|
||||||
summary.dictName =
|
cursor.getInt(cursor.
|
||||||
cursor.getString(cursor.
|
getColumnIndex(DBHelper.DICTLANG));
|
||||||
getColumnIndex(DBHelper.DICTNAME));
|
summary.dictName =
|
||||||
int tmp = cursor.getInt(cursor.
|
cursor.getString(cursor.
|
||||||
getColumnIndex(DBHelper.GAME_OVER));
|
getColumnIndex(DBHelper.DICTNAME));
|
||||||
summary.gameOver = tmp == 0 ? false : true;
|
int tmp = cursor.getInt(cursor.
|
||||||
|
getColumnIndex(DBHelper.GAME_OVER));
|
||||||
|
summary.gameOver = tmp == 0 ? false : true;
|
||||||
|
|
||||||
String scoresStr =
|
String scoresStr =
|
||||||
cursor.getString( cursor.getColumnIndex(DBHelper.SCORES));
|
cursor.getString( cursor.getColumnIndex(DBHelper.SCORES));
|
||||||
if ( null != scoresStr ) {
|
if ( null != scoresStr ) {
|
||||||
StringTokenizer st = new StringTokenizer( scoresStr );
|
StringTokenizer st = new StringTokenizer( scoresStr );
|
||||||
int[] scores = new int[st.countTokens()];
|
int[] scores = new int[st.countTokens()];
|
||||||
for ( int ii = 0; ii < scores.length; ++ii ) {
|
for ( int ii = 0; ii < scores.length; ++ii ) {
|
||||||
Assert.assertTrue( st.hasMoreTokens() );
|
Assert.assertTrue( st.hasMoreTokens() );
|
||||||
String token = st.nextToken();
|
String token = st.nextToken();
|
||||||
scores[ii] = Integer.parseInt( token );
|
scores[ii] = Integer.parseInt( token );
|
||||||
}
|
}
|
||||||
summary.scores = scores;
|
summary.scores = scores;
|
||||||
}
|
}
|
||||||
|
|
||||||
int col = cursor.getColumnIndex( DBHelper.CONTYPE );
|
int col = cursor.getColumnIndex( DBHelper.CONTYPE );
|
||||||
if ( col >= 0 ) {
|
if ( col >= 0 ) {
|
||||||
tmp = cursor.getInt( col );
|
tmp = cursor.getInt( col );
|
||||||
summary.conType = CommsAddrRec.CommsConnType.values()[tmp];
|
summary.conType = CommsAddrRec.CommsConnType.values()[tmp];
|
||||||
col = cursor.getColumnIndex( DBHelper.ROOMNAME );
|
col = cursor.getColumnIndex( DBHelper.ROOMNAME );
|
||||||
if ( col >= 0 ) {
|
if ( col >= 0 ) {
|
||||||
summary.roomName = cursor.getString( col );
|
summary.roomName = cursor.getString( col );
|
||||||
}
|
}
|
||||||
col = cursor.getColumnIndex( DBHelper.RELAYID );
|
col = cursor.getColumnIndex( DBHelper.RELAYID );
|
||||||
if ( col >= 0 ) {
|
if ( col >= 0 ) {
|
||||||
summary.relayID = cursor.getString( col );
|
summary.relayID = cursor.getString( col );
|
||||||
}
|
}
|
||||||
col = cursor.getColumnIndex( DBHelper.SEED );
|
col = cursor.getColumnIndex( DBHelper.SEED );
|
||||||
if ( col >= 0 ) {
|
if ( col >= 0 ) {
|
||||||
summary.seed = cursor.getInt( col );
|
summary.seed = cursor.getInt( col );
|
||||||
}
|
}
|
||||||
col = cursor.getColumnIndex( DBHelper.SMSPHONE );
|
col = cursor.getColumnIndex( DBHelper.SMSPHONE );
|
||||||
if ( col >= 0 ) {
|
if ( col >= 0 ) {
|
||||||
summary.smsPhone = cursor.getString( col );
|
summary.smsPhone = cursor.getString( col );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
col = cursor.getColumnIndex( DBHelper.SERVERROLE );
|
col = cursor.getColumnIndex( DBHelper.SERVERROLE );
|
||||||
tmp = cursor.getInt( col );
|
tmp = cursor.getInt( col );
|
||||||
summary.serverRole = CurGameInfo.DeviceRole.values()[tmp];
|
summary.serverRole = CurGameInfo.DeviceRole.values()[tmp];
|
||||||
|
|
||||||
col = cursor.getColumnIndex( DBHelper.HASMSGS );
|
|
||||||
if ( col >= 0 ) {
|
|
||||||
summary.msgsPending = 0 != cursor.getInt( col );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cursor.close();
|
|
||||||
db.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( null == summary ) {
|
col = cursor.getColumnIndex( DBHelper.HASMSGS );
|
||||||
summary = GameUtils.summarize( context, file );
|
if ( col >= 0 ) {
|
||||||
saveSummary( context, file, summary );
|
summary.msgsPending = 0 != cursor.getInt( col );
|
||||||
}
|
}
|
||||||
return summary;
|
}
|
||||||
}
|
cursor.close();
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
|
|
||||||
public static void saveSummary( Context context, String path,
|
if ( null == summary ) {
|
||||||
GameSummary summary )
|
summary = GameUtils.summarize( context, file );
|
||||||
{
|
saveSummary( context, file, summary );
|
||||||
initDB( context );
|
}
|
||||||
synchronized( s_dbHelper ) {
|
return summary;
|
||||||
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
}
|
||||||
|
|
||||||
if ( null == summary ) {
|
public static void saveSummary( Context context, String path,
|
||||||
String selection = DBHelper.FILE_NAME + "=\"" + path + "\"";
|
GameSummary summary )
|
||||||
db.delete( DBHelper.TABLE_NAME_SUM, selection, null );
|
{
|
||||||
} else {
|
initDB( context );
|
||||||
ContentValues values = new ContentValues();
|
synchronized( s_dbHelper ) {
|
||||||
values.put( DBHelper.NUM_MOVES, summary.nMoves );
|
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
||||||
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.scores ) {
|
if ( null == summary ) {
|
||||||
StringBuffer sb = new StringBuffer();
|
String selection = DBHelper.FILE_NAME + "=\"" + path + "\"";
|
||||||
for ( int score : summary.scores ) {
|
db.delete( DBHelper.TABLE_NAME_SUM, selection, null );
|
||||||
sb.append( String.format( "%d ", score ) );
|
} else {
|
||||||
}
|
ContentValues values = new ContentValues();
|
||||||
values.put( DBHelper.SCORES, sb.toString() );
|
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 ) {
|
if ( null != summary.scores ) {
|
||||||
values.put( DBHelper.CONTYPE, summary.conType.ordinal() );
|
StringBuffer sb = new StringBuffer();
|
||||||
values.put( DBHelper.ROOMNAME, summary.roomName );
|
for ( int score : summary.scores ) {
|
||||||
values.put( DBHelper.RELAYID, summary.relayID );
|
sb.append( String.format( "%d ", score ) );
|
||||||
values.put( DBHelper.SEED, summary.seed );
|
}
|
||||||
values.put( DBHelper.SMSPHONE, summary.smsPhone );
|
values.put( DBHelper.SCORES, sb.toString() );
|
||||||
}
|
}
|
||||||
values.put( DBHelper.SERVERROLE, summary.serverRole.ordinal() );
|
|
||||||
|
|
||||||
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 + "\"";
|
Utils.logf( "saveSummary: nMoves=%d", summary.nMoves );
|
||||||
long result = db.update( DBHelper.TABLE_NAME_SUM,
|
|
||||||
values, selection, null );
|
|
||||||
Assert.assertTrue( result >= 0 );
|
|
||||||
}
|
|
||||||
db.close();
|
|
||||||
}
|
|
||||||
} // saveSummary
|
|
||||||
|
|
||||||
public static int countGamesUsing( Context context, String dict )
|
String selection = DBHelper.FILE_NAME + "=\"" + path + "\"";
|
||||||
{
|
long result = db.update( DBHelper.TABLE_NAME_SUM,
|
||||||
int result = 0;
|
values, selection, null );
|
||||||
initDB( context );
|
Assert.assertTrue( result >= 0 );
|
||||||
synchronized( s_dbHelper ) {
|
}
|
||||||
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
db.close();
|
||||||
String selection = DBHelper.DICTNAME + " LIKE \'"
|
}
|
||||||
+ dict + "\'";
|
} // saveSummary
|
||||||
// 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 );
|
|
||||||
|
|
||||||
result = cursor.getCount();
|
public static int countGamesUsing( Context context, String dict )
|
||||||
cursor.close();
|
{
|
||||||
db.close();
|
int result = 0;
|
||||||
}
|
initDB( context );
|
||||||
return result;
|
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 )
|
result = cursor.getCount();
|
||||||
{
|
cursor.close();
|
||||||
synchronized( s_dbHelper ) {
|
db.close();
|
||||||
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
}
|
||||||
|
return result;
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getPathFor( Context context, String relayID )
|
public static void setHasMsgs( String relayID )
|
||||||
{
|
{
|
||||||
String result = null;
|
synchronized( s_dbHelper ) {
|
||||||
initDB( context );
|
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
||||||
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));
|
|
||||||
|
|
||||||
}
|
String selection = DBHelper.RELAYID + "=\'" + relayID + "\'";
|
||||||
cursor.close();
|
ContentValues values = new ContentValues();
|
||||||
db.close();
|
values.put( DBHelper.HASMSGS, 1 );
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String[] getRelayIDNoMsgs( Context context )
|
int result = db.update( DBHelper.TABLE_NAME_SUM,
|
||||||
{
|
values, selection, null );
|
||||||
String[] result = null;
|
Assert.assertTrue( result == 1 );
|
||||||
initDB( context );
|
db.close();
|
||||||
ArrayList<String> ids = new ArrayList<String>();
|
}
|
||||||
|
}
|
||||||
|
|
||||||
synchronized( s_dbHelper ) {
|
public static String getPathFor( Context context, String relayID )
|
||||||
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
{
|
||||||
String[] columns = { DBHelper.RELAYID };
|
String result = null;
|
||||||
String selection = DBHelper.RELAYID + " NOT null AND "
|
initDB( context );
|
||||||
+ "NOT " + DBHelper.HASMSGS;
|
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() ) {
|
public static String[] getRelayIDNoMsgs( Context context )
|
||||||
cursor.moveToFirst();
|
{
|
||||||
for ( ; ; ) {
|
String[] result = null;
|
||||||
ids.add( cursor.
|
initDB( context );
|
||||||
getString( cursor.
|
ArrayList<String> ids = new ArrayList<String>();
|
||||||
getColumnIndex(DBHelper.RELAYID)) );
|
|
||||||
if ( cursor.isLast() ) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
cursor.moveToNext();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cursor.close();
|
|
||||||
db.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( 0 < ids.size() ) {
|
synchronized( s_dbHelper ) {
|
||||||
result = ids.toArray( new String[ids.size()] );
|
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
||||||
}
|
String[] columns = { DBHelper.RELAYID };
|
||||||
return result;
|
String selection = DBHelper.RELAYID + " NOT null AND "
|
||||||
}
|
+ "NOT " + DBHelper.HASMSGS;
|
||||||
|
|
||||||
public static void addDeceased( Context context, String relayID,
|
Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns,
|
||||||
int seed )
|
selection, null, null, null, null );
|
||||||
{
|
|
||||||
initDB( context );
|
|
||||||
synchronized( s_dbHelper ) {
|
|
||||||
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
|
||||||
|
|
||||||
ContentValues values = new ContentValues();
|
if ( 0 < cursor.getCount() ) {
|
||||||
values.put( DBHelper.RELAYID, relayID );
|
cursor.moveToFirst();
|
||||||
values.put( DBHelper.SEED, seed );
|
for ( ; ; ) {
|
||||||
|
ids.add( cursor.
|
||||||
|
getString( cursor.
|
||||||
|
getColumnIndex(DBHelper.RELAYID)) );
|
||||||
|
if ( cursor.isLast() ) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
cursor.moveToNext();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cursor.close();
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
if ( 0 < ids.size() ) {
|
||||||
long result = db.replaceOrThrow( DBHelper.TABLE_NAME_OBITS,
|
result = ids.toArray( new String[ids.size()] );
|
||||||
"", values );
|
}
|
||||||
} catch ( Exception ex ) {
|
return result;
|
||||||
Utils.logf( "ex: %s", ex.toString() );
|
}
|
||||||
}
|
|
||||||
db.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Obit[] listObits( Context context )
|
public static void addDeceased( Context context, String relayID,
|
||||||
{
|
int seed )
|
||||||
Obit[] result = null;
|
{
|
||||||
ArrayList<Obit> al = new ArrayList<Obit>();
|
initDB( context );
|
||||||
|
synchronized( s_dbHelper ) {
|
||||||
|
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
||||||
|
|
||||||
initDB( context );
|
ContentValues values = new ContentValues();
|
||||||
synchronized( s_dbHelper ) {
|
values.put( DBHelper.RELAYID, relayID );
|
||||||
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
values.put( DBHelper.SEED, seed );
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
int siz = al.size();
|
try {
|
||||||
if ( siz > 0 ) {
|
long result = db.replaceOrThrow( DBHelper.TABLE_NAME_OBITS,
|
||||||
result = al.toArray( new Obit[siz] );
|
"", values );
|
||||||
}
|
} catch ( Exception ex ) {
|
||||||
return result;
|
Utils.logf( "ex: %s", ex.toString() );
|
||||||
}
|
}
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void clearObits( Context context, Obit[] obits )
|
public static Obit[] listObits( Context context )
|
||||||
{
|
{
|
||||||
String fmt = DBHelper.RELAYID + "= \"%s\" AND + "
|
Obit[] result = null;
|
||||||
+ DBHelper.SEED + " = %d";
|
ArrayList<Obit> al = new ArrayList<Obit>();
|
||||||
|
|
||||||
initDB( context );
|
initDB( context );
|
||||||
synchronized( s_dbHelper ) {
|
synchronized( s_dbHelper ) {
|
||||||
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
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 ) {
|
int siz = al.size();
|
||||||
String selection = String.format( fmt, obit.m_relayID,
|
if ( siz > 0 ) {
|
||||||
obit.m_seed );
|
result = al.toArray( new Obit[siz] );
|
||||||
db.delete( DBHelper.TABLE_NAME_OBITS, selection, null );
|
}
|
||||||
}
|
return result;
|
||||||
db.close();
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void saveGame( Context context, String path, byte[] bytes,
|
public static void clearObits( Context context, Obit[] obits )
|
||||||
boolean setCreate )
|
{
|
||||||
{
|
String fmt = DBHelper.RELAYID + "= \"%s\" AND + "
|
||||||
initDB( context );
|
+ DBHelper.SEED + " = %d";
|
||||||
synchronized( s_dbHelper ) {
|
|
||||||
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
|
||||||
|
|
||||||
String selection = DBHelper.FILE_NAME + "=\"" + path + "\"";
|
initDB( context );
|
||||||
ContentValues values = new ContentValues();
|
synchronized( s_dbHelper ) {
|
||||||
values.put( DBHelper.SNAPSHOT, bytes );
|
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
||||||
|
|
||||||
long timestamp = new Date().getTime();
|
for ( Obit obit: obits ) {
|
||||||
if ( setCreate ) {
|
String selection = String.format( fmt, obit.m_relayID,
|
||||||
values.put( DBHelper.CREATE_TIME, timestamp );
|
obit.m_seed );
|
||||||
}
|
db.delete( DBHelper.TABLE_NAME_OBITS, selection, null );
|
||||||
values.put( DBHelper.LASTPLAY_TIME, timestamp );
|
}
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int result = db.update( DBHelper.TABLE_NAME_SUM,
|
public static void saveGame( Context context, String path, byte[] bytes,
|
||||||
values, selection, null );
|
boolean setCreate )
|
||||||
if ( 0 == result ) {
|
{
|
||||||
values.put( DBHelper.FILE_NAME, path );
|
initDB( context );
|
||||||
long row = db.insert( DBHelper.TABLE_NAME_SUM, null, values );
|
synchronized( s_dbHelper ) {
|
||||||
Assert.assertTrue( row >= 0 );
|
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
||||||
}
|
|
||||||
db.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] loadGame( Context context, String path )
|
String selection = DBHelper.FILE_NAME + "=\"" + path + "\"";
|
||||||
{
|
ContentValues values = new ContentValues();
|
||||||
Assert.assertNotNull( path );
|
values.put( DBHelper.SNAPSHOT, bytes );
|
||||||
byte[] result = null;
|
|
||||||
initDB( context );
|
|
||||||
synchronized( s_dbHelper ) {
|
|
||||||
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
|
||||||
|
|
||||||
String[] columns = { DBHelper.SNAPSHOT };
|
long timestamp = new Date().getTime();
|
||||||
String selection = DBHelper.FILE_NAME + "=\"" + path + "\"";
|
if ( setCreate ) {
|
||||||
Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns,
|
values.put( DBHelper.CREATE_TIME, timestamp );
|
||||||
selection, null, null, null, null );
|
}
|
||||||
if ( 1 == cursor.getCount() && cursor.moveToFirst() ) {
|
values.put( DBHelper.LASTPLAY_TIME, timestamp );
|
||||||
result = cursor.getBlob( cursor
|
|
||||||
.getColumnIndex(DBHelper.SNAPSHOT));
|
|
||||||
}
|
|
||||||
cursor.close();
|
|
||||||
db.close();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void deleteGame( Context context, String path )
|
int result = db.update( DBHelper.TABLE_NAME_SUM,
|
||||||
{
|
values, selection, null );
|
||||||
initDB( context );
|
if ( 0 == result ) {
|
||||||
synchronized( s_dbHelper ) {
|
values.put( DBHelper.FILE_NAME, path );
|
||||||
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
long row = db.insert( DBHelper.TABLE_NAME_SUM, null, values );
|
||||||
String selection = DBHelper.FILE_NAME + "=\"" + path + "\"";
|
Assert.assertTrue( row >= 0 );
|
||||||
db.delete( DBHelper.TABLE_NAME_SUM, selection, null );
|
}
|
||||||
db.close();
|
db.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String[] gamesList( Context context )
|
public static byte[] loadGame( Context context, String path )
|
||||||
{
|
{
|
||||||
ArrayList<String> al = new ArrayList<String>();
|
Assert.assertNotNull( path );
|
||||||
|
byte[] result = null;
|
||||||
|
initDB( context );
|
||||||
|
synchronized( s_dbHelper ) {
|
||||||
|
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
||||||
|
|
||||||
initDB( context );
|
String[] columns = { DBHelper.SNAPSHOT };
|
||||||
synchronized( s_dbHelper ) {
|
String selection = DBHelper.FILE_NAME + "=\"" + path + "\"";
|
||||||
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
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 };
|
public static void deleteGame( Context context, String path )
|
||||||
Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns,
|
{
|
||||||
null, null, null, null, null );
|
initDB( context );
|
||||||
if ( 0 < cursor.getCount() ) {
|
synchronized( s_dbHelper ) {
|
||||||
cursor.moveToFirst();
|
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
||||||
for ( ; ; ) {
|
String selection = DBHelper.FILE_NAME + "=\"" + path + "\"";
|
||||||
int index = cursor.getColumnIndex( DBHelper.FILE_NAME );
|
db.delete( DBHelper.TABLE_NAME_SUM, selection, null );
|
||||||
String name = cursor.getString( index );
|
db.close();
|
||||||
al.add( cursor.getString( index ) );
|
}
|
||||||
if ( cursor.isLast() ) {
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
cursor.moveToNext();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cursor.close();
|
|
||||||
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 )
|
private static void initDB( Context context )
|
||||||
|
|
|
@ -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 ) );
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue