public class

Item

extends Object
java.lang.Object
   ↳ net.pierrox.lightning_launcher.script.api.Item
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

The item is the base class for other objects that can be found in a container (shortcuts, folders, etc.). There are specific classes for some items (shortcut, folder, ...) when these items provides custom services. Some other item types don't have a specific class when they don't have more properties (such as widget for instance). Since Lightning V14 allows the same container to be displayed multiple times on the same screen, it is possible to retrieve several Item objects linked with the same underlying data. The identifier (see getId()) will then be the same.

Summary

Public Methods
Scriptable extend()
Return a new script object, with this item as prototype
Array getAllBindings()
This method is deprecated. use #getBindings instead
Binding getBindingByTarget(String target)
Retrieve a binding by its key, the taget.
Binding[] getBindings()
Image getBoxBackground(String state)
Retrieve the image currently displayed as the box background.
RectL getCell()
Returns the cell allocated to this item (only works when attached to the grid).
int getHeight()
Returns this item view height.
int getId()
Returns the unique item identifier.
Scriptable getMy()
Return a scriptable object that can be used to store live data.
String getName()
Container getParent()
Returns the container containing this item.
float getPositionX()
float getPositionY()
PropertySet getProperties()
Retrieve properties for this item.
View getRootView()
Retrieve the root android View for this item.
float getRotation()
Returns the rotation angle in degrees.
float getScaleX()
Returns the X scale for this item (only when detached from the grid).
float getScaleY()
Returns the Y scale for this item (only when detached from the grid).
Screen getScreen()
float getSkewX()
Returns the X skew for this item (only when detached from the grid).
float getSkewY()
Returns the Y skew for this item (only when detached from the grid).
String getTag()
Returns the value associated with this item.
String getTag(String id)
Returns the value associated with this item and id.
String getType()
Returns the item type has a text
int getWidth()
Returns this item view width.
boolean isVisible()
Returns true if the item is visible.
void setBinding(Binding binding)
Set a binding (same as #setBinding(String, String, boolean).
void setBinding(String target, String formula, boolean enabled)
Add or update a binding for this item.
void setBoxBackground(Image image, String state, boolean persistent)
Set a background image, optionally saving the change to file.
void setBoxBackground(Image image, String state)
Set a background image, in memory only, changes will not be persisted and will be lost when the app is restarted.box
void setCell(int left, int top, int right, int bottom)
Set the cell allocated to the item on the grid (only works when attached to the grid).
void setCell(int left, int top, int right, int bottom, boolean portrait)
Set the cell allocated to the item on the grid (only works when attached to the grid), persistently
void setName(String name)
void setPosition(float x, float y)
Set the position of the item (only when detached from the grid).
void setRotation(float angle)
Set the rotation of the item around its center (only when detached from the grid).
void setScale(float scaleX, float scaleY)
Set the scale of the item (only when detached from the grid).
void setSize(float width, float height)
Set the size of the item (only when detached from the grid).
void setSkew(float skewX, float skewY)
Set the skew of the item (only when detached from the grid).
void setTag(String id, String value)
Set a persistent data for this item.
void setTag(String value)
Set a persistent data for this item.
void setVisibility(boolean visible)
Hide or show an item.
String toString()
void unsetBinding(String target)
Removes a binding for this item.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public Scriptable extend ()

Return a new script object, with this item as prototype

Returns
  • a new script object which inherit from this item

public Array getAllBindings ()

This method is deprecated.
use #getBindings instead

Retrieve the list of configured bindings.

Returns
  • an array of bindings

public Binding getBindingByTarget (String target)

Retrieve a binding by its key, the taget.

Returns
  • a binding object, or null if no binding found for this target

public Binding[] getBindings ()

public Image getBoxBackground (String state)

Retrieve the image currently displayed as the box background. This image can be shared amongst several items.

Parameters
state one of "n" (normal), "s" (selected) or "f" (focused)
Returns
  • an image, or null if this is a nine patch or if there is no image

public RectL getCell ()

Returns the cell allocated to this item (only works when attached to the grid).

public int getHeight ()

Returns this item view height.

public int getId ()

Returns the unique item identifier. Each item has its own unique id in the app, meaning that it is not possible to find 2 items in 2 containers with the same id. However the item id will change if it is moved from one desktop to another, or moved in/out of a folder or panel. It may also change when loaded from a template.

public Scriptable getMy ()

Return a scriptable object that can be used to store live data. These data won't be stored, unlike tags.

public String getName ()

public Container getParent ()

Returns the container containing this item.

public float getPositionX ()

Returns
  • this item X position (only available when the script is not run in background).

public float getPositionY ()

Returns
  • this item Y position (only available when the script is not run in background).

public PropertySet getProperties ()

Retrieve properties for this item. Please note that modifying properties is expensive and not well suited for item animation.

public View getRootView ()

Retrieve the root android View for this item.

public float getRotation ()

Returns the rotation angle in degrees.

public float getScaleX ()

Returns the X scale for this item (only when detached from the grid).

public float getScaleY ()

Returns the Y scale for this item (only when detached from the grid).

public Screen getScreen ()

public float getSkewX ()

Returns the X skew for this item (only when detached from the grid).

public float getSkewY ()

Returns the Y skew for this item (only when detached from the grid).

public String getTag ()

Returns the value associated with this item. This is the same as getTag(null);

See Also

public String getTag (String id)

Returns the value associated with this item and id. Can be undefined if it has never been set. Using a null id is the same as calling getTag() without argument

public String getType ()

Returns the item type has a text

Returns
  • one of: Shortcut, Folder, Panel, Widget, StopPoint, DynamicText, Unlocker, PageIndicator or Unknown

public int getWidth ()

Returns this item view width.

public boolean isVisible ()

Returns true if the item is visible.

public void setBinding (Binding binding)

Set a binding (same as #setBinding(String, String, boolean). It is forbidden to modify bindings in a script itself triggered by a binding.

public void setBinding (String target, String formula, boolean enabled)

Add or update a binding for this item. It is forbidden to modify bindings in a script itself triggered by a binding. The target name may be a property name, but not always. Although using any known property may work, only the list below is supported.
Common item properties

NameDescription
i.alphaTransparency
i.visibilityVisibility
i.enabledEnabled
i.zindexZ-Index
i.boxBox
vDummy target

Item geometry, attached to the grid
NameDescription
c.lCell left
c.tCell top
c.rCell right
c.bCell bottom

Item geometry, detached from the grid
NameDescription
t.xLeft (X)
t.yTop (Y)
t.wWidth
t.hHeight
t.aAngle
t.sxScale X
t.syScale Y
t.kxSkew X
t.kySkew Y

Text properties
NameDescription
s.labelLabel
s.labelVisibilityLabel visibility
s.labelFontColorLabel color (normal state)
s.selectionColorLabelLabel color (selected state)
s.focusColorLabelLabel color (focused state)
s.labelFontSizeLabel font size
s.labelFontStyleLabel font style

Icon properties
NameDescription
s.iconVisibilityIcon visibility
s.iconScaleIcon scale
s.iconReflectionIcon reflection
s.iconColorFilterIcon color filter

Folder window properties
NameDescription
f.titleVisibilityTitle visibility
f.titleFontColorTitle font color
f.titleFontSizeTitle font size
f.wAHHorizontal alignment
f.wAVVertical alignment
f.wXLeft
f.wYTop
f.wWWidth
f.wHHeight
f.boxBox

Parameters
target the item's property to change (no check is done on this parameter)
formula the value for the target, a constant value, a short or complex script
enabled whether this binding is active

public void setBoxBackground (Image image, String state, boolean persistent)

Set a background image, optionally saving the change to file. Note that saving the image to file is much slower than setting it in memory only, hence this is not suitable for animations.

Parameters
state a combination of "n" (normal), "s" (selected), "f" (focused)
persistent whether to save changes and affect only this item, when set to false the image will be reset upon the next launcher restart

public void setBoxBackground (Image image, String state)

Set a background image, in memory only, changes will not be persisted and will be lost when the app is restarted.box

Parameters
state a combination of "n" (normal), "s" (selected), "f" (focused)

public void setCell (int left, int top, int right, int bottom)

Set the cell allocated to the item on the grid (only works when attached to the grid). These size and position are transcient and will be lost when the container is reloaded. Use the alternate setCell method to persist changes.

Parameters
left left column
top top row
right right column
bottom bottom row

public void setCell (int left, int top, int right, int bottom, boolean portrait)

Set the cell allocated to the item on the grid (only works when attached to the grid), persistently

Parameters
left left column
top top row
right right column
bottom bottom row
portrait if true will set the portrait position (and landscape if not using dual position), if false will set the landscape position (only if using dual position)

public void setName (String name)

public void setPosition (float x, float y)

Set the position of the item (only when detached from the grid). Warning: any changes made through this method may be saved, meaning that the item position will have to be manually reset.

public void setRotation (float angle)

Set the rotation of the item around its center (only when detached from the grid). Warning: any changes made through this method may be saved, meaning that the item angle will have to be manually reset.

Parameters
angle in degrees

public void setScale (float scaleX, float scaleY)

Set the scale of the item (only when detached from the grid). Warning: any changes made through this method may be saved, meaning that the item scale will have to be manually reset.

public void setSize (float width, float height)

Set the size of the item (only when detached from the grid). Warning: any changes made through this method may be saved, meaning that the item size will have to be manually reset.

public void setSkew (float skewX, float skewY)

Set the skew of the item (only when detached from the grid). Warning: any changes made through this method may be saved, meaning that the item skew will have to be manually reset.

public void setTag (String id, String value)

Set a persistent data for this item. This string value can be used to store non volatile data. Use JSON to store complex structures. The data to store is associated with an identifier. This identifier is useful to reduce conflicts when multiple scripts need to use data for an item. Using a null id is the same as calling setTag(String) without the id argument. Use setTag(id, null) to clear a tag. Example of use:


 // store some simple text
 var name = prompt("What is your name ?", "your name here");
 item.setTag("my_value", name);

 // later, retrieve this text and display it on a shortcut
 var name = item.getTag("my_value");
 other_item.setLabel(name);

 // store more than a string
 var complex_data = new Object();
 complex_data.date = new Date();
 complex_data.x = 4;
 complex_data.done = true;
 item.setTag("my_value", JSON.stringify(complex_data));

 // load these data
 var complex_data = JSON.parse(item.getTag("my_value"));
 

Parameters
id identifier for this tag, valid characters are a-z, A-Z, 0-9 and _ (underscore). The identifier "_" is reserved and shouldn't be used.
value value to store

public void setTag (String value)

Set a persistent data for this item. This is the same as setTag(null, value)

public void setVisibility (boolean visible)

Hide or show an item.

Parameters
visible true to make it visible
See Also

public String toString ()

public void unsetBinding (String target)

Removes a binding for this item. It is forbidden to modify bindings in a script itself triggered by a binding.

Parameters
target target property for which to remove the binding