diff options
author | Martijn Coenen <maco@google.com> | 2014-04-25 16:58:59 -0700 |
---|---|---|
committer | Martijn Coenen <maco@google.com> | 2014-05-16 09:10:30 -0700 |
commit | 00dbb74b8d699510ece683fc7ab12fc2343fa5d5 (patch) | |
tree | 81755e03baaaf0dfddfd6233ea358ef2220bdf51 /src/com/android/settings/nfc | |
parent | 3f7e0571d3baaa9dd2ad887067fb8d86f597f71b (diff) | |
download | packages_apps_Settings-00dbb74b8d699510ece683fc7ab12fc2343fa5d5.zip packages_apps_Settings-00dbb74b8d699510ece683fc7ab12fc2343fa5d5.tar.gz packages_apps_Settings-00dbb74b8d699510ece683fc7ab12fc2343fa5d5.tar.bz2 |
HCE foreground support.
Allow users to configure they want to favor the foreground
app for tap&pay.
Change-Id: I25e1058e84f468e47fd40f43b65389c04373a3ab
Diffstat (limited to 'src/com/android/settings/nfc')
-rw-r--r-- | src/com/android/settings/nfc/PaymentBackend.java | 15 | ||||
-rw-r--r-- | src/com/android/settings/nfc/PaymentDefaultDialog.java | 10 | ||||
-rw-r--r-- | src/com/android/settings/nfc/PaymentSettings.java | 29 |
3 files changed, 40 insertions, 14 deletions
diff --git a/src/com/android/settings/nfc/PaymentBackend.java b/src/com/android/settings/nfc/PaymentBackend.java index f84bc74..25572a7 100644 --- a/src/com/android/settings/nfc/PaymentBackend.java +++ b/src/com/android/settings/nfc/PaymentBackend.java @@ -24,6 +24,7 @@ import android.nfc.NfcAdapter; import android.nfc.cardemulation.ApduServiceInfo; import android.nfc.cardemulation.CardEmulation; import android.provider.Settings; +import android.provider.Settings.SettingNotFoundException; import java.util.ArrayList; import java.util.List; @@ -74,6 +75,20 @@ public class PaymentBackend { return appInfos; } + boolean isForegroundMode() { + try { + return Settings.Secure.getInt(mContext.getContentResolver(), + Settings.Secure.NFC_PAYMENT_FOREGROUND) != 0; + } catch (SettingNotFoundException e) { + return false; + } + } + + void setForegroundMode(boolean foreground) { + Settings.Secure.putInt(mContext.getContentResolver(), + Settings.Secure.NFC_PAYMENT_FOREGROUND, foreground ? 1 : 0) ; + } + ComponentName getDefaultPaymentApp() { String componentString = Settings.Secure.getString(mContext.getContentResolver(), Settings.Secure.NFC_PAYMENT_DEFAULT_COMPONENT); diff --git a/src/com/android/settings/nfc/PaymentDefaultDialog.java b/src/com/android/settings/nfc/PaymentDefaultDialog.java index 61c6fdb..6bc29e1 100644 --- a/src/com/android/settings/nfc/PaymentDefaultDialog.java +++ b/src/com/android/settings/nfc/PaymentDefaultDialog.java @@ -19,14 +19,7 @@ package com.android.settings.nfc; import android.content.ComponentName; import android.content.DialogInterface; import android.content.Intent; -import android.content.pm.ApplicationInfo; -import android.content.pm.PackageManager; -import android.content.pm.ResolveInfo; -import android.content.pm.PackageManager.NameNotFoundException; -import android.nfc.cardemulation.ApduServiceInfo; import android.nfc.cardemulation.CardEmulation; -import android.nfc.cardemulation.HostApduService; -import android.nfc.cardemulation.OffHostApduService; import android.os.Bundle; import android.util.Log; @@ -35,11 +28,8 @@ import com.android.internal.app.AlertController; import com.android.settings.R; import com.android.settings.nfc.PaymentBackend.PaymentAppInfo; -import java.io.IOException; import java.util.List; -import org.xmlpull.v1.XmlPullParserException; - public final class PaymentDefaultDialog extends AlertActivity implements DialogInterface.OnClickListener { diff --git a/src/com/android/settings/nfc/PaymentSettings.java b/src/com/android/settings/nfc/PaymentSettings.java index 7548c50..df4e396 100644 --- a/src/com/android/settings/nfc/PaymentSettings.java +++ b/src/com/android/settings/nfc/PaymentSettings.java @@ -22,7 +22,9 @@ import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.os.Message; +import android.preference.CheckBoxPreference; import android.preference.Preference; +import android.preference.Preference.OnPreferenceChangeListener; import android.preference.PreferenceManager; import android.preference.PreferenceScreen; import android.provider.Settings; @@ -48,7 +50,7 @@ import com.android.settings.nfc.PaymentBackend.PaymentAppInfo; import java.util.List; public class PaymentSettings extends SettingsPreferenceFragment implements - OnClickListener { + OnClickListener, OnPreferenceChangeListener { public static final String TAG = "PaymentSettings"; private LayoutInflater mInflater; private PaymentBackend mPaymentBackend; @@ -67,6 +69,7 @@ public class PaymentSettings extends SettingsPreferenceFragment implements public void refresh() { PreferenceManager manager = getPreferenceManager(); PreferenceScreen screen = manager.createPreferenceScreen(getActivity()); + // Get all payment services List<PaymentAppInfo> appInfos = mPaymentBackend.getPaymentAppInfos(); if (appInfos != null && appInfos.size() > 0) { @@ -92,6 +95,13 @@ public class PaymentSettings extends SettingsPreferenceFragment implements emptyImage.setVisibility(View.VISIBLE); getListView().setVisibility(View.GONE); } else { + CheckBoxPreference foreground = new CheckBoxPreference(getActivity()); + boolean foregroundMode = mPaymentBackend.isForegroundMode(); + foreground.setPersistent(false); + foreground.setTitle(getString(R.string.nfc_payment_favor_foreground)); + foreground.setChecked(foregroundMode); + foreground.setOnPreferenceChangeListener(this); + screen.addPreference(foreground); emptyText.setVisibility(View.GONE); learnMore.setVisibility(View.GONE); emptyImage.setVisibility(View.GONE); @@ -207,14 +217,25 @@ public class PaymentSettings extends SettingsPreferenceFragment implements protected void onBindView(View view) { super.onBindView(view); - view.setOnClickListener(listener); - view.setTag(appInfo); - RadioButton radioButton = (RadioButton) view.findViewById(android.R.id.button1); radioButton.setChecked(appInfo.isDefault); + radioButton.setOnClickListener(listener); + radioButton.setTag(appInfo); ImageView banner = (ImageView) view.findViewById(R.id.banner); banner.setImageDrawable(appInfo.banner); + banner.setOnClickListener(listener); + banner.setTag(appInfo); + } + } + + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + if (preference instanceof CheckBoxPreference) { + mPaymentBackend.setForegroundMode(((Boolean) newValue).booleanValue()); + return true; + } else { + return false; } } } |