Delphi XE6 is on Fire

Remember the demonstration I did showing how Delphi works great with Ouya? Well, there is a new set top box in town, the Amazon Fire TV. Just like the Ouya, it is a Android powered set top box. So, does it support everyone’s favorite Android development tool? Turns out it works great with Delphi XE6. It uses a wireless ADB connection, so you just need to follow their simple steps to Connect ADB and it shows up in the IDE as the Android device AFTB (not sure what that stands for). After that you can develop and deploy to it just like any other Android device.

When you run your app from the IDE it will popup and run on the Fire TV, but after you exit your app you won’t see it anymore. It appears Fire TV only displays apps that are loaded from their app store on the home screen. Not to worry, you can easily launch it from the Settings -> Applications screen. Simply select your app and choose Launch application.

By default your only input device is the Amazon Fire TV remote.

firetvremote

Simply handle the OnKeyUp event on your form and you will receive events with the key codes vkLeft, vkRight, vkUp, vkDown, vkMenu, vkHardwareBack, vkMediaPlayPause and a key value of 0 for the select, fast forward or rewind buttons. The Home and Voice Search buttons are always handled by the OS. If you choose to handle the vkHardwareBack then set the key value to 0 (or any other value) and the system will ignore it, otherwise your app will exit.

Fire TV also supports a gamepad as well as various other bluetooth input devices, like a bluetooth keyboard, which greatly expands the input options. You also could use App Tethering to tether a mobile or desktop/laptop app to your Fire TV app to provide input and display it on the big screen. Like an image receiver that receives pictures from your mobile device to display them to everyone in the room.

If you download the Fire TV SDK it exposes Game Controller and Notification classes. If there is interest I can post some Object Pascal wrappers for those later on.

 

Where is StringToJString and StrToNSStr in XE6?

The useful helper routines StringToJString and StrToNSStr (and other associated ones) moved between XE5 and XE6. In XE6 you can find them in the units Androidapi.Helpers and Macapi.Helpers respectively. But how to find other useful methods? I’ll tell you what I do: Use Windows Search.

You want to go to Indexing Options to set Windows Search up to be useful.

Windows Search Indexing Options

First select Modify and browse to the Source folder and add it to the list of indexed locations. I like to add the source folder as a favorite in Explorer too, to make it easier to get back there.

C:\Program Files (x86)\Embarcadero\Studio\14.0\source

Next click Advanced and go to the File Types tab and select .PAS file and any other file types you would like to have indexed, and change them to Index Properties and File Contents. It uses the plain text filter, which in my experience is good enough, and your only option (without installing a new one).

Indexing Options - Advanced - File Types

It takes a bit for the index to rebuild, but after that you can quickly search all of the XE6 source to find APIs, Helper Methods or any number of other useful code to aid in your development process. This is where that favorite to the source folder is helpful. Either search from the root of the source folder, or browse into a subfolder to only search specific source files.

There are other indexed searching utilities, and I’ve used many of them in the past. The advantage of Windows Search (probably it’s only advantage) is that it is built in and already running.

BlueTooth Remote Control Car

How to use BlueTooth is one of the most common requests with Delphi. During our Devices and Gadgets webinar David I. showed how to browse paired BlueTooth devices and connect to them.

But wait, there’s more! Daniele Teti & Daniele Spinetti of bit Time Software created an Android client app to control a BeeWi – BBZ201 – Mini Cooper S Bluetooth Car. It may work with other BeeWi Bluetooth remote control vehicles, but has not been tested with any (that I know of).

The Multitouch code is Copyright (c) 2006-2014 Iztok Kacin, Cromis and used under the BSD license.

It currently doesn’t have BlueTooth discovery, so once you pair your device you need to update the source code with the MAC address of your car.

I’ve created a GitHub repository for the project. It should work with XE5 or AppMethod just fine. I’ve got a version updated to XE6 that exposes the controls via App Tethering too, which I will upload later.

OpenGL ES Support on Mobile with XE6

OpenGL ES logoAppmethod, RAD Studio, Delphi and C++Builder XE6 all make it really easy to work with OpenGL ES on mobile devices. Under the covers FireMonkey is implemented with OpenGL ES on mobile (iOS & Android), OpenGL on OS X and DirectX on Windows. It provides a number of useful abstractions for working with 2D and 3D graphics, but sometimes you just want to get down to a lower level.

Here is all you need to access an OpenGL ES rendering context in your FireMonkey mobile application. This example is in Object Pascal, but should be easy enough to adapt to C++.

  1. Create a new FireMonkey Mobile application
  2. Select 3D application
  3. Add FMX.Types3D to the Interface uses clause
  4. In the Object Inspector, create a new event handler for the OnRender event for your form
  5. You now have access to the OpenGL render context.

