Skip to content

Commit e69f0ec

Browse files
committed
Rough implementation of Casio watch face
1 parent 4678a88 commit e69f0ec

6 files changed

Lines changed: 133 additions & 3 deletions

File tree

InfiniLink.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@
185185
26D7817926CAD19F00BBF555 /* ColorPalette.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorPalette.swift; sourceTree = "<group>"; };
186186
9255940428BB5342001602F1 /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/Localizable.strings"; sourceTree = "<group>"; };
187187
E021DAB22B489F58005C5E51 /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
188+
E05D11DD2B9BB99300D566EA /* 7segment.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = 7segment.ttf; sourceTree = "<group>"; };
188189
E06973AA2B35E6F4009C2F7D /* InfiniLink.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = InfiniLink.entitlements; sourceTree = "<group>"; };
189190
E079ED002B78903B0038C0F2 /* WatchSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WatchSettingsView.swift; sourceTree = "<group>"; };
190191
E09057E52B9AC12B008C0CFD /* NetworkManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkManager.swift; sourceTree = "<group>"; };
@@ -602,6 +603,7 @@
602603
E53195382B792E3C004FECB4 /* navigation.ttf */,
603604
E53195372B792E3C004FECB4 /* open_sans_light.ttf */,
604605
E53195392B792E3C004FECB4 /* repetitionscrolling.ttf */,
606+
E05D11DD2B9BB99300D566EA /* 7segment.ttf */,
605607
E53195312B792E3B004FECB4 /* Teko-Light.ttf */,
606608
);
607609
path = Fonts;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "casio.png",
5+
"idiom" : "universal",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"author" : "xcode",
19+
"version" : 1
20+
}
21+
}
3.16 KB
Loading

InfiniLink/Core/Home/WatchFace.swift

Lines changed: 108 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ struct WatchFaceView: View {
4040
case 4:
4141
InfineatWF(geometry: .constant(geometry))
4242
case 5:
43-
// Casio G7710
44-
EmptyView()
43+
CasioWF(geometry: .constant(geometry))
4544
default:
4645
ProgressView()
4746
.frame(width: geometry.size.width, height: geometry.size.height, alignment: .center)
@@ -476,6 +475,112 @@ struct TerminalWF: View {
476475
}
477476
}
478477

