Englisch version   Deutsche Version


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.

Content

Download

Usage

Events onPause, onStop,onResume

StringToHex

Image-Import

Other functions

Properties

Functions

Slider example

Tools

Download

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.

Usage

The extension provides functions for three functional areas.

Events onPause, onStop, onResume

The following graphic shows the life cycle of an Android Activity.

State diagram for an Android Activity Lifecycle.

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
Initialize The Initialize event is run when the Screen starts and is only run once per screen.
onPause The app is (partially) covered. User input is not accepted.1)
onStio The app is moved to the background.
onResume The app becomes visible and accepts user input.

1) In all my attempts at these events, onStop was always triggered after onPause.


StringToHex

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
ConvertToHexString 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".
 

Image-Import

Mit der MQTT-Extension lassen sich Byte-Arrays übertragen, dies können z.B. auch JPEG-Images sein. Die Methode konvertiert das Empfange Byte-Array in ein Bitmap-Objekt und zeigt es auf einem im App Inventor enthaltenen Komponente Image an. Diese Methode darf nicht mit der Eigenschaft Picture der Komponente verwechselt werden! Picture erwartet den Dateipfad auf eine Image-Datei.

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
Image-Import 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:

Verwendung JPEGtoImageBlock


Other functions

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.

Properties

ScreenWidth
Gets the width of the screen in pixels.
ScreenHeight
Gets the height of the screen in pixels..
Version
Gest the version of the extension.
VersionSDK
The API level of the currently running Android instance.

Functions

SetX(Component , X)
Specifies the left position of a text box or label. X can be negative.
SetY(Component , Y)
Specifies the top position of a text box or label. Y can be negative.
GetTextWidth(Component )
Gets the length of the text in a text box.

Slider example

Slider Beispiel

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.

Die Blöcke zum Slider-Beispiel

Tools

For developing own extensions I gathered some tips: AI2 FAQ: Develop Extensions.