Page 1 of 1

Touchscreen and DisplayPopupMenu()

Posted: Tue May 14, 2019 2:21 pm
by Dirk Geppert
Hi,

the manual says for DisplayPopupMenu(#Menu) : "Displays a PopupMenu under the current mouse position or at the given screen location".

On devices with no mouse, likes phones or Touchscreens in generell, the menu appears on top left (0, 0) of the Screen.
Is there a way to determine the coordinates of a TouchScreen tap? Then I could store and use it with OpenMenu...

Ciao dige

Re: Touchscreen and DisplayPopupMenu()

Posted: Sat May 18, 2019 1:58 pm
by falsam
Works with an Android terminal.

Code: Select all

Declare DisplayMenuPopUp()
Declare IsMobileDevice()

;Remove debug window
!$('div').eq(0).remove()

OpenWindow(0, 0, 0, 0, 0, "", #PB_Window_Background)

If CreatePopupMenu(0)
  MenuItem(1, "item 1")
  MenuItem(2, "item 2")
  MenuItem(3, "etc ...")
EndIf

If IsMobileDevice()
  BindEvent(#PB_Event_LeftClick, @DisplayMenuPopUp())
Else
  BindEvent(#PB_Event_RightClick, @DisplayMenuPopUp())
EndIf

Procedure DisplayMenuPopUp()
  DisplayPopupMenu(0, WindowID(0))
EndProcedure

Procedure IsMobileDevice()  
  !if ( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
  !   return true;
  ! } else {
  !   return false;
  ! }
EndProcedure
Test with an apk ;)

Re: Touchscreen and DisplayPopupMenu()

Posted: Sat May 18, 2019 2:06 pm
by falsam
I could have used DeviceInfo(#PB_Device_Platform) to determine if I am on a mobile terminal ....

Re: Touchscreen and DisplayPopupMenu()

Posted: Wed Sep 11, 2019 8:46 pm
by majikeyric
DeviceInfo() is not reliable, I personnaly call the Mobile Detect PHP script (http://mobiledetect.net/) at the beginning of my apps.