mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-04 20:46:28 +01:00
add logging toward catching board layout problems; throw exception
when can't unlock game (possible fix to multiple instances of GamesListActivity stacking up); cleanup of GamesListDelegate tracking of open games.
This commit is contained in:
parent
21ef6d4e13
commit
8cb2cecc18
7 changed files with 56 additions and 35 deletions
|
@ -666,8 +666,8 @@ public class BoardDelegate extends DelegateBase
|
|||
m_jniThreadRef.release();
|
||||
m_jniThreadRef = null;
|
||||
// Assert.assertNull( m_jniThreadRef ); // firing
|
||||
GamesListDelegate.boardDestroyed( m_rowid );
|
||||
}
|
||||
GamesListDelegate.boardDestroyed( m_rowid );
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
@ -1464,7 +1464,7 @@ public class BoardDelegate extends DelegateBase
|
|||
|
||||
finish();
|
||||
|
||||
GameUtils.launchGame( m_activity, m_rowid, m_haveInvited );
|
||||
GameUtils.launchGame( getDelegator(), m_rowid, m_haveInvited );
|
||||
}
|
||||
|
||||
private void setGotGameDict( String getDict )
|
||||
|
@ -1474,7 +1474,7 @@ public class BoardDelegate extends DelegateBase
|
|||
String msg = getString( R.string.reload_new_dict_fmt, getDict );
|
||||
showToast( msg );
|
||||
finish();
|
||||
GameUtils.launchGame( m_activity, m_rowid, false );
|
||||
GameUtils.launchGame( getDelegator(), m_rowid, false );
|
||||
}
|
||||
|
||||
private XwJNI.XP_Key keyCodeToXPKey( int keyCode )
|
||||
|
|
|
@ -158,6 +158,7 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
|
|||
DbgUtils.logf( "onMeasure: discarding m_dims" );
|
||||
if ( ++m_dimsTossCount < 4 ) {
|
||||
m_dims = null;
|
||||
m_layoutWidth = m_layoutHeight = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -202,7 +203,7 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
|
|||
ConnStatusHandler.draw( m_context, canvas, getResources(),
|
||||
m_connTypes, m_isSolo );
|
||||
} else {
|
||||
DbgUtils.logf( "board not laid out yet" );
|
||||
DbgUtils.logf( "BoardView.onDraw(): board not laid out yet" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -213,12 +214,15 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
|
|||
final int height = getHeight();
|
||||
boolean layoutDone = width == m_layoutWidth && height == m_layoutHeight;
|
||||
if ( layoutDone ) {
|
||||
// nothing to do
|
||||
DbgUtils.logf( "layoutBoardOnce(): layoutDone true" );
|
||||
} else if ( null == m_gi ) {
|
||||
// nothing to do either
|
||||
DbgUtils.logf( "layoutBoardOnce(): no m_gi" );
|
||||
} else if ( null == m_jniThread ) {
|
||||
// nothing to do either
|
||||
DbgUtils.logf( "layoutBoardOnce(): no m_jniThread" );
|
||||
} else if ( null == m_dims ) {
|
||||
DbgUtils.logf( "layoutBoardOnce(): null m_dims" );
|
||||
// m_canvas = null;
|
||||
// need to synchronize??
|
||||
Paint paint = new Paint();
|
||||
|
@ -234,6 +238,7 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
|
|||
fontWidth, m_defaultFontHt );
|
||||
// We'll be back....
|
||||
} else {
|
||||
DbgUtils.logf( "layoutBoardOnce(): DOING IT" );
|
||||
// If board size has changed we need a new bitmap
|
||||
int bmHeight = 1 + m_dims.height;
|
||||
int bmWidth = 1 + m_dims.width;
|
||||
|
|
|
@ -118,10 +118,14 @@ public class DBUtils {
|
|||
long maxMillis )
|
||||
{
|
||||
GameSummary result = null;
|
||||
GameLock lock = new GameLock( rowid, false ).lock( maxMillis );
|
||||
if ( null != lock ) {
|
||||
result = getSummary( context, lock );
|
||||
lock.unlock();
|
||||
try {
|
||||
GameLock lock = new GameLock( rowid, false ).lock( maxMillis );
|
||||
if ( null != lock ) {
|
||||
result = getSummary( context, lock );
|
||||
lock.unlock();
|
||||
}
|
||||
} catch ( GameLock.GameLockedException gle ) {
|
||||
DbgUtils.loge( gle );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -1166,7 +1166,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
&& 0 == m_car.ip_relay_invite.length() ) {
|
||||
showOKOnlyDialog( R.string.no_empty_rooms );
|
||||
} else {
|
||||
GameUtils.launchGameAndFinish( m_activity, m_rowid );
|
||||
GameUtils.launchGameAndFinish( getDelegator(), m_rowid );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,13 +29,21 @@ import junit.framework.Assert;
|
|||
// write lock is. Write-locks are exclusive.
|
||||
public class GameLock {
|
||||
private static final boolean DEBUG_LOCKS = false;
|
||||
private static final boolean THROW_ON_LOCKED = true;
|
||||
private static final int SLEEP_TIME = 100;
|
||||
private static final long ASSERT_TIME = 2000;
|
||||
private static final long THROW_TIME = 750;
|
||||
private long m_rowid;
|
||||
private boolean m_isForWrite;
|
||||
private int m_lockCount;
|
||||
private StackTraceElement[] m_lockTrace;
|
||||
|
||||
static {
|
||||
Assert.assertTrue( THROW_TIME <= ASSERT_TIME );
|
||||
}
|
||||
|
||||
public static class GameLockedException extends RuntimeException {}
|
||||
|
||||
private static HashMap<Long, GameLock>
|
||||
s_locks = new HashMap<Long,GameLock>();
|
||||
|
||||
|
@ -145,6 +153,8 @@ public class GameLock {
|
|||
|
||||
if ( 0 < maxMillis && sleptTime >= maxMillis ) {
|
||||
break;
|
||||
} else if ( THROW_ON_LOCKED && sleptTime >= THROW_TIME ) {
|
||||
throw new GameLockedException();
|
||||
} else if ( sleptTime >= ASSERT_TIME ) {
|
||||
if ( DEBUG_LOCKS ) {
|
||||
DbgUtils.logf( "lock %H overlocked", this );
|
||||
|
|
|
@ -843,12 +843,13 @@ public class GameUtils {
|
|||
return bundle;
|
||||
}
|
||||
|
||||
public static void launchGame( Activity activity, long rowid,
|
||||
public static void launchGame( Delegator delegator, long rowid,
|
||||
boolean invited )
|
||||
{
|
||||
Activity activity = delegator.getActivity();
|
||||
Bundle extras = makeLaunchExtras( rowid, invited );
|
||||
if ( activity instanceof FragActivity ) {
|
||||
FragActivity.addFragment( new BoardFrag(), extras );
|
||||
FragActivity.addFragment( new BoardFrag(), extras, delegator );
|
||||
} else {
|
||||
Intent intent = new Intent( activity, BoardActivity.class );
|
||||
intent.putExtras( extras );
|
||||
|
@ -856,15 +857,15 @@ public class GameUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static void launchGame( Activity activity, long rowid )
|
||||
public static void launchGame( Delegator delegator, long rowid )
|
||||
{
|
||||
launchGame( activity, rowid, false );
|
||||
launchGame( delegator, rowid, false );
|
||||
}
|
||||
|
||||
public static void launchGameAndFinish( Activity activity, long rowid )
|
||||
public static void launchGameAndFinish( Delegator delegator, long rowid )
|
||||
{
|
||||
launchGame( activity, rowid );
|
||||
activity.finish();
|
||||
launchGame( delegator, rowid );
|
||||
delegator.getActivity().finish();
|
||||
}
|
||||
|
||||
private static class FeedUtilsImpl extends UtilCtxtImpl {
|
||||
|
|
|
@ -580,7 +580,7 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
private String m_nameField;
|
||||
private NetLaunchInfo m_netLaunchInfo;
|
||||
private GameNamer m_namer;
|
||||
private Set<Long> m_launchedGames;
|
||||
private Set<Long> m_launchedGames; // prevent problems with double-taps
|
||||
private boolean m_menuPrepared;
|
||||
private boolean m_moveAfterNewGroup;
|
||||
private Set<Long> m_selGames;
|
||||
|
@ -988,7 +988,9 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
protected void onDestroy()
|
||||
{
|
||||
DBUtils.clearDBChangeListener( this );
|
||||
s_self = null;
|
||||
if ( s_self == this ) {
|
||||
s_self = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected void onSaveInstanceState( Bundle outState )
|
||||
|
@ -1044,16 +1046,7 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
if ( hasFocus ) {
|
||||
updateField();
|
||||
|
||||
if ( 0 != m_launchedGames.size() ) {
|
||||
long rowid = m_launchedGames.iterator().next();
|
||||
m_launchedGames.remove( rowid );
|
||||
|
||||
if ( m_adapter.inExpandedGroup( rowid ) ) {
|
||||
setSelGame( rowid );
|
||||
} else {
|
||||
clearSelections();
|
||||
}
|
||||
}
|
||||
m_launchedGames.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1303,7 +1296,7 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
if ( !cancelled ) {
|
||||
long rowID = data.getLongExtra( GameUtils.INTENT_KEY_ROWID,
|
||||
DBUtils.ROWID_NOTFOUND );
|
||||
GameUtils.launchGame( m_activity, rowID );
|
||||
GameUtils.launchGame( getDelegator(), rowID );
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -2292,7 +2285,7 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
long[] rowIDs = { rowID };
|
||||
doConfirmReset( rowIDs );
|
||||
} else if ( checkWarnNoDict( rowID ) ) {
|
||||
GameUtils.launchGame( m_activity, rowID );
|
||||
GameUtils.launchGame( getDelegator(), rowID );
|
||||
}
|
||||
}
|
||||
return madeGame;
|
||||
|
@ -2306,7 +2299,10 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
// m_delegator.launchGame( rowid, invited );
|
||||
if ( ! m_launchedGames.contains( rowid ) ) {
|
||||
m_launchedGames.add( rowid );
|
||||
GameUtils.launchGame( m_activity, rowid, invited );
|
||||
if ( m_adapter.inExpandedGroup( rowid ) ) {
|
||||
setSelGame( rowid );
|
||||
}
|
||||
GameUtils.launchGame( getDelegator(), rowid, invited );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2342,8 +2338,13 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
&& summary.roomName.length() == 0 ) {
|
||||
Assert.fail();
|
||||
} else {
|
||||
if ( checkWarnNoDict( rowid ) ) {
|
||||
launchGame( rowid );
|
||||
try {
|
||||
if ( checkWarnNoDict( rowid ) ) {
|
||||
launchGame( rowid );
|
||||
}
|
||||
} catch ( GameLock.GameLockedException gle ) {
|
||||
DbgUtils.loge( gle );
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2486,7 +2487,7 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
.CONFIG_GAME, rowID );
|
||||
} else {
|
||||
// launch it
|
||||
GameUtils.launchGame( m_activity, rowID );
|
||||
GameUtils.launchGame( getDelegator(), rowID );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue