Merge "Add text attributes to Wallet manifest entry" into rvc-dev am: 4fca5e9d5b am: 9ec1055d45 am: 5d3c6091b1
Change-Id: I82d055a0c08d50099c2dda4b95fdaa96e1873591
This commit is contained in:
@@ -22,6 +22,7 @@ import android.annotation.Nullable;
|
|||||||
import android.annotation.TestApi;
|
import android.annotation.TestApi;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
@@ -165,4 +166,42 @@ public interface QuickAccessWalletClient extends Closeable {
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
Intent createWalletSettingsIntent();
|
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();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import android.content.ComponentName;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
@@ -256,6 +257,29 @@ public class QuickAccessWalletClientImpl implements QuickAccessWalletClient, Ser
|
|||||||
mServiceInfo.getSettingsActivity()));
|
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() {
|
private void connect() {
|
||||||
mHandler.post(this::connectInternal);
|
mHandler.post(this::connectInternal);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,6 +113,7 @@ import android.util.Log;
|
|||||||
* android:name=".MyQuickAccessWalletService"
|
* android:name=".MyQuickAccessWalletService"
|
||||||
* android:label="@string/my_default_tile_label"
|
* android:label="@string/my_default_tile_label"
|
||||||
* android:icon="@drawable/my_default_icon_label"
|
* android:icon="@drawable/my_default_icon_label"
|
||||||
|
* android:logo="@drawable/my_wallet_logo"
|
||||||
* android:permission="android.permission.BIND_QUICK_ACCESS_WALLET_SERVICE">
|
* android:permission="android.permission.BIND_QUICK_ACCESS_WALLET_SERVICE">
|
||||||
* <intent-filter>
|
* <intent-filter>
|
||||||
* <action android:name="android.service.quickaccesswallet.QuickAccessWalletService" />
|
* <action android:name="android.service.quickaccesswallet.QuickAccessWalletService" />
|
||||||
@@ -133,6 +134,8 @@ import android.util.Log;
|
|||||||
* <quickaccesswallet-service
|
* <quickaccesswallet-service
|
||||||
* xmlns:android="http://schemas.android.com/apk/res/android"
|
* xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
* android:settingsActivity="com.example.android.SettingsActivity"
|
* 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"/>
|
* android:targetActivity="com.example.android.WalletActivity"/>
|
||||||
* }
|
* }
|
||||||
* </pre>
|
* </pre>
|
||||||
@@ -140,9 +143,16 @@ import android.util.Log;
|
|||||||
* <p>The entry for {@code settingsActivity} should contain the fully qualified class name of an
|
* <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}
|
* 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
|
* 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
|
* their entire wallet. The {@code targetActivity} 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} and the {@code settingsActivity} will be started with the Intent
|
||||||
* {@link #ACTION_VIEW_WALLET_SETTINGS}.
|
* 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 {
|
public abstract class QuickAccessWalletService extends Service {
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,9 @@ import android.content.pm.ServiceInfo;
|
|||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.content.res.XmlResourceParser;
|
import android.content.res.XmlResourceParser;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Xml;
|
import android.util.Xml;
|
||||||
@@ -104,11 +106,25 @@ class QuickAccessWalletServiceInfo {
|
|||||||
@Nullable
|
@Nullable
|
||||||
private final String mSettingsActivity;
|
private final String mSettingsActivity;
|
||||||
@Nullable
|
@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) {
|
private static ServiceMetadata empty() {
|
||||||
this.mSettingsActivity = settingsActivity;
|
return new ServiceMetadata(null, null, null, null);
|
||||||
this.mWalletActivity = walletActivity;
|
}
|
||||||
|
|
||||||
|
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);
|
serviceInfo.loadXmlMetaData(pm, QuickAccessWalletService.SERVICE_META_DATA);
|
||||||
|
|
||||||
if (parser == null) {
|
if (parser == null) {
|
||||||
return new ServiceMetadata(null, null);
|
return ServiceMetadata.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -134,11 +150,16 @@ class QuickAccessWalletServiceInfo {
|
|||||||
try {
|
try {
|
||||||
afsAttributes = resources.obtainAttributes(allAttributes,
|
afsAttributes = resources.obtainAttributes(allAttributes,
|
||||||
R.styleable.QuickAccessWalletService);
|
R.styleable.QuickAccessWalletService);
|
||||||
|
String targetActivity = afsAttributes.getString(
|
||||||
|
R.styleable.QuickAccessWalletService_targetActivity);
|
||||||
String settingsActivity = afsAttributes.getString(
|
String settingsActivity = afsAttributes.getString(
|
||||||
R.styleable.QuickAccessWalletService_settingsActivity);
|
R.styleable.QuickAccessWalletService_settingsActivity);
|
||||||
String walletActivity = afsAttributes.getString(
|
CharSequence shortcutShortLabel = afsAttributes.getText(
|
||||||
R.styleable.QuickAccessWalletService_targetActivity);
|
R.styleable.QuickAccessWalletService_shortcutShortLabel);
|
||||||
return new ServiceMetadata(settingsActivity, walletActivity);
|
CharSequence shortcutLongLabel = afsAttributes.getText(
|
||||||
|
R.styleable.QuickAccessWalletService_shortcutLongLabel);
|
||||||
|
return new ServiceMetadata(targetActivity, settingsActivity, shortcutShortLabel,
|
||||||
|
shortcutLongLabel);
|
||||||
} finally {
|
} finally {
|
||||||
if (afsAttributes != null) {
|
if (afsAttributes != null) {
|
||||||
afsAttributes.recycle();
|
afsAttributes.recycle();
|
||||||
@@ -147,13 +168,12 @@ class QuickAccessWalletServiceInfo {
|
|||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "Meta-data does not start with quickaccesswallet-service tag");
|
Log.e(TAG, "Meta-data does not start with quickaccesswallet-service tag");
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (PackageManager.NameNotFoundException
|
} catch (PackageManager.NameNotFoundException
|
||||||
| IOException
|
| IOException
|
||||||
| XmlPullParserException e) {
|
| XmlPullParserException e) {
|
||||||
Log.e(TAG, "Error parsing quickaccesswallet service meta-data", 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
|
@Nullable
|
||||||
String getWalletActivity() {
|
String getWalletActivity() {
|
||||||
return mServiceMetadata.mWalletActivity;
|
return mServiceMetadata.mTargetActivity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -183,4 +203,34 @@ class QuickAccessWalletServiceInfo {
|
|||||||
String getSettingsActivity() {
|
String getSettingsActivity() {
|
||||||
return mServiceMetadata.mSettingsActivity;
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8356,10 +8356,15 @@
|
|||||||
<declare-styleable name="QuickAccessWalletService">
|
<declare-styleable name="QuickAccessWalletService">
|
||||||
<!-- Fully qualified class name of an activity that allows the user to modify
|
<!-- Fully qualified class name of an activity that allows the user to modify
|
||||||
the settings for this service. -->
|
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
|
<!-- Fully qualified class name of an activity that allows the user to view
|
||||||
their entire wallet -->
|
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>
|
</declare-styleable>
|
||||||
|
|
||||||
<!-- Use <code>recognition-service</code> as the root tag of the XML resource that
|
<!-- Use <code>recognition-service</code> as the root tag of the XML resource that
|
||||||
|
|||||||
Reference in New Issue
Block a user