Version | Anpassungen |
---|---|
1.0 (2020-02-29 | Initial version |
2.0 (2020-08-18) | - Renamed to UrsAI2Util - Method MoveTaskToBackground added - Method SimulateHomeKey added - Event OnDestroy removed, raising of events in Form.onDestroy is not supported |
2.1 (2020-10-27) | Method FileListFromAssets added. |
2.2 (2020-12-31) | Methods GetTextWidth, SetX,
SetY, ScreenWidth,
ScreenHeight added. This allows horizontal scrolling to be implemented using a slider. |
2.3 (2023-06-15) | Method SetHypertext added. |
2.4 (2023-08-12) | Methods for logging added. |
3.0 (2023-12-19 | SetX and SetY methods expect values
in DIP (previously in pixels). All visible components can be moved. Methods getY, getY, SetPadding, GetPaddingLeft, GetPaddingTop, GetPaddingRight, GetPaddingBottom, SetBorder added. Properties ScreenDensity, ScreenWidthDIP, ScreenHeightDIP added. |
3.1 (2024-03-24) | FinishAndRemoveTask added |
Events onPause, onStop, onResume
Functions for manipulating visible components
Hypertext for Label, Button and CheckBox
The ZIP archive UrsAI2Utils for downloading. The archive contains the source code and the compiled binary and a sample project to upload to the App Inventor.
The following graphic shows the life cycle of an Android Activity.
For some applications it can be interesting to know the state of the app. The extension provides events that are triggered when the state changes. Unfortunately, only four of these changes can be accessed via the App Inventor Framework. onCreate is already implemented in the screen component as Initialize. onPause, onStop, onResume are provided by this extension.
Block | Funktion |
---|---|
The Initialize event is run when the Screen starts and is only run once per screen. | |
The app is (partially) covered. User input is not accepted.1) | |
The app is moved to the background. | |
The app becomes visible and accepts user input. |
1) In all my attempts at these events, onStop was always triggered after onPause.
This function should make debugging easier. Especially for data exchange purposes it can be interesting to know what the internal representation of a String is. Usually it is UTF-8 coded.
Block | Funktion |
---|---|
The string in the argument Text is converted to a string that contains the hexadecimal representation of the individual characters. e.g. "abcß" becomes "61 62 63 C3 9F". |
Byte arrays can be transferred with the MQTT extension, e.g. this may be JPEG images. The method converts the received byte array into a bitmap object and displays it on an App Inventor Image component. This method should not be confused with the Picture property of the component! Picture expects the file path to an image file.
Block | Funktion |
---|---|
JPEG: Byte array that contains a JPEG image. ImageBlock: A component of the type Image on which the image is to be displayed. Rotation: Rotation angle. |
A typical use of the block could look like this:
The text formatting options in App Inventor always refer to the entire component. For example, highlighting a single word is not possible in the standard.
The SetHypertext method allows text to be provided with HTML tags and thus to design the text individually. Which HTML tags can be used varies depending on the implementation of the Android system. There are hints at Mark Murphy's Technical Stuff or Daniel Lew's Coding Thoughts. The following example shows the usage:
The entries for Button1, Label1 und CheckBox1 for
"The <b>quick <i>brown <strike>fox <u>jumps <font
color="red">over</font></u></strike><i></b> the <font face='cursive'>lazy dog</font>"
and for Label2
"Normal<br/>
<font
face='sans-serif'>sans-serif</font><br/>
<font face='sans-serif-thin'>sans-serif-thin</font><br/>
<font
face='sans-serif-light'>sans-serif-light</font><br/>
<font
face='sans-serif-medium'>sans-serif-medium</font><br/>
<font
face='sans-serif-black'>sans-serif-black</font><br/>
<font
face='sans-serif-condensed'>sans-serif-condensed</font><br/>
<font
face='sans-serif-condensed-light'>sans-serif-condensed-light</font><br/>
<font
face='serif'>serif</font><br/>
<font face='monospace'>monospace</font><br/>
<font
face='serif-monospace'>serif-monospace</font><br/>
<font face='casual'>casual</font><br/>
<font
face='cursive'>cursive</font><br/>
<font face='sans-serif-smallcaps'>sans-serif-smallcaps</font>"
The Android Debug Bridge (adb) allows a log to be displayed, e.g. on a connected PC. These functions can be used to write to the Android-Log.
Block | Funktion |
---|---|
Moves the app to the background. | |
Simulates pressing the home button. | |
Returns a list of the asset file names with the specified extension. "*" return all. |
The text in a TextBox is moved horizontally using a slider.
Actually, it just looks like it. The length of the text is determined and the width of the text box is set to this value. The TextBox can now display the entire text and is therefore wider than the embedding container (the screen in the example). The entire TextBox is now moved based on the slider position. The text parts that are outside of the container are then not visible. Overall, it looks as if the text has been moved.
For developing own extensions I gathered some tips: AI2 FAQ: Develop Extensions.