as a DEBUG-only feature, enable "send" of NFC to self to better

duplicate on a single device how real devices are meant to be
inviting.
This commit is contained in:
Eric House 2015-02-04 22:15:20 -08:00
parent 019d9987c7
commit c2a87c187d
6 changed files with 623 additions and 595 deletions

File diff suppressed because it is too large Load diff

View file

@ -167,6 +167,8 @@
<string name="xlations_locale">Fake locale for translation</string>
<string name="enable_dupes_summary">Accept invitations more than once</string>
<string name="nag_intervals">Reminder intervals (minutes1,minutes2,...)</string>
<string name="nfc_to_self">Send via NFC to self?</string>
<!--string name="dict_url">http://10.0.2.2/~eehouse/and_dicts</string-->
<string-array name="board_sizes">

View file

@ -984,6 +984,9 @@ public class BoardDelegate extends DelegateBase
case LOOKUP_ACTION:
launchLookup( m_words, m_gi.dictLang );
break;
case NFC_TO_SELF:
GamesListDelegate.sendNFCToSelf( m_activity, makeNFCMessage() );
break;
default:
Assert.fail();
}
@ -1000,7 +1003,9 @@ public class BoardDelegate extends DelegateBase
if ( action == Action.LAUNCH_INVITE_ACTION ) {
switch( means ) {
case NFC:
if ( ! NFCUtils.nfcAvail( m_activity )[1] ) {
if ( BuildConfig.DEBUG ) {
showConfirmThen( R.string.nfc_to_self, Action.NFC_TO_SELF );
} else if ( ! NFCUtils.nfcAvail( m_activity )[1] ) {
showDialog( DlgID.ENABLE_NFC );
} else {
showOKOnlyDialog( R.string.nfc_just_tap );

View file

@ -77,6 +77,7 @@ public class DlgDelegate {
VALUES_ACTION,
SMS_CONFIG_ACTION,
BUTTON_BROWSEALL_ACTION,
NFC_TO_SELF,
// Dict Browser
FINISH_ACTION,
@ -345,7 +346,7 @@ public class DlgDelegate {
public void showInviteChoicesThen( final Action action )
{
if ( (XWApp.SMS_INVITE_ENABLED && Utils.deviceSupportsSMS( m_activity ))
|| NFCUtils.nfcAvail( m_activity )[0]
|| (BuildConfig.DEBUG || NFCUtils.nfcAvail( m_activity )[0])
|| BTService.BTAvailable() ) {
DlgState state = new DlgState( DlgID.INVITE_CHOICES_THEN, action );
addState( state );
@ -571,7 +572,7 @@ public class DlgDelegate {
items.add( getString( R.string.invite_choice_bt ) );
means.add( DlgClickNotify.InviteMeans.BLUETOOTH );
}
if ( NFCUtils.nfcAvail( m_activity )[0] ) {
if ( BuildConfig.DEBUG || NFCUtils.nfcAvail( m_activity )[0] ) {
items.add( getString( R.string.invite_choice_nfc ) );
means.add( DlgClickNotify.InviteMeans.NFC );
}

View file

@ -2163,6 +2163,13 @@ public class GamesListDelegate extends ListDelegateBase
return intent;
}
public static void sendNFCToSelf( Context context, String data )
{
Intent intent = makeSelfIntent( context );
NFCUtils.populateIntent( intent, data );
context.startActivity( intent );
}
public static void openGame( Context context, Uri data )
{
Intent intent = makeSelfIntent( context );

View file

@ -40,6 +40,9 @@ import org.eehouse.android.xw4.loc.LocUtils;
public class NFCUtils {
private static final String NFC_TO_SELF_ACTION = "nfc_tsa";
private static final String NFC_TO_SELF_DATA = "nfc_data";
public interface NFCActor {
String makeNFCMessage();
}
@ -105,18 +108,27 @@ public class NFCUtils {
{
String result = null;
if ( NfcAdapter.ACTION_NDEF_DISCOVERED.equals( intent.getAction() ) ) {
String action = intent.getAction();
if ( NfcAdapter.ACTION_NDEF_DISCOVERED.equals( action ) ) {
Parcelable[] rawMsgs =
intent.getParcelableArrayExtra( NfcAdapter.EXTRA_NDEF_MESSAGES );
// only one message sent during the beam
NdefMessage msg = (NdefMessage)rawMsgs[0];
// record 0 contains the MIME type, record 1 is the AAR, if present
result = new String( msg.getRecords()[0].getPayload() );
} else if ( BuildConfig.DEBUG && NFC_TO_SELF_ACTION.equals( action ) ) {
result = intent.getStringExtra( NFC_TO_SELF_DATA );
}
return result;
}
public static void populateIntent( Intent intent, String data )
{
intent.setAction( NFC_TO_SELF_ACTION );
intent.putExtra( NFC_TO_SELF_DATA, data );
}
public static void register( Activity activity, NFCActor actor )
{
if ( null != s_safeNFC ) {