Launcher with Locale API

Post your questions and help other users.

Moderator: Martin

User avatar
Bushmills
Posts: 286
Joined: 23 Sep 2014 21:56

Launcher with Locale API

Post by Bushmills » 20 May 2016 21:41

Quite a number of forum posts relate to affecting desktop/launcher items one way or another, or to different kinds of displaying information on same desktop.
Often some kind of workaround is needed, because Automagic doesn't directly talk to launcher, or creation of a custom widget is suggested.
It may be be unknown to some that there exist launchers which provide the Locale API Automagic can use to talk to them, thereby providing a powerful way to affect desktop look and functionality.
One of those launchers is Lightning Launcher. Because some of its features wrt Automagic are not immediately evident, I thought of telling in a few posts how the combination of these two tools can enable a kind of control over the desktop which is virtually impossible using a stock launcher.
But be aware, Lightning Launcher is not a simple launcher. The price to pay for its flexibility is complexity - but I suppose you wouldn't be using Automagic if simplicity was what you're after.
Last edited by Bushmills on 21 May 2016 13:13, edited 1 time in total.

User avatar
Bushmills
Posts: 286
Joined: 23 Sep 2014 21:56

Interfacing with Automagic

Post by Bushmills » 20 May 2016 22:02

Lightning Launcher functionality can be called from Automagic through the Plugin action. Actions, Scripts and Variables are the functions available through the Plugin action:
Attachments
Screenshot_2016-05-20-21-37-02.png
Screenshot_2016-05-20-21-37-02.png (66.47 KiB) Viewed 70926 times

User avatar
Bushmills
Posts: 286
Joined: 23 Sep 2014 21:56

services under Lightning Action

Post by Bushmills » 20 May 2016 23:00

After pressing the config bar of Lightning Action, the list of services shows:
Attachments
Screenshot_2016-05-20-21-37-53.png
Screenshot_2016-05-20-21-37-53.png (76.74 KiB) Viewed 70920 times
Screenshot_2016-05-20-21-37-46.png
Screenshot_2016-05-20-21-37-46.png (74.08 KiB) Viewed 70920 times
Screenshot_2016-05-20-21-37-35.png
Screenshot_2016-05-20-21-37-35.png (79.37 KiB) Viewed 70921 times

User avatar
Bushmills
Posts: 286
Joined: 23 Sep 2014 21:56

Lightning variable

Post by Bushmills » 21 May 2016 09:34

Very inconspicuous at first sight, this harnesses a lot of desktop affecting configuration power: any desktop item can take values for many characteristics from a variable. When the value of a variable, bound to a characteristics, changes, the desktop item is updated immediately.
Through that mechanism can Automagic set many aspects, like displayed icon, label, rotation, position, colour and many others.

Screenshots: list of item characteristics which can be bound to variables.
Attachments
Screenshot_2016-05-21-12-01-15.png
Screenshot_2016-05-21-12-01-15.png (54.03 KiB) Viewed 70911 times
Screenshot_2016-05-21-12-01-25.png
Screenshot_2016-05-21-12-01-25.png (56.33 KiB) Viewed 70911 times
Screenshot_2016-05-21-12-01-35.png
Screenshot_2016-05-21-12-01-35.png (59.24 KiB) Viewed 70911 times

User avatar
Bushmills
Posts: 286
Joined: 23 Sep 2014 21:56

Example of use: Lightning variable

Post by Bushmills » 21 May 2016 10:19

This example shows how Automagic can use Lightning launcher variables, to change the label of a desktop icon, in response to events.

As events I've picked connection to and disconnection from a charger. I want a desktop item to be named "charge" or "discharge".

