public class

LL

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

This class is deprecated.
use Lightning instead.

Class Overview

The main object to access Lightning Launcher features. The LL object gives access to desktops, items or give contextual data on the event.

Summary

Public Methods
boolean bindClass(String name)
Translate a Java class into a JavaScript object.
ImageAnimation createAnimation(int width, int height, int count, int duration, int loopCount)
Create a blank animation: frames are created fully transparent and need to be drawn.
ImageBitmap createImage(int width, int height)
Create a blank new image of the specified size.
Image createImage(String path)
Create an image from the specified file.
Image createImage(String pkg, String name)
Create an image from a package and a resource name.
ImageScript createImage(Scriptable object, int width, int height)
Create an image whose content is drawn using a script.
Script createScript(String name, String text, int flags)
Create a new script.
ImageBitmap cropImage(ImageBitmap image, boolean full_size)
Request the user to select an area in the image.
void deleteScript(Script script)
Delete a script.
Array getAllDesktops()
Returns an array of desktop identifiers.
Array getAllScriptMatching(int flags)
Return the collection of scripts matching some flags.
Container getContainerById(int id)
This method is deprecated. use getContainerById(int)
Context getContext()
Return the Android Context this script is linked with (an activity context).
Desktop getCurrentDesktop()
Returns the currently displayed desktop.
Script getCurrentScript()
Retrieve the currently executed script.
Desktop getDesktopByName(String name)
Returns a desktop by its name, as set in the "Configure desktop" screen.
Event getEvent()
This method is deprecated. use getEvent()
Desktop getFloatingDesktop()
Returns the desktop used as the floating desktop, or null if not set.
Desktop getHomeDesktop()
Returns the home desktop.
Item getItemById(int id)
This method is deprecated. use getItemById(int)
Desktop getLockscreenDesktop()
Returns the desktop used as the lock screen, or null if not set.
Array getOpenFolders()
Returns the list of currently open folders.
Script getScriptById(String id)
Retrieve a script by its unique identifier
Script getScriptByName(String name)
Retrieve a script by name
String getScriptTag()
This method is deprecated. use Script#getTag() instead
VariableSet getVariables()
Retrieve the whole set of known variables (builtins and user ones).
void goToDesktop(int id)
Go to a specified desktop, without changing the current position in this desktop.
void goToDesktopPosition(int id, float x, float y)
Go to a specified desktop and set the current absolute position in this desktop, setting a scale of 1 and using animations.
void goToDesktopPosition(int id, float x, float y, float scale, boolean animate)
Go to a specified desktop and set the current absolute position in this desktop.
boolean isLocked()
Returns true if the screen is currently locked using the Lightning lock screen.
boolean isPaused()
Returns whether the current context is paused.
String loadRawResource(String pkg, String name)
This method is used to load a text from a package raw resource.
int pickColor(String title, int color, boolean hasAlpha)
Request the user to pick a color.
Image pickImage(int maxPixels)
Request the user to pick an image through the Lightning image picker screen.
float pickNumericValue(String title, float value, String valueType, float min, float max, float interval, String unit)
Request the user to enter a numeric value.
void runAction(int action, Item item, String data)
Run a Lightning action.
void runAction(int action, String data)
Same as #runAction(int,Item,String) with a null item and data.
void runAction(int action)
Same as #runAction(int,String) with a null data.
void runScript(String name, String data)
This method is deprecated. use runScript(String, String)
void save()
Persist launcher data now.
boolean sendTaskerIntent(TaskerIntent intent, boolean synchronous)
Send a tasker intent, optionally waiting for its completion to return.
void setScriptTag(String tag)
This method is deprecated. use Script#setTag(String) instead together with #getCurrentScript
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.
boolean startActivity(Intent intent)
Start an activity.
boolean startActivityForResult(Intent intent, Script receiver, String token)
Start an activity and handle the result in another script.
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 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 ImageAnimation createAnimation (int width, int height, int count, int duration, int loopCount)

Create a blank animation: frames are created fully transparent and need to be drawn. Notes: animations created this way are memory expensive and cannot be persisted (yet). This means that Shortcut.setCustomIcon() wont't work, but Shortcut.setImage() will.

