B4A Library [Lib+Class] CustomGallery

CustomGallery is a very small library (BitmapPlus) and a class (ClsCustomGallery) for B4A v2.0.
Its goal is to display thumbnails in a row, column or grid. It's highly customizable as you can see in the screenshots.

It needs two other libraries: ScrollView2D and Reflection

Tutorial: How they do #2

img1.jpg img2.jpg img3.jpg img4.jpg img5.jpg
List of functions:
Initialize(Parent As Object, Left As Int, Top As Int, Width As Int, Height As Int, GalleryStyle As Int, Callback As Object, subTouch As String, subClick As String, subLongClick As String, subScroll As String)
ClearGallery
RemoveColoredBorders
(bmpToCrop As Bitmap, Color As Int) As Bitmap
NumberOfThumbnails As Int
ProcessBitmap(SrcBmp As Bitmap) As Bitmap
AddThumbnail(SrcBmp As Bitmap, Tag As Object)
AddFolder(Dir As String, MaxNbFiles As Int)
InsertThumbnailAt(SrcBmp As Bitmap, Position As Int, Tag As Object)
InsertOnTop(SrcBmp As Bitmap, Position As Int, Tag As Object)
InsertFileAt(Dir As String, FileName As String, InsertPosition As Int, Tag As Object)
MoveThumbnail(FromPos As Int, ToPos As Int)
RemoveThumbnailAt(Position As Int)
RemoveThumbnailWithTag(Tag As Object)
GetThumbnailAt(Position As Int) As Panel
GetThumbnailWithTag(Tag As Object) As Panel
JumpTo(Position As Int)
SetLabelInGrid(Thumbnail As Panel, LabelText As String, LabelColor As Int, LabelSize As Int)
LoadDrawable(Name As String) As Object
AddDrawableTo(Thumbnail As Panel, Drawable As Object)

List of options:
BorderColor As Int
BorderSize As Int
ForceColorReduction As Boolean: if true, reduces the bitmap colors and removes the alpha channel to save memory
MinTiltAngle As Int
MaxTiltAngle As Int
AlternateAngle As Boolean: if true, tilt angles are alternately < 0 and > 0
HorizontalOffset As Int: shifts the thumbnails to the right (+) or to the left (-)
VerticalOffset As Int: shifts the thumbnails to the bottom (+) or to the top (-)
PressedDrawable As Object: drawable displayed when a thumbnail is clicked
RescaleOnlyIfBigger As Boolean: if true, the rescaling function is called only if the source image is bigger than the thumbnail
LabelHeightInGrid As Int: height of labels below thumbnails
SizeInGrid As Int: size of thumbnails inside a grid
SizeInPile As Int: size of thumbnails with the pile style
SpaceBetweenThumbnails As Int
StillVisible As Int: if there's an offset, defines the minimum visible size of thumbnails

v1.1: see details here
v1.11: Fixed three minor bugs
v1.2: see details here
v1.3: Fixed a bug and added the ForceColorReduction option
v1.31: Compatible with obfuscation and JellyBean
v1.32: No more warnings with B4A v2.7.
v1.321: Minor change. I added two entries to the Manifest of examples to enable the hardware acceleration and a large heap.

If you want to download the library and the class, you need only the file CustomGallery#1.zip. If you want to run the full demo, download the five files. After unzipping, you should have nineteen images (18 jpg + 1 png) in the Files folder of the demo.

Another demo (with the MediaBrowser library) is available here.

Fred
 

Attachments

  • CustomGallery#2.zip
    362.3 KB · Views: 1,115
  • CustomGallery#3.zip
    375.5 KB · Views: 978
  • CustomGallery#4.zip
    296.8 KB · Views: 1,012
  • CustomGallery#5.zip
    331.9 KB · Views: 1,418
  • CustomGallery#1 v1.321.zip
    283.2 KB · Views: 1,237
Last edited:

Informatix

