diff --git a/res/layout/nfc_payment_option.xml b/res/layout/nfc_payment_option.xml
index 04fdc076c35..76fea4fb5de 100644
--- a/res/layout/nfc_payment_option.xml
+++ b/res/layout/nfc_payment_option.xml
@@ -19,7 +19,7 @@
android:layout_weight="1"
android:id="@+id/nfc_payment_pref"
android:focusable="true"
- android:clickable="true"
+ android:clickable="false"
android:gravity="center_vertical"
android:paddingTop="10dp"
android:paddingBottom="10dp"
@@ -37,6 +37,7 @@
android:layout_width="wrap_content"
android:layout_height="96dp"
android:scaleType="centerInside"
+ android:clickable="true"
/>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index aa0c77d1c79..b1df53581cb 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -4957,6 +4957,9 @@
Tap & pay
Pay with just a tap
+
+ Favor foreground app
Learn more
diff --git a/src/com/android/settings/nfc/PaymentBackend.java b/src/com/android/settings/nfc/PaymentBackend.java
index f84bc74d7c4..25572a72af9 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 61c6fdba6b0..6bc29e19a6c 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 7548c5099ef..df4e396d30b 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 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;
}
}
}