public class

Lightning

extends Object
java.lang.Object
   ↳ net.pierrox.lightning_launcher.script.api.Lightning

Class Overview

Entry point for most Lightning Launcher scripted features. The Lightning object is the root object in the script context, hence its functions can be called without naming it, unlike with the deprecated LL object. For instance, instead of using LL.getDesktopByName('d'), simply use getDesktopByName('d')

Summary

Public Methods
void alert(String message)
Display a message in a dialog box.
String argb(float a, float r, float g, float b)
Encode a color as an hexadecimal string, prefixed with '#'.
boolean bindClass(String name)
Translate a Java class into a JavaScript object.
void clearTimeout(int id)
Clear a timeout previously set with #setTimeout
boolean confirm(String message)
Display a message in a dialog box with Ok/Cancel buttons
Screen createScreen(net.pierrox.lightning_launcher.engine.Screen screen)
Script createScript(String path, String name, String text, int flags)
Create a new script.
Script createScript(String name, String text, int flags)
This method is deprecated. use createScript(String, String, String, int) instead
void deleteScript(Script script)
Delete a script.
Screen getActiveScreen()
Retrieve the currently active screen, the one which is displayed to the user.
Script[] getAllScriptMatching(int flags)
Return the collection of scripts matching some flags.
ActivityScreen getAppDrawerScreen()
Return the app drawer screen, null if not created yet
Screen getBackgroundScreen()
Return the background screen.
Configuration getConfiguration()
Retrieve the configuration object used to get and set launcher general settings.
Script getCurrentScript()
Retrieve the currently executed script.
Event getEvent()
Returns the event object associated with this script execution.
Screen getFloatingScreen()
Return the floating screen, null if not created yet
HomeScreen getHomeScreen()
Return the home screen, null if not created yet
Typeface getIconsTypeface()
return the typeface used to draw icons.
Screen getLiveWallpaperScreen()
Return the live wallpaper screen, null if not created yet
ActivityScreen getLockScreen()
Return the lock screen, null if not created yet
Script getScriptById(String id)
Retrieve a script by its unique identifier
Script getScriptByName(String name)
Retrieve a script by name.
Script getScriptByPathAndName(String path, String name)
Retrieve a script by its path and name.
VariableSet getVariables()
Retrieve the whole set of known variables (builtins and user ones).
boolean isLocked()
Returns true if the screen is currently locked using the Lightning lock screen.
String loadRawResource(String pkg, String name)
This method is used to load a text from a package raw resource.
String prompt(String message, String input)
Display a message in a dialog box with an input text area.
void save()
Persist launcher data now.
boolean sendTaskerIntent(TaskerIntent intent, boolean synchronous)
Send a tasker intent, optionally waiting for its completion to return.
int setTimeout(Object function, int delayMillis)
Execute a function later.
void setVariableBoolean(String name, boolean value)
Set a boolean variable.
void setVariableFloat(String name, float value)
Set a boolean variable.
void setVariableInteger(String name, long value)
Set a boolean variable.
void setVariableString(String name, String value)
Set a string variable.
void unlock()
Unlock the screen.
void writeToLogFile(String data, boolean append)
Write data to a file.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public void alert (String message)

Display a message in a dialog box.

Parameters
message text to display

public String argb (float a, float r, float g, float b)

Encode a color as an hexadecimal string, prefixed with '#'. Arguments are color component ranging from 0 to 1. For instance calling argb(1, 1, 0, 0) will return #ffff0000

public boolean bindClass (String name)

Translate a Java class into a JavaScript object. This is a convenience method that avoid repeated use of fully qualified names while scripting Java.

Parameters
name fully qualified class name
Returns
  • true if the operation succeeded, false if the class cannot be loaded or if already bound

public void clearTimeout (int id)

Clear a timeout previously set with #setTimeout

Parameters
id identifier returned by #setTimeout

public boolean confirm (String message)

Display a message in a dialog box with Ok/Cancel buttons

Parameters
message text to display
Returns
  • true if the dialog box has been confirmed with the Ok button

public Screen createScreen (net.pierrox.lightning_launcher.engine.Screen screen)

public Script createScript (String path, String name, String text, int flags)

Create a new script. Use this API wisely. if path is null, "/" is used.

public Script createScript (String name, String text, int flags)

This method is deprecated.
use createScript(String, String, String, int) instead

Create a new script using the default path "/"

public void deleteScript (Script script)

Delete a script.

public Screen getActiveScreen ()

