From 0c77499862b2b07c4812d6cec589ec60873cc3be Mon Sep 17 00:00:00 2001 From: Manuel Martin Date: Tue, 27 Aug 2019 21:10:38 +0200 Subject: [PATCH] Fix context menu size and scrolling issues (#1676) --- .../org/mozilla/vrbrowser/ui/views/ContextMenu.java | 8 ++++++++ .../ui/widgets/dialogs/ContextMenuWidget.java | 11 ++++++----- app/src/main/res/layout/context_menu.xml | 2 +- app/src/main/res/layout/context_menu_item.xml | 2 +- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/views/ContextMenu.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/views/ContextMenu.java index 7f3d352a7..d0e72b189 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/views/ContextMenu.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/views/ContextMenu.java @@ -11,6 +11,8 @@ import android.widget.FrameLayout; import androidx.databinding.DataBindingUtil; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import org.mozilla.vrbrowser.R; import org.mozilla.vrbrowser.databinding.ContextMenuBinding; @@ -47,6 +49,12 @@ private void initialize(Context aContext) { mBinding = DataBindingUtil.inflate(inflater, R.layout.context_menu, this, true); mContextMenuAdapter = new ContextMenuAdapter(mContextMenuClickCallback); mBinding.contextMenuList.setAdapter(mContextMenuAdapter); + mBinding.contextMenuList.setLayoutManager(new LinearLayoutManager(getContext()) { + @Override + public boolean canScrollVertically() { + return false; + } + }); mBinding.executePendingBindings(); } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/dialogs/ContextMenuWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/dialogs/ContextMenuWidget.java index 71ce7ce45..81d721107 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/dialogs/ContextMenuWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/dialogs/ContextMenuWidget.java @@ -58,9 +58,8 @@ private void initialize() { @Override protected void initializeWidgetPlacement(WidgetPlacement aPlacement) { aPlacement.visible = false; - aPlacement.width = WidgetPlacement.pixelDimension(getContext(), R.dimen.browser_width_pixels)/2; - mMaxHeight = WidgetPlacement.dpDimension(getContext(), R.dimen.prompt_height); - aPlacement.height = mMaxHeight; + aPlacement.width = WidgetPlacement.dpDimension(getContext(), R.dimen.context_menu_row_width); + aPlacement.height = WidgetPlacement.dpDimension(getContext(), R.dimen.context_menu_row_height); aPlacement.parentAnchorX = 0.0f; aPlacement.parentAnchorY = 1.0f; aPlacement.anchorX = 0.5f; @@ -89,10 +88,12 @@ public void onGlobalLayout() { PointF anchor = anchorForCurrentMousePosition(); mWidgetPlacement.anchorX = anchor.x; mWidgetPlacement.anchorY = anchor.y; + int paddingH = getPaddingStart() + getPaddingEnd(); + int paddingV = getPaddingTop() + getPaddingBottom(); mWidgetPlacement.translationX = mMousePos.x * WidgetPlacement.worldToWindowRatio(getContext()); mWidgetPlacement.translationY = -(mMousePos.y * WidgetPlacement.worldToWindowRatio(getContext())); - mWidgetPlacement.width = (int)(mContextMenu.getWidth()/mWidgetPlacement.density); - mWidgetPlacement.height = (int)(mContextMenu.getHeight()/mWidgetPlacement.density); + mWidgetPlacement.width = (int)((mContextMenu.getWidth()+paddingH*2)/mWidgetPlacement.density); + mWidgetPlacement.height = (int)((mContextMenu.getHeight()+paddingV*2)/mWidgetPlacement.density); mWidgetManager.updateWidget(ContextMenuWidget.this); } }); diff --git a/app/src/main/res/layout/context_menu.xml b/app/src/main/res/layout/context_menu.xml index e305b7a60..b2d785afa 100644 --- a/app/src/main/res/layout/context_menu.xml +++ b/app/src/main/res/layout/context_menu.xml @@ -2,7 +2,7 @@ diff --git a/app/src/main/res/layout/context_menu_item.xml b/app/src/main/res/layout/context_menu_item.xml index 9553f716c..35c5c1e64 100644 --- a/app/src/main/res/layout/context_menu_item.xml +++ b/app/src/main/res/layout/context_menu_item.xml @@ -14,7 +14,7 @@