76 lines
2.8 KiB
Swift
76 lines
2.8 KiB
Swift
//
|
|
// ComplicationController.swift
|
|
// Switch WatchKit Extension
|
|
//
|
|
// Created by Within on 2019-09-21.
|
|
// Copyright © 2019 Within. All rights reserved.
|
|
//
|
|
|
|
import WatchKit
|
|
|
|
class ComplicationController: NSObject, CLKComplicationDataSource {
|
|
func getSupportedTimeTravelDirections(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimeTravelDirections) -> Void) {
|
|
handler([])
|
|
}
|
|
|
|
func getTimelineStartDate(for complication: CLKComplication, withHandler handler: @escaping (Date?) -> Void) {
|
|
handler(nil)
|
|
}
|
|
|
|
func getTimelineEndDate(for complication: CLKComplication, withHandler handler: @escaping (Date?) -> Void) {
|
|
handler(nil)
|
|
}
|
|
|
|
func getPrivacyBehavior(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationPrivacyBehavior) -> Void) {
|
|
handler(.showOnLockScreen)
|
|
}
|
|
|
|
// MARK: - Timeline Population
|
|
|
|
func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
|
|
// Call the handler with the current timeline entry
|
|
if (complication.family == .graphicCorner) {
|
|
handler(getEntryForGraphicCorner())
|
|
}
|
|
|
|
handler(nil)
|
|
}
|
|
|
|
func getTimelineEntries(for complication: CLKComplication, before date: Date, limit: Int, withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) {
|
|
// Call the handler with the timeline entries prior to the given date
|
|
handler(nil)
|
|
}
|
|
|
|
func getTimelineEntries(for complication: CLKComplication, after date: Date, limit: Int, withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) {
|
|
// Call the handler with the timeline entries after to the given date
|
|
handler(nil)
|
|
}
|
|
|
|
func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -> Void) {
|
|
// This method will be called once per supported complication, and the results will be cached
|
|
|
|
if (complication.family == .graphicCorner) {
|
|
handler(getTemplateForGraphicCorner("Example"))
|
|
}
|
|
|
|
handler(nil)
|
|
}
|
|
|
|
func getEntryForGraphicCorner() -> CLKComplicationTimelineEntry {
|
|
let gc = getTemplateForGraphicCorner(getFront())
|
|
return CLKComplicationTimelineEntry(date: Date(), complicationTemplate: gc)
|
|
}
|
|
|
|
func getTemplateForGraphicCorner(_ front: String) -> CLKComplicationTemplateGraphicCornerStackText {
|
|
let gc = CLKComplicationTemplateGraphicCornerStackText()
|
|
let text = CLKSimpleTextProvider()
|
|
text.text = front
|
|
text.shortText = ""
|
|
text.tintColor = UIColor.white
|
|
|
|
gc.innerTextProvider = text
|
|
|
|
return gc;
|
|
}
|
|
}
|