TimerView | an android open source timer | Date Time Utils library
kandi X-RAY | TimerView Summary
kandi X-RAY | TimerView Summary
an android open source timer
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- initialize view
- called onDraw
- Starts the timer .
- Handle touch event .
- Update the position of the dragging button .
- Initializes the timer .
- Callback method .
- Called when a time changes .
- On time stop .
- Called when timer starts .
TimerView Key Features
TimerView Examples and Code Snippets
Community Discussions
Trending Discussions on TimerView
QUESTION
import SwiftUI
struct ContentView: View {
@State private var set = Set()
@State private var count = "10"
private let columns:[GridItem] = Array(repeating: .init(.flexible()), count: 3)
@State private var timer:Timer? = nil
@State private var time = 0
var body: some View {
VStack {
ScrollView {
LazyVGrid(columns: columns) {
ForEach(Array(set)) { num in
Text(String(num))
}
}
}
.frame(width: 400, height: 400, alignment: .center)
HStack{
TextField("Create \(count) items", text: $count)
Button {
createSet(count: Int(count)!)
} label: {
Text("Create")
}
}
if let _ = timer {
Text(String(time))
.font(.title2)
.foregroundColor(.green)
}
HStack {
Button {
time = 100
let timer = Timer.scheduledTimer(withTimeInterval: 10, repeats: true) { _ in
time -= 10
if time == 0 {
self.timer?.invalidate()
self.timer = nil
}
}
self.timer = timer
} label: {
Text("Start Timer")
}
Button {
self.timer?.invalidate()
self.timer = nil
} label: {
Text("Stop Timer")
}
}
}
.padding()
}
private func createSet(count:Int) {
set.removeAll(keepingCapacity: true)
repeat {
let num = Int.random(in: 1...10000)
set.insert(num)
} while set.count < count
}
}
extension Int:Identifiable {
public var id:Self { self }
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
...ANSWER
Answered 2022-Apr-15 at 09:41That´s pretty much how SwiftUI works. Every change to a @State
var triggers the View to reevaluate. If you put your ForEach
in another view it will only reevaluate if you change a var that changes that view. E.g. set
or columns
.
QUESTION
I have a picker that updates an variable bmr. the picker in not updating the value. I put a test Text on the second screen to see if I can call the new value, its always showing the default.
...ANSWER
Answered 2022-Mar-26 at 18:18The issue is bmr
is an Int?
while your tags are Int
. Since they are not the same thing, the selection won't update it. The trick is to cast your tag as an Int?
like this:
QUESTION
import SwiftUI
struct TimerView: View {
@EnvironmentObject var tm : TimerModel
@State var timerStyle : TimerStyle?
@State var focusColors : [Color] = [Color.green, Color.mint, Color.green, Color.mint, Color.green]
@State var breakColors : [Color] = [Color.blue, Color.mint, Color.blue, Color.mint, Color.blue]
@State var longBreakColors : [Color] = [Color.gray, Color.white, Color.gray, Color.white, Color.gray]
@State var isShowNewTimerView : Bool = false
var body: some View {
NavigationView {
ZStack {
Color("BackgroundColor").ignoresSafeArea(.all)
if tm.timerStyle == nil {
NoTimerView()
} else {
VStack(alignment : .center, spacing: 40){
Spacer()
if let timerStyle = tm.timerStyle {
switch timerStyle {
case .focus:
Text("Focus Mode 🔥")
.font(.system(size: 30, weight: .bold, design: .rounded))
.fontWeight(.bold)
case .short:
Text("Break Mode ☕️")
.font(.system(size: 30, weight: .bold, design: .rounded))
.fontWeight(.bold)
case .long:
Text("Long Break Mode 🌕")
.font(.system(size: 30, weight: .bold, design: .rounded))
.fontWeight(.bold)//
}
}
if let timerStyle = tm.timerStyle {
switch timerStyle {
case .focus:
ProgressView(progress: tm.progress, gradientColors: focusColors, time: formatTime())
.padding()
.onReceive(tm.timer) { _ in
if tm.timerMode == .start {
if tm.elapsedFocusTime != 0 {
tm.trackFocusProgress()
} else {
if tm.isAuto {
tm.timerStyle = .short
tm.progress = 0
tm.elapsedShortTime = tm.totalShortTime
if tm.isOnSound {
playSound(sound: "chimeup", type: "mp3")
}
} else {
tm.timerMode = .normal
tm.timerStyle = .short
tm.isStarted = false
tm.progress = 0
tm.elapsedShortTime = tm.totalShortTime
audioPlayer1?.stop()
if tm.isOnSound {
playSound(sound: "chimeup", type: "mp3")
}
}
}
}
}
case .short:
ProgressView(progress: tm.progress, gradientColors: breakColors, time: formatTime())
.padding()
.onReceive(tm.timer) { _ in
if tm.timerMode == .start {
if tm.elapsedShortTime != 0 {
tm.trackFocusProgress()
} else {
if tm.isAuto {
if tm.isSkipMode {
tm.timerStyle = .focus
tm.progress = 0
tm.elapsedFocusTime = tm.totalFocusTime
if tm.isOnSound {
playSound(sound: "chimeup", type: "mp3")
}
} else {
tm.timerStyle = .long
tm.progress = 0
tm.elapsedLongBreakTime = tm.totalLongBreakTime
if tm.isOnSound {
playSound(sound: "chimeup", type: "mp3")
}
}
} else {
if tm.isSkipMode {
tm.timerStyle = .focus
tm.timerMode = .normal
tm.timerStyle = .focus
tm.isStarted = false
tm.progress = 0
tm.elapsedFocusTime = tm.totalFocusTime
audioPlayer1?.stop()
if tm.isOnSound {
playSound(sound: "chimeup", type: "mp3")
}
} else {
tm.timerMode = .normal
tm.timerStyle = .long
tm.isStarted = false
tm.progress = 0
tm.elapsedLongBreakTime = tm.totalLongBreakTime
audioPlayer1?.stop()
if tm.isOnSound {
playSound(sound: "chimeup", type: "mp3")
}
}
}
}
}
}
case .long:
ProgressView(progress: tm.progress, gradientColors: longBreakColors, time: formatTime())
.padding()
.onReceive(tm.timer) { _ in
if tm.timerMode == .start {
if tm.elapsedLongBreakTime != 0 {
tm.trackFocusProgress()
} else {
if tm.isAuto {
tm.timerStyle = .focus
tm.progress = 0
tm.elapsedFocusTime = tm.totalFocusTime
if tm.isOnSound {
playSound(sound: "chimeup", type: "mp3")
}
} else {
tm.timerMode = .normal
tm.timerStyle = .focus
tm.isStarted = false
tm.progress = 0
tm.elapsedFocusTime = tm.totalFocusTime
audioPlayer1?.stop()
if tm.isOnSound {
playSound(sound: "chimeup", type: "mp3")
}
}
}
}
}
}
}
if let timerStyle = tm.timerStyle {
switch timerStyle {
case .focus:
Text("Let's concentrate on your task!")
.font(.headline)
.multilineTextAlignment(.center)
case .short:
Text("Well done, Have a short break!")
.font(.headline)
.multilineTextAlignment(.center)
case .long:
Text("It's so long journey, take care yourself.")
.font(.headline)
.multilineTextAlignment(.center)
}
}
HStack {
Button(action: {
switch tm.timerMode {
case .normal:
tm.timerMode = .start
tm.isStarted.toggle()
tm.backBroundMusic()
case .start:
audioPlayer1?.stop()
tm.timerMode = .normal
if let timerStyle = tm.timerStyle {
switch timerStyle {
case .focus:
tm.progress = 0
tm.elapsedFocusTime = tm.totalFocusTime
case .short:
tm.progress = 0
tm.elapsedShortTime = tm.totalShortTime
case .long:
tm.progress = 0
tm.elapsedLongBreakTime = tm.totalLongBreakTime
}
}
tm.isStarted.toggle()
case .pause:
tm.isStarted.toggle()
tm.isPaused.toggle()
tm.timerMode = .normal
if let timerStyle = tm.timerStyle {
switch timerStyle {
case .focus:
tm.progress = 0
tm.elapsedFocusTime = tm.totalFocusTime
case .short:
tm.progress = 0
tm.elapsedShortTime = tm.totalShortTime
case .long:
tm.progress = 0
tm.elapsedLongBreakTime = tm.totalLongBreakTime
}
}
case .stop:
tm.timerMode = .normal
}
}, label: {
Image(systemName: tm.isStarted ? "square.fill":"play.fill")
.frame(width : 60, height : 60)
.background(tm.isStarted ? .red : .green)
.foregroundColor(.white)
.font(.title)
.cornerRadius(10)
.shadow(color: .gray.opacity(0.5), radius: 1, x: 1, y: 1)
})
.disabled(tm.timerStyle == nil)
.padding()
Button(action: {
switch tm.timerMode {
case .normal:
return
case .start:
audioPlayer1?.stop()
tm.timerMode = .pause
tm.isPaused.toggle()
case .pause:
tm.backBroundMusic()
tm.timerMode = .start
tm.isPaused.toggle()
case .stop:
return
}
}, label: {
Image(systemName: tm.timerMode == .pause
? "play.fill" : "pause.fill")
.frame(width : 60, height : 60)
.background(tm.timerMode == .normal ? .gray : .yellow)
.foregroundColor(.white)
.font(.title)
.cornerRadius(10)
.shadow(color: .gray.opacity(0.5), radius: 1, x: 1, y: 1)
})
.disabled(tm.timerStyle == nil)
.padding()
Button(action: {
audioPlayer1?.stop()
if let timerStyle = tm.timerStyle {
switch timerStyle {
case .focus:
tm.timerMode = .normal
tm.timerStyle = .short
tm.isStarted = false
tm.progress = 0
tm.elapsedShortTime = tm.totalShortTime
case .short:
if tm.isSkipMode {
tm.timerMode = .normal
tm.timerStyle = .focus
tm.isStarted = false
tm.progress = 0
tm.elapsedFocusTime = tm.totalFocusTime
} else {
tm.timerMode = .normal
tm.timerStyle = .long
tm.isStarted = false
tm.progress = 0
tm.elapsedLongBreakTime = tm.totalLongBreakTime
}
case .long:
tm.timerMode = .normal
tm.timerStyle = .focus
tm.isStarted = false
tm.progress = 0
tm.elapsedFocusTime = tm.totalFocusTime
}
}
}, label: {
Image(systemName: "forward.end.fill")
.frame(width : 60, height : 60)
.background(.blue)
.foregroundColor(.white)
.font(.title)
.cornerRadius(10)
.shadow(color: .gray.opacity(0.5), radius: 1, x: 1, y: 1)
})
.disabled(tm.timerStyle == nil)
.padding()
} // hst
Spacer()
}//vst
}
}//Zstack
.navigationTitle("PPO.MO ⏱")
.navigationBarTitleDisplayMode(.inline)
.navigationBarItems(trailing:
HStack{
if tm.isOnBackgroundSound {
Menu {
Button(action: {
switch tm.timerMode {
case .normal:
tm.backgroundNoise = .forest
case .start:
tm.backgroundNoise = .forest
tm.backBroundMusic()
case .pause:
audioPlayer1?.stop()
case .stop:
tm.backgroundNoise = .forest
}
}, label: {
Label(tm.backgroundNoise == .forest ? "✅ Forest" : "Forest", systemImage: "leaf")
})
Button(action: {
switch tm.timerMode {
case .normal:
tm.backgroundNoise = .river
case .start:
tm.backgroundNoise = .river
tm.backBroundMusic()
case .pause:
audioPlayer1?.stop()
case .stop:
tm.backgroundNoise = .river
}
}, label: {
Label(tm.backgroundNoise == .river ? "✅ River" : "River", systemImage: "drop.circle")
})
Button(action: {
switch tm.timerMode {
case .normal:
tm.backgroundNoise = .rain
case .start:
tm.backgroundNoise = .rain
tm.backBroundMusic()
case .pause:
audioPlayer1?.stop()
case .stop:
tm.backgroundNoise = .rain
}
}, label: {
Label(tm.backgroundNoise == .rain ? "✅ Rain" : "Rain", systemImage: "cloud.rain")
})
Button(action: {
switch tm.timerMode {
case .normal:
tm.backgroundNoise = .wave
case .start:
tm.backgroundNoise = .wave
tm.backBroundMusic()
case .pause:
audioPlayer1?.stop()
case .stop:
tm.backgroundNoise = .wave
}
}, label: {
Label(tm.backgroundNoise == .wave ? "✅ Wave" : "Wave", systemImage: "cloud.rain")
})
Button(action: {
tm.backgroundNoise = .turnOff
audioPlayer1?.stop()
}, label: {
Label(tm.backgroundNoise == .turnOff ? "✅ Turn off" : "Turn off", systemImage: "speaker.slash")
})
} label: {
Image(systemName: tm.backgroundNoise == .turnOff ? "speaker.slash.circle" : "speaker.circle")
}
}
NavigationLink(destination: {
AddTimerView()
}, label: {
Image(systemName: "plus")
})
.simultaneousGesture(TapGesture().onEnded({
tm.timerMode = .pause
audioPlayer1?.stop()
}))
})
}//nav
}
}
extension TimerView {
func formatTime() -> String {
if let timerStyle = tm.timerStyle {
switch timerStyle {
case .focus:
let minute = Int(tm.elapsedFocusTime) / 60 % 60
let second = Int(tm.elapsedFocusTime) % 60
return String(format: "%02i:%02i", minute, second)
case .short:
let minute = Int(tm.elapsedShortTime) / 60 % 60
let second = Int(tm.elapsedShortTime) % 60
return String(format: "%02i:%02i", minute, second)
case .long:
let minute = Int(tm.elapsedLongBreakTime) / 60 % 60
let second = Int(tm.elapsedLongBreakTime) % 60
return String(format: "%02i:%02i", minute, second)
}
}
return "00:00"
}
}
...ANSWER
Answered 2022-Mar-17 at 13:36Put onReceive on some always-shown view, like
QUESTION
I'm continuing to develop a timer app for practice purposes and have the basic functions ready so far.
The timer works in such a way that if you click on "Start" the timer simply runs down to 0 and then selects the next player - here you can also the button in the upper middle whether an alarm is played after the timer or not - however, this also stops the timer, although this does not occur in the implementation (see also video below). I hope someone can help me.
For the timer I made a StopWatchManager
class:
ANSWER
Answered 2022-Mar-11 at 19:38You are instantiating your playTimer
in the subview ... That will reset it when the view is redrawn. Instead you should do this in the parent view and pass it down.
Also you should use @StateObject
to instantiate.
QUESTION
I have an app with 3 views. they are connected by a NavigationView and have NavigationLinks that link to the next view. however, all views are created with an extra NavigationBar and with lots of blank white space on the bottom that travels up the screen every time you click through the views and go back to the home page. I remember a few days ago having this issue when I went from the HomeView() to the TimerView() but I'm not sure how I got rid of it. and also I definitely did not get rid of it because I'm still having the same problem. and also I don't remember how I worked around this the first time. I have seen other posts which say I should set the navigationBar color to clear but that does nothing. not sure what is going on. most other posts on this topic are about removing the space up top and very few talk about the blank space on the bottom so I'm not really sure what to do.
I go into the capture view hierarchy and I see that white footer bar is created when the view is created but then just seems to stack on top of every other view until the application is unusable. using Xcode 13.1 and running in simulator on iPhone 12 with iOS 15.0.
here's the video as well as pictures from the capture view hierarchy thing https://imgur.com/a/jBprYbN
and here's the code
...ANSWER
Answered 2022-Feb-10 at 20:40The issue is caused by the UITabBar.appearance().isTranslucent = false
line -- without that, as you confirmed in the comments, it behaves as expected.
Here's a working version with a note about that line:
QUESTION
I would like to develop an app that includes a timer - everything works fine so far - yet I have the problem that the CircleProgress is not quite at 0 when the counter is. (as you can see in the picture below)
Long story short - my timer is not precise... How can I make it better?
So this is my code:
This is the View where I give my Binding to the ProgressCircleView:
...ANSWER
Answered 2021-Aug-25 at 17:19You cannot control the timer, it will never be entirely accurate.
Instead, I suggest you save the end date and calculate your progress based on it:
QUESTION
Semi related question: SwiftUI ActionSheet does not dismiss when timer is running
I am currently experiencing an issue with alerts in a project that I am working on. Presented alerts will not dismiss when there is a timer running in the background. Most of the time it requires several clicks of the dismissal button to disappear. I have recreated this issue with as little overhead as possible in a sample project.
My primary project has this issue when trying to display an alert on a different view but I could not reproduce that issue in the sample project. The issue can be reliably replicated by toggling the alert on the same view that the timer is running. I have also tested by removing the binding from the text field to stop the text field view from updating. The alert still fails to dismiss on the first click. I am unsure if there is a way to work around this and am looking for any advice possible.
Xcode 13.0/iOS 15.0 and occurs in iOS 14.0 also
Timerview.swift
...ANSWER
Answered 2021-Oct-22 at 20:52Every time timer runs UI will recreate, since "secondsElapsed" is an observable object. SwiftUI will automatically monitor for changes in "secondsElapsed", and re-invoke the body property of your view. In order to avoid this we need to separate the button and Alert to another view like below.
QUESTION
I m making a TimerView in swiftui getting a start time and stop time on button pressed.
I am using two VStack inside a HStack to ensure that the text are aligned properly, but I am unable to account for the timestamp text size that are sometimes too large and goes out of alignment (timestamp is lower than the label!) (click start) or that the two different timestamps have different sizing (click stop)
How should I ensure that the text is uniformly sized while fitting to the window (the text was too long and went out of bounds)?
...ANSWER
Answered 2021-Oct-17 at 03:33you could just simply adjust the font size according to the screen size, eg: one small font for small size devices and another for larger devices. See this How to get device width and height?
Then use this, given the desired font fsize
:
QUESTION
I am trying to show a custom view on a dismiss of a controller. It's working fine if I am sowing it on popViewController but not working when I am using dismiss method. If anybody knows the solution please help me out.
...ANSWER
Answered 2021-Aug-16 at 09:27According to the docs, the presenting controller is responsible for the actual dismiss. When the presented controller dismisses itself, it will ask the presenter to do it for it. In here you need to use the closure or protocol. for e.g use like
on your LogWorkoutViewController VC / presented VC declare the variable as like
QUESTION
I want to attach a view from a specific controller (MyController) just above the tabbar but my problem is how would I calculate the height of the tabbar from MyController so that I could give y position to my custom view. I am trying to achieve with statusBarFrame but it's not working. If anybody has some idea please help me out.
...ANSWER
Answered 2021-Aug-16 at 05:25directly take the y position of tabBarController?.tabBar.frame.origin.y and add your timerview frame height
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install TimerView
You can use TimerView like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the TimerView component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page