You are browsing the archive for Java.

Getting an Android app’s version number

September 18, 2012 in Guest Post, Java, Oxygene, Prism

A while back I was preparing an app to upload to the Android Market Google Play. One of the requirements of uploading is that the app must contain version information. As of the August update of Oxygene for Java 5.2, the default Android application template does not contain version information so you need to insert this manually, and then update it as and when your code is updated.

You add version information to your Android application by editing the manifest file. In the outermost element, the manifest element, you add in a couple of attributes: versionCode and versionName.

versionCode is an integer that can be anything you like, as long as each new version code is higher than the last – clearly an incrementing number is the simplest option here. versionName is the string that is shown to the user – it’s not used by the system so can be any test you like.

So, for example, you could open the manifest element like this on your first app version:

<manifest
    xmlns:android=”
http://schemas.android.com/apk/res/android”
    package=”com.acme.app”
    android:versionCode=”1″ android:versionName=”1.00″>

Each time you want to issue a new application you simply update the two version-related attributes, maybe like this:

<manifest
    xmlns:android=”
http://schemas.android.com/apk/res/android”
    package=”com.acme.app”
    android:versionCode=”2″ android:versionName=”1.01″>

With that done, what’s involved in displaying some version information to the user, say in an About screen in the app? Well that’s what I wanted to do with the app mentioned above – it was my Plasma app (a free graphics plasma effect demo written in Oxygene for Java).

To get version info we must access a PackageInfo class for the app as that can give us information about the Android package gleaned from the application manifest file – specifically the class exposes versionCode and versionName members that return the values from the manifest discussed above.

How do we get a PackageInfo class? That can be arranged by a PackagManager object that offers a getPackageInfo() method (that we can access as a PackageInfo property). Pass it the package name and it will return the goods for us.

The Context class is what Activity inherits from, and it defines two useful methods: getPackageManager() and getPackageName() – hopefully it will be patently clear these will finish the job off.

In the case of my plasma app I have layout resource containing a TextView called aboutText. I also have two string resources that define formatted strings waiting to have a version string (the version name from the manifest file) plugged in. For example, one of them is used to set up the About activity’s title and is defined thus:

<string name=”plasma_about_title”>About Plasma %s</string>

The code to access the TextView control and give it a formatted string containing the version information looks like this:

var aboutTextView: TextView :=
 
TextView(findViewById(R.id.aboutText));
var versionName :=
  PackageManager.PackageInfo[PackageName, 0].versionName;
aboutTextView.Text :=
  String[R.string.plasma_about_text, versionName];
Title := String[R.string.plasma_about_title, versionName];

If you want to use the original method names as defined in the Google Android documentation, as opposed to the equivalent implied properties, it would look like this instead:

var aboutTextView: TextView :=
  TextView(findViewById(R.id.aboutText));
var versionName :=
  getPackageManager().getPackageInfo(
    getPackageName(), 0).versionName;
aboutTextView.setText(getString(
  R.string.plasma_about_text, versionName));
setTitle(getString(R.string.plasma_about_title, versionName));

Notice we are making use of the overload of getString() that takes a string resource id and a list of format string arguments to use when building the formatted string.

Porting some Android SDK samples

July 13, 2012 in Guest Post, Java, Oxygene, Prism

As I mentioned last time, I’ve been porting some of the Java Android SDK demos over to Oxygene for Java. This is for various purposes:

  • to ensure I am on top of various Java code layout approaches. The one that requires the most faffing about is nested classes. In Java the nested class gets access to members of the outer class, thanks to having an implicit this parameter passed through the constructor. That requires a bit of manual rewiring, which is a bit of a bore, but no big deal.
  • to get some exposure to various additional Android programming areas.
  • to run more and more code through Oxygene for Java and report any latent bugs that show up when trying it out.
  • to build up more useful Oxygene for Java examples that can be packaged in with the product and thus be of reference use to Oxygene users
  • to find out what issues and bugs are lying in wait for unsuspecting newcomers to Android programming within the recesses of those SDK demos.