478+
struct CasioWF: View {
479+
@ObservedObject var bleManagerVal = BLEManagerVal.shared
480+
@ObservedObject var bleManager = BLEManager.shared
481+
@Environment(\.colorScheme) var colorScheme
482+
@Binding var geometry: GeometryProxy
483+
484+
let colorText: Color = Color(red: 152 / 255.0, green: 182 / 255.0, blue: 154 / 255.0)
485+
486+
var hour24: Bool {
487+
switch bleManagerVal.timeFormat {
488+
case .H12:
489+
return false
490+
case .H24:
491+
return true
492+
default:
493+
return true
494+
}
495+
}
496+
497+
var body: some View {
498+
ZStack {
499+
Image("casio")
500+
.scaleEffect(0.81)
501+
CustomTextView(text: String(Int(bleManager.batteryLevel)), font: .custom("open_sans_light", size: geometry.size.width * 0.09), lineSpacing: 0)
502+
.frame(width: geometry.size.width, height: geometry.size.height, alignment: .topTrailing)
503+
.padding(.trailing, 22)
504+
CustomTextView(
505+
text: {
506+
let dateFormatter = DateFormatter()
507+
dateFormatter.dateFormat = "E"
508+
509+
let weekOfYear = Calendar.current.component(.weekOfYear, from: Date())
510+
511+
return "WK\(weekOfYear)\n\(dateFormatter.string(from: Date()).uppercased())"
512+
}(),
513+
font: .custom("repetitionscrolling", size: geometry.size.width * 0.16),
514+
lineSpacing: 0
515+
)
516+
.frame(width: geometry.size.width / 1.04, height: geometry.size.height / 1.2, alignment: .topLeading)
517+
CustomTextView(
518+
text: {
519+
let calendar = Calendar.current
520+
let now = Date()
521+
522+
let startOfYear = calendar.startOfDay(for: calendar.date(from: DateComponents(year: calendar.component(.year, from: now)))!)
523+
let endOfYear = calendar.startOfDay(for: calendar.date(byAdding: DateComponents(year: 1, day: -1), to: calendar.date(from: DateComponents(year: calendar.component(.year, from: now)))!)!)
524+
525+
let daysIn = calendar.dateComponents([.day], from: startOfYear, to: now).day! + 1
526+
let daysLeft = calendar.dateComponents([.day], from: now, to: endOfYear).day! + 1
527+
528+
return "\(daysIn)-\(daysLeft)"
529+
}(),
530+
font: .custom("open_sans_light ", size: geometry.size.width * 0.13),
531+
lineSpacing: 0
532+
)
533+
.frame(width: geometry.size.width / 1.04, height: geometry.size.height / 1.3, alignment: .topTrailing)
534+
CustomTextView(
535+
text: {
536+
let calendar = Calendar.current
537+
let now = Date()
538+
539+
let month = calendar.component(.month, from: now)
540+
let day = calendar.component(.day, from: now)
541+
542+
return "\(month)- \(day)"
543+
}(),
544+
font: .custom("open_sans_light ", size: geometry.size.width * 0.13),
545+
lineSpacing: 0
546+
)
547+
.frame(width: geometry.size.width / 1.08, height: geometry.size.height / 2.25, alignment: .topTrailing)
548+
if Calendar.current.component(.hour, from: Date()) > 12 && !hour24 {
549+
CustomTextView(text: "\(Calendar.current.component(.hour, from: Date()) - 12):\(String(format: "%02d", Calendar.current.component(.minute, from: Date())))", font: .custom("7-segment", size: geometry.size.width * 0.36), lineSpacing: 0)
550+
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .trailing)
551+
.position(x: geometry.size.width / 2.0, y: geometry.size.height / 1.30)
552+
} else {
553+
CustomTextView(text: "\(String(format: "%02d", Calendar.current.component(.hour, from: Date()))):\(String(format: "%02d", Calendar.current.component(.minute, from: Date())))", font: .custom("7-segment", size: geometry.size.width * 0.36), lineSpacing: 0)
554+
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .trailing)
555+
.position(x: geometry.size.width / 2.0, y: geometry.size.height / 1.30)
556+
}
557+
HStack(spacing: 4) {
558+
Image(systemName: "heart.fill")
559+
.font(.system(size: geometry.size.width * 0.08))
560+
.foregroundColor(bleManagerVal.heartBPM != 0 ? colorText : .gray)
561+
.opacity(bleManagerVal.heartBPM != 0 ? 1.0 : 0.5)
562+
if bleManagerVal.heartBPM != 0 {
563+
CustomTextView(text: String(Int(bleManagerVal.heartBPM)), font: .custom("open_sans_light", size: geometry.size.width * 0.11), lineSpacing: 0)
564+
}
565+
}
566+
.frame(width: geometry.size.width, height: geometry.size.height, alignment: .bottomLeading)
567+
.padding(.leading, 10)
568+
.padding(.bottom, bleManagerVal.heartBPM != 0 ? 0 : -4)
569+
HStack(spacing: 4) {
570+
Image(systemName: "shoeprints.fill")
571+
.rotationEffect(Angle(degrees: 90))
572+
.font(.system(size: geometry.size.width * 0.08))
573+
CustomTextView(text: "\(bleManagerVal.stepCount)", font: .custom("open_sans_light", size: geometry.size.width * 0.11), lineSpacing: 0)
574+
}
575+
.frame(width: geometry.size.width, height: geometry.size.height, alignment: .bottomTrailing)
576+
.padding(.trailing, 10)
577+
.padding(.bottom, -4)
578+
}
579+
.foregroundColor(colorText)
580+
.frame(width: geometry.size.width, height: geometry.size.height, alignment: .center)
581+
}
582+
}
583+
479584
struct CustomTextView: View {
480585
var text: String
481586
var font: Font
@@ -494,7 +599,7 @@ struct CustomTextView: View {
494599
#Preview {
495600
NavigationView {
496601
GeometryReader { geometry in
497-
WatchFaceView(watchface: .constant(4))
602+
WatchFaceView(watchface: .constant(5))
498603
.padding(22)
499604
.frame(width: geometry.size.width / 1.65, height: geometry.size.width / 1.65, alignment: .center)
500605
.clipped(antialiased: true)

InfiniLink/Fonts/7segment.ttf

5.69 KB
Binary file not shown.

InfiniLink/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
<string>JetBrainsMono-Regular.ttf</string>
4949
<string>open_sans_light.ttf</string>
5050
<string>BebasNeue-Regular.ttf</string>
51+
<string>repetitionscrolling.ttf</string>
52+
<string>7-segment.ttf</string>
5153
<string>Teko-Light.ttf</string>
5254
</array>
5355
<key>UIApplicationSceneManifest</key>

0 commit comments

Comments
 (0)