Expert
Licensed User
Longtime User
Hi Informatix, sorry but "old" project was deleted :(
Anyway if you work with 100 image or more...and click, one, two, ten time.... dont work. You need to restart the app.
You got probably an Out of Memory error but without something to test, I can't help more.
 

juanM1

Member
Licensed User
Longtime User
Hi Informatix.

In android 5.0.1 y 2, when you scroll to the right or left, fails, not in android 4.2.2

Thanks
 

juanM1

Member
Licensed User
Longtime User
Informatix thanks, that was, I had installed the version 2.20 of scrollview2d of 09/01/2013
 

Informatix

Expert
Licensed User
Longtime User
Informatix thanks, that was, I had installed the version 2.20 of scrollview2d of 09/01/2013
This version 2 is a special version originally created for ULV but since version 3 of ULV it is no longer used and has not been updated.
 
Last edited:

shashkiranr

Active Member
Licensed User
Longtime User
Hi All,

I am getting invalid zip while opening the zip files of the latest v1.321. Am i the only one who is facing this.? Kindly let me know.

Regards,
SK
 

shashkiranr

Active Member
Licensed User
Longtime User
The downloaded file from chrome is not working. tried with other download manager and it worked. thank you Fred :)
 

susu

Well-Known Member
Licensed User
Longtime User
Hi @Informatix,
Base on your sample #4, I just add this code into Sub Gallery_OnClick(Thumbnail As Panel) to remove thumbnail

B4X:
Sub Gallery_OnClick(Thumbnail As Panel)
    Log("Delete thumbnail " & Thumbnail.Tag)
    MyGallery1.RemoveThumbnailWithTag(Thumbnail.Tag)
End Sub

It works as expected but if I click on the last thumbnail, all other thumbnails will be deleted except the first 3. Could you please explain and guide me how to fix it? Thank you so much.

Ps: I attached the sample code below.
 

Attachments

  • removethumbnail.zip
    13.6 KB · Views: 93

Informatix

Expert
Licensed User
Longtime User
Hi @Informatix,
Base on your sample #4, I just add this code into Sub Gallery_OnClick(Thumbnail As Panel) to remove thumbnail

B4X:
Sub Gallery_OnClick(Thumbnail As Panel)
    Log("Delete thumbnail " & Thumbnail.Tag)
    MyGallery1.RemoveThumbnailWithTag(Thumbnail.Tag)
End Sub

It works as expected but if I click on the last thumbnail, all other thumbnails will be deleted except the first 3. Could you please explain and guide me how to fix it? Thank you so much.

Ps: I attached the sample code below.
You should do that with ULV, not with this class. You would avoid Out of Memory errors. In "My Playground", my first app, I made all the image lists with ULV. You create each row with 3 cells and you put one image per cell.
Concerning the bug that you encounter, it is probably in the MoveInGrid function of the class.
 

susu

Well-Known Member
Licensed User
Longtime User
Thank you very much although I spent 3 days to make a very nice image explorer base on your CustomGallery. It's really hurt to do it again with ULV :D
Can you tell me which example of ULV that I can refer to?
 

Informatix

Expert
Licensed User
Longtime User
Thank you very much although I spent 3 days to make a very nice image explorer base on your CustomGallery. It's really hurt to do it again with ULV :D
Can you tell me which example of ULV that I can refer to?
None, but it's pretty easy to do:
A row layout with three cells.
An imageview in each cell.
 

Jack Cole

Well-Known Member
Licensed User
Longtime User
In example #4, I get the following error when I try to scroll.

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.graphics.drawable.Drawable.setAlpha(int)' on a null object reference
at flm.b4a.scrollview2d.EdgeEffect.draw(EdgeEffect.java:320)
at flm.b4a.scrollview2d.TwoDScrollView.draw(TwoDScrollView.java:2016)
at android.view.View.updateDisplayListIfDirty(View.java:15402)
at android.view.View.getDisplayList(View.java:15424)
at android.view.View.draw(View.java:16194)
at android.view.ViewGroup.drawChild(ViewGroup.java:3709)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3502)
at android.view.View.updateDisplayListIfDirty(View.java:15397)
at android.view.View.getDisplayList(View.java:15424)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3693)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3672)
at android.view.View.updateDisplayListIfDirty(View.java:15362)
at android.view.View.getDisplayList(View.java:15424)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3693)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3672)
at android.view.View.updateDisplayListIfDirty(View.java:15362)
at android.view.View.getDisplayList(View.java:15424)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3693)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3672)
at android.view.View.updateDisplayListIfDirty(View.java:15362)
at android.view.View.getDisplayList(View.java:15424)
at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:310)
at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:316)
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:355)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:2890)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2684)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2271)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1265)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6945)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:821)
at android.view.Choreographer.doCallbacks(Choreographer.java:606)
at android.view.Choreographer.doFrame(Choreographer.java:576)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:807)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6895)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
** Activity (main) Resume **
 
Top