I’ve uploaded a bunch of them to Google Play now (see the end of this post) so anyone interested can check them out and report any problems left in there so I can try and remedy them. Of course they are demo apps and so you shouldn’t expect too much of them. They’re just there to demonstrate certain Android programming techniques and so aren’t professional-level applications.

In the last post I looked at the poor support for the exit-the-app-and-come-back situation with Lunar Lander and JetBoy. Well, poor support isn’t really accurate as the apps just crash out when you try and resume them. Poor implementation, poor planning, something like that perhaps.

Anyway, other common themes that come out of more demos are as follows:

1) Background image resources are not resized to accommodate screen sizes. Perhaps back when these demos were written, the various bitmaps used in AccelerometerPlay, JetBoy were larger than the largest of screens. Not now with tablets and large display phones.

In the case of an image on a game that will get an initial size on startup and not change, for example a game that is fixed to landscape or portrait orientation, then you can size the bitmap once after having loaded it. JetBoy is fixed to landscape orientation thanks to this attribute in its activity declaration in the Android manifest file:

android:screenOrientation=”landscape”

Similarly the AccelerometerPlay demo is forced to portrait with this attribute in the activity declaration in the Android manifest:

android:screenOrientation=”portrait”

If you draw in a View descendant, then override the onSizeChanged() method and you can resize the bitmap by passing it to the static Bitmap method Bitmap.createScaledBitmap() along with the target width and height, typically as passed in parameters to onSizeChanged(). For example, in the accelerometer demo I now have this:

method SimulationView.onSizeChanged(w, h, oldw, oldh: Integer);
begin
  // other stuff is here
  …
  // Resize the background bitmap
  // NOTE: original code did not resize the background bitmap
  // so it did not cover the background on larger displays
  mWood := Bitmap.createScaledBitmap(mWood, w, h, true)
end;

If you’re working with a SurfaceView and have implemented the SurfaceHolder.Callback interface then you can do much the same thing in the surfaceChanged() method.

You can also choose to size the bitmap on-demand when it’s needed from its original size to the required size for the target canvas. This will be a little less performant than a one-off resize but can be useful. For example, the JetBoy app has a ready screen before play starts. The background to that screen was not resized appropriately. If you didn’t want to resize the background bitmap once ahead of time you could identify the current size and target size as Rect objects and call an appropriate override of the Canvas object’s drawBitmap() method:

method JetBoyThread.doDrawReady(aCanvas: Canvas);
begin
  var src := new Rect(0, 0, mTitleBG.Width, mTitleBG.Height);
  var dest := new Rect(0, 0, aCanvas.Width, aCanvas.Height);
  aCanvas.drawBitmap(mTitleBG, src, dest, nil);
end;

2) Older games were coded to assume the presence of a directional touchpad (D-Pad). Most modern devices come without one of these, so to make them usable on current devices I’ve had to add in onTouchEvent() overrides in either the View or Activity for simple screen touch responses. In the case of the Snake demo app I implemented GestureDetector.SimpleOnGestureListener to handle directional swipes.

3) Some demos have been updated over the Android releases to take on newer behaviour. For example, there is a simple Bluetooth Chat demo. You can install it and run it on two devices and the users can connect and do a simple Instant Message type chat. In the most recent SDKs for Android 4.0.x (Ice Cream Sandwich) this demo has been tweaked compared to what you see in the samples for the older Android versions. This newer version uses the so-called Holographic theme introduced in Android 3, which adds an ActionBar to the app as a side-effect. What are menu options in the earlier version are now ActionBar actions when installed on a more recent OS.

Also the newer version of the app offers both secure and insecure Bluetooth connections, something the original version didn’t as insecure Bluetooth connections were introduced in Android 2.3.3 (Gingerbread MR1).

The initial question was which version of the demo to bring over to Oxygene. In the end I got the translated app to operate on any Android version from 2.0 (Eclair) onwards.

To get the Holographic theme to be applied for Android 3 (Honeycomb) and later (and thus get the ActionBar) I took advantage of Android’s resource system (as mentioned here). I defined an app theme to be based on Android’s default old-school Theme in a resource file in res\values as per usual.

