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: 648
  • AirView.zip
    3.4 KB · Views: 621
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
No hands :)

SS-2013-06-25_12.38.18.png


Works very nice.
Does Samsung SDK include a method to check whether AirView is enabled?

Don't forget to add it to the libraries wiki... Libraries - Basic4android Wiki
 

barx

Well-Known Member
Licensed User
Longtime User
@Erel, thanks for testing it out, your feedback is always welcomed. As for the query on the Samsung SDK. An SDK doesn't exist. After searching high and low, i found that the feature is achieved with

B4X:
view.setOnHoverListener

Then a little voodoo with motionEvent and raising the right events. I will try to discover IF such a feature could be hacked in. No idea what to look for yet.

@jaames, thanks for confirming compatibility with the Note 2. it was assumed to work but I don't have such device to test the functionality.
 

barx

Well-Known Member
Licensed User
Longtime User
After plenty of reading I cannot figure a way to tell if the device support the Hover or not.

The way I envisaged an app being coded is as follows,

code the app and include AirView, build the UI elements as though AirView IS supported. If it is indeed supported then great, your app supports a great new feature. If not, the end user is non the wiser. No errors occur or anything like that.

The main use of the AirView seems to be for previewing data. i.e. preview a long text from the conversations activity. Preview news headlines from news categories activity, etc. NOT to show info that would be otherwise unobtainable.
 

ivan.tellez

Active Member
Licensed User
Longtime User
Great Lib

Hi, I just tested on my S4, works nice.

while i was testing noticed a little problem in the edges of the x Axis.

The demo only works between 10%x and 90%x.

So, I modiffied the demo to be Full screen and make InfoPnl to cover whole screes to test y axis.

And it works between 5%y and 95%y.


So, the Question; is this a normal behavior of the Air View?, its a problem with the lib? or its a limitation of the device?

By the way, is there an Air Gesture Lib planed?

Thanks
 

barx

Well-Known Member
Licensed User
Longtime User
The limitations found will be due to hardware capabilities. Checking out the Hover on the S4 lockscreen I see a similar action.

I was hoping to create libs for all the new Samsung features. Air Gestures, Smart Scroll, Smart Pause etc. but it appears that all but Air View and the irda functions would require an SDK from Samsung. Something they currently have no plans on releasing.

Personally I think it is a) daft and b) a shame to pack these features into a device and not let devs build apps that support them.

Even if they provided system intents for the actions, but I cannot find such info...

I will keep an eye on the situation but cannot promise anything.
 

maiconcwb

Member
Licensed User
Longtime User
The limitations found will be due to hardware capabilities. Checking out the Hover on the S4 lockscreen I see a similar action.

I was hoping to create libs for all the new Samsung features. Air Gestures, Smart Scroll, Smart Pause etc. but it appears that all but Air View and the irda functions would require an SDK from Samsung. Something they currently have no plans on releasing.

Personally I think it is a) daft and b) a shame to pack these features into a device and not let devs build apps that support them.

Even if they provided system intents for the actions, but I cannot find such info...

I will keep an eye on the situation but cannot promise anything.

barx!!! :sign0098:

I hope you can find out a way to make libs to all these features. But, first of all, I need to congratulate you and thank for this lib! It works perfectly on my S4 (I9505 brazilian version).

Many thanks! (and sorry my english...)
 

iwan.deejay

Member
Licensed User
Longtime User
Great library, congratulations and thank you to make it happen.
By the way, how to utilize it in ListView? I want to show the information of the item one by one. If you see in Note's or S4's messaging, the AirView shows the message in a listview.

Thank you
 

barx

Well-Known Member
Licensed User
Longtime User
I don't think it would be possible with a listview as the AirView lib requires a view to work on, not a part of a view

BUT... I think it could well work using a scrollview if you add your items on panels and pass the panel as the view. I may be wrong and haven't tested that.
 

iwan.deejay

Member
Licensed User
Longtime User
I don't think it would be possible with a listview as the AirView lib requires a view to work on, not a part of a view

BUT... I think it could well work using a scrollview if you add your items on panels and pass the panel as the view. I may be wrong and haven't tested that.

Thanks @Barx, I tried it and it works.
But, I tried to move the Information Panel according to the coordinate of the pointer, I put the code on _HoverMove event. It seems the coordinate is relative to the panel, not the whole screen.

Is there any way to override the coordinate? I tried to make another instance of AirViewListener, and I set the target to Activity, but it fails.

