For my Developer Skill Sprint I was originally scheduled to show how to do a Google Glass Voice Trigger. That is pretty cool because it allows you to launch a Google Glass app with your voice, but I decided to expand on that to also show how the Google Glass app can be launched with the results of additional voice input, as well as how to take dictation and do text to speech everywhere else in Android.
For more see: C:\Program Files (x86)\Embarcadero\Studio\14.0\source\rtl\android (Object Pascal) and C:\Program Files (x86)\Embarcadero\Studio\14.0\include\android\rtl (C++)
You will want to make use of Conditional Defines in Object Pascal and Predefined Macros in C++. In my blog post on Android Settings I showed how to make a JNI call with Object Pascal, but you can also look at the DeviceInfo Mobile Code Snippet in both C++ and Object Pascal. To create your own JNI Bridge wrappers, look at the source code in C:\Program Files (x86)\Embarcadero\Studio\14.0\source\rtl\android (Object Pascal) and C:\Program Files (x86)\Embarcadero\Studio\14.0\include\android\rtl (C++). You can also consider the following 3rd party utilities:
If you just want to include standard Android APIs then check out the FMXExpress (also an Embarcadero MVP) project on GitHub that includes all the Android APIs. Here is the video replay of my skill sprint
Also, check out Brian Long’s video on accessing the Android API with XE5
That includes both OAuth1 and OAuth2 usage. My Dropbox demo is a mobile app written in both C++ and Object Pascal. It uses OAuth2 and the mobile TWebBrowser to perform the authentication. You can view and download the slides as well. Useful links:
Recently I was discussing with some friends if everyone should learn to code and one friend said “I think everyone should learn to write unit tests.” I was reading Nick Hodges’ Coding In Delphi book (available free when you buy XE5) in the chapter on Unit Tests and my son asked me about it. In trying to explain it to him, my son was convinced it was a great idea and wanted to know why everyone didn’t do unit testing. Good question.
This month, for our RAD-In-Action webinar series we have Nick Hodges talking about Unit Testing in Delphi. If you sign up to attend the event you get a copy of the chapter on unit testing from Nick’s book. It is a good one.
This is sure to be a great event, and I highly recommend everyone makes time for it. In preparation for the event I thought I would list out some Delphi Unit Testing tools. These are covered in Nick’s book, but I’ll add my commentary here:
DUnit: The original unit testing framework for Delphi. It still ships with Delphi, and still works great.
DUnit2: A fork of the original DUnit this is an alternative unit testing framework that is enhanced to work with the language features introduced in Delphi 2009.
DUnitX: There are a lot of new language features in Delphi since DUnit was created. DUnitX is a whole new unit testing framework that takes advantage of these new language features to do some really cool things. MVP Robert Love has an excellent blog post about some of the cool things you can do with DUnitX and his plans and contributions.
Delphi Code Coverage: Curious how much of your code is covered by unit tests? This tool answers that question for you. There is a wizard that goes with it to integrate it into the IDE.
Delphi Mocks: One of the tricks with unit testing is to separate dependencies, but if your code depends on a database or network socket, how do you test it by itself? Enter Mocks. A brilliant tool to let you test the independent units of code without dependencies.
One side not about unit testing is you actually don’t need to use a framework, you just need to do it. Maybe there is another framework or tool you use, or you’ve developed your own in-house methodology. I’d love to hear about it, and I hope you join us Wednesday for Nick’s webinar, and bring your questions. I’ve got a few myself.
Google Glass is an exciting new platform and form factor. Éric Bonilha from Digifort joined us to show interfacing IP Controllers and streaming video from IP Cameras.
Something we didn’t get to show is Éric built a prototype app for streaming video to Google Glass. His plan is to build a version of his camera surveillance app for Google Glass that will stream surveillance video to security guards on patrol. Additionally it will stream the video from Google Glass back to the security system.
It was so cool how fast Éric used Delphi XE5 to prototype accessing the camera on Google Glass and streaming video from his system to it.
The source code for my Google Glass app, and Éric’s code for accessing IP Camera & IO Controllers is available along with the replay from our RAD-In-Action Webinar. I’m looking to pick up a PTZ IP Camera and streaming it to my Google Glass next.
The Ouya is an Android powered game console / set-top box that you can pick up for $99. Not only is it a cheap game console, but it is also an affordable Android platform designed to drive big screen TVs. Easily turn a TV into a wall mounted dashboard or living picture frame.
Once the ADB driver is installed, You can develop for and deploy to it with Delphi XE5 just like any other Android device.
The Emotiv EPOC might seem more Sci-Fi than practical technology. It is designed to pick up on brain waves through its 14 brain wave sensors (plus 2 reference receivers) and convert them into a usable signal for your computer. For head tracking it also includes a head mounted gyroscope.
The sensor input comes in 4 different categories:
Head rotation: The gyroscope returns acceleration information about the movement of your head.
Facial Expressions: Referred to as the Expressiv Suite, it processes the signals to detect facial expressions in real time. This includes winks, smiles, and eye movement.
Emotions: The Affectiv Suiteprovides real time emotional feedback including frustration, distraction, etc.
Direct Thought Control: The Cognitiv Suite lets you define trained brain patterns that you associate with different outcomes. When you repeat the brain pattern the system responds appropriately.
If you want to play with the Emotiv EPOC it is $500 for the developer set. The normal consumer set only works with official licensed software. It comes with a nice control panel that lets you play with the different inputs.
Thanks to the work of Simon J. Stuart (aka LaKraven) the SDK has a full Delphi translation. I have a short demo using the gyroscope. The brain access systems were giving me a handshake error, but that may be a commentary on my brain power.
My next objective is to unlock the brain interface and combine that with the Parrot AR.Drone api so I can fly the quadricopter with my mind.
That was part of the 11 demos in our Devices and Gadgets webinar. You can access the full replay on demand, which includes access to most all the drivers, wrappers, apis and source code. The only missing source code is to Allen Bauer‘s bluetooth infrared velocity screen system. He’ll have a blog post about that one.
Working with sensors on devices can often lead to large amounts of data coming to you really fast. For example the TMotionSensor’s OnDataChange event fires 100 times a second on my Nexus 5. When I was building my level app for Google Glass the level bar was bouncing all over the place because of the sensitivity and sample rate.
My first thought was to only take every 10th sample, but I wasn’t happy with that either because the specific sample it pulled could be the one when there was a jitter.
If I just looked at sample 1 and 11 then I would see a lot of movement, but in reality it was relatively stable most of the time.
What I ended up doing was buffering the data and taking an average. I just created a generic TList of the appropriate type, and during the OnDataChange event I would simply store the sample data. When it came time to update the display I took an average sample, which I found gave a much smoother and more representational display.
Although it was still possible the line could jump erratically if I really moved a lot. So I decided to use an animation for the movement. This keeps the line movement smooth, even if there is a lot of movement (it interpolates the positions between the current line position and the new position). I used a TFloatAnimation and set the StartFromCurrent property to true.
When the animation is finished I set the StopValue to the the average of the values, then enable again. It is important to always clear the sample values after taking an average. Otherwise the movement will continue to get slower and slower as it becomes more and more stable (averaging a large enough sample of numbers results in a smaller range of results.)
I was really pleased with how smooth things looked with a 0.1 second duration on the animation. With 100 samples a second, this translates into each animation covering the average of 10 samples. The built in animations made it really easy, and the final display looked great.
I got a great call the other morning. A Delphi developer from a few versions back was considering upgrading to XE5, but he wanted to know if FireDAC was recommended for database access, or if he would need a 3rd party library.
I remember working on some data driven Delphi applications when the drill was you always bought a 3rd party database access library. There are lots of great database access libraries to choose from, which is one of the great things about Delphi: all the technology partners!
In XE5 the BDE is officially deprecated (and has been for a while), but it still ships (maybe not for much longer though). dbExpress is still there, and so is dbGo and IBX, and they are all good, specialized database access libraries. But with the full integration of FireDAC in XE5, it is the recommended database access library, and for good reason.
FireDAC is a universal data access library: you use the same components to connect to a huge variety of databases. The usage pattern is similar to the BDE, and it is fully bidirectional. It also has a large collection of specialized features for dealing with specific databases, and local, in memory data.
Of course you are still welcome to continue using 3rd party libraries, and some of them may offer some other specialized features. That is one of the great things about Delphi, C++Builder and RAD Studio: It comes with great features in the box, but you can expand on those with 3rd party libraries.
If you still aren’t on XE5, you still have a little time to take advantage of the special offers.
Glenn Stephens with Orchard eBusiness has a Delphi XE5 Mobile App Development Workshop coming up next month. It is divided up into 4 different 4 hour workshops, each on a different day. This gives you a chance to work on what you learned in preparation for the next workshop. The objective is to take a developer who is experienced with Delphi and prepare them for Mobile App Development.
Glenn does good work, so I am sure this is a great opportunity to anyone who wants to make the move to mobile app development.
If you haven’t yet, take advantage of the end of year special offers before time runs out so you will have XE5 and be ready for Glenn’s workshop. I’m looking forward to seeing all your apps in the app stores!