FANDOM


Container types Edit

Application Edit

Properties

Syntax Description
description
name
startup

Events

Syntax Description
on_close
on_open
on_service Fires after any service's on_update fires.

Methods

Syntax Description
close_application()
close_module()
delete_database(name) Deletes the database and all records in it.
database = get_database(name) Retrieve the database and create if it doesn't exist.
array = get_database_names()
log(message) Log a user event.
open_application(name) Open a Phonebot application by passing pbot:APPLICATION_NAME. Open other Android applications using their Intent URI:
open_module(name)

Module Edit

Properties

Syntax Description
name
orientation [ vertical | horizontal ]
text

Events

Syntax Description
on_open
on_close
on_service Fires after any service's on_update fires.

Visual types Edit

Properties

Syntax Description
gravity [ bottom | center_horizontal | center_vertical | left | right | top ], default center_horizontal | center_vertical Read-only array
group Read-only
layout_height [ fill_container | wrap_content ]
layout_width [ fill_container | wrap_content ]
name
text
visible true/false
type [ button | check | edit | label | list | radio ] Read-only

Events

Syntax Description
on_click

Check Edit

Properties

Syntax Description
value true/false

Drop down list Edit

See List.

Edit box Edit

Events

Syntax Description
on_update Fires after any change to the contents

List Edit

Properties

Syntax Description
selected_index Read-only
selected_item Read-only. The text of column zero of the selected row
size Read-only

Methods

Syntax Description
index = add_item(item) Add and item to the list and return the index of the added item.
clear()
delete_item(index)
item = get_item(row, col) Pass any non-numeric value as col to retrieve the previously set named data value.
set_item(row, col, value) Pass any non-numeric value as col to set a named data value associated with the row.
/* Add 10 rows */
for (index = 0; index < 10; index = index + 1)
    list1.add_item("New item " & index)
end

/* Set and get the string displayed in the 5th row */
list1.set_item(4, 0, "New text for the row")     /* Note: the row must already exist. */
row_val = list1.get_item(4, 0)                   /* will retrieve "New item 4" */

/* Set and get the a named data value for the 5th row */
list1.set_item(4, "my data", "hidden value")     /* Note: the row must already exist. */
list1.set_item(4, "more data", "another value")  /* Note: the row must already exist. */
row_val = list1.get_item(4, "my data")           /* will retrieve "hidden value" */

Option Edit

Properties

Syntax Description
value true/false

Services Edit

Services are non-visual components that monitor different environment states and trigger an event when the state changes. When using multiple services, call service.event_size to determine if the specific service was updated.

Service Properties Description
http url Makes a GET request to a URL. Returns a single event in the queue containing the response.
sensor sensors - array of sensor names

update_frequency - time between updates in milliseconds

Monitors one or more hardware sensors. Returns an event containing a comma-delimited list of values beginning with the sensor name (e.g. orientation,60.0,-28.0,3.0). The range of each value is dependent on the sensor.
timer duration - time between updates, formatted as h:m:s, m:s, or s Fire the update events at regular intervals. Returns an event containing the datetime value when the update happened.

Properties

Syntax Description
auto_start Read-only.
event_size Read-only. The number of events in the queue. When monitoring multiple services, this property can be used in on_service events to determine which service was updated.
name Read-only.
text Read-only.

Methods

Syntax Description
size = clear_events() Delete all events and return how many were deleted.
event = get_event() Retrieve the next event in the queue.
value = get_property(name) Retrieve a service property.
event = pop_event() Retrieve and delete the next event in the queue.
set_property(name, value) Set a service property.
start() Start the service.
stop() Stop the service.

Events

Syntax Description
on_service

Variables Edit

Properties

Syntax Description
(value) Tacit, set/return value by default

Array Edit

Manage a collection of values. Values are stored in the order they are added; sorting reorders and eliminates the original order.

Properties

Syntax Description
size

Methods

