B4A Library CoverLoadingView

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

Click on the start button:
1. Click on the image once progress started to pause the progress
2. Click on the paused image to resume progress

1.png



2.png


3.png


Sample code:

B4X:
#Region  Project Attributes
    #ApplicationLabel: CoverLoadingView
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #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.
   
    Dim t1, t2 As Timer

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 clv1, clv2 As CoverView
    Dim bm1, bm2 As Bitmap
    Dim cnt1, cnt2 As Int = 0
   
    Private b1, b2 As Button

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")
    t1.Initialize("t1", 100)
    t2.Initialize("t2", 200)   
   
    bm1.Initialize(File.DirAssets,"cover.png")
    bm2.Initialize(File.DirAssets,"cover2.png")

    clv1.ShadowColor = 0x99000000
    clv1.CoverViewBitmap = bm1
    clv1.Progress = 0
   
    clv2.ShadowColor = 0x99000000
    clv2.CoverViewBitmap = bm2
    clv2.Progress = 0   
   
End Sub

Sub Activity_Resume
   

End Sub

Sub Activity_Pause (UserClosed As Boolean)
   
    t1.Enabled = False
    t2.Enabled = False

End Sub

Sub t1_tick
   
    cnt1 = cnt1 + 1
    If cnt1 < 101 Then
      Log("clv1 progress = " & cnt1)       
      clv1.Progress = cnt1    
    Else
      clv1.Progress = 101      'force finish
    End If 

End Sub

Sub t2_tick
   
    cnt2 = cnt2 + 1
    If cnt2 < 101 Then
      Log("clv2 progress = " & cnt2)       
      clv2.Progress = cnt2    
    Else
      clv2.Progress = 101      'force finish
    End If 

End Sub

Sub clv1_progress_completed
   
    clv1.resetValues
    t1.Enabled = False
    Log("clv1 done")
   
End Sub

Sub clv1_progress_paused
   
    Log("clv1 paused")
    t1.Enabled = False
   
End Sub

Sub clv1_progress_resumed
   
    Log("clv1 resumed")
    t1.Enabled = True
   
End Sub

Sub clv2_progress_completed
   
    clv2.resetValues
    t2.Enabled = False
    Log("clv2 done")
   
End Sub

Sub clv2_progress_paused
   
    Log("clv2 paused")
    t2.Enabled = False
   
End Sub

Sub clv2_progress_resumed
   
    Log("clv2 resumed")
    t2.Enabled = True
   
End Sub

Sub b1_Click
    clv1.Progress = 0
    t1.Enabled = True
   
End Sub

Sub b2_Click
    clv2.Progress = 0
    t2.Enabled = True
   
End Sub


The library:

CoverLoadingView
Author:
Github: Frank Cheng, Wrapped by: Johan Schoeman
Version: 1
  • CoverView
    Events:
    • progress_completed
    • progress_paused
    • progress_resumed
    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)
    • resetValues
    Properties:
    • Background As Drawable
    • Color As Int [write only]
    • CoverViewBitmap As Bitmap [write only]
    • Enabled As Boolean
    • Height As Int
    • Left As Int
    • Progress As Int [write only]
    • ShadowColor As Int [write only]
    • Tag As Object
    • Top As Int
    • Visible As Boolean
    • Width As Int
 

Attachments

  • CoverLoadingViewLibFiles.zip
    123.1 KB · Views: 308
  • b4aCoverLoadingView.zip
    240 KB · Views: 319
  • TheJavaCode.zip
    181.3 KB · Views: 299

Johan Schoeman

Expert
Licensed User
Longtime User
Yho!! You are the boss! Been looking for this...
Make sure you set cnt back to 0 in the ELSE statement (forgot to add it to the code in post #1):

B4X:
Sub t1_tick
  
    cnt1 = cnt1 + 1
    If cnt1 < 101 Then
      Log("clv1 progress = " & cnt1)      
      clv1.Progress = cnt1   
    Else
      clv1.Progress = 101      'force finish
      cnt1 = 0
    End If

End Sub

Sub t2_tick
  
    cnt2 = cnt2 + 1
    If cnt2 < 101 Then
      Log("clv2 progress = " & cnt2)      
      clv2.Progress = cnt2   
    Else
      clv2.Progress = 101      'force finish
     cnt2 = 0
    End If

End Sub
 
Top