B4A Library [Class] Message

My solution to the Msgbox.
This one is modal-like or non-modal so the result is returned either in the calling sub or in a special return sub.
Size, colors and textsize are controlled.
See also http://www.b4x.com/forum/additional...updates/24911-class-getfiles-file-dialog.html and the discussion there.

I'll be glad to have your feedback.

Edit: Updated.
Edit: Orientation changes happen only after dialog is off.
Edit : version 2, added the FreezeOrientation by stevel05 (Thanks !) see here http://www.b4x.com/android/forum/threads/freeze-orientation.41681/
Edit: After finding problems with some devices with the freezing method, I replaced it and attached Message ver 4.
Note: use only after activity_resume is done otherwise it is ignored by the OS.
Edit: Change of method name, version 4.1
 

Attachments

  • msg1.png
    msg1.png
    25.6 KB · Views: 1,205
  • msg2.png
    msg2.png
    23.4 KB · Views: 1,064
  • msg3.png
    msg3.png
    25.3 KB · Views: 981
  • Message4.1.zip
    23.3 KB · Views: 327
Last edited:

Harris

Expert
Licensed User
Longtime User
derez,

I like the message class, and use it. It is adjustable, colorful / useful. My audience needs large text and bold buttons that they can see.

I have found one issue and wish if you can confirm...

Start a messagebox. Then push the power button to make the device sleep (shut off screen). Then. after several minutes, push power back on and restore the app (messagebox). Press OK or Cancel to dismiss Msgbox. Then try any other button or actions of the calling activity.

What I have noticed (more often than not) is that nothing else will respond. Buttons will press - but no event is raised.

If one cycles the power button again, things work as expected.

I wonder if this is a side effect of the do while loop, calling DoEvents?


Thanks
 

derez

Expert
Licensed User
Longtime User
Its the re-init of the object.
Try this (and please tell me if it works for you):
B4X:
Sub Activity_Resume
If mymsg.IsInitialized = False Then
    mymsg.initialize(Me, "mymsg", Colors.black ,Colors.yellow, 24, Colors.White, 20 ,Colors.black, Activity)
End If
End Sub
 

Harris

Expert
Licensed User
Longtime User
Its the re-init of the object.
Try this (and please tell me if it works for you):
B4X:
Sub Activity_Resume
If mymsg.IsInitialized = False Then
    mymsg.initialize(Me, "mymsg", Colors.black ,Colors.yellow, 24, Colors.White, 20 ,Colors.black, Activity)
End If
End Sub

Ok, I shall give a try and follow up.

Thx
 

Harris

Expert
Licensed User
Longtime User
It's better - but not perfect...

The first time I press the power button and restore, all other controls may work...
The second or third time - back to original problem, buttons press but no event sadly...
It is now sporadic.


Is there a way to incorporate a timer rather than hammering on the DoEvents in a loop? I tried, but failed to do so - course I am not as brilliant as you.

For me, it is hard to understand what the issue is since I don't know what is going on under the hood. As a note, I did see some time ago (6 months?) the message - App not responding - force close or wait... But have not seen since.

Same prob on 2.3.3 and 4.4.2

Thanks

My resume below...

B4X:
Sub Activity_Resume
    Tim1.Enabled = True
      If DefCM.GetDevicePhysicalSize < 6 Then
      Activity.SetBackgroundImage(LoadBitmap(File.DirAssets, "bg1.jpg"))
      If MB.IsInitialized = False Then
          MB.Initialize(Me, "MB", Colors.RGB(0, 100, 175), Colors.yellow, 28, Colors.White,  28 , Colors.RGB(51, 153, 255), 100%x, 100%y)
          MB.Set_Button_Font_Size(24)
          MB.SetScale(1.3)
          Activity.AddView(MB.AsView, 0, 0, 100%x, 100%y)
      End If   
    Else
      If MB.IsInitialized = False Then
            MB.Initialize(Me, "MB", Colors.RGB(0, 100, 175), Colors.yellow, 24, Colors.White, 20 , Colors.RGB(51, 153, 255), 100%x, 100%y)
          MB.Set_Button_Font_Size(20)
          MB.SetScale(1.2)
          Activity.AddView(MB.AsView, 0, 0, 100%x, 100%y)
      End If
      If DefCM.rS.Height > DefCM.rS.Width Then   
          Activity.SetBackgroundImage(LoadBitmap(File.DirAssets, "bg1.jpg"))
      Else
          Activity.SetBackgroundImage(LoadBitmap(File.DirAssets, "bgls.jpg"))
      End If
    End If
 

Harris

Expert
Licensed User
Longtime User
For anybody who may be following this thread..

I am sure you may have encountered this:

My audience is generally 40 to 75 years old (truck drivers in North America). I need to modify the tiny text presented as the default MsgBox to something readable (text and buttons) based on device (phone or tablet).

Younger eyes have no problem reading a default (standard) Msgbox, but us older guys struggle - and eventually give up (bad) particularly on a phone (-6) device.