<resources
    xmlns:android=”
http://schemas.android.com/apk/res/android”>
  <style name=”AppTheme” parent=”@android:style/Theme”>
  </style>
</resources>

But then I defined the same app theme to be based on Theme.Holo in a resource file in res\values-v11.

<resources
    xmlns:android=
http://schemas.android.com/apk/res/android>
  <style name=”AppTheme” parent=”@android:style/Theme.Holo”>
  </style>
</resources>

If running on API 11 (Android 3.0 aka Honeycomb) or later the theme definition will be pulled from this latter directory. All that’s left to finish the job is to apply the app theme to the application in the Android manifest file:

<application android:label=”@string/app_name”
             android:icon=”@drawable/app_icon”
             android:theme=”@style/AppTheme”
             android:debuggable=”true” >

  …
</application>

That’s the appearance. But it was also important to ensure the option for establishing an insecure Bluetooth connection was removed from the menu if running on Android earlier than 2.3.3. Since the menu is defined in a menu resource file this simply involved having two menu definitions, one in the usual res\menu directory and one in res\menu-v10. The menu definition in res\menu has the problem option removed; the menu definition in menu-v10 will be used on Android API 11 (2.3.3) or later and has all menu options defined.

The final aspect of keeping the app version-agnostic is to check the code and what relies on the newer aspects of the source. Anything that needs to be skipped on Android versions earlier than 2.3.3 can be conditionalised using Build.VERSION.SDK_INT, something like this:

if Build.VERSION.SDK_INT >=
     Build.VERSION_CODES.GINGERBREAD_MR1 then
begin
  …
end;

Uploaded demos

Ok, so I’m done pulling Java code over to Oxygene and making it work properly for the time being. I’ve tidied up the demos that I’ve ported and uploaded them to Google Play, giving as useful a description as I can for each of them. The following are online – if you encounter any problems or have any simple improvement suggestions (bear in mind they are meant to just be ports of existing demos) I would appreciate hearing from you.

  • AccelerometerPlay: demonstrates the accelerometer sensor by representing a slab of wood with three shiny balls on it. Tilt the device and the balls roll in a quite realistic manner.
  • Bluetooth Chat: install on 2 Android phones and you can establish a connection (secure or, if on Android 2.3.3 or later, insecure) and have an IM-style chat
  • Cube Live Wallpaper: two live wallpapers. One is a rotating wire cube. One has a settings page to allow to to choose between a rotating wire cube and a rotating wire dodecahedron. On Android home screens that support it (not HTC Sense 3.0 or later, or Android 4.0 or later) the wallpaper responds to offset messages, meaning that the shape will rotate as you move from home screen to home screen.
  • JetBoy: a scroller game that demonstrates Android’s JET audio engine. Destroy a certain number of asteroids in a certain amount of time by firing in time to the music.
  • Lunar Lander: use direction and thrusters to safely land on the landing pad. I’ve mapped touches on areas of the screen (as per the app description on Google Play) to the D-Pad controls, but apparently it’s still a but tricky. This could just be a function of the game implementation, or maybe the D-Pad to screen mappings. Any thoughts, let me know!
  • Snake: The classic snake game. Swipe the screen to change the snake’s direction and reach the apples. Mind yourself and mind the walls!
  • Wiktionary ‘Word of the Day’ Widget: install on your home screen and you get Wiktionary’s word of the day displayed, along with the word’s definition. Touch the widget to open up a Wiktionary browser where you can follow links to other words, search for words or go to a random word.

The full set of Oxygene-ported Android SDK apps can be found at this link.

Alternatively all my Oxygene-powered Android apps can be found at this link.

Android game loops

July 10, 2012 in Guest Post, Java, Oxygene, Prism

I’ve been porting some of the Android SDK samples from their original Java over to Oxygene for Java, with the hope they’ll be included in a forthcoming update to the product.

I’d already contributed a port of the AccelerometerPlay demo, which is a neat little demo of using the accelerometer to control several balls on a surface (the screen).

