Skip to content

Commit

Permalink
[BitWatch] add sample code for watchOS complication
Browse files Browse the repository at this point in the history
  • Loading branch information
Watson1978 committed Dec 11, 2016
1 parent 43548ab commit 3635b43
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ios/BitWatch/WatchAppV2/Rakefile
Expand Up @@ -15,6 +15,17 @@ Motion::Project::App.setup do |app|
# app.provisioning_profile = '../provisions/BitWatchWatchKitExtension.mobileprovision'
# app.watch_app_config.codesign_certificate = app.codesign_certificate
# app.watch_app_config.provisioning_profile = '../provisions/BitWatchWatchApp.mobileprovision'
app.frameworks << 'ClockKit'

app.info_plist['CLKComplicationPrincipalClass'] = 'ComplicationController'
app.info_plist['CLKComplicationDefaultImagesAssetName'] = 'Complication'
app.info_plist['CLKComplicationSupportedFamilies'] = %w(
CLKComplicationFamilyModularLarge
CLKComplicationFamilyUtilitarianSmall
CLKComplicationFamilyUtilitarianLarge
CLKComplicationFamilyCircularSmall
)
app.info_plist['WKExtensionDelegateClassName'] = 'ExtensionDelegate'
end

require 'ib/tasks'
Expand Down
75 changes: 75 additions & 0 deletions ios/BitWatch/WatchAppV2/app/complication_controller.rb
@@ -0,0 +1,75 @@
class ComplicationController
# Timeline Configuration

def getSupportedTimeTravelDirectionsForComplication(complication, withHandler:handler)
handler.call(CLKComplicationTimeTravelDirectionForward|CLKComplicationTimeTravelDirectionBackward)
end

def getTimelineStartDateForComplication(complication, withHandler:handler)
handler.call(nil)
end

def getTimelineEndDateForComplication(complication, withHandler:handler)
handler.call(nil)
end

def getPrivacyBehaviorForComplication(complication, withHandler:handler)
handler.call(CLKComplicationPrivacyBehaviorShowOnLockScreen)
end

# Timeline Population

def getCurrentTimelineEntryForComplication(complication, withHandler:handler)
# Call the handler with the current timeline entry
entry = nil

case complication.family
when CLKComplicationFamilyCircularSmall
image = UIImage.imageNamed("Complication/Circular")
template = CLKComplicationTemplateCircularSmallSimpleImage.new
template.imageProvider = CLKImageProvider.imageProviderWithOnePieceImage(image)
entry = CLKComplicationTimelineEntry.entryWithDate(Time.now, complicationTemplate:template)

when CLKComplicationFamilyUtilitarianSmall
image = UIImage.imageNamed("Complication/Circular")
template = CLKComplicationTemplateUtilitarianSmallRingImage.new
template.imageProvider = CLKImageProvider.imageProviderWithOnePieceImage(image)
template.ringStyle = CLKComplicationRingStyleClosed
entry = CLKComplicationTimelineEntry.entryWithDate(Time.now, complicationTemplate:template)

when CLKComplicationFamilyUtilitarianLarge
image = UIImage.imageNamed("Complication/Circular")
template = CLKComplicationTemplateUtilitarianLargeFlat.new
template.textProvider = CLKSimpleTextProvider.textProviderWithText("RubyMotion sample")
template.imageProvider = CLKImageProvider.imageProviderWithOnePieceImage(image)
entry = CLKComplicationTimelineEntry.entryWithDate(Time.now, complicationTemplate:template)

when CLKComplicationFamilyModularLarge
template = CLKComplicationTemplateModularLargeStandardBody.new
template.headerTextProvider = CLKSimpleTextProvider.textProviderWithText("RubyMotion sample")
template.body1TextProvider = CLKSimpleTextProvider.textProviderWithText("This is Complication sample")
entry = CLKComplicationTimelineEntry.entryWithDate(Time.now, complicationTemplate:template)

end

handler.call(entry)
end

def getTimelineEntriesForComplication(complication, beforeDate:date, limit:limit, withHandler:handler)
# Call the handler with the timeline entries prior to the given date
handler.call(nil)
end

def getTimelineEntriesForComplication(complication, afterDate:date, limit:limit, withHandler:handler)
# Call the handler with the timeline entries after to the given date
handler.call(nil)
end

# Placeholder Templates

def getLocalizableSampleTemplateForComplication(complication, withHandler:handler)
# This method will be called once per supported complication, and the results will be cached
handler.call(nil)
end

end
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,20 @@
{
"images" : [
{
"idiom" : "watch",
"filename" : "Circular_38mm@2x.png",
"screen-width" : "<=145",
"scale" : "2x"
},
{
"idiom" : "watch",
"filename" : "Circular_42mm@2x.png",
"screen-width" : ">145",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
@@ -0,0 +1,28 @@
{
"assets" : [
{
"idiom" : "watch",
"filename" : "Circular.imageset",
"role" : "circular"
},
{
"idiom" : "watch",
"filename" : "Extra Large.imageset",
"role" : "extra-large"
},
{
"idiom" : "watch",
"filename" : "Modular.imageset",
"role" : "modular"
},
{
"idiom" : "watch",
"filename" : "Utilitarian.imageset",
"role" : "utilitarian"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
@@ -0,0 +1,18 @@
{
"images" : [
{
"idiom" : "watch",
"scale" : "2x",
"screen-width" : "<=145"
},
{
"idiom" : "watch",
"scale" : "2x",
"screen-width" : ">145"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
@@ -0,0 +1,18 @@
{
"images" : [
{
"idiom" : "watch",
"scale" : "2x",
"screen-width" : "<=145"
},
{
"idiom" : "watch",
"scale" : "2x",
"screen-width" : ">145"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
@@ -0,0 +1,18 @@
{
"images" : [
{
"idiom" : "watch",
"scale" : "2x",
"screen-width" : "<=145"
},
{
"idiom" : "watch",
"scale" : "2x",
"screen-width" : ">145"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

0 comments on commit 3635b43

Please sign in to comment.