B4A Library BadgedImageView

The attached project wraps this Github project. Posting the following:
1. B4A Project
2. B4A Library files (2 x jar and 1 x xml) - copy them to your additional library folder

Add your images to the Objects/res/drawable folder of the B4A project and set their property to READ ONLY.

Two wrappers:
1. Square image
2. Image as a 4:3 aspect ratio image

1.png


Some sample code:

B4X:
#Region  Project Attributes
    #ApplicationLabel: BadgedImageView
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: landscape
    #CanInstallToExternalStorage: False
#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.

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 bsiv1 As BadgedSquareImageView
    Private bsiv2 As BadgedFourThreeImageView
    Private bsiv3 As BadgedSquareImageView
    Private bsiv4 As BadgedFourThreeImageView
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")
 
    bsiv1.addImage("pluto")
    bsiv1.BadgeColor = Colors.Magenta
    bsiv2.BadgeTextSize = 15                   'set the text size before you set the text
    bsiv1.BadgeText = "MY DOG PLUTO"
    bsiv1.showBadge(True)
    bsiv1.badgeGravity = bsiv1.Gravity_START_TOP
 
    bsiv2.addImage("stitch")
    bsiv2.BadgeColor = Colors.Cyan
    bsiv2.BadgeTextSize = 15                   'set the text size before you set the text
    bsiv2.BadgeText = "MY DOG STITCH"
    bsiv2.showBadge(True) 
    bsiv2.BadgeGravity = bsiv2.Gravity_CENTER_TOP
 
    bsiv3.addImage("stitch")
    bsiv3.BadgeColor = Colors.WHITE
    bsiv3.BadgeTextSize = 25                   'set the text size before you set the text
    bsiv3.BadgeText = "STITCH"
    bsiv3.showBadge(True)
    bsiv3.badgeGravity = bsiv3.Gravity_END_BOTTOM
 
    bsiv4.addImage("pluto")
    bsiv4.BadgeColor = Colors.Green
    bsiv4.BadgeTextSize = 30                   'set the text size before you set the text
    bsiv4.BadgeText = "PLUTO"
    bsiv4.showBadge(True)
    bsiv4.badgeGravity = bsiv4.Gravity_START_BOTTOM 

 

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

The library:

BadgedImageView
Author:
Github: Yesid Lazaro, Wrapped by: Johan Schoeman
Version: 1
  • BadgedFourThreeImageView
    Fields:
    • Gravity_BOTTOM_CENTRE_HORIZONTAL As String
    • Gravity_CENTER_BOTTOM As String
    • Gravity_CENTER_TOP As String
    • Gravity_CENTER_VERTICAL_CENTRE_HORIZONTAL As String
    • Gravity_END_BOTTOM As String
    • Gravity_END_CENTRE_VERTICAL As String
    • Gravity_END_TOP As String
    • Gravity_START_BOTTOM As String
    • Gravity_START_CENTRE_VERTICAL As String
    • Gravity_START_TOP As String
    • Gravity_TOP_CENTRE_HORIZONTAL As String
    • 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)
    • addImage (draw As String)
    • showBadge (show As Boolean)
    Properties:
    • Background As Drawable
    • BadgeColor As Int [write only]
    • BadgeGravity As String [write only]
    • BadgeText As String [write only]
    • BadgeTextSize As Int [write only]
    • Color As Int [write only]
    • Enabled As Boolean
    • Height As Int
    • Left As Int
    • Tag As Object
    • Top As Int
    • Visible As Boolean
    • Width As Int
  • BadgedSquareImageView
    Fields:
    • Gravity_BOTTOM_CENTRE_HORIZONTAL As String
    • Gravity_CENTER_BOTTOM As String
    • Gravity_CENTER_TOP As String
    • Gravity_CENTER_VERTICAL_CENTRE_HORIZONTAL As String
    • Gravity_END_BOTTOM As String
    • Gravity_END_CENTRE_VERTICAL As String
    • Gravity_END_TOP As String
    • Gravity_START_BOTTOM As String
    • Gravity_START_CENTRE_VERTICAL As String
    • Gravity_START_TOP As String
    • Gravity_TOP_CENTRE_HORIZONTAL As String
    • 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)
    • addImage (draw As String)
    • showBadge (show As Boolean)
    Properties:
    • Background As Drawable
    • BadgeColor As Int [write only]
    • BadgeGravity As String [write only]
    • BadgeText As String [write only]
    • BadgeTextSize As Int [write only]
    • Color As Int [write only]
    • Enabled As Boolean
    • Height As Int
    • Left As Int
    • Tag As Object
    • Top As Int
    • Visible As Boolean
    • Width As Int
 

Attachments

  • BadgedImageViewLibFiles.zip
    28.8 KB · Views: 195
  • b4aBadgedImageView.zip
    80.9 KB · Views: 219
Top