First, the Automagic flow, with triggers by either event. Of course, having two flows, each with its own trigger, is just as possible - but as the count of flows on my device is considerable, as is the number of flow groups, decluttering the flow list by grouping several together into a single flow helps me avoiding to lose track over those, for the cost of a few extra CPU cycles:
Screenshot_2016-05-21-12-12-11.png
Screenshot_2016-05-21-12-12-11.png (66.67 KiB) Viewed 70910 times
The first action determines the reason for triggering the flow, and sets an Automagic variable "power" accordingly:
Screenshot_2016-05-21-12-21-02.png
Screenshot_2016-05-21-12-21-02.png (70.31 KiB) Viewed 70910 times
Next and last action simply assigns to Lightning launcher variable "power" the value of Automagic variable {power}. Remember to check the "substitute variables" box, otherwise the literal string "{power}" instead of the value of the variable will be assigned.
Screenshot_2016-05-21-12-39-18.png
Screenshot_2016-05-21-12-39-18.png (79.15 KiB) Viewed 70908 times
Now the desktop item must be told to change its label accordingly, by editing its properties. The relevant settings are under the "Bindings" tab:
(screenshot pending)
Oops, ran into screenshot limit of 3
Last edited by Bushmills on 21 May 2016 15:26, edited 3 times in total.

User avatar
Bushmills
Posts: 286
Joined: 23 Sep 2014 21:56

configuring desktop item to reflect name passed in variable

Post by Bushmills » 21 May 2016 15:32

(Insert post or description here: types of desktop items, creating an item)


Now the desktop item must be told to change its label accordingly, by editing its properties. The relevant settings are under the "Bindings" tab:
Screenshot_2016-05-21-17-15-39.png
Screenshot_2016-05-21-17-15-39.png (78.52 KiB) Viewed 70890 times
All bindings configured for this item are shown on the configuration page. As there isn't any yet, the box is empty:
Screenshot_2016-05-21-17-15-56.png
Screenshot_2016-05-21-17-15-56.png (71.03 KiB) Viewed 70890 times
Adding a new binding, "label" is chosen, which expects a string.
Instead of assigning a static value, the variable "power" is used instead.
Lightning Launcher identifies variables by the leading dollar sign:
Screenshot_2016-05-21-17-16-32.png
Screenshot_2016-05-21-17-16-32.png (102.2 KiB) Viewed 70890 times

newturn
Posts: 30
Joined: 20 Apr 2016 08:36

Re: Launcher with Locale API

Post by newturn » 21 May 2016 19:54

hi,

nice tutorial. Thank you !!!

Can you somehow show how to change the icon on the desktop? For example in your "power charging" task?

User avatar
Bushmills
Posts: 286
Joined: 23 Sep 2014 21:56

Re: Launcher with Locale API

Post by Bushmills » 21 May 2016 22:14

Undecided, because I focus on Automagic - Lightning Launcher interaction. The principle of writing to a variable "icon" instead of "power" is from Automagic viewpoint identical. The difference is found in the item configuration - that's more a matter for a Lightning launcher tutorial than what I'm striving to show in these posts. That's also why I don't intend to get "fancy" on this power example, like rotating the text according battery charge, or colouring the display - that's just outside of scope. I also risk to get questions asked like "why don't you use an Automagic custom widget for this" :) (answer would probably be along the line of "why should I have to build a widget, if i can do with a plain desktop launcher object?")

I can give you a few hints, though, how I handle this: depending on whether the item is meant to switch been two or between more than two icons, I pick one or another approach.
In case of just two icons, I create two icon objects, and control the property "z-axis" of one of those through a variable, say "layer". Then I move both items to the same screen position. This approach I choose because only one item needs control through binding.

In case of more than two items, I use the property "display the icon" of every icon object, with a value of "$icon == id" where id is the value (number or string) which causes that specific icon to show. There will be only one object matching, and therefore display the icon. The alternative expressions, for rearranging Z-axis ordering, could be "($icon == id)+2", resulting in 3 for the matching item, and 2 for all others. The higher, the topper.

