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