using multitouch and sensors in java
DESCRIPTION
TRANSCRIPT
![Page 1: Using multitouch and sensors in Java](https://reader033.vdocuments.net/reader033/viewer/2022042713/545c9f08af7959be098b48a8/html5/thumbnails/1.jpg)
Using multi-touch and sensors in Java
Felipe Pedroso
![Page 2: Using multitouch and sensors in Java](https://reader033.vdocuments.net/reader033/viewer/2022042713/545c9f08af7959be098b48a8/html5/thumbnails/2.jpg)
2
Agenda
•The future of PCs• JavaFX and Touch Support•Using JNI to work with sensors
![Page 3: Using multitouch and sensors in Java](https://reader033.vdocuments.net/reader033/viewer/2022042713/545c9f08af7959be098b48a8/html5/thumbnails/3.jpg)
Mobile Computing Lines are Blurring
Ultrabook™ Convertible & Detachable
Ultrabook™TabletSmartphone
Consumption Usages Creation/Productivity
Notebook
![Page 4: Using multitouch and sensors in Java](https://reader033.vdocuments.net/reader033/viewer/2022042713/545c9f08af7959be098b48a8/html5/thumbnails/4.jpg)
4
Reshaping the PC Experience
Ambient Light
Sensor
GPSCompass
Near Field Communicati
on
Gyroscope
Ultrabook™
Accelerometer
Multi-Touch
Context Aware Sensors
![Page 5: Using multitouch and sensors in Java](https://reader033.vdocuments.net/reader033/viewer/2022042713/545c9f08af7959be098b48a8/html5/thumbnails/5.jpg)
OK, they have all those features…
… but how can we implement them using Java?
![Page 6: Using multitouch and sensors in Java](https://reader033.vdocuments.net/reader033/viewer/2022042713/545c9f08af7959be098b48a8/html5/thumbnails/6.jpg)
6
To allow users to TOUCH my Java App...
• Should I use...• AWT?• Swing?• SWT?
• Actually, you can use them but...• They aren’t made for multi-touch (OK, there’s a way to do it)• You must optimize your UI controls to be more ‘touch friendly’
• So, how to do it in a simple and easy way?
![Page 7: Using multitouch and sensors in Java](https://reader033.vdocuments.net/reader033/viewer/2022042713/545c9f08af7959be098b48a8/html5/thumbnails/7.jpg)
7
![Page 8: Using multitouch and sensors in Java](https://reader033.vdocuments.net/reader033/viewer/2022042713/545c9f08af7959be098b48a8/html5/thumbnails/8.jpg)
8
Actions supported
• Touch events: Down, Move and Up• Tap (Down and Up) / Double tap• Drag and Drop (Down, Move and Up)• Hold
• Gestures• Swipe: Up, Down, Left and Right• Zoom: Pinch / Spread• Rotate
![Page 9: Using multitouch and sensors in Java](https://reader033.vdocuments.net/reader033/viewer/2022042713/545c9f08af7959be098b48a8/html5/thumbnails/9.jpg)
9
What I need to do to manipulate components?
• Your components must extend the Node class or any of its subclasses (StackPane, ImageView, etc)
• Set the proper EventHandler to handle the action.
![Page 10: Using multitouch and sensors in Java](https://reader033.vdocuments.net/reader033/viewer/2022042713/545c9f08af7959be098b48a8/html5/thumbnails/10.jpg)
10
What I need to do to manipulate components?
• Apply a transform to the component (Translation, Rotation and Scale):
• Let’s dive into some code!
![Page 11: Using multitouch and sensors in Java](https://reader033.vdocuments.net/reader033/viewer/2022042713/545c9f08af7959be098b48a8/html5/thumbnails/11.jpg)
What about the sensors?
JNI, I choose you!
![Page 12: Using multitouch and sensors in Java](https://reader033.vdocuments.net/reader033/viewer/2022042713/545c9f08af7959be098b48a8/html5/thumbnails/12.jpg)
12
Available sensors on Ultrabooks
• Accelerometer• Proper acceleration in three axis (x, y, z)
• Gyrometer• Device orientation
• Magnetometer• Strenght and direction of magnetic fields
• GPS (Global Positioning System)• Location and Time information
• NFC• Near Field Communication
• Ambient Light Sensor• Ambient Light Level
![Page 13: Using multitouch and sensors in Java](https://reader033.vdocuments.net/reader033/viewer/2022042713/545c9f08af7959be098b48a8/html5/thumbnails/13.jpg)
13
API Windows – Sensor Fusion
![Page 14: Using multitouch and sensors in Java](https://reader033.vdocuments.net/reader033/viewer/2022042713/545c9f08af7959be098b48a8/html5/thumbnails/14.jpg)
14
API Windows – Namespaces• Windows.Sensors.* Common sensors
• Accelerometer• Gyrometer• Inclinometer• OrientationSensor• SimpleOrientationSensor• Compass• LightSensor
• Windows.Devices.Geolocation GPS• Geolocator
• Windows.Networking.Proximity NFC• ProximityDevice
![Page 15: Using multitouch and sensors in Java](https://reader033.vdocuments.net/reader033/viewer/2022042713/545c9f08af7959be098b48a8/html5/thumbnails/15.jpg)
15
Windows API – How to
• Get the default object of your sensor using the GetDefault method
• You can call the GetCurrentReading() to get the current value of the sensors or...
• ... work with the ReadingChanged event• Set the attribute ReportInterval (please, respect the MinimumReportInterval to avoid problems)• Delegate a method to handle the event (something like setting a method as a listener)• Handle the event!
• This procedure is valid only for sensors from Windows.Sensors namespace
![Page 16: Using multitouch and sensors in Java](https://reader033.vdocuments.net/reader033/viewer/2022042713/545c9f08af7959be098b48a8/html5/thumbnails/16.jpg)
16
How can I access that?
![Page 17: Using multitouch and sensors in Java](https://reader033.vdocuments.net/reader033/viewer/2022042713/545c9f08af7959be098b48a8/html5/thumbnails/17.jpg)
17
Using JNI to access the sensors from Windows.Sensors
1. [Java] Create a native method to register the object that will handle the events that come from the sensor
2. Generate the header file using javah
3. [C++] Create a DLL Project in Visual Studio with the DLLs and namespaces of the Windows 8 APIS
4. [C++] Use a variable to keep a reference to the object and the ID (GetMethodID) of the method that will handle the event
![Page 18: Using multitouch and sensors in Java](https://reader033.vdocuments.net/reader033/viewer/2022042713/545c9f08af7959be098b48a8/html5/thumbnails/18.jpg)
18
Using JNI to access the sensors from Windows.Sensors
5. [C++] Initialize the sensor and delegate a C++ method to handle the event
6. [C++] Redirect the delegate method call to the Java method using the function CallVoidMethod with the following parameters: the Java Object, the method ID and it’s parameters
7. [Java] Handle the event!
A lot of text? Please, show me the code!
![Page 19: Using multitouch and sensors in Java](https://reader033.vdocuments.net/reader033/viewer/2022042713/545c9f08af7959be098b48a8/html5/thumbnails/19.jpg)
19
What about Linux?
• Touch works fine, but there aren’t clear APIs to read sensors. If you know how to do it, let’s work together!
![Page 20: Using multitouch and sensors in Java](https://reader033.vdocuments.net/reader033/viewer/2022042713/545c9f08af7959be098b48a8/html5/thumbnails/20.jpg)
20
Wants to know more about Intel Software?http://software.intel.com/pt-br/
![Page 21: Using multitouch and sensors in Java](https://reader033.vdocuments.net/reader033/viewer/2022042713/545c9f08af7959be098b48a8/html5/thumbnails/21.jpg)
21
Windows Community
http://software.intel.com/en-us/windows
![Page 22: Using multitouch and sensors in Java](https://reader033.vdocuments.net/reader033/viewer/2022042713/545c9f08af7959be098b48a8/html5/thumbnails/22.jpg)
22
www.javafxcommunity.com
![Page 23: Using multitouch and sensors in Java](https://reader033.vdocuments.net/reader033/viewer/2022042713/545c9f08af7959be098b48a8/html5/thumbnails/23.jpg)
23
JFXtras.org
![Page 24: Using multitouch and sensors in Java](https://reader033.vdocuments.net/reader033/viewer/2022042713/545c9f08af7959be098b48a8/html5/thumbnails/24.jpg)
Take aways
• The PC experience is being reshaped
• JavaFX + Touch = AWESOME
• Using JNI to access the sensors can be LEGENDARY!
![Page 25: Using multitouch and sensors in Java](https://reader033.vdocuments.net/reader033/viewer/2022042713/545c9f08af7959be098b48a8/html5/thumbnails/25.jpg)
Any doubts?(if yes, the answer is 42)
![Page 26: Using multitouch and sensors in Java](https://reader033.vdocuments.net/reader033/viewer/2022042713/545c9f08af7959be098b48a8/html5/thumbnails/26.jpg)
Thanks a lot!
Felipe Pedrosofacebook.com/felipe.a.pedroso
@felipeapedroso