Skip to content

Wallpaper Json Structure

Dani Mahardhika edited this page Jun 26, 2017 · 2 revisions

This is a sample for default json structure. With dashboard configuration which available in release 3.2.0 and above, you can define your own json structure.

{
    "Wallpapers":
        [
	    {
		"author": "Taken from gadgetraid",
		"url": "http://www.gadgetraid.com/wp-content/uploads/2016/07/android-n-nougat-wallpaper-1.png",
		"thumbUrl": "https://drive.google.com/uc?id=0B0f4ypHfNKm5TkZ0amk4TGZWYkU",
		"name": "Nougat Wallpaper 1"

	    },
	    {
                "author": "Taken from gadgetraid",
		"url": "http://www.gadgetraid.com/wp-content/uploads/2016/07/android-n-nougat-wallpaper-2.jpg",
		"thumbUrl": "https://drive.google.com/uc?id=0B0f4ypHfNKm5WTh5X054ZHJocmM",
		"name": "Nougat Wallpaper 2"
	    }
        ]
}

How to change wallpaper json structure?

  1. Open CandyBar.java inside apps\java\com.yourpackagename\applications\.
  2. Use setWallpaperJsonStructure() from Configuration to define your own json structure. Be careful, array name, name, author, url, and thumbUrl are case sensitive.

Here an example

import com.dm.material.dashboard.candybar.utils.JsonStructure;

public class CandyBar extends CandyBarApplication {

    @Override
    public void onCreate() {
        Configuration configuration = new Configuration();
        
        /* This is default json structure */
        configuration.setWallpaperJsonStructure(
                new JsonStructure.Builder("Wallpapers")
                        .name("name")
                        .author("author")
                        .url("url")
                        .thumbUrl("thumbUrl")
                        .build());
        
        initApplication(configuration);
    }
}

NOTE: If you are following default json structure, you don't need to add this.

Still confused?

Here more example

1. You have json with structure like this

{
    "wallpapers": --> different array name
        [
	    {
		"author": "Taken from gadgetraid",
		"url": "http://www.gadgetraid.com/wp-content/uploads/2016/07/android-n-nougat-wallpaper-1.png",
		"name": "Nougat Wallpaper 1"
                --> no thumbUrl
	    },
	    {
                "author": "Taken from gadgetraid",
		"url": "http://www.gadgetraid.com/wp-content/uploads/2016/07/android-n-nougat-wallpaper-2.jpg",
		"name": "Nougat Wallpaper 2"
                --> no thumbUrl
	    }
        ]
}

The configuration

configuration.setWallpaperJsonStructure(
    new JsonStructure.Builder("wallpapers")
        .name("name")
        .author("author")
        .url("url")
        /* If thumbUrl set to null, url will be used as thumbUrl */
        .thumbUrl(null)
        .build());

2. Another json structure

{
    "wallpapers": --> different array name
        [
	    {
		"creator": "Taken from gadgetraid", --> different author name
		"imageUrl": "http://www.gadgetraid.com/wp-content/uploads/2016/07/android-n-nougat-wallpaper-1.png", --> different url name
		"name": "Nougat Wallpaper 1"
                --> no thumbUrl
	    },
	    {
                "creator": "Taken from gadgetraid", --> different author name
		"imageUrl": "http://www.gadgetraid.com/wp-content/uploads/2016/07/android-n-nougat-wallpaper-2.jpg", --> different url name
		"name": "Nougat Wallpaper 2"
                --> no thumbUrl
	    }
        ]
}

The configuration

configuration.setWallpaperJsonStructure(
    new JsonStructure.Builder("wallpapers")
        .name("name")
        .author("creator")
        .url("imageUrl")
        .thumbUrl(null)
        .build());

3. Weird json structure

[ --> no array name
    {
        "creator": "Taken from gadgetraid", --> different author name
	"imageUrl": "http://www.gadgetraid.com/wp-content/uploads/2016/07/android-n-nougat-wallpaper-1.png", --> different url name
	"name": "Nougat Wallpaper 1"
        --> no thumbUrl
    },
    {
        "creator": "Taken from gadgetraid", --> different author name
	"imageUrl": "http://www.gadgetraid.com/wp-content/uploads/2016/07/android-n-nougat-wallpaper-2.jpg", --> different url name
	"name": "Nougat Wallpaper 2"
        --> no thumbUrl
    }
]

The configuration

configuration.setWallpaperJsonStructure(
    new JsonStructure.Builder(null)
        .name("name")
        .author("creator")
        .url("imageUrl")
        .thumbUrl(null)
        .build());

4. Another weird json structure

[ --> no array name
    {
        "creator": "Taken from gadgetraid", --> different author name
	"imageUrl": "http://www.gadgetraid.com/wp-content/uploads/2016/07/android-n-nougat-wallpaper-1.png", --> different url name
	--> no name
        --> no thumbUrl
    },
    {
        "creator": "Taken from gadgetraid", --> different author name
	"imageUrl": "http://www.gadgetraid.com/wp-content/uploads/2016/07/android-n-nougat-wallpaper-2.jpg", --> different url name
	--> no name
        --> no thumbUrl
    }
]

The configuration

configuration.setWallpaperJsonStructure(
    new JsonStructure.Builder(null)
        /* If name set to null, wallpaper name will be generated automatically
         * Like: Wallpaper 1, Wallpaper 2, Wallpaper 3, ...
         */
        .name(null)
        .author("creator")
        .url("imageUrl")
        .thumbUrl(null)
        .build());