B4A Library [Class] File Explorer with visualization

Hi,

I created this class because I was frustrated by the File Dialog in the (great) Dialogs lib. With that class, you can customize everything (since you have the source code) and add new functions like rename, delete, create folder, etc.
Currently, the class can visualize picture and text files (or not if you set the option to false) when you select them.
You can make multiple selections.

If your activity contains a TabHost, loot at post #7.

Add this permission to the manifest for Android v4+:
AddPermission(android.permission.READ_EXTERNAL_STORAGE)


Since September 1st 2014, this class is completely free.

Enjoy,
Fred
 

Attachments

  • img1.jpg
    img1.jpg
    54.1 KB · Views: 3,448
  • img2.jpg
    img2.jpg
    68 KB · Views: 2,938
  • multi.png
    multi.png
    41.6 KB · Views: 2,736
  • FileExplorer v2.1.zip
    61.2 KB · Views: 2,225
Last edited:

dewif

Member
Licensed User
Longtime User
can't open any folder

I've tried the example, but I can't open any folder. when I write the folder name in the EditText, it shows MsgBox "Your choice /mnt/<chosen folder>" and then shows a toastMsgBox "Unable to access folder" (even if I chose sdcard folder).
I used File Explorer v1.2.
Happens in emulator and device HTC Evo View 4G.
Any help?
 

Informatix

Expert
Licensed User
Longtime User
I've tried the example, but I can't open any folder. when I write the folder name in the EditText, it shows MsgBox "Your choice /mnt/<chosen folder>" and then shows a toastMsgBox "Unable to access folder" (even if I chose sdcard folder).
I used File Explorer v1.2.
Happens in emulator and device HTC Evo View 4G.
Any help?

:eek: The changes introduced by Erel in its ListView broke my code and made this view unusable. I'm going to find an alternative. Sorry for the inconvenience and thanks for the report.
 

Informatix

Expert
Licensed User
Longtime User
Do you know what has changed? Is it the handling of events?

In ListView_ItemClick, the click is now delayed to avoid the "motion event recycled twice" error. In my class, the event is now received a long time after the click has been done, and it is unusable. I'm going to replace the listview by the CheckList class. The behavior and appareance will be the same as before.
 

thedesolatesoul

Expert
Licensed User
Longtime User
In ListView_ItemClick, the click is now delayed to avoid the "motion event recycled twice" error. In my class, the event is now received a long time after the click has been done, and it is unusable. I'm going to replace the listview by the CheckList class. The behavior and appareance will be the same as before.
I see. I wish there was a better workaround for it (motion event recylced twice), because the simple listview is useful at times. Thank you.
 

JohnC

Expert
Licensed User
Longtime User
Can I explore Internal Memory?

Can this class be used to navigate internal memory (not just storage card)- in other words, can I explore *ANY* location *ANY*where in my device if I give this app SuperUser Permission (and my device is rooted of course)?

I basically want to create an app that offers a subset of the features in "Root Explorer" in the play store.
 

Informatix

Expert
Licensed User
Longtime User
Can this class be used to navigate internal memory (not just storage card)- in other words, can I explore *ANY* location *ANY*where in my device if I give this app SuperUser Permission (and my device is rooted of course)?

I basically want to create an app that offers a subset of the features in "Root Explorer" in the play store.

The answer is clearly Yes.
Try it and you'll see.
 

melamoud

Active Member
Licensed User
Longtime User
trying to use your class from within a dialog

hi,

I'm trying to use your explorer class from within a modal dialog, Iguess this is wrong, since it does nothing, and after trying few times, I think I get into stack overflow, do youknow why ?