Retrieve the currently active screen, the one which is displayed to the user. Note that this is often the same as Lightning.getEvent().getScreen(), but not always : events and script execution can occur in non active screens.

Returns
  • the active screen, or null if no screen is active at the moment

public Script[] getAllScriptMatching (int flags)

Return the collection of scripts matching some flags.

Parameters
flags see Script#FLAG_*

public ActivityScreen getAppDrawerScreen ()

Return the app drawer screen, null if not created yet

public Screen getBackgroundScreen ()

Return the background screen. This special screen is used when running background scripts. It can be used to query items and containers, but position and size may not be computed since the screen is not displayed and has no size.

public Configuration getConfiguration ()

Retrieve the configuration object used to get and set launcher general settings.

public Script getCurrentScript ()

Retrieve the currently executed script.

public Event getEvent ()

Returns the event object associated with this script execution. The event provides contextual data, such as the current desktop, which item has been tapped, and so on.

public Screen getFloatingScreen ()

Return the floating screen, null if not created yet

public HomeScreen getHomeScreen ()

Return the home screen, null if not created yet

public Typeface getIconsTypeface ()

return the typeface used to draw icons.

public Screen getLiveWallpaperScreen ()

Return the live wallpaper screen, null if not created yet

public ActivityScreen getLockScreen ()

Return the lock screen, null if not created yet

public Script getScriptById (String id)

Retrieve a script by its unique identifier

Parameters
id identifier as given by Script#getId()
Returns
  • a script or null if no script with this id

public Script getScriptByName (String name)

Retrieve a script by name.

Parameters
name as given by Script#getName()
Returns
  • a script or null if not found

public Script getScriptByPathAndName (String path, String name)

Retrieve a script by its path and name.

Parameters
path as given by Script#getPath()
name as given by Script#getName()
Returns
  • a script or null if not found

public VariableSet getVariables ()

Retrieve the whole set of known variables (builtins and user ones).

public boolean isLocked ()

Returns true if the screen is currently locked using the Lightning lock screen.

public String loadRawResource (String pkg, String name)

This method is used to load a text from a package raw resource. Instances of use of this method are:

  • load scripts and set them as event handler (useful in script plugins)
  • load JSON data, such as theme colors, data, etc.

Parameters
pkg package name from which to read resources
name name of the raw resource. It must not contain the extension of the raw file, this is the Android identifier.
Returns
  • a string or null if the resource cannot be found or read

public String prompt (String message, String input)

Display a message in a dialog box with an input text area.

Parameters
message text to display
input initial value in the input text
Returns
  • the inputed text, null if the dialog box has been canceled

public void save ()

Persist launcher data now.

public boolean sendTaskerIntent (TaskerIntent intent, boolean synchronous)

Send a tasker intent, optionally waiting for its completion to return.

Parameters
intent an intent built with TaskerIntent (see http://tasker.dinglisch.net/invoketasks.html for samples)
synchronous when true, Lightning will wait for Tasker task completion before to return, otherwise it will return immediately
Returns
  • when synchronous is true returns true if the intent has been sent successfully and Tasker reports a success too, when synchronous is false this method always returns true..

public int setTimeout (Object function, int delayMillis)

Execute a function later.

Parameters
function need to be a function
delayMillis anything below 0 will be handled as 0
Returns
  • timeout id, can be used with #clearTimeout to cancel it, will return 0 if function is not a function

public void setVariableBoolean (String name, boolean value)

Set a boolean variable. This is a shortcut for LL.getVariables().edit().setBoolean(name, value).commit();. When modifying several at once, consider using the PropertyEditor object instead for best efficiency.

public void setVariableFloat (String name, float value)

Set a boolean variable. This is a shortcut for LL.getVariables().edit().setFloat(name, value).commit();. When modifying several at once, consider using the PropertyEditor object instead for best efficiency.

public void setVariableInteger (String name, long value)

Set a boolean variable. This is a shortcut for LL.getVariables().edit().setInteger(name, value).commit();. When modifying several at once, consider using the PropertyEditor object instead for best efficiency.

public void setVariableString (String name, String value)

Set a string variable. This is a shortcut for LL.getVariables().edit().setString(name, value).commit();. When modifying several at once, consider using the PropertyEditor object instead for best efficiency.

public void unlock ()

Unlock the screen.

public void writeToLogFile (String data, boolean append)

Write data to a file. This is for logging and debug purpose only. The path is not configurable and is: /LightningLauncher/script/log.txt. Please note that this method won't add newlines automatically when appending data.

Parameters
data text to write to the file
append whether to clear the file before to write data, or append data to the existing content