Search code examples
androidbackgroundtablet

how to create a tablet background using android studio


I have been following this tutorial: Page. I have been getting a lot of errors. Can you please help me by sharing the code on GitHub? You can also post your answer on Stack Overflow. This is my Gif I have used this in my java file:

package com.example.background;
import android.graphics.Canvas;
import android.graphics.Movie;
import android.os.Handler;
import android.service.wallpaper.WallpaperService;
import android.util.Log;
import android.view.SurfaceHolder;

import java.io.IOException;


public class GIFWallpaperEngine extends WallpaperService{
private final int frameDuration = 20;

private SurfaceHolder holder;
private Movie movie;
private boolean visible;
private Handler handler;

public GIFWallpaperEngine(Movie movie) {
    this.movie = movie;
    handler = new Handler();
}



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

private Runnable drawGIF = new Runnable() {
    public void run() {
        draw();
    }
};

private void draw() {
    if (visible) {
        Canvas canvas = holder.lockCanvas();
        canvas.save();
        // Adjust size and position so that
        // the image looks good on your screen
        canvas.scale(3f, 3f);
        movie.draw(canvas, -100, 0);
        canvas.restore();
        holder.unlockCanvasAndPost(canvas);
        movie.setTime((int) (System.currentTimeMillis() % movie.duration()));

        handler.removeCallbacks(drawGIF);
        handler.postDelayed(drawGIF, frameDuration);
    }
}
@Override
public void onVisibilityChanged(boolean visible) {
    this.visible = visible;
    if (visible) {
        handler.post(drawGIF);
    } else {
        handler.removeCallbacks(drawGIF);
    }
}
@Override
public void onDestroy() {
    super.onDestroy();
    handler.removeCallbacks(drawGIF);
}
@Override
public Engine onCreateEngine() {
    try {
        Movie movie = Movie.decodeStream(
                getResources().getAssets().open("wolverine.gif"));

        return new Engine(movie);
    }catch(IOException e){
        Log.d("GIF", "Could not load asset");
        return null;
    }
}
}

Is there anything wrong because the override is showing an error. It's this: Override is not required because method whatever super does.


Solution

  • Well, this is the solution for me GitLink

    Solution to your problem when you try to run app, first click in app and in Edit Configurations

    enter image description here

    Now, in Launch Options select NOTHING:

    enter image description here

    Last step, press OK:

    enter image description here

    Finally, you can run your app. Try it!