Parameters
width image width
height image height
count number of frames to allocate
duration default frame duration
loopCount initial number of loops to play, use 0 for infinite
Returns
  • an animation or null in case of error (most likely out of memory)

public ImageBitmap createImage (int width, int height)

Create a blank new image of the specified size. Pixel format is always ARGB 8888. Take care when creating images since it can rapidly exhaust memory and lead to a crash.

Returns
  • can return null if not enough memory

public Image createImage (String path)

Create an image from the specified file.

Parameters
path path of the image
Returns
  • can return null if an image cannot be read from the file (not an image or not enough memory)

public Image createImage (String pkg, String name)

Create an image from a package and a resource name. For instance:LL.createImage("net.pierrox.lightning_launcher_extreme", "icon") The density used is either the one given by ActivityManager.getLauncherLargeIconDensity if available, or the current one.

Parameters
pkg name of the package, use "android" to access system resources.
name name of the drawable resource
Returns
  • can return null if an image cannot be read from the package (unknown package, wrong resource name or not enough memory)

public ImageScript createImage (Scriptable object, int width, int height)

Create an image whose content is drawn using a script. This can be used for memory efficient graphics and animations. Please refer to ImageScript for the documentation on how to use it.

Parameters
object the set of functions
width the prefered image width, use -1 for as big as possible
height the prefered image height, use -1 for as big as possible

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

Create a new script. Use this API wisely.

public ImageBitmap cropImage (ImageBitmap image, boolean full_size)

Request the user to select an area in the image. Warning: because images need to be persisted to file while cropping, this method may be slow.

Parameters
image image to be cropped
full_size handling big images can be slow or request too much memory, by setting full_size to false this will allow this method to downscale images (approx. the size of the screen)
Returns
  • a cropped image, or null if the operation failed or the user canceled it

public void deleteScript (Script script)

Delete a script.

public Array getAllDesktops ()

Returns an array of desktop identifiers.

public Array getAllScriptMatching (int flags)

Return the collection of scripts matching some flags.

Parameters
flags see Script#FLAG_*

public Container getContainerById (int id)

This method is deprecated.
use getContainerById(int)

Returns a container by its id.

public Context getContext ()

Return the Android Context this script is linked with (an activity context). This is meant to be used with Android services.

public Desktop getCurrentDesktop ()

Returns the currently displayed desktop.

public Script getCurrentScript ()

Retrieve the currently executed script.

public Desktop getDesktopByName (String name)

Returns a desktop by its name, as set in the "Configure desktop" screen. The desktop name can be retrieved using getName(). This method will return null if no desktop by that name can be found

Parameters
name name of the desktop

public Event getEvent ()

This method is deprecated.
use 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 Desktop getFloatingDesktop ()

Returns the desktop used as the floating desktop, or null if not set.

public Desktop getHomeDesktop ()

Returns the home desktop. As of Lightning V14, this method looks for the desktop in the home screen, then in the background desktop.

public Item getItemById (int id)

This method is deprecated.
use getItemById(int)

Returns an item by its id. This is a shortcut avoiding to traverse the list of all desktops and folders.

Parameters
id item identifier
Returns
  • an item, or null if this id is not known.

public Desktop getLockscreenDesktop ()

Returns the desktop used as the lock screen, or null if not set. As of Lightning V14, this method looks for the desktop in the lock screen, then in the home screen, and finally in the background desktop.

public Array getOpenFolders ()

Returns the list of currently open folders. This function returns the opener item, not the container itself. This method will return null when the script is executed in the background.

Returns
  • an Array of Folder items, sorted top to bottom (topmost folder is at index 0).

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 String getScriptTag ()

This method is deprecated.
use Script#getTag() instead

public VariableSet getVariables ()

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

public void goToDesktop (int id)

Go to a specified desktop, without changing the current position in this desktop.

Parameters
id desktop identifier

public void goToDesktopPosition (int id, float x, float y)

Go to a specified desktop and set the current absolute position in this desktop, setting a scale of 1 and using animations. This method does nothing when the script is run in background.