Among other examples I’ve been looking at are the Lunar Lander and JetBoy demo games. Now, if you wanted to start writing a graphics frame-based game that used a SurfaceView as its output you’d think these would be a great starting point, right?

LunarLander

Wrong!

Well, kind of wrong anyway.

JetBoy

The games work ok and you can play them, although they both have the shortcoming that they were written back in the days when most devices had a D-Pad (directional pad) and/or physical keyboard. Consequently the original examples are unplayable on many current devices. That’s no problem – it’s not much trouble to add in support for touches on bits of the screen or swipes across or up and down the screen. Actually I had to add in swipe support for the Snake sample game, which also relied on a D-Pad, but since that one’s not based on a thread (being a simpler game it uses a Handler and its sendMessageDelayed() method).

The problem with Lunar Lander and JetBoy is with how their thread-based operation has been laid out. The JetBoy architecture was based on the simpler Lunar Lander and so both games suffer from the same problem. The symptom is that if you switch away, maybe by pressing Home or by a phone call coming through, and then switch back the game crashes out. If you look at a logcat from either app running and crashing you’ll find that the problem is an IllegalThreadStateException being thrown with the message:

java.lang.IllegalThreadStateException: Thread already started.

This doesn’t look like a very good basis for a couple of evidently appealing sample apps, being designed with a thread crash in… Clearly people will base their own games on these apps and be rather frustrated by this poor design.

Anyway, enough of the criticism. What’s the issue here? Well, a cursory search on the web shows this has (unsurprisingly) cropped up a lot of times and there have been various ways it has been responded to. So let’s look at the problem and the solution.

The games have an Activity whose UI is made up of a SurfaceView descendant. The game logic is contained in a Thread descendant. When the app starts up and the activity’s onCreate() method runs it creates the custom surface view and asks that view to create the thread.

The surface view has a couple of methods that mark the lifetime of the actual drawable surface: surfaceCreated() and surfaceDestroyed(). In surfaceCreated() the thread is set in motion with a call to its start() method. When the surface is destroyed, for example by switching back to the home screen, two things occur. Firstly a member field flag is set to indicate that the thread’s body (its run() method) should stop whirring round updating state and drawing frames. Then the thread’s join() method is called, which blocks the surface view thread until that run() method has done its job and exited.

Ok, with me so far? No evident problem so far. What happens when we switch back to the app?

Well, when the app’s UI resumes the surface view’s surfaceCreated() method is called, which calls the thread’s start() method to start it off again. And therein lies the nub of the problem. As the documentation states, start() will throw an IllegalThreadStateException if the thread has been started before.

Because of this coding scheme the Lunar Lander and JetBoy apps are set up to fail. So, what’s a good solution?

Well, I’ve tried a couple of options, some of which are frowned upon as not being the right way and settled for the suggestion of StackOverflow user Pompe de velo in this post. The changes required are as follows:

  • in the thread define member variables:
    • var mPauseLock: Object := new Object;
    • var mPaused: Boolean;
  • have the thread’s run() method keep iterating endlessly (while true do… instead of while mRun do…).
  • in this loop, after all the individual iteration’s physics update and frame drawing add:

    locking mPauseLock do
       while mPaused do
         try
           mPauseLock.wait
         except
           on e: InterruptedException do
             { whatever };
         end

  • if your thread already has pause() and unpause()/resume() type methods implemented then great. If not add them.
  • have the pause() method do this:

    locking mPauseLock do
      mPaused := true;

  • have the unpause() method do this:

    locking mPauseLock do
    begin
      mPaused := false;
      mPauseLock.notifyAll
    end;

  • in the activity’s onPause() method call the thread’s pause() method
  • declare a member field in the surface view:

    var mGameIsRunning: Boolean := false;

  • in the surface view’s surfaceDestroyed() method remove all the code relating to managing the thread
  • have the surface view’s surfaceCreated() method change the call to thread.start() to this code:

    if not mGameIsRunning then
    begin
      thread.start;
      mGameIsRunning := true
    end
    else
      thread.unpause;

Yeah, so there’s a few changes there, but once done the app can survive being switched away from and back to.

