Android Question [Solved]Circle ProgressBar based on Timer

Schakalaka

Active Member
Licensed User
Hello. i'm looking to do something like this:

1588872732271.png



For this code i'm use a normal progressbar.
i have find this in the forum:
But the circleprogressbarr.value is a floar or a int, and i convert the datetime into string...



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



    Dim ClickTimer As Timer
   
   
End Sub

Sub Globals
    Private Circle As CircleTimerView
Private Button1 As Button
    Private TimerLabel As Label
 
    Dim StrUt As StringFunctions
    StrUt.Initialize
    Dim StartTime As Long
 
    Dim InizioTimer As Long
    Dim FineTimer As Long
   
    Dim TempoVisualizzato As Long
       
    Dim timeclick As Int
    Dim timetxt As String
    Private last As Float
    Private second As Float = 0.001745329238474369
   
    Private energyProgressBar As ProgressBar
End Sub


Sub Button1_Click

    If ClickTimer.IsInitialized = True Then
   
        Log(ConvertTicksToHHMMSSMS(TempoVisualizzato))
   
    End If
   
   
       
    StartTime = DateTime.Now
    ClickTimer.Enabled = True
    TimerLabel.Text = ConvertTicksToHHMMSSMS(TempoVisualizzato)
    Log(ConvertTicksToHHMMSSMS(TempoVisualizzato))

End Sub


Sub ConvertTicksToHHMMSSMS(Time As Long) As String
   
    Dim Diff As Long = DateTime.Now - StartTime
     
    TempoVisualizzato = InizioTimer - Diff
   
    Dim HH,MM,SS,MS As Int
    Dim T As Long=Abs(Time)
     
    If TempoVisualizzato < FineTimer Then
        ClickTimer.Enabled = False
        Return "Claim BTC"
    Else
        MS = T Mod 1000
        SS = (T/1000) Mod 60
        MM = (T/60000) Mod 60
        HH = (T/3600000) Mod 24
        Return NumberFormat(MM,2,0) & ":" & NumberFormat(SS,2,0)
        End If  
End Sub




Sub ClickTimer_Tick
    Dim sec As Float  = 0.6
   
    energyProgressBar.Progress = energyProgressBar.Progress -sec
    Log(sec)
    Log(energyProgressBar.Progress)


End Sub


Sub Circle_onTimerTick(radian As Float)
   
    Dim sec As Int = Abs(radian/second)
    Dim minutes As Int = Abs(sec/60)
    Dim seconds As Int = Abs(sec-(minutes*60))
    'Dim s As Int = Floor(radian/second/60)
   
    Log("Timer: "&NumberFormat2(minutes,2,0,0,False)&":"&NumberFormat2(seconds,2,0,0,False))

    'Log("Timer Tick: "&(radian-last))
    last = radian
   
End Sub
 
Last edited:

Schakalaka

Active Member
Licensed User
ok, thanks.


i have change class sub into:


B4X:
Private Sub DrawValue(Value As Float)
    cvs.ClearRect(cvs.TargetRect)
    cvs.DrawCircle(cx, cy, radius, clrEmpty, False, stroke)
    If myMaxMillisecs = 0 Then
        mLbl.Text = "Claim BTC"
    Else ' Show m:ss by scaling maxMilliseconds
        Dim lblMillisecs As Long = myMaxMillisecs * (Value / 100) ' Adjust code here to round up or down to next second
        mLbl.Text =    ConvertTicksToTimeString(lblMillisecs)
    End If
    Dim startAngle = -90, sweepAngle = Value / 100 * 360 As Float

    If Value < 100 Then
        Dim p As B4XPath
        p.InitializeArc(cx, cy, radius + stroke + 1dip, startAngle, sweepAngle)
        cvs.ClipPath(p)
        cvs.DrawCircle(cx, cy, radius - 0.5dip, clrFull, False, stroke + 1dip)
        cvs.RemoveClip
    Else
        cvs.DrawCircle(cx, cy, radius - 0.5dip, clrFull, False, stroke + 1dip)
    End If
    cvs.Invalidate
End Sub

Sub ConvertTicksToTimeString(t As Long) As String
    Dim  hours, minutes, seconds As Int
    hours = t / DateTime.TicksPerHour
    minutes = (t Mod DateTime.TicksPerHour) / DateTime.TicksPerMinute
    seconds = (t Mod DateTime.TicksPerMinute) / DateTime.TicksPerSecond
    Return NumberFormat(minutes, 2, 0) & ":" & NumberFormat(seconds, 2, 0)
End Sub

and now it display as "05:00"

i hav edefine myMaxMillisecs as int on class


Now i need to add a timer, so:


B4X:
(in Process_Globals)

Dim clickTimer as timer

'--------------------------------------------------------'--------------------------------------------------------'--------------------------------------------------------

(Sub Activity_Create)

clickTimer.initialize("clickTimer",5000)

'--------------------------------------------------------'--------------------------------------------------------'--------------------------------------------------------

Sub Button1_Click

    timer.Enabled = True


End Sub

'--------------------------------------------------------'--------------------------------------------------------'--------------------------------------------------------

Sub clickTimet_Tick

mLbl.Text = for each tick the timer should decrease ( 05:00-> 04:59-> 04:58-> 04:57...........00:01-> "Hello world" when the bar value is 100... :oops:šŸ˜ØšŸ‘½
(defined in clas as public)

End Sub


'--------------------------------------------------------'--------------------------------------------------------'--------------------------------------------------------

i can 't understand what i have missiong for sync timer with bar.....:oops:
 
Upvote 0

Schakalaka

Active Member
Licensed User
hello, again. after a bit of work, this is the result.
i have move the timer as service, for make it working in backend.

The current problem, is that with value as 300 (5 minutes, the bar don' t start....
 

Attachments

  • SchakaV2.zip
    11.6 KB · Views: 316
Last edited:
Upvote 0
Top