Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(662)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/share/ShareHelper.java

Issue 2775373002: Add a Share Icon to Tabular Context Menu (Closed)
Patch Set: Fixed more tests! Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..79ef3a334bb661d51960348702b5927b4ee1a11c 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,11 @@ public class ShareHelper {
return intent;
}
- private static ComponentName getLastShareComponentName() {
+ /**
+ * Gets the {@link ComponentName} of the app that was used to last share.
+ */
+ @Nullable
+ public static ComponentName getLastShareComponentName() {
SharedPreferences preferences = ContextUtils.getAppSharedPreferences();
String packageName = preferences.getString(PACKAGE_NAME_KEY, null);
String className = preferences.getString(CLASS_NAME_KEY, null);

Powered by Google App Engine
This is Rietveld 408576698