This is an issue when developing apps for the real world - and needs libs and classes like this.

Maybe we could use a small. medium and large text property?

Thank you derez...
 
Last edited:

derez

Expert
Licensed User
Longtime User
Like I said above, it is not because of the do loop but because of re- initialization of the mb object after poweroff and poweron. If the mb is on and you initialize it - the one on display does not react to events anymore.
Try to delete it and init a new one every resume and see how it works.
 

Harris

Expert
Licensed User
Longtime User
Like I said above, it is not because of the do loop but because of re- initialization of the mb object after poweroff and poweron. If the mb is on and you initialize it - the one on display does not react to events anymore.
Try to delete it and init a new one every resume and see how it works.

I'm sorry. I am not familiar with how to delete this object (MB).

Thanks
 

Harris

Expert
Licensed User
Longtime User
MB is in focus when I hit the power off (screen blank) hard button

My log:

** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
---- Removing MB (remove existing MB)
MB wasn't inited < 6 (create new MB)

All works fine above

NOW hit Ok or Cancel on the MB...
Create a new MB dialog on screen and shut down.

Upon power on:

** Activity (main) Pause, UserClosed = false **

Now, nothing on the main form works. Panels or buttons act as selected - yet no event raised.

Power down again....
** Activity (main) Pause, UserClosed = false **
java.lang.NullPointerException

Strangely enough, after power up, it all works again after this error (NullPointerException) ??? (log below)
** Activity (main) Resume **
---- Removing MB
MB wasn't inited < 6


(Note: I had to remove checking (if Init = False) cause even after removing the view, it still thought it was inited and did not create a new MB... (ie. MB wasn't inited < 6 did not show in log and a Msgbox would not show).

My new resume...

B4X:
Sub Activity_Resume
    If MB.IsInitialized = True Then
      MB.AsView.RemoveView
      Log("  ---- Removing MB")
    End If   

    If DefCM.GetDevicePhysicalSize < 6 Then
      Activity.SetBackgroundImage(LoadBitmap(File.DirAssets, "bg1.jpg"))
          MB.Initialize(Me, "MB", Colors.RGB(0, 100, 175), Colors.yellow, 28, Colors.White,  28 , Colors.RGB(51, 153, 255), 100%x, 100%y)
          MB.Set_Button_Font_Size(24)
          MB.SetScale(1.3)
          Log(" MB wasn't inited < 6")
          Activity.AddView(MB.AsView, 0, 0, 100%x, 100%y)
    Else
            MB.Initialize(Me, "MB", Colors.RGB(0, 100, 175), Colors.yellow, 24, Colors.White, 20 , Colors.RGB(51, 153, 255), 100%x, 100%y)
          MB.Set_Button_Font_Size(20)
          MB.SetScale(1.2)
          Activity.AddView(MB.AsView, 0, 0, 100%x, 100%y)
            Log(" MB wasn't inited > 6")

    End If

I have added to the Public Sub Show(.. keepalive and partialLock...
B4X:
If ModalMsg Then
        Phonews.PartialLock
        Phonews.KeepAlive(False)
        If AW > AH Then
            Phone.SetScreenOrientation(0)
        Else
            Phone.SetScreenOrientation(1)
        End If
        result = 0
        Do While result = 0
            DoEvents
        Loop
        Phone.SetScreenOrientation( - 1)
        Phonews.ReleaseKeepAlive
        Phonews.ReleasePartialLock
       
        Return result
    Else
    End If




Do you see something different in your tests?


Thanks
 
Last edited:

Harris

Expert
Licensed User
Longtime User
I know; what are the chances that someone will press the power off button while in a MB? (the only time this issue occurs). It is quite easy to do if you slip your phone into your pants pocket (like I have done) and it contacts the power off button (how I actually discovered this problem).

This is a strange problem and hopefully someone has encountered this to provide some insight.

Thanks for your effort.
 

derez

Expert
Licensed User
Longtime User
Sorry to say but the Freeze orientation works on some devices while in others it rotates the screen instead of freezing it. So if you encounter problems - remove it from Show method (remove FreezeOrientation)
 

derez

Expert
Licensed User
Longtime User
Message ver 4 solves the freezing effect better, see first post.
 

padvou

Active Member
Licensed User
Longtime User
Hello,
I downloaded the project but when I try to compile it, it gives an error message
upload_2017-2-15_12-15-34.png
 

derez

Expert
Licensed User
Longtime User
The error comes from the name of a method which I called "set_type". In the menu that opens when you add dot to the object name it is written as "_type" and if you add it like this it creates this error.
The problem is that methods that have set and get in their names are changed to the name without the words set or get (set-get pair).
to overcome the problem I changed the method to this:
B4X:
'If True - will not use the return sub in the main activity, but return the call from  "Show" .
Public Sub modal(modalType As Boolean)
ModalMsg = modalType
End Sub
The new version 4.1 is attached at post 1.
 
Top