Merge "Add text attributes to Wallet manifest entry" into rvc-dev am: 4fca5e9d5b

Change-Id: I59e950d8e4be89a8f9ab0675288cbf615725594b
This commit is contained in:
Sean Pont
2020-03-31 20:13:14 +00:00
committed by Automerger Merge Worker
5 changed files with 144 additions and 16 deletions

View File

@@ -22,6 +22,7 @@ import android.annotation.Nullable;
import android.annotation.TestApi;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import java.io.Closeable;
import java.util.concurrent.Executor;
@@ -165,4 +166,42 @@ public interface QuickAccessWalletClient extends Closeable {
*/
@Nullable
Intent createWalletSettingsIntent();
/**
* Returns the logo associated with the {@link QuickAccessWalletService}. This is specified by
* {@code android:logo} manifest entry. If the logo is not specified, the app icon will be
* returned instead ({@code android:icon}).
*
* @hide
*/
@Nullable
Drawable getLogo();
/**
* Returns the service label specified by {@code android:label} in the service manifest entry.
*
* @hide
*/
@Nullable
CharSequence getServiceLabel();
/**
* Returns the text specified by the {@link android:shortcutShortLabel} in the service manifest
* entry. If the shortcutShortLabel isn't specified, the service label ({@code android:label})
* will be returned instead.
*
* @hide
*/
@Nullable
CharSequence getShortcutShortLabel();
/**
* Returns the text specified by the {@link android:shortcutLongLabel} in the service manifest
* entry. If the shortcutShortLabel isn't specified, the service label ({@code android:label})
* will be returned instead.
*
* @hide
*/
@Nullable
CharSequence getShortcutLongLabel();
}

View File

@@ -26,6 +26,7 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
@@ -256,6 +257,29 @@ public class QuickAccessWalletClientImpl implements QuickAccessWalletClient, Ser
mServiceInfo.getSettingsActivity()));
}
@Override
@Nullable
public Drawable getLogo() {
return mServiceInfo == null ? null : mServiceInfo.getWalletLogo(mContext);
}
@Override
@Nullable
public CharSequence getServiceLabel() {
return mServiceInfo == null ? null : mServiceInfo.getServiceLabel(mContext);
}
@Override
@Nullable
public CharSequence getShortcutShortLabel() {
return mServiceInfo == null ? null : mServiceInfo.getShortcutShortLabel(mContext);
}
@Override
public CharSequence getShortcutLongLabel() {
return mServiceInfo == null ? null : mServiceInfo.getShortcutLongLabel(mContext);
}
private void connect() {
mHandler.post(this::connectInternal);
}

View File

