blob: 0096f2e5a2288397ccb733d7e675942c79ecbc5f [file] [log] [blame]
Nick Pellyad50ba02010-09-22 10:55:13 -07001/*
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
17package com.android.settings.nfc;
18
Nick Pellyad50ba02010-09-22 10:55:13 -070019import android.content.Context;
Nick Pelly454d2ef2010-10-12 13:07:06 -070020import android.nfc.NfcAdapter;
Stanley Wang10b7a7d2021-01-29 01:17:43 +080021
Edgar Wangcfaa4ea2025-06-03 04:35:02 +000022import androidx.preference.TwoStatePreference;
Chihhang Chuang3b387a02018-03-29 17:26:04 +080023
Nick Pellyad50ba02010-09-22 10:55:13 -070024/**
HJ ChangLiaob2473112018-03-21 16:01:31 +080025 * 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.
Nick Pellyad50ba02010-09-22 10:55:13 -070027 */
Chihhang Chuang3b387a02018-03-29 17:26:04 +080028public class NfcEnabler extends BaseNfcEnabler {
Edgar Wangcfaa4ea2025-06-03 04:35:02 +000029 private final TwoStatePreference mPreference;
Brad Fitzpatrickd36d6502010-10-18 14:04:24 -070030
Edgar Wangcfaa4ea2025-06-03 04:35:02 +000031 public NfcEnabler(Context context, TwoStatePreference preference) {
HJ ChangLiaob2473112018-03-21 16:01:31 +080032 super(context);
HJ ChangLiaob2473112018-03-21 16:01:31 +080033 mPreference = preference;
Nick Pellyad50ba02010-09-22 10:55:13 -070034 }
35
HJ ChangLiaob2473112018-03-21 16:01:31 +080036 @Override
37 protected void handleNfcStateChanged(int newState) {
Nick Pelly9894d4a2011-08-09 07:10:16 -070038 switch (newState) {
HJ ChangLiaob2473112018-03-21 16:01:31 +080039 case NfcAdapter.STATE_OFF:
Jacky Wang041bc112025-01-20 21:19:46 +080040 mPreference.setChecked(false);
Roshan Pius3ebfcea2023-03-29 10:48:23 -070041 mPreference.setEnabled(true);
HJ ChangLiaob2473112018-03-21 16:01:31 +080042 break;
43 case NfcAdapter.STATE_ON:
Jacky Wang041bc112025-01-20 21:19:46 +080044 mPreference.setChecked(true);
HJ ChangLiaob2473112018-03-21 16:01:31 +080045 mPreference.setEnabled(true);
46 break;
47 case NfcAdapter.STATE_TURNING_ON:
Jacky Wang041bc112025-01-20 21:19:46 +080048 mPreference.setChecked(true);
HJ ChangLiaob2473112018-03-21 16:01:31 +080049 mPreference.setEnabled(false);
50 break;
51 case NfcAdapter.STATE_TURNING_OFF:
Jacky Wang041bc112025-01-20 21:19:46 +080052 mPreference.setChecked(false);
HJ ChangLiaob2473112018-03-21 16:01:31 +080053 mPreference.setEnabled(false);
54 break;
Nick Pelly9894d4a2011-08-09 07:10:16 -070055 }
Nick Pellyad50ba02010-09-22 10:55:13 -070056 }
Amith Yamasani1bdb7872010-10-14 17:20:59 -070057}