B4A Library ShelfView

A wrap for this Github project. Posting
1. B4A project
2. Java Code (src and libs folders)
3. B4A library files
4. Other JAR's and XML's to be copied to your additional library folder.

It will raise an event in the B4A project when a book is clicked.

Copy LibRes.zip from here https://www.dropbox.com/s/z8g1y000r3go6iv/ShelfViewLibRes.zip?dl=0
Extract it and copy folder LibRes and its contents to be on the same folder level as that of the /Files and /Objects folders of the B4A project

Ensure that you have AppCompat V3.20 enabled in your B4A project's library tab


Change the wrapper and original Java code to your liking.

Take note of the permissions added in the B4A manifest file.
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="19"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")

AddManifestText(<uses-permission android:name="android.permission.INTERNET" />)
AddManifestText(<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />)
'End of default text.

Sample Code:
B4X:
#Region  Project Attributes
    #ApplicationLabel: b4aShelfView
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
#End Region

#AdditionalRes: ..\LibRes

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

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

    Private sv1 As ShelfView
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("main")
  
    Dim url() As String = Array As String("http://eurodroid.com/pics/beginning_android_book.jpg", _
                                          "http://eurodroid.com/wp3/wp-content/uploads/2014/10/samsung-galaxy-a5.jpg", _
                                          "http://3.bp.blogspot.com/-aDUhP55KerE/UGbxmCkyKOI/AAAAAAAAKM8/Ms7Hs6Ln524/s1600/cover.png", _
                                          "https://raw.githubusercontent.com/emmby/android-For-dummies-v3/master/assets/book-cover.png", _
                                          "http://devproconnections.com/site-files/devproconnections.com/files/uploads/2014/06/Riley%20DCM1061%20Pro_Android_book_cover.jpg", _
                                          "http://whatpixel.com/images/2016/08/android-programming-pushing-the-limits.jpg", _
                                          "http://www.lopez-manas.com/wp-content/uploads/2015/07/cover-Kopie-212x300.png", _
                                          "https://www.packtpub.com/sites/default/files/9781785883262.png")
                                        
                                        
    Dim index() As String = Array As String("1", "2", "3", "4", "5", "6", "7", "8")
  
    Dim bookname() As String = Array As String("Beginning Android", _
                                               "Samsung", _
                                               "Smashing Android UI", _
                                               "Android For Dummies V3", _
                                               "Professional Android Programming", _
                                               "Pushing The Limits", _
                                               "100 Questions and Answers", _
                                               "Android Programming for Beginners")
                 
  
    sv1.loadFromURL(url, index, bookname)

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub sv1_book_clicked(position As Int, bookId As String, bookTitle As String)
  
    Log("position = " & position)
    Log("book ID = " & bookId)
    Log("book Title = " & bookTitle)
  
  
End Sub

Library:
ShelfView
Author:
Github: Adeyinka Adediji, Wrapped by: Johan Schoeman
Version: 1
  • ShelfView
    Events:
    • book_clicked (position As Int, bookId As String, bookTitle As String)
    Fields:
    • ba As BA
    Methods:
    • BringToFront
    • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
    • Initialize (EventName As String)
    • 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)
    • loadFromURL (booksurl() As String, booksid() As String, bookname() As String)
    • onBookClicked (position As Int, bookId As String, bookTitle As String)
    Properties:
    • Background As Drawable
    • Color As Int [write only]
    • Enabled As Boolean
    • Height As Int
    • Left As Int
    • Padding()() As Int
    • Parent As Object [read only]
    • Tag As Object
    • Top As Int
    • Visible As Boolean
    • Width As Int

pic1.png


pic2.png
 

Attachments

  • ShelfViewlibFiles.zip
    19.5 KB · Views: 383
  • TheJavaCodeAndLibsFolder.zip
    134.2 KB · Views: 382
  • OtherJars.zip
    124.8 KB · Views: 366
  • b4aShelfView.zip
    239.7 KB · Views: 383

Mashiane

Expert
Licensed User
Longtime User
Very nice, I'm going to definately use this. Just my two cents. Why dont you have a single method e.g..