It would probably be a good move to take the fixed app, strip all the logic out and use it as a skeleton gaming loop app, which I may well do.

For now, I have more bugs to fix in SDK demo apps I’m porting over. Currently I’m getting on top of an issue with the BluetoothChat demo where exiting and restarting the app means connections from another device no longer show up on the UI. It would appear the Android SDK demos didn’t get a particularly good test through….. What’s more of a shame, though, is that despite numerous people reporting issues, the demo apps do not get updated to fix the problems.

<sigh>

Android XML IntelliSense

July 9, 2012 in Android, Cooper, Java, Oxygene, Visual Studio

Many of the Android resources, from layouts and styles to animations and even manifests are defined in XML. The XML spec for all of these different resources is a bit dynamic and varies based on things outside the XML document. For these and other reasons there is no official schema provided by Google to define the XML document, as would be needed for Visual Studio to provide IntelliSense for these XML files.

The “June 2012″ release of Oxygene for Java changes all that. We’ve generated 4 schema files that provide IntelliSense for pretty much all the Android XML resources you may encounter. The IntelliSense provides elements and attributes, and in a few cases values for everything from Layouts to Manifests.

Because of the way the XML IntelliSense works in Visual Studio, and because the Android XML doesn’t completely implement the schema as it should, we had to rename the XML files to make them work with the schemas and provide IntelliSense. So to get all the Android IntelliSense goodness, you need to rename your XML layouts to *.layout-xml and every other XML document to *.android-xml. All of the examples and templates are updated with this new naming.

Android Solution Explorer

Since there is no official schema, and the XML specification in the Android documentation is a little vague in places, we are looking for your feedback how better to improve the IntelliSense. An important area you will notice is with user defined widgets in the layouts. Currently, the IntelliSense schemas are static, so if you add a new widget, it won’t show up in the IntelliSense. Let us know if you run into any other situations where the IntelliSense could be a little more intelligent.

Also, to make the IntelliSense even more helpful, we added a range of new item templates to Android projects. They all get put into the correct folder as required by the Android spec. For Drawables, it puts them in the default /res/drawable folder. From there you can move them to a drawable folder for a specific DPI.

Add New Android Templates

Likewise, if you come across any other Android templates that should be included to make your life easier, please let us know.

Retro effects with Android

July 8, 2012 in Guest Post, Java, Oxygene, Prism

A few weeks back I was browsing Paweł Głowacki’s blog and saw his write-up on implementing both a parallax starfield as well as a 3D starfield using Delphi and FireMonkey. Quite taken with the classic starfield demo idea I though it might be neat to have a go at putting together an Android implementation in Pascal using Oxygene for Java.

As Paweł did, I used the basic Python logic from http://codentronix.com/2011/04/27/a-cool-parallax-starfield-simulation-using-python to build up the parallax version from and then used the logic from http://codentronix.com/2011/05/28/3d-starfield-made-using-python-and-pygame for a basic 3D implementation. Then I bumped into a nice DHTML JavaScript implementation of an interactive starfield at http://www.chiptune.com/starfield/starfield.html, where moving the mouse changes the aspect of travel through the starfield.

So I knocked up some equivalent logic in Oxygene in an Android application and uploaded the result to the Android Market, oh, I mean Google Play. You find the free app through this link if you want to check out the results. The interactive starfield has some settings to customise the number and speed of stars as well as whether touching the screen changes the travel aspect.

StarfieldAppMenu StarfieldAppSettings

StarFieldApp StarFieldApp2

Clearly the logic is reasonably straightforward – in each case it’s really just dots of various sizes drawn on the Canvas of a SurfaceView. This is done again and again after having moved the positions of the stars in ‘space’, but of course care must be taken to be CPU-friendly. To that end an Android Handler is used and each time a frame is drawn, the next one is scheduled in for some small time period later using a call to its postDelayed() method.

Anyway, I was quite pleased with how this little app turned out, and how it gave me an opportunity to go through the Google Play application publication process. And then I started thinking about other old effects from the demos that used to be quite popular in the late 80s and early 90s…

