Skip to content

Wallpaper JSON

Sarsa Murmu edited this page May 13, 2023 · 7 revisions

This is the default wallpaper JSON structure of CandyBar

[
  {
    "name": "Toyota Rock Car",
    "author": "JC Falcon",
    "url": "https://images.unsplash.com/photo-1564844159766-f1565806300b?ixlib=rb-1.2.1&q=80",
    "thumbUrl": "https://images.unsplash.com/photo-1564844159766-f1565806300b?ixlib=rb-1.2.1&q=80&w=200"
  },
  {
    "name": "Tasty Fruit",
    "author": "Alexandra Kikot",
    "url": "https://images.unsplash.com/photo-1564750497011-ead0ce4b9448?ixlib=rb-1.2.1&q=80",
    "thumbUrl": "https://images.unsplash.com/photo-1564750497011-ead0ce4b9448?ixlib=rb-1.2.1&q=80&w=200"
  },
  {
    "name": "Coral Coast",
    "author": "Seaside Feel",
    "url": "https://images.unsplash.com/photo-1564639566047-dc4a1b86a90f?ixlib=rb-1.2.1&q=80",
    "thumbUrl": "https://images.unsplash.com/photo-1564639566047-dc4a1b86a90f?ixlib=rb-1.2.1&q=80&w=200"
  },
  {
    "name": "Duotone Dahlias",
    "author": "Annie Spratt",
    "url": "https://images.unsplash.com/photo-1513682322455-ea8b2d81d418?ixlib=rb-1.2.1&q=80",
    "thumbUrl": "https://images.unsplash.com/photo-1513682322455-ea8b2d81d418?ixlib=rb-1.2.1&q=80&w=200"
  }
]
  • name: Name of the wallpaper
  • author: Author of the wallpaper
  • url: Image URL of the Wallpaper, use raw links.
  • thumbUrl: Image URL of the wallpaper's thumbnail, use raw links.

Changing JSON Structure

  1. Open CandyBar.java inside apps/java/.../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's an example

import candybar.lib.utils.JsonStructure;

public class CandyBar extends CandyBarApplication {

    @NonNull
    @Override
    public Configuration onInit() {
        Configuration configuration = new Configuration();

        // This is the default JSON structure
        configuration.setWallpaperJsonStructure(
                new JsonStructure.Builder(null)   //-->  Wallpaper array's name
                        .name("name")             //-->  Wallpaper's name
                        .author("author")         //-->  Author's name
                        .url("url")               //-->  Wallpaper's URL
                        .thumbUrl("thumbUrl")     //-->  Wallpaper's thumbnail's URL
                        .build());

        return configuration;
    }
}

NOTE: If you are using the default JSON structure, you don't need to add this.

More examples

NOTE: Comments are NOT SUPPORTED in JSON. I am using JavaScript syntax with comments for demonstration. If you are going to copy these, you have to remove the comments.

With wallpaper array name

{
  "wallpapers": [ //--> This is the array name
    {
      "name": "Sample 1",
      "author": "Sample Maker",
      "url": "https://samplemaker.com/sample-1.jpg",
      "thumbUrl": "https://samplemaker.com/sample-1-thumb.jpg"
    },
    {
      "name": "Sample 2",
      "author": "Sample Maker",
      "url": "https://samplemaker.com/sample-2.jpg",
      "thumbUrl": "https://samplemaker.com/sample-2-thumb.jpg"
    }
  ]
}

The Configuration

configuration.setWallpaperJsonStructure(
        new JsonStructure.Builder("wallpapers")   //--> Wallpaper array name changed
                .name("name")
                .author("author")
                .url("url")
                .thumbUrl("thumbUrl")
                .build());

With different names and no thumbnail

[
  {
    "name": "Sample 1",
    "creator": "Sample Maker",
    "link": "https://samplemaker.com/sample-1.jpg",  //--> Different url Name
    //--> No thumbnails
  },
  {
    "name": "Sample 2",
    "creator": "Sample Maker",
    "link": "https://samplemaker.com/sample-2.jpg",  //--> Different url Name
    //--> No thumbnails
  }
]

The Configuration

configuration.setWallpaperJsonStructure(
        new JsonStructure.Builder(null)
                .name("name")
                .author("creator")     //--> Author's name changed
                .url("link")           //--> Wallpaper's URL name changed
                .thumbUrl(null)        //--> Wallpaper's Thumbnail's URL name changed
                .build());

The bare minimum structure

[
  {
    //--> No name
    "maker": "Sample Maker",
    "src": "https://samplemaker.com/sample-1.jpg",  //--> Different url name
    //--> No Thumbnails
  },
  {
    //--> No name
    "maker": "Sample Maker",
    "src": "https://samplemaker.com/sample-2.jpg",  //--> Different url name
    //--> No Thumbnails
  }
]

The Configuration

configuration.setWallpaperJsonStructure(
        new JsonStructure.Builder(null)
                .name(null)          //--> No name
                .author("maker")     //--> Author's name Changed
                .url("src")          //--> Wallpaper's URL name Changed
                .thumbUrl(null)
                .build());
Clone this wiki locally