B4A Library [Lib] Air View

Ok here is a relatively simple, Free to use, library that utilizes the Hover gesture. This is what is used by Samsung to create their 'Air View' on the S4 and I believe the Note 2 and some Note tabs. I also believe this works on 1 or 2 SONY models, but not sure which ones. Hopefully more devices will support in future.

The release is v1.00 but the code is still the same as the beta as no problems were raised.

Update: v 1.1:
It was reported to me that on earlier versions (I'm assuming < 14), a NoClassDefFoundError occurred. I have amended the library to solve this issue.
Thanks to @mcmanu for reporting ;)


There is only one method and 3 raised events.


AirView
Author:
BarxDroid
Version: 1.10
  • AirViewListener
    Events:
    • HoverEnd (x as Float As , y as Float As )
    • HoverMove (x as Float As , y as Float As )
    • HoverStart (x as Float As , y as Float As )
    Methods:
    • Initialize (view As View, Eventname As String)
      Initializes a Hover Listener against a given View.

      View - The View that will react to the Hover event
      EventName - The sub that will handle the events

      Be sure to add the following to the manifest using the Manifest Editor:-
      AddActivityText(Main, <intent-filter>
      <action android:name="com.sec.android.airview.HOVER" />
      </intent-filter>)

To install, simply unpack and copy the .jar and .xml to libs folder as usual.

You must edit the manifest and add the following code:

B4X:
AddActivityText(Main, <intent-filter>
<action android:name="com.sec.android.airview.HOVER" />
</intent-filter>)

There is a demo project added below too to demonstrate the usage. I have updated the code a tiny bit compared to the beta demo, just to make the placement of the panel shown on the button hover prettier.

Notes:
The x, y, co-ordinates returned are relative to the assigned view, not the activity.
The device HAS to support the Hover gesture. To my knowledge the only device that support are the Samsung AirView compatible devices. S4, Note 2 (think Note too but not 100%) and some Sammy tabs). Please report compatibility to help others.

As always, any questions, ask away. All feedback welcome, Good or Bad

Source Code available Here
 

Attachments

  • AirViewDemo.zip
    6.4 KB · Views: 642
  • AirView.zip
    3.4 KB · Views: 610
Last edited:

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!
 
Top