B4X:
AddBook(bookID as int, bookTitle as string, bookURL as string)

which will later can be used to form the arrays.

Perhaps this "long" method would help..

B4X:
public Sub List2Array (a_lstArgs As List) As String()
    Dim arrArgs(a_lstArgs.Size) As String
    For i = 0 To arrArgs.Length - 1
        arrArgs(i) = a_lstArgs.Get(i)
    Next
    Return arrArgs
End Sub

2. Can one use images from File.DirAssets perhaps?
 

Johan Schoeman

Expert
Licensed User
Longtime User
Very nice, I'm going to definately use this. Just my two cents. Why dont you have a single method e.g..

B4X:
AddBook(bookID as int, bookTitle as string, bookURL as string)

which will later can be used to form the arrays.

Perhaps this "long" method would help..

B4X:
public Sub List2Array (a_lstArgs As List) As String()
    Dim arrArgs(a_lstArgs.Size) As String
    For i = 0 To arrArgs.Length - 1
        arrArgs(i) = a_lstArgs.Get(i)
    Next
    Return arrArgs
End Sub

2. Can one use images from File.DirAssets perhaps?
The B4A event already has the position. The position is directly related to the entries in the arrays. With a slight mod to the B4A code (in the event) you can pick any of the entries in any of the arrays being passed when a book is clicked.

Yes, the lib can be amended to allow for images from File.DirAssets.
 

jahswant

Well-Known Member
Licensed User
Longtime User
This Is my Implementation. I have 2 Objects the bookModel And the shelfView Itself.
ShelfView
Version:
1.2

  • Fields:
    • book_background As Int
    • book_cover As Int
    • progressBar As Int
    • shelf_background As Int
    • spine_grey As Int
    • spine_white As Int

  • Methods:
    • areAllItemsEnabled As Boolean
    • getDropDownView (arg0 As Int, arg1 As View, arg2 As ViewGroup) As View
    • getItem (position As Int) As Object
    • getItemId (position As Int) As Long
    • getItemViewType (arg0 As Int) As Int
    • getView (position As Int, convertView As View, parent As ViewGroup) As View
    • hasStableIds As Boolean
    • isEmpty As Boolean
    • isEnabled (arg0 As Int) As Boolean
    • notifyDataSetChanged
    • notifyDataSetInvalidated
    • registerDataSetObserver (arg0 As DataSetObserver)
    • unregisterDataSetObserver (arg0 As DataSetObserver)
    Properties:
    • BookSource As Int [write only]
    • Count As Int [read only]
    • ViewTypeCount As Int [read only]

  • Properties:
    • BookCoverSource As String
    • BookId As String
    • BookTitle As String
    • Show As Boolean
    • Type As String

  • Properties:
    • BookCoverSource As String
    • BookId As String
    • BookTitle As String

  • Fields:
    • book_shelf_grid_item As Int

  • Fields:
    • grid_item_background_center As Int
    • grid_item_background_left As Int
    • grid_item_background_right As Int

  • Fields:
    • book_height As Int
    • book_width As Int
    • shelf_column_width As Int
    • shelf_list_item As Int
  • BookModel
    Methods:
    • Initialize (bookCoverSource As String, bookId As String, bookTitle As String)
    • IsInitialized As Boolean
    Properties:
    • BookCoverSource As String [write only]
    • BookId As String
    • BookTitle As String
  • ShelfView
    Events:
    • onBookClicked (Position As Int, bookId As String, bookTitle As String)
    Fields:
    • BOOK_SOURCE_ASSETS_FOLDER As Int
    • BOOK_SOURCE_DRAWABLE_FOLDER As Int
    • BOOK_SOURCE_FILE As Int
    • BOOK_SOURCE_URL As Int
    • ba As BA
    Methods:
    • AddToParent (Parent As ViewGroup, left As Int, top As Int, width As Int, height As Int)
    • BringToFront
    • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
    • Initialize (EventName As String)
    • 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)
    • loadData (bookModel As ArrayList, bookSource As Int)
      Populate shelf with books
      bookModel:
      bookSource:
    Permissions:
    • android.permission.INTERNET
    • android.permission.READ_EXTERNAL_STORAGE
    Properties:
    • Background As Drawable
    • Color As Int [write only]
    • Enabled As Boolean
    • Height As Int
    • Left As Int
    • Padding()() As Int
    • Parent As Object [read only]
    • Tag As Object
    • Top As Int
    • Visible As Boolean
    • Width As Int
 

