B4A Library [Lib] CoverFlow v2.0

Hi guys, as I have promised, CoverFlow is here.

Download the Coverflow.zip

The zip contains the library and an example that´s all


The CoverFlow Class = Neil Davies




B4ACoverFlow
Author:
Giuseppe Salvi
Version: 2
  • PhotoFlow
    Events:
    • ItemClick (Position As Int, Value As Object)
    • ItemLongClick (Position As Int, Value As Object)
    • ItemSelected (Position As Int, Value As Object)
    Methods:
    • AddImage (Dir As String, FileName As String)
      Add an image at the end of the PhotoFlow from sdcard or AssetsDir
      Example:
      PhotoFlow.AddImage(File.DirRootExternal,"a.jpg")
    • AddImageAt (index As Int, Dir As String, FileName As String)
      Add an image to the desired position in the PhotoFlow from sdcard or AssetsDir
      Example:
      PhotoFlow.AddImage(1,File.DirRootExternal,"a.jpg")
    • BringToFront
    • ClearCache
      Delete entire disk and memory cache created before
    • GetImageListFromAssets (path As String) As List
      Get entire list of images stored in assets folder
      Examples:
      Dim lv as ListView
      Dim l as list
      l.Initialize
      lv.Initialize("lv")
      Sub Menu_Click
      Activity.AddView(lv,0,0,100%x,100%y)
      l = Coverflow.GetImageListFromAssets("Here the Images path u've in assets")
      For n = 0 To l.Size-1
      lv.AddSingleLine(l.Get(n))
      next
      End Sub
    • GetItem (position As Int) As String
      Returns Item
      Example:
      i.Bitmap=LoadBitmap("",PhotoFlow.GetItem(Position))
    • InitializeCarousel (EventName As String)
      Initialize the Carousel
    • InitializeCoverflow (EventName As String)
      Initialize the PhotoFlow
    • IsInitialized As Boolean
    • PopulatePhotoFlow (dir As String, path As String)
      Populate PhotoFlow from sdcard not from assets
    • PopulatePhotoFlowFromAssets (path As String)
      Populate CoverFlow from assets not from sdcard
    • RemoveView
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    Permissions:
    • android.permission.WRITE_EXTERNAL_STORAGE
    Properties:
    • AnimationDuration As Int [write only]
      Sets how long the transition animation should run when a child view changes position.
    • Carousel As Boolean [write only]
      Set as Carousel
    • Color As Int [write only]
    • CreateCache As String [write only]
      Sets the name of your own cache
      Examples:
      PhotoFlow.CreateCache = "Your cache Name Here")
      It'll create a cache in "Android/data/Your cache name/cache/.thumbs" in to SdCard
    • Enabled As Boolean
    • FadingEdgeLength As Int [write only]
      Set the size of the faded edge used to indicate that more content in this view is available.
    • Height As Int
    • ItemHeight As Int
      Get or Set ItemHeight
    • ItemWidth As Int
      Get or Sets ItemWidth
    • Left As Int
    • Length As Int [read only]
      Returns lenght
    • Reverse As Boolean [write only]
      Set reverse
    • Selection As Int [write only]
      Jump directly to a specific item in the adapter data.
    • ShowText As Boolean
      Get or Sets the visibility of the text - by default is hide
    • Spacing As Int [write only]
      Sets the spacing between items in a Gallery
    • Tag As Object
    • TextColor As Int
      Get or Sets Text Color - by default is White
    • TextSize As Int
      Get or Sets Text size
    • Top As Int
    • Version As String [read only]
      Return Author and Version of this library
    • Visible As Boolean
    • Width As Int
 

