kandi background
Explore Kits

timer2 | timer2 is an evented timer | Date Time Utils library

 by   thenativeweb JavaScript Version: Current License: No License

 by   thenativeweb JavaScript Version: Current License: No License

Download this library from

kandi X-RAY | timer2 Summary

timer2 is a JavaScript library typically used in Utilities, Date Time Utils applications. timer2 has no bugs, it has no vulnerabilities and it has low support. You can install using 'npm i timer2' or download it from GitHub, npm.
timer2 is an evented timer.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • timer2 has a low active ecosystem.
  • It has 7 star(s) with 3 fork(s). There are 4 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 0 open issues and 4 have been closed. On average issues are closed in 198 days. There are no pull requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of timer2 is current.
timer2 Support
Best in #Date Time Utils
Average in #Date Time Utils
timer2 Support
Best in #Date Time Utils
Average in #Date Time Utils

quality kandi Quality

  • timer2 has 0 bugs and 0 code smells.
timer2 Quality
Best in #Date Time Utils
Average in #Date Time Utils
timer2 Quality
Best in #Date Time Utils
Average in #Date Time Utils

securitySecurity

  • timer2 has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • timer2 code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
timer2 Security
Best in #Date Time Utils
Average in #Date Time Utils
timer2 Security
Best in #Date Time Utils
Average in #Date Time Utils

license License

  • timer2 does not have a standard license declared.
  • Check the repository for any license declaration and review the terms closely.
  • Without a license, all rights are reserved, and you cannot use the library in your applications.
timer2 License
Best in #Date Time Utils
Average in #Date Time Utils
timer2 License
Best in #Date Time Utils
Average in #Date Time Utils

buildReuse

  • timer2 releases are not available. You will need to build from source code and install.
  • Deployable package is available in npm.
  • Installation instructions, examples and code snippets are available.
timer2 Reuse
Best in #Date Time Utils
Average in #Date Time Utils
timer2 Reuse
Best in #Date Time Utils
Average in #Date Time Utils
Top functions reviewed by kandi - BETA

kandi has reviewed timer2 and discovered the below as its top functions. This is intended to give you an instant insight into timer2 implemented functionality, and help decide if they suit your requirements.

  • Timer class
  • Define properties on a Object
  • Call a constructor method
  • Returns the result of the constructor if this method does not already have a call to the constructor .
  • Inherit one class into another

timer2 Key Features

timer2 is an evented timer.

Installation

copy iconCopydownload iconDownload
$ npm install timer2

Quick start

copy iconCopydownload iconDownload
const Timer = require('timer2');

Creating immediate timers

copy iconCopydownload iconDownload
const timer = new Timer(100, {
  immediate: true
});

Creating wobbling timers

copy iconCopydownload iconDownload
const timer = new Timer(2000, {
  variation: 500
});

Stopping and restarting timers

copy iconCopydownload iconDownload
timer.stop();

Destroying timers

copy iconCopydownload iconDownload
timer.stop();
timer.removeAllListeners();

Running the build

copy iconCopydownload iconDownload
$ bot

Do not reset a timer after a pause/resume when it has already ended (difficult to explain)

copy iconCopydownload iconDownload
Boolean startTimer = true;
Timer2 = new CountDownTimer(...){
   ....
     @Override
     public void onFinish() {
      ....
      startTimer = false;
     }
                
                    
protected void onResume(){
   ...
   if(startTimer){
       Timer2.start()
   }
}
-----------------------
Boolean startTimer = true;
Timer2 = new CountDownTimer(...){
   ....
     @Override
     public void onFinish() {
      ....
      startTimer = false;
     }
                
                    
protected void onResume(){
   ...
   if(startTimer){
       Timer2.start()
   }
}
-----------------------
Boolean startTimer = true;
Timer2 = new CountDownTimer(...){
   ....
     @Override
     public void onFinish() {
      ....
      startTimer = false;
     }
                
                    
protected void onResume(){
   ...
   if(startTimer){
       Timer2.start()
   }
}

How to Save and retrieve 24hrs Countdown timer to Local.Storage

copy iconCopydownload iconDownload
     if(hours <= 0 && minutes == 0 && seconds == 0){
         // if you want to delete it on local storage
         localStorage.removeItem('timer');
         console.log('Transaction Cancelled')
     }
     else{
         $('#remainingTime').html(timer2);
         // if you want to save it on local storage
         localStorage.setItem('timer', timer2.toString());
     }
-----------------------
//  this code set time to 24 hrs
let duration = luxon.Duration.fromObject({
  days: 1
});

var interval;

function tick() {
  let remaining = localStorage.getItem("interval") || duration.toMillis();

  remaining -= 1000;

  let d = luxon.Duration.fromMillis(remaining);
  console.log(d.toHuman());

  localStorage.setItem("interval", remaining);
}

function onLoad() {
  var interval = setInterval(tick, 1000);

  console.log("Timer Started");
}

function onUnLoad() {
  cancelInterval(interval);

  console.log("Timer Stopped");
}

onLoad();
onUnLoad();
<script src="https://moment.github.io/luxon/global/luxon.min.js"></script>
-----------------------
//  this code set time to 24 hrs
let duration = luxon.Duration.fromObject({
  days: 1
});

var interval;

function tick() {
  let remaining = localStorage.getItem("interval") || duration.toMillis();

  remaining -= 1000;

  let d = luxon.Duration.fromMillis(remaining);
  console.log(d.toHuman());

  localStorage.setItem("interval", remaining);
}

function onLoad() {
  var interval = setInterval(tick, 1000);

  console.log("Timer Started");
}

function onUnLoad() {
  cancelInterval(interval);

  console.log("Timer Stopped");
}

onLoad();
onUnLoad();
<script src="https://moment.github.io/luxon/global/luxon.min.js"></script>

How to add DateTimePicker value to Current Time

copy iconCopydownload iconDownload
 Dim UserTime As String()
 UserTime = Duration.Text.Split(':')
 AlarmTimeLBL.Text = DateTime.Now.AddHours(UserTime(0)).AddMinutes(UserTime(1)).AddSeconds(UserTime(2))
-----------------------
Private setTime As DateTime

Private Sub AlarmTimerFRM_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    UpdateCurrentTime()
    outCurrentTimeLBL.BackColor = Color.LightGray
    Timer1.Start()
    setTimerDTP.Format = DateTimePickerFormat.Custom
    setTimerDTP.CustomFormat = "HH:mm:ss"
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    UpdateCurrentTime()
End Sub

Private Sub UpdateCurrentTime()
    outCurrentTimeLBL.Text = DateTime.Now.ToString("hh:mm:ss tt")
End Sub

Private Sub SetBTN_Click(sender As Object, e As EventArgs) Handles SetBTN.Click
    setTime = DateTime.Now.Add(setTimerDTP.Value.TimeOfDay)
    AlarmTimeLBL.Text = setTime.ToString("hh:mm:ss tt")
    SetBTN.Enabled = False
    setTimerDTP.Enabled = False
    Timer2.Start()
End Sub

Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
    If DateTime.Now >= setTime Then
        Timer2.Stop()
        MessageBox.Show("Alarm time reached!")
        SetBTN.Enabled = True
        setTimerDTP.Enabled = True
    End If
End Sub

Does changing widget stylesheets using properties work in Qt6 (it did in Qt5)?

copy iconCopydownload iconDownload
    def set_property(self, style_red):
        self.label.setProperty('StyleRed', style_red)
        app.setStyleSheet(app.styleSheet())
    def set_property(self, style_red):
        self.label.setProperty('StyleRed', style_red)
        old = self.label.styleSheet()
        if not old:
            self.label.setStyleSheet('* {}')
        self.label.setStyleSheet(old)
-----------------------
    def set_property(self, style_red):
        self.label.setProperty('StyleRed', style_red)
        app.setStyleSheet(app.styleSheet())
    def set_property(self, style_red):
        self.label.setProperty('StyleRed', style_red)
        old = self.label.styleSheet()
        if not old:
            self.label.setStyleSheet('* {}')
        self.label.setStyleSheet(old)

C++ Linux fastest way to measure time (faster than std::chrono) ? Benchmark included

copy iconCopydownload iconDownload
#include <iostream>
#include <cstdio>

void dosomething() {
    // yada yada
}

int main() {
    double sum = 0;
    const uint32_t numloops = 100000000;
    for ( uint32_t j=0; j<numloops; ++j ) {
        uint64_t t0 = __builtin_ia32_rdtsc();
        dosomething();
        uint64_t t1 = __builtin_ia32_rdtsc();
        uint64_t elapsed = t1-t0;
        sum += elapsed;
    }
    std::cout << "Average:" << sum/numloops << std::endl;
}

ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings] if (ser.find(&quot;Error&quot;)){

copy iconCopydownload iconDownload
ser.find((char*) "Error")

Using reduce to change struct in Swift

copy iconCopydownload iconDownload
@State var timer1 = CountdownTimer()
@State var timer2 = CountdownTimer()
@State var timer3 = CountdownTimer()
@State var timer4 = CountdownTimer()
var timer = timer1
timer.isActive = true
let timer = \Self.timer1  // Note capital Self
self[keyPath: timer].isActive = true
zip(timers, timers.cycled().dropFirst())
(value1, value2)
(value2, value3)
(value3, value4)
(value4, value1)
let timers = [\Self.timer1, \.timer2, \.timer3, \.timer4]

if let (current, next) = zip(timers, timers.cycled().dropFirst())
    .first(where: { self[keyPath: $0.0].isActive })
{
    self[keyPath: current].isActive = false
    self[keyPath: next].isActive = true
}
class TimerBank: ObservableObject {
    @Published private(set) var timers: [CGFloat] = []
    @Published private(set) var active: Int?
    var count: Int { timers.count }

    init(timers: [CGFloat]) {
        self.timers = timers
        self.active = timers.startIndex
    }

    func addTimer(timeRemaining: CGFloat = 1000) {
        timers.append(timeRemaining)
    }

    func start(index: Int? = nil) {
        if let index = index {
            active = index
        } else {
            active = timers.startIndex
        }
    }

    func stop() {
        active = nil
    }

    func cycle() {
        if let currentActive = active {
            active = (currentActive + 1) % timers.count
            print("active = \(active)")
        } else {
            active = timers.startIndex
            print("(init) active = \(active)")
        }
    }
}
-----------------------
@State var timer1 = CountdownTimer()
@State var timer2 = CountdownTimer()
@State var timer3 = CountdownTimer()
@State var timer4 = CountdownTimer()
var timer = timer1
timer.isActive = true
let timer = \Self.timer1  // Note capital Self
self[keyPath: timer].isActive = true
zip(timers, timers.cycled().dropFirst())
(value1, value2)
(value2, value3)
(value3, value4)
(value4, value1)
let timers = [\Self.timer1, \.timer2, \.timer3, \.timer4]

if let (current, next) = zip(timers, timers.cycled().dropFirst())
    .first(where: { self[keyPath: $0.0].isActive })
{
    self[keyPath: current].isActive = false
    self[keyPath: next].isActive = true
}
class TimerBank: ObservableObject {
    @Published private(set) var timers: [CGFloat] = []
    @Published private(set) var active: Int?
    var count: Int { timers.count }

    init(timers: [CGFloat]) {
        self.timers = timers
        self.active = timers.startIndex
    }

    func addTimer(timeRemaining: CGFloat = 1000) {
        timers.append(timeRemaining)
    }

    func start(index: Int? = nil) {
        if let index = index {
            active = index
        } else {
            active = timers.startIndex
        }
    }

    func stop() {
        active = nil
    }

    func cycle() {
        if let currentActive = active {
            active = (currentActive + 1) % timers.count
            print("active = \(active)")
        } else {
            active = timers.startIndex
            print("(init) active = \(active)")
        }
    }
}
-----------------------
@State var timer1 = CountdownTimer()
@State var timer2 = CountdownTimer()
@State var timer3 = CountdownTimer()
@State var timer4 = CountdownTimer()
var timer = timer1
timer.isActive = true
let timer = \Self.timer1  // Note capital Self
self[keyPath: timer].isActive = true
zip(timers, timers.cycled().dropFirst())
(value1, value2)
(value2, value3)
(value3, value4)
(value4, value1)
let timers = [\Self.timer1, \.timer2, \.timer3, \.timer4]

if let (current, next) = zip(timers, timers.cycled().dropFirst())
    .first(where: { self[keyPath: $0.0].isActive })
{
    self[keyPath: current].isActive = false
    self[keyPath: next].isActive = true
}
class TimerBank: ObservableObject {
    @Published private(set) var timers: [CGFloat] = []
    @Published private(set) var active: Int?
    var count: Int { timers.count }

    init(timers: [CGFloat]) {
        self.timers = timers
        self.active = timers.startIndex
    }

    func addTimer(timeRemaining: CGFloat = 1000) {
        timers.append(timeRemaining)
    }

    func start(index: Int? = nil) {
        if let index = index {
            active = index
        } else {
            active = timers.startIndex
        }
    }

    func stop() {
        active = nil
    }

    func cycle() {
        if let currentActive = active {
            active = (currentActive + 1) % timers.count
            print("active = \(active)")
        } else {
            active = timers.startIndex
            print("(init) active = \(active)")
        }
    }
}
-----------------------
@State var timer1 = CountdownTimer()
@State var timer2 = CountdownTimer()
@State var timer3 = CountdownTimer()
@State var timer4 = CountdownTimer()
var timer = timer1
timer.isActive = true
let timer = \Self.timer1  // Note capital Self
self[keyPath: timer].isActive = true
zip(timers, timers.cycled().dropFirst())
(value1, value2)
(value2, value3)
(value3, value4)
(value4, value1)
let timers = [\Self.timer1, \.timer2, \.timer3, \.timer4]

if let (current, next) = zip(timers, timers.cycled().dropFirst())
    .first(where: { self[keyPath: $0.0].isActive })
{
    self[keyPath: current].isActive = false
    self[keyPath: next].isActive = true
}
class TimerBank: ObservableObject {
    @Published private(set) var timers: [CGFloat] = []
    @Published private(set) var active: Int?
    var count: Int { timers.count }

    init(timers: [CGFloat]) {
        self.timers = timers
        self.active = timers.startIndex
    }

    func addTimer(timeRemaining: CGFloat = 1000) {
        timers.append(timeRemaining)
    }

    func start(index: Int? = nil) {
        if let index = index {
            active = index
        } else {
            active = timers.startIndex
        }
    }

    func stop() {
        active = nil
    }

    func cycle() {
        if let currentActive = active {
            active = (currentActive + 1) % timers.count
            print("active = \(active)")
        } else {
            active = timers.startIndex
            print("(init) active = \(active)")
        }
    }
}
-----------------------
@State var timer1 = CountdownTimer()
@State var timer2 = CountdownTimer()
@State var timer3 = CountdownTimer()
@State var timer4 = CountdownTimer()
var timer = timer1
timer.isActive = true
let timer = \Self.timer1  // Note capital Self
self[keyPath: timer].isActive = true
zip(timers, timers.cycled().dropFirst())
(value1, value2)
(value2, value3)
(value3, value4)
(value4, value1)
let timers = [\Self.timer1, \.timer2, \.timer3, \.timer4]

if let (current, next) = zip(timers, timers.cycled().dropFirst())
    .first(where: { self[keyPath: $0.0].isActive })
{
    self[keyPath: current].isActive = false
    self[keyPath: next].isActive = true
}
class TimerBank: ObservableObject {
    @Published private(set) var timers: [CGFloat] = []
    @Published private(set) var active: Int?
    var count: Int { timers.count }

    init(timers: [CGFloat]) {
        self.timers = timers
        self.active = timers.startIndex
    }

    func addTimer(timeRemaining: CGFloat = 1000) {
        timers.append(timeRemaining)
    }

    func start(index: Int? = nil) {
        if let index = index {
            active = index
        } else {
            active = timers.startIndex
        }
    }

    func stop() {
        active = nil
    }

    func cycle() {
        if let currentActive = active {
            active = (currentActive + 1) % timers.count
            print("active = \(active)")
        } else {
            active = timers.startIndex
            print("(init) active = \(active)")
        }
    }
}
-----------------------
@State var timer1 = CountdownTimer()
@State var timer2 = CountdownTimer()
@State var timer3 = CountdownTimer()
@State var timer4 = CountdownTimer()
var timer = timer1
timer.isActive = true
let timer = \Self.timer1  // Note capital Self
self[keyPath: timer].isActive = true
zip(timers, timers.cycled().dropFirst())
(value1, value2)
(value2, value3)
(value3, value4)
(value4, value1)
let timers = [\Self.timer1, \.timer2, \.timer3, \.timer4]

if let (current, next) = zip(timers, timers.cycled().dropFirst())
    .first(where: { self[keyPath: $0.0].isActive })
{
    self[keyPath: current].isActive = false
    self[keyPath: next].isActive = true
}
class TimerBank: ObservableObject {
    @Published private(set) var timers: [CGFloat] = []
    @Published private(set) var active: Int?
    var count: Int { timers.count }

    init(timers: [CGFloat]) {
        self.timers = timers
        self.active = timers.startIndex
    }

    func addTimer(timeRemaining: CGFloat = 1000) {
        timers.append(timeRemaining)
    }

    func start(index: Int? = nil) {
        if let index = index {
            active = index
        } else {
            active = timers.startIndex
        }
    }

    func stop() {
        active = nil
    }

    func cycle() {
        if let currentActive = active {
            active = (currentActive + 1) % timers.count
            print("active = \(active)")
        } else {
            active = timers.startIndex
            print("(init) active = \(active)")
        }
    }
}
-----------------------
@State var timer1 = CountdownTimer()
@State var timer2 = CountdownTimer()
@State var timer3 = CountdownTimer()
@State var timer4 = CountdownTimer()
var timer = timer1
timer.isActive = true
let timer = \Self.timer1  // Note capital Self
self[keyPath: timer].isActive = true
zip(timers, timers.cycled().dropFirst())
(value1, value2)
(value2, value3)
(value3, value4)
(value4, value1)
let timers = [\Self.timer1, \.timer2, \.timer3, \.timer4]

if let (current, next) = zip(timers, timers.cycled().dropFirst())
    .first(where: { self[keyPath: $0.0].isActive })
{
    self[keyPath: current].isActive = false
    self[keyPath: next].isActive = true
}
class TimerBank: ObservableObject {
    @Published private(set) var timers: [CGFloat] = []
    @Published private(set) var active: Int?
    var count: Int { timers.count }

    init(timers: [CGFloat]) {
        self.timers = timers
        self.active = timers.startIndex
    }

    func addTimer(timeRemaining: CGFloat = 1000) {
        timers.append(timeRemaining)
    }

    func start(index: Int? = nil) {
        if let index = index {
            active = index
        } else {
            active = timers.startIndex
        }
    }

    func stop() {
        active = nil
    }

    func cycle() {
        if let currentActive = active {
            active = (currentActive + 1) % timers.count
            print("active = \(active)")
        } else {
            active = timers.startIndex
            print("(init) active = \(active)")
        }
    }
}
-----------------------
let timers = [\Self.timer1, \.timer2, \.timer3, \.timer4]

if let onIndex = timers.firstIndex(where: { self[keyPath: $0].isActive }) {
    self[keyPath: timers[onIndex]].isActive = false

    let nextIndex = (onIndex + 1) % 4 // instead of 4, could use timers.count
    self[keyPath: timers[nextIndex]].isActive = true
}

Click the button only when the time is zero in Jquery html?

copy iconCopydownload iconDownload
const btnSendActive = document.getElementById('Send_Active');

function buttonClicked() {
  btnSendActive.removeEventListener('click', buttonClicked);
  enableButton();
  alert('ok');
}

function enableButton() {

  var timer2 = "00:03";

  var interval = setInterval(function() {
    var timer = timer2.split(':');
    var minutes = parseInt(timer[0], 10);
    var seconds = parseInt(timer[1], 10);

    --seconds;
    minutes = (seconds < 0) ? --minutes : minutes;
    if (minutes < 0) clearInterval(interval);
    seconds = (seconds < 0) ? 59 : seconds;

    $('.countdown').html(minutes + ':' + seconds);
    timer2 = minutes + ':' + seconds;
    if (minutes == 0 && seconds == 0) {
      clearInterval(interval);
      btnSendActive.addEventListener('click', buttonClicked);
    }
  }, 1000);

}

enableButton();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="form-group">
  <div id="countdown" class="countdown"></div>
</div>
<div class="form-group">
  <a id="Send_Active">send again</a>
</div>
-----------------------
const btnSendActive = document.getElementById('Send_Active');

function buttonClicked() {
  btnSendActive.removeEventListener('click', buttonClicked);
  enableButton();
  alert('ok');
}

function enableButton() {

  var timer2 = "00:03";

  var interval = setInterval(function() {
    var timer = timer2.split(':');
    var minutes = parseInt(timer[0], 10);
    var seconds = parseInt(timer[1], 10);

    --seconds;
    minutes = (seconds < 0) ? --minutes : minutes;
    if (minutes < 0) clearInterval(interval);
    seconds = (seconds < 0) ? 59 : seconds;

    $('.countdown').html(minutes + ':' + seconds);
    timer2 = minutes + ':' + seconds;
    if (minutes == 0 && seconds == 0) {
      clearInterval(interval);
      btnSendActive.addEventListener('click', buttonClicked);
    }
  }, 1000);

}

enableButton();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="form-group">
  <div id="countdown" class="countdown"></div>
</div>
<div class="form-group">
  <a id="Send_Active">send again</a>
</div>

&quot;The call stack contains only external code&quot; error

copy iconCopydownload iconDownload
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim pfc As PrivateFontCollection = New PrivateFontCollection
    pfc.AddFontFile("digital-7 (italic).ttf")
    Label2.Font = New Font(pfc.Families(0), 30.0F, FontStyle.Regular)
    Label2.ForeColor = Color.Black
    Dim pfc2 As PrivateFontCollection = New PrivateFontCollection
    pfc2.AddFontFile("digital-7.ttf")
    Label1.Font = New Font(pfc2.Families(0), 26.0F, FontStyle.Regular)
    Label1.ForeColor = Color.Black
    BtnCase.Hide()
    BtnOn.Hide()
    HideControls()
End Sub

Private Sub ButtonClickMethod(sender As Object, e As EventArgs) Handles BtnCase.Click, BtnVer.Click, BtnOff.Click, BtnOn.Click, BtnExp.Click, BtnCube.Click, BtnFact.Click, BtnSqrt.Click, Num7.Click, Num8.Click, Num9.Click, BtnDel.Click, BtnAC.Click, Num4.Click, Num5.Click, Num6.Click, BtnMult.Click, BtnDiv.Click, Num1.Click, Num2.Click, Num3.Click, BtnAdd.Click, BtnSub.Click, Num0.Click, BtnPi.Click, BtnSqrd.Click, BtnDot.Click, BtnEql.Click, BtnUp.Click, BtnDown.Click, BtnLeft.Click, BtnRight.Click
    Dim btn As Button = CType(sender, Button)
    Select Case btn.Name
        Case "BtnCase"
            Timer2.Enabled = True
            BtnCase.Hide()
            BtnOn.Hide()
            HideControls()
        Case "BtnVer"
            Label1.Text = ""
            Label2.Text = "WE BARE BEARS"
        Case "BtnOff"
            Label1.Text = ""
                Label2.Text = "CASEO"
                Timer1.Enabled = True
                HideControls()
        Case "BtnOn"
            Label1.Text = ""
                Label2.Text = 0
                BtnVer.Show()
                BtnOff.Show()
                BtnExp.Show()
                BtnCube.Show()
                BtnFact.Show()
                BtnSqrt.Show()
                Num7.Show()
                Num8.Show()
                Num9.Show()
                BtnDel.Show()
                BtnAC.Show()
                Num4.Show()
                Num5.Show()
                Num6.Show()
                BtnMult.Show()
                BtnDiv.Show()
                Num1.Show()
                Num2.Show()
                Num3.Show()
                BtnAdd.Show()
                BtnSub.Show()
                Num0.Show()
                BtnPi.Show()
                BtnSqrd.Show()
                BtnDot.Show()
                BtnEql.Show()
                BtnUp.Show()
                BtnDown.Show()
                BtnLeft.Show()
                BtnRight.Show()
        Case "BtnExp"
            Label1.Text &= "^"
        Case "BtnCube"
            Label1.Text &= "^3"
        Case "BtnFact"
            Label1.Text &= "!"
        Case "BtnSqrt"
            Label1.Text &= "√"
        Case "Num7"
            Label1.Text &= "7"
        Case "Num8"
            Label1.Text &= "8"
        Case "Num9"
            Label1.Text &= "9"
        Case "Num4"
            Label1.Text &= "4"
        Case "Num5"
            Label1.Text &= "5"
        Case "Num6"
            Label1.Text &= "6"
        Case "BtnMult"
            Label1.Text &= "×"
        Case "BtnDiv"
            Label1.Text &= "÷"
        Case "Num1"
            Label1.Text &= "1"
        Case "Num2"
            Label1.Text &= "2"
        Case "Num3"
            Label1.Text &= "3"
        Case "BtnAdd"
            Label1.Text &= "+"
        Case "BtnSub"
            Label1.Text &= "-"
        Case "Num0"
            Label1.Text &= "0"
        Case "BtnPi"
            Label1.Text &= "π"
        Case "BtnSqrd"
            Label1.Text &= "^2"
        Case "BtnDot"
            Label1.Text &= "."
        Case "BtnEql"
            Label1.Text &= "="
    End Select
End Sub

Private Sub HideControls()
    BtnVer.Hide()
    BtnOff.Hide()
    BtnExp.Hide()
    BtnCube.Hide()
    BtnFact.Hide()
    BtnSqrt.Hide()
    Num7.Hide()
    Num8.Hide()
    Num9.Hide()
    BtnDel.Hide()
    BtnAC.Hide()
    Num4.Hide()
    Num5.Hide()
    Num6.Hide()
    BtnMult.Hide()
    BtnDiv.Hide()
    Num1.Hide()
    Num2.Hide()
    Num3.Hide()
    BtnAdd.Hide()
    BtnSub.Hide()
    Num0.Hide()
    BtnPi.Hide()
    BtnSqrd.Hide()
    BtnDot.Hide()
    BtnEql.Hide()
    BtnUp.Hide()
    BtnDown.Hide()
    BtnLeft.Hide()
    BtnRight.Hide()
End Sub
Private Sub ButtonClickMethod(sender As Object, e As EventArgs) Handles BtnCase.Click, BtnVer.Click, BtnOff.Click, BtnOn.Click, BtnExp.Click, BtnCube.Click, BtnFact.Click, BtnSqrt.Click, Num7.Click, Num8.Click, Num9.Click, BtnDel.Click, BtnAC.Click, Num4.Click, Num5.Click, Num6.Click, BtnMult.Click, BtnDiv.Click, Num1.Click, Num2.Click, Num3.Click, BtnAdd.Click, BtnSub.Click, Num0.Click, BtnPi.Click, BtnSqrd.Click, BtnDot.Click, BtnEql.Click, BtnUp.Click, BtnDown.Click, BtnLeft.Click, BtnRight.Click
    Dim btn As Button = CType(sender, Button)
    Label1.Text = btn.Tag.ToString
    Select Case btn.Name
        Case "BtnCase"
            Timer2.Enabled = True
            BtnCase.Hide()
            BtnOn.Hide()
            HideControls()
        Case "BtnVer"
            Label2.Text = "WE BARE BEARS"
        Case "BtnOff"
            Label2.Text = "CASEO"
            Timer1.Enabled = True
            HideControls()
        Case "BtnOn"
            Label2.Text = "0"
            ShowControls()
    End Select
End Sub

Private Sub ShowControls()
    BtnVer.Show()
    BtnOff.Show()
    BtnExp.Show()
    BtnCube.Show()
    BtnFact.Show()
    BtnSqrt.Show()
    Num7.Show()
    Num8.Show()
    Num9.Show()
    BtnDel.Show()
    BtnAC.Show()
    Num4.Show()
    Num5.Show()
    Num6.Show()
    BtnMult.Show()
    BtnDiv.Show()
    Num1.Show()
    Num2.Show()
    Num3.Show()
    BtnAdd.Show()
    BtnSub.Show()
    Num0.Show()
    BtnPi.Show()
    BtnSqrd.Show()
    BtnDot.Show()
    BtnEql.Show()
    BtnUp.Show()
    BtnDown.Show()
    BtnLeft.Show()
    BtnRight.Show()
End Sub
-----------------------
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim pfc As PrivateFontCollection = New PrivateFontCollection
    pfc.AddFontFile("digital-7 (italic).ttf")
    Label2.Font = New Font(pfc.Families(0), 30.0F, FontStyle.Regular)
    Label2.ForeColor = Color.Black
    Dim pfc2 As PrivateFontCollection = New PrivateFontCollection
    pfc2.AddFontFile("digital-7.ttf")
    Label1.Font = New Font(pfc2.Families(0), 26.0F, FontStyle.Regular)
    Label1.ForeColor = Color.Black
    BtnCase.Hide()
    BtnOn.Hide()
    HideControls()
End Sub

Private Sub ButtonClickMethod(sender As Object, e As EventArgs) Handles BtnCase.Click, BtnVer.Click, BtnOff.Click, BtnOn.Click, BtnExp.Click, BtnCube.Click, BtnFact.Click, BtnSqrt.Click, Num7.Click, Num8.Click, Num9.Click, BtnDel.Click, BtnAC.Click, Num4.Click, Num5.Click, Num6.Click, BtnMult.Click, BtnDiv.Click, Num1.Click, Num2.Click, Num3.Click, BtnAdd.Click, BtnSub.Click, Num0.Click, BtnPi.Click, BtnSqrd.Click, BtnDot.Click, BtnEql.Click, BtnUp.Click, BtnDown.Click, BtnLeft.Click, BtnRight.Click
    Dim btn As Button = CType(sender, Button)
    Select Case btn.Name
        Case "BtnCase"
            Timer2.Enabled = True
            BtnCase.Hide()
            BtnOn.Hide()
            HideControls()
        Case "BtnVer"
            Label1.Text = ""
            Label2.Text = "WE BARE BEARS"
        Case "BtnOff"
            Label1.Text = ""
                Label2.Text = "CASEO"
                Timer1.Enabled = True
                HideControls()
        Case "BtnOn"
            Label1.Text = ""
                Label2.Text = 0
                BtnVer.Show()
                BtnOff.Show()
                BtnExp.Show()
                BtnCube.Show()
                BtnFact.Show()
                BtnSqrt.Show()
                Num7.Show()
                Num8.Show()
                Num9.Show()
                BtnDel.Show()
                BtnAC.Show()
                Num4.Show()
                Num5.Show()
                Num6.Show()
                BtnMult.Show()
                BtnDiv.Show()
                Num1.Show()
                Num2.Show()
                Num3.Show()
                BtnAdd.Show()
                BtnSub.Show()
                Num0.Show()
                BtnPi.Show()
                BtnSqrd.Show()
                BtnDot.Show()
                BtnEql.Show()
                BtnUp.Show()
                BtnDown.Show()
                BtnLeft.Show()
                BtnRight.Show()
        Case "BtnExp"
            Label1.Text &= "^"
        Case "BtnCube"
            Label1.Text &= "^3"
        Case "BtnFact"
            Label1.Text &= "!"
        Case "BtnSqrt"
            Label1.Text &= "√"
        Case "Num7"
            Label1.Text &= "7"
        Case "Num8"
            Label1.Text &= "8"
        Case "Num9"
            Label1.Text &= "9"
        Case "Num4"
            Label1.Text &= "4"
        Case "Num5"
            Label1.Text &= "5"
        Case "Num6"
            Label1.Text &= "6"
        Case "BtnMult"
            Label1.Text &= "×"
        Case "BtnDiv"
            Label1.Text &= "÷"
        Case "Num1"
            Label1.Text &= "1"
        Case "Num2"
            Label1.Text &= "2"
        Case "Num3"
            Label1.Text &= "3"
        Case "BtnAdd"
            Label1.Text &= "+"
        Case "BtnSub"
            Label1.Text &= "-"
        Case "Num0"
            Label1.Text &= "0"
        Case "BtnPi"
            Label1.Text &= "π"
        Case "BtnSqrd"
            Label1.Text &= "^2"
        Case "BtnDot"
            Label1.Text &= "."
        Case "BtnEql"
            Label1.Text &= "="
    End Select
End Sub

Private Sub HideControls()
    BtnVer.Hide()
    BtnOff.Hide()
    BtnExp.Hide()
    BtnCube.Hide()
    BtnFact.Hide()
    BtnSqrt.Hide()
    Num7.Hide()
    Num8.Hide()
    Num9.Hide()
    BtnDel.Hide()
    BtnAC.Hide()
    Num4.Hide()
    Num5.Hide()
    Num6.Hide()
    BtnMult.Hide()
    BtnDiv.Hide()
    Num1.Hide()
    Num2.Hide()
    Num3.Hide()
    BtnAdd.Hide()
    BtnSub.Hide()
    Num0.Hide()
    BtnPi.Hide()
    BtnSqrd.Hide()
    BtnDot.Hide()
    BtnEql.Hide()
    BtnUp.Hide()
    BtnDown.Hide()
    BtnLeft.Hide()
    BtnRight.Hide()
End Sub
Private Sub ButtonClickMethod(sender As Object, e As EventArgs) Handles BtnCase.Click, BtnVer.Click, BtnOff.Click, BtnOn.Click, BtnExp.Click, BtnCube.Click, BtnFact.Click, BtnSqrt.Click, Num7.Click, Num8.Click, Num9.Click, BtnDel.Click, BtnAC.Click, Num4.Click, Num5.Click, Num6.Click, BtnMult.Click, BtnDiv.Click, Num1.Click, Num2.Click, Num3.Click, BtnAdd.Click, BtnSub.Click, Num0.Click, BtnPi.Click, BtnSqrd.Click, BtnDot.Click, BtnEql.Click, BtnUp.Click, BtnDown.Click, BtnLeft.Click, BtnRight.Click
    Dim btn As Button = CType(sender, Button)
    Label1.Text = btn.Tag.ToString
    Select Case btn.Name
        Case "BtnCase"
            Timer2.Enabled = True
            BtnCase.Hide()
            BtnOn.Hide()
            HideControls()
        Case "BtnVer"
            Label2.Text = "WE BARE BEARS"
        Case "BtnOff"
            Label2.Text = "CASEO"
            Timer1.Enabled = True
            HideControls()
        Case "BtnOn"
            Label2.Text = "0"
            ShowControls()
    End Select
End Sub

Private Sub ShowControls()
    BtnVer.Show()
    BtnOff.Show()
    BtnExp.Show()
    BtnCube.Show()
    BtnFact.Show()
    BtnSqrt.Show()
    Num7.Show()
    Num8.Show()
    Num9.Show()
    BtnDel.Show()
    BtnAC.Show()
    Num4.Show()
    Num5.Show()
    Num6.Show()
    BtnMult.Show()
    BtnDiv.Show()
    Num1.Show()
    Num2.Show()
    Num3.Show()
    BtnAdd.Show()
    BtnSub.Show()
    Num0.Show()
    BtnPi.Show()
    BtnSqrd.Show()
    BtnDot.Show()
    BtnEql.Show()
    BtnUp.Show()
    BtnDown.Show()
    BtnLeft.Show()
    BtnRight.Show()
End Sub

Moving PictureBox with Timer

copy iconCopydownload iconDownload
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    PictureBox1.Location = New Point(PictureBox1.Location.X, PictureBox1.Location.Y + 9)
    If (PictureBox1.Location = New Point(700, 1100)) Then
    Timer1.Enabled = False
    End If

End Sub
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
    PictureBox1.Location = New Point(PictureBox1.Location.X, PictureBox1.Location.Y - 9)
    If (PictureBox1.Location = New Point((Me.Width / 700) - (PictureBox1.Width / 700), (Me.Height / 1000) - (PictureBox1.Height / 1000))) Then
        Timer2.Enabled = False
    End If
End Sub
Private Const INCREMENT As Integer = 9

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    Timer1.Enabled = True

End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

    If PictureBox1.Location.Y >= 1100 Then

        Timer1.Enabled = False

    Else

        PictureBox1.Location = New Point(PictureBox1.Location.X, PictureBox1.Location.Y + INCREMENT)

    End If

End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

    Timer2.Enabled = True

End Sub

Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick

    If PictureBox1.Location.Y <= 0 Then

        Timer2.Enabled = False

    Else

        PictureBox1.Location = New Point(PictureBox1.Location.X, PictureBox1.Location.Y - INCREMENT)

    End If

End Sub
-----------------------
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    PictureBox1.Location = New Point(PictureBox1.Location.X, PictureBox1.Location.Y + 9)
    If (PictureBox1.Location = New Point(700, 1100)) Then
    Timer1.Enabled = False
    End If

End Sub
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
    PictureBox1.Location = New Point(PictureBox1.Location.X, PictureBox1.Location.Y - 9)
    If (PictureBox1.Location = New Point((Me.Width / 700) - (PictureBox1.Width / 700), (Me.Height / 1000) - (PictureBox1.Height / 1000))) Then
        Timer2.Enabled = False
    End If
End Sub
Private Const INCREMENT As Integer = 9

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    Timer1.Enabled = True

End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

    If PictureBox1.Location.Y >= 1100 Then

        Timer1.Enabled = False

    Else

        PictureBox1.Location = New Point(PictureBox1.Location.X, PictureBox1.Location.Y + INCREMENT)

    End If

End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

    Timer2.Enabled = True

End Sub

Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick

    If PictureBox1.Location.Y <= 0 Then

        Timer2.Enabled = False

    Else

        PictureBox1.Location = New Point(PictureBox1.Location.X, PictureBox1.Location.Y - INCREMENT)

    End If

End Sub
-----------------------
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    PictureBox1.Location = New Point(PictureBox1.Location.X, PictureBox1.Location.Y + 9)
    If (PictureBox1.Location = New Point(700, 1100)) Then
    Timer1.Enabled = False
    End If

End Sub
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
    PictureBox1.Location = New Point(PictureBox1.Location.X, PictureBox1.Location.Y - 9)
    If (PictureBox1.Location = New Point((Me.Width / 700) - (PictureBox1.Width / 700), (Me.Height / 1000) - (PictureBox1.Height / 1000))) Then
        Timer2.Enabled = False
    End If
End Sub
Private Const INCREMENT As Integer = 9

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    Timer1.Enabled = True

End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

    If PictureBox1.Location.Y >= 1100 Then

        Timer1.Enabled = False

    Else

        PictureBox1.Location = New Point(PictureBox1.Location.X, PictureBox1.Location.Y + INCREMENT)

    End If

End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

    Timer2.Enabled = True

End Sub

Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick

    If PictureBox1.Location.Y <= 0 Then

        Timer2.Enabled = False

    Else

        PictureBox1.Location = New Point(PictureBox1.Location.X, PictureBox1.Location.Y - INCREMENT)

    End If

End Sub

Community Discussions

Trending Discussions on timer2
  • Do not reset a timer after a pause/resume when it has already ended (difficult to explain)
  • How to fire multiple different timers in a synchronous way?
  • How to Save and retrieve 24hrs Countdown timer to Local.Storage
  • How to add DateTimePicker value to Current Time
  • NPM warning: 'unsupported engine'
  • Does changing widget stylesheets using properties work in Qt6 (it did in Qt5)?
  • C++ Linux fastest way to measure time (faster than std::chrono) ? Benchmark included
  • ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings] if (ser.find(&quot;Error&quot;)){
  • Using reduce to change struct in Swift
  • C# WinForm ChartControl sometimes shows zero in real time
Trending Discussions on timer2

QUESTION

Do not reset a timer after a pause/resume when it has already ended (difficult to explain)

Asked 2022-Apr-10 at 11:14

I'm a newbie in java android. I've done a lot of research on SO but couldn't find a case that matches mine.

I made an android app game with different timers. I implemented the pause/resume method, it works fine but big problem with the second timer: i would like this timer not to resume in return from a pause when it is already finished in the cycle of the activity. This timer corresponds to the action of a character in the game. I hope I explained myself well (sorry for my English, I'm French). thanks a lot for your help...

My ON PAUSE:

 protected void onPause() {
        super.onPause();
        MyMediaPlayer.getMediaPlayerInstance().stopAudioFile();
        SharedPreferences prefs = getSharedPreferences("X", MODE_PRIVATE);
        SharedPreferences.Editor editor = prefs.edit();
        editor.putString("lastActivity", getClass().getName());
        editor.commit();
        mCountDownTimer.cancel();
        mCountDownTimer = null;
        Timer2.cancel();
        Timer2 = null;
    }

My ON RESUME:

 protected void onResume() {
        super.onResume();
        MyMediaPlayer.getMediaPlayerInstance().resumeAudio();
        if (mCountDownTimer == null) {
            mCountDownTimer = new CountDownTimer(mTimeRemaining, TIMER_INTERVAL) {
                @Override
                public void onTick(long millisUntilFinished) {
                    textView.setText(String.format(Locale.getDefault(), "%d sec.", millisUntilFinished / 1000L));
                    mTimeRemaining = millisUntilFinished;
                }

                @Override
                public void onFinish() {
                    Intent intent = new Intent(P39x.this, Lose15b.class);
                    Toast toast = Toast.makeText(P39x.this, "time has passed...\n" +
                            "\n" +
                            "YOU HAVE LOST !", Toast.LENGTH_LONG);
                    View toastView = toast.getView();
                    TextView toastMessage = (TextView) toastView.findViewById(android.R.id.message);
                    Typeface typeface = Typeface.createFromAsset(getAssets(), "SanvitoProLight.ttf");
                    toastMessage.setTypeface(typeface);
                    toastMessage.setTextSize(50);
                    toastMessage.setBackgroundResource(R.drawable.quiet);
                    toastMessage.setTextColor(Color.RED);
                    toastMessage.setGravity(Gravity.CENTER_VERTICAL);
                    toast.show();
                    getMediaPlayerInstance().stopAudioFile();
                    startActivity(intent);
                    finish();
                    MediaPlayer mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.collapse);
                    mediaPlayer.start();
                }
            }.start();

            if (Timer2 == null) {
                Timer2 = new CountDownTimer(TIMERDURATION, TIMERINTERVAL) {
                    @Override
                    public void onTick(long millisUntilFinished) {
                        mTimeRemainin = millisUntilFinished;
                    }

                    @Override
                    public void onFinish() {
                        toast = Toast.makeText(P39x.this, "Find your way now", Toast.LENGTH_LONG);
                        View toastView = toast.getView();
                        TextView toastMessage = (TextView) toastView.findViewById(android.R.id.message);
                        Typeface typeface = Typeface.createFromAsset(getAssets(), "SanvitoProLight.ttf");
                        toastMessage.setTypeface(typeface);
                        toastMessage.setTextSize(40);
                        toastMessage.setBackgroundColor(Color.BLACK);
                        toastMessage.setTextColor(Color.MAGENTA);
                        toastMessage.setGravity(Gravity.CENTER_VERTICAL);
                        toast.show();
                    }
                }.start();

I would like Timer2 not to resume in return from a pause when it is already finished in the cycle of the activity.

ANSWER

Answered 2022-Apr-10 at 10:58

This is a lifecycle issue, move timer2 to onCreate() method instead of onResume because onResume get called after onPause() is active.

Source https://stackoverflow.com/questions/71815374

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install timer2

First you need to add a reference to timer2 to your application. Then you are able to create new timers by calling the Timer constructor with the desired timeout in milliseconds. The timer then periodically emits tick events. You can subscribe to these events using the usual EventEmitter functions, such as on and once. Please remember that you need to unsubscribe from the tick event if you do not need the timer any longer. For that you can use the usual EventEmitter functions, such as removeListener and removeAllListeners.
To build this module use roboter.

Support

For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

Explore Related Topics

Share this Page

share link
Consider Popular Date Time Utils Libraries
Compare Date Time Utils Libraries with Highest Support
Compare Date Time Utils Libraries with Permissive License
Compare Date Time Utils Libraries with Highest Reuse
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.