From 0bf28c133d6875499394b418b90dc53230b09444 Mon Sep 17 00:00:00 2001 From: Eric House Date: Sat, 16 Nov 2013 09:02:52 -0800 Subject: [PATCH] always have board ready to send invite via NFC --- .../eehouse/android/xw4/BoardActivity.java | 19 ++++++++++++++- .../org/eehouse/android/xw4/GameUtils.java | 1 - .../src/org/eehouse/android/xw4/NFCUtils.java | 23 ++++++++++--------- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java index ed9b69066..cdf380240 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java @@ -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 ////////////////////////////////////////////////// diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java index d8373ccb9..4fe31f9f0 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java @@ -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; diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NFCUtils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NFCUtils.java index 8ff5f9c4a..54be61c25 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NFCUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NFCUtils.java @@ -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;