B4A Library FileSelect Library With Type Icons

Attached is Version 1.02 of my File Selecting library. It includes type icons for most every type of file, creates a selection list which can be collected and produces thumbnails on the fly of image files. Copy the .jar and .xml file to your XtraLibs folder.

Requires: Reflections Library 2.4+, the Reflection lib does not need to be checked in the Libs tab but must be included in your XtraLibs folder or whatever path you have set for them.

Thanks to Stevel05 it moves more swiftly throughout!

Below are a few screen shots and some sample code.

B4X:
Sub Globals
    Dim FS As FileSelect
    FS.Initialize(Activity, Me, True, 0dip, 0dip, 500dip, 600dip)
End Sub
Sub Activity_Create(FirstTime As Boolean)
    FS.ShowFiles("/mnt")
End Sub
 
'Be sure to include this sub in your Activity. This sub
'is called by the Library once a file is selected.
Sub File_Selected(FileName As String, PathAndFile As String)
    Msgbox(FileName, PathAndFile)
End Sub
 

Attachments

  • FileSelect Ver. 1.02.zip
    193.5 KB · Views: 1,114
  • fs1.png
    fs1.png
    124.4 KB · Views: 1,196
  • fs2.png
    fs2.png
    37.5 KB · Views: 982
Last edited:

stevel05

Expert
Licensed User
Longtime User
Can you check the unfiltered logs
 

merlin2049er

Well-Known Member
Licensed User
Longtime User
Nothing appears in my unfiltered logs.

B4X:
Sub File_Selected(FileName As String, PathAndFile As String)

If rename.Checked = True Then
    CancelPaste_off

Dim db As BetterDialogs
  Dim sf As StringFunctions
 
  Dim length As Long
  sf.Initialize
 
  length = sf.Len (PathAndFile ) - sf.Len (FileName) -1

    Dim input As BD_InputBoxParams
    input.Initialize
    input.InputType = input.INPUT_TYPE_TEXT
    input.Default = FileName

    Dim result As Int
    Dim PathOnly As String
    ToastMessageShow(PathAndFile, True )
    Log(PathAndFile)
   
    PathOnly = sf.Left (PathAndFile, length)
    currentpath = PathOnly
   

    result = db.InputBox("Rename File ",input, "Rename","Cancel","",Null)
If result = DialogResponse.POSITIVE Then
    ToastMessageShow("File Renamed", True)
   
    ' rename here... need path only
   
    RenameFile(PathAndFile & "" ,  PathOnly & input.Answer )
End If
FS.Invalidate_FilesList    'Causes the view to reload and redraw
End If


If Copy.Checked = True Then
    CancelPaste_on
    ToastMessageShow("File copied to clipboard", True)
    ' need to store file and path
   
    FS.Invalidate_FilesList    'Causes the view to reload and redraw
   
End If

If  Cut.checked = True Then
    CancelPaste_on
    ToastMessageShow("File cut to clipboard", True)   
    ' need to store file and path
   
    FS.Invalidate_FilesList    'Causes the view to reload and redraw
   
End If


If Delete.Checked = True Then
    CancelPaste_off

   
    Dim db As BetterDialogs
   
    Dim result As Int

        result = db.Msgbox("Delete File?",FileName,"Delete","Cancel","",Null)
        If result = DialogResponse.POSITIVE Then
       
            If File.Delete(FS.SelectionPath , FileName) = True Then
                ToastMessageShow("File " & FileName & " Deleted", True)
            Else
                ToastMessageShow("Something strange happened...", True)
            End If
           
   
      FS.Invalidate_FilesList    'Causes the view to reload and redraw
      'FS.RemoveView '<- Use this command if you wish to remove/close the selector after a Long Click

   
        End If
End If
'FS.ShowFiles(currentpath)

End Sub
 

stevel05

Expert
Licensed User
Longtime User
There's nothing obvious in the code, which option does it fail on? Can you post an example project that fails?
 

merlin2049er

Well-Known Member
Licensed User
Longtime User
It fails to refresh on all my radio button options: Cut, Copy, Delete, Rename.

What I'd like to happen is, when I single click on a file, it checks the radio buttons - sees what's checked to preform that action (then refresh the contents).
 

stevel05

Expert
Licensed User
Longtime User
Without being able to test it it's difficult to suggest where it is going wrong. Are the actions performed before the app crashes?
 

merlin2049er

Well-Known Member
Licensed User
Longtime User
It doesn't crash, last thing that happens is the toast message pops up and then the fs goes blank.
 

stevel05

Expert
Licensed User
Longtime User
See Margret's Answer to your post #11
 

stevel05

