B4A Library SwipeCardView

This is a wrap for this github project. I got inspired by the lib posted and i found it nice... So i build it


SwipeCard
Version:
1
  • Card
    Methods:
    • Initialize (Name As CharSequence, Image As String, color As Int, bgcolor As Int)
    • IsInitialized As Boolean
  • SwipeCardView
    Events:
    • onAdapterAboutToEmpty (itemsInAdapter As Int)
    • onCardExit (position As String, dataObject As Object)
    • onItemClicked (position As Int, dataObject As Object)
    • onScroll (scrollProgressPercent As Float)
    Fields:
    • ba As BA
    Methods:
    • BringToFront
    • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
    • Initialize (EventName As String, cards As ArrayList)
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • RemoveView
    • RequestFocus As Boolean
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
    • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
    • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
    • addListener
    • restart
    • setAdapterItems (cards As ArrayList)
    • throwBottom
    • throwLeft
    • throwRight
    • throwTop
    Properties:
    • Background As Drawable
    • Color As Int [write only]
    • Enabled As Boolean
    • Height As Int
    • Left As Int
    • MaxVisible As Int [write only]
    • MinStackInAdapter As Int [write only]
    • Padding()() As Int
    • Parent As Object [read only]
    • Tag As Object
    • Top As Int
    • Visible As Boolean
    • Width As Int


B4X:
[CODE]Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private SwipeCard As SwipeCardView
    Dim cs As CSBuilder
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")
    Dim cards As List
    cards.Initialize
    Dim c1 As Card
    'cs.Initialize.Typeface(Typeface.FONTAWESOME).Color(0xFF01FF20).Size(40).Append(Chr(0xF17B)).popall

    c1.Initialize(cs.Initialize.Typeface(Typeface.FONTAWESOME).Size(20).Color(0xFF01FF20).Append(Chr(0xF17B)).Append(" rulez!").PopAll,"androidapple", Colors.Black, Colors.Gray)
    cards.Add(c1)
    Dim c2 As Card
    c2.Initialize("Face 1","faces1", Colors.White, Colors.Black)
    cards.Add(c2)
    Dim c3 As Card
    c3.Initialize("Face 2","faces2", Colors.Black, Colors.White)
    cards.Add(c3)
    Dim c4 As Card
    c4.Initialize("Face 3","faces3", Colors.Black, Colors.White)
    cards.Add(c4)
    Dim c5 As Card
    c5.Initialize("Face 4","faces4", Colors.Black, Colors.White)
    cards.Add(c5)
    Dim c6 As Card
    c6.Initialize("Face 5","faces5", Colors.Black, Colors.White)
    cards.Add(c6)
    Dim c7 As Card
    c7.Initialize("Face 6","faces6", Colors.Black, Colors.White)
    cards.Add(c7)
    Dim c8 As Card
    c8.Initialize("Face 7","faces7", Colors.Black, Colors.White)
    cards.Add(c8)
    Dim c9 As Card
    c9.Initialize("Face 8","faces8", Colors.Black, Colors.White)
    cards.Add(c9)
    Dim c10 As Card
    c10.Initialize("Face 9","faces9", Colors.Black, Colors.White)
    cards.Add(c10)
    Dim c11 As Card
    c11.Initialize("Face 10","faces10", Colors.Black, Colors.White)
    cards.Add(c11)
    Dim c12 As Card
    c12.Initialize("Face 11","faces11", Colors.Black, Colors.White)
    cards.Add(c12)
    SwipeCard.setAdapterItems(cards)
    SwipeCard.addListener


End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub SwipeCard_onItemClicked(position As Int, dataObject As Object)
    Log($"SwipeCard_onItemClicked(${position})"$)
End Sub
Sub SwipeCard_onCardExit(position As String, dataObject As Object)
    Log($"SwipeCard_onCardExit(${position})"$)
End Sub
Sub SwipeCard_onAdapterAboutToEmpty(itemsInAdapter As Int)
    Log($"SwipeCard_onAdapterAboutToEmpty(${itemsInAdapter})"$)
    If itemsInAdapter = 0 Then
        SwipeCard.restart
    End If
End Sub
Sub SwipeCard_onScroll(scrollProgressPercent As Float)
    'Log($"SwipeCard_onScroll(${scrollProgressPercent})"$)
