From 54d78491915e2fce2dd19fcd158e6fd51baecf7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Mon, 10 Mar 2014 18:30:42 +0100 Subject: [PATCH] Get rid of lint TargetApi warnings --- .../fdroid/fdroid/NfcNotEnabledActivity.java | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/org/fdroid/fdroid/NfcNotEnabledActivity.java b/src/org/fdroid/fdroid/NfcNotEnabledActivity.java index 711a17f97..793949cc7 100644 --- a/src/org/fdroid/fdroid/NfcNotEnabledActivity.java +++ b/src/org/fdroid/fdroid/NfcNotEnabledActivity.java @@ -9,29 +9,38 @@ import android.os.Build; import android.os.Bundle; import android.provider.Settings; -@TargetApi(14) // aka Android 4.0 aka Ice Cream Sandwich public class NfcNotEnabledActivity extends Activity { + /* + * ACTION_NFC_SETTINGS was added in 4.1 aka Jelly Bean MR1 as a + * separate thing from ACTION_NFCSHARING_SETTINGS. It is now + * possible to have NFC enabled, but not "Android Beam", which is + * needed for NDEF. Therefore, we detect the current state of NFC, + * and steer the user accordingly. + */ + @TargetApi(14) + private void doOnJellybean(Intent intent) { + if (NfcAdapter.getDefaultAdapter(this).isEnabled()) + intent.setAction(Settings.ACTION_NFCSHARING_SETTINGS); + else + intent.setAction(Settings.ACTION_NFC_SETTINGS); + } + + // this API was added in 4.0 aka Ice Cream Sandwich + @TargetApi(16) + private void doOnIceCreamSandwich(Intent intent) { + intent.setAction(Settings.ACTION_NFCSHARING_SETTINGS); + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Intent intent = new Intent(); if (Build.VERSION.SDK_INT >= 16) { - /* - * ACTION_NFC_SETTINGS was added in 4.1 aka Jelly Bean MR1 as a - * separate thing from ACTION_NFCSHARING_SETTINGS. It is now - * possible to have NFC enabled, but not "Android Beam", which is - * needed for NDEF. Therefore, we detect the current state of NFC, - * and steer the user accordingly. - */ - if (NfcAdapter.getDefaultAdapter(this).isEnabled()) - intent.setAction(Settings.ACTION_NFCSHARING_SETTINGS); - else - intent.setAction(Settings.ACTION_NFC_SETTINGS); + doOnJellybean(intent); } else if (Build.VERSION.SDK_INT >= 14) { - // this API was added in 4.0 aka Ice Cream Sandwich - intent.setAction(Settings.ACTION_NFCSHARING_SETTINGS); + doOnIceCreamSandwich(intent); } else { // no NFC support, so nothing to do here finish();