You can work with the TContext3D that is passed in via a parameter, and your code will work across platforms automatically. If you want to work with the OpenGL ES APIs directly you can do that too with the following uses clause in your Implementation section:

uses
  // Gives you access to the FMX wrappers for GLES
  FMX.Context.GLES, 
{$IFDEF ANDROID}
  // Direct access to the Android GLES implementation
  Androidapi.Gles, FMX.Context.GLES.Android;
  // More useful units for Android
  //, FMX.Platform.Android, Androidapi.Gles2, Androidapi.JNI.OpenGL,
  // Androidapi.Glesext, Androidapi.Gles2ext;
{$ENDIF}
{$IFDEF IOS}
  // Direct access to the iOS GLES implementation
  iOSapi.OpenGLES, FMX.Context.GLES.iOS;
  // More useful units for iOS
  //, iOSapi.GLKIT, FMX.Platform.iOS;
{$ENDIF}

And here is an example event handler with a couple calls to the OpenGL ES APIs:

procedure TForm1.Form3DRender(Sender: TObject; Context: TContext3D);
begin
  glClearColor(1, 1, 0, 1);
  glClear(GL_COLOR_BUFFER_BIT);
end;

This accesses the iOS and Android equivalents of the same OpenGL ES APIs. Thanks to the compiler directives, and the cross platform nature of OpenGL ES, this code just works. I’m not an OpenGL expert, but I looked through the OpenGL ES API and all the routines I tested worked, but I never did anything interesting with them.

Meet Me in Chicago & D.C./Baltimore for a First Look at XE6

I’m joining Bob Swart and Cary Jensen for the U.S. cities of their annual Delphi Developer Days 2014 tour with the keynote and a free evening event. During my keynote and the evening session I’ll show off Google Glass development with XE6, as well as using an EEG Brain-Computer Interface to control a Mini-Cooper via Bluetooth.

I highly recommend you find time to attend the whole two days of training. I always learn a lot.

May 5-6, 2014: Washington DC/Baltimore
SpringHill Suites Arundel Mills BWI Airport
Register for Training in Washington DC/Baltimore
The free evening event starts at 6:30 PM on Monday the 5th with pizza and drinks. Same location. [Register for free event]

May 8-9, 2014: Chicago
Holiday Inn Express Hotel & Suites, Arlington Heights (O’Hare Airport)
Register for Training in Chicago
The free evening event starts at 6:30 PM on Wednesday the 8th with pizza and drinks. Same location. [Register for free event]

Delphi Developer Days are two-day live Delphi events that provide you with the latest information on Delphi as well as practical techniques to help you improve your Delphi development skills. Each event includes both joint sessions, presented by Bob and Cary together, as well as simultaneous tracks, where Cary and Bob break out into separate rooms to present individual sessions. There is also an Embarcadero Technologies Keynote by Jim McKeeth and guest speaker sessions with Nick Hodges (former Delphi product manager) of Veeva Systems in DC/Baltimore, and with Ray Konopka of Raize Software in Chicago.

A wide variety of topics are covered. Some topics, such as FireDAC and mobile development, apply to the latest versions of Delphi, but there are also many topics that apply across many versions of Delphi. See the detailed description and agenda.

All attendees receive:

  • An extensive course book (several hundred pages in length) written by Cary and Bob that includes the material covered in their sessions
  • Source code examples from their sessions
  • A chance to win valuable prizes from sponsors.
  • Lunch on both days

Space is limited to the first 42 people in each city. There is a discount for attendees of previous 2009-2013 tours, and group discounts are available when registering three or more people from the same company.Visit www.DelphiDeveloperDays.com for complete information.Platinum Sponsors: Embarcadero Technologies, Sybase, An SAP Company, and TMS software. Gold Sponsors: Devart, Dr.Explain, Gnostice Information Technologies, and Raize Software.

C++Builder XE6 for Android Wallpaper

Remember the great Delphi for Android wallpaper? Well Dave has a new wallpaper to celebrate the new C++Builder for Android support.

C++Builder for Android

Thanks Dave for the great new wallpaper!

What You Need To Know #1

