Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ComplicationController.swift 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright @ 2018-present 8x8, Inc.
  3. * Copyright @ 2017-2018 Atlassian Pty Ltd
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. import ClockKit
  18. class ComplicationController: NSObject, CLKComplicationDataSource {
  19. // MARK: - Timeline Configuration
  20. func getSupportedTimeTravelDirections(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimeTravelDirections) -> Void) {
  21. handler([])
  22. }
  23. func getPrivacyBehavior(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationPrivacyBehavior) -> Void) {
  24. handler(.showOnLockScreen)
  25. }
  26. // MARK: - Timeline Population
  27. func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
  28. // Call the handler with the current timeline entry
  29. getLocalizableSampleTemplate(for: complication) {template in
  30. guard let template = template else {
  31. handler(nil)
  32. return
  33. }
  34. handler(CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template))
  35. }
  36. }
  37. func getTimelineEntries(for complication: CLKComplication, before date: Date, limit: Int, withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) {
  38. // Call the handler with the timeline entries prior to the given date
  39. handler(nil)
  40. }
  41. func getTimelineEntries(for complication: CLKComplication, after date: Date, limit: Int, withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) {
  42. // Call the handler with the timeline entries after to the given date
  43. handler(nil)
  44. }
  45. // MARK: - Placeholder Templates
  46. func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -> Void) {
  47. // This method will be called once per supported complication, and the results will be cached
  48. let imageProvider = CLKImageProvider(onePieceImage: UIImage(named: "jitsi")!)
  49. if complication.family == .circularSmall {
  50. let small = CLKComplicationTemplateCircularSmallRingImage()
  51. small.imageProvider = imageProvider
  52. small.ringStyle = .closed
  53. small.fillFraction = 0
  54. handler(small)
  55. } else if complication.family == .utilitarianSmall {
  56. let utilitarian = CLKComplicationTemplateUtilitarianSmallSquare()
  57. utilitarian.imageProvider = imageProvider
  58. handler(utilitarian)
  59. } else if complication.family == .modularSmall {
  60. let modular = CLKComplicationTemplateModularSmallRingImage()
  61. modular.imageProvider = imageProvider
  62. modular.ringStyle = .closed
  63. modular.fillFraction = 0
  64. handler(modular)
  65. }
  66. }
  67. }