This is my code:
B4X:
#Region  Project Attributes 
   #ApplicationLabel: CustomListView Experiment
   #VersionCode: 1
   #VersionName: 1.0.0
   'SupportedOrientations possible values: unspecified, landscape or portrait.
   #SupportedOrientations: unspecified
   #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes 
   #FullScreen: False
   #IncludeTitle: True
#End Region

Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim clv As CustomListView
   Dim p(10) As Panel
   Dim Av(10) As AirViewListener
   Dim InfoPanel As Panel
   Dim ll As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
   clv.Initialize(Me, "CustomListView")
   Activity.AddView(clv.AsView, 0, 0, 100%x, 100%y)
   InfoPanel.Initialize("")
   InfoPanel.Color = Colors.White
   InfoPanel.Visible = False
   ll.Initialize("")
   ll.TextColor = Colors.Black
   InfoPanel.AddView(ll, 10dip, 10dip, 90dip, 30dip)
   Activity.AddView(InfoPanel, 0, 0, 110dip, 50dip)
   
   For i=0 To 9
      clv.AddTextItem("Item #" & i, i)
      p(i) = clv.GetPanel(i)
      Av(i).Initialize(p(i), "AirView")
   Next
End Sub

Sub AirView_HoverStart(x As Float, y As Float)
   Dim ps As Panel
   ps = Sender
   
   Dim l As Label
   l = ps.GetView(0)
   InfoPanel.Visible = True
   ll.Text = l.Text
End Sub

Sub AirView_HoverEnd(x As Float, y As Float)
   InfoPanel.Visible = False
End Sub

Sub AirView_HoverMove(x As Float, y As Float)
   InfoPanel.Top = y
   InfoPanel.Left = x
End Sub
 

Attachments

  • Screenshot1.png
    Screenshot1.png
    47 KB · Views: 442

barx

Well-Known Member
Licensed User
Longtime User
well, that's good news so far.

Yes the returned co-ordinates are relative to the view, not the screen.

If you look at the demo project attached at the first post. Take a look at the 2 _HoverMove subs you will see the ways to used to provide the required effect.

Hope this helps,
 

barx

Well-Known Member
Licensed User
Longtime User
The source code is available for this library. See first post for link...
 

adrianstanescu85

Active Member
Licensed User
Longtime User
Hello!

I successfully tried the included sample on my Galaxy Note 3 device, and it all works well with the S-Pen. However, this device surely does recognize a hovering finger, i.e. not S-Pen (for instance over the unlock screen).

My question is what modifications are necessary so that an airview-enabled device (like this Note 3) would recognize and act on a hovering finger instead of a hovering S-Pen.

Thank you!
Adrian
 

barx

Well-Known Member
Licensed User
Longtime User
Hello!

I successfully tried the included sample on my Galaxy Note 3 device, and it all works well with the S-Pen. However, this device surely does recognize a hovering finger, i.e. not S-Pen (for instance over the unlock screen).

My question is what modifications are necessary so that an airview-enabled device (like this Note 3) would recognize and act on a hovering finger instead of a hovering S-Pen.

Thank you!
Adrian
if I remember rightly, the library makes no discrimination between finger or pen. It is whatever the device supports. Did you try finger with the pen inserted into the device? I don't have a note device so unfortunately cannot test and advise further. Sorry
 

adrianstanescu85

Active Member
Licensed User
Longtime User
I tried both situations, finger with s-pen inserted and taken out, either way the finger is not detected. Note 3 is clearly an airview enabled device, since the airview function works with this library, but with s-pen only. The unlock screen locates the finger when hoovering above the screen in each position, so this is another instance of airview. I also tried boosting the sensitivity of touch, since this is also an option, still no changes.

There has to be a difference though...
 

barx

Well-Known Member
Licensed User
Longtime User
I tried both situations, finger with s-pen inserted and taken out, either way the finger is not detected. Note 3 is clearly an airview enabled device, since the airview function works with this library, but with s-pen only. The unlock screen locates the finger when hoovering above the screen in each position, so this is another instance of airview. I also tried boosting the sensitivity of touch, since this is also an option, still no changes.

There has to be a difference though...


Did you add the text to the manifest editor?
 

barx

Well-Known Member
Licensed User
Longtime User
I took the exact sample that appears at the top of this post and ran it without any modifications.

One the Note device, go to Settings > Controls > Air View Mode and select Finger or Auto to accept input from a finger ;)
 
Top