Attachments

  • coverflow.jpg
    coverflow.jpg
    83.8 KB · Views: 2,378
  • coverflow2.jpg
    coverflow2.jpg
    81.1 KB · Views: 2,176
  • CoverFlow with Text.jpg
    CoverFlow with Text.jpg
    115.6 KB · Views: 1,590
  • B4ACoverFlow v.1.70.zip
    36.2 KB · Views: 462
  • B4ACoverFlow v.1.80.zip
    40.2 KB · Views: 463
  • B4ACoverFlow v2.0 fix.zip
    40.6 KB · Views: 1,072
Last edited:

Mashiane

Expert
Licensed User
Longtime User
Hi,

For some reason, in version 2, if I change this line

From
B4X:
Coverflow.CreateCache = "Pippo.Pluto.Paperino"

To
B4X:
Coverflow.CreateCache = "a.b.c.d"

The CoverFlow plugin does not work.
Q1. Is the Cache locked to "Pippo.Pluto.Paperino" or can someone use their own cache names?

Q2. I have placed the CoverFlow inside a panel with....
B4X:
pnlCoverFlow.AddView(Coverflow, 0dip, 0dip, 100%x, 100%y)

and did this also

B4X:
Coverflow.ItemWidth = 50%x
    Coverflow.ItemHeight = 100%y

because I was under the impression that each image will fit the panel size height. Unfortunately it does not. How can I ensure that each image fits perfectly (see attached images for clarity)

Q3. Each image I am adding is currently sitting in the Assets folder and I am using AddImage method. I will not use all the images in the assets folder but some. The thing is, I have to call this method below for my code to even display in the emulator otherwise nothing happens. When this line is commented out, my app does not even run.
B4X:
Coverflow.PopulatePhotoFlowFromAssets("a")

Is it possible to make this library to work without having to populate from assets but instead populate from a list of given files? I don't have a folder called "a" in assets and this methods is supposed to read that folder and display the images isn't it? Below is my complete source for this. Can someone please advise?

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    ProgressDialogShow("Loading...") 
    DoEvents
    Activity.LoadLayout("vSplash")
    Activity.Color = Colors.black
    modMashiane.Button_PowderBlueWhite(btnLogin)
    modMashiane.Button_PowderBlueWhite(cmdRegister)
    StateManager.Initialize(Application.LabelName)
    pnlCoverFlow.Color = Colors.transparent
    Coverflow.InitializeCoverflow("Coverflow")
    ' if string below is changed to anything else other than Pippo.Pluto.Paperino
    ' nothing is displayed on coverflow
    Coverflow.CreateCache = "Pippo.Pluto.Paperino"
    pnlCoverFlow.AddView(Coverflow, 0dip, 0dip, 100%x, 100%y)
    Coverflow.Spacing= -15
    Coverflow.ItemWidth = 50%x
    Coverflow.ItemHeight = 100%y
    Coverflow.AnimationDuration=1000
    ' if this line is commented out, the app does start, there is no folder called "a" in assets
    Coverflow.PopulatePhotoFlowFromAssets("a")  
    Coverflow.ShowText = False
    Coverflow.AddImage(File.DirAssets,"slide1.jpg")
    Coverflow.AddImage(File.DirAssets,"slide2.jpg")
    Coverflow.AddImage(File.DirAssets,"slide3.jpg")
    Coverflow.AddImage(File.DirAssets,"slide4.jpg")
    Coverflow.AddImage(File.DirAssets,"slide5.jpg")
    Coverflow.AddImage(File.DirAssets,"slide6.jpg")
    Coverflow.AddImage(File.DirAssets,"slide7.jpg")
    Coverflow.AddImage(File.DirAssets,"slide8.jpg")
    Coverflow.AddImage(File.DirAssets,"slide9.jpg")
    Coverflow.AddImage(File.DirAssets,"slide10.jpg")
    Coverflow.AddImage(File.DirAssets,"slide11.jpg")
    Coverflow.AddImage(File.DirAssets,"slide12.jpg")
    Coverflow.AddImage(File.DirAssets,"slide13.jpg")
    Coverflow.AddImage(File.DirAssets,"slide14.jpg")
    Coverflow.Selection = 1
    ProgressDialogHide
