Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

Wednesday, August 3, 2011

Android Live Wallpaper tutorial

Continuing my Android exploration, I found AndEngine.
It's a great tool to do graphics and the forums are very active and helpful.

Based on a few of the samples that include a multiplayer pong, I decided to go for a Pong Clone as a first approach to Android Games, and see how it works.
The basics are covered in the tutorials and examples in AndEngine forums.

I started installing the engine and examples. They worked great and was easy to read and the code is very readable.
Though as the engine is new and in constant development, it changes faster than the samples found on the web, and some tweaks have to be done to get it to compile.

Then I found the live wallpaper extension and in the forums a Template by Mimminito for AndEngine Live Wallpapers, and it seemed like a good idea to have a pong game playing itself as a wallpaper, so I moved my pong code to it.

I had some troubles at first, figuring out how to move objects around.
For example, the ball:



When the object is created, you can override the update method, and add the behaviour you want to it.
I thought this was going to solve all my problems, but when I got to the paddles, the overriden function cant access the ball position, so I went looking around for info on how to do this, and found that I can override the method
@Override
public void onUpdate(final float pSecondsElapsed)

and put my logic there.

The wallpaper looks great, very retro, and can be found on the Android Market





Here's the full code:

Thursday, July 28, 2011

Start custom Service when Android starts up

Another interesting part of the RemindMe development is considering what happens when the phone is powered up.
The Reminder service must be "woken up" for it to be useful.

The way to do this, is to create a receiver, and hook it up to the android action BOOT_COMPLETED

In the AndroidManifest.xml, declare the following receiver:



With this, every time the phone is powered up, after boot is complete, AlarmBroadcastReciever will be called, which sets up the inexactRepeatingAlarm mentioned in my previous post.

Wednesday, July 27, 2011

Android Reminder Application Development

I started working on a simple reminder application for Android.
The idea is to gain some experience in android development, and also to try to create a useful tool.

You can find the latest version here: RemindMe

I'm still working on it, I won't post the complete code here as it might change, but feel free to email me and I'll provide the latest version.

The idea of the app is to create a tool that can set up simple text reminders, independent of the actual time.
For example, to be able to say "remind me in two hours" and you don't have to configure when that is, just the delay.
It also allows for daily reminders.

The design is fairly straightforward: A SqlLite database to store the notifications, the application to create them, and the task to poll the database and alert the user.

One thing particularly interesting here is how to schedule the task to check for expired notifications.
The way to do this is to set up an AlarmManager and utilize the setRepeating() method.
But there's also a setInexactRepeating() method that allows to set the time, though the android system does not necessarily fire it at the exact moment, but might wait and group different alarms that happen around the same time, and then fire them all at once, making it more power-efficient.

This is how the wake up alarm is set up for the Reminder:



What this does is set up a timer to check for expired reminders every 30 seconds, but not necessarily exactly in 30 seconds, more likely when android wakes up and has some task to perform.

The app is free in the market, and i'm open to suggestions on how to improve it!