From 03f532374be65a7615cc61cccdabebae23a68e96 Mon Sep 17 00:00:00 2001 From: Eric House Date: Mon, 18 Nov 2013 06:27:24 -0800 Subject: [PATCH] put up NFC button even if turned off, and when it's used offer to turn it on. --- .../android/XWords4/res/values/strings.xml | 4 +++ .../eehouse/android/xw4/BoardActivity.java | 28 +++++++++++++++++-- .../org/eehouse/android/xw4/DlgDelegate.java | 4 +-- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/xwords4/android/XWords4/res/values/strings.xml b/xwords4/android/XWords4/res/values/strings.xml index b3c020f4c..01c15916f 100644 --- a/xwords4/android/XWords4/res/values/strings.xml +++ b/xwords4/android/XWords4/res/values/strings.xml @@ -2176,4 +2176,8 @@ Invitation ignored: already used %1$s (yours) Invite + + NFC is turned off on this device. Use + the Android Settings app to turn it on . + Launch Settings 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 a716a6f63..f57e5504e 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java @@ -86,6 +86,7 @@ public class BoardActivity extends XWActivity private static final int DLG_GETDICT = DLG_OKONLY + 13; private static final int GAME_OVER = DLG_OKONLY + 14; private static final int DLG_CONNSTAT = DLG_OKONLY + 15; + private static final int ENABLE_NFC = DLG_OKONLY + 16; private static final int CHAT_REQUEST = 1; private static final int BT_INVITE_RESULT = 2; @@ -512,6 +513,22 @@ public class BoardActivity extends XWActivity } break; + case ENABLE_NFC: + lstnr = new DialogInterface.OnClickListener() { + public void onClick( DialogInterface dialog, + int item ) { + startActivity( new Intent("android.settings" + + ".NFC_SETTINGS" ) ); + } + }; + dialog = new AlertDialog.Builder( this ) + .setTitle( R.string.info_title ) + .setMessage( R.string.enable_nfc ) + .setPositiveButton( R.string.button_cancel, null ) + .setNegativeButton( R.string.button_go_settings, lstnr ) + .create(); + break; + default: // just drop it; super.onCreateDialog likely failed break; @@ -918,9 +935,14 @@ public class BoardActivity extends XWActivity { if ( LAUNCH_INVITE_ACTION == id ) { if ( DlgDelegate.DISMISS_BUTTON != which ) { - GameUtils.launchInviteActivity( this, which, - m_room, null, m_gi.dictLang, - m_gi.dictName, m_gi.nPlayers ); + if ( DlgDelegate.NFC_BTN == which + && !NFCUtils.nfcAvail( this )[1] ) { + showDialog( ENABLE_NFC ); + } else { + GameUtils.launchInviteActivity( this, which, + m_room, null, m_gi.dictLang, + m_gi.dictName, m_gi.nPlayers ); + } } } else if ( AlertDialog.BUTTON_POSITIVE == which ) { JNICmd cmd = JNICmd.CMD_NONE; diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java index 43368f20a..d3381f765 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java @@ -229,7 +229,7 @@ public class DlgDelegate { public void showInviteChoicesThen( final int callbackID ) { if ( Utils.deviceSupportsSMS( m_activity ) - || NFCUtils.nfcAvail( m_activity )[1] ) { + || NFCUtils.nfcAvail( m_activity )[0] ) { DlgState state = new DlgState( INVITE_CHOICES_THEN, callbackID ); addState( state ); m_activity.showDialog( INVITE_CHOICES_THEN ); @@ -415,7 +415,7 @@ public class DlgDelegate { OnClickListener lstnr = mkCallbackClickListener( state ); boolean haveSMS = Utils.deviceSupportsSMS( m_activity ); - boolean haveNFC = NFCUtils.nfcAvail( m_activity )[1]; + boolean haveNFC = NFCUtils.nfcAvail( m_activity )[0]; int msgID; if ( haveSMS && haveNFC ) { msgID = R.string.nfc_or_sms_or_email;