B4A Library FlatTimeCollection

A warp for this Github project. It is a 3-in-1 wrapper:
Clock
Hour Glass
Count Down Timer

Copy the B4A lib files to your additional libs folder:
Posting the Java code for whoever wants to change it

b4aFlatTimeCollection.png


Sample code:
B4X:
#Region  Project Attributes
    #ApplicationLabel: b4aFlatTimeCollection
    #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 fcv, fcv1 As FlatClockView
    Private hgv As HourGlassView
    Private cdtv As CountDownTimerView
    
    Private Button1 As Button
    Private Button2 As Button
    Private Button3 As Button
    Private Button4 As Button
    Private Button5 As Button
    Private Button6 As Button
    Private Button7 As Button
    Private Button8 As Button
    Private Button9 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")

    fcv.BackgroundCircleColor = Colors.LightGray
    
    fcv.BigMarkColor = Colors.Magenta
    fcv.SmallMarkColor = Colors.White
    
    fcv.HourIndicatorColor = Colors.Red
    fcv.MinIndicatorColor = Colors.Green
    fcv.SecIndicatorColor = Colors.Cyan
    
    fcv.WithBackground = False
    
    fcv.setTimeToNow
    
    'the second clock
    fcv1.BackgroundCircleColor = Colors.LightGray
    
    fcv1.BigMarkColor = Colors.Magenta
    fcv1.SmallMarkColor = Colors.White
    
    fcv1.HourIndicatorColor = Colors.Red
    fcv1.MinIndicatorColor = Colors.Green
    fcv1.SecIndicatorColor = Colors.Cyan
    
    fcv1.WithBackground = True
    
    fcv1.setTimeToNow
    
    fcv1.setTime_2(1, 25)   
    
    'Hour Glass
    hgv.HourGlassColor = Colors.Red
    hgv.SandColor = Colors.Yellow
    hgv.ready
    
    'CountDownTimer
    cdtv.FinishMode = cdtv.FinishMode_Success
    cdtv.IndicatorColor = Colors.Red
    cdtv.RemainingTimeColor = Colors.Yellow
    cdtv.StrokeColor = Colors.Green
    cdtv.StrokeWidth = 10
    cdtv.ElapsedTimeColor = Colors.White
    
    
End Sub

Sub Activity_Resume
    

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub fcv_clock_time(hr As Int, mnt As Int, scnd As Int)
    
    Log("fcv time = " & hr & ":" & mnt & ":" & scnd)
    Log(" ")
    
End Sub

Sub fcv1_clock_time(hr As Int, mnt As Int, scnd As Int)
    
    Log("fcv1 time = " & hr & ":" & mnt & ":" & scnd)
    Log(" ")
    
End Sub

Sub hgv_hour_glass_finished()
    
    Log("Hour Glass Timed Out")
    Log("remaining time = " & hgv.RemainingTime)
    hgv.flip
    Sleep(1000)
    hgv.start(5000)
    
End Sub

Sub Button1_Click
    Button2.Text = "Pause HG"
    Log("remaining time = " & hgv.RemainingTime)
    hgv.start(5000)
    
    
End Sub

Sub Button2_Click
    
    If hgv.RemainingTime > 0  And hgv.RemainingTime < hgv.FullTime Then
        If Button2.Text = "Pause HG" Then
            hgv.pause
            Button2.Text = "Resume HG"
        Else
            hgv.pause
            Button2.Text = "Pause HG"   
        End If
    End If   
    
End Sub

Sub Button3_Click
    
    hgv.stop
    Button2.Text = "Pause HG"
    
End Sub

Sub Button4_Click
    
    hgv.ready
    Button2.Text = "Pause HG"
    
End Sub

Sub cdtv_timer_finished()
    
    Log("timer finished")
    
End Sub

Sub Button5_Click
    
    cdtv.start(4000)
    
    
End Sub

Sub Button6_Click
    
    cdtv.pause
    
End Sub

Sub Button7_Click
    
    cdtv.resume
    
End Sub

Sub Button8_Click
    
    cdtv.stop
    
End Sub

Sub Button9_Click
    
    cdtv.ready
    
End Sub

