mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-29 08:34:37 +01:00
Put up Toast messages on connecting to relay.
This commit is contained in:
parent
7d385e180a
commit
885c9093fb
3 changed files with 75 additions and 15 deletions
|
@ -82,13 +82,28 @@ and_xport_send( const XP_U8* buf, XP_U16 len, const CommsAddrRec* addr,
|
|||
static void
|
||||
and_xport_relayStatus( void* closure, CommsRelayState newState )
|
||||
{
|
||||
LOG_FUNC();
|
||||
AndTransportProcs* aprocs = (AndTransportProcs*)closure;
|
||||
if ( NULL != aprocs->jxport ) {
|
||||
JNIEnv* env = *aprocs->envp;
|
||||
const char* sig = "(I)V";
|
||||
jmethodID mid = getMethodID( env, aprocs->jxport, "relayStatus", sig );
|
||||
|
||||
(*env)->CallVoidMethod( env, aprocs->jxport, mid, newState );
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
and_xport_relayConnd( void* closure, XP_Bool allHere, XP_U16 nMissing )
|
||||
{
|
||||
LOG_FUNC();
|
||||
AndTransportProcs* aprocs = (AndTransportProcs*)closure;
|
||||
if ( NULL != aprocs->jxport ) {
|
||||
JNIEnv* env = *aprocs->envp;
|
||||
const char* sig = "(ZI)V";
|
||||
jmethodID mid = getMethodID( env, aprocs->jxport, "relayConnd", sig );
|
||||
|
||||
(*env)->CallVoidMethod( env, aprocs->jxport, mid,
|
||||
allHere, nMissing );
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -21,6 +21,7 @@ import android.app.Dialog;
|
|||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.res.Resources;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.eehouse.android.xw4.jni.*;
|
||||
import org.eehouse.android.xw4.jni.JNIThread.*;
|
||||
|
@ -138,7 +139,24 @@ public class BoardActivity extends Activity implements UtilCtxt {
|
|||
m_jniGamePtr = XwJNI.initJNI();
|
||||
|
||||
if ( m_gi.serverRole != DeviceRole.SERVER_STANDALONE ) {
|
||||
m_xport = new CommsTransport( m_jniGamePtr, this );
|
||||
Handler handler = new Handler() {
|
||||
public void handleMessage( Message msg ) {
|
||||
switch( msg.what ) {
|
||||
case CommsTransport.DIALOG:
|
||||
m_dlgBytes = (String)msg.obj;
|
||||
m_dlgTitle = msg.arg1;
|
||||
showDialog( DLG_OKONLY );
|
||||
break;
|
||||
case CommsTransport.TOAST:
|
||||
Toast.makeText( BoardActivity.this,
|
||||
(CharSequence)(msg.obj),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
m_xport = new CommsTransport( m_jniGamePtr, this, handler,
|
||||
m_gi.serverRole );
|
||||
}
|
||||
|
||||
if ( null == stream ||
|
||||
|
|
|
@ -16,18 +16,26 @@ import android.telephony.SmsManager;
|
|||
import android.content.Intent;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
|
||||
import org.eehouse.android.xw4.jni.*;
|
||||
import org.eehouse.android.xw4.jni.JNIThread.*;
|
||||
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
|
||||
import org.eehouse.android.xw4.jni.CurGameInfo.DeviceRole;
|
||||
|
||||
public class CommsTransport extends Thread implements TransportProcs {
|
||||
|
||||
public static final int DIALOG = 0;
|
||||
public static final int TOAST = 1;
|
||||
|
||||
private Selector m_selector;
|
||||
private SocketChannel m_socketChannel;
|
||||
private int m_jniGamePtr;
|
||||
private boolean m_running = false;
|
||||
private CommsAddrRec m_addr;
|
||||
private JNIThread m_jniThread;
|
||||
private Handler m_handler;
|
||||
private boolean m_done = false;
|
||||
|
||||
private Vector<ByteBuffer> m_buffersOut;
|
||||
|
@ -35,16 +43,19 @@ public class CommsTransport extends Thread implements TransportProcs {
|
|||
private ByteBuffer m_bytesIn;
|
||||
|
||||
private Context m_context;
|
||||
|
||||
private DeviceRole m_role;
|
||||
|
||||
// assembling inbound packet
|
||||
private byte[] m_packetIn;
|
||||
private int m_haveLen = -1;
|
||||
|
||||
public CommsTransport( int jniGamePtr, Context context )
|
||||
public CommsTransport( int jniGamePtr, Context context, Handler handler,
|
||||
DeviceRole role )
|
||||
{
|
||||
m_jniGamePtr = jniGamePtr;
|
||||
m_context = context;
|
||||
m_handler = handler;
|
||||
m_role = role;
|
||||
m_buffersOut = new Vector<ByteBuffer>();
|
||||
m_bytesIn = ByteBuffer.allocate( 2048 );
|
||||
}
|
||||
|
@ -248,21 +259,26 @@ public class CommsTransport extends Thread implements TransportProcs {
|
|||
nSent = buf.length;
|
||||
break;
|
||||
case COMMS_CONN_SMS:
|
||||
Utils.logf( "sending via sms to " + m_addr.sms_phone + ":127" );
|
||||
Utils.logf( "sending via sms to " + m_addr.sms_phone
|
||||
+ m_addr.sms_port );
|
||||
|
||||
try {
|
||||
Intent intent = new Intent( m_context, StatusReceiver.class);
|
||||
PendingIntent pi
|
||||
= PendingIntent.getBroadcast( m_context, 0,
|
||||
intent, 0 );
|
||||
// SmsManager.getDefault().sendTextMessage( m_addr.sms_phone,
|
||||
// null, "Hello world",
|
||||
// pi, pi );
|
||||
SmsManager.getDefault().sendDataMessage( m_addr.sms_phone,
|
||||
(String)null, (short)127,
|
||||
//(short)m_addr.sms_port,
|
||||
buf, pi, pi );
|
||||
Utils.logf( "called sendDataMessage" );
|
||||
if ( 0 == m_addr.sms_port ) {
|
||||
SmsManager.getDefault().sendTextMessage( m_addr.sms_phone,
|
||||
null, "Hello world",
|
||||
pi, pi );
|
||||
Utils.logf( "called sendTextMessage" );
|
||||
} else {
|
||||
SmsManager.getDefault().
|
||||
sendDataMessage( m_addr.sms_phone, (String)null,
|
||||
(short)m_addr.sms_port,
|
||||
buf, pi, pi );
|
||||
Utils.logf( "called sendDataMessage" );
|
||||
}
|
||||
nSent = buf.length;
|
||||
} catch ( java.lang.IllegalArgumentException iae ) {
|
||||
Utils.logf( iae.toString() );
|
||||
|
@ -277,14 +293,25 @@ public class CommsTransport extends Thread implements TransportProcs {
|
|||
|
||||
public void relayStatus( int newState )
|
||||
{
|
||||
Utils.logf( "relayStatus called" );
|
||||
}
|
||||
|
||||
public void relayConnd( boolean allHere, int nMissing )
|
||||
{
|
||||
String message = null;
|
||||
if ( allHere ) {
|
||||
message = m_context.getString( R.string.msg_relay_all_here );
|
||||
} else if ( nMissing > 0 ) {
|
||||
String fmt = m_context.getString( R.string.msg_relay_waiting );
|
||||
message = String.format( fmt, nMissing );
|
||||
}
|
||||
if ( null != message ) {
|
||||
Message.obtain( m_handler, TOAST, message ).sendToTarget();
|
||||
}
|
||||
}
|
||||
|
||||
public void relayErrorProc( XWRELAY_ERROR relayErr )
|
||||
{
|
||||
Utils.logf( "relayErrorProc called" );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue