mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-22 07:28:16 +01:00
fix timer-draw NPE due to race condition
use runOnUiThread()....
This commit is contained in:
parent
a328221b63
commit
39efbaa7f5
1 changed files with 24 additions and 15 deletions
|
@ -322,26 +322,35 @@ public class BoardCanvas extends Canvas implements DrawCtx {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawTimer( Rect rect, int player, int secondsLeft )
|
public void drawTimer( Rect rect, final int player,
|
||||||
|
int secondsLeft )
|
||||||
{
|
{
|
||||||
if ( null != m_jniThread &&
|
if ( m_lastSecsLeft != secondsLeft || m_lastTimerPlayer != player ) {
|
||||||
(m_lastSecsLeft != secondsLeft || m_lastTimerPlayer != player) ) {
|
final Rect rectCopy = new Rect(rect);
|
||||||
m_lastSecsLeft = secondsLeft;
|
final int secondsLeftCopy = secondsLeft;
|
||||||
m_lastTimerPlayer = player;
|
m_activity.runOnUiThread( new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if ( null != m_jniThread ) {
|
||||||
|
m_lastSecsLeft = secondsLeftCopy;
|
||||||
|
m_lastTimerPlayer = player;
|
||||||
|
|
||||||
String negSign = secondsLeft < 0? "-":"";
|
String negSign = secondsLeftCopy < 0? "-":"";
|
||||||
secondsLeft = Math.abs( secondsLeft );
|
int secondsLeft = Math.abs( secondsLeftCopy );
|
||||||
String time = String.format( "%s%d:%02d", negSign, secondsLeft/60,
|
String time =
|
||||||
secondsLeft%60 );
|
String.format( "%s%d:%02d", negSign,
|
||||||
|
secondsLeft/60, secondsLeft%60 );
|
||||||
|
|
||||||
fillRectOther( rect, CommonPrefs.COLOR_BACKGRND );
|
fillRectOther( rectCopy, CommonPrefs.COLOR_BACKGRND );
|
||||||
m_fillPaint.setColor( m_playerColors[player] );
|
m_fillPaint.setColor( m_playerColors[player] );
|
||||||
|
|
||||||
Rect shorter = new Rect( rect );
|
rectCopy.inset( 0, rectCopy.height() / 5 );
|
||||||
shorter.inset( 0, shorter.height() / 5 );
|
drawCentered( time, rectCopy, null );
|
||||||
drawCentered( time, shorter, null );
|
|
||||||
|
|
||||||
m_jniThread.handle( JNIThread.JNICmd.CMD_DRAW );
|
m_jniThread.handle( JNIThread.JNICmd.CMD_DRAW );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue