diff options
author | Martijn Coenen <maco@google.com> | 2011-07-27 17:31:41 -0500 |
---|---|---|
committer | Martijn Coenen <maco@google.com> | 2011-07-27 17:31:41 -0500 |
commit | bb4bdc29d64714546255681fcd9c9d92efa9328f (patch) | |
tree | 632521639a25260871e983d7afefb6a15329a124 /src | |
parent | 7485addd8c230812b33f7043de3ff47d97b79bc1 (diff) | |
download | packages_apps_settings-bb4bdc29d64714546255681fcd9c9d92efa9328f.zip packages_apps_settings-bb4bdc29d64714546255681fcd9c9d92efa9328f.tar.gz packages_apps_settings-bb4bdc29d64714546255681fcd9c9d92efa9328f.tar.bz2 |
Add on/off actionbar switch for NFC Tap To Share.
Change-Id: I009a31d8862a23e15d89fe9813eca02e06469531
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/settings/WirelessSettings.java | 16 | ||||
-rw-r--r-- | src/com/android/settings/nfc/ZeroClick.java | 55 |
2 files changed, 55 insertions, 16 deletions
diff --git a/src/com/android/settings/WirelessSettings.java b/src/com/android/settings/WirelessSettings.java index beab491..7efa15d 100644 --- a/src/com/android/settings/WirelessSettings.java +++ b/src/com/android/settings/WirelessSettings.java @@ -54,6 +54,7 @@ public class WirelessSettings extends SettingsPreferenceFragment { private AirplaneModeEnabler mAirplaneModeEnabler; private CheckBoxPreference mAirplaneModePreference; private NfcEnabler mNfcEnabler; + private NfcAdapter mNfcAdapter; /** * Invoked on each preference click in this hierarchy, overrides @@ -113,7 +114,8 @@ public class WirelessSettings extends SettingsPreferenceFragment { } // Remove NFC if its not available - if (NfcAdapter.getDefaultAdapter(activity) == null) { + mNfcAdapter = NfcAdapter.getDefaultAdapter(activity); + if (mNfcAdapter == null) { getPreferenceScreen().removePreference(nfc); getPreferenceScreen().removePreference(zeroclick); } @@ -175,6 +177,18 @@ public class WirelessSettings extends SettingsPreferenceFragment { mAirplaneModeEnabler.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 diff --git a/src/com/android/settings/nfc/ZeroClick.java b/src/com/android/settings/nfc/ZeroClick.java index 7868662..4d657d9 100644 --- a/src/com/android/settings/nfc/ZeroClick.java +++ b/src/com/android/settings/nfc/ZeroClick.java @@ -16,28 +16,54 @@ package com.android.settings.nfc; +import android.app.ActionBar; +import android.app.Activity; 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.preference.PreferenceActivity; +import android.view.Gravity; 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 android.widget.Switch; import com.android.settings.R; public class ZeroClick extends Fragment implements CompoundButton.OnCheckedChangeListener { private View mView; - private CheckBox mCheckbox; 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 public View onCreateView(LayoutInflater inflater, ViewGroup container, @@ -48,10 +74,9 @@ public class ZeroClick extends Fragment } private void initView(View view) { - mCheckbox = (CheckBox) mView.findViewById(R.id.zeroclick_checkbox); - mCheckbox.setOnCheckedChangeListener(this); mNfcAdapter = NfcAdapter.getDefaultAdapter(getActivity()); - mCheckbox.setChecked(mNfcAdapter.zeroClickEnabled()); + mActionBarSwitch.setOnCheckedChangeListener(this); + mActionBarSwitch.setChecked(mNfcAdapter.zeroClickEnabled()); } @Override @@ -67,15 +92,15 @@ public class ZeroClick extends Fragment @Override public void onCheckedChanged(CompoundButton buttonView, boolean desiredState) { boolean success = false; - mCheckbox.setEnabled(false); + mActionBarSwitch.setEnabled(false); if (desiredState) { success = mNfcAdapter.enableZeroClick(); } else { success = mNfcAdapter.disableZeroClick(); } if (success) { - mCheckbox.setChecked(desiredState); + mActionBarSwitch.setChecked(desiredState); } - mCheckbox.setEnabled(true); + mActionBarSwitch.setEnabled(true); } } |