Parameters
id desktop identifier
x absolute X position, in pixel
y absolute Y position, in pixel

public void goToDesktopPosition (int id, float x, float y, float scale, boolean animate)

Go to a specified desktop and set the current absolute position in this desktop. This method does nothing when the script is run in background.

Parameters
id desktop identifier
x absolute X position, in pixel
y absolute Y position, in pixel
scale zoom factor (1=100%, 0.5=50%, negative values are acceptable, 0 is not very useful)
animate whether to animate the move

public boolean isLocked ()

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

public boolean isPaused ()

Returns whether the current context is paused. It often means that Lightning Launcher is not displayed, for instance because another app is running. When the script is executed in the background this method always returns true.

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 int pickColor (String title, int color, boolean hasAlpha)

Request the user to pick a color.

Parameters
title text displayed at the top of the dialog
color initial color to display
hasAlpha whether to display the transparency slider. It will not enforce a fully opaque color, it only acts on the slider visibility.
Returns
  • either the selected color, or undefined if the dialog has been canceled

public Image pickImage (int maxPixels)

Request the user to pick an image through the Lightning image picker screen. Warning: images returned by this function may be very large, take care at memory use as exceeding limits will make the launcher crash. Use the maxPixels parameter: the image will be scaled by a power of two so that its number of pixels is below or equal. This function supports picking bitmaps and nine patches.

Parameters
maxPixels maximum number of pixels in the returned image (width x height), 0 for no limit, 1048576 is one mega pixels (1024 x 1024)
Returns
  • an Image, or null if the user canceled the operation, or if the image cannot be loaded

public float pickNumericValue (String title, float value, String valueType, float min, float max, float interval, String unit)

Request the user to enter a numeric value. When using the "%" unit, valueType must be set to FLOAT: the dialog will scale a decimal value so that 0.75 is displayed as 75%. Warning: the returned value may be subject to rounding errors.

Parameters
title text displayed at the top of the dialog
value initial value to display
valueType either INT or FLOAT. It will default to FLOAT if valueType is not a known value.
min minimum value for the slider
max maximum value for the slider
interval interval between values when sliding
unit text to display after the value (for instance "%" or "px"). When using "%" with FLOAT, scale value by 100
Returns
  • either the selected value, or undefined if the dialog has been canceled

public void runAction (int action, Item item, String data)

Run a Lightning action. This method does nothing when the script is run in background.

Parameters
action action code (one of the values defined in EventHandler
item item to be used as the target (only useful with actions requiring an item)
data optional data to send to be used by the action, use null if none

public void runAction (int action, String data)

Same as #runAction(int,Item,String) with a null item and data.

public void runAction (int action)

Same as #runAction(int,String) with a null data.

public void runScript (String name, String data)

This method is deprecated.
use runScript(String, String)

Run another script. Optional data can be transmitted to the called script and retrieved using getData().

Parameters
name name of the script as found in the script editor
data optional data to send to the script. Use JSON to pass more than a string.

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 void setScriptTag (String tag)

This method is deprecated.
use Script#setTag(String) instead together with #getCurrentScript

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 boolean startActivity (Intent intent)

Start an activity. Example:

 var intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.pierrox.net/")
 LL.startActivity(intent);

Parameters
intent intent to start the activity
Returns
  • true if launch is successful, false if activity not found or permission denied

public boolean startActivityForResult (Intent intent, Script receiver, String token)

Start an activity and handle the result in another script. This is similar to http://developer.android.com/reference/android/app/Activity.html#onActivityResult%28int,%20int,%20android.content.Intent%29 This call is asynchronous and the script will continue its execution. Once the started activity ends, the "receiver" script is called with the following parameters set:

  • resultCode: Integer, the activity result, most often Activity.RESULT_OK or Activity.RESULT_CANCELED
  • data: Intent, data provided by the activity, if any
  • token: String, optional value passed as third argument in startActivityForResult
This method cannot be called when the executing script is run in the background. In that case it will do nothing and return false

Parameters
intent intent to start the activity
receiver a script to execute upon activity end
token an optional string data that you can transmit to the receiver script
Returns
  • true if the activity has been started

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