Android Code Snippet FilePicker

Discussion in 'Code Snippets' started by Robert Valentino, Sep 2, 2018.

  1. Robert Valentino

    Robert Valentino Well-Known Member Licensed User

    I made my own FilePicker (see Attached)

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

    Code:
    ret = fd.Show("Pick Database to restore""Restore""Cancel"""Null)
    I didn't want the CallBacks so I used wait for

    My FilePicker
    Code:
    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
     

    Attached Files:

    Last edited: Sep 3, 2018
    hatzisn, Levit, Pencil3 and 4 others like this.
  2. JohnC

    JohnC Well-Known Member Licensed User

    Can you post a sample screen shot of how it looks?
     
  3. Robert Valentino

    Robert Valentino Well-Known Member Licensed User

  4. JohnC

    JohnC Well-Known Member Licensed User

    Nice - thanks for the contribution!
     
  5. Robert Valentino

    Robert Valentino Well-Known Member Licensed User

    Oops found a bug in the GetDirs code Fixed
     
    Claudio Oliveira likes this.
  6. Robert Valentino

    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?

    Code:
    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

    Code:
    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

    Code:
    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
     
  7. Harris

    Harris Well-Known Member Licensed User

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice