1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settings.nfc;
18 
19 import android.content.Context;
20 import android.nfc.NfcAdapter;
21 import android.provider.Settings;
22 
23 import androidx.annotation.VisibleForTesting;
24 import androidx.preference.SwitchPreference;
25 
26 import com.android.settings.R;
27 
28 /**
29  * SecureNfcEnabler is a helper to manage the Secure Nfc on/off checkbox preference
30  * It turns on/off Secure NFC and ensures the summary of the preference reflects
31  * the current state.
32  */
33 public class SecureNfcEnabler extends BaseNfcEnabler {
34     private final SwitchPreference mPreference;
35 
SecureNfcEnabler(Context context, SwitchPreference preference)36     public SecureNfcEnabler(Context context, SwitchPreference preference) {
37         super(context);
38         mPreference = preference;
39     }
40 
41     @Override
handleNfcStateChanged(int newState)42     protected void handleNfcStateChanged(int newState) {
43         switch (newState) {
44             case NfcAdapter.STATE_OFF:
45                 mPreference.setSummary(R.string.nfc_disabled_summary);
46                 mPreference.setEnabled(false);
47                 break;
48             case NfcAdapter.STATE_ON:
49                 mPreference.setSummary(R.string.nfc_secure_toggle_summary);
50                 mPreference.setChecked(mPreference.isChecked());
51                 mPreference.setEnabled(true);
52                 break;
53             case NfcAdapter.STATE_TURNING_ON:
54                 mPreference.setEnabled(false);
55                 break;
56             case NfcAdapter.STATE_TURNING_OFF:
57                 mPreference.setEnabled(false);
58                 break;
59         }
60     }
61 }
62