Skip to content

Example 4: Using the StreamDeckController

Roland edited this page Sep 17, 2018 · 2 revisions

THIS TUTORIAL IS OUTDATED ATM

For easier handling the stream deck, displaying images and receiving events the class StreamDeckController can be used.

Instead of binding every item to the responding key, with the StreamDeckController we create a root FolderItem, add a bunch of items to it and pass them over to the StreamDeckController. This enables the use of complexer folder structures without having to hanlde them.

The StreamDeckController handles the traversion of the folders.

Beside the icons, StreamItems can hold information on how and if the key should have animations. Those informations are stored in the class AnimationStack. The playback of the animation is controlled by the StreamDeckController, the user only has to add the AnimationStack to the StreamItem.

This example will show how to use the StreamDeckController by creating a root folder and adding one ExecutableItem and one RunnableItem:


Includes:

import de.rcblum.stream.deck.StreamDeck;
import de.rcblum.stream.deck.StreamDeckController;
import de.rcblum.stream.deck.StreamDeckDevices;
import de.rcblum.stream.deck.items.ExecutableItem;
import de.rcblum.stream.deck.items.FolderItem;
import de.rcblum.stream.deck.util.IconHelper;
import de.rcblum.stream.deck.items.ExecutableItem;
import de.rcblum.stream.deck.items.RunnableItem;

Create the ExecutableItem with the icon "icon1.png":

byte[] img1 = IconHelper.loadImage("resources" + File.separator + "icon1.png");
ExecutableItem executableItem = new ExecutableItem(img1,"explorer.exe");

Create the RunnableItem with the icon "icon2.png":

byte[] img2 = IconHelper.loadImage("resources" + File.separator + "icon2.png");
RunnableItem runnableItem = new RunnableItem (img2,
	new Runnable() {
		public void run() {
			System.out.println("Runnable task has been called.");
		}
	}
);

Create the root folder and add the items to it:

StreamItem[] items = new StreamItem[15];
items[5] = executableItem;
items[9] = runnableItem;
FolderItem root = new FolderItem(null, null, items);

Now get the StreamDeck and create the controller:

StreamDeck sd = StreamDeckDevices.getStreamDeck();
sd.reset();
StreamDeckController sdc = new StreamDeckController(sd, root);

Clone this wiki locally