Do you know the song “Video Killed The Radio Star“? It seems like today it is “Twitter & G+ killed the blog post.” I thought I would summarize some of the recent news I’ve posted elsewhere.

  • bit Time Lab has a video showing off their multi-touch bluetooth app that controls a very small mini-cooper. They developed the libraries for multi-touch support and bluetooth they used with Appmethod (Object Pascal). Very cool!
  • Project Indy has an OpenSSL update for the Heartbleed vulnerability.
  • InterBase uses OpenSSL, but was never vulnerable to Heartbleed.
  • I’ll be at Delphi Developer Days in Chicago and D.C. and we will have free evening events there too. These are great events full of fabulous content (I’ve attended in the past). I highly recommend you check them out. I’ll be showing Delphi working with Google Glass, Brain-Computer Interface, FireDAC, REST, and anything else I can squeeze in.
  • I’m also traveling to India and South Korea this month.
  • I worked with Sarina on this Tutorial for accessing Parse.com from Appmethod Object Pascal with the REST components. Great technology.
  • Eric compiled a partial list of over 100 Delphi apps in the Play Store.
  • Eric Bonilha was featured in the Brazilian News for his work on a DigiFort app for Google Glass that stream live video to and from Google Glass. It is in Portuguese, but you can see some live demos of the app starting at just after 7 minutes in. All the software used to stream video and control cameras in that segment is written in Delphi by Eric and his team.
  • Curious about what is coming in XE6? There is a RAD Studio XE6 Sneak Peak event taking place April 16th. It looks really exciting!
  • I still get people asking about the new upgrade pricing. Check out the new License Recharge Program – if you own the latest version of Delphi, RAD Studio, or C++Builder then you qualify to save a lot of money when a new product is released.
  • David Intersimone and myself are running regular Google Hangout On-Air events. These are informal technical events we share some of the things we’ve been working on recently. Make sure you join the Embarcadero Technologies G+ community so you can be involved in the next one. The first two were experiments, we plan to promote the future ones better (although they will probably remain experimental and informal).

RAD Studio XE6 Preview Event

Thought Controlled Quadcopter

Last night I “controlled” my Parrot AR.Drone Quadcopter with my thoughts through my Emotiv EPOC Brain Computer Interface via an app written in Delphi XE5. I qualify “controlled” in that my flight pattern was a little irregular and short before I crashed it. It was a “look mom, no hands” moment though as the drone was clearly responding to my thoughts for the few seconds before it crashed. I’ve got a lot of work to do in improving the process, so I will be posting code and videos soon. If you want to get a start on it though, it is based on my work from the Devices and Gadgets webinar.

I’m presenting tomorrow at Boise Code Camp on “Is Thought the Future of Wearable Input?” and if all goes well I’ll have a brief demonstration of the tech in action. If you are in the area my presentation is at 11 AM in the Special Events Center at Boise State University.

Setting Android Settings

On the Android platform all the system wide settings that are accessible via the Settings app are also accessible to your app. You just need to add the uses permission WRITE_SETTINGS. Here is a simple Delphi XE5 example for changing the screen timeout.

First you need the following in your uses clause:

Androidapi.JNI.Provider, // JSettings_SystemClass
FMX.Helpers.Android; // SharedActivityContext

Here is the code to read and set the Screen Off Timeout:

function GetScreenOffTimeout: Integer;
begin
  Result := TJSettings_System.JavaClass.getInt(
    SharedActivityContext.getContentResolver,
    TJSettings_System.JavaClass.SCREEN_OFF_TIMEOUT,
    15000);  // 15 seconds is default is not found
end;

function SetScreenOffTimeout(ATimeOut: Integer): Boolean;
begin
  Result := TJSettings_System.JavaClass.putInt(
    SharedActivityContext.getContentResolver,
    TJSettings_System.JavaClass.SCREEN_OFF_TIMEOUT,
    ATimeOut);
end;

In the GetScreenOffTimeout we pass a default value to use if none is found. I passed in 15000, which is 15 seconds, or the smallest value for my phone. The largest value on my phone is 600000, which is 10 minutes. It appears you can set it to any value, even one that the settings app doesn’t explicitly list as an option.

There are lots of other settings available for your adjustment.

CodeRage C++

Tomorrow is the start of CodeRage 8 C++, which is a lot like regular CodeRage, but with an emphasis on C++Builder. This time there is a lot of coverage on the new iOS support, as well as the new REST Components and FireDAC data access.

It all starts with JT’s opening keynote at 6:00 AM Pacific Time, which may also be of interest to Delphi developers who want to get some glimmers of future plans, roadmaps and announcements. Actually most of the sessions will have content of interest to Delphi developers, especially if you’ve missed some of the more recent CodeRage conferences. But if you are a C++ developers, then be sure to make time for all the sessions!

CodeRage C++ - February 25-26, 2014