My favourite was the plasma effect: an undulating oozing flow of colours shifting through the screen. A bit of research helped me understand the general principle of how the plasma effect is implemented, with a plasma function at the heart of it. I found a selection of different plasma functions and rolled them into a configurable Android plasma app built with Oxygene for Java, available for free at this link:

Plasma1 Plasma3 Plasma2

Plasma4 Plasma5 Plasma6

These plasma effects are implemented by pre-assigning an interesting palette of colours and then iteratively calculating the value of each pixel of the plasma surface and plotting it on a bitmap. To keep things performant the plasma surface is typically rather less dense than the pixel count of a smart phone screen and so this bitmap is then stretched onto the Canvas of the underlying SurfaceView. However, to minimise the evident pixellation some of the effects actually render virtual pixels and use a random jitter (x & y offset) in conjunction with opacity to smooth out the edges.

Having been bitten by the bug of retro demo effects I then bumped into the Demo Effects Collection Open Source project. This shows, in C++, how a whole raft of old demo effects are implemented, so I picked a few other effects I had a nostalgic affection for and concocted Retro Effects, another free Android app built with Oxygene for Java and available at this link. This one has a fire effect, a particle explosion, shadebobs and copper bars (as well as a starfield and plasma implementation for completeness):

Fire Shadebobs

Copperbars Explosion2

This has all been a terrific trip down memory lane for me, resurging my interest in the old demo effect scene, and using Oxygene for Java has allowed me to build the apps on my favourite mobile platform, Android, using my favourite language syntax, Pascal.

Oh, just in signing off I should mention that I also uploaded a couple of live wallpapers, one with the interactive starfield and one with the configurable plasma functions. Live wallpapers are quite a nice distraction and needn’t be as much of a battery hog as they are sometimes made out to be (especially if implemented carefully). The Android live wallpapers do, however, have a nominal download charge associated with them.

I’ve been porting some of the Android SDK demos from the original Java to Oxygene, including the live wallpaper demo (a rotating cube and a rotating dodecahedron), so I’ll probably blog some technical details on how these things are built at some point in the near future.

Avatar of marc

by marc

The Oxygene “Project Switcher”

May 22, 2012 in .NET, Java, Oxygene, Platforms

While we’re putting the finishing touches on the May release for Oxygene, due some time next week, i wanted to share a first peek at what’s in the works for the release after that:

The Project Switcher

If you have ever worked on a solution where one source file was shared between multiple projects, you probably have seen Visual Studio pop up this little dialog:



What happens essentially is that you have your file, say Foo.pas, already open from “Project B”, and now you double-clicked Foo.pas in “Project A” or clicked an error message from that project. And up comes this dialog. If you dismiss it, the file shows just fine, but it shows in the context of the wrong project, so your conditional defines, if any, are off; CC might not show you the items you are looking for, etc.

Annoying, right?

Well, say good-bye to this dialog once and for all, because we thought so too, and for the June release, it’s going to go away: we are introducing the Project Switcher (a.k.a. the Project Indicator).

In the following screenshot, you see a side project i’m working on right now. There are different projects in the solution that contain (more or less) the exact same code files. One is for Echoes (a.k.a. Oxygene for .NET) and one is for Cooper (a.k.a. Oxygene for Java). There are conditional defines all over the source files.



But take a closer look a the top right corner of the Editor. What’s that? That’s the Project Switcher, and it shows you two pieces of information:

For one it shows you the name of the project the current file is in (“RemObjects.Sugar.Cooper”, in this case). For another, it indicates the platform for the project, using the background color (yellow if for Cooper/Java; Blue is for Echoes/.NET).

So far so good,but note there’s also a little disclosure triangle next to the name. Click that, and you get a list of all the projects this file is part of. Select a different one, and not only does the Project Switcher change its display, all conditional defines and other IDE smarts for this file change to match the new project:



This allows you to seamlessly switch the “context” in which you are working. In this case, i might write a few lines of code for the .NET version of the project, then switch over, and write a few lines for the Java version. But this is similarly useful if you have several projects for the same platform that share source code.

