frameworks/base
修訂 | c5dffc9a4a64ad0b12343cee791800fd4f67cd41 (tree) |
---|---|
時間 | 2019-12-19 10:43:51 |
作者 | Dan Sandler <dsandler@andr...> |
Commiter | Daniel Sandler |
DO NOT MERGE: Allow nearby sharing to substitute name & icon in chip
meta-data bundle keys (values are resids):
Test: manual, confirm that correct name & icon are used
Bug: 144290152
Change-Id: I57157e07630fa8bec3057e6d18336c59944fcb4f
@@ -54,6 +54,7 @@ import android.content.pm.ResolveInfo; | ||
54 | 54 | import android.content.pm.ShortcutInfo; |
55 | 55 | import android.content.pm.ShortcutManager; |
56 | 56 | import android.content.res.Configuration; |
57 | +import android.content.res.Resources; | |
57 | 58 | import android.database.Cursor; |
58 | 59 | import android.database.DataSetObserver; |
59 | 60 | import android.graphics.Bitmap; |
@@ -931,20 +932,38 @@ public class ChooserActivity extends ResolverActivity { | ||
931 | 932 | |
932 | 933 | final Intent resolveIntent = new Intent(); |
933 | 934 | resolveIntent.setComponent(cn); |
934 | - final ResolveInfo ri = getPackageManager().resolveActivity(resolveIntent, 0); | |
935 | - if (ri == null) { | |
935 | + final ResolveInfo ri = getPackageManager().resolveActivity( | |
936 | + resolveIntent, PackageManager.GET_META_DATA); | |
937 | + if (ri == null || ri.activityInfo == null) { | |
936 | 938 | Log.e(TAG, "Device-specified nearby sharing component (" + cn |
937 | 939 | + ") not available"); |
938 | 940 | return null; |
939 | 941 | } |
940 | 942 | |
941 | - // TODO(b/144290152): CHIP_LABEL_METADATA_KEY / CHIP_ICON_METADATA_KEY | |
942 | - | |
943 | - CharSequence name = ri.loadLabel(getPackageManager()); | |
943 | + // Allow the nearby sharing component to provide a more appropriate icon and label | |
944 | + // for the chip. | |
945 | + CharSequence name = null; | |
946 | + Drawable icon = null; | |
947 | + final Bundle metaData = ri.activityInfo.metaData; | |
948 | + if (metaData != null) { | |
949 | + try { | |
950 | + final Resources pkgRes = getPackageManager().getResourcesForActivity(cn); | |
951 | + final int nameResId = metaData.getInt(CHIP_LABEL_METADATA_KEY); | |
952 | + name = pkgRes.getString(nameResId); | |
953 | + final int resId = metaData.getInt(CHIP_ICON_METADATA_KEY); | |
954 | + icon = pkgRes.getDrawable(resId); | |
955 | + } catch (NameNotFoundException ex) { } | |
956 | + } | |
957 | + if (TextUtils.isEmpty(name)) { | |
958 | + name = ri.loadLabel(getPackageManager()); | |
959 | + } | |
960 | + if (icon == null) { | |
961 | + icon = ri.loadIcon(getPackageManager()); | |
962 | + } | |
944 | 963 | |
945 | 964 | final DisplayResolveInfo dri = new DisplayResolveInfo( |
946 | 965 | originalIntent, ri, name, "", null); |
947 | - dri.setDisplayIcon(ri.loadIcon(getPackageManager())); | |
966 | + dri.setDisplayIcon(icon); | |
948 | 967 | return dri; |
949 | 968 | } |
950 | 969 |
@@ -976,7 +995,10 @@ public class ChooserActivity extends ResolverActivity { | ||
976 | 995 | return createActionButton( |
977 | 996 | ti.getDisplayIcon(), |
978 | 997 | ti.getDisplayLabel(), |
979 | - (View unused) -> safelyStartActivity(ti) | |
998 | + (View unused) -> { | |
999 | + safelyStartActivity(ti); | |
1000 | + finish(); | |
1001 | + } | |
980 | 1002 | ); |
981 | 1003 | } |
982 | 1004 |
@@ -18,8 +18,10 @@ | ||
18 | 18 | android:width="24dp" |
19 | 19 | android:height="24dp" |
20 | 20 | android:viewportWidth="24" |
21 | - android:viewportHeight="24"> | |
21 | + android:viewportHeight="24" | |
22 | + android:autoMirrored="true" | |
23 | + android:tint="?attr/colorControlNormal"> | |
22 | 24 | <path |
23 | - android:fillColor="?android:attr/textColorSecondary" | |
25 | + android:fillColor="@color/white" | |
24 | 26 | 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"/> |
25 | 27 | </vector> |
@@ -25,4 +25,6 @@ | ||
25 | 25 | android:singleLine="true" |
26 | 26 | android:clickable="true" |
27 | 27 | android:background="@drawable/chooser_action_button_bg" |
28 | + android:drawableTint="?android:attr/colorControlNormal" | |
29 | + android:drawableTintMode="src_in" | |
28 | 30 | /> |