Skip to content

Commit 3635b43

Browse files
committed
[BitWatch] add sample code for watchOS complication
1 parent 43548ab commit 3635b43

File tree

9 files changed

+188
-0
lines changed

9 files changed

+188
-0
lines changed

ios/BitWatch/WatchAppV2/Rakefile

+11
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ Motion::Project::App.setup do |app|
1515
# app.provisioning_profile = '../provisions/BitWatchWatchKitExtension.mobileprovision'
1616
# app.watch_app_config.codesign_certificate = app.codesign_certificate
1717
# app.watch_app_config.provisioning_profile = '../provisions/BitWatchWatchApp.mobileprovision'
18+
app.frameworks << 'ClockKit'
19+
20+
app.info_plist['CLKComplicationPrincipalClass'] = 'ComplicationController'
21+
app.info_plist['CLKComplicationDefaultImagesAssetName'] = 'Complication'
22+
app.info_plist['CLKComplicationSupportedFamilies'] = %w(
23+
CLKComplicationFamilyModularLarge
24+
CLKComplicationFamilyUtilitarianSmall
25+
CLKComplicationFamilyUtilitarianLarge
26+
CLKComplicationFamilyCircularSmall
27+
)
28+
app.info_plist['WKExtensionDelegateClassName'] = 'ExtensionDelegate'
1829
end
1930

2031
require 'ib/tasks'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
class ComplicationController
2+
# Timeline Configuration
3+
4+
def getSupportedTimeTravelDirectionsForComplication(complication, withHandler:handler)
5+
handler.call(CLKComplicationTimeTravelDirectionForward|CLKComplicationTimeTravelDirectionBackward)
6+
end
7+
8+
def getTimelineStartDateForComplication(complication, withHandler:handler)
9+
handler.call(nil)
10+
end
11+
12+
def getTimelineEndDateForComplication(complication, withHandler:handler)
13+
handler.call(nil)
14+
end
15+
16+
def getPrivacyBehaviorForComplication(complication, withHandler:handler)
17+
handler.call(CLKComplicationPrivacyBehaviorShowOnLockScreen)
18+
end
19+
20+
# Timeline Population
21+
22+
def getCurrentTimelineEntryForComplication(complication, withHandler:handler)
23+
# Call the handler with the current timeline entry
24+
entry = nil
25+
26+
case complication.family
27+
when CLKComplicationFamilyCircularSmall
28+
image = UIImage.imageNamed("Complication/Circular")
29+
template = CLKComplicationTemplateCircularSmallSimpleImage.new
30+
template.imageProvider = CLKImageProvider.imageProviderWithOnePieceImage(image)
31+
entry = CLKComplicationTimelineEntry.entryWithDate(Time.now, complicationTemplate:template)
32+
33+
when CLKComplicationFamilyUtilitarianSmall
34+
image = UIImage.imageNamed("Complication/Circular")
35+
template = CLKComplicationTemplateUtilitarianSmallRingImage.new
36+
template.imageProvider = CLKImageProvider.imageProviderWithOnePieceImage(image)
37+
template.ringStyle = CLKComplicationRingStyleClosed
38+
entry = CLKComplicationTimelineEntry.entryWithDate(Time.now, complicationTemplate:template)
39+
40+
when CLKComplicationFamilyUtilitarianLarge
41+
image = UIImage.imageNamed("Complication/Circular")
42+
template = CLKComplicationTemplateUtilitarianLargeFlat.new
43+
template.textProvider = CLKSimpleTextProvider.textProviderWithText("RubyMotion sample")
44+
template.imageProvider = CLKImageProvider.imageProviderWithOnePieceImage(image)
45+
entry = CLKComplicationTimelineEntry.entryWithDate(Time.now, complicationTemplate:template)
46+
47+
when CLKComplicationFamilyModularLarge
48+
template = CLKComplicationTemplateModularLargeStandardBody.new
49+
template.headerTextProvider = CLKSimpleTextProvider.textProviderWithText("RubyMotion sample")
50+
template.body1TextProvider = CLKSimpleTextProvider.textProviderWithText("This is Complication sample")
51+
entry = CLKComplicationTimelineEntry.entryWithDate(Time.now, complicationTemplate:template)
52+
53+
end
54+
55+
handler.call(entry)
56+
end
57+
58+
def getTimelineEntriesForComplication(complication, beforeDate:date, limit:limit, withHandler:handler)
59+
# Call the handler with the timeline entries prior to the given date
60+
handler.call(nil)
61+
end
62+
63+
def getTimelineEntriesForComplication(complication, afterDate:date, limit:limit, withHandler:handler)
64+
# Call the handler with the timeline entries after to the given date
65+
handler.call(nil)
66+
end
67+
68+
# Placeholder Templates
69+
70+
def getLocalizableSampleTemplateForComplication(complication, withHandler:handler)
71+
# This method will be called once per supported complication, and the results will be cached
72+
handler.call(nil)
73+
end
74+
75+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "watch",
5+
"filename" : "[email protected]",
6+
"screen-width" : "<=145",
7+
"scale" : "2x"
8+
},
9+
{
10+
"idiom" : "watch",
11+
"filename" : "[email protected]",
12+
"screen-width" : ">145",
13+
"scale" : "2x"
14+
}
15+
],
16+
"info" : {
17+
"version" : 1,
18+
"author" : "xcode"
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"assets" : [
3+
{
4+
"idiom" : "watch",
5+
"filename" : "Circular.imageset",
6+
"role" : "circular"
7+
},
8+
{
9+
"idiom" : "watch",
10+
"filename" : "Extra Large.imageset",
11+
"role" : "extra-large"
12+
},
13+
{
14+
"idiom" : "watch",
15+
"filename" : "Modular.imageset",
16+
"role" : "modular"
17+
},
18+
{
19+
"idiom" : "watch",
20+
"filename" : "Utilitarian.imageset",
21+
"role" : "utilitarian"
22+
}
23+
],
24+
"info" : {
25+
"version" : 1,
26+
"author" : "xcode"
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "watch",
5+
"scale" : "2x",
6+
"screen-width" : "<=145"
7+
},
8+
{
9+
"idiom" : "watch",
10+
"scale" : "2x",
11+
"screen-width" : ">145"
12+
}
13+
],
14+
"info" : {
15+
"version" : 1,
16+
"author" : "xcode"
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "watch",
5+
"scale" : "2x",
6+
"screen-width" : "<=145"
7+
},
8+
{
9+
"idiom" : "watch",
10+
"scale" : "2x",
11+
"screen-width" : ">145"
12+
}
13+
],
14+
"info" : {
15+
"version" : 1,
16+
"author" : "xcode"
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "watch",
5+
"scale" : "2x",
6+
"screen-width" : "<=145"
7+
},
8+
{
9+
"idiom" : "watch",
10+
"scale" : "2x",
11+
"screen-width" : ">145"
12+
}
13+
],
14+
"info" : {
15+
"version" : 1,
16+
"author" : "xcode"
17+
}
18+
}

0 commit comments

Comments
 (0)