Added setting for zero-click sharing over NFC.
Change-Id: I3848c4815d65d3a8b9b5e579c6a353dde6901ee4
This commit is contained in:
69
res/layout/zeroclick.xml
Normal file
69
res/layout/zeroclick.xml
Normal file
@@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="6dip"
|
||||
android:paddingRight="6dip"
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:scrollbars="vertical" >
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fillViewport="true">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<View
|
||||
android:paddingTop="53dip"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dip"
|
||||
android:background="#ff404040"
|
||||
/>
|
||||
|
||||
<CheckBox android:id="@+id/zeroclick_checkbox"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="64dip"
|
||||
android:gravity="center_vertical"
|
||||
android:text="@string/zeroclick_label"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
/>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dip"
|
||||
android:background="#ff404040"
|
||||
/>
|
||||
|
||||
<TextView android:id="@+id/zeroclick_explained"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dip"
|
||||
android:gravity="top"
|
||||
android:text="@string/zeroclick_explained"
|
||||
/>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
</LinearLayout>
|
||||
|
@@ -1087,6 +1087,12 @@
|
||||
<!-- NFC settings -->
|
||||
<!-- Used in the 1st-level settings screen to turn on NFC -->
|
||||
<string name="nfc_quick_toggle_title">NFC</string>
|
||||
<!-- Used to enter the Zero-click sharing preferences screen -->
|
||||
<string name="zeroclick_settings_title">Zero-click sharing</string>
|
||||
<string name="zeroclick_settings_summary"></string>
|
||||
<!-- Used in the zero-click sharing preferences screen -->
|
||||
<string name="zeroclick_label">Zero-click sharing</string>
|
||||
<string name="zeroclick_explained">Lorem ipsum dolor sit amet.</string>
|
||||
|
||||
<!-- Wi-Fi Settings --> <skip />
|
||||
<!-- Used in the 1st-level settings screen to turn on Wi-Fi -->
|
||||
|
@@ -38,6 +38,14 @@
|
||||
android:title="@string/nfc_quick_toggle_title"
|
||||
android:persistent="false" />
|
||||
|
||||
<PreferenceScreen
|
||||
android:fragment="com.android.settings.nfc.ZeroClick"
|
||||
android:key="zeroclick_settings"
|
||||
android:title="@string/zeroclick_settings_title"
|
||||
android:summary="@string/zeroclick_settings_summary" >
|
||||
</PreferenceScreen>
|
||||
|
||||
|
||||
<PreferenceScreen
|
||||
android:key="mobile_network_settings"
|
||||
android:title="@string/network_settings_title"
|
||||
|
@@ -37,6 +37,7 @@ public class WirelessSettings extends SettingsPreferenceFragment {
|
||||
|
||||
private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane";
|
||||
private static final String KEY_TOGGLE_NFC = "toggle_nfc";
|
||||
private static final String KEY_ZEROCLICK_SETTINGS = "zeroclick_settings";
|
||||
private static final String KEY_VPN_SETTINGS = "vpn_settings";
|
||||
private static final String KEY_TETHER_SETTINGS = "tether_settings";
|
||||
private static final String KEY_PROXY_SETTINGS = "proxy_settings";
|
||||
@@ -87,9 +88,11 @@ public class WirelessSettings extends SettingsPreferenceFragment {
|
||||
final Activity activity = getActivity();
|
||||
mAirplaneModePreference = (CheckBoxPreference) findPreference(KEY_TOGGLE_AIRPLANE);
|
||||
CheckBoxPreference nfc = (CheckBoxPreference) findPreference(KEY_TOGGLE_NFC);
|
||||
PreferenceScreen zeroclick = (PreferenceScreen)
|
||||
findPreference(KEY_ZEROCLICK_SETTINGS);
|
||||
|
||||
mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference);
|
||||
mNfcEnabler = new NfcEnabler(activity, nfc);
|
||||
mNfcEnabler = new NfcEnabler(activity, nfc, zeroclick);
|
||||
|
||||
String toggleable = Settings.System.getString(activity.getContentResolver(),
|
||||
Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
|
||||
@@ -107,6 +110,7 @@ public class WirelessSettings extends SettingsPreferenceFragment {
|
||||
// Remove NFC if its not available
|
||||
if (NfcAdapter.getDefaultAdapter(activity) == null) {
|
||||
getPreferenceScreen().removePreference(nfc);
|
||||
getPreferenceScreen().removePreference(zeroclick);
|
||||
}
|
||||
|
||||
// Remove Mobile Network Settings if it's a wifi-only device.
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
83
src/com/android/settings/nfc/ZeroClick.java
Normal file
83
src/com/android/settings/nfc/ZeroClick.java
Normal file
@@ -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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user