RVS_RunningTimerAmbiaMara_ViewController

class RVS_RunningTimerAmbiaMara_ViewController : UIViewController
extension RVS_RunningTimerAmbiaMara_ViewController: RVS_BasicGCDTimerDelegate

This is the view controller for the running timer screen.

Private Static Properties

  • The distance from the bottom of the time set slider to the toolbar or the bottom of the screen.

    Declaration

    Swift

    private static let _timeSetSliderViewBottomContraintConstant: CGFloat
  • The color for the digital display, when in “Pause” mode.

    Declaration

    Swift

    private static let _pausedLEDColor: UIColor?
  • The opacity of the “traffic lights,” when in “Paused” mode.

    Declaration

    Swift

    private static let _pausedStoplightAlpha: CGFloat
  • The opacity of the currently active “traffic light,” when the timer is running.

    Declaration

    Swift

    private static let _activeStoplightAlpha: CGFloat
  • The opacity of the currently inactive “traffic lights,” when the timer is running.

    Declaration

    Swift

    private static let _inactiveStoplightAlpha: CGFloat
  • The color of the digits, when the timer is running, and is still in “Start” mode.

    Declaration

    Swift

    private static let _startLEDColor: UIColor?
  • The color of the digits, when the timer is running, and is in “Warn” mode.

    Declaration

    Swift

    private static let _warnLEDColor: UIColor?
  • The color of the digits, when the timer is running, and is in “Final” mode.

    Declaration

    Swift

    private static let _finalLEDColor: UIColor?
  • The animation duration of the screen flashes.

    Declaration

    Swift

    private static let _flashDurationInSeconds: TimeInterval
  • The repeat rate of the alarm “pulses.”

    Declaration

    Swift

    private static let _alarmDurationInSeconds: TimeInterval
  • The time between timer checks.

    Declaration

    Swift

    private static let _clockPeriodInSeconds: TimeInterval
  • The number of milliseconds to allow for timer leeway.

    Declaration

    Swift

    private static let _leewayInMilliseconds: Int
  • The number of seconds to wait before the toolbar auto-hides.

    Declaration

    Swift

    private static let _autoHidePeriodInSeconds: TimeInterval
  • The period of the auto-hide duration.

    Declaration

    Swift

    private static let _autoHideAnimationDurationInSeconds: TimeInterval

Private Stored Instance Properties

  • The main timer instance.

    Declaration

    Swift

    private var _timer: RVS_BasicGCDTimer?
  • The timer that is set when the alarm is sounding.

    Declaration

    Swift

    private var _alarmTimer: RVS_BasicGCDTimer?
  • The timer that is used to trigger auto-hide (Toolbar On, Auto-Hide Working).

    Declaration

    Swift

    private var _autoHideTimer: RVS_BasicGCDTimer?
  • This is the audio player (for playing alarm sounds).

    Declaration

    Swift

    private var _audioPlayer: AVAudioPlayer!
  • This aggregates our available sounds. The sounds are files, stored in the resources, so this simply gets them, and stores them as path URIs.

    Declaration

    Swift

    private var _soundSelection: [String]
  • When the timer is started (or continued), the initial time is set here.

    Declaration

    Swift

    private var _startingTime: Date?
  • This contains the elapsed time since start, in seconds.

    Declaration

    Swift

    private var _tickTimeInSeconds: Int
  • This will provide haptic/audio feedback for continues and ticks.

    Declaration

    Swift

    private var _selectionFeedbackGenerator: UISelectionFeedbackGenerator?
  • This will provide haptic/audio feedback for gestures, alams, and transitions.

    Declaration

    Swift

    private var _feedbackGenerator: UIImpactFeedbackGenerator?
  • True, if the timer is currently in “alarm” state.

    Declaration

    Swift

    private var _isAlarming: Bool { get set }
  • If true, then the currently selected sound is playing.

    Declaration

    Swift

    private var _isSoundPlaying: Bool { get set }
  • This is used for the toolbar auto-hide.

    Declaration

    Swift

    private var _lastActivityTime: Date?
  • If the slider is up, it will be stored here.

    Declaration

    Swift

    private weak var _timeSetSlider: UISlider?