@@ -113,6 +113,7 @@ import android.util.Log;
* android:name=".MyQuickAccessWalletService"
* android:label="@string/my_default_tile_label"
* android:icon="@drawable/my_default_icon_label"
* android:logo="@drawable/my_wallet_logo"
* android:permission="android.permission.BIND_QUICK_ACCESS_WALLET_SERVICE">
* <intent-filter>
* <action android:name="android.service.quickaccesswallet.QuickAccessWalletService" />
@@ -133,6 +134,8 @@ import android.util.Log;
* <quickaccesswallet-service
* xmlns:android="http://schemas.android.com/apk/res/android"
* android:settingsActivity="com.example.android.SettingsActivity"
* android:shortcutLongLabel="@string/my_wallet_empty_state_text"
* android:shortcutShortLabel="@string/my_wallet_button_text"
* android:targetActivity="com.example.android.WalletActivity"/>
* }
* </pre>
@@ -140,9 +143,16 @@ import android.util.Log;
* <p>The entry for {@code settingsActivity} should contain the fully qualified class name of an
* activity that allows the user to modify the settings for this service. The {@code targetActivity}
* entry should contain the fully qualified class name of an activity that allows the user to view
* their entire wallet. If specified, the wallet activity will be started with the Intent action
* {@link #ACTION_VIEW_WALLET} and the settings activity will be started with the Intent action
* {@link #ACTION_VIEW_WALLET_SETTINGS}.
* their entire wallet. The {@code targetActivity} will be started with the Intent action
* {@link #ACTION_VIEW_WALLET} and the {@code settingsActivity} will be started with the Intent
* action {@link #ACTION_VIEW_WALLET_SETTINGS}.
*
* <p>The {@code shortcutShortLabel} and {@code shortcutLongLabel} are used by the QuickAccessWallet
* in the buttons that navigate to the wallet app. The {@code shortcutShortLabel} is displayed next
* to the cards that are returned by the service and should be no more than 20 characters. The
* {@code shortcutLongLabel} is displayed when no cards are returned. This 'empty state' view also
* displays the service logo, specified by the {@code android:logo} manifest entry. If the logo is
* not specified, the empty state view will show the app icon instead.
*/
public abstract class QuickAccessWalletService extends Service {

View File

@@ -29,7 +29,9 @@ import android.content.pm.ServiceInfo;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.graphics.drawable.Drawable;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Xml;
@@ -104,11 +106,25 @@ class QuickAccessWalletServiceInfo {
@Nullable
private final String mSettingsActivity;
@Nullable
private final String mWalletActivity;
private final String mTargetActivity;
@Nullable
private final CharSequence mShortcutShortLabel;
@Nullable
private final CharSequence mShortcutLongLabel;
private ServiceMetadata(String settingsActivity, String walletActivity) {
this.mSettingsActivity = settingsActivity;
this.mWalletActivity = walletActivity;
private static ServiceMetadata empty() {
return new ServiceMetadata(null, null, null, null);
}
private ServiceMetadata(
String targetActivity,
String settingsActivity,
CharSequence shortcutShortLabel,
CharSequence shortcutLongLabel) {
mTargetActivity = targetActivity;
mSettingsActivity = settingsActivity;
mShortcutShortLabel = shortcutShortLabel;
mShortcutLongLabel = shortcutLongLabel;
}
}
@@ -118,7 +134,7 @@ class QuickAccessWalletServiceInfo {
serviceInfo.loadXmlMetaData(pm, QuickAccessWalletService.SERVICE_META_DATA);
if (parser == null) {
return new ServiceMetadata(null, null);
return ServiceMetadata.empty();
}
try {
@@ -134,11 +150,16 @@ class QuickAccessWalletServiceInfo {
try {
afsAttributes = resources.obtainAttributes(allAttributes,
R.styleable.QuickAccessWalletService);
String targetActivity = afsAttributes.getString(
R.styleable.QuickAccessWalletService_targetActivity);
String settingsActivity = afsAttributes.getString(
R.styleable.QuickAccessWalletService_settingsActivity);
String walletActivity = afsAttributes.getString(
R.styleable.QuickAccessWalletService_targetActivity);
return new ServiceMetadata(settingsActivity, walletActivity);
CharSequence shortcutShortLabel = afsAttributes.getText(
R.styleable.QuickAccessWalletService_shortcutShortLabel);
CharSequence shortcutLongLabel = afsAttributes.getText(
R.styleable.QuickAccessWalletService_shortcutLongLabel);
return new ServiceMetadata(targetActivity, settingsActivity, shortcutShortLabel,
shortcutLongLabel);
} finally {
if (afsAttributes != null) {
afsAttributes.recycle();
@@ -147,13 +168,12 @@ class QuickAccessWalletServiceInfo {
} else {
Log.e(TAG, "Meta-data does not start with quickaccesswallet-service tag");
}
} catch (PackageManager.NameNotFoundException
| IOException
| XmlPullParserException e) {
Log.e(TAG, "Error parsing quickaccesswallet service meta-data", e);
}
return new ServiceMetadata(null, null);
return ServiceMetadata.empty();
}
/**
@@ -171,7 +191,7 @@ class QuickAccessWalletServiceInfo {
*/
@Nullable
String getWalletActivity() {
return mServiceMetadata.mWalletActivity;
return mServiceMetadata.mTargetActivity;
}
/**
@@ -183,4 +203,34 @@ class QuickAccessWalletServiceInfo {
String getSettingsActivity() {
return mServiceMetadata.mSettingsActivity;
}
@NonNull
Drawable getWalletLogo(Context context) {
Drawable drawable = mServiceInfo.loadLogo(context.getPackageManager());
if (drawable != null) {
return drawable;
}
return mServiceInfo.loadIcon(context.getPackageManager());
}
@NonNull
CharSequence getShortcutShortLabel(Context context) {
if (!TextUtils.isEmpty(mServiceMetadata.mShortcutShortLabel)) {
return mServiceMetadata.mShortcutShortLabel;
}
return mServiceInfo.loadLabel(context.getPackageManager());
}
@NonNull
CharSequence getShortcutLongLabel(Context context) {
if (!TextUtils.isEmpty(mServiceMetadata.mShortcutLongLabel)) {
return mServiceMetadata.mShortcutLongLabel;
}
return mServiceInfo.loadLabel(context.getPackageManager());
}
@NonNull
CharSequence getServiceLabel(Context context) {
return mServiceInfo.loadLabel(context.getPackageManager());
}
}

View File

@@ -8356,10 +8356,15 @@
<declare-styleable name="QuickAccessWalletService">
<!-- Fully qualified class name of an activity that allows the user to modify
the settings for this service. -->
<attr name="settingsActivity"/>
<attr name="settingsActivity" format="string"/>
<!-- Fully qualified class name of an activity that allows the user to view
their entire wallet -->
<attr name="targetActivity"/>
<attr name="targetActivity" format="string"/>
<!-- Text shown on the empty state button if no cards are provided -->
<attr name="shortcutLongLabel"/>
<!-- Text shown on the button that takes users to the wallet application -->
<attr name="shortcutShortLabel"/>
</declare-styleable>
<!-- Use <code>recognition-service</code> as the root tag of the XML resource that