Check, Radio and Toggle Functions
ListView and Spinner Functions
Additional View Events
DEVICE FUNCTIONS
Get the available width of the window.
Depending upon the device orientation this is not necessarily the same as the physical display width.
WindowWidth
Get the available height of the window.
Depending upon the device orientation this is not necessarily the same as the physical display height.
WindowHeight
Get the scaling value (density) for this device.
ScreenScale
Get the layout values for this device in a comma separated string "width,height,density",
GetLayoutValues
Contents
ACTIVITY FUNCTIONS
Returns true if this is the first time the initial code block program has been run.
This is the equivalent of FirstTime in Activity_Create.
GetFirstTime
Get a previously saved an array of persistent data that will survive activity destruction.
GetSavedData(dataarrayname As String)
Save an array of data that will survive activity destruction.
SetSavedData(dataarrayname As String)
Close the Activity and return to the editor
Call this at the end of the initial code block for a program that does not support events otherwise the
program will be left waiting for an event that won't come and the back button will be needed to close it.
A program that does support events can end by calling AppClose or this.
ActivityFinish
Set the Background property of the Activity to the GradientDrawable.
Returns false if less than two colors are in the array otherwise returns true.
Orientation can be one of the following -
"TOP_BOTTOM", "TR_BL" (Top-Right To Bottom-Left, "RIGHT_LEFT", "BR_TL" (Bottom-Right To Top-Left)
"BOTTOM_TOP", "BL_TR" (Bottom-Left To Top-Right), "LEFT_RIGHT", "TL_BR" (Top-Left To Bottom-Right)
SetActivityBackground(orientation As String, radius As String, colorsarrayname As String)
Logs the provided message to the Logcat output.
LogCat(message As String)
Closes the Activity menu. This is added for symmetry with OpenMenu but seems of little practical use.
CloseMenu
Opens the Activity menu
OpenMenu
Contents
VIEWS AND EVENTS
On Activity_Create the inital block of code up to the first Sub statement is run. GetFirstTime returns true the first time.
On Activity_Pause "Sub activity_pause(userclosed)" is called if implemented.
On Activity_Resume "Sub activity_resume" is called if implemented.
All MenuItem Click events are vectored to a single BasicLib sub "Sub menu_click(menutext)".
All Button Click events are vectored to a single BasicLib sub "Sub button_click(sender)".
All Checkbox CheckedChange events are vectored to a single BasicLib sub "Sub check_change(sender, checked)".
All EditText TextChanged events are vectored to a single BasicLib sub "Sub edit_change(sender, oldtext, newtext)".
All EditText EnterPressed events are vectored to a single BasicLib sub "Sub edit_enterpressed(sender)".
All ListView ItemClick events are vectored to a single BasicLib sub "Sub listview_itemclick(sender, position, value)".
All RadioButton CheckedChange events are vectored to a single BasicLib sub "Sub radio_change(sender, checked)".
All SeekBar ValueChanged events are vectored to a single BasicLib sub "Sub seekbar_valuechanged(sender, value, userchanged)".
All Spinner ItemClick events are vectored to a single BasicLib sub "Sub spinner_itemclick(sender, position, value)".
All TabHost TabChanged events are vectored to a single BasicLib sub "Sub tabhost_tabchanged(sender)".
All ToggleButton CheckedChange events are vectored to a single BasicLib sub "Sub toggle_change(sender, checked)".
Sender will be set to the name of view that caused the event.
If a view raising events is added then the appropriate event Sub or Subs must be present in the program.
Here are all the event Sub templates to copy and paste if desired.
Sub activity_pause(userclosed)
End Sub
Sub activity_resume
End Sub
Sub button_click(who)
End Sub
Sub check_change(who, checked)
End Sub
Sub edit_change(who, old, new)
End Sub
Sub edit_enterpressed(who)
End Sub
Sub listview_itemclick(who, pos, value)
End Sub
Sub menu_click(menutext)
End Sub
Sub radio_change(who, checked)
End Sub
Sub seekbar_valuechanged(who, pos, value)
End Sub
Sub spinner_itemclick(who, pos, value)
End Sub
Sub tabhost_tabchanged(who)
End Sub
Sub toggle_change(who, checked)
End Sub
Completely remove the named view from the program.
RemoveView(name As String)
Add a MenuItem to the Activity.
The maximum of six menu itemsthat was present in previous versions no longer applies
AddMenuItem(menutext As String)
Add a Button to the window or a panel.
AddButton(name As String, left As String, top As String, width As String, height As String, parent As String)
Add a ToggleButton to the window or a panel.
AddToggleButton(name As String, left As String, top As String, width As String, height As String, parent As String)
Add a CheckBox to the window.
AddCheckBox(name As String, left As String, top As String, width As String, height As String, parent As String)
Add an EditText to the window or a panel.
AddEditText(name As String, left As String, top As String, width As String, height As String, parent As String)
Add an ImageView to the window or a panel.
AddImage(name As String, left As String, top As String, width As String, height As String, parent As String)
Add a Label to the window or a panel.
AddLabel(name As String, left As String, top As String, width As String, height As String, parent As String)
Add a ListView to the window or a panel.
AddListView(name As String, left As String, top As String, width As String, height As String, parent As String)
Add a Panel to the window or a panel.
AddPanel(name As String, left As String, top As String, width As String, height As String, parent As String)
Add a RadioButton to the window or a panel.
AddRadioButton(name As String, left As String, top As String, width As String, height As String, parent As String)
Add a ScrollView to the window or a panel.
AddScrollView(name As String, left As String, top As String, width As String, height As String, parent As String)
Add a SeekBar to the window or a panel.
AddSeekBar(name As String, left As String, top As String, width As String, height As String, parent As String)
Add a Spinner to the window or a panel.
AddSpinner(name As String, left As String, top As String, width As String, height As String, parent As String)
Add a TabHost to the window or a panel.
AddTabHost(name As String, left As String, top As String, width As String, height As String, parent As String)
Contents
VIEW FUNCTIONS
Get the Enabled property of the named view.
GetEnabled(name As String)
Get the Visible property of the named view.
GetVisible(name As String)
Get the Top property of the named view.
GetTop(name As String)
Get the Left property of the named view.
GetLeft(name As String)
Get the Width property of the named view.
GetWidth(name As String)
Get the Height property of the named view.
GetHeight(name As String)
Set the Enabled property of the named view.
SetEnabled(name As String, state As String)
Set the Visible property of the named view.
SetVisible(name As String, visible As String)
Set the Top property of the named view.
SetTop(name As String, top As String)
Set the Left property of the named view.
SetLeft(name As String, left As String)
Set the Width property of the named view.
SetWidth(name As String, width As String)
Set the Height property of the named view.
SetHeight(name As String, height As String)
Bring the named view to the front of the Z order.
BringToFront(name As String)
Send the named view to the back of the Z order.
SendToBack(name As String)
Set the focus to the named view.
RequestFocus(name As String)
Set the BackgroundImage of the view to the present bitmap.
Return true if both view and bitmap are initialised otherwise return false.
SetBackgroundImage(name As String)
Set the Background property of the named view to a ColorDrawable.
SetColor(name As String, radius As String, Color As String)
Set the Background property of the named view to a GradientDrawable.
Returns false if less than two colors are in the array or name not found otherwise returns true.
Orientation can be one of the following -
"TOP_BOTTOM", "TR_BL" (Top-Right To Bottom-Left, "RIGHT_LEFT", "BR_TL" (Bottom-Right To Top-Left)
"BOTTOM_TOP", "BL_TR" (Bottom-Left To Top-Right), "LEFT_RIGHT", "TL_BR" (Top-Left To Bottom-Right)
SetBackground(name As String, orientation As String, radius As String, colorsarrayname As String)
Invalidate the named view
Invalidate(name As String)
Contents
TEXTVIEW FUNCTIONS
Views containing text support these functions in addition to the View functions.
Set the Gravity property, if any, of the named view.
NO_GRAVITY = 0; TOP = 48 (0x30) ; BOTTOM = 80 (0x50; LEFT = 3; RIGHT = 5; CENTER = 17 (0x11);
CENTER_HORIZONTAL = 1; CENTER_VERTICAL = 16 (0x10) ; FILL = 119 (0x77);
SetGravity(name As String, gravityvalue As String)
Get the Text property, if any, of the named view.
GetText(name As String)
Set the Text property, if any, of the named view.
SetText(name As String, Text As String)
Set the TextColor property, if any, of the named view.
SetTextColor(name As String, Color As String)
Set the TextSize property, if any, of the named view.
SetTextSize(name As String, size As String)
There is one Typeface but it can be reinitialised as required.
Typeface - "Default", "Monospace", "Serif", "Sans_Serif"
Style - 0 Normal : 1 Bold : 2 Italic : 3 Bold_Italic
CreateTypeface(face As String, style As String)
Set the Typeface property, if any, of the named view to the current typeface.
SetTypeface(name As String)
Contents
EDITTEXT FUNCTIONS
EditText supports these functions in addition to the View and TextView functions.
Gets the selection start position (or the cursor position) of the EditText.
Returns -1 if there is no selection or cursor.
GetSelectionStart(name As String)
Force the EditText virtual keyboard action key to display Done by setting this value to True.
SetForceDoneButton(name As String, forcestate As String)
Set the text that will appear when the EditText is empty.
SetHint(name As String, hint As String)
Set the color of the text that will appear when the EditText is empty.
SetHintColor(name As String, hintcolor As String)
Set the value of the EditText InputType property.
NONE = 0; TEXT = 1; NUMBERS = 2; _PHONE = 3; DECIMAL_NUMBERS = 12290;
SetInputType(name As String, inputtype As String)
Set the value of the EditText PasswordMode property.
SetPasswordMode(name As String, state As String)
Sets the selection start position (or the cursor position) of the EditText.
SetSelectionStart(name As String, selectionstart As String)
Set the value of the EditText SingleLine property.
SetSingleLine(name As String, state As String)
Set the value of the EditText Wrap property.
SetWrap(name As String, state As String)
Contents
CHECKBOX, RADIOBUTTON AND TOGGLEBUTTON FUNCTIONS
Get the Checked state of a CheckBox, RadioButton or ToggleButton.
GetChecked(name As String)
Set the Checked state of a CheckBox, RadioButton or ToggleButton.
SetChecked(name As String, checked As String)
Set the TextOn property of a ToggleButton.
SetTextOn(name As String, Text As String)
Set the TextOff property property of a ToggleButton.
SetTextOff(name As String, Text As String)
Contents
TIMER FUNCTIONS
There is one time and the Timer Tick events are vectored to a BasicLib sub "Sub timer_tick".
If the Timer is enabled this event Sub must be present in the program.
Enable or disable the timer.
SetTimerEnabled(enabled As String)
Set the timer interval in milliseconds.
SetTimerInterval(interval As String)
Contents
SEEKBAR FUNCTIONS
Returns the current SeekBar Max value.
GetMax(seekbarname As String)
Returns the current SeekBar Value.
GetValue(seekbarname As String)
Sets the current SeekBar Max value.
SetMax(seekbarname As String, maxvalue As String)
Sets the current SeekBar Value.
SetValue(seekbarname As String, value As String)
Contents
SCROLLVIEW FUNCTIONS
Returns the current ScrollView ScrollPosition.
GetScrollPosition(scrollviewname As String)
Sets the current ScrollView ScrollPosition.
SetScrollPosition(scrollviewname As String, value As String)
Scrolls the ScrollView to the top or bottom.
FullScroll(scrollviewname As String, bottom As String)
Makes the ScrollView Panel accessible as a named Panel View.
GetPanel(scrollviewname As String, panelname As String)
Contents
SPINNER FUNCTIONS
Sets the title that will be displayed when the Spinner is opened.
SetPrompt(name As String, index As String)
Returns the index of the selected item of a Spinner. Returns -1 if no item is selected.
GetSelectedIndex(name As String)
Selects the item at the specified index of a Spinner. Pass -1 if no item is selected.
SetSelectedIndex(name As String, index As String)
Returns the the selected item of a Spinner. Returns "" if no item is selected.
GetSelectedItem(name As String)
Contents
LISTVIEW FUNCTIONS
Sets the background color that will be used while scrolling the ListView.
SetScrollColor(name As String, Color As String)
Sets whether the fast scroll icon will appear when the user scrolls the list. The default Is False.
SetFastScrollEnabled(name As String, state As String)
Sets the ItemHeight of the SingleLineLayout in a ListView.
SetItemHeight(name As String, height As String)
Makes the ListView.SingleLineLayout.Label accessible as a Label view.
The layout functions of the ListView items may be changed using the label functions.
GetLabel(listviewname As String, labelname As String)
Set the ListView.SingleLineLayout.Background property of the ListView to a ColorDrawable.
SetLayoutBackgroundColor(name As String, radius As String, Color As String)
Set the ListView.SingleLineLayout.Background property of the ListView to a GradientDrawable.
Returns false if less than two colors are in the array or name not found otherwise returns true.
Orientation can be one of the following -
"TOP_BOTTOM", "TR_BL" (Top-Right To Bottom-Left, "RIGHT_LEFT", "BR_TL" (Bottom-Right To Top-Left)
"BOTTOM_TOP", "BL_TR" (Bottom-Left To Top-Right), "LEFT_RIGHT", "TL_BR" (Top-Left To Bottom-Right)
SetLayoutBackgroundColorgradient(name As String, orientation As String, radius As String, colorsarrayname As String)
Contents
LISTVIEW AND SPINNER FUNCTIONS
Add an item To a ListView or Spinner.
Add(name As String, item As String)
Add an array of items to a ListView or Spinner.
AddAll(name As String, itemarrayname As String)
Clears the items from a ListView or Spinner.
Clear(name As String)
Returns the item at the specified index from a ListView or Spinner.
GetItem(name As String, index As String)
Removes the item at the specified index from a ListView or Spinner.
RemoveAt(name As String, index As String)
Returns the number of items in a ListView or Spinner.
GetSize(name As String, index As String)
Contents
TABHOST
Add a Tab and a new associated Panel to a TabHost.
The panelname may be used to add views To the Tab.
AddTab(title As String, panelname As String, parenttabhost As String)
Returns the number of tab pages.
GetTabCount(tabhostname As String)
Returns the index of the current tab page.
GetCurrentTab(tabhostname As String)
Selects the current tab page.
SetCurrentTab(tabhostname As String, tabnumber As String)
Contents
GRAPHICS FUNCTIONS
There is one bitmap but it can be reinitialised to a bitmap from a file.
BitmapInit(dir As String, fileName As String)
The one bitmap can also be reinitialised to a mutable bitmap.
BitmapInitMutable(width As String, height As String)
Get the width of the current bitmap.
BitmapWidth
Get the height of the current bitmap.
BitmapHeight
There is one canvas but it can be reinitialised on any View.
CanvasInit(imageviewname As String)
The one canvas can also be reinitialised on a mutable Bitmap if the sole Bitmap object is one.
CanvasInit2()
Draws the present bitmap
SrcRect - The subset of the Bitmap that will be drawn.
DestRect - The rectangle that the Bitmap will be drawn to.
Returns false if more or less than two points are in the rectangle arrays otherwise returns true.
DrawBitmap(srcrectarrayname As String, destrectarrayname As String)
Draws the present bitmap rotated.
SrcRect - The subset of the Bitmap that will be drawn.
DestRect - The rectangle that the Bitmap will be drawn to.
Returns false if more or less than two points are in the rectangle arrays otherwise returns true.
DrawBitmapRotated(srcrectarrayname As String, destrectarrayname As String, degrees As String)
Fills the entire canvas with the given color.
DrawColor(Color As String)
Draws a circle.
DrawCircle(x As String, y As String, radius As String, Color As String, filled As String, strokewidth As String)
Draws a line.
DrawLine(x1 As String, y1 As String, x2 As String, y2 As String, Color As String, strokewidth As String)
Draws a set of connected lines from the points provided in a named array.
Returns false if less than two points are in the array otherwise returns true.
DrawPath(pointsarrayname As String, Color As String, filled As String, strokewidth As String)
Sets a single pixel to the specified color.
DrawPoint(x As String, y As String, Color As String)
Draws a rectangle from the points provided in a named array.
Returns false if more or less than two points are in the array otherwise returns true.
DrawRect(rectarrayname As String, Color As String, filled As String, strokewidth As String)
Draws a rotated rectangle from the points provided in a named array.
Returns false if more or less than two points are in the array otherwise returns true.
DrawRectRotated(rectarrayname As String, Color As String, filled As String, strokewidth As String, degrees As String)
Draw text. Align is one of the following values: "LEFT", "CENTER", "RIGHT".
DrawText(Text As String, x As String, y As String, textsize As String, Color As String, align As String)
Draw text. Align is one of the following values: "LEFT", "CENTER", "RIGHT".
DrawTextRotated(Text As String, x As String, y As String, textsize As String, Color As String, align As String, degrees As String)
Contents
ARRAY FUNCTIONS
Fully or partially fills the specified array with the specified value.
FillArray(arrayname As String, start As String, len As String, value As String)
Sort the specified array into ascending order in the specified manner.
SORTCASESENSITIVE is 0, SORTCASEINSENSITIVE is 1, SORTNUMERIC = 2
Note that for use with BinarySearch SORTCASESENSITIVE should be used otherwise the result may not be accurate
SortArray(arrayname As String, sorttype As String)
Searches the specified array for the specified value using the binary search algorithm.
The array must be sorted into ascending order using SORTCASESENSITIVE otherwise the result may not be accurate
SearchArray(arrayname As String, value As String)
Contents
USER INTERACTION FUNCTIONS
Shows a Toast.
ShowToast(msg As String, longtime As String)
Get the user input from the latest InputBox, InputDate or InputTime modal dialog.
GetInput
Show a modal dialog box and prompt the user for data.
Returns a DialogResponse value with the input text available to GetInput.
InputBox(prompt As String, title As String, Positive As String, Cancel As String, Negative As String)
Show a modal dialog box and prompt the user for a date.
Returns a DialogResponse value with the input value avalable to GetInput as a ticks value.
InputDate(prompt As String, title As String, startdateticks As String, Positive As String, Cancel As String, Negative As String)
Show a modal dialog box and prompt the user for a path or file name.
Returns a DialogResponse value with the input values available to GetInput as a comma separated string.
The first part is the file path and the last part is file name. If the user selected a path the file name is an empty string.
InputFile(filepath As String, filename As String, filefilter As String, title As String, Positive As String, Cancel As String, Negative As String)
Show a modal dialog box and prompt the user for a time.
Returns a DialogResponse value with the input value available to GetInput as a ticks value.
InputTime(prompt As String, title As String, starttimeticks As String, as24hrs As String, Positive As String, Cancel As String, Negative As String)
Show a modal dialog box and prompt the user to select an item.
selecteditem is the index of the item that will first be selected or -1 if no item should be preselected.
Returns the index of the selected item or DialogResponse.Cancel if the user pressed on the back key.
InputListBox(itemarrayname As String, title As String, selecteditem As String )
Show a modal dialog box and prompt the user to select one or more items.
returns a comma separated list of indices selected that may be separated with StrSplit.
InputMultiListBox(itemarrayname As String, title As String)
Show a modal dialog box and prompt the user for an integer number.
If ShowSign is True the sign of the number corresponds to the sign entered by the user.
Returns a DialogResponse value with the input number available to GetInput.
If ShowSign is True the sign of the number corresponds to the sign entered by the user.
InputNumber(showsign As String, digits As String, number As String, title As String, Positive As String, Cancel As String, Negative As String)
Show a modal dialog box and prompt the user to make a selection.
Returns a DialogResponse
MessageBox(message As String, title As String, Positive As String, Cancel As String, Negative As String)
Show a non-modal progress dialog.
ProgressShow(Text As String)
Hide a non-modal progress dialog.
ProgressHide
Allow the message loop to run, lets the progress dialog repaint itself.
CallDoEvents
Contents
FILE OPERATION FUNCTIONS
Reads the entire file and fills a named array with all lines as strings.
Returns true if successful, false otherwise.
FileReadList(dir As String, fileName As String, listarrayname As String)
Reads the entire file and returns it as a string.
Returns an empty string on failure.
FileReadString(dir As String, fileName As String)
Writes each item in the List As a single line.
Note that a value containing CRLF will be saved as two lines which will return two items when read with ReadList.
Returns true if successful, false otherwise.
FileWriteList(dir As String, filename As String, listarrayname As String)
Writes the given text to a new file.
Returns true if successful, false otherwise.
FileWriteString(dir As String, filename As String, Text As String)
Deletes the specified file. If the file name is a directory then it must be empty in order to be deleted.
Returns true if the file was successfully deleted.
Files in the assets folder cannot be deleted.
Returns true if successful, false otherwise.
FileDelete(dir As String, filename As String)
Returns true if the specified FileName exists in the specified Dir.
Note that the Android file system is case sensitive.
FileExists(dir As String, filename As String)
Tests whether the specified file is a directory.
FileIsDirectory(dir As String, filename As String)
Creates the given folder (dir can be a path like "dir1/dir2", creates all folders as needed).
Returns true if successful, false otherwise.
FileMakeDir(parentdir As String, dir As String)
Fills an array with a list with all the files and directories which are stored in the specified path.
Returns true if successful, false otherwise.
FileListFiles(dir As String, filesarrayname As String)
Returns the internal private storage dir.
FileDirInternal As String
Returns the root folder of the external storage media.
FileDirRootExternal
Returns the application default external folder which is based on the package name.
The folder is created if needed.
FileDirDefaultExternal
Returns a reference to the files added with the Files Manager. These files are read-only.
FileDirAssets
Contents
Contents
CUSTOM FUNCTIONS
These additional functions have been added by B4A user JesseW to compliment the BasicLib library and extend its functionality.
Keycode functions:
KeyCode_isNumber(KeyCode)
KeyCode_isAlpha(KeyCode)
KeyCode_isSymbol(KeyCode)
KeyCode_isKeyboard(KeyCode)
KeyCode_isDPad(KeyCode)
KeyCode_isMedia(KeyCode)
KeyCode_isDevice(KeyCode)
--
Pass the KeyCode value from the Activity_KeyPress event to any of these
functions and they will return true or false depending upon whether
the passed KeyCode is contained within that particular set.
KeyCode constants:
Note that not all KeyCode constants are supported. Letters, numbers and
symbols can all be checked for using the KeyCode functions above. These
constants contain the remaining values.
--
KeyCode_AltLeft
KeyCode_AltRight
KeyCode_Back
KeyCode_Call
KeyCode_Camera
KeyCode_Clear
KeyCode_Del
KeyCode_DPadCenter
KeyCode_DPadDown
KeyCode_DPadLeft
KeyCode_DPadRight
KeyCode_DPadUp
KeyCode_EndCall
KeyCode_Enter
KeyCode_Envelope
KeyCode_Explorer
KeyCode_Focus
KeyCode_Grave
KeyCode_HeadSetHook
KeyCode_Home
KeyCode_MediaFastForward
KeyCode_MediaNext
KeyCode_MediaPlayPause
KeyCode_MediaPrevious
KeyCode_MediaRewind
KeyCode_MediaStop
KeyCode_Menu
KeyCode_Mute
KeyCode_Notification
KeyCode_Num
KeyCode_Search
KeyCode_ShiftLeft
KeyCode_ShiftRight
KeyCode_SoftLeft
KeyCode_SoftRight
KeyCode_Sym
KeyCode_Tab
KeyCode_Unknown
KeyCode_VolumeDown
KeyCode_VolumnUp
Color constants:
Colors_Black
Colors_Blue
Colors_Cyan
Colors_DarkGray
Colors_Gray
Colors_Green
Colors_LightGray
Colors_Magenta
Colors_Red
Colors_Transparent
Colors_White
Colors_Yellow
Typeface constants:
Typeface_FontDefault
Typeface_FontMonospace
Typeface_FontSerif
Typeface_FontSansSerif
Typeface_StyleNormal
Typeface_StyleBold
Typeface_StyleItalic
Typeface_StyleBoldItalic
These Gravity constants are for use for justifying text and images:
Gravity_None
Gravity_Top
Gravity_Bottom
Gravity_Left
Gravity_Right
Gravity_Center
Gravity_CenterHorizontal
Gravity_CenterVertical
Gravity_Fill
These functions setup and use the new default parameter system which
improves render time of certain views by reducing the number of calls
required for a custom view from several to just one.
Sets a default set of parameters to be used with a default view
defid (string) name of the parameter set
radius (number) corner radius of a color drawable (see setcolor)
color (number) color param of a color drawable (see setcolor)
tcolor (number) text color (see settextcolor)
tsize (number) text size (see settextsize)
grav (number) view gravity (see setgravity)
tface (boolean) true/false: indicates whether or not to set the labels typeface using the settypeface function (see settypeface)
Example:
SetTypeFace("Monospace", 1)
SetDefaultParams("header", 8, cgray, cwhite, 24, 21, True)
AddDefaultLabel("lblhname", 0, 0, 200, 40, "", "header", "Name")
AddDefaultLabel("lblhaddr", 210, 0, 200, 40, "", "header", "Address")
AddDefaultLabel("lblhphone", 420, 0, 100, 40, "", "header", "Phone")
This example sets the typeface to bold monospace font, then sets the
default label parameters to a corner radius of 8 (mildly rounded), a
background color of gray, white text color, text size of 24, gravity
(or justification) to right justifified, centered vertically, and indicates
to use the bold monospaced typeface font. Then 3 custom labels are added,
each with a single call.
SetDefaultParams(defid As String, radius As String, color As String, tcolor As String, tsize As String, grav As String, tface As String)
Adds a custom label which uses the defaults as explained above. This
allows a custom label to be rendered with a single call.
These parameters are in addition to the standard AddLabel parameters:
defid (string) name of the parameter set (see SetDefaultLabel)
text (string) text of the label (see SetText)
AddDefaultLabel(name As String, left As String, top As String, width As String, height As String, parent As String, defid As String, text As String)
These functions reflect the recent changes that were made to the B4A
Designer, which include the new Designer Script functions which are not
available directly from code.
Sets the right side of the named view
SetRight(name As String, right As String)
Gets the right side of the named view
GetRight(name As String) As String
Sets the bottom side of the named view
SetBottom(name As String, bottom As String)
Gets the bottom side of the named view
GetBottom(name As String) As String
Sets the horizontal center of the named view
SetHCenter(name As String, hcenter As String)
Gets the horizontal center of the named view
GetHCenter(name As String) As String
Sets the vertical center of the named view
SetVCenter(name As String, vcenter As String)
Gets the vertical center of the named view
GetVCenter(name As String) As String
Sets the left and right sides of the named view, adjusting its width
as necessary
SetLeftAndRight(name As String, left As String, right As String)
Sets the top and bottom sides of the named view, adjusting its height
as necessary
SetTopAndBottom(name As String, top As String, bottom As String)
***NOTE: The Chain and Run statements are not stable at this time.
They seem to work properly for small scripts, but for larger scripts,
they do not handle starting the new script properly!!!
*** USE CHAIN AND RUN AT YOUR OWN RISK !!!
The Chain statement starts another B4Script program in the same project, and sends an array of args
that the other program can catch and use via the system array Args(0). The other program also has access to
the process safe saved data array that is accessed via GetSavedData. It is not
necessary to use the .b4s file ext of the other program name.
Usage:
Chain("B4SProgram", "arrayname")
Example: Setup.b4s:
Dim PGlobals(4)
...
Dim CArgs(3)
CArgs(0) = "My Name"
CArgs(1) = "My Address"
CArgs(2) = "My City, St Zip"
SetSavedData("PGlobals")
Chain("Address", "CArgs")
Address.b4s:
Dim PGlobals(0)
If ArrayLen(Args) = 3 Then
MyName = Args(0)
MyAddress = Args(1)
MyCityStZip = Args(2)
Endif
Rem This program also has access to the sending programs saved global array
GetSavedData("PGlobals")
Chain(prg As String, argsarrayname As String) As String
Run
The Run statement is similar to Chain in that it calls another B4Script program,
but it starts fresh, as though it had just been run, instead of passing arguments
and having access to other programs global saved arrays.
Usage:
Run("B4SProgram")
Run(prg As String) As String
Runs the current program again
Restart As String
Returns true if the named view exists, otherwise false
isView(name As String) As String
Removes all views from the Activity
RemoveAllViews
Calculates the height of the text in a label or edittext
TextHeight(name As String, text As String) As String
Sets the activity title text in the activity's title label
SetActivityTitle(title As String)
Sets the activity title text color
SetActivityTitleColor(Color As String)
Removes the named view from its parent, but doesn't destroy it.
RemoveFromParent(name As String)
Allow a custom dialog to be presented to the display.
Usage:
InputCustom("name", "title", "positive", "cancel", "negative")
Example:
# first add your panel. It needs a black background
AddPanel("mypanel", 0, 0, pwidth, pheight, "")
SetColor("mypanel", 0, cBlack)
# next, add all the desired views to the panel like this
AddLabel("mylabel", 0, 0, 60 * ScreenScale, 30 * ScreenScale, "mypanel")
SetText("mylabel", "label text")
# now remove the panel from the activity
RemoveFromParent("mypanel")
# now call InputCustom
sel = InputCustom("mypanel", "Yes", "Cancel", "No")
name - the name of the view to display in the dialog, most probably a panel with other views (for a multi-view input dialog).
title - the text in the dialog's title bar.
positive - the text on the positive, or Ok or Yes, button. Leave blank to remove the button.
cancel - the text on the Cancel button. Leave blank to remove the button
negative - the text on the negative, or No, button. Leave blank to remove the button.
Returns a dialog response
InputCustom(name As String, title As String, positive As String, cancel As String, negative As String) As String
Dialog reponse codes:
DialogResponse_Positive
DialogResponse_Cancel
DialogResponse_Negative
IIf is a function that allows a traditional 5 line If statement on one line.
It should not replace an If block that makes tests to ensure an error will not
result. It has 3 parts: a condition, a true part and a false part. The condition
is evaluated, and if it evaluates true, the true part is returned, otherwise
the false part is returned.
Usage:
IIf(condition, truepart, falsepart)
Example:
instead of this...
If a = 5 Then
b = b + 1
Else
b = b - 1
Endif
use this...
b = b + IIf(a = 5, 1, -1)
iif(condition As String, truepart As String, falsepart As String) As String
Returns a string that has had spaces trimmed from the start and end of the passed string
Ex. StrTrim(" 123 ") returns "123"
StrTrim(Str As String) As String
Returns a string that containing the given number of characters from the left hand side of the passed string
Ex. StrLeft("12345", 3) returns "123"
StrLeft(str As String, ct As String) As String
The B4Script SubString statement returns what the traditional basic Mid statement returns.
StrMid emulates the basic Mid statement with the standard Mid$ 3rd argument omitted, by returning the
end part of the passed string, starting at the indicated index. Remember indexes into strings
start at zero.
Ex. StrMid("1234567", 3) returns "4567"
StrMid(str As String, ct As String) As String
Returns a string that contains the given number of characters from the right hand side of the passed string
Ex. StrRight("123456", 2) returns "56"
StrRight(str As String, ct As String) As String
The isNumeric function is safer to use than the B4Script isNumber statement, in that it will not generate
an error if the passed number is blank instead of containing digits, or returning false for fractions
starting with the decimal point instead of an actial numeric digit.
Care MUST be taken, because although isNumeric will return True for a number starting with a decimal point, as in .5,
B4Script cannot use that number without a leading 0 (ie. 0.5) and will cause an error if its omitted.
Example 1:
isNumber("") - generates an error
isNumeric("") - returns false
Example 2:
isNumber(".5") - returns false
isNumeric(".5") - returns true
isNumeric(num As String) As String
Contents
OTHER EVENT FUNCTIONS
These additional Events have been added by B4A user JesseW to compliment the BasicLib library and extend its functionality.
Event Label_Click can now be used in your B4Script.
No errors will be triggered if omitted.
Usage:
Sub Label_Click(who)
-- your label click event code goes here
-- who has the name of the label, as a string, that caused the Click event.
End Sub
Event Panel_Click can now be used in your B4Script.
No errors will be triggered if omitted.
Usage:
Sub Panel_Click(who)
-- your panel click event code goes here
-- who has the name of the panel, as a string, that caused the Click event.
End Sub
Event Edit_FocusChanged can now be used in your B4Script.
No errors will be triggered if omitted.
Usage:
Sub Edit_FocusChanged(who, hasfocus)
-- your edittext focus changed event code goes here
-- who has the name of the edittext, as a string, that caused the FocusChanged event.
-- hasfocus is true if the edittext gained focus, false if it lost focus.
End Sub
EditText_FocusChanged(HasFocus As Boolean)
Contents