Categories
Android Mobile Source Code Tools webinar

Skill Sprint: Android Voice – Speech Recognition and TTS

Androids can talk and listen!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.

I’ve still got a lot of work to do on the components, but they work as is for now. If you want to modify the component code then take a look at my Skill Sprint and blog post on the Android JNI Bridge.

 

Categories
Android Mobile MVP News Source Code Tools webinar

Android JNI Bridge and Custom Classes.dex

By creating a custom Classes.dex you can get access to 3rd party Java JAR APIs from your application. For my Integrate More Android with a JNI Call to your Android App Developer Skill Sprint I created a demo app that demonstrates creating a custom Classes.dex. This is a new feature in XE6 and Appmethod 1.14. [Download the demo] [Download the slides] The Demo app uses the Base64Coder JAR file (included). To build the demo:

  1. Examine the createdex.bat file to make sure it refers to the correct location for your dx.bat utility and the fmx.jar & android-support-v4.jar files.
  2. Run the createdex.bat file to create the classes.dex file which includes the two jar files above, plus the base64coder.jar file.
  3. Double check that the Deployment Manager references the new classes.dex and not the old ones, and that the remote path is “classes\”
  4. Notice that the android.JNI.Base64Coder.pas file wraps and exposes the methods of the base64coder class.
  5. Run the app on your Android device and verify that it works as expected.

The Base64Coder.JAR is Android specific, so it will not work on iOS or Windows. Some additional notes from the Developer Skill Sprint: Some useful units for making JNI calls

  • Androidapi.Jni – Java Native Interface type definitions
  • Androidapi.JNIBridge – The JNI Bridge
  • Androidapi.JNI.JavaTypes – JString and other common types.
  • Androidapi.Helpers – JStringToString and other useful conversions.
  • FMX.Platform.Android– Useful platform methods like GetAndroidApp, MainActivity and ConvertPointToPixel
  • Others useful units: Androidapi.AppGlue, Androidapi.JNIMarshal, Androidapi.JNI.Embarcadero
  • 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

Categories
Android Components gadgets iOS Source Code

Parrot AR.Drone 2.0 Delphi Component

githubI took my code I previously used to control the Parrot AR.Drone and turned it into a reusable component. I added some more functionality to it as well, although there is a lot more to cover. The component is available on GitHub.

It should work with Delphi, C++Builder, Appmethod and RAD Studio on iOS, Android, Windows and OS X. I’d love to hear how it works for you and what you use it for!

Categories
Android Graphics iOS Mobile Source Code

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.

Categories
REST Source Code Tools

XE5 REST Debugger Supercharged

Some people asked for the source code to using the new XE5 REST Client Library to consume the Kimono web service. The crazy thing is there isn’t any. I decided to make a video about how easy it is to consume REST web services the the new REST Client Library and the REST Debugger. In the process I thought of a way to make it even easier by supercharging the Rest Debugger (source code below).

In this video I show you how to create a REST Web service with Kimono Labs (in beta, so it will change) and then bind that data to your XE5 app using the REST Debugger.

You can supercharge your REST Debugger too. The source code is installed with XE5

C:\Program Files (x86)\Embarcadero\RAD Studio\12.0\source\data\rest\restdebugger

You will want to copy it somewhere else before modifying it. Then add a button where ever you want, and on the click event for the button add the following code:

StreamToClipboard([RESTClient, RESTRequest, RESTResponse, RESTResponseDataSetAdapter, RESTClient.Authenticator]);

And then download uCopyComponents.pas and add it to your project and uses clause. It is pretty simple, but is designed specifically to work with non-visual components, although could be modified to work with visual components too.

If you want to include the TClientDataSet in the copy, then add it to the array (although make sure it is not active). Or you could modify it to add a TFDMemTable. Use it how you wish, I hope it works for you. If you discover any bugs make any changes let me know. If anyone is interested in contributing to it, let me know.

Categories
Android MVP Source Code

Every Android API for Delphi

Delphi XE5’s support for Android includes many of the most common Android APIs either wrapped in nice cross platform libraries and component or accessible directly via the JNI wrappers. The rest can be accessed by creating headers to expose them. The new JNI Bridge makes this calling of the managed Java APIs from the native Delphi app much easier then it used to be, but it still takes a little effort to make the translation (it is easier than translating a Windows API). Brian Long (an Embarcadero MVP) has an excellent video from CodeRage 8 that goes into great detail on the process.

But all of that has now changed. CHUA Chee Wee aka “Chewy” (also an Embarcadero MVP) has released an Android2DelphiImport tool that makes wrapping and accessing any and every Android API much easier. It gives you 3 distinct benefits:

  1. You can point it at Android.jar in the Android SDK and have it create wrappers for EVERY Android API. You’ll need to copy and paste out the pieces you want (it puts them all in one source file), but it saves a lot of typing and research. It implements the wrapper using the JNI Bridge just like the RTL does.
  2. You can point it at any other built in Java library, like the Google Glass GDK that provides all the Glass specific features on Google Glass, or maybe the Google Cloud Messaging (GCM) API. You’ll have a source file that wraps all the API calls exposed in that JAR file.
  3. You can use it to wrap a 3rd party Java JAR file for Android and it will create a .PAS interface for it, bundle it up for inclusion in your Delphi app, and load it at runtime.