jahswant

Well-Known Member
Licensed User
Longtime User
This is an eXample. Use Same Resources As In first Post. The Only Difference is that you do not need to check AppCompact.
B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
    #AdditionalRes:..\res
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim BookModelList As List
    'Dim BookModelList2 As List

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim Model1 As BookModel
    'Dim Model5 As BookModel
    Private ShelfView1 As ShelfView
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")
    BookModelList.Initialize

    For i = 1 To 100
        Model1.Initialize("http://eurodroid.com/pics/beginning_android_book.jpg",i,"Beginning Android")
        BookModelList.Add(Model1)
    Next
    'BookModelList2.Initialize

'    Model1.Initialize("http://eurodroid.com/pics/beginning_android_book.jpg","5","Beginning Android")
'    'Model1.BookCoverSource = "http://eurodroid.com/pics/beginning_android_book.jpg"
'    'Model1.BookId =  "1"
'    'Model1.BookTitle=  "Beginning Android"
'
'
'    Model2.Initialize("http://eurodroid.com/pics/beginning_android_book.jpg","2","Beginning Android")
'    'Model2.BookCoverSource = "http://eurodroid.com/pics/beginning_android_book.jpg"
'    'Model2.BookId =  "2"
'    'Model2.BookTitle=  "Beginning Android"
'
'
'
'    Model3.Initialize("http://eurodroid.com/pics/beginning_android_book.jpg","3","Beginning Android")
'    'Model3.BookCoverSource = "http://eurodroid.com/pics/beginning_android_book.jpg"
'    'Model3.BookId =  "3"
'    'Model3.BookTitle=  "Beginning Android"
'
'    Model4.Initialize("http://eurodroid.com/pics/beginning_android_book.jpg","4","Beginning Android")
'    'Model4.BookCoverSource = "http://eurodroid.com/pics/beginning_android_book.jpg"
'    'Model4.BookId =  "4"
'    'Model4.BookTitle=  "Beginning Android"
'
'    'Model5.Initialize("cover.jpg","5","Beginning Android")
'    'Model5.BookCoverSource = "http://eurodroid.com/pics/beginning_android_book.jpg"
'    'Model5.BookId =  "5"
'    'Model5.BookTitle=  "Beginning Android"
'
'
'
'    BookModelList.AddAll(Array As Object(Model1,Model2,Model3,Model4))

    'BookModelList2.AddAll(Array As Object(Model5))

    ShelfView1.loadData(BookModelList,ShelfView1.BOOK_SOURCE_URL)

    'ShelfView1.loadData(BookModelList2,ShelfView1.BOOK_SOURCE_ASSETS_FOLDER)

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub




Sub ShelfView1_onBookClicked(Position As Int,bookId As String,bookTitle As String)
    Log("Position = " & Position & "  bookId = " & bookId & "bookTitle = "& bookTitle)
End Sub

For COMPLETE BUNDLE
 

Attachments

  • AdditionalLibraries.zip
    21.1 KB · Views: 326
Last edited:

Beja

Expert
Licensed User
Longtime User
Thanks
Can it be more realistic shelf by arranging the books aideways? Instead of wide front vew. At this time it looks like a collection of image or list view. Side view will save space and look more realistic. You only see the spine of the book. There are many apps in the store for natural looking book shelf.
 

jahswant

Well-Known Member
Licensed User
Longtime User
Thanks
Can it be more realistic shelf by arranging the books aideways? Instead of wide front vew. At this time it looks like a collection of image or list view. Side view will save space and look more realistic. You only see the spine of the book. There are many apps in the store for natural looking book shelf.
We Just Wrap Original Views.
 
Top