Add on/off actionbar switch for NFC Tap To Share.
Change-Id: I009a31d8862a23e15d89fe9813eca02e06469531
This commit is contained in:
@@ -30,28 +30,6 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical">
|
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"
|
<TextView android:id="@+id/zeroclick_explained"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@@ -1091,11 +1091,13 @@
|
|||||||
<!-- Used in the 1st-level settings screen to turn on NFC -->
|
<!-- Used in the 1st-level settings screen to turn on NFC -->
|
||||||
<string name="nfc_quick_toggle_title">NFC</string>
|
<string name="nfc_quick_toggle_title">NFC</string>
|
||||||
<!-- Used to enter the Zero-click sharing preferences screen -->
|
<!-- Used to enter the Zero-click sharing preferences screen -->
|
||||||
<string name="zeroclick_settings_title">Zero-click sharing</string>
|
<string name="zeroclick_settings_title">Tap to share</string>
|
||||||
<string name="zeroclick_settings_summary"></string>
|
<string name="zeroclick_settings_summary"></string>
|
||||||
|
<string name="zeroclick_on_summary">On</string>
|
||||||
|
<string name="zeroclick_off_summary">Off</string>
|
||||||
<!-- Used in the zero-click sharing preferences screen -->
|
<!-- Used in the zero-click sharing preferences screen -->
|
||||||
<string name="zeroclick_label">Zero-click sharing</string>
|
<string name="zeroclick_label">Zero-click sharing</string>
|
||||||
<string name="zeroclick_explained">Zero-click sharing allows you to share content from applications, just by tapping your NFC-enabled device to another.</string>
|
<string name="zeroclick_explained">Tap to share allows you to share content from applications, just by tapping your NFC-enabled device to another.</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 -->
|
||||||
|
@@ -54,6 +54,7 @@ public class WirelessSettings extends SettingsPreferenceFragment {
|
|||||||
private AirplaneModeEnabler mAirplaneModeEnabler;
|
private AirplaneModeEnabler mAirplaneModeEnabler;
|
||||||
private CheckBoxPreference mAirplaneModePreference;
|
private CheckBoxPreference mAirplaneModePreference;
|
||||||
private NfcEnabler mNfcEnabler;
|
private NfcEnabler mNfcEnabler;
|
||||||
|
private NfcAdapter mNfcAdapter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked on each preference click in this hierarchy, overrides
|
* Invoked on each preference click in this hierarchy, overrides
|
||||||
@@ -113,7 +114,8 @@ public class WirelessSettings extends SettingsPreferenceFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Remove NFC if its not available
|
// Remove NFC if its not available
|
||||||
if (NfcAdapter.getDefaultAdapter(activity) == null) {
|
mNfcAdapter = NfcAdapter.getDefaultAdapter(activity);
|
||||||
|
if (mNfcAdapter == null) {
|
||||||
getPreferenceScreen().removePreference(nfc);
|
getPreferenceScreen().removePreference(nfc);
|
||||||
getPreferenceScreen().removePreference(zeroclick);
|
getPreferenceScreen().removePreference(zeroclick);
|
||||||
}
|
}
|
||||||
@@ -175,6 +177,18 @@ public class WirelessSettings extends SettingsPreferenceFragment {
|
|||||||
|
|
||||||
mAirplaneModeEnabler.resume();
|
mAirplaneModeEnabler.resume();
|
||||||
mNfcEnabler.resume();
|
mNfcEnabler.resume();
|
||||||
|
|
||||||
|
if (mNfcAdapter != null) {
|
||||||
|
// Update zero-click subtitle
|
||||||
|
Preference zeroClick = getPreferenceScreen().
|
||||||
|
findPreference(KEY_ZEROCLICK_SETTINGS);
|
||||||
|
|
||||||
|
if (mNfcAdapter.zeroClickEnabled()) {
|
||||||
|
zeroClick.setSummary(R.string.zeroclick_on_summary);
|
||||||
|
} else {
|
||||||
|
zeroClick.setSummary(R.string.zeroclick_off_summary);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -16,28 +16,54 @@
|
|||||||
|
|
||||||
package com.android.settings.nfc;
|
package com.android.settings.nfc;
|
||||||
|
|
||||||
|
import android.app.ActionBar;
|
||||||
|
import android.app.Activity;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.content.ContentResolver;
|
|
||||||
import android.nfc.NfcAdapter;
|
import android.nfc.NfcAdapter;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.CheckBoxPreference;
|
import android.preference.PreferenceActivity;
|
||||||
import android.preference.Preference;
|
import android.view.Gravity;
|
||||||
import android.provider.Settings;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.CheckBox;
|
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
import android.widget.EditText;
|
import android.widget.Switch;
|
||||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
|
||||||
import android.util.Log;
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
|
||||||
public class ZeroClick extends Fragment
|
public class ZeroClick extends Fragment
|
||||||
implements CompoundButton.OnCheckedChangeListener {
|
implements CompoundButton.OnCheckedChangeListener {
|
||||||
private View mView;
|
private View mView;
|
||||||
private CheckBox mCheckbox;
|
|
||||||
private NfcAdapter mNfcAdapter;
|
private NfcAdapter mNfcAdapter;
|
||||||
|
private Switch mActionBarSwitch;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
Activity activity = getActivity();
|
||||||
|
|
||||||
|
mActionBarSwitch = new Switch(activity);
|
||||||
|
|
||||||
|
if (activity instanceof PreferenceActivity) {
|
||||||
|
PreferenceActivity preferenceActivity = (PreferenceActivity) activity;
|
||||||
|
if (preferenceActivity.onIsHidingHeaders() || !preferenceActivity.onIsMultiPane()) {
|
||||||
|
final int padding = activity.getResources().getDimensionPixelSize(
|
||||||
|
R.dimen.action_bar_switch_padding);
|
||||||
|
mActionBarSwitch.setPadding(0, 0, padding, 0);
|
||||||
|
activity.getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
|
||||||
|
ActionBar.DISPLAY_SHOW_CUSTOM);
|
||||||
|
activity.getActionBar().setCustomView(mActionBarSwitch, new ActionBar.LayoutParams(
|
||||||
|
ActionBar.LayoutParams.WRAP_CONTENT,
|
||||||
|
ActionBar.LayoutParams.WRAP_CONTENT,
|
||||||
|
Gravity.CENTER_VERTICAL | Gravity.RIGHT));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mActionBarSwitch.setOnCheckedChangeListener(this);
|
||||||
|
|
||||||
|
mNfcAdapter = NfcAdapter.getDefaultAdapter(getActivity());
|
||||||
|
mActionBarSwitch.setChecked(mNfcAdapter.zeroClickEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
@@ -48,10 +74,9 @@ public class ZeroClick extends Fragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initView(View view) {
|
private void initView(View view) {
|
||||||
mCheckbox = (CheckBox) mView.findViewById(R.id.zeroclick_checkbox);
|
|
||||||
mCheckbox.setOnCheckedChangeListener(this);
|
|
||||||
mNfcAdapter = NfcAdapter.getDefaultAdapter(getActivity());
|
mNfcAdapter = NfcAdapter.getDefaultAdapter(getActivity());
|
||||||
mCheckbox.setChecked(mNfcAdapter.zeroClickEnabled());
|
mActionBarSwitch.setOnCheckedChangeListener(this);
|
||||||
|
mActionBarSwitch.setChecked(mNfcAdapter.zeroClickEnabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -67,15 +92,15 @@ public class ZeroClick extends Fragment
|
|||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean desiredState) {
|
public void onCheckedChanged(CompoundButton buttonView, boolean desiredState) {
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
mCheckbox.setEnabled(false);
|
mActionBarSwitch.setEnabled(false);
|
||||||
if (desiredState) {
|
if (desiredState) {
|
||||||
success = mNfcAdapter.enableZeroClick();
|
success = mNfcAdapter.enableZeroClick();
|
||||||
} else {
|
} else {
|
||||||
success = mNfcAdapter.disableZeroClick();
|
success = mNfcAdapter.disableZeroClick();
|
||||||
}
|
}
|
||||||
if (success) {
|
if (success) {
|
||||||
mCheckbox.setChecked(desiredState);
|
mActionBarSwitch.setChecked(desiredState);
|
||||||
}
|
}
|
||||||
mCheckbox.setEnabled(true);
|
mActionBarSwitch.setEnabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user