Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <pre>Im using WallpaperService to set the live wallpaper on homescreen. Im able to set 10 pics from resources and rotate them
- class WallpaperEngine extends Engine {
- //frequency selected by user to update the wallpaper
- private final int Wallpaper_DURATION = utils.getFrequency;
- private int[] mImagesArray;
- private int mImagesArrayIndex = 0;
- private Thread mDrawWallpaper;
- public WallpaperEngine() {
- customWallpaperHelper = new CustomWallpaperHelper(getApplicationContext(), getResources());
- mImagesArray = new int[] {R.drawable.one,R.drawable.two,R.drawable.three,R.drawable.four,R.drawable.five};
- mDrawWallpaper = new Thread(new Runnable() {
- @Override
- public void run() {
- try {
- while (true) {
- drawFrame();
- incrementCounter();
- Thread.sleep(Wallpaper_DURATION);
- }
- } catch (Exception e) {
- //
- }
- }
- });
- mDrawWallpaper.start();
- }
- private void incrementCounter() {
- mImagesArrayIndex++;
- if (mImagesArrayIndex >= mImagesArray.length) {
- mImagesArrayIndex = 0;
- }
- }
- private void drawFrame() {
- final SurfaceHolder holder = getSurfaceHolder();
- Canvas canvas = null;
- try {
- canvas = holder.lockCanvas();
- if (canvas != null) {
- drawImage(canvas);
- }
- } finally {
- if (canvas != null) {
- holder.unlockCanvasAndPost(canvas);
- }
- }
- }
- private void drawImage(Canvas canvas)
- {
- Bitmap image = BitmapFactory.decodeResource(getResources(),
- mImagesArray[mImagesArrayIndex]);
- Bitmap b=Bitmap.createScaledBitmap(image, canvas.getWidth(), canvas.getHeight(), true);
- canvas.drawBitmap(b, 0,0, null);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement