سؤال

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);
}

}

هل كانت مفيدة؟

المحلول

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 ;)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top