always have board ready to send invite via NFC

This commit is contained in:
Eric House 2013-11-16 09:02:52 -08:00
parent deff81cfd1
commit 0bf28c133d
3 changed files with 30 additions and 13 deletions

View file

@ -65,7 +65,8 @@ import org.eehouse.android.xw4.jni.JNIThread.*;
public class BoardActivity extends XWActivity
implements TransportProcs.TPMsgHandler, View.OnClickListener,
DictImportActivity.DownloadFinishedListener,
ConnStatusHandler.ConnStatusCBacks {
ConnStatusHandler.ConnStatusCBacks,
NFCUtils.NFCActor {
public static final String INTENT_KEY_CHAT = "chat";
@ -1158,6 +1159,22 @@ public class BoardActivity extends XWActivity
}
}
//////////////////////////////////////////////////
// NFCUtils.NFCActor
//////////////////////////////////////////////////
public String makeNFCMessage()
{
String data = null;
if ( 0 < m_missing ) { // Isn't there a better test??
String inviteID = GameUtils.makeRandomID();
data = NetLaunchInfo.makeLaunchJSON( this, m_room, inviteID,
m_gi.dictLang,
m_gi.dictName, m_gi.nPlayers );
}
return data;
}
//////////////////////////////////////////////////
// ConnStatusHandler.ConnStatusCBacks
//////////////////////////////////////////////////

View file

@ -536,7 +536,6 @@ public class GameUtils {
if ( null != msgString ) {
if ( DlgDelegate.NFC_BTN == chosen ) {
NFCUtils.buildAndPush( activity, msgString );
Utils.showToast( activity, "Tap the receiving device now" );
} else {
boolean choseEmail = DlgDelegate.EMAIL_BTN == chosen;

View file

@ -30,7 +30,14 @@ import android.nfc.NfcEvent;
import android.nfc.NfcManager;
import android.os.Parcelable;
import junit.framework.Assert;
public class NFCUtils {
public interface NFCActor {
String makeNFCMessage();
}
private static boolean s_inSDK;
private static SafeNFC s_safeNFC;
static {
@ -39,7 +46,6 @@ public class NFCUtils {
s_safeNFC = new SafeNFCImpl();
}
}
private static String s_data = null;
private static interface SafeNFC {
public void register( Activity activity );
@ -48,12 +54,15 @@ public class NFCUtils {
private static class SafeNFCImpl implements SafeNFC {
public void register( final Activity activity )
{
Assert.assertTrue( activity instanceof NFCActor );
final NFCActor actor = (NFCActor)activity;
NfcAdapter.CreateNdefMessageCallback cb =
new NfcAdapter.CreateNdefMessageCallback() {
public NdefMessage createNdefMessage( NfcEvent event ) {
NdefMessage msg = null;
if ( null != s_data ) {
msg = makeMessage( activity, s_data );
String data = actor.makeNFCMessage();
if ( null != data ) {
msg = makeMessage( activity, data );
}
return msg;
}
@ -78,14 +87,6 @@ public class NFCUtils {
return result;
}
public static void buildAndPush( Activity activity, String data )
{
s_data = data;
// NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter( activity );
// NdefMessage msg = makeMessage( activity, data );
// nfcAdapter.setNdefPushMessage( msg, activity );
}
public static String getFromIntent( Intent intent )
{
String result = null;