Android Code Snippet FilePicker

I made my own FilePicker (see Attached)

I wanted it to work like FileDialog (not sure how it completely works)

B4X:
           ret = fd.Show("Pick Database to restore", "Restore", "Cancel", "", Null)

I didn't want the CallBacks so I used wait for

My FilePicker
B4X:
    wait for (FilePicker.CreateScreen(File.Combine(File.DirRootExternal, "Download"), "*.db", "", "Pick a database to restore", "", "Restore")) complete (Result As cTFilePickerResult)
 
   Log("Result Completed:" &Result.Completed &"  IsValid:" &Result.IsValid &"   Result:" &Result.FullFileName)

I wanted the program to be standalone so you didn't need to include any other code so I embedded some of Don Manfred's WildCardList program (gave him credit of course) so that the program was just a single basic Class Module.

One problem I had was if I try to add it to my library of other functions I get a Typeface error when using it I believe this is because I am using Typeface.FONTAWESOME in the code and this is not carrying forward into the library (I know I saw a post on this but haven't been able to find it).

In any case it works find as an Included Module

Enjoy

BobVal

NOTE: Zip file contains a working Example should just compile and run


NOTE: Found a bug in OPC fixed Sept/2/2018 7:18 EST
 

Attachments

  • Screenshot_20180902-183501.jpg
    Screenshot_20180902-183501.jpg
    34.6 KB · Views: 664
  • Screenshot_20180902-183716.jpg
    Screenshot_20180902-183716.jpg
    115.7 KB · Views: 736
  • Screenshot_20180902-183734.jpg
    Screenshot_20180902-183734.jpg
    97.6 KB · Views: 703
  • FilePicker.zip
    15.1 KB · Views: 373
Last edited:

JohnC

Expert
Licensed User
Can you post a sample screen shot of how it looks?
 

JohnC

Expert
Licensed User
Nice - thanks for the contribution!
 

Robert Valentino

Well-Known Member
Licensed User
I uploaded FilePicker and made a few changes.

What I found is if the App is Paused that the wait I was waiting on gets lost?

B4X:
Logger connected to: b6ea4342
--------- beginning of /dev/log/main
--------- beginning of /dev/log/system
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
Sleep not resumed (context is paused): com.BOBs.FilePicker.cfilepicker$ResumableSub_ShowFiles
** Activity (main) Resume **

So I added code in the Calling Routine to check if it was showing/waiting and cancel it

If we resume and we were waiting for FilePicker then End it (stop showing the screen because wait was terminated)

If I didn't do the below then the screen from FilePicker would be showing but if could not return any data.

I've added routines so you can rewait if you want

Mixed bag here. If the user left the App to see what file they needed to select and came back then they would have to go through finding the file again

B4X:
Sub Activity_Resume
    If  mFilePicker.IsShowing    Then
       If  mEndOrReWait Then
           Log("Ending FilePicker")
           
           mFilePicker.EndShowing(True)           
       Else
           Log("ReWaiting FilePicker")
           
           CallSubDelayed(Me, "FilePicker_Wait")
       End If
       
       mEndOrReWait = Not(mEndOrReWait)
   End If

End Sub


If the user presses the Back key and FilePicker was showing the End the FilePicker wait

B4X:
Sub Activity_KeyPress(KeyCode As Int) As Boolean
    If  KeyCode = KeyCodes.KEYCODE_BACK Then
       If  mFilePicker.IsShowing    Then
           mFilePicker.EndShowing(False)
           Return True
       End If
   Return False
End Sub
 
Top