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

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

Issue 2868403003: added scale animation for context menu (Closed)
Patch Set: fixing broken tests Created 3 years, 6 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/TabularContextMenuUi.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/TabularContextMenuUi.java b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/TabularContextMenuUi.java
index 09428c07607022ac3b53855c70553f103e64cdfe..7a7e5c125a29017108dab2dbfb3e6060d42b70d0 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/TabularContextMenuUi.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/TabularContextMenuUi.java
@@ -5,7 +5,6 @@
package org.chromium.chrome.browser.contextmenu;
import android.app.Activity;
-import android.app.Dialog;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.graphics.Bitmap;
@@ -14,7 +13,6 @@ import android.graphics.Shader;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.support.design.widget.TabLayout;
-import android.support.v4.view.ViewPager;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.util.Pair;
@@ -31,6 +29,8 @@ import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.Callback;
import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.R;
+import org.chromium.chrome.browser.widget.ContextMenuDialog;
+import org.chromium.content.browser.RenderCoordinates;
import java.util.ArrayList;
import java.util.List;
@@ -39,71 +39,88 @@ import java.util.List;
* A custom dialog that separates each group into separate tabs. It uses a dialog instead.
*/
public class TabularContextMenuUi implements ContextMenuUi, AdapterView.OnItemClickListener {
- private Dialog mDialog;
+ private ContextMenuDialog mContextMenuDialog;
private Callback<Integer> mCallback;
private int mMenuItemHeight;
private ImageView mHeaderImageView;
private Runnable mOnShareItemClicked;
+ private View mPagerView;
+ private RenderCoordinates mRenderCoordinates;
public TabularContextMenuUi(Runnable onShareItemClicked) {
mOnShareItemClicked = onShareItemClicked;
}
@Override
- public void displayMenu(Activity activity, ContextMenuParams params,
+ public void displayMenu(final Activity activity, ContextMenuParams params,
List<Pair<Integer, List<ContextMenuItem>>> items, Callback<Integer> onItemClicked,
final Runnable onMenuShown, final Runnable onMenuClosed) {
mCallback = onItemClicked;
- mDialog = createDialog(activity, params, items);
- mDialog.getWindow().setBackgroundDrawable(ApiCompatibilityUtils.getDrawable(
- activity.getResources(), R.drawable.white_with_rounded_corners));
+ float density = Resources.getSystem().getDisplayMetrics().density;
+ final float touchPointXPx = params.getTriggeringTouchXDp() * density;
+ final float touchPointYPx = params.getTriggeringTouchYDp() * density;
- mDialog.setOnShowListener(new DialogInterface.OnShowListener() {
+ mContextMenuDialog =
+ createContextMenuDialog(activity, params, items, touchPointXPx, touchPointYPx);
+
+ mContextMenuDialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialogInterface) {
onMenuShown.run();
}
});
- mDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
+ mContextMenuDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialogInterface) {
onMenuClosed.run();
}
});
- mDialog.show();
+ mContextMenuDialog.show();
}
/**
* Returns the fully complete dialog based off the params and the itemGroups.
+ *
* @param activity Used to inflate the dialog.
* @param params Used to get the header title.
* @param itemGroups If there is more than one group it will create a paged view.
+ * @param touchPointYPx The x-coordinate of the touch that triggered the context menu.
+ * @param touchPointXPx The y-coordinate of the touch that triggered the context menu.
* @return Returns a final dialog that does not have a background can be displayed using
* {@link AlertDialog#show()}.
*/
- private Dialog createDialog(Activity activity, ContextMenuParams params,
- List<Pair<Integer, List<ContextMenuItem>>> itemGroups) {
- Dialog dialog = new Dialog(activity);
- dialog.setContentView(createPagerView(activity, params, itemGroups));
+ private ContextMenuDialog createContextMenuDialog(Activity activity, ContextMenuParams params,
+ List<Pair<Integer, List<ContextMenuItem>>> itemGroups, float touchPointXPx,
+ float touchPointYPx) {
+ View view = LayoutInflater.from(activity).inflate(R.layout.tabular_context_menu, null);
+
+ mPagerView = initPagerView(activity, params, itemGroups,
+ (TabularContextMenuViewPager) view.findViewById(R.id.custom_pager));
+
+ final ContextMenuDialog dialog = new ContextMenuDialog(activity, R.style.DialogWhenLarge,
+ touchPointXPx, touchPointYPx, mPagerView, mRenderCoordinates);
+ dialog.setContentView(view);
+
return dialog;
}
/**
* Creates a ViewPageAdapter based off the given list of views.
- * @param activity Used to inflate the new ViewPager
+ *
+ * @param activity Used to inflate the new ViewPager.
* @param params Used to get the header text.
* @param itemGroups The list of views to put into the ViewPager. The string is the title of the
- * tab
+ * tab.
+ * @param viewPager The {@link TabularContextMenuViewPager} to initialize.
* @return Returns a complete tabular context menu view.
*/
@VisibleForTesting
- View createPagerView(Activity activity, ContextMenuParams params,
- List<Pair<Integer, List<ContextMenuItem>>> itemGroups) {
- View view = LayoutInflater.from(activity).inflate(R.layout.tabular_context_menu, null);
-
+ View initPagerView(Activity activity, ContextMenuParams params,
+ List<Pair<Integer, List<ContextMenuItem>>> itemGroups,
+ TabularContextMenuViewPager viewPager) {
List<Pair<String, ViewGroup>> viewGroups = new ArrayList<>();
int maxCount = 0;
for (int i = 0; i < itemGroups.size(); i++) {
@@ -118,30 +135,23 @@ public class TabularContextMenuUi implements ContextMenuUi, AdapterView.OnItemCl
createContextMenuPageUi(
activity, params, itemGroup.second, isImageTab, maxCount)));
}
- if (itemGroups.size() == 1) {
- viewGroups.get(0)
- .second.getChildAt(0)
- .findViewById(R.id.context_header_layout)
- .setBackgroundResource(R.color.google_grey_100);
- }
-
- TabularContextMenuViewPager pager =
- (TabularContextMenuViewPager) view.findViewById(R.id.custom_pager);
- pager.setAdapter(new TabularContextMenuPagerAdapter(viewGroups));
- TabLayout tabLayout = (TabLayout) view.findViewById(R.id.tab_layout);
+ viewPager.setAdapter(new TabularContextMenuPagerAdapter(viewGroups));
+ TabLayout tabLayout = (TabLayout) viewPager.findViewById(R.id.tab_layout);
if (itemGroups.size() <= 1) {
tabLayout.setVisibility(View.GONE);
} else {
- tabLayout.setupWithViewPager((ViewPager) view.findViewById(R.id.custom_pager));
+ tabLayout.setBackgroundResource(R.drawable.grey_with_top_rounded_corners);
+ tabLayout.setupWithViewPager(viewPager);
}
- return view;
+ return viewPager;
}
/**
* Creates the view of a context menu. Based off the Context Type, it'll adjust the list of
* items and display only the ones that'll be on that specific group.
+ *
* @param activity Used to get the resources of an item.
* @param params used to create the header text.
* @param items A set of Items to display in a context menu. Filtered based off the type.
@@ -172,7 +182,7 @@ public class TabularContextMenuUi implements ContextMenuUi, AdapterView.OnItemCl
@Override
public void run() {
mOnShareItemClicked.run();
- mDialog.dismiss();
+ mContextMenuDialog.dismiss();
}
};
TabularContextMenuListAdapter listAdapter =
@@ -245,6 +255,7 @@ public class TabularContextMenuUi implements ContextMenuUi, AdapterView.OnItemCl
* To save time measuring the height, this method gets an item if the height has not been
* previous measured and multiplies it by count of the total amount of items. It is fine if the
* height too small as the ListView will scroll through the other values.
+ *
* @param listView The ListView to measure the surrounding padding.
* @param listAdapter The adapter which contains the items within the list.
* @return Returns the combined height of the padding of the ListView and the approximate height
@@ -263,8 +274,8 @@ public class TabularContextMenuUi implements ContextMenuUi, AdapterView.OnItemCl
}
/**
- * When an thumbnail is retrieved for the header of an image, this will set the header to
- * that particular bitmap.
+ * When an thumbnail is retrieved for the header of an image, this will set the header to that
+ * particular bitmap.
*/
public void onImageThumbnailRetrieved(Bitmap bitmap) {
if (mHeaderImageView != null) {
@@ -274,7 +285,15 @@ public class TabularContextMenuUi implements ContextMenuUi, AdapterView.OnItemCl
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
- mDialog.dismiss();
+ mContextMenuDialog.dismiss();
mCallback.onResult((int) id);
}
+
+ /**
+ * Gives this class access to the render coordinates to allow access to the total size of the
+ * toolbar and tab strip.
+ */
+ public void setRenderCoordinates(RenderCoordinates renderCoordinates) {
+ mRenderCoordinates = renderCoordinates;
+ }
}

Powered by Google App Engine
This is Rietveld 408576698