First Play on Muzei

Muzei live wallpaper is a new opensource project from Roman Nurik which provide a nice API for other developers to build extension on it easily. Just a few days after its release on Feb 12, you can already find quite many different data source for it. So I played for a while today and found that it is… really easy to implement your own data source.

Here is a quick start on creating the extension.

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
public class MyArtSource extends RemoteMuzeiArtSource {

    private static final int UPDATE_INTERVAL = 60 * 60 * 1000; // 60min

    public MyArtSource() {
        super("my-art-source");
    }


    @Override
    public void onCreate() {
        super.onCreate();
        setUserCommands(BUILTIN_COMMAND_ID_NEXT_ARTWORK); // manual switch image
    }

    @Override
    protected void onTryUpdate(int reason) throws RetryException {
        // fetch title, imageUrl, id, url from remote or hardcode

        publishArtwork(new Artwork.Builder()
            .title(title)
            .imageUri(Uri.parse(imageUrl))
            .token(id)
            .viewIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(url)))
            .build());

        scheduleUpdate(System.currentTimeMillis() + UPDATE_INTERVAL); // switch image after 60min
    }
}

You can find my Muzei 9GAG extension on Play store, source code available on Github

Comments