mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-22 07:28:16 +01:00
toward working better in background: log and print stack when doing
nothing because jnithread is null. Pass incoming chat messages to ChatDelegate if it's up, and otherwise launch it as before.
This commit is contained in:
parent
919e44f21e
commit
3a368a8efd
1 changed files with 40 additions and 44 deletions
|
@ -232,7 +232,7 @@ public class BoardDelegate extends DelegateBase
|
||||||
lstnr = new OnClickListener() {
|
lstnr = new OnClickListener() {
|
||||||
public void onClick( DialogInterface dlg,
|
public void onClick( DialogInterface dlg,
|
||||||
int whichButton ) {
|
int whichButton ) {
|
||||||
m_jniThread.handle( JNICmd.CMD_RESET );
|
handleViaThread( JNICmd.CMD_RESET );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
ab.setNegativeButton( R.string.button_retry, lstnr );
|
ab.setNegativeButton( R.string.button_retry, lstnr );
|
||||||
|
@ -422,8 +422,7 @@ public class BoardDelegate extends DelegateBase
|
||||||
public void
|
public void
|
||||||
onClick( DialogInterface dlg,
|
onClick( DialogInterface dlg,
|
||||||
int item ) {
|
int item ) {
|
||||||
m_jniThread.
|
handleViaThread(JNICmd.CMD_ENDGAME);
|
||||||
handle(JNICmd.CMD_ENDGAME);
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.setNegativeButton( R.string.button_no, null )
|
.setNegativeButton( R.string.button_no, null )
|
||||||
|
@ -740,7 +739,7 @@ public class BoardDelegate extends DelegateBase
|
||||||
m_firingPrefs = false;
|
m_firingPrefs = false;
|
||||||
m_volKeysZoom = XWPrefs.getVolKeysZoom( m_activity );
|
m_volKeysZoom = XWPrefs.getVolKeysZoom( m_activity );
|
||||||
if ( null != m_jniThread ) {
|
if ( null != m_jniThread ) {
|
||||||
m_jniThread.handle( JNICmd.CMD_PREFS_CHANGE );
|
handleViaThread( JNICmd.CMD_PREFS_CHANGE );
|
||||||
}
|
}
|
||||||
// in case of change...
|
// in case of change...
|
||||||
setBackgroundColor();
|
setBackgroundColor();
|
||||||
|
@ -779,7 +778,7 @@ public class BoardDelegate extends DelegateBase
|
||||||
if ( null != m_jniThread ) {
|
if ( null != m_jniThread ) {
|
||||||
XwJNI.XP_Key xpKey = keyCodeToXPKey( keyCode );
|
XwJNI.XP_Key xpKey = keyCodeToXPKey( keyCode );
|
||||||
if ( XwJNI.XP_Key.XP_KEY_NONE != xpKey ) {
|
if ( XwJNI.XP_Key.XP_KEY_NONE != xpKey ) {
|
||||||
m_jniThread.handle( JNICmd.CMD_KEYDOWN, xpKey );
|
handleViaThread( JNICmd.CMD_KEYDOWN, xpKey );
|
||||||
} else {
|
} else {
|
||||||
switch( keyCode ) {
|
switch( keyCode ) {
|
||||||
case KeyEvent.KEYCODE_VOLUME_DOWN:
|
case KeyEvent.KEYCODE_VOLUME_DOWN:
|
||||||
|
@ -802,7 +801,7 @@ public class BoardDelegate extends DelegateBase
|
||||||
if ( null != m_jniThread ) {
|
if ( null != m_jniThread ) {
|
||||||
XwJNI.XP_Key xpKey = keyCodeToXPKey( keyCode );
|
XwJNI.XP_Key xpKey = keyCodeToXPKey( keyCode );
|
||||||
if ( XwJNI.XP_Key.XP_KEY_NONE != xpKey ) {
|
if ( XwJNI.XP_Key.XP_KEY_NONE != xpKey ) {
|
||||||
m_jniThread.handle( JNICmd.CMD_KEYUP, xpKey );
|
handleViaThread( JNICmd.CMD_KEYUP, xpKey );
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -968,7 +967,7 @@ public class BoardDelegate extends DelegateBase
|
||||||
StudyListDelegate.launchOrAlert( getDelegator(), m_gi.dictLang, this );
|
StudyListDelegate.launchOrAlert( getDelegator(), m_gi.dictLang, this );
|
||||||
break;
|
break;
|
||||||
case R.id.board_menu_game_netstats:
|
case R.id.board_menu_game_netstats:
|
||||||
m_jniThread.handle( JNICmd.CMD_NETSTATS, R.string.netstats_title );
|
handleViaThread( JNICmd.CMD_NETSTATS, R.string.netstats_title );
|
||||||
break;
|
break;
|
||||||
case R.id.board_menu_game_invites:
|
case R.id.board_menu_game_invites:
|
||||||
SentInvitesInfo sentInfo = DBUtils.getInvitesFor( m_activity, m_rowid );
|
SentInvitesInfo sentInfo = DBUtils.getInvitesFor( m_activity, m_rowid );
|
||||||
|
@ -988,24 +987,23 @@ public class BoardDelegate extends DelegateBase
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R.id.board_menu_game_counts:
|
case R.id.board_menu_game_counts:
|
||||||
m_jniThread.handle( JNICmd.CMD_COUNTS_VALUES,
|
handleViaThread( JNICmd.CMD_COUNTS_VALUES,
|
||||||
R.string.counts_values_title );
|
R.string.counts_values_title );
|
||||||
break;
|
break;
|
||||||
case R.id.board_menu_game_left:
|
case R.id.board_menu_game_left:
|
||||||
m_jniThread.handle( JNICmd.CMD_REMAINING,
|
handleViaThread( JNICmd.CMD_REMAINING, R.string.tiles_left_title );
|
||||||
R.string.tiles_left_title );
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R.id.board_menu_game_history:
|
case R.id.board_menu_game_history:
|
||||||
m_jniThread.handle( JNICmd.CMD_HISTORY, R.string.history_title );
|
handleViaThread( JNICmd.CMD_HISTORY, R.string.history_title );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R.id.board_menu_game_resign:
|
case R.id.board_menu_game_resign:
|
||||||
m_jniThread.handle( JNICmd.CMD_FINAL, R.string.history_title );
|
handleViaThread( JNICmd.CMD_FINAL, R.string.history_title );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R.id.board_menu_game_resend:
|
case R.id.board_menu_game_resend:
|
||||||
m_jniThread.handle( JNICmd.CMD_RESEND, true, false, true );
|
handleViaThread( JNICmd.CMD_RESEND, true, false, true );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R.id.gamel_menu_checkmoves:
|
case R.id.gamel_menu_checkmoves:
|
||||||
|
@ -1025,7 +1023,7 @@ public class BoardDelegate extends DelegateBase
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( handled && cmd != JNICmd.CMD_NONE ) {
|
if ( handled && cmd != JNICmd.CMD_NONE ) {
|
||||||
m_jniThread.handle( cmd );
|
handleViaThread( cmd );
|
||||||
}
|
}
|
||||||
return handled;
|
return handled;
|
||||||
}
|
}
|
||||||
|
@ -1125,7 +1123,7 @@ public class BoardDelegate extends DelegateBase
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( JNICmd.CMD_NONE != cmd ) {
|
if ( JNICmd.CMD_NONE != cmd ) {
|
||||||
checkAndHandle( cmd );
|
handleViaThread( cmd );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1190,9 +1188,9 @@ public class BoardDelegate extends DelegateBase
|
||||||
public void onClick( View view )
|
public void onClick( View view )
|
||||||
{
|
{
|
||||||
if ( view == m_exchCommmitButton ) {
|
if ( view == m_exchCommmitButton ) {
|
||||||
m_jniThread.handle( JNICmd.CMD_COMMIT );
|
handleViaThread( JNICmd.CMD_COMMIT );
|
||||||
} else if ( view == m_exchCancelButton ) {
|
} else if ( view == m_exchCancelButton ) {
|
||||||
m_jniThread.handle( JNICmd.CMD_CANCELTRADE );
|
handleViaThread( JNICmd.CMD_CANCELTRADE );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1621,7 +1619,7 @@ public class BoardDelegate extends DelegateBase
|
||||||
@Override
|
@Override
|
||||||
public void requestTime()
|
public void requestTime()
|
||||||
{
|
{
|
||||||
post( new Runnable() {
|
runOnUiThread( new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
if ( null != m_jniThread ) {
|
if ( null != m_jniThread ) {
|
||||||
m_jniThread.handleBkgrnd( JNICmd.CMD_DO );
|
m_jniThread.handleBkgrnd( JNICmd.CMD_DO );
|
||||||
|
@ -1633,8 +1631,7 @@ public class BoardDelegate extends DelegateBase
|
||||||
@Override
|
@Override
|
||||||
public void remSelected()
|
public void remSelected()
|
||||||
{
|
{
|
||||||
m_jniThread.handle( JNICmd.CMD_REMAINING,
|
handleViaThread( JNICmd.CMD_REMAINING, R.string.tiles_left_title );
|
||||||
R.string.tiles_left_title );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1645,7 +1642,7 @@ public class BoardDelegate extends DelegateBase
|
||||||
if ( newRole != m_gi.serverRole ) {
|
if ( newRole != m_gi.serverRole ) {
|
||||||
m_gi.serverRole = newRole;
|
m_gi.serverRole = newRole;
|
||||||
if ( !isServer ) {
|
if ( !isServer ) {
|
||||||
m_jniThread.handle( JNICmd.CMD_SWITCHCLIENT );
|
handleViaThread( JNICmd.CMD_SWITCHCLIENT );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1786,7 +1783,7 @@ public class BoardDelegate extends DelegateBase
|
||||||
R.string.key_notagain_turnchanged );
|
R.string.key_notagain_turnchanged );
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
m_jniThread.handle( JNICmd. CMD_ZOOM, -8 );
|
handleViaThread( JNICmd. CMD_ZOOM, -8 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1989,7 +1986,7 @@ public class BoardDelegate extends DelegateBase
|
||||||
public void notifyGameOver()
|
public void notifyGameOver()
|
||||||
{
|
{
|
||||||
m_gameOver = true;
|
m_gameOver = true;
|
||||||
m_jniThread.handle( JNICmd.CMD_POST_OVER );
|
handleViaThread( JNICmd.CMD_POST_OVER );
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void yOffsetChange( int maxOffset, int oldOffset, int newOffset )
|
// public void yOffsetChange( int maxOffset, int oldOffset, int newOffset )
|
||||||
|
@ -2029,11 +2026,14 @@ public class BoardDelegate extends DelegateBase
|
||||||
String fromPlayer )
|
String fromPlayer )
|
||||||
{
|
{
|
||||||
if ( BuildConstants.CHAT_SUPPORTED ) {
|
if ( BuildConstants.CHAT_SUPPORTED ) {
|
||||||
post( new Runnable() {
|
runOnUiThread( new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
DBUtils.appendChatHistory( m_activity, m_rowid, msg,
|
DBUtils.appendChatHistory( m_activity, m_rowid, msg,
|
||||||
fromIndx );
|
fromIndx );
|
||||||
startChatActivity();
|
if ( ! ChatDelegate.append( m_rowid, msg,
|
||||||
|
fromIndx ) ) {
|
||||||
|
startChatActivity();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
@ -2170,7 +2170,7 @@ public class BoardDelegate extends DelegateBase
|
||||||
Assert.assertNotNull( m_connTypes );
|
Assert.assertNotNull( m_connTypes );
|
||||||
m_xport.setReceiver( m_jniThread, m_handler );
|
m_xport.setReceiver( m_jniThread, m_handler );
|
||||||
}
|
}
|
||||||
m_jniThread.handle( JNICmd.CMD_START );
|
handleViaThread( JNICmd.CMD_START );
|
||||||
|
|
||||||
if ( !CommonPrefs.getHideTitleBar( m_activity ) ) {
|
if ( !CommonPrefs.getHideTitleBar( m_activity ) ) {
|
||||||
setTitle( GameUtils.getName( m_activity, m_rowid ) );
|
setTitle( GameUtils.getName( m_activity, m_rowid ) );
|
||||||
|
@ -2194,7 +2194,7 @@ public class BoardDelegate extends DelegateBase
|
||||||
}
|
}
|
||||||
if ( m_gameOver ) {
|
if ( m_gameOver ) {
|
||||||
m_overNotShown = false;
|
m_overNotShown = false;
|
||||||
m_jniThread.handle( JNICmd.CMD_POST_OVER, auto );
|
handleViaThread( JNICmd.CMD_POST_OVER, auto );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( 0 != flags ) {
|
if ( 0 != flags ) {
|
||||||
|
@ -2237,8 +2237,7 @@ public class BoardDelegate extends DelegateBase
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( 0 < m_connTypes.size() ) {
|
if ( 0 < m_connTypes.size() ) {
|
||||||
m_jniThread.handle( JNIThread.JNICmd.CMD_RESEND, force, true,
|
handleViaThread( JNIThread.JNICmd.CMD_RESEND, force, true, false );
|
||||||
false );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2270,13 +2269,6 @@ public class BoardDelegate extends DelegateBase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkAndHandle( JNICmd cmd )
|
|
||||||
{
|
|
||||||
if ( null != m_jniThread ) {
|
|
||||||
m_jniThread.handle( cmd );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void populateToolbar()
|
private void populateToolbar()
|
||||||
{
|
{
|
||||||
if ( null != m_toolbar ) {
|
if ( null != m_toolbar ) {
|
||||||
|
@ -2402,7 +2394,7 @@ public class BoardDelegate extends DelegateBase
|
||||||
{
|
{
|
||||||
boolean handled = null != m_jniThread;
|
boolean handled = null != m_jniThread;
|
||||||
if ( handled ) {
|
if ( handled ) {
|
||||||
m_jniThread.handle( JNICmd.CMD_ZOOM, zoomBy );
|
handleViaThread( JNICmd.CMD_ZOOM, zoomBy );
|
||||||
}
|
}
|
||||||
return handled;
|
return handled;
|
||||||
}
|
}
|
||||||
|
@ -2489,7 +2481,7 @@ public class BoardDelegate extends DelegateBase
|
||||||
if ( BuildConstants.CHAT_SUPPORTED && null != m_jniThread ) {
|
if ( BuildConstants.CHAT_SUPPORTED && null != m_jniThread ) {
|
||||||
Iterator<String> iter = m_pendingChats.iterator();
|
Iterator<String> iter = m_pendingChats.iterator();
|
||||||
while ( iter.hasNext() ) {
|
while ( iter.hasNext() ) {
|
||||||
m_jniThread.handle( JNICmd.CMD_SENDCHAT, iter.next() );
|
handleViaThread( JNICmd.CMD_SENDCHAT, iter.next() );
|
||||||
}
|
}
|
||||||
m_pendingChats.clear();
|
m_pendingChats.clear();
|
||||||
}
|
}
|
||||||
|
@ -2622,7 +2614,8 @@ public class BoardDelegate extends DelegateBase
|
||||||
if ( canPost ) {
|
if ( canPost ) {
|
||||||
m_handler.post( runnable );
|
m_handler.post( runnable );
|
||||||
} else {
|
} else {
|
||||||
DbgUtils.logf( "post: dropping because handler null" );
|
DbgUtils.logf( "BoardDelegate.post(): dropping b/c handler null" );
|
||||||
|
DbgUtils.printStack();
|
||||||
}
|
}
|
||||||
return canPost;
|
return canPost;
|
||||||
}
|
}
|
||||||
|
@ -2844,10 +2837,13 @@ public class BoardDelegate extends DelegateBase
|
||||||
DBUtils.recordInviteSent( m_activity, m_rowid, means, dev );
|
DBUtils.recordInviteSent( m_activity, m_rowid, means, dev );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void noteSkip()
|
private void handleViaThread( JNICmd cmd, Object... args )
|
||||||
{
|
{
|
||||||
String msg = "BoardActivity.feedMessage[s](): skipped because "
|
if ( null == m_jniThread ) {
|
||||||
+ "too many open Boards";
|
DbgUtils.logf( "BoardDelegate: not calling handle(%s)", cmd.toString() );
|
||||||
DbgUtils.logf(msg );
|
DbgUtils.printStack();
|
||||||
|
} else {
|
||||||
|
m_jniThread.handle( cmd, args );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} // class BoardDelegate
|
} // class BoardDelegate
|
||||||
|
|
Loading…
Reference in a new issue