Internal IB Stored Properties

  • This is the main view, containing the digital display.

    Declaration

    Swift

    @IBOutlet
    weak var digitalDisplayContainerView: UIView?
  • The hours digit pair.

    Declaration

    Swift

    @IBOutlet
    weak var digitalDisplayViewHours: RVS_RetroLEDDigitalDisplay?
  • The minutes digit pair.

    Declaration

    Swift

    @IBOutlet
    weak var digitalDisplayViewMinutes: RVS_RetroLEDDigitalDisplay?
  • The seconds digit pair.

    Declaration

    Swift

    @IBOutlet
    weak var digitalDisplayViewSeconds: RVS_RetroLEDDigitalDisplay?
  • This is the toolbar that may (or may not) be displayed at the bottom of the screen.

    Declaration

    Swift

    @IBOutlet
    weak var controlToolbar: UIToolbar?
  • The “Play” of “Pause” toolbar button.

    Declaration

    Swift

    @IBOutlet
    weak var playPauseToolbarItem: UIBarButtonItem?
  • The “Stop” toolbar button.

    Declaration

    Swift

    @IBOutlet
    weak var stopToolbarItem: UIBarButtonItem?
  • The “Fast Forward”/“Next Timer” toolbar button.

    Declaration

    Swift

    @IBOutlet
    weak var fastForwardBarButtonItem: UIBarButtonItem?
  • The “Rewind”/“Previous Timer” toolbar button.

    Declaration

    Swift

    @IBOutlet
    weak var rewindToolbarItem: UIBarButtonItem?
  • The button in the center of the toolbar that indicates the timer index (if we have multiple timers).

    Declaration

    Swift

    @IBOutlet
    weak var timerIndicatorToolbarItem: UIBarButtonItem!
  • The filter that gives the “gas blur” effect.

    Declaration

    Swift

    @IBOutlet
    weak var blurFilterView: UIVisualEffectView!
  • The image that displays the “hex grid” over the digital display.

    Declaration

    Swift

    @IBOutlet
    weak var hexGridImageView: UIImageView?
  • The view across the back that is filled with a color, during a “flash.”

    Declaration

    Swift

    @IBOutlet
    weak var flasherView: UIView?
  • The stack view that contains the digit pairs.

    Declaration

    Swift

    @IBOutlet
    var digitContainerInternalView: UIView?
  • The view that contains the three “traffic lights.”

    Declaration

    Swift

    @IBOutlet
    weak var stoplightsContainerView: UIStackView?
  • The “traffic light” that is displayed during the “Start” phase of the timer.

    Declaration

    Swift

    @IBOutlet
    weak var startTrafficLightImageView: UIImageView?
  • The “traffic light” that is displayed during the “Warn” phase of the timer.

    Declaration

    Swift

    @IBOutlet
    weak var warnTrafficLightImageView: UIImageView?
  • The “traffic light” that is displayed during the “Final” phase of the timer.

    Declaration

    Swift

    @IBOutlet
    weak var finalTrafficLightImageView: UIImageView?
  • The view that is used to detect a long-press, and will contain the slider to set the time. This is not available in Toolbar Displayed Mode.

    Declaration

    Swift

    @IBOutlet
    weak var timeSetSwipeDetectorView: UIView?
  • The gesture recognizer that will detect a long-press (to bring up the slider). This is not available in Toolbar Displayed Mode.

    Declaration

    Swift

    @IBOutlet
    weak var longPressTimeSetGestureRecognizer: UILongPressGestureRecognizer?
  • The gesture recognizer that will detect taps.

    Declaration

    Swift

    @IBOutlet
    weak var tapGestureRecognizer: UITapGestureRecognizer?
  • The gesture recognizer that will detect double-taps.

    Declaration

    Swift

    @IBOutlet
    weak var doubleTapGestureRecognizer: UITapGestureRecognizer?
  • In order to maintain the proper aspect ratio of the digit pairs, we need to ensconce them in container views. This is the hours view.

    Declaration

    Swift

    @IBOutlet
    weak var hoursContainerView: UIView!
  • In order to maintain the proper aspect ratio of the digit pairs, we need to ensconce them in container views. This is the minutes view.

    Declaration

    Swift

    @IBOutlet
    weak var minutesContainerView: UIView!
  • In order to maintain the proper aspect ratio of the digit pairs, we need to ensconce them in container views. This is the seconds view.

    Declaration

    Swift

    @IBOutlet
    weak var secondsContainerView: UIView!
  • The constraint for the bottom of the slider. We move it around, if we display the toolbar.

    Declaration

    Swift

    @IBOutlet
    weak var timeSetSliderViewBottomContraint: NSLayoutConstraint!