End Sub
 

Attachments

  • coverflow.png
    coverflow.png
    318.4 KB · Views: 283
  • slide1.jpg
    slide1.jpg
    289.2 KB · Views: 256
Last edited:

lonleystar

Well-Known Member
Licensed User
Longtime User
Hi,

For some reason, in version 2, if I change this line

From
B4X:
Coverflow.CreateCache = "Pippo.Pluto.Paperino"

To
B4X:
Coverflow.CreateCache = "a.b.c.d"

The CoverFlow plugin does not work.
Q. Is the Cache locked to "Pippo.Pluto.Paperino" or can someone use their own cache names?

Q. I have placed the CoverFlow inside a panel with....
B4X:
pnlCoverFlow.AddView(Coverflow, 0dip, 0dip, 100%x, 100%y)

and did this also

B4X:
Coverflow.ItemWidth = 50%x
    Coverflow.ItemHeight = 100%y

because I was under the impression that each image will fit the panel size height. Unfortunately it does not. How can I ensure that each image fits perfectly (see attached images for clarity)

Q. Each image I am adding is currently sitting in the Assets folder and I am using AddImage method. I will not use all the images in the assets folder but some. The thing is, I have to call this method below for my code to even display in the emulator otherwise nothing happens. When this line is commented out, my app does not even run.
B4X:
Coverflow.PopulatePhotoFlowFromAssets("a")

Is it possible to make this library to work without having to populate from assets but instead populate from a list of given files? I don't have a folder called "a" in assets and this methods is supposed to read that folder and display the images isn't it? Below is my complete source for this. Can someone please advise?

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    ProgressDialogShow("Loading...")
    DoEvents
    Activity.LoadLayout("vSplash")
    Activity.Color = Colors.black
    modMashiane.Button_PowderBlueWhite(btnLogin)
    modMashiane.Button_PowderBlueWhite(cmdRegister)
    StateManager.Initialize(Application.LabelName)
    pnlCoverFlow.Color = Colors.transparent
    Coverflow.InitializeCoverflow("Coverflow")
    ' if string below is changed to anything else other than Pippo.Pluto.Paperino
    ' nothing is displayed on coverflow
    Coverflow.CreateCache = "Pippo.Pluto.Paperino"
    pnlCoverFlow.AddView(Coverflow, 0dip, 0dip, 100%x, 100%y)
    Coverflow.Spacing= -15
    Coverflow.ItemWidth = 50%x
    Coverflow.ItemHeight = 100%y
    Coverflow.AnimationDuration=1000
    ' if this line is commented out, the app does start, there is no folder called "a" in assets
    Coverflow.PopulatePhotoFlowFromAssets("a")
    Coverflow.ShowText = False
    Coverflow.AddImage(File.DirAssets,"slide1.jpg")
    Coverflow.AddImage(File.DirAssets,"slide2.jpg")
    Coverflow.AddImage(File.DirAssets,"slide3.jpg")
    Coverflow.AddImage(File.DirAssets,"slide4.jpg")
    Coverflow.AddImage(File.DirAssets,"slide5.jpg")
    Coverflow.AddImage(File.DirAssets,"slide6.jpg")
    Coverflow.AddImage(File.DirAssets,"slide7.jpg")
    Coverflow.AddImage(File.DirAssets,"slide8.jpg")
    Coverflow.AddImage(File.DirAssets,"slide9.jpg")
    Coverflow.AddImage(File.DirAssets,"slide10.jpg")
    Coverflow.AddImage(File.DirAssets,"slide11.jpg")
    Coverflow.AddImage(File.DirAssets,"slide12.jpg")
    Coverflow.AddImage(File.DirAssets,"slide13.jpg")
    Coverflow.AddImage(File.DirAssets,"slide14.jpg")
    Coverflow.Selection = 1
    ProgressDialogHide
End Sub


