Bug 1417361: Use anchor for context menu on tablet. r=liuche

This uses the same anchors as the old code so should be low risk.

MozReview-Commit-ID: 7pA3SSRghv0

--HG--
extra : rebase_source : b7b4bb7afbd7569085416c5f1d74e714eef4216d
This commit is contained in:
Michael Comella 2017-11-28 16:35:54 -08:00
Родитель b0ebfcccd9
Коммит 9e2b82c64c
7 изменённых файлов: 34 добавлений и 24 удалений

Просмотреть файл

@ -138,8 +138,9 @@ public class StreamRecyclerAdapter extends RecyclerView.Adapter<StreamViewHolder
if (type == RowItemType.TOP_PANEL.getViewType()) {
return new TopPanelRow(inflater.inflate(TopPanelRow.LAYOUT_ID, parent, false), onUrlOpenListener, new TopPanelRow.OnCardLongClickListener() {
@Override
public boolean onClick(final TopSite topSite, final int absolutePosition, final int faviconWidth, final int faviconHeight) {
openContextMenuForTopSite(topSite, absolutePosition, parent, faviconWidth, faviconHeight);
public boolean onClick(final TopSite topSite, final int absolutePosition,
final View tabletContextMenuAnchor, final int faviconWidth, final int faviconHeight) {
openContextMenuForTopSite(topSite, absolutePosition, tabletContextMenuAnchor, parent, faviconWidth, faviconHeight);
return true;
}
});
@ -352,31 +353,32 @@ public class StreamRecyclerAdapter extends RecyclerView.Adapter<StreamViewHolder
.set(ActivityStreamTelemetry.Contract.ACTION_POSITION, actionPosition)
.set(ActivityStreamTelemetry.Contract.INTERACTION, interactionExtra);
openContextMenuInner(snackbarAnchor, extras, menuMode, model,
openContextMenuInner(webpageItemRow.getTabletContextMenuAnchor(), snackbarAnchor, extras, menuMode, model,
/* shouldOverrideWithImageProvider */ true, // we use image providers in HighlightItem.pageIconLayout.
webpageItemRow.getTileWidth(), webpageItemRow.getTileHeight());
}
private void openContextMenuForTopSite(final TopSite topSite, final int absolutePosition, final View snackbarAnchor,
final int faviconWidth, final int faviconHeight) {
private void openContextMenuForTopSite(final TopSite topSite, final int absolutePosition, final View tabletContextMenuAnchor,
final View snackbarAnchor, final int faviconWidth, final int faviconHeight) {
ActivityStreamTelemetry.Extras.Builder extras = ActivityStreamTelemetry.Extras.builder()
.forTopSite(topSite)
.set(ActivityStreamTelemetry.Contract.ACTION_POSITION, absolutePosition);
openContextMenuInner(snackbarAnchor, extras, ActivityStreamContextMenu.MenuMode.TOPSITE, topSite,
openContextMenuInner(tabletContextMenuAnchor, snackbarAnchor, extras, ActivityStreamContextMenu.MenuMode.TOPSITE, topSite,
/* shouldOverrideWithImageProvider */ false, // we only use favicons for top sites.
faviconWidth, faviconHeight);
}
/**
* @param snackbarAnchor See {@link ActivityStreamContextMenu#show(View, ActivityStreamTelemetry.Extras.Builder, ActivityStreamContextMenu.MenuMode, WebpageModel, boolean, HomePager.OnUrlOpenListener, HomePager.OnUrlOpenInBackgroundListener, int, int)}
* @param snackbarAnchor See {@link ActivityStreamContextMenu#show(View, View, ActivityStreamTelemetry.Extras.Builder, ActivityStreamContextMenu.MenuMode, WebpageModel, boolean, HomePager.OnUrlOpenListener, HomePager.OnUrlOpenInBackgroundListener, int, int)} )}
* for additional details.
*/
private void openContextMenuInner(final View snackbarAnchor, final ActivityStreamTelemetry.Extras.Builder extras,
private void openContextMenuInner(final View tabletContextMenuAnchor, final View snackbarAnchor,
final ActivityStreamTelemetry.Extras.Builder extras,
final ActivityStreamContextMenu.MenuMode menuMode, final WebpageModel webpageModel,
final boolean shouldOverrideWithImageProvider,
final int faviconWidth, final int faviconHeight) {
ActivityStreamContextMenu.show(snackbarAnchor,
ActivityStreamContextMenu.show(tabletContextMenuAnchor, snackbarAnchor,
extras,
menuMode,
webpageModel,

Просмотреть файл

@ -340,13 +340,15 @@ public abstract class ActivityStreamContextMenu
}
/**
* @param anchor A view to anchor the Snackbar on. Don't use items in the recyclerView because these views can be
* @param tabletContextMenuAnchor A view to anchor the context menu on tablet, where it doesn't fill the screen.
* @param snackbarAnchor A view to anchor the Snackbar on. Don't use items in the recyclerView because these views can be
* removed from the view hierarchy when the recyclerView scrolls.
* @param shouldOverrideIconWithImageProvider true if the favicon should be replaced with an image provider,
* if applicable, false otherwise.
*/
@RobocopTarget
public static ActivityStreamContextMenu show(View anchor, ActivityStreamTelemetry.Extras.Builder telemetryExtraBuilder,
public static ActivityStreamContextMenu show(final View tabletContextMenuAnchor, final View snackbarAnchor,
ActivityStreamTelemetry.Extras.Builder telemetryExtraBuilder,
final MenuMode menuMode, final WebpageModel item,
final boolean shouldOverrideIconWithImageProvider,
HomePager.OnUrlOpenListener onUrlOpenListener,
@ -355,12 +357,12 @@ public abstract class ActivityStreamContextMenu
final ActivityStreamContextMenu menu;
if (!HardwareUtils.isTablet()) {
menu = new BottomSheetContextMenu(anchor,
menu = new BottomSheetContextMenu(snackbarAnchor,
telemetryExtraBuilder, menuMode,
item, shouldOverrideIconWithImageProvider, onUrlOpenListener, onUrlOpenInBackgroundListener,
tilesWidth, tilesHeight);
} else {
menu = new PopupContextMenu(anchor,
menu = new PopupContextMenu(tabletContextMenuAnchor, snackbarAnchor,
telemetryExtraBuilder, menuMode,
item, onUrlOpenListener, onUrlOpenInBackgroundListener);
}

Просмотреть файл

@ -26,23 +26,24 @@ import org.mozilla.gecko.activitystream.homepanel.model.WebpageModel;
private final PopupWindow popupWindow;
private final NavigationView navigationView;
private final View anchor;
private final View contextMenuAnchor;
public PopupContextMenu(final View anchor,
public PopupContextMenu(final View contextMenuAnchor,
final View snackbarAnchor,
final ActivityStreamTelemetry.Extras.Builder telemetryExtraBuilder,
final MenuMode mode,
final WebpageModel item,
HomePager.OnUrlOpenListener onUrlOpenListener,
HomePager.OnUrlOpenInBackgroundListener onUrlOpenInBackgroundListener) {
super(anchor,
super(snackbarAnchor,
telemetryExtraBuilder,
mode,
item,
onUrlOpenListener,
onUrlOpenInBackgroundListener);
final Context context = anchor.getContext();
final Context context = contextMenuAnchor.getContext();
this.anchor = anchor;
this.contextMenuAnchor = contextMenuAnchor;
final LayoutInflater inflater = LayoutInflater.from(context);
@ -76,9 +77,9 @@ import org.mozilla.gecko.activitystream.homepanel.model.WebpageModel;
public void show() {
// By default popupWindow follows the pre-material convention of displaying the popup
// below a View. We need to shift it over the view:
popupWindow.showAsDropDown(anchor,
popupWindow.showAsDropDown(contextMenuAnchor,
0,
-(anchor.getHeight() + anchor.getPaddingBottom()));
-(contextMenuAnchor.getHeight() + contextMenuAnchor.getPaddingBottom()));
}
public void dismiss() {

Просмотреть файл

@ -92,6 +92,6 @@ public class TopPanelRow extends StreamViewHolder {
}
public interface OnCardLongClickListener {
boolean onClick(TopSite topSite, int absolutePosition, int faviconWidth, int faviconHeight);
boolean onClick(TopSite topSite, int absolutePosition, View tabletContextMenuAnchor, int faviconWidth, int faviconHeight);
}
}

Просмотреть файл

@ -41,6 +41,7 @@ public class WebpageItemRow extends StreamViewHolder {
private final TextView pageTitleView;
private final ImageView pageSourceIconView;
private final TextView pageSourceView;
private final ImageView menuButton;
public WebpageItemRow(final View itemView, final OnMenuButtonClickListener onMenuButtonClickListener) {
super(itemView);
@ -51,7 +52,7 @@ public class WebpageItemRow extends StreamViewHolder {
pageDomainView = (TextView) itemView.findViewById(R.id.page_domain);
pageSourceIconView = (ImageView) itemView.findViewById(R.id.page_source_icon);
final ImageView menuButton = (ImageView) itemView.findViewById(R.id.menu);
menuButton = (ImageView) itemView.findViewById(R.id.menu);
menuButton.setImageDrawable(
DrawableUtil.tintDrawable(menuButton.getContext(), R.drawable.menu, Color.LTGRAY));
TouchTargetUtil.ensureTargetHitArea(menuButton, itemView);
@ -171,6 +172,10 @@ public class WebpageItemRow extends StreamViewHolder {
}
}
public View getTabletContextMenuAnchor() {
return menuButton;
}
public interface OnMenuButtonClickListener {
void onMenuButtonClicked(WebpageItemRow row, int position);
}

Просмотреть файл

@ -52,7 +52,7 @@ import java.util.concurrent.Future;
@Override
public boolean onLongClick(View v) {
if (onCardLongClickListener != null) {
return onCardLongClickListener.onClick(topSite, absolutePosition, faviconView.getWidth(), faviconView.getHeight());
return onCardLongClickListener.onClick(topSite, absolutePosition, card, faviconView.getWidth(), faviconView.getHeight());
}
return false;
}

Просмотреть файл

@ -231,7 +231,7 @@ public class testActivityStreamContextMenu extends OldBaseTest {
private void testMenuForItem(WebpageModel item, boolean bookmarked, boolean pinned, boolean visited) {
final View anchor = new View(getActivity());
final ActivityStreamContextMenu menu = ActivityStreamContextMenu.show(
anchor, ActivityStreamTelemetry.Extras.builder(),
anchor, anchor, ActivityStreamTelemetry.Extras.builder(),
ActivityStreamContextMenu.MenuMode.HIGHLIGHT, item,
false, null, null, 100, 100);