DO NOT MERGE: Allow nearby sharing to substitute name & icon in chip
meta-data bundle keys (values are resids):
CHIP_LABEL_METADATA_KEY = "android.service.chooser.chip_label"
CHIP_ICON_METADATA_KEY = "android.service.chooser.chip_icon"
Test: manual, confirm that correct name & icon are used
and that custom icon is tinted in light/dark theme
(and that the copy chip is tinted right, too!)
Bug: 144290152
Change-Id: I57157e07630fa8bec3057e6d18336c59944fcb4f
This commit is contained in:
committed by
Daniel Sandler
parent
4d271f3d9a
commit
c5dffc9a4a
@@ -54,6 +54,7 @@ import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.ShortcutInfo;
|
||||
import android.content.pm.ShortcutManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.database.Cursor;
|
||||
import android.database.DataSetObserver;
|
||||
import android.graphics.Bitmap;
|
||||
@@ -931,20 +932,38 @@ public class ChooserActivity extends ResolverActivity {
|
||||
|
||||
final Intent resolveIntent = new Intent();
|
||||
resolveIntent.setComponent(cn);
|
||||
final ResolveInfo ri = getPackageManager().resolveActivity(resolveIntent, 0);
|
||||
if (ri == null) {
|
||||
final ResolveInfo ri = getPackageManager().resolveActivity(
|
||||
resolveIntent, PackageManager.GET_META_DATA);
|
||||
if (ri == null || ri.activityInfo == null) {
|
||||
Log.e(TAG, "Device-specified nearby sharing component (" + cn
|
||||
+ ") not available");
|
||||
return null;
|
||||
}
|
||||
|
||||
// TODO(b/144290152): CHIP_LABEL_METADATA_KEY / CHIP_ICON_METADATA_KEY
|
||||
|
||||
CharSequence name = ri.loadLabel(getPackageManager());
|
||||
// Allow the nearby sharing component to provide a more appropriate icon and label
|
||||
// for the chip.
|
||||
CharSequence name = null;
|
||||
Drawable icon = null;
|
||||
final Bundle metaData = ri.activityInfo.metaData;
|
||||
if (metaData != null) {
|
||||
try {
|
||||
final Resources pkgRes = getPackageManager().getResourcesForActivity(cn);
|
||||
final int nameResId = metaData.getInt(CHIP_LABEL_METADATA_KEY);
|
||||
name = pkgRes.getString(nameResId);
|
||||
final int resId = metaData.getInt(CHIP_ICON_METADATA_KEY);
|
||||
icon = pkgRes.getDrawable(resId);
|
||||
} catch (NameNotFoundException ex) { }
|
||||
}
|
||||
if (TextUtils.isEmpty(name)) {
|
||||
name = ri.loadLabel(getPackageManager());
|
||||
}
|
||||
if (icon == null) {
|
||||
icon = ri.loadIcon(getPackageManager());
|
||||
}
|
||||
|
||||
final DisplayResolveInfo dri = new DisplayResolveInfo(
|
||||
originalIntent, ri, name, "", null);
|
||||
dri.setDisplayIcon(ri.loadIcon(getPackageManager()));
|
||||
dri.setDisplayIcon(icon);
|
||||
return dri;
|
||||
}
|
||||
|
||||
@@ -976,7 +995,10 @@ public class ChooserActivity extends ResolverActivity {
|
||||
return createActionButton(
|
||||
ti.getDisplayIcon(),
|
||||
ti.getDisplayLabel(),
|
||||
(View unused) -> safelyStartActivity(ti)
|
||||
(View unused) -> {
|
||||
safelyStartActivity(ti);
|
||||
finish();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,10 @@
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
android:viewportHeight="24"
|
||||
android:autoMirrored="true"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="?android:attr/textColorSecondary"
|
||||
android:fillColor="@color/white"
|
||||
android:pathData="M18,21L4,21L4,7L2,7v14c0,1.1 0.9,2 2,2h14v-2zM21,17L21,3c0,-1.1 -0.9,-2 -2,-2L8,1c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h11c1.1,0 2,-0.9 2,-2zM19,17L8,17L8,3h11v14z"/>
|
||||
</vector>
|
||||
|
||||
@@ -25,4 +25,6 @@
|
||||
android:singleLine="true"
|
||||
android:clickable="true"
|
||||
android:background="@drawable/chooser_action_button_bg"
|
||||
android:drawableTint="?android:attr/colorControlNormal"
|
||||
android:drawableTintMode="src_in"
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user