mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-08 05:24:39 +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 )
|
public void showInviteChoicesThen( final int callbackID )
|
||||||
{
|
{
|
||||||
if ( Utils.deviceSupportsSMS( m_activity )
|
if ( Utils.deviceSupportsSMS( m_activity )
|
||||||
|| NFCUtils.nfcAvail( m_activity ) ) {
|
|| NFCUtils.nfcAvail( m_activity )[1] ) {
|
||||||
DlgState state = new DlgState( INVITE_CHOICES_THEN, callbackID );
|
DlgState state = new DlgState( INVITE_CHOICES_THEN, callbackID );
|
||||||
addState( state );
|
addState( state );
|
||||||
m_activity.showDialog( INVITE_CHOICES_THEN );
|
m_activity.showDialog( INVITE_CHOICES_THEN );
|
||||||
|
@ -415,7 +415,7 @@ public class DlgDelegate {
|
||||||
OnClickListener lstnr = mkCallbackClickListener( state );
|
OnClickListener lstnr = mkCallbackClickListener( state );
|
||||||
|
|
||||||
boolean haveSMS = Utils.deviceSupportsSMS( m_activity );
|
boolean haveSMS = Utils.deviceSupportsSMS( m_activity );
|
||||||
boolean haveNFC = NFCUtils.nfcAvail( m_activity );
|
boolean haveNFC = NFCUtils.nfcAvail( m_activity )[1];
|
||||||
int msgID;
|
int msgID;
|
||||||
if ( haveSMS && haveNFC ) {
|
if ( haveSMS && haveNFC ) {
|
||||||
msgID = R.string.nfc_or_sms_or_email;
|
msgID = R.string.nfc_or_sms_or_email;
|
||||||
|
|
|
@ -39,6 +39,7 @@ public class NFCUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean s_inSDK;
|
private static boolean s_inSDK;
|
||||||
|
private static boolean[] s_nfcAvail;
|
||||||
private static SafeNFC s_safeNFC;
|
private static SafeNFC s_safeNFC;
|
||||||
static {
|
static {
|
||||||
s_inSDK = 14 <= Integer.valueOf( android.os.Build.VERSION.SDK );
|
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 ( null == s_nfcAvail ) {
|
||||||
if ( result ) {
|
s_nfcAvail = new boolean[] {
|
||||||
NfcManager manager =
|
s_inSDK && null != getNFCAdapter( context ),
|
||||||
(NfcManager)context.getSystemService( Context.NFC_SERVICE );
|
false
|
||||||
NfcAdapter adapter = manager.getDefaultAdapter();
|
};
|
||||||
result = null != adapter && adapter.isEnabled();
|
|
||||||
}
|
}
|
||||||
return result;
|
if ( s_nfcAvail[0] ) {
|
||||||
|
s_nfcAvail[1] = getNFCAdapter( context ).isEnabled();
|
||||||
|
}
|
||||||
|
return s_nfcAvail;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getFromIntent( Intent intent )
|
public static String getFromIntent( Intent intent )
|
||||||
|
@ -122,4 +128,12 @@ public class NFCUtils {
|
||||||
});
|
});
|
||||||
return msg;
|
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