1 /* 2 * Copyright (C) 2010 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 22 import com.android.settingslib.widget.MainSwitchPreference; 23 24 /** 25 * NfcEnabler is a helper to manage the Nfc on/off checkbox preference. It turns on/off Nfc 26 * and ensures the summary of the preference reflects the current state. 27 */ 28 public class NfcEnabler extends BaseNfcEnabler { 29 private final MainSwitchPreference mPreference; 30 NfcEnabler(Context context, MainSwitchPreference preference)31 public NfcEnabler(Context context, MainSwitchPreference preference) { 32 super(context); 33 mPreference = preference; 34 } 35 36 @Override handleNfcStateChanged(int newState)37 protected void handleNfcStateChanged(int newState) { 38 switch (newState) { 39 case NfcAdapter.STATE_OFF: 40 mPreference.updateStatus(false); 41 mPreference.setEnabled(true); 42 break; 43 case NfcAdapter.STATE_ON: 44 mPreference.updateStatus(true); 45 mPreference.setEnabled(true); 46 break; 47 case NfcAdapter.STATE_TURNING_ON: 48 mPreference.updateStatus(true); 49 mPreference.setEnabled(false); 50 break; 51 case NfcAdapter.STATE_TURNING_OFF: 52 mPreference.updateStatus(false); 53 mPreference.setEnabled(false); 54 break; 55 } 56 } 57 } 58