Add NFC checkbox to Settings app.
Based on Trusted_NFC_Device_Host_AA03.01e02_google.zip code drop (23-Sep-2010) Heavily modified to remove dead code. Change-Id: I9e5f0bf2d32105feff4d68f03adebe87d2e9d900
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
<uses-permission android:name="android.permission.VIBRATE" />
|
<uses-permission android:name="android.permission.VIBRATE" />
|
||||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||||
|
<uses-permission android:name="com.trustedlogic.trustednfc.permission.NFC_ADMIN" />
|
||||||
<uses-permission android:name="android.permission.HARDWARE_TEST" />
|
<uses-permission android:name="android.permission.HARDWARE_TEST" />
|
||||||
<uses-permission android:name="android.permission.CALL_PHONE" />
|
<uses-permission android:name="android.permission.CALL_PHONE" />
|
||||||
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
|
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
|
||||||
|
@@ -757,6 +757,12 @@
|
|||||||
<!-- Bluetooth settings. Dock Setting Dialog - Remember setting and don't ask user again -->
|
<!-- Bluetooth settings. Dock Setting Dialog - Remember setting and don't ask user again -->
|
||||||
<string name="bluetooth_dock_settings_remember">Remember settings</string>
|
<string name="bluetooth_dock_settings_remember">Remember settings</string>
|
||||||
|
|
||||||
|
<!-- NFC settings -->
|
||||||
|
<!-- Used in the 1st-level settings screen to turn on NFC -->
|
||||||
|
<string name="nfc_quick_toggle_title">NFC</string>
|
||||||
|
<!-- Used in the 1st-level settings screen as the turn-on summary -->
|
||||||
|
<string name="nfc_quick_toggle_summary">Turn on NFC</string>
|
||||||
|
|
||||||
<!-- Wi-Fi Settings --> <skip />
|
<!-- Wi-Fi Settings --> <skip />
|
||||||
<!-- Used in the 1st-level settings screen to turn on Wi-Fi -->
|
<!-- Used in the 1st-level settings screen to turn on Wi-Fi -->
|
||||||
<string name="wifi_quick_toggle_title">Wi-Fi</string>
|
<string name="wifi_quick_toggle_title">Wi-Fi</string>
|
||||||
|
@@ -40,6 +40,12 @@
|
|||||||
android:targetClass="com.android.settings.wifi.WifiSettings" />
|
android:targetClass="com.android.settings.wifi.WifiSettings" />
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="toggle_nfc"
|
||||||
|
android:title="@string/nfc_quick_toggle_title"
|
||||||
|
android:summary="@string/nfc_quick_toggle_summary"
|
||||||
|
android:persistent="false" />
|
||||||
|
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:key="toggle_bluetooth"
|
android:key="toggle_bluetooth"
|
||||||
android:title="@string/bluetooth_quick_toggle_title"
|
android:title="@string/bluetooth_quick_toggle_title"
|
||||||
|
@@ -20,7 +20,6 @@ import android.bluetooth.BluetoothAdapter;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.wifi.WifiManager;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
import android.os.SystemProperties;
|
import android.os.SystemProperties;
|
||||||
@@ -29,28 +28,30 @@ import android.preference.Preference;
|
|||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
import android.preference.PreferenceScreen;
|
import android.preference.PreferenceScreen;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import com.android.internal.telephony.TelephonyIntents;
|
import com.android.internal.telephony.TelephonyIntents;
|
||||||
import com.android.internal.telephony.TelephonyProperties;
|
import com.android.internal.telephony.TelephonyProperties;
|
||||||
import com.android.settings.bluetooth.BluetoothEnabler;
|
import com.android.settings.bluetooth.BluetoothEnabler;
|
||||||
import com.android.settings.wifi.WifiEnabler;
|
import com.android.settings.wifi.WifiEnabler;
|
||||||
|
import com.android.settings.nfc.NfcEnabler;
|
||||||
|
|
||||||
public class WirelessSettings extends PreferenceActivity {
|
public class WirelessSettings extends PreferenceActivity {
|
||||||
|
|
||||||
private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane";
|
private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane";
|
||||||
private static final String KEY_TOGGLE_BLUETOOTH = "toggle_bluetooth";
|
private static final String KEY_TOGGLE_BLUETOOTH = "toggle_bluetooth";
|
||||||
private static final String KEY_TOGGLE_WIFI = "toggle_wifi";
|
private static final String KEY_TOGGLE_WIFI = "toggle_wifi";
|
||||||
|
private static final String KEY_TOGGLE_NFC = "toggle_nfc";
|
||||||
private static final String KEY_WIFI_SETTINGS = "wifi_settings";
|
private static final String KEY_WIFI_SETTINGS = "wifi_settings";
|
||||||
private static final String KEY_BT_SETTINGS = "bt_settings";
|
private static final String KEY_BT_SETTINGS = "bt_settings";
|
||||||
private static final String KEY_VPN_SETTINGS = "vpn_settings";
|
private static final String KEY_VPN_SETTINGS = "vpn_settings";
|
||||||
private static final String KEY_TETHER_SETTINGS = "tether_settings";
|
private static final String KEY_TETHER_SETTINGS = "tether_settings";
|
||||||
|
|
||||||
public static final String EXIT_ECM_RESULT = "exit_ecm_result";
|
public static final String EXIT_ECM_RESULT = "exit_ecm_result";
|
||||||
public static final int REQUEST_CODE_EXIT_ECM = 1;
|
public static final int REQUEST_CODE_EXIT_ECM = 1;
|
||||||
|
|
||||||
private AirplaneModeEnabler mAirplaneModeEnabler;
|
private AirplaneModeEnabler mAirplaneModeEnabler;
|
||||||
private CheckBoxPreference mAirplaneModePreference;
|
private CheckBoxPreference mAirplaneModePreference;
|
||||||
private WifiEnabler mWifiEnabler;
|
private WifiEnabler mWifiEnabler;
|
||||||
|
private NfcEnabler mNfcEnabler;
|
||||||
private BluetoothEnabler mBtEnabler;
|
private BluetoothEnabler mBtEnabler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -91,11 +92,13 @@ public class WirelessSettings extends PreferenceActivity {
|
|||||||
CheckBoxPreference airplane = (CheckBoxPreference) findPreference(KEY_TOGGLE_AIRPLANE);
|
CheckBoxPreference airplane = (CheckBoxPreference) findPreference(KEY_TOGGLE_AIRPLANE);
|
||||||
CheckBoxPreference wifi = (CheckBoxPreference) findPreference(KEY_TOGGLE_WIFI);
|
CheckBoxPreference wifi = (CheckBoxPreference) findPreference(KEY_TOGGLE_WIFI);
|
||||||
CheckBoxPreference bt = (CheckBoxPreference) findPreference(KEY_TOGGLE_BLUETOOTH);
|
CheckBoxPreference bt = (CheckBoxPreference) findPreference(KEY_TOGGLE_BLUETOOTH);
|
||||||
|
CheckBoxPreference nfc = (CheckBoxPreference) findPreference(KEY_TOGGLE_NFC);
|
||||||
|
|
||||||
mAirplaneModeEnabler = new AirplaneModeEnabler(this, airplane);
|
mAirplaneModeEnabler = new AirplaneModeEnabler(this, airplane);
|
||||||
mAirplaneModePreference = (CheckBoxPreference) findPreference(KEY_TOGGLE_AIRPLANE);
|
mAirplaneModePreference = (CheckBoxPreference) findPreference(KEY_TOGGLE_AIRPLANE);
|
||||||
mWifiEnabler = new WifiEnabler(this, wifi);
|
mWifiEnabler = new WifiEnabler(this, wifi);
|
||||||
mBtEnabler = new BluetoothEnabler(this, bt);
|
mBtEnabler = new BluetoothEnabler(this, bt);
|
||||||
|
mNfcEnabler = new NfcEnabler(this, nfc);
|
||||||
|
|
||||||
String toggleable = Settings.System.getString(getContentResolver(),
|
String toggleable = Settings.System.getString(getContentResolver(),
|
||||||
Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
|
Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
|
||||||
@@ -113,9 +116,14 @@ public class WirelessSettings extends PreferenceActivity {
|
|||||||
findPreference(KEY_BT_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
|
findPreference(KEY_BT_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable Bluetooth Settings if Bluetooth service is not available.
|
// Remove Bluetooth Settings if Bluetooth service is not available.
|
||||||
if (ServiceManager.getService(BluetoothAdapter.BLUETOOTH_SERVICE) == null) {
|
if (ServiceManager.getService(BluetoothAdapter.BLUETOOTH_SERVICE) == null) {
|
||||||
findPreference(KEY_BT_SETTINGS).setEnabled(false);
|
getPreferenceScreen().removePreference(bt);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove NFC if its not available
|
||||||
|
if (ServiceManager.getService(Context.NFC_SERVICE) == null) {
|
||||||
|
getPreferenceScreen().removePreference(nfc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable Tethering if it's not allowed
|
// Disable Tethering if it's not allowed
|
||||||
@@ -149,6 +157,7 @@ public class WirelessSettings extends PreferenceActivity {
|
|||||||
mAirplaneModeEnabler.resume();
|
mAirplaneModeEnabler.resume();
|
||||||
mWifiEnabler.resume();
|
mWifiEnabler.resume();
|
||||||
mBtEnabler.resume();
|
mBtEnabler.resume();
|
||||||
|
mNfcEnabler.resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -158,6 +167,7 @@ public class WirelessSettings extends PreferenceActivity {
|
|||||||
mAirplaneModeEnabler.pause();
|
mAirplaneModeEnabler.pause();
|
||||||
mWifiEnabler.pause();
|
mWifiEnabler.pause();
|
||||||
mBtEnabler.pause();
|
mBtEnabler.pause();
|
||||||
|
mNfcEnabler.pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
106
src/com/android/settings/nfc/NfcEnabler.java
Normal file
106
src/com/android/settings/nfc/NfcEnabler.java
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2010 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 com.android.settings.R;
|
||||||
|
import com.trustedlogic.trustednfc.android.NfcException;
|
||||||
|
import com.trustedlogic.trustednfc.android.NfcManager;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.preference.Preference;
|
||||||
|
import android.preference.CheckBoxPreference;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NfcEnabler is a helper to manage the Nfc on/off checkbox preference. It is
|
||||||
|
* turns on/off Nfc and ensures the summary of the preference reflects the
|
||||||
|
* current state.
|
||||||
|
*/
|
||||||
|
public class NfcEnabler implements Preference.OnPreferenceChangeListener {
|
||||||
|
private static final String TAG = "NfcEnabler";
|
||||||
|
|
||||||
|
private final Context mContext;
|
||||||
|
private final CheckBoxPreference mCheckbox;
|
||||||
|
private final NfcManager mNfcManager;
|
||||||
|
|
||||||
|
private boolean mNfcState;
|
||||||
|
|
||||||
|
public NfcEnabler(Context context, CheckBoxPreference checkBoxPreference) {
|
||||||
|
mContext = context;
|
||||||
|
mCheckbox = checkBoxPreference;
|
||||||
|
mNfcManager = (NfcManager) context.getSystemService(Context.NFC_SERVICE);
|
||||||
|
|
||||||
|
if (mNfcManager == null) {
|
||||||
|
// NFC is not supported
|
||||||
|
mCheckbox.setEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resume() {
|
||||||
|
if (mNfcManager == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mCheckbox.setOnPreferenceChangeListener(this);
|
||||||
|
mNfcState = Settings.System.getInt(mContext.getContentResolver(),
|
||||||
|
Settings.System.NFC_ON, 0) != 0;
|
||||||
|
updateUi();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void pause() {
|
||||||
|
if (mNfcManager == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mCheckbox.setOnPreferenceChangeListener(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object value) {
|
||||||
|
// Turn on/off Nfc
|
||||||
|
mNfcState = (Boolean) value;
|
||||||
|
setEnabled();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setEnabled() {
|
||||||
|
if (mNfcState) {
|
||||||
|
try {
|
||||||
|
mNfcManager.enable();
|
||||||
|
} catch (NfcException e) {
|
||||||
|
Log.w(TAG, "NFC enabling failed: " + e.getMessage());
|
||||||
|
mNfcState = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
mNfcManager.disable();
|
||||||
|
} catch (NfcException e) {
|
||||||
|
Log.w(TAG, "NFC disabling failed: " + e.getMessage());
|
||||||
|
mNfcState = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateUi();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateUi() {
|
||||||
|
mCheckbox.setChecked(mNfcState);
|
||||||
|
if (mNfcState) {
|
||||||
|
mCheckbox.setSummary(R.string.nfc_quick_toggle_summary);
|
||||||
|
} else {
|
||||||
|
mCheckbox.setSummary("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user