As a matter of testing this tool I pointed it the Android.jar file for Kit Kat. It took a little while, but when it was done I had over 100,000 lines of interface wrappers covering EVERY Android API on Kit Kit. I copied out the lines for Toast support, added in the necessary uses statements, and I had full toast support in just a few minutes.

My next test was to point it to the Google Glass GDK (Glass Development Kit) for building native Glass Apps. Previously I had only used the Android SDK & NDK, which supports the common Android functionality on Glass, but the GDK adds support for Glass specific features. Once the GDK is installed (via the Android SDK Manager under API 15) you will find gdk.jar in the sdk\add-ons\addon-google_gdk-google-15\libs folder. It created a nice wrapper for it, but that wrapper wouldn’t compile because the uses clause was incomplete (it has a notice that you need to adjust the uses clause). I had to track down 4 additional units for the uses clause and then I extracted 3 more apis from the earlier Android wrapper to cover APIs that weren’t previously exposed. In all it took me about 15 minutes and then I had full support for the Google Glass GDK.

Since compiling isn’t enough, I built a simple app to insert and remove cards on the Google Glass timeline. It worked like a charm. I didn’t need to tweak or adjust the generated code at all (beyond the uses clause). Here is my code:

tm := TJTimelineManager.JavaClass.from(SharedActivityContext);
card := TJCard.JavaClass.Init(SharedActivityContext);
card.setText(StringToJString('Hello Glass'));
card.setFootnote(StringToJString('From Delphi'));
id := tm.insert(card); // Use id to edit or remove card later

I haven’t tested the 3rd scenario yet, but I did observe how it works. The tool creates a .apk out of the selected JAR file. It then includes a routine to load that APK at runtime so you can call into the methods it includes. You would need to go this route when the JAR isn’t built into the platform already. I have a library that I’m planning to test this with (so stay tuned), but I wanted to blog about the other benefits right way.

I am really excited about the potential of this tool. Not only does this mean you have even easier access to the entire Android API, but you also have easy access to all the extended APIs and 3rd party APIs. It has a simple command-line interface, and very few options, but when it works that is all you need.

Right now purchasing it is a little more complicated than using it. He only accepts Bitcoins, 1/4 Bitcoin to be exact. Based on the current exchange rate it is about $200 US, which is an excellent value for what you get (and considering how much effort has gone into its development). So you will either need to mine or purchase a bitcoin to pick this tool up, but if you are doing Android development I highly recommend it.

Categories
Delphi Projects REST Source Code

Delphi XE5 Mobile REST Client Demo Source

With the release of Delphi XE5 I’ve made the source of the Mobile REST Client Demo available. This is a really super simple demo of the Mobile REST Client in XE5. It is designed to show up how you can consume a JSON REST Service and adapt it into a DataSet and then bind that to the UI. If you change the data source you will probably need to change the live binding.

I’ve changed the demo from the one I used in the video to consume an OData data source. OData is a new standard backed by Microsoft for sharing data over the web. You can think of it as SQL for the web. It is a combination of other technologies, including REST, AtomPub, and JSON. Sybase supports OData on all of their databases now, as does Microsoft and others.

The change was simply a matter of pointing it to the Northwind OData endpoint provided on Odata.org. The binding is setup to show the company name in the listview. I added the ability to specify a Root Element, but that isn’t necessary for the demo.

This new technology works in both desktop and mobile, FireMonkey and VCL. It should also work in C++ Builder.

[Download the demo] (MobileRestXE5.7z 8 KB – Requires Delphi XE5 – Builds for iOS, Android or Win32)

Categories
Delphi Projects News Source Code

Android Screen View

Android Screen View UI

People have asked for a copy of the utility I wrote to view the attached Android device on the screen. It uses the built in screencap functionality of Android and the ADB (Android Debug Bridge) to grab and display a series of screenshots. It requires the Android SDK installed and does not require a rooted device.

The speed of update has to do with the screen resolution and image complexity. Simple screens (text and controls) update about twice a second. More complex screens (pictures, graphics, etc.) are slower than that.

For best results, turn on “Show Touches” under debug options.

It also supports saving a PNG to file.

Get the source: https://code.google.com/p/android-screenview/

Download the build: http://delphi.org/downloads/AndroidScreenView.7z

There are a few pending features that I just haven’t gotten to. If you’d like to contribute let me know. Thanks to Stephen Ball for all his contributions already!

Categories
Source Code

Mobile Location on iOS and Android

Most Android and iOS devices either include a GPS antenna, the ability to triangulate off cellular or wireless access points, or some combination. Accessing the location is different when using the platform APIs for iOS and Android. Luckily Delphi XE5 includes the TLocationSensor component. When activated it has a OnLocationChanged event which fired when the location changes more than the specified distance. In there simply examine the NewLocation.Latitude and NewLocation.Longitude to know the current location.

Learn more about multi-device, true-native app development with Delphi XE5 and check out other Mobile Code Snippets.

Categories
News Source Code

ShineOn 1.0.1.0 Released

Per Carlo Kok, ShineOn 1.0.1.0 is released today.  ShineOn is a library for Delphi Prism to assist in porting Delphi/Win32 and Delphi for .NET projects to Delphi Prism by providing a subset of RTL and core VCL classes that can be used instead of replacing all RTL/VCL calls with native FCL alternatives.

This is the first actual release.  Previously you had to download it from SVN.  It still appears to be a little lite on the documentation though, but it is exciting to see this project progressing forward.