mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-23 07:27:22 +01:00
remove Context ivar from CurGameInfo
It claimed to be Serializable but wasn't: Crash. Now it is.
This commit is contained in:
parent
1de838171b
commit
2a4bce4ad1
5 changed files with 43 additions and 41 deletions
|
@ -569,7 +569,7 @@ public class GameConfigDelegate extends DelegateBase
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( null == m_gi ) {
|
if ( null == m_gi ) {
|
||||||
m_gi = new CurGameInfo( m_activity, m_giOrig );
|
m_gi = new CurGameInfo( m_giOrig );
|
||||||
}
|
}
|
||||||
|
|
||||||
m_carOrig = new CommsAddrRec();
|
m_carOrig = new CommsAddrRec();
|
||||||
|
@ -848,7 +848,7 @@ public class GameConfigDelegate extends DelegateBase
|
||||||
if ( !isFinishing() ) {
|
if ( !isFinishing() ) {
|
||||||
m_playerLayout.removeAllViews();
|
m_playerLayout.removeAllViews();
|
||||||
|
|
||||||
String[] names = m_gi.visibleNames( false );
|
String[] names = m_gi.visibleNames( m_activity, false );
|
||||||
// only enable delete if one will remain (or two if networked)
|
// only enable delete if one will remain (or two if networked)
|
||||||
boolean canDelete = names.length > 2
|
boolean canDelete = names.length > 2
|
||||||
|| (localOnlyGame() && names.length > 1);
|
|| (localOnlyGame() && names.length > 1);
|
||||||
|
@ -973,7 +973,8 @@ public class GameConfigDelegate extends DelegateBase
|
||||||
|
|
||||||
private void selLangChanged( String chosen )
|
private void selLangChanged( String chosen )
|
||||||
{
|
{
|
||||||
m_gi.setLang( DictLangCache.getLangLangCode( m_activity, chosen ) );
|
m_gi.setLang( m_activity, DictLangCache
|
||||||
|
.getLangLangCode( m_activity, chosen ) );
|
||||||
loadPlayersList();
|
loadPlayersList();
|
||||||
configDictSpinner( m_dictSpinner, m_gi.dictLang, m_gi.dictName );
|
configDictSpinner( m_dictSpinner, m_gi.dictLang, m_gi.dictName );
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,7 +124,7 @@ public class GameUtils {
|
||||||
gamePtr.release();
|
gamePtr.release();
|
||||||
|
|
||||||
gamePtr = XwJNI.initNew( gi, dictNames, pairs.m_bytes, pairs.m_paths,
|
gamePtr = XwJNI.initNew( gi, dictNames, pairs.m_bytes, pairs.m_paths,
|
||||||
gi.langName(), (UtilCtxt)null,
|
gi.langName( context ), (UtilCtxt)null,
|
||||||
JNIUtilsImpl.get( context ), (DrawCtx)null,
|
JNIUtilsImpl.get( context ), (DrawCtx)null,
|
||||||
CommonPrefs.get( context ), (TransportProcs)null );
|
CommonPrefs.get( context ), (TransportProcs)null );
|
||||||
|
|
||||||
|
@ -363,7 +363,7 @@ public class GameUtils {
|
||||||
DbgUtils.logw( TAG, "loadMakeGame() failing: dicts %s unavailable",
|
DbgUtils.logw( TAG, "loadMakeGame() failing: dicts %s unavailable",
|
||||||
TextUtils.join( ",", dictNames ) );
|
TextUtils.join( ",", dictNames ) );
|
||||||
} else {
|
} else {
|
||||||
String langName = gi.langName();
|
String langName = gi.langName( context );
|
||||||
gamePtr = XwJNI.initFromStream( rowid, stream, gi, dictNames,
|
gamePtr = XwJNI.initFromStream( rowid, stream, gi, dictNames,
|
||||||
pairs.m_bytes, pairs.m_paths,
|
pairs.m_bytes, pairs.m_paths,
|
||||||
langName, util,
|
langName, util,
|
||||||
|
@ -585,7 +585,7 @@ public class GameUtils {
|
||||||
Assert.assertNotNull( inviteID );
|
Assert.assertNotNull( inviteID );
|
||||||
CurGameInfo gi = new CurGameInfo( context, inviteID );
|
CurGameInfo gi = new CurGameInfo( context, inviteID );
|
||||||
gi.setFrom( jsonData );
|
gi.setFrom( jsonData );
|
||||||
gi.setLang( lang[0], dict[0] );
|
gi.setLang( context, lang[0], dict[0] );
|
||||||
gi.forceChannel = forceChannel;
|
gi.forceChannel = forceChannel;
|
||||||
lang[0] = gi.dictLang;
|
lang[0] = gi.dictLang;
|
||||||
dict[0] = gi.dictName;
|
dict[0] = gi.dictName;
|
||||||
|
@ -977,7 +977,7 @@ public class GameUtils {
|
||||||
XwJNI.gi_from_stream( gi, stream );
|
XwJNI.gi_from_stream( gi, stream );
|
||||||
|
|
||||||
// first time required so dictNames() will work
|
// first time required so dictNames() will work
|
||||||
gi.replaceDicts( newDict );
|
gi.replaceDicts( context, newDict );
|
||||||
|
|
||||||
String[] dictNames = gi.dictNames();
|
String[] dictNames = gi.dictNames();
|
||||||
DictUtils.DictPairs pairs = DictUtils.openDicts( context,
|
DictUtils.DictPairs pairs = DictUtils.openDicts( context,
|
||||||
|
@ -986,11 +986,11 @@ public class GameUtils {
|
||||||
GamePtr gamePtr =
|
GamePtr gamePtr =
|
||||||
XwJNI.initFromStream( rowid, stream, gi, dictNames,
|
XwJNI.initFromStream( rowid, stream, gi, dictNames,
|
||||||
pairs.m_bytes, pairs.m_paths,
|
pairs.m_bytes, pairs.m_paths,
|
||||||
gi.langName(), null,
|
gi.langName( context ), null,
|
||||||
JNIUtilsImpl.get(context), null,
|
JNIUtilsImpl.get(context), null,
|
||||||
CommonPrefs.get( context ), null );
|
CommonPrefs.get( context ), null );
|
||||||
// second time required as game_makeFromStream can overwrite
|
// second time required as game_makeFromStream can overwrite
|
||||||
gi.replaceDicts( newDict );
|
gi.replaceDicts( context, newDict );
|
||||||
|
|
||||||
saveGame( context, gamePtr, gi, lock, false );
|
saveGame( context, gamePtr, gi, lock, false );
|
||||||
|
|
||||||
|
@ -1022,7 +1022,7 @@ public class GameUtils {
|
||||||
// games?
|
// games?
|
||||||
String[] dictNames = gi.dictNames();
|
String[] dictNames = gi.dictNames();
|
||||||
DictUtils.DictPairs pairs = DictUtils.openDicts( context, dictNames );
|
DictUtils.DictPairs pairs = DictUtils.openDicts( context, dictNames );
|
||||||
String langName = gi.langName();
|
String langName = gi.langName( context );
|
||||||
GamePtr gamePtr = null;
|
GamePtr gamePtr = null;
|
||||||
boolean madeGame = false;
|
boolean madeGame = false;
|
||||||
CommonPrefs cp = CommonPrefs.get( context );
|
CommonPrefs cp = CommonPrefs.get( context );
|
||||||
|
|
|
@ -71,7 +71,6 @@ public class CurGameInfo implements Serializable {
|
||||||
// private int m_nVisiblePlayers;
|
// private int m_nVisiblePlayers;
|
||||||
private int m_smartness;
|
private int m_smartness;
|
||||||
private String m_name; // not shared across the jni boundary
|
private String m_name; // not shared across the jni boundary
|
||||||
private Context m_context;
|
|
||||||
|
|
||||||
public CurGameInfo( Context context )
|
public CurGameInfo( Context context )
|
||||||
{
|
{
|
||||||
|
@ -81,7 +80,6 @@ public class CurGameInfo implements Serializable {
|
||||||
public CurGameInfo( Context context, String inviteID )
|
public CurGameInfo( Context context, String inviteID )
|
||||||
{
|
{
|
||||||
boolean isNetworked = null != inviteID;
|
boolean isNetworked = null != inviteID;
|
||||||
m_context = context;
|
|
||||||
nPlayers = 2;
|
nPlayers = 2;
|
||||||
gameSeconds = 60 * nPlayers *
|
gameSeconds = 60 * nPlayers *
|
||||||
CommonPrefs.getDefaultPlayerMinutes( context );
|
CommonPrefs.getDefaultPlayerMinutes( context );
|
||||||
|
@ -127,12 +125,11 @@ public class CurGameInfo implements Serializable {
|
||||||
juggle();
|
juggle();
|
||||||
}
|
}
|
||||||
|
|
||||||
setLang( 0 );
|
setLang( context, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
public CurGameInfo( Context context, CurGameInfo src )
|
public CurGameInfo( CurGameInfo src )
|
||||||
{
|
{
|
||||||
m_context = context;
|
|
||||||
m_name = src.m_name;
|
m_name = src.m_name;
|
||||||
gameID = src.gameID;
|
gameID = src.gameID;
|
||||||
nPlayers = src.nPlayers;
|
nPlayers = src.nPlayers;
|
||||||
|
@ -200,23 +197,23 @@ public class CurGameInfo implements Serializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLang( int lang, String dict )
|
public void setLang( Context context, int lang, String dict )
|
||||||
{
|
{
|
||||||
if ( null != dict ) {
|
if ( null != dict ) {
|
||||||
dictName = dict;
|
dictName = dict;
|
||||||
}
|
}
|
||||||
setLang( lang );
|
setLang( context, lang );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLang( int lang )
|
public void setLang( Context context, int lang )
|
||||||
{
|
{
|
||||||
if ( 0 == lang ) {
|
if ( 0 == lang ) {
|
||||||
String dictName = CommonPrefs.getDefaultHumanDict( m_context );
|
String dictName = CommonPrefs.getDefaultHumanDict( context );
|
||||||
lang = DictLangCache.getDictLangCode( m_context, dictName );
|
lang = DictLangCache.getDictLangCode( context, dictName );
|
||||||
}
|
}
|
||||||
if ( dictLang != lang ) {
|
if ( dictLang != lang ) {
|
||||||
dictLang = lang;
|
dictLang = lang;
|
||||||
assignDicts();
|
assignDicts( context );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,10 +314,10 @@ public class CurGameInfo implements Serializable {
|
||||||
return locs;
|
return locs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] visibleNames( boolean withDicts )
|
public String[] visibleNames( Context context, boolean withDicts )
|
||||||
{
|
{
|
||||||
String nameFmt = withDicts?
|
String nameFmt = withDicts?
|
||||||
LocUtils.getString( m_context, R.string.name_dict_fmt )
|
LocUtils.getString( context, R.string.name_dict_fmt )
|
||||||
: "%s";
|
: "%s";
|
||||||
String[] names = new String[nPlayers];
|
String[] names = new String[nPlayers];
|
||||||
for ( int ii = 0; ii < nPlayers; ++ii ) {
|
for ( int ii = 0; ii < nPlayers; ++ii ) {
|
||||||
|
@ -328,14 +325,14 @@ public class CurGameInfo implements Serializable {
|
||||||
if ( lp.isLocal || serverRole == DeviceRole.SERVER_STANDALONE ) {
|
if ( lp.isLocal || serverRole == DeviceRole.SERVER_STANDALONE ) {
|
||||||
String name;
|
String name;
|
||||||
if ( lp.isRobot() ) {
|
if ( lp.isRobot() ) {
|
||||||
String format = LocUtils.getString( m_context, R.string.robot_name_fmt );
|
String format = LocUtils.getString( context, R.string.robot_name_fmt );
|
||||||
name = String.format( format, lp.name );
|
name = String.format( format, lp.name );
|
||||||
} else {
|
} else {
|
||||||
name = lp.name;
|
name = lp.name;
|
||||||
}
|
}
|
||||||
names[ii] = String.format( nameFmt, name, dictName(lp) );
|
names[ii] = String.format( nameFmt, name, dictName(lp) );
|
||||||
} else {
|
} else {
|
||||||
names[ii] = LocUtils.getString( m_context, R.string.guest_name );
|
names[ii] = LocUtils.getString( context, R.string.guest_name );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return names;
|
return names;
|
||||||
|
@ -352,10 +349,10 @@ public class CurGameInfo implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace any dict that doesn't exist with newDict
|
// Replace any dict that doesn't exist with newDict
|
||||||
public void replaceDicts( String newDict )
|
public void replaceDicts( Context context, String newDict )
|
||||||
{
|
{
|
||||||
String[] dicts =
|
String[] dicts =
|
||||||
DictLangCache.getHaveLang( m_context, dictLang );
|
DictLangCache.getHaveLang( context, dictLang );
|
||||||
HashSet<String> installed = new HashSet<String>( Arrays.asList(dicts) );
|
HashSet<String> installed = new HashSet<String>( Arrays.asList(dicts) );
|
||||||
|
|
||||||
if ( !installed.contains( dictName ) ) {
|
if ( !installed.contains( dictName ) ) {
|
||||||
|
@ -372,9 +369,9 @@ public class CurGameInfo implements Serializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String langName()
|
public String langName( Context context )
|
||||||
{
|
{
|
||||||
return DictLangCache.getLangName( m_context, dictLang );
|
return DictLangCache.getLangName( context, dictLang );
|
||||||
}
|
}
|
||||||
|
|
||||||
public String dictName( final LocalPlayer lp )
|
public String dictName( final LocalPlayer lp )
|
||||||
|
@ -484,7 +481,7 @@ public class CurGameInfo implements Serializable {
|
||||||
return canJuggle;
|
return canJuggle;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assignDicts()
|
private void assignDicts( Context context )
|
||||||
{
|
{
|
||||||
// For each player's dict, if non-null and language matches
|
// For each player's dict, if non-null and language matches
|
||||||
// leave it alone. Otherwise replace with default if that
|
// leave it alone. Otherwise replace with default if that
|
||||||
|
@ -492,13 +489,13 @@ public class CurGameInfo implements Serializable {
|
||||||
// right language.
|
// right language.
|
||||||
|
|
||||||
String humanDict =
|
String humanDict =
|
||||||
DictLangCache.getBestDefault( m_context, dictLang, true );
|
DictLangCache.getBestDefault( context, dictLang, true );
|
||||||
String robotDict =
|
String robotDict =
|
||||||
DictLangCache.getBestDefault( m_context, dictLang, false );
|
DictLangCache.getBestDefault( context, dictLang, false );
|
||||||
|
|
||||||
if ( null == dictName
|
if ( null == dictName
|
||||||
|| ! DictUtils.dictExists( m_context, dictName )
|
|| ! DictUtils.dictExists( context, dictName )
|
||||||
|| dictLang != DictLangCache.getDictLangCode( m_context,
|
|| dictLang != DictLangCache.getDictLangCode( context,
|
||||||
dictName ) ) {
|
dictName ) ) {
|
||||||
dictName = humanDict;
|
dictName = humanDict;
|
||||||
}
|
}
|
||||||
|
@ -507,7 +504,7 @@ public class CurGameInfo implements Serializable {
|
||||||
LocalPlayer lp = players[ii];
|
LocalPlayer lp = players[ii];
|
||||||
|
|
||||||
if ( null != lp.dictName &&
|
if ( null != lp.dictName &&
|
||||||
dictLang != DictLangCache.getDictLangCode( m_context,
|
dictLang != DictLangCache.getDictLangCode( context,
|
||||||
lp.dictName ) ) {
|
lp.dictName ) ) {
|
||||||
lp.dictName = null;
|
lp.dictName = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -358,7 +358,7 @@ public class GameSummary implements Serializable {
|
||||||
{
|
{
|
||||||
String[] names = null;
|
String[] names = null;
|
||||||
if ( null != m_gi ) {
|
if ( null != m_gi ) {
|
||||||
names = m_gi.visibleNames( false );
|
names = m_gi.visibleNames( m_context, false );
|
||||||
} else if ( null != m_playersSummary ) {
|
} else if ( null != m_playersSummary ) {
|
||||||
names = TextUtils.split( m_playersSummary, "\n" );
|
names = TextUtils.split( m_playersSummary, "\n" );
|
||||||
}
|
}
|
||||||
|
|
|
@ -218,15 +218,19 @@ public class JNIThread extends Thread {
|
||||||
}
|
}
|
||||||
m_jniGamePtr = null;
|
m_jniGamePtr = null;
|
||||||
if ( null != stream ) {
|
if ( null != stream ) {
|
||||||
m_jniGamePtr = XwJNI.initFromStream( m_rowid, stream, m_gi, dictNames,
|
m_jniGamePtr = XwJNI.initFromStream( m_rowid, stream, m_gi,
|
||||||
pairs.m_bytes, pairs.m_paths,
|
dictNames, pairs.m_bytes,
|
||||||
m_gi.langName(), utils, jniUtils,
|
pairs.m_paths,
|
||||||
|
m_gi.langName( m_context ),
|
||||||
|
utils, jniUtils,
|
||||||
null, cp, m_xport );
|
null, cp, m_xport );
|
||||||
}
|
}
|
||||||
if ( null == m_jniGamePtr ) {
|
if ( null == m_jniGamePtr ) {
|
||||||
m_jniGamePtr = XwJNI.initNew( m_gi, dictNames, pairs.m_bytes,
|
m_jniGamePtr = XwJNI.initNew( m_gi, dictNames, pairs.m_bytes,
|
||||||
pairs.m_paths, m_gi.langName(), utils,
|
pairs.m_paths,
|
||||||
jniUtils, null, cp, m_xport );
|
m_gi.langName(m_context),
|
||||||
|
utils, jniUtils, null, cp,
|
||||||
|
m_xport );
|
||||||
}
|
}
|
||||||
Assert.assertNotNull( m_jniGamePtr );
|
Assert.assertNotNull( m_jniGamePtr );
|
||||||
m_lastSavedState = Arrays.hashCode( stream );
|
m_lastSavedState = Arrays.hashCode( stream );
|
||||||
|
|
Loading…
Add table
Reference in a new issue