fix so board still works after reloading, e.g. after turning screen

off and back on.
This commit is contained in:
Eric House 2013-11-11 08:09:15 -08:00
parent da3215c116
commit 7cf297ad0e
3 changed files with 33 additions and 5 deletions

View file

@ -163,6 +163,14 @@ public class BoardCanvas extends Canvas implements DrawCtx {
fillRect( m_boundsScratch, WHITE );
}
public void setJNIThread( JNIThread jniThread )
{
if ( ! jniThread.equals( m_jniThread ) ) {
DbgUtils.logf( "BoardCanvas changing threads" );
m_jniThread = jniThread;
}
}
public int getCurPlayer()
{
return m_trayOwner;
@ -528,7 +536,8 @@ public class BoardCanvas extends Canvas implements DrawCtx {
m_dictChars = XwJNI.dict_getChars( dictPtr );
// draw again
if ( null != m_jniThread ) {
m_jniThread.handle( JNIThread.JNICmd.CMD_DRAW );
m_jniThread.handle( JNIThread.JNICmd
.CMD_INVALALL );
}
}
});

View file

@ -251,7 +251,10 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
if ( null == m_canvas ) {
DbgUtils.logf( "layoutBoardOnce: allocating canvas for %d, %d",
bmWidth, bmHeight );
m_canvas = new BoardCanvas( m_parent, s_bitmap, m_jniThread, m_dims );
m_canvas = new BoardCanvas( m_parent, s_bitmap, m_jniThread,
m_dims );
} else {
m_canvas.setJNIThread( m_jniThread );
}
m_jniThread.handle( JNIThread.JNICmd.CMD_SETDRAW, m_canvas );
m_jniThread.handle( JNIThread.JNICmd.CMD_DRAW );
@ -270,7 +273,6 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
int gamePtr, CurGameInfo gi,
CommsAddrRec.CommsConnType connType )
{
DbgUtils.logf( "startHandling()" );
m_parent = parent;
m_jniThread = thread;
m_jniGamePtr = gamePtr;
@ -279,6 +281,11 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
m_layoutWidth = 0;
m_layoutHeight = 0;
// Set the jni layout if we already have one
if ( null != m_dims ) {
m_jniThread.handle( JNIThread.JNICmd.CMD_LAYOUT, m_dims );
}
// Make sure we draw. Sometimes when we're reloading after
// an obsuring Activity goes away we otherwise won't.
invalidate();

View file

@ -361,8 +361,15 @@ public class JNIThread extends Thread {
break;
case CMD_LAYOUT:
doLayout( (Integer)args[0], (Integer)args[1], (Integer)args[2],
(Integer)args[3] );
Object args0 = args[0];
BoardDims dims = null;
if ( args0 instanceof BoardDims ) {
dims = (BoardDims)args0;
XwJNI.board_applyLayout( m_jniGamePtr, dims );
} else {
doLayout( (Integer)args0, (Integer)args[1],
(Integer)args[2], (Integer)args[3] );
}
draw = true;
// check and disable zoom button at limit
handle( JNICmd.CMD_ZOOM, 0 );
@ -644,6 +651,11 @@ public class JNIThread extends Thread {
{
QueueElem elem = new QueueElem( cmd, true, args );
m_queue.add( elem );
if ( m_stopped ) {
DbgUtils.logf( "WARNING: adding %s to stopped thread!!!",
cmd.toString() );
DbgUtils.printStack();
}
}
// public void run( boolean isUI, Runnable runnable )