2

I have a graphical program that I would like to manipulate to liveWallpaper.. I went through a couple of the tutorials and it looked like it fit the mold pretty well.

So I started but soon I realized that LiveWallpaper doesn't SurfaceView.

fine.. so I see.. SurfaceHolder obj = getSurfaceHolder(); then some methods to deal w/ the surface..

anyone mind giving me the quick rundown.. I don't have good explanation for onSurfaceChaanged(), OnVisibilityChanged, OnSurfaceCreated(), OnSurfaceDestroyed. Seems like one you get a good layout for LiveWallpaper you can just use a pretty generic template and crank em out..

DJPlayer
  • 3,244
  • 2
  • 33
  • 40

1 Answers1

1

I use the following code to paint the wallpaper:

void drawFrame() {
    final SurfaceHolder holder = getSurfaceHolder();

    Canvas c = null;
    try {
        c = holder.lockCanvas();
        if (c != null) {
            //do your drawing here
        }
    } finally {
        if (c != null) holder.unlockCanvasAndPost(c);
    }
}

Using this you can draw on a Canvas as you are used to.

I personally don't override onSurfaceChanged() and onSurfaceDestroyed(). I do override onSurfaceCreated() to start drawing. You need onVisibilityChanged() to start/stop the drawing if the LWP becomes visible/invisible.

Thomas
  • 1,508
  • 2
  • 22
  • 35