 Chromium Code Reviews
 Chromium Code Reviews Issue 2775373002:
  Add a Share Icon to Tabular Context Menu  (Closed)
    
  
    Issue 2775373002:
  Add a Share Icon to Tabular Context Menu  (Closed) 
  | 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..129ec054397f8b4cecb96b5a763447bc77457c5f 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 the | 
| + * {@link ComponentName} | 
| */ | 
| - 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,23 @@ public class ShareHelper { | 
| * @param item The menu item that is used for direct share | 
| */ | 
| public static void configureDirectShareMenuItem(Activity activity, MenuItem item) { | 
| + Pair<Drawable, CharSequence> directShare = getShareableIconAndName(activity); | 
| + Drawable directShareIcon = directShare.first; | 
| + CharSequence 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 +622,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 +695,7 @@ public class ShareHelper { | 
| return intent; | 
| } | 
| - private static ComponentName getLastShareComponentName() { | 
| + public static ComponentName getLastShareComponentName() { | 
| 
David Trainor- moved to gerrit
2017/03/30 23:50:22
Javadoc?
 
JJ
2017/03/31 20:58:54
Done.
 | 
| SharedPreferences preferences = ContextUtils.getAppSharedPreferences(); | 
| String packageName = preferences.getString(PACKAGE_NAME_KEY, null); | 
| String className = preferences.getString(CLASS_NAME_KEY, null); |