FloatingTouch_660x384

Floating touch™ API now available

Xperia™ sola is the first smartphone to introduce a brand new touch sensor technology called Floating touch. This unique feature lets you control parts of the user interface (UI) by simply letting your finger hover above the touch screen. And with the latest Ice Cream Sandwich (ICS) update for Xperia™ sola, the API for Floating touch™ is now available, so that you can add Floating touch™ to your apps and allow users to control app actions through finger hovering. This makes it possible to interact with the UI in many new ways!  We asked Andreas Sandblad, Software Architect at Sony, to explain the API in detail. Read further to get more information plus code example.

Andreas Sandblad, Software Architect at Sony.

Hi, I’m Andreas Sandblad, and I work as a Software Architect at Sony. In this tutorial I will explain the new Floating touch™ API coming with the latest ICS update, which means you can make it possible to control your own app by hovering your finger above the touch screen. This ICS update actually brings another cool feature for users – now you can highlight any link that you hover over in the web browser. In the Gingerbread software for Xperia™ sola, the link required a CSS :hover selector effect to be defined when you hovered over a link. For ICS, we’ve added a default CSS :hover selection effect which applies to all web sites. The CSS “outline” property was chosen to ensure that the existing web site layout was not affected. So now the Floating touch™ functionality works for all links!

But now let’s dig into the Floating touch™ API. Further down, you’ll find a code example for the Floating touch™ event stream so that you can start to use the Floating touch™ feature in Xperia™ sola for your own app! By doing this, there’s a good chance you’ll get an innovative edge on your competition.

Mapping out the details of the Floating touch™ API
A Floating touch™ event in Android™ is just an ordinary MotionEvent with the action ACTION_HOVER_ENTER, ACTION_HOVER_MOVE, or ACTION_HOVER_EXIT. To get the event stream, you can let your app override View.onHoverEvent or Activity.dispatchGenericMotionEvent. For compatibility reasons between various devices, it is highly recommended to check the action value of the event, and to not rely on all motion events being the same event. This means that you should look at both hover and touch events.

In addition to the X and Y coordinate, the distance of the finger from the touch screen is available through the distance axis. A general rule to keep in mind, is that an application should not hardcode the distance range. Instead it should rely on InputDevice.getMotionRange. The distance value is a raw value from the touch firmware and cannot be mapped precisely to a distance unit such as millimeters. Since this is a capacitive value, the value will depend on the angle and the thickness of the finger, and also other factors such as temperature and hardware differences. Hover events will be dispatched up to approximately one centimeter from the screen.

An application can check whether Floating touch™ is available on a phone by calling the PackageManager.hasSystemFeature method with the feature name com.sonymobile.floating_touch.

Note that the Floating touch™ API is not supported while the phone is used in glove mode, which means it has been unlocked with a glove on. The reason for this is that in glove mode, the Floating touch™ events are rewritten as normal touch events. Read more in my blog post explaining the basics of glove mode!

Example code using the Floating touch™ API
The following simple examples get the Floating touch™ event stream and writes it to a TextView.

@Override
public boolean dispatchGenericMotionEvent(MotionEvent ev) {
	StringBuffer output = new StringBuffer();
	output.append("action: " + ev.getActionMasked() + "\n");
	output.append("x: " + ev.getX() + "\n");
	output.append("y: " + ev.getY() + "\n");
	MotionRange range = ev.getDevice().getMotionRange(MotionEvent.AXIS_DISTANCE);

	if (range != null) {
		output.append("distance: " + ev.getAxisValue(MotionEvent.AXIS_DISTANCE)
                        + "\n");
		output.append("distance min: " + range.getMin() + "\n");
		output.append("distance max: " + range.getMax() + "\n");
	}

	if (mHasFloatingtouch == null) {
		mHasFloatingtouch = getPackageManager().hasSystemFeature(
		"com.sonymobile.floating_touch");
	}

	output.append("has floating touch: " + mHasFloatingtouch);

	if (mTextOutput == null) {
		mTextOutput = (TextView) findViewById(R.id.textView1);
	}

	mTextOutput.setText(output);
	return mHasFloatingtouch;
}