the error:
B4X:
22:20:43 MNot:HeaderClick: 0
22:20:43 MNot:AddFile: 
22:21:03 MNot:Folders CellClick: 0 , 0
22:21:03 MNot:cell value:/mnt/sdcard/amazonmp3
22:21:04 MNot:HeaderClick: 0
22:21:04 MNot:AddFile: 
22:21:05 MNot:HeaderClick: 0
22:21:05 MNot:AddFile: 
22:21:06 MNot:HeaderClick: 0
22:21:06 MNot:AddFile: 
clsexplorer_commonexplorer (java line: 426)
java.lang.StackOverflowError
   at android.text.Layout.draw(Layout.java:340)
   at android.text.BoringLayout.draw(BoringLayout.java:365)
   at android.widget.TextView.onDraw(TextView.java:4473)
   at android.view.View.draw(View.java:6880)
   at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
   at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
   at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
   at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
   at android.view.View.draw(View.java:6986)
   at android.widget.FrameLayout.draw(FrameLayout.java:357)
   at android.widget.ScrollView.draw(ScrollView.java:1409)
   at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
   at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
   at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
   at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
   at android.view.View.draw(View.java:6883)
   at android.widget.FrameLayout.draw(FrameLayout.java:357)
   at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
   at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
   at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
   at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
   at android.view.View.draw(View.java:6883)
   at android.widget.FrameLayout.draw(FrameLayout.java:357)
   at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2090)
   at android.view.ViewRoot.draw(ViewRoot.java:1522)
   at android.view.ViewRoot.performTraversals(ViewRoot.java:1258)
   at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at anywheresoftware.b4a.Msgbox.waitForMessage(Msgbox.java:211)
   at anywheresoftware.b4a.Msgbox.waitForMessage(Msgbox.java:180)
   at anywheresoftware.b4a.keywords.Common.DoEvents(Common.java:370)
   at appsright.musicnotifier.clsexplorer._commonexplorer(clsexplorer.java:426)
   at appsright.musicnotifier.clsexplorer._explorer2(clsexplorer.java:815)
   at appsright.musicnotifier.main._addfile(main.java:324)
   at appsright.musicnotifier.main._cb_headerclick(main.java:450)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:507)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:165)
   at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:798)
   at anywheresoftware.b4a.keywords.Common.CallSub2(Common.java:783)
   at appsright.musicnotifier.table._header_click(table.java:338)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:507)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:165)
   at anywheresoftware.b4a.BA.raiseEvent(BA.java:149)
   at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:55)
   at android.view.View.performClick(View.java:2485)
   at android.view.View$PerformClick.run(View.java:9089)
   at android.os.Handler.handleCallback(Handler.java:587)
   at android.os.Handler.dispatchMessage(Handler.java:92)
   at anywheresoftware.b4a.Msgbox.waitForMessage(Msgbox.java:211)
   at anywheresoftware.b4a.Msgbox.waitForMessage(Msgbox.java:180)
   at anywheresoftware.b4a.keywords.Common.DoEvents(Common.java:370)
   at appsright.musicnotifier.clsexplorer._commonexplorer(clsexplorer.java:426)
   at appsright.musicnotifier.clsexplorer._explorer2(clsexplorer.java:815)
   at appsright.musicnotifier.main._addfile(main.java:324)
   at appsright.musicnotifier.main._cb_headerclick(main.java:450)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:507)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:165)
   at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:798)
   at anywheresoftware.b4a.keywords.Common.CallSub2(Common.java:783)
   at appsright.musicnotifier.table._header_click(table.java:338)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:507)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:165)
   at anywheresoftware.b4a.BA.raiseEvent(BA.java:149)
   at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.
** Activity (main) Resume **


the code:


B4X:
Sub btn_folders_Click
   Utilities.LogM(0,"open folders dialog")
   Dim nd As CustomDialog
   Dim ret As Int
   Dim p As Panel
   Dim l As List : l = DBHandler.getFolders
   ' build table
   p.Initialize("")
   tbl_folders.Initialize(Me,"cb",1)
   tbl_folders.AddToActivity(p,0,10,100%x,100%y-50)
   tbl_folders.SetHeader(Array As String("Folders"))
   For i = 0 To l.Size -1
      tbl_folders.AddRow(Array As String(l.Get(i)))
   Next
   
   addFile
   
   
   nd.AddView(p,0,0,100%x,100%y)      
   ret = DialogResponse.CANCEL
   ret = nd.Show("You have " & l.Size & " Folders", "Ok", "", "", Null)
End Sub

Sub cb_CellClick (Col As Int, Row As Int)
   Utilities.LogM(0,"Folders CellClick: " & Col & " , " & Row)
   Utilities.LogM(0,"cell value:" & tbl_folders.GetValue(Col, Row))
End Sub

Sub cb_HeaderClick (Col As Int)
   Utilities.LogM(0,"HeaderClick: " & Col)
   addFile
End Sub