Library:
FlatTimeCollection
Author: Github: Anas Altair, Wrapped by: Johan Schoeman
Version: 1
  • CountDownTimerView
    Events:
    • timer_finished ( As )
    Fields:
    • FinishMode_Faulure As int
    • FinishMode_NoAnimation As int
      to change End Animation, Once implemented the time.
    • FinishMode_Default As int
    • FinishMode_Success As int
    • ba As anywheresoftware.b4a.BA
    Methods:
    • DesignerCreateView (base As anywheresoftware.b4a.objects.PanelWrapper, lw As anywheresoftware.b4a.objects.LabelWrapper, props As anywheresoftware.b4a.objects.collections.Map) As void
    • IsInitialized As boolean
    • Initialize (ba As anywheresoftware.b4a.BA, EventName As java.lang.String) As void
    • BringToFront As void
    • SetLayout (arg0 As int, arg1 As int, arg2 As int, arg3 As int) As void
    • ready As void
    • isCountDownTimerRunning As boolean
    • SendToBack As void
    • SetVisibleAnimated (arg0 As int, arg1 As boolean) As void
    • resume As void
      Resumes a paused CountDownTimer, causing the CountDownTimer to pick up where it left off
      when it was paused. This method should only be called on the same thread on
      which the CountDownTimer was started. Calls to resume() on an CountDownTimer that is
      not currently paused will be ignored.
    • isPaused As boolean
      Returns whether this CountDownTimer is currently in a paused state.
      Return type: @return:True if the CountDownTimer is currently paused, false otherwise.
    • RemoveView As void
    • Invalidate3 (arg0 As int, arg1 As int, arg2 As int, arg3 As int) As void
    • start (timeInMillisecond As long) As void
      start the CountDownTimer.
      this well stop CountDownTimer if it was running.
      timeInMillisecond: time in Millisecond.
    • Invalidate2 (arg0 As android.graphics.Rect) As void
    • SetColorAnimated (arg0 As int, arg1 As int, arg2 As int) As void
    • failed As void
    • SetBackgroundImageNew (arg0 As android.graphics.Bitmap) As anywheresoftware.b4a.objects.drawable.BitmapDrawable
    • pause As void
      Pauses a running CountDownTimer. This method should only be called on the same thread on
      which the CountDownTimer was started. If the CountDownTimer has not yet been {@link
      #start(long)} started} or has since ended, then the call is ignored. Paused
      CountDownTimer can be resumed by calling {@link #resume()}.
    • stop As void
      Ends the CountDownTimer. this will not call
      {@link OnTimeFinish#onFinish()} method on
      its listeners.
    • success As void
      stop the CountDownTimer and start success Animation.
      this will called {@link OnTimeFinish#onFinish()} method on
      its listeners which set By {@link #setOnEndAnimationFinish(OnTimeFinish)}.

      <p>this method will change finish mode to Success.</p>
    • failure As void
      stop the CountDownTimer and start failure Animation.
      this will called {@link OnTimeFinish#onFinish()} method on
      its listeners which set By {@link #setOnEndAnimationFinish(OnTimeFinish)}.

      <p>this method will change finish mode to Failure.</p>
    • Invalidate As void
    • SetLayoutAnimated (arg0 As int, arg1 As int, arg2 As int, arg3 As int, arg4 As int) As void
    • RequestFocus As boolean
    Properties:
    • Left As int
    • Background As android.graphics.drawable.Drawable
    • RemainingTimeColor As int [write only]
    • Parent As java.lang.Object [read only]
    • FinishMode As int
    • Color As int [write only]
    • RemainingTime As long [read only]
      Time that remains.
    • ElapsedTime As long [read only]
      The time that has elapsed.
    • Enabled As boolean
    • StrokeColor As int [write only]
    • FullTime As long [read only]
      The full time that you set by {@link #start(long)} method.
      Or default: 1000.
    • IndicatorColor As int [write only]
    • ElapsedTimeColor As int [write only]
    • Top As int
    • StrokeWidth As float [write only]
    • Visible As boolean
    • Padding As int[]
    • Height As int
    • Tag As java.lang.Object
    • Width As int

  • Methods:
    • valueOf (name As java.lang.String) As flattimecollectionwrapper.countdowntimerviewWrapper.FinishMode
    • hashCode As int
    • values As flattimecollectionwrapper.countdowntimerviewWrapper.FinishMode[]
    • equals (arg0 As java.lang.Object) As boolean
    • name As java.lang.String
    • clone As java.lang.Object
    • toString As java.lang.String
    • finalize As void
    • compareTo (arg0 As E) As int
    • ordinal As int
    Properties:
    • DeclaringClass As java.lang.Class [read only]
  • FlatClockView
    Events:
    • clock_time (hr As Int, mnt As Int, scnd As Int)
    Fields:
    • ba As anywheresoftware.b4a.BA
    Methods:
    • DesignerCreateView (base As anywheresoftware.b4a.objects.PanelWrapper, lw As anywheresoftware.b4a.objects.LabelWrapper, props As anywheresoftware.b4a.objects.collections.Map) As void
    • IsInitialized As boolean
    • Initialize (ba As anywheresoftware.b4a.BA, EventName As java.lang.String) As void
    • BringToFront As void
    • SetLayout (arg0 As int, arg1 As int, arg2 As int, arg3 As int) As void
    • SendToBack As void
    • setTimeToNow As void
    • SetVisibleAnimated (arg0 As int, arg1 As boolean) As void
    • RemoveView As void
    • Invalidate3 (arg0 As int, arg1 As int, arg2 As int, arg3 As int) As void
    • Invalidate2 (arg0 As android.graphics.Rect) As void
    • SetColorAnimated (arg0 As int, arg1 As int, arg2 As int) As void
    • SetBackgroundImageNew (arg0 As android.graphics.Bitmap) As anywheresoftware.b4a.objects.drawable.BitmapDrawable
    • Invalidate As void
    • setTime_2 (hour As int, minute As int) As void
      to set custom Time.
      hour: should be between {0,11}
      minute: should be between {0,59}
    • setTime_4 (hour As int, minute As int, second As int) As void
      to set custom Time.
      hour: should be between {0,11}
      minute: should be between {0,59}
      second: should be between {0,59}
    • SetLayoutAnimated (arg0 As int, arg1 As int, arg2 As int, arg3 As int, arg4 As int) As void
    • RequestFocus As boolean
    Properties:
    • BackgroundCircleColor As int [write only]
    • Left As int
    • Background As android.graphics.drawable.Drawable
    • Parent As java.lang.Object [read only]
    • Color As int [write only]
    • MinIndicatorColor As int [write only]
    • Enabled As boolean
    • Time_1 As int [write only]
      to set custom Time.
    • SmallMarkColor As int [write only]
    • Time_3 As java.lang.String [write only]
      to set custom Time.
    • HourIndicatorColor As int [write only]
    • SecIndicatorColor As int [write only]
    • Top As int
    • Visible As boolean
    • BigMarkColor As int [write only]
    • Padding As int[]
    • WithBackground As boolean [write only]
    • Height As int
    • Tag As java.lang.Object
    • Width As int
  • HourGlassView
    Events:
    • hour_glass_finished ( As )
    Fields:
    • ba As anywheresoftware.b4a.BA
    Methods:
    • DesignerCreateView (base As anywheresoftware.b4a.objects.PanelWrapper, lw As anywheresoftware.b4a.objects.LabelWrapper, props As anywheresoftware.b4a.objects.collections.Map) As void
    • IsInitialized As boolean
    • Initialize (ba As anywheresoftware.b4a.BA, EventName As java.lang.String) As void
    • BringToFront As void
    • SetLayout (arg0 As int, arg1 As int, arg2 As int, arg3 As int) As void
    • ready As void
    • SendToBack As void
    • flip As void
    • SetVisibleAnimated (arg0 As int, arg1 As boolean) As void
    • canFlip As boolean
      use if you need to check if HourGlass can flip or not.
      Return type: @return:{@code true} if HourGlass doesn't flipping
      or doesn't started yet, {@code false} otherwise.
    • RemoveView As void
    • Invalidate3 (arg0 As int, arg1 As int, arg2 As int, arg3 As int) As void
    • start (timeInMillisecond As long) As void
    • Invalidate2 (arg0 As android.graphics.Rect) As void
    • SetColorAnimated (arg0 As int, arg1 As int, arg2 As int) As void
    • SetBackgroundImageNew (arg0 As android.graphics.Bitmap) As anywheresoftware.b4a.objects.drawable.BitmapDrawable
    • pause As void
    • stop As void
      Ends the HourGlass. this will not call
      {@link OnTimeFinish#onFinish()} method on
      its listeners.
    • isFlipping As boolean

      Return type: @return:{@code true} if HourGlass doing flip, {@code false} otherwise.
    • Invalidate As void
    • SetLayoutAnimated (arg0 As int, arg1 As int, arg2 As int, arg3 As int, arg4 As int) As void
    • RequestFocus As boolean
    Properties:
    • Left As int
    • Background As android.graphics.drawable.Drawable
    • Parent As java.lang.Object [read only]
    • SandColor As int [write only]
    • Color As int [write only]
    • RemainingTime As long [read only]
      Time that remains.
    • ElapsedTime As long [read only]
      The time that has elapsed.
    • Enabled As boolean
    • FullTime As long [read only]
      The full time that you set by {@link #start(long)} method.
    • Top As int
    • Visible As boolean
    • Padding As int[]
    • Height As int
    • Tag As java.lang.Object
    • HourGlassColor As int [write only]
    • Width As int
 

Attachments

  • b4aFlatTimeCollection.zip
    10.3 KB · Views: 290
  • b4aLibFiles.zip
    37.6 KB · Views: 270
  • TheJavaCode.zip
    19.3 KB · Views: 311
Top