Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/share/ShareHelper.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/share/ShareHelper.java b/chrome/android/java/src/org/chromium/chrome/browser/share/ShareHelper.java |
| index 8d66037e5b0a03de13b61c1b93cac9b15b22bd4d..24a7a9eec5373a8eb904130beef60c4bd76d44f2 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/share/ShareHelper.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/share/ShareHelper.java |
| @@ -314,8 +314,11 @@ public class ShareHelper { |
| * Trigger the share action for the given image data. |
| * @param activity The activity used to trigger the share action. |
| * @param jpegImageData The image data to be shared in jpeg format. |
| + * @param name When this is not null, it will share the image directly with whatever the |
| + * component name is. |
|
Theresa
2017/03/30 15:12:45
nit: ...will share the image directly with the app
JJ
2017/03/30 16:20:17
Whoops. You just got a glimpse into what my javado
|
| */ |
| - public static void shareImage(final Activity activity, final byte[] jpegImageData) { |
| + public static void shareImage( |
| + final Activity activity, final byte[] jpegImageData, final ComponentName name) { |
| if (jpegImageData.length == 0) { |
| Log.w(TAG, "Share failed -- Received image contains no data."); |
| return; |
| @@ -361,9 +364,15 @@ public class ShareHelper { |
| != ApplicationState.HAS_DESTROYED_ACTIVITIES) { |
| Uri imageUri = ApiCompatibilityUtils.getUriForImageCaptureFile(saveFile); |
| - Intent chooserIntent = Intent.createChooser(getShareImageIntent(imageUri), |
| - activity.getString(R.string.share_link_chooser_title)); |
| - fireIntent(activity, chooserIntent); |
| + if (name == null) { |
| + Intent chooserIntent = Intent.createChooser(getShareImageIntent(imageUri), |
| + activity.getString(R.string.share_link_chooser_title)); |
| + fireIntent(activity, chooserIntent); |
| + } else { |
| + Intent imageIntent = getShareImageIntent(imageUri); |
| + imageIntent.setComponent(name); |
| + fireIntent(activity, imageIntent); |
| + } |
| } |
| } |
| }.execute(); |
| @@ -539,6 +548,26 @@ public class ShareHelper { |
| * @param item The menu item that is used for direct share |
| */ |
| public static void configureDirectShareMenuItem(Activity activity, MenuItem item) { |
| + Drawable directShareIcon; |
| + CharSequence directShareTitle; |
|
Theresa
2017/03/30 15:12:45
nit: these can both defined when they are set belo
JJ
2017/03/30 16:20:17
Done.
|
| + |
| + Pair<Drawable, CharSequence> directShare = getShareableIconAndName(activity); |
| + directShareIcon = directShare.first; |
| + directShareTitle = directShare.second; |
| + |
| + item.setIcon(directShareIcon); |
| + if (directShareTitle != null) { |
| + item.setTitle( |
| + activity.getString(R.string.accessibility_menu_share_via, directShareTitle)); |
| + } |
| + } |
| + |
| + /** |
| + * Get the icon and name of the most recently shared app within chrome. |
| + * @param activity Activity that is used to access the package manager. |
| + * @return The Image and the String of the recently shared Icon. |
| + */ |
| + public static Pair<Drawable, CharSequence> getShareableIconAndName(Activity activity) { |
| Drawable directShareIcon = null; |
| CharSequence directShareTitle = null; |
| @@ -596,11 +625,7 @@ public class ShareHelper { |
| "Android.IsLastSharedAppInfoRetrieved", retrieved); |
| } |
| - item.setIcon(directShareIcon); |
| - if (directShareTitle != null) { |
| - item.setTitle(activity.getString(R.string.accessibility_menu_share_via, |
| - directShareTitle)); |
| - } |
| + return new Pair<>(directShareIcon, directShareTitle); |
| } |
| /* |
| @@ -673,7 +698,7 @@ public class ShareHelper { |
| return intent; |
| } |
| - private static ComponentName getLastShareComponentName() { |
| + public static ComponentName getLastShareComponentName() { |
| SharedPreferences preferences = ContextUtils.getAppSharedPreferences(); |
| String packageName = preferences.getString(PACKAGE_NAME_KEY, null); |
| String className = preferences.getString(CLASS_NAME_KEY, null); |