Another consideration which approach to choose can be how you want the objects to respond to touches: If gestures and actions should be the same for all icon visualisations, control of icon display may be the preferred method, because that way you can keep one object on top of Z-axis, which then deals with user interaction. In case other properties, such as actions bound to gestures, should change too, moving the respective object to top of Z-axis may be more desirable, because that way can each icon provide its own set of responses to user interaction. After all, desktop objects can respond to tap, long tap, 4 ways of swipes, or faster touch (no delay until it can be determined whether a tap was short or long one), apart from pausing or resuming actions. I'm using the Z axis sequence for app launcher, with several similar apps on apparently one button. As a long push gesture switches to the next app, easy configuration of the app on the launcher, while keeping its function group the same, is possible. Examples: choice of navigation apps, choice of star chart app, choice of calculator.

To deal with moving such a multiple object around, it may be practical to place it in its own container (an icon sized panel), which, when moved, moves all contained objects along with it.

User avatar
Bushmills
Posts: 286
Joined: 23 Sep 2014 21:56

Lightning Action: Go to specified desktop

Post by Bushmills » 23 May 2016 17:28

Almost a no-brainer, compared to the variable example above: Let Automagic decide what desktop to switch to.
But that what Lightning calls "desktop" may not exactly be what you understand as "desktop" coming from different launcher. Usually, another "desktop" is considered one of those pages to swipe right or left from the home page to. This is NOT what Lightning calls a desktop. Those are, from Lightning viewpoint and terminology, merely "positions" - regions of the same desktop, but outside current view unless moved to.

(Screenshot: desktop full zoom, home position) - the clock is an Automagic custom widget, btw. It's colouring conveys a lot of information. The green bar at top is an Automagic widget too, in its 1 pixel wide overlay, indicating battery charge by its length, and charger state by colour. The menu button at bottom right invokes another Automagic widget.
Screenshot_2016-05-24-00-14-25.png
Screenshot_2016-05-24-00-14-25.png (153.98 KiB) Viewed 70681 times
(Screenshot: same desktop, full zoom but different position) - home position is the only place with desktop items, other than the four locked text-only items in the corners. Most of them switch to other desktops, instantly and void of any transition animation. A very conservative estimation is that about 100 man years are lost every day by needless animations.
Screenshot_2016-05-24-00-14-44.png
Screenshot_2016-05-24-00-14-44.png (32.77 KiB) Viewed 70681 times
(Screenshot: same desktop, zoomed out) - The noisy little rectangle is the home position from first screenshot
Screenshot_2016-05-24-00-15-13.png
Screenshot_2016-05-24-00-15-13.png (36.73 KiB) Viewed 70681 times
Another Lightning desktop bears no geographical relationship to any other Lightning desktop - one can not pan from one to another, as they are completely separate from each other. They may look similar, but that's only by user choice (by applying the same "profile" to some or all other desktops) - their look and function may also be completely different, as each desktop has its own configuration, can have its own icon theme, color theme, screen grid, script set etc, more like a completely different launcher.

Having Automagic detect that device is used in a vehicle, in the office or at home, and switch desktop accordingly, can therefore present a very different user interface, customised to work best in the resp. environment. The flow for this is so trivial that a screenshot, or step by step instructions, should be completely unnecessary.

(No screenshot for stated reason, which is good because I hit the limit of 3 already)

User avatar
Bushmills
Posts: 286
Joined: 23 Sep 2014 21:56

Action: Lightning Script

Post by Bushmills » 24 May 2016 12:52

Ever wished to run a script, written in JavaScript, in response to an Automagic trigger? JavaScript is the scripting language of Lightning Launcher, and their names are also exposed through the Locale API, from where they are available to Automagic for execution.
Scripts can either be written beforehand, imported from external sources, or written on the fly during creation of the Automagic flow. Arguments can be passed to the script from the Automagic action.

(Screenshot: creating Automagic action for executing JavaScript)

Post Reply