B4A Library [Lib] Air View

Dave O

Well-Known Member
Licensed User
Longtime User
As for the query on the Samsung SDK. An SDK doesn't exist.

Just to update this thread (I'm interested in adding S Pen support to my Quick Proto sketching app), Samsung has since published their SDKs here:
http://developer.samsung.com/galaxy#pen

Would love to see some of these wrapped for use in B4A. (Libraries are beyond my modest coding skills, I reckon.)

In the meantime, I'll give your AirView lib a whirl on my Note 8 tablet and report back. Thanks!
 

Dave O

Well-Known Member
Licensed User
Longtime User
The Air View demo works great on my Galaxy Note 8 tablet.

FWIW, there's no Finger/Auto option in my Settings > S Pen > Air View (Android 4.4.2), and using a finger does not seem to work. But that's not an issue for my purposes.

Keen to add this to my prototyping app. Thanks!
 

Dave O

Well-Known Member
Licensed User
Longtime User
Just added some hovers to my Quick Proto app (because most of my users are on Galaxy Note devices and the hovers are good for icon hints and custom tool pointers).

I was getting a lot of crashes (with no error showing in the logs), but soon discovered that it was because my hover event handlers were calling subs that had "doEvents" in them. It seems that Air View (like Gesture Detector) doesn't like doEvents. Changing these calls to use CallSubDelayed fixed the crashes, and everything works well now.

Thanks!
 

adrianstanescu85

Active Member
Licensed User
Longtime User
Hello Dave,

I'm very interested in changing the doEvents to CallSubDelayed, I got a few crashes in one of my apps that uses doEvents. Can you give a short example on how to do the replacement please?

Thank you!
 

Dave O

Well-Known Member
Licensed User
Longtime User
Hi Adrian,

Here's an example where I put a hover event on a button (triggered by AirViewListener), so I could show a toast-style hint of the button's purpose when they hovered over it with the stylus:

B4X:
Sub buttonHover_HoverStart(x As Float, y As Float)
   Dim hoverText As String
   Dim sourceButton As View = Sender
   Select sourceButton
     Case penButton
         hoverText = "Pen"
     Case highlighterButton
         hoverText = "Highlighter"
   End Select
   Dim tempPosition As percentPosition
   tempPosition.y = 90
   tempPosition.x = Min((sourceButton.Left / Activity.Width) * 100 + 5, 90)
   CallSubDelayed3(Me, "showHoverToast", hoverText, tempPosition)
End Sub

Sub showHoverToast(textArg As String, positionArg As percentPosition)
   hoverToast.ToastMessageShow2(textArg, 2, positionArg.y, positionArg.x, "", Colors.White, Colors.DarkGray, 16, True, 10)
End Sub

In the original code, the CallSubDelayed wasn't there - that line was just the "ToastMessageShow2" call (using Margret's Custom Toast class).

However, it resulted in crashes which usually left no error or exception in the log. Some digging in the forums suggested that certain libraries like Air View and Gesture Detector don't like DoEvents in calls from their events. When I looked in Margret's source code, there was indeed a DoEvents call in "ToastMessageShow2".

So, instead of mucking with Margret's code, I simply moved the "ToastMessageShow2" call to its own sub (shown above) and called it with CallSubDelayed. That lets the hover event finish before the toast call is started. The toast call still does its DoEvents thing, but the hover event has already finished so it no longer cares.

Hope this helps!
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…