Expert
Licensed User
Longtime User
I recreated your app so I could test it and Uncommenting FS.ShowFiles(currentpath) works. but in addition you have errors in the Rename and Delete functions (I cant test the cut and paste as I don't have your code for that).

You are missing a "/" in the rename file command target parameter. And FS.SelectedPath returns the whole path and filename used in the delete routine. Also you ned to maintain the selected path for both, I suggest you do it before any processing something like this:

B4X:
Sub File_Selected(FileName As String, PathAndFile As String)

    Dim sf As StringFunctions
   
    Dim length As Long
    sf.Initialize
   
    length = sf.Len (PathAndFile ) - sf.Len (FileName) -1
 
    Dim PathOnly As String
    ToastMessageShow(PathAndFile, True )
    Log(PathAndFile)
   
    PathOnly = sf.Left (PathAndFile, length)
    currentpath = PathOnly

If Rename.Checked = True Then
'    CancelPaste_off

    Dim input As BD_InputBoxParams
    input.Initialize
    input.InputType = input.INPUT_TYPE_TEXT
    input.Default = FileName

    Dim db As BetterDialogs
    Dim result As Int
   

    result = db.InputBox("Rename File ",input, "Rename","Cancel","",Null)
If result = DialogResponse.POSITIVE Then
    ToastMessageShow("File Renamed", True)
 
    ' rename here... need path only
 
    FS.RenameFile(PathAndFile & "" ,  PathOnly & "/" & input.Answer )
End If
FS.Invalidate_FilesList    'Causes the view to reload and redraw
End If


If Copy.Checked = True Then
'    CancelPaste_on
    ToastMessageShow("File copied to clipboard", True)
    ' need to store file and path
 
    FS.Invalidate_FilesList    'Causes the view to reload and redraw
 
End If

If  Cut.checked = True Then
'    CancelPaste_on
    ToastMessageShow("File cut to clipboard", True) 
    ' need to store file and path
 
    FS.Invalidate_FilesList    'Causes the view to reload and redraw
 
End If


If Delete.Checked = True Then
'    CancelPaste_off

 
    Dim db As BetterDialogs
 
    Dim result As Int

        result = db.Msgbox("Delete File?",FileName,"Delete","Cancel","",Null)
        If result = DialogResponse.POSITIVE Then
            If File.Delete(PathOnly , FileName) = True Then
                ToastMessageShow("File " & FileName & " Deleted", True)
            Else
                ToastMessageShow("Something strange happened...", True)
            End If
         
 
      FS.Invalidate_FilesList    'Causes the view to reload and redraw
      'FS.RemoveView '<- Use this command if you wish to remove/close the selector after a Long Click

 
        End If
End If
FS.ShowFiles(currentpath)

End Sub
 

merlin2049er

Well-Known Member
Licensed User
Longtime User
Right, I didn't get around to finishing the code. But with, Fs.showfiles(currentpath) your going to loose the ability to navigate because that becomes the root now. It was suggested to use FS.Invalidate_FilesList to refresh my files.
 

stevel05

Expert
Licensed User
Longtime User
Are your radiobuttons visible at the same time as the file selector? You could add an up button.
 

stevel05

Expert
Licensed User
Longtime User
I can see your problem now, you may have to add the button until Margret can look at it.
 

merlin2049er

Well-Known Member
Licensed User
Longtime User
How about mounting the file system again FS.ShowFiles("/mnt") and bringing up the current folder?
 

stevel05

Expert
Licensed User
Longtime User
Can you auto navigate? I think it needs a screen touch to make a selection.
 

jparkerri

Member
Licensed User
Longtime User
I think if you create a folder named [ftypes] in the [Files] folder and put the icons there, you can then change them. Here is a list of what the names should be:
I like your library. I think I'm not doing something right though. When I initialize the FS to a folder with only 5 small files in it, it takes up to 30 secs to display. SHould it take this long? Thanks.
 

merlin2049er

Well-Known Member
Licensed User
Longtime User
I like your library. I think I'm not doing something right though. When I initialize the FS to a folder with only 5 small files in it, it takes up to 30 secs to display. SHould it take this long? Thanks.

I've noticed that it takes a while. :)
 

margret

Well-Known Member
Licensed User
Longtime User
OK, this may work better for what you are trying to do. I added three new vars you can access from any sub with information about the last LongClick event. See the code sample below and the new lib is attached. As to the speed issue, the files on my devices come up right away, unless they are large .jpg files that it is generating thumbnail images for.

B4X:
'This sub is called by the Library once a file is Long Clicked
Sub File_Selected_LongClick(PathWithFileName As String, IsDirectory As Boolean)
    'This is just a sample, you can have a panel, etc.
    'Then do the rename, delete, etc. in another sub.
    Edit1.Visible = True
    Edit1.BringToFront
    Edit1.RequestFocus
End Sub
Sub Edit1_EnterPressed
    'Three new variables added to use under the Long Click event;
    'FS.LongClick_IsDir, FS.LongClickSelection, FS.PathOnly
    If Not(FS.LongClick_IsDir) Then
        FS.RenameFile(FS.LongClickSelection, FS.PathOnly & "/" & Edit1.Text.Trim)
        FS.Invalidate_FilesList    'Causes the view to reload and redraw
    Else
        'Do whatever is needed for the Directory
        File.MakeDir(FS.LongClickSelection, Edit1.Text.Trim)
    End If   
End Sub
 

Attachments

  • FileSelect Ver. 1.03.zip
    194.6 KB · Views: 263

merlin2049er

Well-Known Member
Licensed User
Longtime User
Great, thanks. I'm not sure how to handle the disappearing fs screen after single clicking a file? I tried refreshing, but the display is gone so that doesn't seem to matter.
 

margret

Well-Known Member
Licensed User
Longtime User
I need the FS to close on single clicks for my use. Once you said what you wanted to do, I changed it and added the longclick for your use. You have said in a previous post, you wanted to copy, delete, etc. on a longclick. What are you doing now with the click? The click is for selection and the longclick is for manipulation of the longclicked item.
 
Top