End Sub


This library is Donationware. You can download the library, you can test the library. But if you want to USE the library in your App you need to Donate for it.
Please click here to donate (You can donate any amount you want to donate for the library (or my work) :)
 

Attachments

  • SwipeCardEx.zip
    414.7 KB · Views: 643
  • SwipeCardExV1.1.zip
    415 KB · Views: 675
Last edited:

Peter Simpson

Expert
Licensed User
Longtime User

alimanam3386

Active Member
Licensed User
Longtime User
Good work thank you ....:)

How can we load bitmap or drawable images from DirAssets or DirRootExternal path ?
I know it's not available in source of this lib but I think it is better to someone improve it .
 

DonManfred

Expert
Licensed User
Longtime User
How can we load bitmap or drawable images from DirAssets or DirRootExternal path ?
i´ve added a method to the CARD Object. Respectively you can set a Image or Uri in the initialize method... If the Image is not empty then the Drawable will be used else the the Uri is used.

you need to set ImageUri as String
file://somepath

One of the both should be not ""

See V1.1 in Post #1
 

DonManfred

Expert
Licensed User
Longtime User
See the post above yours... i have added parameters but did not updated the Example...

B4X:
Initialize(CharSequence Name, String Image, String Uri, int color, int bgcolor)

/**
* Initialize the Card
* Name The Title for the image
* Image The name of the Image Drawable
* Uri The Path of the image as Uri to load into the Imageview. Set either Image OR Uri to a String <> ""
* color The Textcolor for the Title
* bgcolor The Backgroundcolor for the Title
*/
 
Last edited:

alimanam3386

Active Member
Licensed User
Longtime User
See the post above yours... i have added parameters but did not updated the Example...

B4X:
Initialize(CharSequence Name, String Image, String Uri, int color, int bgcolor)


Dear DonManfred , I think if you have a description of the method used in your library update is better because it will be clear to developer. thank you

erro2-jpg.54458
 

monic

Active Member
Licensed User
Longtime User
Hi

How should the example be referenced to add an image to the card?
B4X:
Dim UriString As String : UriString = "file:///android_asset/1.jpg"
    c1.Initialize("name", "imagename", UriString, Colors.White, Colors.Black)
 
Last edited:

scsjc

Well-Known Member
Licensed User
Longtime User
Hello DonManfred,
nice library great work !!!

Is possible get a images from a URL ???

Thanks !!!
 

scsjc

Well-Known Member
Licensed User
Longtime User
I guess no. I did not saw any code related to downloading an image.

You need to download it first and then add it to the card-stack using the correct uri.

Ok, thanks...
and can easy way to use a URISTRING.... ( file.dirinternal,"file.jpg" ) ??
 

scsjc

Well-Known Member
Licensed User
Longtime User
Hello DonManfred,
Im crazy to work with uristring "file:/..." , always don't work
The problem are when use a DEBUG MODE, in release mode work perfect... i leave a sample
Can you fix the DebugMode work too.
Thanks!!!
 

Attachments

  • SwipeCardEx_UriString.zip
    288.5 KB · Views: 367

DonManfred

Expert
Licensed User
Longtime User
Im crazy to work with uristring "file:/..." , always don't work

Hmmm... Looks like the problem happens in the underlying library. I am using a uri path in the example... and it works in releasemode though the lib does not really use a "Uri"
It it would then i would have a code in my wrapper to convert the string given to an Uri
B4X:
Uri.parse(uristring)
but i am not creating a Uri

All i am doing is to give the string you give to the wrapper to the underlying lib. Nothing more.

I don´t know how to fix and - honestly - i dont want to fix others code.
 
Last edited:

scsjc

Well-Known Member
Licensed User
Longtime User
Hmmm... Looks like the problem happens in the underlying library. I am using a uri path in the example... and it works in releasemode though the lib does not really use a "Uri"
It it would then i would have a code in my wrapper to convert the string given to an Uri
B4X:
Uri.parse(uristring)
but i am not creating a Uri

All i am doing is to give the string you give to the wrapper to the underlying lib. Nothing more.

I don´t know how to fix and - honestly - i dont want to fix others code.

Ok Thanks !!!
 
Top