summaryrefslogtreecommitdiff
path: root/app/src/main/java/com/javispedro/wallmotion/WallService.java
blob: 6a004ff9cfdac736618b350365c1d0f9d723356a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.javispedro.wallmotion;

import android.service.wallpaper.WallpaperService;
import android.util.Log;
import android.view.SurfaceHolder;

public class WallService extends WallpaperService {
    private static final String TAG = "WallService";

    @Override
    public Engine onCreateEngine() {
        return new WallpaperEngine();
    }

    private class WallpaperEngine extends Engine {
        private static final String TAG = "WallpaperEngine";

        private Renderer renderer;

        @Override
        public void onCreate(SurfaceHolder surfaceHolder) {
            Log.d(TAG, "onCreate");
            renderer = new Renderer(WallService.this);
        }

        @Override
        public void onDestroy() {
            Log.d(TAG, "onDestroy");
            renderer.stop();
            renderer = null;
        }

        @Override
        public void onSurfaceDestroyed(SurfaceHolder holder) {
            Log.d(TAG, "onSurfaceDestroyed");
            renderer.stop();
        }

        @Override
        public void onSurfaceCreated(SurfaceHolder holder)  {
            Log.d(TAG, "onSurfaceCreated");
        }

        @Override
        public void onSurfaceChanged(SurfaceHolder holder, int format,
                                     int width, int height) {
            Log.d(TAG, "onSurfaceChanged");
        }

        @Override
        public void onSurfaceRedrawNeeded(SurfaceHolder holder) {
            Log.d(TAG, "onSurfaceRedrawNeeded");
        }

        @Override
        public void onVisibilityChanged(boolean visible) {
            Log.d(TAG, "onVisibilityChanged(visible: " + visible + ")");
            if (visible) {
                renderer.start(getSurfaceHolder().getSurface());
            } else {
                renderer.stop();
            }
        }
    }
}