Back

CreateOverlay

JS Py
Hello World
Content:
- Properties
- Methods

Overlays are displayed above everything on the screen - even on the home screen or above other applications.

ovl = app.CreateOverlay( options? ) → app object: Overlay

Overlays can be created from services as well which makes them almost perfect for interacting with them.

Note: This function is a premium feature. Please consider subscribing to Premium to use this feature and support DroidScript in its further development.

Example - Memory Monitor

cfg.Portrait;

function OnStart()
{
    app.ToBack();
    lay = app.CreateLayout( "Linear" );

    img = app.CreateImage( null, .3, .1 );
    img.SetBackColor( "#66333333" );
    img.SetAutoUpdate( false );
    lay.AddChild( img );

    ovl = app.CreateOverlay();
    ovl.AddLayout( lay, 0.8, app.GetTop() );

    app.Animate( Update, 1 );
}

var lst = new Array(100).fill(1e5);

function Update( time )
{
    var mem = app.GetMemoryInfo();
    lst.push( Math.round( 100 * mem.avail / mem.total ) - 50 );
    lst = lst.slice( -100 );

    img.Clear();
    img.SetPaintColor( "red" );
    img.DrawLine( 0, mem.threshold / mem.total, 1, mem.threshold / mem.total );

    img.SetPaintColor( "white" );
    img.DrawSamples( lst, 50 );
    img.Update();
}
# cfg.Portrait

from native import app

def OnStart():
    global img
    app.ToBack()
    lay = app.CreateLayout("Linear")

    img = app.CreateImage(None, 0.3, 0.1)
    img.SetBackColor("#66333333")
    img.SetAutoUpdate(False)
    lay.AddChild(img)

    ovl = app.CreateOverlay()
    ovl.AddLayout(lay, 0.8, app.GetTop())

    app.Animate(Update, 1)

lst = [1e5] * 100

def Update(time, dtime):
    mem = app.GetMemoryInfo()
    lst.append(round(100 * mem.avail / mem.total) - 50)
    lst = lst[-100:]

    img.Clear()
    img.SetPaintColor("red")
    img.DrawLine(0, mem.threshold / mem.total, 1, mem.threshold / mem.total)

    img.SetPaintColor("white")
    img.DrawSamples(lst, 50)
    img.Update()
Copy All       Run      

Properties

The following properties are available on the Overlay object:

dataObject: { key, value }

Methods

The following methods are available on the Overlay object:

GetParent() → app object
GetType() → String: “Overlay”
all types
String
Number: fraction (0..1)
String: comma “,” separated: “ShowWhenLocked”, “TurnScreenOn”, “KeepScreenOn”
String: “px”
Object: { command: args }
app object: Layout
ovl.AddLayout
Adds a layout to the overlay.
ovl.Batch
Batch method calls to be able to set all object's properties at once.
Note that you need to specify each parameter (use “” or null to leave some out)
Inherited methods can be called by appending an underscore to the function name (ie. txt.Batch({ SetBackColor_: [“red”] })
ovl.data
An object for saving individual extra properties.
ovl.GetParent
Returns the parent control object where the object was added to - commonly a layout.
ovl.GetType
Returns the control class name.
ovl.RemoveLayout
Removes a layout from the overlay.
ovl.SetPosition
Defines the position of a contained layout.