I am trying to create a slideshow in Android using its WallpaperService
class. I am using Canvas
and Bitmap
to display images. I am able to display images sequentially but I am unable to figure out a way to add fade in animation to the images while they change. I know how to animate View
s in Android but I am unable to implement the same on Canvas
. I tried looking for a similar question on SO and found one here but it would have been great had the answer been a detailed one.
I'd be grateful if someone pointed me to a source that can help me overcome this problem.
EDIT:
I set the image on the Canvas
as follows:
Inside the class extending WallpaperService.Engine
, I do the following:
@Override
public void run() {
SurfaceHolder holder = getSurfaceHolder();
Canvas canvas = null;
try {
canvas = holder.lockCanvas();
if (canvas != null) {
canvas.drawColor(0, Mode.CLEAR);
Bitmap bitmap = //get bitmap
if (bitmap != null) {
paint.setAlpha(alpha);
if (alpha < 255 ) {
canvas.drawBitmap(bitmap, new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()), new Rect(0, 0, width, height), paint);
bitmap.eraseColor(Color.TRANSPARENT);
bitmap.recycle();
}
alpha+=1;
}
}
} catch (IllegalStateException ignore) {
ignore.printStackTrace();
} finally {
if (canvas != null) {
holder.unlockCanvasAndPost(canvas);
}
}
handler.removeCallbacks(this);
}
All I get is a black screen after this.