Sub addFile
   Utilities.LogM(0,"AddFile: ")
   Dim nd As ClsExplorer
   
   nd.Initialize(Activity, File.DirRootExternal,"",True,True,"Ok")
   nd.DialogRect.Left = 5dip
   nd.DialogRect.Right = 100%x - 5dip
   nd.DialogRect.Top = 25dip
   nd.DialogRect.Bottom = 100%y-25dip
   nd.BackgroundColor = Colors.LightGray
   nd.BorderColor = Colors.RGB(128, 128, 128)
   nd.FolderTextColor = Colors.Black
   nd.FileTextColor1 = Colors.Blue
   nd.FileTextColor2 = Colors.White
   nd.DividerColor = Colors.Gray

   nd.Explorer2(False)
   If Not(nd.Selection.Canceled OR nd.Selection.ChosenPath = "") Then
      Utilities.LogM(0,"User press ok:" & nd.Selection.ChosenPath)
      tbl_folders.AddRow(Array As String(nd.Selection.ChosenPath))
   Else      
         Utilities.LogM(0,"User press cancel")
   End If
End Sub
 

shashkiranr

Active Member
Licensed User
Longtime User
Hi Fred,

I am using Explorer2(DarkTheme as Boolean). but i want to set the width and height according to my need by using dialog.rect parameters. (I am having a customized title bar but this is hiding that)

i am not able to achieve this.

Kindly let me know if it is possible.

Regards,
SK
 

shashkiranr

Active Member
Licensed User
Longtime User
Hi Fred,

Thanks for the tip. Unfortunately i am stuck with one more problem. everything loads properly. I have an action bar on the top of the screen and below it i am opening the file dialog. There are button on action bar like share and delete. If i click on those buttons nothing happens....
Before loading the file dialog the button works but after loading the file dialog it does not work. Is it the request focus problem or is it something else?

I have removed the edit text box and replaced it with a label.

Kindly provide ur suggestions and inputs.

Regards,
SK
 

Informatix

Expert
Licensed User
Longtime User
Hi Fred,

Thanks for the tip. Unfortunately i am stuck with one more problem. everything loads properly. I have an action bar on the top of the screen and below it i am opening the file dialog. There are button on action bar like share and delete. If i click on those buttons nothing happens....
Before loading the file dialog the button works but after loading the file dialog it does not work. Is it the request focus problem or is it something else?

I have removed the edit text box and replaced it with a label.

Kindly provide ur suggestions and inputs.

Regards,
SK
The file dialog is modal, so you cannot use buttons or any other view not on the dialog. And if you remove the edit text, I doubt that the dialog works since the focus is set on, and kept by, the edit text. I will rewrite this class some day to use my Better Dialog library because I'm not satisfied by the "trick" I use, but I don't know when.
 

shashkiranr

Active Member
Licensed User
Longtime User
ok ,fred is it possible to use the checklist class and retrieve all the files from the file explorer and update in the checklist.
 

shashkiranr

Active Member
Licensed User
Longtime User
Hmmm One more question does Ultimate List View can display the files retrieved along with checkbox ??
 

BvdB

Member
Licensed User
Longtime User
Hi Fred and/or Erel,

I am testing v3 Beta and found that the clsexplorer class version 1.3 gives and error when run with Debug (rapid) mode
It crashes on lines 352 and 359
Below is the code from line 348 to 359

B4X:
Private Sub CommonExplorer
    Selection.Canceled = True
    Selection.ChosenPath = ""
    Selection.ChosenFile = ""
    edtFilename.RequestFocus
    Do While WaitUntilOK
        ' Main loop - we wait until the OK btn is pressed or the back key is used
        DoEvents
    Loop
    pnlMasque.RemoveView
    pnlMasque = Null
End Sub

First line on which it crashes is: edtFilename.RequestFocus
Unexpected event (missing RaiseSynchronousEvents): dlg_hasfocus

If I comment it out, the code continues to run, but when I click on the Ok button, it crashes on: pnlMasque.RemoveView
The error that appears in the log is:
Unexpected event (missing RaiseSynchronousEvents): dlg_hasfocus

Have you or any-one else experienced this with V3 beta, running under v3 Beta Degug (rapid) mode?
It works fine with v2.7 and v3 Beta with Debug (legacy) mode.

Not sure if this is the correct place to place the feedback, if not, feel free to move the post where most relevant or appropriate.
 
Top