For all you Android developers out there, let us know if you have any questions about using the Floating touch™ API – drop us a line in the comments field below. We’re looking forward to seeing what you innovate!

More information

Comments 11

Sort by: Newest | Oldest | Most popular

  1. By Jan Pool

    #1

    Hi,

    I’ve written a simple application to test Floating touch API. I can see a lot of potential for this technology.

    I have the following questions:
    * What is the future of this technology? Will there be more models coming out that support the Floating touch API?
    * For the hover event, one can get a value for z between 0 and 255. The values I get for my specific device (and fingers) is mostly in the higher bracket of the range (>128). Is there a way to recalibrate the device so that the reported values are scaled so that a value of 0 is on the screen and a value of 255 is just in range.
    * The rate (or maybe the latency for the first event?) at which the hover events are reported is slow. If I approach the screen at a fast rate (for example, at the typicaly typing rate), no hover events are generated, only touch events. Is there a way to increase the reporting rate?
    * Once a touch event is registered and you move your finger away from the screen, no hover events are generated until you are out of range again (and maybe also after some time out?). Why would that be? Can I change this behaviour?

    Regards,

    • By Anna Aleryd

      #2

      Hi Jan,

      Good to hear that you like the Floating touch technology! I talked to Andreas Sandblad (one of the developers behind Floating touch), who gave me some answers to your technical questions:

      * For the hover event, one can get a value for z between 0 and 255. The values I get for my specific device (and fingers) is mostly in the higher bracket of the range (>128). Is there a way to recalibrate the device so that the reported values are scaled so that a value of 0 is on the screen and a value of 255 is just in range.
      ANSWER: The z value is a raw value received from the touch firmware. We currently don’t support a way to calibrate it on a system level.

      * The rate (or maybe the latency for the first event?) at which the hover events are reported is slow. If I approach the screen at a fast rate (for example, at the typicaly typing rate), no hover events are generated, only touch events. Is there a way to increase the reporting rate?
      * Once a touch event is registered and you move your finger away from the screen, no hover events are generated until you are out of range again (and maybe also after some time out?). Why would that be? Can I change this behaviour?
      ANSWER: This is due to hardware limitation. The touch hardware recalibrates the baseline on touch events to avoid problems with water on the panel.

      And as for your first question, I have no good answer for you, as I cannot comment on our future plans or products.

      Br,
      Anna from Developer World

      • By Jan Pool

        #3

        Thanks Anna.

        Regarding recalibration of the hardware. Is this something that may be supported in future versions of the firmware. Or perhaps even automatic recalibration.

        • By Anna Aleryd

          #4

          Hi,

          I’m sorry, but I cannot give you any information about our future plans at the moment. However, I have brought your request to the developers behind Floating touch as a suggestion for the future.

          Br,
          Anna

          • By Jan Pool

            #5

            Great, thanks for passing on the request.

  2. By christian alkonga

    #6

    hi sony support,
    i bought sony xperia sola and just upgraded it to android 4.0, everything’s working fine except from the some camera control, it can’t take picture in just one click of the cam button or the shutter button in on the screen, i need help to fix this, and i heard that if the devices OS is upgraded, it’s warranty will be voided.

    thanks for the future reply. I’ll wait for your immediate response, thanks

    • By Anna Aleryd

      #7

      Hi,

      Try heading over to our support forum, where you should be able to get an answer for this. Good luck!

      Br,
      Anna from Developer World

  3. By Abhinav Tripathi

    #8

    i have updated my xperia sola to 4.0 and found this amazing feature of floating touch throughout the UI but plzz tell me how to disable it coz i have problem in playnig games….when i dont want to select anytinhg in game it gets selected via floating touch…

  4. By ESWAR NARAYANAN

    #10

    how to enable the API features to use floating touch fully.The API feature is working sometimes but sometimes it is not working i dont know how to enable it.can u please help me

  5. By Alexander Ledkov

    #11

    It is very intresting technology. Can you give us full sample project, not a piece of code?

1-11 of 11 comments.