在动态壁纸引擎中没有调用Run方法

时间:2013-03-26 11:29:44

标签: android live-wallpaper

我是android的新手,开始使用Wallpaper Engine进行livewallpaper开发。我的问题是Runnable里面的run()方法没有调用,不知道为什么......我错过了什么?

这是我的代码:

public class Hearts extends WallpaperService {
    public static boolean LANDSCAPE;
    public static Paint backgroundPaint;
    public static Point backgroundSize;
    public static Point globalCanvasSize;
    public static boolean landscapeMode = false;
    public static int maxScreenSize;
    Bitmap background;
    private final Handler mHandler = new Handler();

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

    public WallpaperService.Engine onCreateEngine() {
        return new HeartsEngine();
    }

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

    class HeartsEngine extends Engine {
        private final int amountOfFlakes = 40;
        private final Paint backgroundPaint = new Paint();
        private Canvas c;
        public Flake[] flakeArray = new Flake[40];
        final SurfaceHolder holder = getSurfaceHolder();
        private final Runnable mDrawCube = new Runnable() {

            @Override
            public void run() {
                Log.d("tag", "Inside Run Called");
                drawFrame();
            }
        };
        float mXOffset;
        float mYOffset;
        private float oldScreen;
        Random random = new Random();
        Resources res = Hearts.this.getResources();

        HeartsEngine() {

            super();
            Log.d("tag", "Constructyor");
        }

void drawFrame() {
            Log.d("tag", "drawFrame");
            this.oldScreen -= this.mXOffset;
            Flake.scrollSpeed = 48.0F * this.oldScreen;
            this.oldScreen = this.mXOffset;
            this.c = null;
            this.c = this.holder.lockCanvas();
            try {
                if (this.c != null)
                    this.c.drawBitmap(Hearts.this.background, 0.0F, 0.0F, null);
                for (int i = 0;; i++) {
                    if (i >= 40) {
                        this.holder.unlockCanvasAndPost(this.c);
                        Hearts.this.mHandler.postDelayed(this.mDrawCube, 16L);

                    }
                    this.flakeArray[i].updateFlake(this.random, this.res,
                            this.c);
                }
            } catch (IllegalArgumentException localIllegalArgumentException) {
                // break label94;
                localIllegalArgumentException.printStackTrace();
                return;

            }
        }

1 个答案:

答案 0 :(得分:0)

您只能在drawFrame() mDrawCube内拨打Runnable。因此first time call方法

没有drawFrame()