Latest UX for Tap & pay.

Bug: 10862185
Change-Id: I4344f70533a69d422159547c58bbc981f4d889ca
This commit is contained in:
Martijn Coenen
2013-09-24 17:31:25 -07:00
parent 372b6f74b1
commit 0e940d6c00
11 changed files with 118 additions and 44 deletions

View File

@@ -61,8 +61,11 @@ public class PaymentBackend {
for (ApduServiceInfo service : serviceInfos) {
PaymentAppInfo appInfo = new PaymentAppInfo();
appInfo.caption = service.loadLabel(pm);
appInfo.banner = service.loadBanner(pm);
appInfo.caption = service.getDescription();
if (appInfo.caption == null) {
appInfo.caption = service.loadLabel(pm);
}
appInfo.isDefault = service.getComponent().equals(defaultApp);
appInfo.componentName = service.getComponent();
appInfos.add(appInfo);

View File

@@ -21,8 +21,12 @@ 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;
@@ -31,8 +35,11 @@ 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 {
@@ -81,17 +88,20 @@ public final class PaymentDefaultDialog extends AlertActivity implements
}
// Check if passed in service exists
boolean found = false;
PaymentAppInfo requestedPaymentApp = null;
PaymentAppInfo defaultPaymentApp = null;
List<PaymentAppInfo> services = mBackend.getPaymentAppInfos();
for (PaymentAppInfo service : services) {
if (component.equals(service.componentName)) {
found = true;
break;
requestedPaymentApp = service;
}
if (service.isDefault) {
defaultPaymentApp = service;
}
}
if (!found) {
if (requestedPaymentApp == null) {
Log.e(TAG, "Component " + component + " is not a registered payment service.");
return false;
}
@@ -103,36 +113,18 @@ public final class PaymentDefaultDialog extends AlertActivity implements
return false;
}
PackageManager pm = getPackageManager();
ApplicationInfo newAppInfo;
try {
newAppInfo = pm.getApplicationInfo(component.getPackageName(), 0);
} catch (NameNotFoundException e) {
Log.e(TAG, "PM could not load app info for " + component);
return false;
}
ApplicationInfo defaultAppInfo = null;
try {
if (defaultComponent != null) {
defaultAppInfo = pm.getApplicationInfo(defaultComponent.getPackageName(), 0);
}
} catch (NameNotFoundException e) {
Log.e(TAG, "PM could not load app info for " + defaultComponent);
// Continue intentionally
}
mNewDefault = component;
// Compose dialog; get
final AlertController.AlertParams p = mAlertParams;
p.mTitle = getString(R.string.nfc_payment_set_default_label);
if (defaultAppInfo == null) {
if (defaultPaymentApp == null) {
String formatString = getString(R.string.nfc_payment_set_default);
String msg = String.format(formatString, newAppInfo.loadLabel(pm));
String msg = String.format(formatString, requestedPaymentApp.caption);
p.mMessage = msg;
} else {
String formatString = getString(R.string.nfc_payment_set_default_instead_of);
String msg = String.format(formatString, newAppInfo.loadLabel(pm), defaultAppInfo.loadLabel(pm));
String msg = String.format(formatString, requestedPaymentApp.caption,
defaultPaymentApp.caption);
p.mMessage = msg;
}
p.mPositiveButtonText = getString(R.string.yes);

View File

@@ -17,12 +17,19 @@
package com.android.settings.nfc;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.preference.Preference;
import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
@@ -30,6 +37,7 @@ import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;
import com.android.internal.content.PackageMonitor;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.nfc.PaymentBackend.PaymentAppInfo;
@@ -42,6 +50,8 @@ public class PaymentSettings extends SettingsPreferenceFragment implements
private LayoutInflater mInflater;
private PaymentBackend mPaymentBackend;
private final PackageMonitor mSettingsPackageMonitor = new SettingsPackageMonitor();
@Override
public void onCreate(Bundle icicle) {
@@ -50,12 +60,12 @@ public class PaymentSettings extends SettingsPreferenceFragment implements
setHasOptionsMenu(false);
mPaymentBackend = new PaymentBackend(getActivity());
mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
setHasOptionsMenu(true);
}
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) {
@@ -80,17 +90,15 @@ public class PaymentSettings extends SettingsPreferenceFragment implements
} else {
emptyText.setVisibility(View.GONE);
emptyImage.setVisibility(View.GONE);
setPreferenceScreen(screen);
}
setPreferenceScreen(screen);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View v = mInflater.inflate(R.layout.nfc_payment, container, false);
return v;
}
@@ -108,9 +116,54 @@ public class PaymentSettings extends SettingsPreferenceFragment implements
@Override
public void onResume() {
super.onResume();
mSettingsPackageMonitor.register(getActivity(), getActivity().getMainLooper(), false);
refresh();
}
@Override
public void onPause() {
mSettingsPackageMonitor.unregister();
super.onPause();
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.nfc_payment_settings, menu);
MenuItem menuItem = menu.findItem(R.id.nfc_payment_menu_item_add_service);
menuItem.setIntent(new Intent(Intent.ACTION_VIEW,
Uri.parse(getString(R.string.download_nfc_payment_service_query))));
}
private final Handler mHandler = new Handler() {
@Override
public void dispatchMessage(Message msg) {
refresh();
}
};
private class SettingsPackageMonitor extends PackageMonitor {
@Override
public void onPackageAdded(String packageName, int uid) {
mHandler.obtainMessage().sendToTarget();
}
@Override
public void onPackageAppeared(String packageName, int reason) {
mHandler.obtainMessage().sendToTarget();
}
@Override
public void onPackageDisappeared(String packageName, int reason) {
mHandler.obtainMessage().sendToTarget();
}
@Override
public void onPackageRemoved(String packageName, int uid) {
mHandler.obtainMessage().sendToTarget();
}
}
public static class PaymentAppPreference extends Preference {
private final OnClickListener listener;
private final PaymentAppInfo appInfo;