mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-07 05:24:46 +01:00
return whether NFC *can* be enabled as well as whether it is
This commit is contained in:
parent
e701af7262
commit
3278b55819
2 changed files with 24 additions and 10 deletions
|
@ -229,7 +229,7 @@ public class DlgDelegate {
|
|||
public void showInviteChoicesThen( final int callbackID )
|
||||
{
|
||||
if ( Utils.deviceSupportsSMS( m_activity )
|
||||
|| NFCUtils.nfcAvail( m_activity ) ) {
|
||||
|| NFCUtils.nfcAvail( m_activity )[1] ) {
|
||||
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 );
|
||||
boolean haveNFC = NFCUtils.nfcAvail( m_activity )[1];
|
||||
int msgID;
|
||||
if ( haveSMS && haveNFC ) {
|
||||
msgID = R.string.nfc_or_sms_or_email;
|
||||
|
|
|
@ -39,6 +39,7 @@ public class NFCUtils {
|
|||
}
|
||||
|
||||
private static boolean s_inSDK;
|
||||
private static boolean[] s_nfcAvail;
|
||||
private static SafeNFC s_safeNFC;
|
||||
static {
|
||||
s_inSDK = 14 <= Integer.valueOf( android.os.Build.VERSION.SDK );
|
||||
|
@ -75,16 +76,21 @@ public class NFCUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static boolean nfcAvail( Context context )
|
||||
// Return array of two booleans, the first indicating whether the
|
||||
// device supports NFC and the second whether it's on. Only the
|
||||
// second can change.
|
||||
public static boolean[] nfcAvail( Context context )
|
||||
{
|
||||
boolean result = s_inSDK;
|
||||
if ( result ) {
|
||||
NfcManager manager =
|
||||
(NfcManager)context.getSystemService( Context.NFC_SERVICE );
|
||||
NfcAdapter adapter = manager.getDefaultAdapter();
|
||||
result = null != adapter && adapter.isEnabled();
|
||||
if ( null == s_nfcAvail ) {
|
||||
s_nfcAvail = new boolean[] {
|
||||
s_inSDK && null != getNFCAdapter( context ),
|
||||
false
|
||||
};
|
||||
}
|
||||
return result;
|
||||
if ( s_nfcAvail[0] ) {
|
||||
s_nfcAvail[1] = getNFCAdapter( context ).isEnabled();
|
||||
}
|
||||
return s_nfcAvail;
|
||||
}
|
||||
|
||||
public static String getFromIntent( Intent intent )
|
||||
|
@ -122,4 +128,12 @@ public class NFCUtils {
|
|||
});
|
||||
return msg;
|
||||
}
|
||||
|
||||
private static NfcAdapter getNFCAdapter( Context context )
|
||||
{
|
||||
NfcManager manager =
|
||||
(NfcManager)context.getSystemService( Context.NFC_SERVICE );
|
||||
return manager.getDefaultAdapter();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue