Android Question how to put a timer in a button

piero123

Member
Licensed User
Longtime User
hi all , need some help , i have a screenshoot button but I want every 3 seconds to execute how i can do that? ty :)
B4X:
Sub btnScrShot_LongClick
    ' Take a screenshot.
    Dim Obj1, Obj2 As Reflector
    Dim bmp As Bitmap
    Dim c As Canvas
    Dim now, i As Long
    Dim dt As String
    DateTime.DateFormat = "yyMMddHHmmss"
    now = DateTime.now
    dt = DateTime.Date(now) ' e.g.: "110812150355" is Aug.12, 2011, 3:03:55 p.m.
    Obj1.Target = Obj1.GetActivityBA
    Obj1.Target = Obj1.GetField("vg")
    bmp.InitializeMutable(Activity.Width, Activity.Height)
    c.Initialize2(bmp)
    Dim args(1) As Object
    Dim types(1) As String
    Obj2.Target = c
    Obj2.Target = Obj2.GetField("canvas")
    args(0) = Obj2.Target
    types(0) = "android.graphics.Canvas"
    Obj1.RunMethod4("draw", args, types)
    Dim Out As OutputStream
    Out = File.OpenOutput(File.DirRootExternal, dt & ".png", False)
    bmp.WriteToStream(Out, 100, "PNG")
    Out.Close
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
something like this... it´s not tested... Just copied and typed it here in forumeditor... Hope it helps

B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   Dim Timer1 As Timer
End Sub
Sub Activity_Create(FirstTime As Boolean)
  Timer1.Initialize("timer",3000)
  Timer1.Enabled = false
End Sub
sub TakeScreenshot
  ' Take a screenshot.
  Dim Obj1, Obj2 AsReflector
  Dim bmp AsBitmap
  Dim c As Canvas
  Dim now, i As Long
  Dim dt AsString
  DateTime.DateFormat = "yyMMddHHmmss"
  now = DateTime.now
  dt = DateTime.Date(now) ' e.g.: "110812150355" is Aug.12, 2011, 3:03:55 p.m.
  Obj1.Target = Obj1.GetActivityBA
  Obj1.Target = Obj1.GetField("vg")
  bmp.InitializeMutable(Activity.Width, Activity.Height)
  c.Initialize2(bmp)Dim args(1) AsObjectDim types(1) AsString
  Obj2.Target = c
  Obj2.Target = Obj2.GetField("canvas")
  args(0) = Obj2.Target
  types(0) = "android.graphics.Canvas"
  Obj1.RunMethod4("draw", args, types)Dim Out AsOutputStream
  Out = File.OpenOutput(File.DirRootExternal, dt & ".png", False)
  bmp.WriteToStream(Out, 100, "PNG")
  Out.Close
end sub
Sub btnScrShot_LongClick
  TakeScreenshot
  Timer1.Enabled = true 
End Sub
Sub timer_tick
  timer1.enabled = false 
  TakeScreenshot
  timer1.enabled = true
End Sub
 
Upvote 0
Top