By default, this new UI only shows for files shared between two or more projects, but if you like, you can also enable to show the Project Indicator (minus the switcher triangle) for any file in a multi-project solution, or even when only a single project is open.

That’s Not All Folks

But that’s not all. Remember the annoying dialog we talked about at the beginning of the post, and how i said it was gone? It is. If you double-click a file in Solution Explorer, instead of popping up the dialog, we just open the file and switch it over to the right project.

The same goes for clicking on messages in the error list. Not only will you see the file in the context of the right project immediately — the IDE will also narrow down any inline errors it displays, so you can focus on the errors from the right project. So whenif your code fails to compile and you get errors from both projects, it’s now even easier to keep them apart.

What’s Sugar?

“Never mind all that”, you ask, “what’s Sugar”? Ah well. Sugar is a small library that we have been working on as a side project, and it aims at making it really easy to share low-level business logic code between Oxygene projects on different platforms. I don’t really want to go into more detail just yet, but suffice to say it will have a rather unique and cool approach at the problem. It will be open source, and part of a future Oxygene release.

Summary

So there you have it: the Project Switcher/Project Indicator — one of many features where Oxygene takes the general Visual Studio code editing experience to the next level. You should find a preview of this in the next beta drop and, as indicated above, this feature is planned to ship in the June 2012 update.

Let me know what you think!

marc

Android development session at mobile-focused conference

May 17, 2012 in Guest Post, Java, Oxygene, Prism

On 29th June, 2012 I’ll be travelling to Cambridge, UK to speak at Mobile East 2012, a mobile-focused conference. I’ll be delivering a session on Android development using RemObjects’ Oxygene for Java development tool and catching several of the other sessions during down-time on the day.

I’m looking forward to it – it’s been some months since I’ve spoken at a conference!

Avatar of marc

by marc

Announcing Oxygene 5.1 and Embarcadero Prism XE2.5

May 17, 2012 in .NET, Java, Oxygene, Prism, Visual Studio

Hi.

i’m very happy to announce the immediate availability of Oxygene 5.1 for .NET and Java.

What’s new in Oxygene 5.1

We’ve kept busy since the initial release of Oxygene 5.0, which introduced Oxygene for Java, last fall. With the exception of March and December, we have shipped monthly interim releases in September, October, November, January and February, each containing literally dozens of fixes and minor enhancements.

Now the time has come for Oxygene 5.1 (and Embarcadero Prism XE2.5), our next feature release. So, what’s new in this .1?

Visual Studio 11. Oxygene 5.1 brings full support for Visual Studio 11, the latest and greatest version of Microsofts’s development environment. Visual Studio 11, currently available as beta, provides a wide range of enhancements and — most noticeably — a brand new and more streamlined look and feel. Oxygene integrates with the current beta/preview build of Visual Studio 11, and a lot of work has been put into adopting the IDE’s new look and feel all-throughout Oxygene, from a redesigned Solution Explorer theme to reworked templates.


Echoes and Cooper in Solution Explorer

While Visual Studio 11 is still in beta, we are not shipping an installer that includes the Visual Studio 11 Shell yet — but that should not stop you from experiencing Oxygene in the new IDE, because you can download the beta version for free.

Of course Oxygene 5.1 will continue to work great with Visual Studio 2010 as well.

