Create a live aquarium wallpaper in Android
Posted on: 27 Dec 2010
| Filed under: Android, CodeProject, Google
| Tagged under: Andriod
|
comments (28)
Download the source code: http://www.rajeeshcv.com/download/LiveAquariumWallpaper.zip Android package: http://www.rajeeshcv.com/download/LiveAquariumWallpaper.apk (I have only tested this in the SDK simulator and haven’t considered all the screen sizes, so may find some UI glitches)Few weeks ago I started learning Android programming , so this article is an outcome of that out-side office study :). Here I will be explaining – how to create a live wallpaper which looks like an aquarium with fishes swimming across the screen. The fish animation is done using sprite technique. Courtesy :
- Fish sprite used here is from a code project article - http://www.codeproject.com/KB/GDI-plus/LovelyGoldFishDeskPet.aspx
- Creating animation using sprites - http://www.droidnova.com/2d-sprite-animation-in-android,471.html
public class AquariumWallpaperService extends WallpaperService {
@Override
public Engine onCreateEngine() {
return new AquariumWallpaperEngine();
}
class AquariumWallpaperEngine extends Engine{
private Aquarium _aquarium;
public AquariumWallpaperEngine() {
this._aquarium = new Aquarium();
this._aquarium.initialize(getBaseContext(), getSurfaceHolder());
}
@Override
public void onVisibilityChanged(boolean visible) {
if(visible){
this._aquarium.render();
}
}
@Override
public void onSurfaceChanged(SurfaceHolder holder, int format,
int width, int height) {
super.onSurfaceChanged(holder, format, width, height);
}
@Override
public void onSurfaceCreated(SurfaceHolder holder) {
super.onSurfaceCreated(holder);
this._aquarium.start();
}
@Override
public void onSurfaceDestroyed(SurfaceHolder holder) {
super.onSurfaceDestroyed(holder);
this._aquarium.stop();
}
}
}
Aquarium class wraps all the rendering logic, as well as creating the fishes. This also starts a thread which is responsible for updating the view.
Read more...