B4A Library [Class] DEDialogs

[Class] DEDialogs - Files and input dialogs

The attached class is an addition to the already many solutions to such dialog.
This one has the following features:
1. It is modal-like, so the result is returned to the same sub that launched the request . Events are limited to the dialog events.
2. Flexibility in the appearance - size, colors, textsize.
3. Length is adjusted to the number of files.
4. A single filter or a list of filters.
5. Enable or disable browsing from the pre-defind directory.
6. Single or multiple files selection (returned as a string or a list)
7. File name can be returned with or without the full path.

Explanation and question:
the 1 feature is achieved by using this piece of code in the "show" sub:
B4X:
result = 0
Do While result = 0
   DoEvents
Loop
If result = DialogResponse.POSITIVE Then
   Return ret
Else
   Return DialogResponse.CANCEL
End If
The loop is waiting for the buttons click events and then return the result.
I found that the doevent allows click events but not events like keyboard keying or list_ItemClick of a listview - they are just ignored. While doing the message class [Class] Message I found that if a dialog like this is launched by activity_keypress, it doesn't work also. I have read what Agraham wrote in his Dialog library but understood only partly and whould like to get better understanding.

Anyway - this class works, I'll be glad to have feedback.

Edit: some improvements , better look.
Edit: Orientation change is not performed while the dialog is on !

Edit:
Class name was changed to DEDialogs as the following methods were included:
- GetSingleFile - to select an existing file
- GetSeveralFiles - to select several files to a list
- SetFileName - to create a new file or select an existing file
- GetInput - to get input from the user
- SetSort - to define type and direction of sorting the list
Edit: ver updated to 1.1 :
- added SetButtomsText - to change the text of "Ok" and "Cancel" from default
- added parameter of header text in SetInput.
Edit: ver 1.2 better adaptation to various screen sizes.
Edit: ver 1.3 added sort by date using this http://www.b4x.com/android/forum/threads/sorting-of-filelist.18337/#post-108770 and added method SetSort to define type and direction of sorting the list.
A bug in input ET color was fixed.

Edit: ver 1.4 includes correction for item line height in tablets.
Edit: ver 1.5 compatible with b4a ver. 7 (wait for)
 

Attachments

  • ded1.png
    ded1.png
    29.2 KB · Views: 1,318
  • ded2.png
    ded2.png
    31.2 KB · Views: 1,111
  • ded3.png
    ded3.png
    23.2 KB · Views: 1,075
  • DEDialogs1.4.zip
    12.3 KB · Views: 349
  • DeDialogs1.5.zip
    12.4 KB · Views: 294
Last edited:

thedesolatesoul

Expert
Licensed User
Longtime User
Hi David,
I havent tested your class but I have some comments.
The Do...While loop isnt ideal because it keeps your UI Thread busy. Very few events can be raised during this time as you noticed.
The major problem with this approach (for me) is in rotation/orientation change. The activity layout is not allowed to refresh, thus you are left with a portait layout in a landscape mode.
 

derez

Expert
Licensed User
Longtime User
The activity layout is not allowed to refresh, thus you are left with a portait layout in a landscape mode..
Actually, the activity layout is refreshed but if the message is on it does not refresh, so it is displayed sideways instead of in the center.
The main advantage, and for me it overcomes the disadvantages, is the immediate use of the result in the calling sub.
 

Attachments

  • getfile4.png
    getfile4.png
    24.7 KB · Views: 426
Last edited:

thedesolatesoul

Expert
Licensed User
Longtime User
Actually, the activity layout is refreshed but if the message is on it does not refresh, so it is displayed sideways instead of in the center.
The main advantage, and for me it overcomes the disadvantages, is the immediate use of the result in the calling sub.
I had the same thought. But most users (especially tablet) will not like to be stuck to portrait. Usually the problem only happens when you rotate in mid-operation which may be rare, but gives the impression that the app isnt professional enough.
Also, the activity layout does not refresh, try to make the button width to 100%x and see.
I had to break my subroutines into two, just for this reason to avoid modal dialogs. Sometimes we have to think what is best for the user not for the programmer.
 

derez

Expert
Licensed User
Longtime User
I added this to the show methods:
B4X:
If AW>AH Then Phone.SetScreenOrientation(0) Else Phone.SetScreenOrientation(1)
...
[the loop]
...
Phone.SetScreenOrientation(-1)

So orientation change does not happen until the dialog is off.
Updated at the first post.
 
Last edited:

derez

Expert
Licensed User
Longtime User
You have to use the SetOnKeyListener method of the Reflection library to declare your keyboard handler.

I try to do it but it is probably wrong: in initialize I added
B4X:
r.Target = inputet
r.SetOnKeyListener("Key_input")
and a sub
B4X:
Sub Key_input(ViewTag As Object, KeyCode As Int, KeyEvent As Object) As Boolean
Log(KeyCode)
Return True
End Sub

But typing the keyboard when the edittext has focus is not sensed as an event and the text is not inserted.
Can you show me how to do it if this is wrong ?
 

Informatix

Expert
Licensed User
Longtime User
I try to do it but it is probably wrong: in initialize I added
B4X:
r.Target = inputet
r.SetOnKeyListener("Key_input")
and a sub
B4X:
Sub Key_input(ViewTag As Object, KeyCode As Int, KeyEvent As Object) As Boolean
Log(KeyCode)
Return True
End Sub

But typing the keyboard when the edittext has focus is not sensed as an event and the text is not inserted.
Can you show me how to do it if this is wrong ?

That should work, so I don't know what to say if that does not work. I use that myself in my File Explorer class.
You have to be sure that the EditText keeps the focus. Maybe it loses it when you start typing. That's why I added in my code:
r.SetOnFocusListener("dlg_HasFocus")

Private Sub dlg_HasFocus(ViewTag As Object, HasFocus As Boolean)
If Not(HasFocus) Then edtFilename.RequestFocus
End Sub
 

derez

Expert
Licensed User
Longtime User
Thank you Informatix but it doesn't work.
As I said above - only click events are sensed while the loop is on by doevents.
Even an ItemClick of a listview was ignored so I changed it to scrollview with labels.
 

Informatix

Expert
Licensed User
Longtime User
Thank you Informatix but it doesn't work.
As I said above - only click events are sensed while the loop is on by doevents.
Even an ItemClick of a listview was ignored so I changed it to scrollview with labels.

It's normal for the ListView. But it's not for an EditText if you handle the keys with your own handler. As my class proves it, that works (with any Android version). You probably do something that prevents it from working but I'm too busy to look at your code.
 
Last edited:

derez

Expert
Licensed User
Longtime User
Well, after rechecking I have found that the listener works, but I get only the arrow keys (keycodes 19-23), not letters.
How do I get the letters ?

Edit: It works - but not on the emulator ... on the device everything works, all the keys are accepted and displayed :sign0060: (even without the reflector listener)
 
Last edited:

derez

Expert
Licensed User
Longtime User
New Class

Class name was changed to DEDialogs as the following methods were included:
- GetsingleFile - to select an existing file
- GetSeveralFiles - to select several files to a list
- SetFileName - to create a new file or select an existing file
- GetInput - to get input from the user

Updated in the first post.

Erel - can the thread name be changed as well ?
 
Last edited:
Top