1

(Android) I am working on adapting a full-screen analog clock app to a live wallpaper. The app use three separate ImageView for hour, min, sec hands and RotateAnimation.

I have been looking around for a method to use ImageView in live wallpaper. this and this indicates that this should be possible with measure() and layout(), but I don't really know how to use it. For example, I use the code below to load clock_background.png into a ImageView.

public class MyWallpaperService extends WallpaperService {
    @Override
    public Engine onCreateEngine() {
        return new MyWallpaperEngine();
    }
    ....
    public void onCreate(SurfaceHolder surfaceHolder) {
        super.onCreate(surfaceHolder);
        mContext = getBaseContext();
        backgroundImage = new ImageView(mContext);
        backgroundImage.setImageDrawable(mContext.getResources().getDrawable(R.drawable.clock_background));
    }
}

Later I have:

backgroundImage.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
backgroundImage.layout(0, 0, 150, 150);

I expect the code above would display clock_background.png in the upper-left corner of the screen. I tried to put the two lines above in OnSurfaceCreated and OnSurfaceChanged. Unfortunately it does not work. As I understand, live wallpaper gives a Surface (not SurfaceView), from which one can get canvas and draw things on it. I apologise for being very new at Android: Am I doing it all wrong? I just don't want to mess with drawBitmap or likes, and I don't care about battery anyway. Any help is highly appreciated. Thank you very much!

Community
  • 1
  • 1
pp35377
  • 173
  • 1
  • 1
  • 4

1 Answers1

0

I short, yes you're doing it wrong. Use the supplied canvas and its drawX() methods

MrChaz
  • 1,065
  • 1
  • 8
  • 17
  • Thanks! but I am looking for a way to avoid canvas and draw..(). And as I mentioned that way does exist, though may not preferred. – pp35377 Nov 13 '12 at 22:16
  • It would be useful when referring someone to a different method to provide some direction how to use it for the desired results. – Abandoned Cart Sep 21 '13 at 15:25