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,030
  • fs1.png
    fs1.png
    124.4 KB · Views: 1,115
  • fs2.png
    fs2.png
    37.5 KB · Views: 918
Last edited:

merlin2049er

Well-Known Member
Licensed User
Longtime User
I wanted to create my own buttons for some commands on that blue bar. It's ok, I'll use another panel for some basic functions.
 

merlin2049er

Well-Known Member
Licensed User
Longtime User
Here's my code for renaming files on a single click...

B4X:
Sub File_Selected(FileName As String, PathAndFile As String)
  Dim db As BetterDialogs

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

    Dim result As Int
    Dim PathOnly As String
    PathOnly = PathAndFile.SubString2(0, PathAndFile.LastIndexOf("/"))
   
   
   

    result = db.InputBox("Rename File",input, "Rename","Cancel","",Null)
If result = DialogResponse.POSITIVE Then
    ToastMessageShow("File / Folder Renamed", True)
   
    ' rename here... need path only
   
    RenameFile(PathAndFile & "" ,  PathOnly & input.Answer )
   
   
End If

FS.ShowFiles(PathOnly)

End Sub

It renames the file ok, but pathonly is not returning the path - it's returning the path+ filename.

Then I loose my up arrow, and can't navigate between folders.

Any suggestions?
 

merlin2049er

Well-Known Member
Licensed User
Longtime User
Ok, it still returned the whole path+filename. What I did was use the string function library and subtracted the length of the filename from the length of the path + filename and (-1 for the "/"). Then used sf.left...

B4X:
Sub File_Selected(FileName As String, PathAndFile As String)
  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 )' i tried lastindex of too ' i know
    Log(PathAndFile)
    'PathOnly = PathAndFile.SubString2(0, PathAndFile.lastIndexOf("/"))
    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.ShowFiles(currentpath)

End Sub

It works! Only issue I'm having is when I use FS.ShowFiles(currentpath), it looses the uparrow and cant navigate (I guess it thinks the current path is the root?)

The other thing is , I need to keep track of the path at all times. I've got a MKDIR button, but don't know how to refer to the current path I'm in.

Any suggestions?
 

merlin2049er

Well-Known Member
Licensed User
Longtime User
ok, thanks. I think I need permission in the manifest to write (or create folders) ?
 

merlin2049er

Well-Known Member
Licensed User
Longtime User
I can't seem to pick up the last navigated folder to. I'm using fs.selectionpath but it returns null.

B4X:
Sub MKDIR_Click

'' need to get last known folder
'

Dim db As BetterDialogs

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


Dim result As Int

result = db.InputBox("Create Folder",input, "Create","Cancel","",Null)
If result = DialogResponse.POSITIVE Then
   
    If input.Answer <> ""  Then
        File.MakeDir(FS.SelectionPath, input.Answer)
        ' Log(FS.SelectionPath & "  " & input.Answer )
        ToastMessageShow("Folder Created", True)
    Else
        ToastMessageShow("Please enter a Folder name ", True)
    End If
   
End If

   
End Sub
 

margret

Well-Known Member
Licensed User
Longtime User
This sub works for me for files and Folders, maybe you can change it to fit your needs.

B4X:
'This sub is called by the Library once a file is Long Clicked
Sub File_Selected_LongClick(PathWithFileName As String, IsFolder As Boolean)
    If Not(IsFolder) Then    'It's not a folder it's just a file
        'Rename the file, it will log the results and will only rename if a
        'file of the same name does not already exist.
        FS.RenameFile(PathWithFileName, FS.PathOnly & "/yournamehere.jpg")
        FS.Invalidate_FilesList    'Causes the view to reload and redraw
    Else
        'It is a Folder, do whatever is needed for the Folder
        File.MakeDir(PathWithFileName, "MyMusic")
    End If   
End Sub
 

merlin2049er

Well-Known Member
Licensed User
Longtime User
Hmm, I have to be able to pass the path into that mkdir sub.

That button is off to the side on it's own panel, and FS.PathOnly and FS.SelectionPath both return null.
 

margret

Well-Known Member
Licensed User
Longtime User
If you look at this line of code:
B4X:
File.MakeDir(PathWithFileName, "MyMusic")

PathWithFileName will hold the path and the folder name you long clicked on, which is what you need. Then "MyMusic" can be anything you want or a variable. So if PathWithFileName was: "/mnt/ext_sdcard/Dev", then it would create a folder called "MyMusic" under Dev.
 

merlin2049er

Well-Known Member
Licensed User
Longtime User
Hi, ok. I've got lib 1.03 installed, and I've got a problem refreshing the current folder with FS.Invalidate_FilesList.
 

stevel05

Expert
Licensed User
Longtime User
Are you getting an error?
 
Top