B4i Library iHUD library - Toast messages and progress dialogs

This library is based on the following open source project: https://github.com/matej/MBProgressHUD
License: https://github.com/matej/MBProgressHUD/blob/master/LICENSE

It includes two features available in B4A: Toast messages and progress dialogs.

Using this library is very simple.
Declare a process global variable:
B4X:
Private hd As HUD

Show a toast message:
B4X:
hd.ToastMessageShow("Some message", True) 'second parameter is LongDuration
Unlike in Android the toast message appears in the middle of the screen.

Show a progress dialog (that disables user interaction):
B4X:
hd.ProgressDialogShow("Downloading...")
Later you should call hd.ProgressDialogHide. Note that there is no DoEvents method in B4i. You should instead use asynchronous method for long tasks (when such are available).

SS-2014-10-26_17.05.14.png


Library installation:
- Download the zip file, unzip it and copy the xml file to the libraries folder.
 

Attachments

  • iHUD.zip
    606 bytes · Views: 741

JanPRO

Well-Known Member
Licensed User
Longtime User
Hi,

Yes:
B4X:
'Example:
hd.ToastMessageShow("Have a nice day :)", True)
CustomizeHud(Font.CreateNew(30),Colors.Red,Colors.Green)

Sub CustomizeHud (aFont As Object, TextColor As Int, BackgroundColor As Int)
    Dim no1 As NativeObject = App.KeyController
    no1 = no1.GetField("view")
    Dim no2 As NativeObject
    Dim hud As NativeObject = no2.Initialize("MMBProgressHUD").RunMethod("HUDForView:", Array(no1))
    If hud.IsInitialized Then
        hud.SetField("color",hud.ColorToUIColor(BackgroundColor))
        hud.SetField("labelColor",hud.ColorToUIColor(TextColor))
        hud.SetField("labelFont",aFont)
    End If
End Sub

Jan
 

MikeH

Well-Known Member
Licensed User
Longtime User
Hi Jan,

Thank you for this code. Is it possible to change the colour of the indicator?

1669731131843.png

I'd like it to be the same colour as the text

Thanks again :)
 
Last edited:

Alessandro71

Well-Known Member
Licensed User
Longtime User
Last time I checked, BCToast was not able to show a Toast Message from a running Android service, which is the reason I still use native ToastMessage
 

MikeH

Well-Known Member
Licensed User
Longtime User
Which indicator? Why not use BCToast which is cross platform and easier to customize?
This round swirly thing:
1669810080358.png

I've tried the B4XProgress view and may go with that and also I'll look at BCToast, thank you. I just want a progress indicator to show the phone hasnt frozen. Ideally, Id like an actual progress indicator like this I did for iOS but couldnt get it working in Android:
progressBar.gif

I've thought of a way to do it though. Thats my next task.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Example of a custom progress indicator using B4XDialog + B4XActivityIndicator
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    ProgressDialog.Initialize(Root)
    ProgressDialog.OverlayColor = xui.Color_Transparent
    ProgressDialog.BorderWidth = 0
    ProgressDialog.BackgroundColor = xui.Color_Transparent
    ProgressDialog.ButtonsHeight = 0
End Sub


Private Sub Button1_Click
    Dim pnl As B4XView = xui.CreatePanel("")
    pnl.SetLayoutAnimated(0, 0, 0, 100dip, 100dip)
    pnl.LoadLayout("ProgressDialog")
    ProgressDialog.ShowCustom(pnl, "", "", "")
    Sleep(5000)
    ProgressDialog.Close(xui.DialogResponse_Cancel)
End Sub
It is completely customizable.
The animation is very smooth in release mode.
 

Attachments

  • Project.zip
    176.1 KB · Views: 18
Top