Syntax Description
index = add_element(element) Add an element to the end of the collection.
clear()
delete_element(index)
boolean = exists(index)
element = get_element(index) Get the value at index.
string = join(delimiter) Join the array elements with delimiter and return the string.
reverse()
index = set_element(index, value) Set the element. Log runtime error if it doesn't exist.
sort(type) 0 = alpha-numeric by value, 1 = numeric by value

Database Edit

A database is accessed by its name. Records are accessed by their zero-based index. Fields within records are accessed by their zero-based index or by their field name.

Properties

Syntax Description
field_size The number of fields in the database.
name
size The number of records in the database.

Methods

Syntax Description
index = add_field(name) Returns zero-based index. -1 if the field cannot be added.
record = add_record()
delete_field(index | name) Delete the field. The values in the associated field in every record in the database will be deleted. This included those records currently referenced by variables. The index value of the remaining fields will change if those fields have a higher index value than the field being deleted.
delete_record(index | record)
name = get_field(index)

index = get_field(name)

Returns -1 if the field does not exist.
record = get_record(index)
record = get_record_by_id(id) Get the record based on its unique ID. Retrieved from record.id.

Usage:

/* Create a database and record */
db = application1.get_database("contacts")
db:database.add_field("name")
db:database.add_field("email")
first_rec = db:database.add_record()
first_rec:record.set_field("name", "Joe Bot")
first_rec:record.set_field("email", "jbot@android.com")

/* Loop through all fields in the database */
for (field_index = 0; field_index < db:database.field_size; field_index = field_index + 1)
    field_name = db:database.get_field(field_index)
end

/* Loop through all records in a database */
for (index = 0; index < db:database.size; index = index + 1)
    rec = db:database.get_record(index)
    name = rec:record.get_field("name")
    email = rec:record.get_field("email")
    for (field_index = 0; field_index < db:database.field_size; field_index = field_index + 1)
        field_value = rec:record.get_field(field_index)
    end
end

/* Delete the new record and database */
db:database.delete_record(first_rec)
application1.delete_database("contacts")

Datetime Edit

Properties

Syntax Description

Methods

Syntax Description
add_duration(formatted_value) Add a duration to the datetime. Values are strings in the format:
DURATION[y|M|d|h|m|s]
datetime = difference(datetime)
string = format(format) Uses the Java date format pattern syntax
now()
TBD parse(value, format) Set the datetime to the string value formatted as format.

Json Edit

Properties

Syntax Description
size Read-only. Returns the size of the Json array.

Methods

Syntax Description
string = get_element(name) Returns the named value or a Json array.
string = get_record(index) Returns a value or Json object at the index.

Map Edit

Manage a collection of names mapped to values. Pairs are stored in the order they are added; sorting reorders and eliminates the original order.

Properties

Syntax Description
size

Methods

Syntax Description
index = add_named_element(name, value) Add an element to the end of the collection.
clear()
delete_element(name)
boolean = exists(name)
value = get_element(name) Get the value mapped by name.
name = get_name(index) Get the name at index.
string = join_names(delimiter) Join the names with delimiter and return the string.
string = join_values(delimiter) Join the values with delimiter and return the string.
reverse()
index = set_element(name, value) Set the element. Log runtime error if it doesn't exist.
sort(type) 0 = alpha-numeric by value, 1 = numeric by value, 2 = alpha-numeric by name, 3 = numeric by name

Number Edit

Properties

Syntax Description

Methods

Syntax Description
number = average(array) Sets the value to the average and returns that value.
number = fraction() x.y returns 0.y
number = integer() x.y returns x
TBD number = random(min, max) A random number between min and max
number = round() < x.5 returns x; >= x.5 returns x + 1

Record Edit

Properties

Syntax Description
id The unique ID for the record. Read-only.

Methods

Syntax Description
field = get_field(index | name)
set_field(index | name, field)

String Edit

Properties

Syntax Description
size Read-only

Methods

Syntax Description
index = index_of(string)
string = replace_all(value, replacement)
array = split(delimiter)
string = substring(start_index, end_index)

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.