diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarView.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarView.kt index e015cd1720..da73f560ca 100644 --- a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarView.kt +++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarView.kt @@ -4,17 +4,22 @@ import android.content.ClipData import android.content.ClipDescription.MIMETYPE_TEXT_PLAIN import android.content.ClipboardManager import android.content.Context.CLIPBOARD_SERVICE +import android.view.Gravity import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.PopupMenu +import android.widget.LinearLayout +import android.widget.PopupWindow import androidx.core.content.ContextCompat +import androidx.core.view.isVisible import kotlinx.android.extensions.LayoutContainer +import kotlinx.android.synthetic.main.browser_toolbar_popup_window.view.* import mozilla.components.browser.domains.autocomplete.ShippedDomainsProvider import mozilla.components.browser.session.Session import mozilla.components.browser.toolbar.BrowserToolbar import mozilla.components.support.ktx.android.util.dpToFloat import mozilla.components.support.ktx.android.util.dpToPx +import org.jetbrains.anko.dimen import org.mozilla.fenix.R import org.mozilla.fenix.customtabs.CustomTabToolbarMenu import org.mozilla.fenix.ext.components @@ -47,31 +52,34 @@ class BrowserToolbarView( init { view.setOnUrlLongClickListener { - val popup = PopupMenu(view.context, view) - popup.menuInflater.inflate(R.menu.browser_toolbar_popup_menu, popup.menu) - popup.show() - val clipboard = view.context.getSystemService(CLIPBOARD_SERVICE) as ClipboardManager - - popup.menu.findItem(R.id.paste)?.isVisible = clipboard.containsText() - popup.menu.findItem(R.id.paste_and_go)?.isVisible = clipboard.containsText() - - popup.setOnMenuItemClickListener { - when (it.itemId) { - R.id.copy -> { - clipboard.primaryClip = ClipData.newPlainText("Text", view.url.toString()) - } - - R.id.paste -> { - interactor.onBrowserToolbarPaste(clipboard.primaryClip?.getItemAt(0)?.text.toString()) - } - - R.id.paste_and_go -> { - interactor.onBrowserToolbarPasteAndGo(clipboard.primaryClip?.getItemAt(0)?.text.toString()) - } - } + val customView = LayoutInflater.from(view.context).inflate(R.layout.browser_toolbar_popup_window, null) + val popupWindow = PopupWindow(customView, + LinearLayout.LayoutParams.WRAP_CONTENT, + view.context.dimen(R.dimen.context_menu_height), true + ) + + popupWindow.showAsDropDown(view, view.context.dimen(R.dimen.context_menu_x_offset), 0, Gravity.START) + + customView.paste.isVisible = clipboard.containsText() + customView.paste_and_go.isVisible = clipboard.containsText() + + customView.copy.setOnClickListener { + popupWindow.dismiss() + clipboard.primaryClip = ClipData.newPlainText("Text", view.url.toString()) } + + customView.paste.setOnClickListener { + popupWindow.dismiss() + interactor.onBrowserToolbarPaste(clipboard.primaryClip?.getItemAt(0)?.text.toString()) + } + + customView.paste_and_go.setOnClickListener { + popupWindow.dismiss() + interactor.onBrowserToolbarPasteAndGo(clipboard.primaryClip?.getItemAt(0)?.text.toString()) + } + true } diff --git a/app/src/main/res/layout/browser_toolbar_popup_window.xml b/app/src/main/res/layout/browser_toolbar_popup_window.xml new file mode 100644 index 0000000000..b3d94c630c --- /dev/null +++ b/app/src/main/res/layout/browser_toolbar_popup_window.xml @@ -0,0 +1,46 @@ + + + +