How to make Android Live Wallpaper with LibGDx?
Asked Answered
R

1

6

I want to make Android Live Wallpaper using LibGDx. I created the project following the instructions from this github link

but Eclipse show error:

"The method createListener() of typeMainActivity must override or implement a supertype method"

"The method createConfig() of type MainActivity must override or implement a supertype method"

and offers remove @Override annotation. Where is my mistake?

My code:

public class MainActivity extends AndroidLiveWallpaperService {

@Override
public ApplicationListener createListener() {
    return new Wallpaper();
}

@Override
public AndroidApplicationConfiguration createConfig () {
    return new AndroidApplicationConfiguration();
}

@Override
public void offsetChange (ApplicationListener listener, float xOffset, float yOffset, float xOffsetStep, float yOffsetStep,
    int xPixelOffset, int yPixelOffset) {
    Gdx.app.log("LiveWallpaper", "offset changed: " + xOffset + ", " + yOffset);
}

}

Rutger answered 27/12, 2013 at 17:24 Comment(1)
If you change the method signatures of the methods annotated with @Override, you don't override you method anymore and the annotation is therefor wrong.Bred
C
3

It seems the wiki about LiveWallpapers is outdated o.o (I'm gonna check that). This is the way I do it:

MainActivity.java

package com.zoryth.blockslw;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.badlogic.gdx.backends.android.AndroidLiveWallpaperService;
import com.badlogic.gdx.backends.android.AndroidWallpaperListener;

public class MainActivity extends AndroidLiveWallpaperService{
    public static float pixelOffset = 0;

    @Override
    public void onCreateApplication () {
        super.onCreateApplication();

        final AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
        config.useGL20 = false;
        config.useCompass = false;
        config.useWakelock = false;
        config.useAccelerometer = false;
        config.getTouchEventsForLiveWallpaper = true;

        final ApplicationListener listener = new WallpaperListener();
        initialize(listener, config);
    }

    public static class WallpaperListener extends BlocksLW implements AndroidWallpaperListener {
        @Override
        public void create() {
            super.resolver = new Resolver() {
                @Override
                public float getxPixelOffset() {
                    return pixelOffset;
                }
        };

            super.create();
        };

        /*
         * never use xOffset/yOffset and xOffsetStep/yOffsetStep, because custom launchers will mess with your 
         * brain and this problem can't be fixed! Use only xPixelOffset/yPixelOffset (who used yPixelOffset???)))
         */

        @Override
        public void offsetChange (float xOffset, float yOffset, float xOffsetStep, float yOffsetStep, int xPixelOffset, int yPixelOffset) {
            pixelOffset = xPixelOffset;
        }

        @Override
        public void previewStateChange (boolean isPreview) {
        }
    }
}

(BlocksLW is my App Listener in the core project)

This is a very good Template made by Semtiko LW Template. I based my code mostly on it, I recommend you to give it a check ;)

Charwoman answered 27/12, 2013 at 18:3 Comment(1)
template giving me error whole importing kindly tell me the wayCommunistic

© 2022 - 2024 — McMap. All rights reserved.