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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ContextMenuHelper.java

Issue 2777773002: Show the image header for the Context Menu (Closed)
Patch Set: git rebase 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/contextmenu/ContextMenuHelper.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ContextMenuHelper.java b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ContextMenuHelper.java
index dbb62b1694e5b2f51452d42dbae5dffa2134433f..7410ca676f3726ecef35c6de8edcbbe2e5ccd691 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ContextMenuHelper.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ContextMenuHelper.java
@@ -6,6 +6,8 @@ package org.chromium.chrome.browser.contextmenu;
import android.app.Activity;
import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
import android.util.Pair;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
@@ -37,6 +39,22 @@ public class ContextMenuHelper implements OnCreateContextMenuListener {
private Callback<Integer> mCallback;
private Runnable mOnMenuShown;
private Runnable mOnMenuClosed;
+ private OnThumbnailReceivedListener mOnThumbnailReceivedListener;
+
+ /**
+ * This waits for a thumbnail to be retrieved by the native code.
+ */
+ interface OnThumbnailReceivedListener {
+ /**
+ * When the thumbnail is received it will send the thumbnail via this method. This is
+ * activated after calling {@link #getThumbnail()}.
+ * @param bitmap The bitmap that is retrieved from native code.
+ */
+ void onThumbnailReceived(Bitmap bitmap);
+ }
+
+ @VisibleForTesting
+ ContextMenuHelper() {}
private ContextMenuHelper(long nativeContextMenuHelper) {
mNativeContextMenuHelper = nativeContextMenuHelper;
@@ -108,7 +126,7 @@ public class ContextMenuHelper implements OnCreateContextMenuListener {
List<Pair<Integer, List<ContextMenuItem>>> items =
mPopulator.buildContextMenu(null, mContext, mCurrentContextMenuParams);
- ContextMenuUi menuUi = new TabularContextMenuUi();
+ ContextMenuUi menuUi = new TabularContextMenuUi(this);
menuUi.displayMenu(mContext, mCurrentContextMenuParams, items, mCallback, mOnMenuShown,
mOnMenuClosed);
return;
@@ -164,6 +182,22 @@ public class ContextMenuHelper implements OnCreateContextMenuListener {
ShareHelper.shareImage(activity, jpegImageData);
}
+ /**
+ * Gets the thumbnail of the current image that triggered the context menu.
+ */
+ public void getThumbnail() {
David Trainor- moved to gerrit 2017/03/30 05:03:14 I actually think this (and maybe shareImage() with
JJ 2017/03/30 16:00:25 You make an interesting point on that native can c
JJ 2017/03/30 17:09:00 Checked it out! It's not impossible, but there are
David Trainor- moved to gerrit 2017/03/30 23:45:14 You could probably just do it all with finals. Fo
JJ 2017/03/31 02:28:45 It's not the Java side that's the problem. That pa
+ if (mNativeContextMenuHelper == 0) return;
+ nativeRetrieveHeaderThumbnail(mNativeContextMenuHelper);
+ }
+
+ @CalledByNative
+ private void onHeaderThumbnailReceived(WindowAndroid windowAndroid, byte[] jpegImageData) {
+ Bitmap bitmap = BitmapFactory.decodeByteArray(jpegImageData, 0, jpegImageData.length);
+ if (mOnThumbnailReceivedListener != null) {
+ mOnThumbnailReceivedListener.onThumbnailReceived(bitmap);
+ }
+ }
+
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
List<Pair<Integer, List<ContextMenuItem>>> items =
@@ -174,6 +208,14 @@ public class ContextMenuHelper implements OnCreateContextMenuListener {
}
/**
+ * Sets the listener for retrieving a thumbnail when calling {@link #getThumbnail()}.
+ * @param listener The listener that will be called once a thumbnail is retrieved.
+ */
+ public void setOnThumbnailReceivedListener(OnThumbnailReceivedListener listener) {
+ mOnThumbnailReceivedListener = listener;
+ }
+
+ /**
* @return The {@link ContextMenuPopulator} responsible for populating the context menu.
*/
@VisibleForTesting
@@ -186,4 +228,5 @@ public class ContextMenuHelper implements OnCreateContextMenuListener {
private native void nativeSearchForImage(long nativeContextMenuHelper);
private native void nativeShareImage(long nativeContextMenuHelper);
private native void nativeOnContextMenuClosed(long nativeContextMenuHelper);
+ private native void nativeRetrieveHeaderThumbnail(long nativeContextMenuHelper);
}

Powered by Google App Engine
This is Rietveld 408576698