Private Computed Properties

  • Declaration

    Swift

    private var _remainingTime: Int { get }

    Return Value

    The remaining countdown time, in seconds.

  • Declaration

    Swift

    private var _isTimerRunning: Bool { get }

    Return Value

    True, if the timer is currently running.

  • Declaration

    Swift

    private var _isAtStart: Bool { get }

    Return Value

    True, if the current time is at the “starting gate.”

  • Declaration

    Swift

    private var _isAtEnd: Bool { get }

    Return Value

    True, if the current time is at the end.

  • Declaration

    Swift

    private var _isWarning: Bool { get }

    Return Value

    True, if the current time is within the “warning” window.

  • Declaration

    Swift

    private var _isFinal: Bool { get }

    Return Value

    True, if the current time is within the “final countdown” window.

  • Declaration

    Swift

    private var _nextTimerIndex: Int? { get }

    Return Value

    The index of the following timer. Nil, if no following timer. This “circles around,” so the last timer points to the first timer.

  • Declaration

    Swift

    private var _previousTimerIndex: Int? { get }

    Return Value

    The index of the previous timer. Nil, if no previous timer. This “circles around,” so the first timer points to the last timer.

  • Declaration

    Swift

    private var _currentBottomConstraintInDisplayUnits: CGFloat { get }

    Return Value

    The height of the toolbar, plus the offset (or just the offset). This depends upon whether or not the toolbar is displayed.

Private Class Functions

  • This creates an array of CGPoint, based on a 0,0 origin, that describe a hexagon, on its “side” (point facing up).

    Declaration

    Swift

    private class func _pointySideUpHexagon(_ inHowBig: CGFloat) -> [CGPoint]

    Parameters

    inHowBig

    The radius, in display units.

    Return Value

    an array of CGPoint, that can be used to describe a path.

  • This returns a CGMutablePath, describing a “pointy side up” hexagon.

    Declaration

    Swift

    private class func _getHexPath(_ inHowBig: CGFloat) -> CGMutablePath

    Parameters

    inHowBig

    The radius, in display units.

    Return Value

    A CGMutablePath, describing a “pointy side up” hexagon.

Private Instance Methods

  • This class generates an overlay image of a faint “hex grid” that allows us to simulate an old-fashioned “fluorescent” display.

    Declaration

    Swift

    private func _generateHexOverlayImage(_ inBounds: CGRect) -> UIImage?

    Parameters

    inBounds

    The main bounds of the screen, from which the array will be calculated.

Base Class Overrides

  • Declaration

    Swift

    override var prefersHomeIndicatorAutoHidden: Bool { get }
  • Declaration

    Swift

    override var prefersStatusBarHidden: Bool { get }
  • Called when the hierarchy is loaded.

    Declaration

    Swift

    override func viewDidLoad()
  • Called when the view is about to appear.

    Declaration

    Swift

    override func viewWillAppear(_ inIsAnimated: Bool)

    Parameters

    inIsAnimated

    True, if the appearance is animated.

  • Called when the view has appeared. We use this to start the timer (if necessary).

    Declaration

    Swift

    override func viewDidAppear(_ inIsAnimated: Bool)

    Parameters

    inIsAnimated

    True, if the appearance is animated.

  • Called when the view will rearrange its view hierarchy.

    Declaration

    Swift

    override func viewWillLayoutSubviews()
  • Called when the view is about to disappear.

    Declaration

    Swift

    override func viewWillDisappear(_ inIsAnimated: Bool)

    Parameters

    inIsAnimated

    True, if the disappearance is animated.

  • This allows Catalyst apps to use the keyboard to control the timer, like gestures.

    Declaration

    Swift

    override func pressesBegan(_ inKeyPresses: Set<UIPress>, with inEvent: UIPressesEvent?)

    Parameters

    inKeyPresses

    The pressed keys.

    with

    The event, creating the keypresses.

Instance Methods

  • This prepares the time set slider.

    Declaration

    Swift

    func prepareSlider(atThisLocation inLocation: Float)

    Parameters

    atThisLocation

    A float, from 0, to 1, with the starting thumb location (0 is left, 1 is right).

  • This animates the toolbar into visibility.

    Declaration

    Swift

    func showToolbar()
  • This animates the toolbar into invisibility.

    Declaration

    Swift

    func hideToolbar()
  • This resets the autohide timer.

    Declaration

    Swift

    func setAutoHide()
  • See if we have another timer to which we can cascade.

    Declaration

    Swift

    @discardableResult
    func cascadeTimer(backwards inUsePreviousTimer: Bool = false) -> Bool

    Parameters

    backwards

    True, if this is a backwards cascade (previous timer). Default is false (next timer).

    Return Value

    True, if the timer cascaded. Can be ignored.

  • This sets up the toolbar, by adding all the timers.

    Declaration

    Swift

    func setUpToolbar()
  • This initializes the timer screen.

    Declaration

    Swift

    func initializeTimer()
  • Fast forward will either sto the alarm, or cascade to the next timer.

    Declaration

    Swift

    func fastForwardHit()
  • Rewind will either reset the alarm, or cascade to the previous timer.

    Declaration

    Swift

    func rewindHit()
  • This stops the alarm, sets the timer to zero, and pauses it.

    Declaration

    Swift

    func stopAlarm()
  • This starts the timer from scratch.

    Declaration

    Swift

    func startTimer()
  • This sets the timer to scratch, but does not start it.

    Declaration

    Swift

    func resetTimer()
  • This sets the timer to scratch, but does not start it.

    Declaration

    Swift

    func finishTimer()
  • Pauses the timer, without resetting anything. Any playing sounds are stopped.

    Declaration

    Swift

    func pauseTimer()
  • Continues the timer, setting the counter to the last time.

    Declaration

    Swift

    func continueTimer()
  • Stops the timer, by popping the screen.

    Declaration

    Swift

    func stopTimer()
  • Stops any playing sounds.

    Declaration

    Swift

    func stopSounds()
  • This sets up the timer display, according to the time and the settings.

    Declaration

    Swift

    func setTimerDisplay()
  • This determines the proper color for the digit “LEDs.”

    Declaration

    Swift

    func determineStoplightColor(_ inCurrentTime: Int = 0)

    Parameters

    inCurrentTime

    Optional. Default is 0. This is the elapsed time, in seconds.

  • This determines the proper color for the digit “LEDs.”

    Declaration

    Swift

    func determineDigitLEDColor(_ inCurrentTime: Int = 0)

    Parameters

    inCurrentTime

    Optional. Default is 0. This is the elapsed time, in seconds.

  • This will flash the screen, for transitions between timer states. It will also set the colors for the digits and/or traffic lights.

    Declaration

    Swift

    func flashIfNecessary(previousTickTime inTickTime: Int)

    Parameters

    previousTickTime

    The previous ticktime.

  • This flashes the screen briefly cyan (pause)

    Declaration

    Swift

    func flashCyan()
  • This flashes the screen briefly green

    Declaration

    Swift

    func flashGreen()
  • This flashes the screen briefly yellow

    Declaration

    Swift

    func flashYellow()
  • This flashes the screen briefly red

    Declaration

    Swift

    func flashRed()
  • This flashes the current timer number, in an expanding and fading image.

    Declaration

    Swift

    func flashTimerNumber(_ inNumber: Int)
  • This sets the digits, directly.

    Declaration

    Swift

    func setDigitalTimeAs(hours inHours: Int, minutes inMinutes: Int, seconds inSeconds: Int)

    Parameters

    hours

    The hour number

    minutes

    The minute number

    seconds

    The second number.

  • This calculates the current time, and sets the digital display to that time.

    Declaration

    Swift

    func setDigitDisplayTime()
  • This plays any sound, using a given URL.

    Declaration

    Swift

    func playThisSound(_ inSoundURL: URL)

    Parameters

    inSoundURL

    This is the URI to the sound resource.

Callbacks

  • Called if the background was tapped. This is how we start/pause/continue the timer. This only works for toolbar hidden.

    Declaration

    Swift

    @IBAction
    func backgroundTapped(_: UITapGestureRecognizer)
  • The user right-swiped the timer. This only works for toolbar hidden.

    Declaration

    Swift

    @IBAction
    func rightSwipeGestureReceived(_: UISwipeGestureRecognizer)
  • The user left-swiped the timer. This only works for toolbar hidden.

    Declaration

    Swift

    @IBAction
    func leftSwipeGestureReceived(_ inGestureRecognizer: UISwipeGestureRecognizer)
  • The double-tapped the timer, signifying that we will return to the set screen. This only works for toolbar hidden.

    Declaration

    Swift

    @IBAction
    func leaveDisplay(_: Any)
  • The long-press on the bottom of the screen was detected.

    See more

    Declaration

    Swift

    @IBAction
    func longPressGestureDetected(_ inGestureRecognizer: UILongPressGestureRecognizer)

    Parameters

    inGestureRecognizer

    The gesture recognizer that was triggered.

  • One of the toolbar controls was hit.

    Declaration

    Swift

    @IBAction
    func toolbarItemHit(_ inSender: UIBarButtonItem)

    Parameters

    inSender

    The item that was activated.

RVS_BasicGCDTimerDelegate Conformance

  • Called when the timer fires.

    Declaration

    Swift

    func basicGCDTimerCallback(_ inTimer: RVS_BasicGCDTimer)

    Parameters

    inTimer

    The timer