Hi, if U dont set the cache does matter, it will create a cache named your package name.

right now i tested the library:

Coverflow.CreateCache = "Pippo.Pluto.Paperino"
To
Coverflow.CreateCache = "a.b.c.d"

and work fine.
 

Attachments

  • a.b.c.d.png
    a.b.c.d.png
    240.5 KB · Views: 239

lonleystar

Well-Known Member
Licensed User
Longtime User
Q2 and Q3 as question 2 and question 3 respectively. Can you please look into those in the first post? Thanks.

Hi the first question the Cache is not locked, the second question I test with panel and not work fine, third question ShowFromAssets(Your path neme here) instead of PopulatePhotoFlowFromAssets("a")

Best Regard.

G.Salvi
 
  • Like
Reactions: tmf

tmf

Member
Licensed User
Longtime User
OK this is driving me nuts!

First had issues I think finding paths to the files, but now it should be OK as its returning TRUE to the msgbox() seen below... so what is the issue?

Sub Globals
Dim cf As PhotoFlow
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
cf.InitializeCoverflow("cover")
cf.CreateCache = "Pippo.Pluto.Paperino"
cf.Spacing = -20
cf.ItemWidth = 200
cf.ItemHeight = 200
cf.AnimationDuration = 800
cf.ClearCache
Activity.AddView(cf, 0dip, 0dip, 100%x, 100%y)

' returns a TRUE so the file exists
Msgbox(File.Exists("/storage/emulated/0", "k2.jpg"), "")
' returns a TRUE so cf is initialized
Msgbox(cf.IsInitialized, "")

' this next line throws up the error below which I thought was due to file missing
cf.AddImage("/storage/emulated/0", "k2.jpg")
cf.Enabled = True
End Sub

LogCat connected to: B4A-Bridge: motorola XT1064
--------- beginning of main
Installing file.
PackageAdded: package:b4a.example
** Activity (main) Create, isFirst = true **
main_activity_create (B4A line: 43)
cf.AddImage("/storage/emulated/0", "k2.jpg")
java.lang.NullPointerException: Attempt to invoke interface method 'boolean java.util.List.add(java.lang.Object)' on a null object reference
at it.giuseppe.salvi.PhotoFlowActivity.AddImage(PhotoFlowActivity.java:229)
at b4a.example.main._activity_create(main.java:376)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
at b4a.example.main.afterFirstLayout(main.java:100)
at b4a.example.main.access$100(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:78)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5310)
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:901)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
Installing file.
PackageAdded: package:b4a.example
 

tmf

Member
Licensed User
Longtime User
OK I added cf.PopulatePhotoFlowFromAssets("") before cf.addimage and even though it loaded no images from assets it allowed the cf.addimage to work :) Can someone answer why so I have a full understanding of this.
 

tmf

Member
Licensed User
Longtime User
Thanks! I will test it for you once I receive it, I am actively writing an APP that will require it, hope it works for me! :)
 

victormedranop

Well-Known Member
Licensed User
Longtime User
Something strange happened I add the library, I can see the library loaded but I cant create the code.
B4X:
Dim Coverflow As B4ACoverFlow
 

Attachments

  • Capture1.PNG
    Capture1.PNG
    1.4 KB · Views: 187
  • Capture2.PNG
    Capture2.PNG
    1.3 KB · Views: 192

victormedranop

Well-Known Member
Licensed User
Longtime User
I need son help with this lib, can't make carousel to start. stay in the first picture.
check my code
B4X:
#region: image
 If image_list.Size > 0 Then
 ImageView1.Visible = False
 Coverflow.Visible = True
 Coverflow.Carousel = True
 Coverflow.Reverse = True
 Try
 Coverflow.PopulatePhotoFlow(File.DirRootExternal,"") 
 Log("starting coverflow")
 Catch
 Log(LastException)
 End Try
 Else
 Log ("No image files to display ") 
 End If
#end region
[\CODE]
 
Top