android live wallpaper with image?

748 views Asked by At

-> I have create an application.

-> In application i have take 10 images.

-> And my problem is that,i have set one of images out of 10 images as live wallpaper but it is not moving after some time and my code is below:

import android.graphics.Bitmap;

import android.graphics.BitmapFactory;

import android.graphics.Canvas;

import android.service.wallpaper.WallpaperService;

import android.view.SurfaceHolder;



public class LiveWallpaperService extends WallpaperService 
{
    public void onCreate() 

    {
        super.onCreate();
    }

    public void onDestroy() 
    {
        super.onDestroy();
    }

    public Engine onCreateEngine() 
    {
        return new WallpaperSerEngine();
    }

    class WallpaperSerEngine extends Engine 
    {
        public Bitmap image1; 
        public Bitmap image2;
        public Bitmap image3;

        WallpaperSerEngine() 
        {       
                image1 = BitmapFactory.decodeResource(getResources(), R.drawable.fish);
                image2 = BitmapFactory.decodeResource(getResources(), R.drawable.fish1);       
                image3 = BitmapFactory.decodeResource(getResources(), R.drawable.fish2); 

        }

        public void onCreate(SurfaceHolder surfaceHolder) 
        {
            super.onCreate(surfaceHolder);
        }

        public void onOffsetsChanged(float xOffset, float yOffset, float xStep, float yStep, int xPixels, int yPixels) 
        {
            drawFrame();

        }

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

            Canvas c = null;
            try 
            {
                c = holder.lockCanvas();
                if (c != null) 
                {              
                     c.drawBitmap(image1, 0, 0, null);
                     c.drawBitmap(image2, 0, 0, null);
                     c.drawBitmap(image3, 0, 0, null);

                }
            } finally 
            {
                if (c != null) holder.unlockCanvasAndPost(c);
            }
        }
    }
}
1

There are 1 answers

0
Chiral Code On

Your code makes no sense. You are drawing frame only if user scrolls the wallpaper. All bitmaps are placed at point (0,0), there will be no change in their position.

My proposition for you is to experiment using this live wallpaper template.