Metro and WinRT. Windows 8 is coming, and with it the new Windows Runtime (WinRT) API stack for creating visually stunning touch-enabled Metro applications. Oxygene 5.5 provides experimental support for developing Metro apps and for working against the WinRT APIs, based on the current Consumer Preview of Windows 8 (which can also be downloaded for free from Microsoft. Developing Metro apps requires Visual Studio 11 and Windows 8.


Echoes and Cooper in Solution Explorer

Flow Control Analysis. The Oxygene 5 complier has been extended with an enhanced flow control analysis infrastructure that analyzes your code beyond the basic compile and gives you additional warnings and hints to point out possible coding errors, unnecessary code or other code smells. Of course, this analysis integrates with our existing Inline Error infrastructure, giving you details right inside the editor window.

Await. Oxygene 5.1 introduces the “await” keyword that is also coming to the next versions of C# and VB.NET. Simply put, “await” lets you unwrap asynchronous calls and write linear code that can use or build on the results of asynchronous operations. Of course “await” integrates seamlessly with and extends the great support for asynchronicity that Oxygene has long provided, by working with our exiting “future” types, async statements and async methods. You can read more about the “await” keyword in my previous blog post.


The "await" keyword in action

Mapped Types. Finally, Oxygene 5.1 adds support for an exciting new language concept, called “mapped types”. Mapped types are virtual classes or interfaces that map to existing types in the framework or your own code, exposing them with a different API. One great use for mapped types is the ability to expose similar classes with slightly different APIs in a common fashion: for example the java.lang.Dictionary class in the Java framework could be mapped to look like the System.Collections.Generic.Dictionary class provided by .NET, so that common code can be written to run on both platforms.


Echoes and Cooper in Solution Explorer

Get Your Copy Now!

Oxygene 5.1 is now available for download, both in our registered downloads section on the customer portal, and on our free/trial downloads page. Enjoy!

Managed is the New Native

May 15, 2012 in .NET, Java, Oxygene, Prism, Windows

It used to be that native development referred to compilers outputting code ready to execute on the target CPU. At the time, the pool of possible CPUs was small, and the alternatives where runtime interpretation. Since then a lot has changed. Modern CPUs have multiple modes of execution (protected mode, long mode, etc.) and optionals instruction sets (SSE4a, SSE5, etc.). A “native code” compiler must choose a minimum level to target, ignoring “higher” level functionality available on newer CPUs. This leaves programs unable to take advantage of the latest CPU innovations, and often running in a legacy compatibility mode on the very CPU it targets.

What is more native on the latest 64-bit processor: 32-bit x86 code or intermediate code just-in-time compiled to take advantage of the 64-bit architecture and latest SSE instruction set? Not so simple, is it?

Managed code platforms such as Java and .NET have a “native” advantage that no unmanaged (so called “native code”) compilers can match. Because managed platforms distribute their programs in an intermediate format (Intermediate Language [IL] Assemblies for .NET and Byte-code for Java) the Just-In-Time (JIT) compiler is able to compile the program to specifically target the CPU it is running on. This means the program can scale up or down as necessary on each CPU, even a CPU that wasn’t released when you wrote the code.

A misconception is that managed applications are slower than unmanaged applications, or that managed applications are interpreted at runtime. A managed application is JIT compiled into highly optimized machine code immediately on execution.

The alternative for non-managed compilers is to compile to multiple targets and then provide software emulation for CPU instruction sets on older CPUs. The result is a more bloated program that contains emulation code that is rarely used, or a program that is unable to take advantage of the latest CPU optimizations.

Now that managed is the new native, it leaves developers free to focus on what is really important: A Native User Experience.

The Importance of Compatibility

May 10, 2012 in Android, Cooper, Java, Oxygene

When you are choosing a tool or library for Android development it is really important to consider platform compatibility. Some tools only support the latest and greatest version of Android, while the majority of devices are still running Gingerbread. It is always useful to consult the monthly updated Platform Versions Distribution when considering which version of Android to target.

May 2012 Android Platform Version Distribution

While Ice Cream Sandwich (Android 4 / API 15) is all the rage, it is only installed on around 5% of the devices. Gingerbread (Android 2.3 / API 10) is the current front running with over 60% of the devices. It took over from Froyo (Android 2.2 / API 8) just last year. If you target Froyo or greater, you have the potential to reach a whooping 93.5% of the 300+ million Android devices. A whole lot better than the 5% that Ice Cream Sandwich gives you.

That is why RemObjects SDK for Java and Oxygene for Java support Froyo and newer – to give you access to the greatest possible number of Android devices. This level of support and compatibility is the result of our commitment to provide a native developer experience on each platform we support.

And thanks to the Support Package compatibility libraries your app can take advantage of a lot of the latest Ice Cream Sandwich features even when running on a Froyo or Gingerbread device. That way you can have your dessert and eat it too!