mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-28 09:58:30 +01:00
move bteventhandler implementation up into XWActivity so subclasses
can easily listen for one or two events. Have Board listen to events for un/successful message sends and up up icon to indicate if BT is working.
This commit is contained in:
parent
00a0ecb1b8
commit
82586668f9
4 changed files with 60 additions and 20 deletions
|
@ -200,8 +200,8 @@ public class BoardActivity extends XWActivity
|
|||
public void run() {
|
||||
m_timers[m_why] = null;
|
||||
if ( null != m_jniThread ) {
|
||||
m_jniThread.handle( JNICmd.CMD_TIMER_FIRED, false,
|
||||
m_why, m_when, m_handle );
|
||||
m_jniThread.handleBkgrnd( JNICmd.CMD_TIMER_FIRED,
|
||||
m_why, m_when, m_handle );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -788,6 +788,25 @@ public class BoardActivity extends XWActivity
|
|||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// BTService.BTEventListener interface
|
||||
//////////////////////////////////////////////////
|
||||
@Override
|
||||
public void eventOccurred( BTService.BTEvent event, final Object ... args )
|
||||
{
|
||||
switch( event ) {
|
||||
case MESSAGE_ACCEPTED:
|
||||
m_jniThread.handle( JNICmd.CMD_DRAW_BT_STATUS, true );
|
||||
break;
|
||||
case MESSAGE_REFUSED:
|
||||
m_jniThread.handle( JNICmd.CMD_DRAW_BT_STATUS, false );
|
||||
break;
|
||||
default:
|
||||
super.eventOccurred( event, args );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// TransportProcs.TPMsgHandler interface
|
||||
//////////////////////////////////////////////////
|
||||
|
@ -998,7 +1017,7 @@ public class BoardActivity extends XWActivity
|
|||
post( new Runnable() {
|
||||
public void run() {
|
||||
if ( null != m_jniThread ) {
|
||||
m_jniThread.handle( JNIThread.JNICmd.CMD_DO, false );
|
||||
m_jniThread.handleBkgrnd( JNIThread.JNICmd.CMD_DO );
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
@ -1361,7 +1380,9 @@ public class BoardActivity extends XWActivity
|
|||
|
||||
m_jniGamePtr = XwJNI.initJNI();
|
||||
|
||||
if ( m_gi.serverRole != DeviceRole.SERVER_STANDALONE ) {
|
||||
boolean standalone =
|
||||
m_gi.serverRole == DeviceRole.SERVER_STANDALONE;
|
||||
if ( !standalone ) {
|
||||
m_xport = new CommsTransport( m_jniGamePtr, this, this,
|
||||
m_gi.serverRole );
|
||||
}
|
||||
|
@ -1443,7 +1464,10 @@ public class BoardActivity extends XWActivity
|
|||
DBUtils.setMsgFlags( m_rowid, GameSummary.MSG_FLAGS_NONE );
|
||||
}
|
||||
|
||||
trySendChats();
|
||||
if ( !standalone ) {
|
||||
trySendChats();
|
||||
m_jniThread.handle( JNIThread.JNICmd.CMD_RESEND );
|
||||
}
|
||||
}
|
||||
}
|
||||
} // loadGame
|
||||
|
|
|
@ -44,8 +44,7 @@ import org.eehouse.android.xw4.jni.CommsAddrRec;
|
|||
import org.eehouse.android.xw4.jni.XwJNI;
|
||||
|
||||
|
||||
public class NewGameActivity extends XWActivity
|
||||
implements BTService.BTEventListener {
|
||||
public class NewGameActivity extends XWActivity {
|
||||
|
||||
private static final int NEW_GAME_ACTION = 1;
|
||||
private static final String SAVE_DEVNAMES = "DEVNAMES";
|
||||
|
@ -202,13 +201,6 @@ public class NewGameActivity extends XWActivity
|
|||
protected void onResume() {
|
||||
super.onResume();
|
||||
checkEnableBT( false );
|
||||
BTService.setBTEventListener( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
BTService.setBTEventListener( null );
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -226,6 +218,7 @@ public class NewGameActivity extends XWActivity
|
|||
}
|
||||
|
||||
// BTService.BTEventListener interface
|
||||
@Override
|
||||
public void eventOccurred( BTService.BTEvent event, final Object ... args )
|
||||
{
|
||||
switch( event ) {
|
||||
|
@ -271,7 +264,6 @@ public class NewGameActivity extends XWActivity
|
|||
break;
|
||||
default:
|
||||
DbgUtils.logf( "unexpected event %s", event.toString() );
|
||||
Assert.fail();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ import android.os.Bundle;
|
|||
import org.eehouse.android.xw4.jni.CommonPrefs;
|
||||
|
||||
public class XWActivity extends Activity
|
||||
implements DlgDelegate.DlgClickNotify {
|
||||
implements DlgDelegate.DlgClickNotify, BTService.BTEventListener {
|
||||
|
||||
private DlgDelegate m_delegate;
|
||||
|
||||
|
@ -57,6 +57,7 @@ public class XWActivity extends Activity
|
|||
protected void onResume()
|
||||
{
|
||||
DbgUtils.logf( "%s.onResume(this=%H)", getClass().getName(), this );
|
||||
BTService.setBTEventListener( this );
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
|
@ -64,6 +65,7 @@ public class XWActivity extends Activity
|
|||
protected void onPause()
|
||||
{
|
||||
DbgUtils.logf( "%s.onPause(this=%H)", getClass().getName(), this );
|
||||
BTService.setBTEventListener( null );
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
|
@ -172,4 +174,10 @@ public class XWActivity extends Activity
|
|||
Assert.fail();
|
||||
}
|
||||
|
||||
// BTService.BTEventListener interface
|
||||
public void eventOccurred( BTService.BTEvent event, final Object ... args )
|
||||
{
|
||||
DbgUtils.logf( "eventOccurred: unhandled event %s", event.toString() );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* -*- compile-command: "cd ../../../../../../; ant debug install"; -*- */
|
||||
/*
|
||||
* Copyright 2009-2010 by Eric House (xwords@eehouse.org). All
|
||||
* Copyright 2009 - 2012 by Eric House (xwords@eehouse.org). All
|
||||
* rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
|
@ -37,6 +37,7 @@ import org.eehouse.android.xw4.GameUtils;
|
|||
import org.eehouse.android.xw4.DBUtils;
|
||||
import org.eehouse.android.xw4.Toolbar;
|
||||
import org.eehouse.android.xw4.jni.CurGameInfo.DeviceRole;
|
||||
import junit.framework.Assert;
|
||||
|
||||
public class JNIThread extends Thread {
|
||||
|
||||
|
@ -81,6 +82,7 @@ public class JNIThread extends Thread {
|
|||
CMD_POST_OVER,
|
||||
CMD_SENDCHAT,
|
||||
CMD_DRAW_CONNS_STATUS,
|
||||
CMD_DRAW_BT_STATUS,
|
||||
};
|
||||
|
||||
public static final int RUNNING = 1;
|
||||
|
@ -532,6 +534,13 @@ public class JNIThread extends Thread {
|
|||
m_connsIconID = newID;
|
||||
}
|
||||
break;
|
||||
|
||||
case CMD_DRAW_BT_STATUS:
|
||||
boolean btWorking = ((Boolean)args[0]).booleanValue();
|
||||
m_connsIconID = btWorking ? R.drawable.bluetooth_active
|
||||
: R.drawable.bluetooth_disabled;
|
||||
draw = true;
|
||||
break;
|
||||
|
||||
case CMD_TIMER_FIRED:
|
||||
draw = XwJNI.timerFired( m_jniGamePtr,
|
||||
|
@ -539,6 +548,12 @@ public class JNIThread extends Thread {
|
|||
((Integer)args[1]).intValue(),
|
||||
((Integer)args[2]).intValue() );
|
||||
break;
|
||||
|
||||
case CMD_NONE: // ignored
|
||||
break;
|
||||
default:
|
||||
DbgUtils.logf( "dropping cmd: %s", elem.m_cmd.toString() );
|
||||
Assert.fail();
|
||||
}
|
||||
|
||||
if ( draw ) {
|
||||
|
@ -563,16 +578,17 @@ public class JNIThread extends Thread {
|
|||
}
|
||||
} // run
|
||||
|
||||
public void handle( JNICmd cmd, boolean isUI, Object... args )
|
||||
public void handleBkgrnd( JNICmd cmd, Object... args )
|
||||
{
|
||||
QueueElem elem = new QueueElem( cmd, isUI, args );
|
||||
QueueElem elem = new QueueElem( cmd, false, args );
|
||||
// DbgUtils.logf( "adding: %s", cmd.toString() );
|
||||
m_queue.add( elem );
|
||||
}
|
||||
|
||||
public void handle( JNICmd cmd, Object... args )
|
||||
{
|
||||
handle( cmd, true, args );
|
||||
QueueElem elem = new QueueElem( cmd, true, args );
|
||||
m_queue.add( elem );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue