diff options
Diffstat (limited to 'src/com/android/settings/nfc')
-rw-r--r-- | src/com/android/settings/nfc/NfcEnabler.java | 7 | ||||
-rw-r--r-- | src/com/android/settings/nfc/ZeroClick.java | 83 |
2 files changed, 89 insertions, 1 deletions
diff --git a/src/com/android/settings/nfc/NfcEnabler.java b/src/com/android/settings/nfc/NfcEnabler.java index dba1329..99cf8f0 100644 --- a/src/com/android/settings/nfc/NfcEnabler.java +++ b/src/com/android/settings/nfc/NfcEnabler.java @@ -24,6 +24,7 @@ import android.nfc.NfcAdapter; import android.os.Handler; import android.preference.CheckBoxPreference; import android.preference.Preference; +import android.preference.PreferenceScreen; import android.util.Log; /** @@ -36,6 +37,7 @@ public class NfcEnabler implements Preference.OnPreferenceChangeListener { private final Context mContext; private final CheckBoxPreference mCheckbox; + private final PreferenceScreen mZeroClick; private final NfcAdapter mNfcAdapter; private final IntentFilter mIntentFilter; private final Handler mHandler = new Handler(); @@ -54,9 +56,11 @@ public class NfcEnabler implements Preference.OnPreferenceChangeListener { private boolean mNfcState; - public NfcEnabler(Context context, CheckBoxPreference checkBoxPreference) { + public NfcEnabler(Context context, CheckBoxPreference checkBoxPreference, + PreferenceScreen zeroclick) { mContext = context; mCheckbox = checkBoxPreference; + mZeroClick = zeroclick; mNfcAdapter = NfcAdapter.getDefaultAdapter(context); if (mNfcAdapter == null) { @@ -127,5 +131,6 @@ public class NfcEnabler implements Preference.OnPreferenceChangeListener { private void handleNfcStateChanged(boolean newState) { mCheckbox.setChecked(newState); mCheckbox.setEnabled(true); + mZeroClick.setEnabled(newState); } } diff --git a/src/com/android/settings/nfc/ZeroClick.java b/src/com/android/settings/nfc/ZeroClick.java new file mode 100644 index 0000000..11c35db --- /dev/null +++ b/src/com/android/settings/nfc/ZeroClick.java @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.nfc; + +import android.app.Fragment; +import android.content.ContentResolver; +import android.nfc.NfcAdapter; +import android.os.Bundle; +import android.preference.CheckBoxPreference; +import android.preference.Preference; +import android.provider.Settings; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.CheckBox; +import android.widget.CompoundButton; +import android.widget.EditText; +import android.widget.CompoundButton.OnCheckedChangeListener; +import android.util.Log; +import com.android.settings.R; + +public class ZeroClick extends Fragment + implements CompoundButton.OnCheckedChangeListener { + private View mView; + private CheckBox mCheckbox; + private NfcAdapter mNfcAdapter; + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + mView = inflater.inflate(R.layout.zeroclick, container, false); + initView(mView); + return mView; + } + + private void initView(View view) { + mCheckbox = (CheckBox) mView.findViewById(R.id.zeroclick_checkbox); + mCheckbox.setOnCheckedChangeListener(this); + mNfcAdapter = NfcAdapter.getDefaultAdapter(getActivity()); + mCheckbox.setChecked(mNfcAdapter.zeroClickEnabled()); + } + + @Override + public void onPause() { + super.onPause(); + } + + @Override + public void onResume() { + super.onResume(); + } + + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean value) { + Log.e("AAP", "onCheckedChanged!"); + final boolean desiredState = (Boolean) value; + boolean success = false; + mCheckbox.setEnabled(false); + if (desiredState) { + success = mNfcAdapter.enableZeroClick(); + } else { + success = mNfcAdapter.disableZeroClick(); + } + if (success) { + mCheckbox.setChecked(desiredState); + } + mCheckbox.setEnabled(true); + } +} |