mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-07 05:24:46 +01:00
pass Context fix NotSerializableException
Backgrounding with Wait/Invite alert up mean serializing something that included a Context. Fix to pass it instead into methods that need it.
This commit is contained in:
parent
e7a2657a91
commit
a5d0d02faf
7 changed files with 42 additions and 54 deletions
|
@ -1208,7 +1208,7 @@ public class BoardDelegate extends DelegateBase
|
|||
break;
|
||||
case EMAIL:
|
||||
case CLIPBOARD:
|
||||
NetLaunchInfo nli = new NetLaunchInfo( m_summary, m_gi, 1,
|
||||
NetLaunchInfo nli = new NetLaunchInfo( m_activity, m_summary, m_gi, 1,
|
||||
1 + m_nGuestDevs );
|
||||
if ( m_relayMissing ) {
|
||||
nli.removeAddress( CommsConnType.COMMS_CONN_RELAY );
|
||||
|
@ -2405,7 +2405,7 @@ public class BoardDelegate extends DelegateBase
|
|||
int nPlayers = m_missingCounts[ii];
|
||||
Assert.assertTrue( 0 <= m_nGuestDevs );
|
||||
int forceChannel = ii + m_nGuestDevs + 1;
|
||||
NetLaunchInfo nli = new NetLaunchInfo( m_summary, m_gi,
|
||||
NetLaunchInfo nli = new NetLaunchInfo( m_activity, m_summary, m_gi,
|
||||
nPlayers, forceChannel );
|
||||
if ( m_relayMissing ) {
|
||||
nli.removeAddress( CommsConnType.COMMS_CONN_RELAY );
|
||||
|
@ -2660,7 +2660,7 @@ public class BoardDelegate extends DelegateBase
|
|||
|
||||
if ( doIt ) {
|
||||
CommsConnTypeSet connTypes = summary.conTypes;
|
||||
String newName = summary.getRematchName();
|
||||
String newName = summary.getRematchName( activity );
|
||||
Intent intent = GamesListDelegate
|
||||
.makeRematchIntent( activity, rowid, gi, connTypes, btAddr,
|
||||
phone, relayID, p2pMacAddress, newName );
|
||||
|
@ -2716,8 +2716,8 @@ public class BoardDelegate extends DelegateBase
|
|||
// only supports a single invite for now!
|
||||
int numHere = 1;
|
||||
int forceChannel = 1;
|
||||
NetLaunchInfo nli = new NetLaunchInfo( m_summary, m_gi, numHere,
|
||||
forceChannel );
|
||||
NetLaunchInfo nli = new NetLaunchInfo( m_activity, m_summary, m_gi,
|
||||
numHere, forceChannel );
|
||||
|
||||
String value;
|
||||
value = m_summary.getStringExtra( GameSummary.EXTRA_REMATCH_PHONE );
|
||||
|
|
|
@ -149,7 +149,7 @@ public class DBUtils {
|
|||
Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns,
|
||||
selection, null, null, null, null );
|
||||
if ( 1 == cursor.getCount() && cursor.moveToFirst() ) {
|
||||
summary = new GameSummary( context );
|
||||
summary = new GameSummary();
|
||||
summary.nMoves = cursor.getInt(cursor.
|
||||
getColumnIndex(DBHelper.NUM_MOVES));
|
||||
summary.nPlayers =
|
||||
|
@ -177,7 +177,7 @@ public class DBUtils {
|
|||
|
||||
String players = cursor.
|
||||
getString(cursor.getColumnIndex( DBHelper.PLAYERS ));
|
||||
summary.readPlayers( players );
|
||||
summary.readPlayers( context, players );
|
||||
|
||||
summary.dictLang =
|
||||
cursor.getInt(cursor.
|
||||
|
|
|
@ -234,7 +234,7 @@ public class GameListItem extends LinearLayout
|
|||
{
|
||||
String state = null; // hack to avoid calling summarizeState twice
|
||||
if ( null != m_summary ) {
|
||||
state = m_summary.summarizeState();
|
||||
state = m_summary.summarizeState( m_context );
|
||||
String value = null;
|
||||
switch ( m_fieldID ) {
|
||||
case R.string.game_summary_field_empty:
|
||||
|
@ -255,7 +255,7 @@ public class GameListItem extends LinearLayout
|
|||
value = LocUtils.xlateLang( m_context, value, true );
|
||||
break;
|
||||
case R.string.game_summary_field_opponents:
|
||||
value = m_summary.playerNames();
|
||||
value = m_summary.playerNames( m_context );
|
||||
break;
|
||||
case R.string.game_summary_field_state:
|
||||
value = state;
|
||||
|
@ -291,7 +291,7 @@ public class GameListItem extends LinearLayout
|
|||
ExpiringLinearLayout tmp = (ExpiringLinearLayout)
|
||||
LocUtils.inflate( m_context, R.layout.player_list_elem );
|
||||
TextView tview = (TextView)tmp.findViewById( R.id.item_name );
|
||||
tview.setText( summary.summarizePlayer( ii ) );
|
||||
tview.setText( summary.summarizePlayer( m_context, ii ) );
|
||||
tview = (TextView)tmp.findViewById( R.id.item_score );
|
||||
tview.setText( String.format( " %d", summary.scores[ii] ) );
|
||||
boolean thisHasTurn = summary.isNextToPlay( ii, isLocal );
|
||||
|
@ -324,7 +324,7 @@ public class GameListItem extends LinearLayout
|
|||
}
|
||||
} );
|
||||
|
||||
String roleSummary = summary.summarizeRole( m_rowid );
|
||||
String roleSummary = summary.summarizeRole( m_context, m_rowid );
|
||||
if ( null != roleSummary ) {
|
||||
m_role.setText( roleSummary );
|
||||
} else {
|
||||
|
|
|
@ -186,7 +186,7 @@ public class GameUtils {
|
|||
GamePtr gamePtr,
|
||||
CurGameInfo gi )
|
||||
{
|
||||
GameSummary summary = new GameSummary( context, gi );
|
||||
GameSummary summary = new GameSummary( gi );
|
||||
XwJNI.game_summarize( gamePtr, summary );
|
||||
|
||||
DBUtils.saveSummary( context, lock, summary );
|
||||
|
@ -1059,7 +1059,7 @@ public class GameUtils {
|
|||
|
||||
saveGame( context, gamePtr, gi, lock, false );
|
||||
|
||||
GameSummary summary = new GameSummary( context, gi );
|
||||
GameSummary summary = new GameSummary( gi );
|
||||
XwJNI.game_summarize( gamePtr, summary );
|
||||
gamePtr.release();
|
||||
DBUtils.saveSummary( context, lock, summary );
|
||||
|
|
|
@ -225,9 +225,10 @@ public class NetLaunchInfo {
|
|||
gameID = gamID;
|
||||
}
|
||||
|
||||
public NetLaunchInfo( GameSummary summary, CurGameInfo gi, int numHere, int fc )
|
||||
public NetLaunchInfo( Context context, GameSummary summary, CurGameInfo gi,
|
||||
int numHere, int fc )
|
||||
{
|
||||
this( summary, gi );
|
||||
this( context, summary, gi );
|
||||
nPlayersH = numHere;
|
||||
forceChannel = fc;
|
||||
}
|
||||
|
@ -237,7 +238,7 @@ public class NetLaunchInfo {
|
|||
this( gi.gameID, gi.getName(), gi.dictLang, gi.dictName, gi.nPlayers );
|
||||
}
|
||||
|
||||
public NetLaunchInfo( GameSummary summary, CurGameInfo gi )
|
||||
public NetLaunchInfo( Context context, GameSummary summary, CurGameInfo gi )
|
||||
{
|
||||
this( gi );
|
||||
|
||||
|
@ -251,10 +252,10 @@ public class NetLaunchInfo {
|
|||
addRelayInfo( summary.roomName, summary.relayID );
|
||||
break;
|
||||
case COMMS_CONN_SMS:
|
||||
addSMSInfo( summary.getContext() );
|
||||
addSMSInfo( context );
|
||||
break;
|
||||
case COMMS_CONN_P2P:
|
||||
addP2PInfo( summary.getContext() );
|
||||
addP2PInfo( context );
|
||||
break;
|
||||
default:
|
||||
Assert.fail();
|
||||
|
|
|
@ -79,20 +79,13 @@ public class GameSummary implements Serializable {
|
|||
private Integer m_giFlags;
|
||||
private String m_playersSummary;
|
||||
private CurGameInfo m_gi;
|
||||
private Context m_context;
|
||||
private String[] m_remotePhones;
|
||||
private String m_extras;
|
||||
|
||||
private GameSummary() {}
|
||||
public GameSummary() {}
|
||||
|
||||
public GameSummary( Context context ) {
|
||||
m_context = context;
|
||||
gameID = 0;
|
||||
}
|
||||
|
||||
public GameSummary( Context context, CurGameInfo gi )
|
||||
public GameSummary( CurGameInfo gi )
|
||||
{
|
||||
this( context );
|
||||
nPlayers = gi.nPlayers;
|
||||
dictLang = gi.dictLang;
|
||||
serverRole = gi.serverRole;
|
||||
|
@ -100,12 +93,6 @@ public class GameSummary implements Serializable {
|
|||
m_gi = gi;
|
||||
}
|
||||
|
||||
public Context getContext()
|
||||
{
|
||||
Assert.assertNotNull( m_context );
|
||||
return m_context;
|
||||
}
|
||||
|
||||
public boolean inRelayGame()
|
||||
{
|
||||
return null != relayID;
|
||||
|
@ -136,10 +123,10 @@ public class GameSummary implements Serializable {
|
|||
return result;
|
||||
}
|
||||
|
||||
public String getRematchName()
|
||||
public String getRematchName( Context context )
|
||||
{
|
||||
return LocUtils.getString( m_context, R.string.rematch_name_fmt,
|
||||
playerNames() );
|
||||
return LocUtils.getString( context, R.string.rematch_name_fmt,
|
||||
playerNames( context ) );
|
||||
}
|
||||
|
||||
public void setRemoteDevs( Context context, CommsConnType typ, String str )
|
||||
|
@ -156,7 +143,7 @@ public class GameSummary implements Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
public void readPlayers( String playersStr )
|
||||
public void readPlayers( Context context , String playersStr )
|
||||
{
|
||||
if ( null != playersStr ) {
|
||||
m_players = new String[nPlayers];
|
||||
|
@ -164,7 +151,7 @@ public class GameSummary implements Serializable {
|
|||
if ( playersStr.contains("\n") ) {
|
||||
sep = "\n";
|
||||
} else {
|
||||
sep = LocUtils.getString( m_context, R.string.vs_join );
|
||||
sep = LocUtils.getString( context, R.string.vs_join );
|
||||
}
|
||||
|
||||
int ii, nxt;
|
||||
|
@ -188,13 +175,13 @@ public class GameSummary implements Serializable {
|
|||
m_playersSummary = summary;
|
||||
}
|
||||
|
||||
public String summarizeState()
|
||||
public String summarizeState( Context context )
|
||||
{
|
||||
String result = null;
|
||||
if ( gameOver ) {
|
||||
result = LocUtils.getString( m_context, R.string.gameOver );
|
||||
result = LocUtils.getString( context, R.string.gameOver );
|
||||
} else {
|
||||
result = LocUtils.getQuantityString( m_context, R.plurals.moves_fmt,
|
||||
result = LocUtils.getQuantityString( context, R.plurals.moves_fmt,
|
||||
nMoves, nMoves );
|
||||
}
|
||||
return result;
|
||||
|
@ -202,7 +189,7 @@ public class GameSummary implements Serializable {
|
|||
|
||||
// FIXME: should report based on whatever conType is giving us a
|
||||
// successful connection.
|
||||
public String summarizeRole( long rowid )
|
||||
public String summarizeRole( Context context, long rowid )
|
||||
{
|
||||
String result = null;
|
||||
if ( isMultiGame() ) {
|
||||
|
@ -210,10 +197,10 @@ public class GameSummary implements Serializable {
|
|||
|
||||
int missing = countMissing();
|
||||
if ( 0 < missing ) {
|
||||
DBUtils.SentInvitesInfo si = DBUtils.getInvitesFor( m_context,
|
||||
DBUtils.SentInvitesInfo si = DBUtils.getInvitesFor( context,
|
||||
rowid );
|
||||
if ( si.getMinPlayerCount() >= missing ) {
|
||||
result = LocUtils.getString( m_context,
|
||||
result = LocUtils.getString( context,
|
||||
R.string.summary_invites_out );
|
||||
}
|
||||
}
|
||||
|
@ -232,7 +219,7 @@ public class GameSummary implements Serializable {
|
|||
} else {
|
||||
fmtID = R.string.summary_relay_conn_fmt;
|
||||
}
|
||||
result = LocUtils.getString( m_context, fmtID, roomName );
|
||||
result = LocUtils.getString( context, fmtID, roomName );
|
||||
}
|
||||
|
||||
// Otherwise, use BT or SMS
|
||||
|
@ -250,13 +237,13 @@ public class GameSummary implements Serializable {
|
|||
} else if ( null != remoteDevs
|
||||
&& conTypes.contains( CommsConnType.COMMS_CONN_SMS)){
|
||||
result =
|
||||
LocUtils.getString( m_context, R.string.summary_conn_sms_fmt,
|
||||
LocUtils.getString( context, R.string.summary_conn_sms_fmt,
|
||||
TextUtils.join(", ", m_remotePhones) );
|
||||
} else {
|
||||
fmtID = R.string.summary_conn;
|
||||
}
|
||||
if ( null == result ) {
|
||||
result = LocUtils.getString( m_context, fmtID );
|
||||
result = LocUtils.getString( context, fmtID );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -333,14 +320,14 @@ public class GameSummary implements Serializable {
|
|||
m_giFlags = new Integer( flags );
|
||||
}
|
||||
|
||||
public String summarizePlayer( int indx )
|
||||
public String summarizePlayer( Context context, int indx )
|
||||
{
|
||||
String player = m_players[indx];
|
||||
int formatID = 0;
|
||||
if ( !isLocal(indx) ) {
|
||||
boolean isMissing = 0 != ((1 << indx) & missingPlayers);
|
||||
if ( isMissing ) {
|
||||
player = LocUtils.getString( m_context, R.string.missing_player );
|
||||
player = LocUtils.getString( context, R.string.missing_player );
|
||||
} else {
|
||||
formatID = R.string.str_nonlocal_name_fmt;
|
||||
}
|
||||
|
@ -349,23 +336,23 @@ public class GameSummary implements Serializable {
|
|||
}
|
||||
|
||||
if ( 0 != formatID ) {
|
||||
player = LocUtils.getString( m_context, formatID, player );
|
||||
player = LocUtils.getString( context, formatID, player );
|
||||
}
|
||||
return player;
|
||||
}
|
||||
|
||||
public String playerNames()
|
||||
public String playerNames( Context context )
|
||||
{
|
||||
String[] names = null;
|
||||
if ( null != m_gi ) {
|
||||
names = m_gi.visibleNames( m_context, false );
|
||||
names = m_gi.visibleNames( context, false );
|
||||
} else if ( null != m_playersSummary ) {
|
||||
names = TextUtils.split( m_playersSummary, "\n" );
|
||||
}
|
||||
|
||||
String result = null;
|
||||
if ( null != names && 0 < names.length ) {
|
||||
String joiner = LocUtils.getString( m_context, R.string.vs_join );
|
||||
String joiner = LocUtils.getString( context, R.string.vs_join );
|
||||
result = TextUtils.join( joiner, names );
|
||||
}
|
||||
|
||||
|
|
|
@ -381,7 +381,7 @@ public class JNIThread extends Thread {
|
|||
// Don't need this!!!! this only runs on the run() thread
|
||||
synchronized( this ) {
|
||||
Assert.assertNotNull( m_lock );
|
||||
GameSummary summary = new GameSummary( m_context, m_gi );
|
||||
GameSummary summary = new GameSummary( m_gi );
|
||||
XwJNI.game_summarize( m_jniGamePtr, summary );
|
||||
DBUtils.saveGame( m_context, m_lock, state, false );
|
||||
DBUtils.saveSummary( m_context, m_lock, summary );
|
||||
|
|
Loading…
Reference in a new issue