Appliweb

All dimensions of your web developments

Affichage des articles marqués android

About Android,

We all know Android is getter bigger and bigger each day. More applications
(http://www.androlib.com/appstats.aspx), more phones
(http://en.wikipedia.org/wiki/List_of_Android_devices),
are coming each day, and this is growing exponentially.

I really enjoy this, mainly because:

  • It’s an OpenSource platform
  • Java is the main development language for it
  • I don’t like Apple we-decide-everything-and-you-pay business model.

As you can see, in 2 years, Android has become  one of the main competitor in the smartphone market (along with Nokia, BlackBerry and Apple).

Now let’s talk about Java Mobile Edition

  • It is the real winner for low-end phones
  • In high-end market, only Nokia and BlackBerry supports it, and it seems you’ll have to use proprietary API for a good result.
  • Evolution is too slow for mobile: Inside the JCP for JavaME, I’m sure there are lots of discussions between competitors companies, and that takes a lot of time.
  • Who understands the MIDP/CDC/CLDC concepts (http://java.sun.com/javame/technology/index.jsp) ?

Oracle didn’t ask me, and I’m sure they have lots of smart people thinking of these facts, but that won’t prevent me from telling my opinion.

I know this is almost infeasible from a business and maybe technical point of view, but I think it would be a good thing if:

Android becomes the next Java ME !

And I mean, the last Android version, that takes shape rapidly in Google offices. Don’t try to take one version and go again with 3 year release schedules !

Let’s just imagine if Oracle (-and Nokia, and BlackBerry, and Sony-Ericssson, etc…) decided to follow Google on JavaME:

The not so good things:

  • Oracle will loose control of mobile market software developement, but they are loosing it anyway, and I’m not sure they’re interested in it.
  • Of course, Android is not just Java, but it’s a Linux OS too. And I think all the phone makers would have to switch to it too.
  • And even if the language is Java, the JVM that’s running is not really Java… But who cares ?

The really good things:

  • We would have a new release every 6 monthes, with the features of the latest phones !
  • There would be as many hardware maker backing Java as a mobile platform
  • Apple would have a run for their money – What a dream
  • Java ME will be the coolest thing in mobile again !

Oracle, If you hear me, just think about this.

Gerard.

Since google « offered » Java support to their cloud platform , I just see java coming everywhere now.

While Oracle is getting rid of the OS to run directly Java on VM hypervisors, I see VMware (Spring) and salesforce.com doing the same….

Not talking about the Android Platform, which is now the most dangerous concurrent to IPhone…

Who said Java is dead ? I just think they’re plain wrong….

In this third installment of the Android Game Development series, I’ll try to explain how to construct the project. I know the LunaLander sample directly uses thread and SurfaceHolder.Callback, but my first goal is simply to display an image, I will complexify later.

Games don’t use Views

In Android, most of the games don’t really use the View hierarchy of objects, because it’s too slow and cumbersome. They instead write directly to a Canvas.

In order to get the Canvas displayed to the screen, you create a SurfaceView object.

Thus, the page is a  FrameLayout, and inside we put our SurfaceView class, as shown in the main resource file:

How to insert an Image into Android project ?

Using Gimp, I have drawn a small red ball:  Nice isn’t it ?

How can I use it in my project. Well it’s quite simple, you copy the file in your project res/drawable subdirectory, you update your Eclipse Project (F5 key). Automagically, you see your new image in the project, and the Eclipse Plugin regenerates the R class so that you can easily access the resource in your code or Layout file. Just take a look at this sample (called by the constructor of our SurfaceView):

We can now easily override the onDraw method on our SurfaceView derived class, and display the image:

Notice we set the position and dimension to display in the image itself, and tells it to display into the canvas. I would have expected the other way round (calling a Canvas method to draw the image).

I run the  project and here is the result :

Well something got wrong, but what ? Maybe I should check in Android documentation how to see some sort of logs or whatever, but for now, each time I get this, I’m clueless about what went wrong.
This time it was easy, I put the wrong class name in the layout.xml file, and it couldn’t find my SurfaceView class. Too bad Eclipse didn’t warn me about this. I fixed the error, started again, and then:

A Black screen. No Error but no red ball neither….

Running it under debugger shows me that the onDraw method on my SurfaceView class is not called !

After some more experiments, (checked the LunarLander sample, tried to draw a big green square on Canvas, etc….) I finally managed to make it work.
To have the SurfaceView displayed, you have to set a background color. With my init method like that:

I get the « good » result as follow: Yeepeee !!!


GC.

Welcome into part 2 of the Android blog series !

Today, I will try to explain the concepts I discovered when creating the project.

Finding a Sample:

When trying new libraries or new functionalities, I always try to find sample code I can analyse and copy to my own project. Fortunately, Android project pages contains such samples.

One of them seems to be a perfect starting point for my game: The Lunar Lander Sample. It’s a classic game where you want to land a lunar module by switching off and on reactors. The difficulty is that the module follows gravity rules, and you really need to predict it’s behavior.

Remember this game now ?

The documentation explains to a great extend the source code of the sample, so I won’t repeat it here. Well, just in two words then.

General Guidelines:

The Main class is called an Activity. An Activity is like a controler (in MVC pattern), there can be many activities in a single application. Think of it has a screen in your application. It creates a View class, either programmatically or by reading an XML description file. The View class represents, errr…. the View part of the MVC pattern.

All images, view xml files and string resources are parsed by a sdk tool that generates a class, the R class (what’s this name ???), that contains the Ids of these resources. You can write your application like that:

- You design you application U.I. using the XML file (and the plugin shows you instantly the result).

- You override the  onCreate function in your activity class to load and set the view to display.

- From the View class you just created, you get the Java classes of your controls  (buttons, input fields) by using their Ids in the generated R.class

-  You then can get / set  the values of these controls, listen to a click, etc….

- Of course, for a game, you don’t use the View classes hierarchy, but directly draw into a canvas. More on that later.

NB: The eclipse plugin handles SDK tools for you.  It re-generates automatically the R.class (Did I told you the name was awful ?) whenever you create a new resource, it immediatly shows a bad reference in your layout file, it can display the result of your layout (screen below), and it packs the project and installs it into the emulator when you click on the Eclipse Run button.

GC.

As a side project, I’m trying to develop a small game in Android.

As you know, Android is the new open source platform, designed by Google, for smartphones.

It is based on Linux, and the language used to develop applications on it is Java. So I decided to try to develop a small application for it: A game.

I will try to  explain here the things are discovered in this journey.

The project:

A very simple game that uses the touch screen capabilities of the phone: You throw a ball using you fingers and it must either go into holes, avoid pitfalls, bump into, errr…. bumpers and so on. You will have many different levels with many kinds of obstacles to overcome. This game will involve precision in your fingertips !

Starting:

First I downloaded the Android SDK, along with Eclipse and it’s plugin. All is clearly explained here and installs without an itch. Along with the SDK comes a smartphone emulator, that shows this:

Nice no ?

The Eclipse plugin integrates Android SDK seamlessly with eclipse: You can create a new android project, run it in the emulator, design the screen (with preview), etc….

Next part will talk about creating the game project using a provided sample  project.