-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from blackboxembedded/carplay
Initial CarPlay Support
- Loading branch information
Showing
8 changed files
with
980 additions
and
864 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/* | ||
WunderLINQ Client Application | ||
Copyright (C) 2020 Keith Conger, Black Box Embedded, LLC | ||
|
||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
|
||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import UIKit | ||
import CarPlay | ||
|
||
class CarPlaySceneDelegate: UIResponder, CPTemplateApplicationSceneDelegate, CPListTemplateDelegate { | ||
var interfaceController: CPInterfaceController? | ||
var refreshTimer: Timer? | ||
|
||
func templateApplicationScene(_ templateApplicationScene: CPTemplateApplicationScene, | ||
didConnect interfaceController: CPInterfaceController) { | ||
|
||
self.interfaceController = interfaceController | ||
|
||
updateGridTemplate() | ||
|
||
// Start the timer to refresh the grid template every 10 seconds | ||
startRefreshTimer() | ||
} | ||
|
||
@objc func updateGridTemplate() { | ||
|
||
if #available(iOS 14.0, *) { | ||
let dataPoint1 = UserDefaults.standard.integer(forKey: "grid_one_preference") | ||
let gridButton1 = CPGridButton(titleVariants: [padString(MotorcycleData.getValue(dataPoint: dataPoint1))], | ||
image: MotorcycleData.getIcon(dataPoint: dataPoint1)) { button in | ||
} | ||
let dataPoint2 = UserDefaults.standard.integer(forKey: "grid_two_preference") | ||
let gridButton2 = CPGridButton(titleVariants: [padString(MotorcycleData.getValue(dataPoint: dataPoint2))], | ||
image: MotorcycleData.getIcon(dataPoint: dataPoint2)) { button in | ||
} | ||
let dataPoint3 = UserDefaults.standard.integer(forKey: "grid_three_preference") | ||
let gridButton3 = CPGridButton(titleVariants: [padString(MotorcycleData.getValue(dataPoint: dataPoint3))], | ||
image: MotorcycleData.getIcon(dataPoint: dataPoint3)) { button in | ||
} | ||
let dataPoint4 = UserDefaults.standard.integer(forKey: "grid_four_preference") | ||
let gridButton4 = CPGridButton(titleVariants: [padString(MotorcycleData.getValue(dataPoint: dataPoint4))], | ||
image: MotorcycleData.getIcon(dataPoint: dataPoint4)) { button in | ||
} | ||
let dataPoint5 = UserDefaults.standard.integer(forKey: "grid_five_preference") | ||
let gridButton5 = CPGridButton(titleVariants: [padString(MotorcycleData.getValue(dataPoint: dataPoint5))], | ||
image: MotorcycleData.getIcon(dataPoint: dataPoint5)) { button in | ||
} | ||
let dataPoint6 = UserDefaults.standard.integer(forKey: "grid_six_preference") | ||
let gridButton6 = CPGridButton(titleVariants: [padString(MotorcycleData.getValue(dataPoint: dataPoint6))], | ||
image: MotorcycleData.getIcon(dataPoint: dataPoint6)) { button in | ||
} | ||
let dataPoint7 = UserDefaults.standard.integer(forKey: "grid_seven_preference") | ||
let gridButton7 = CPGridButton(titleVariants: [padString(MotorcycleData.getValue(dataPoint: dataPoint7))], | ||
image: MotorcycleData.getIcon(dataPoint: dataPoint7)) { button in | ||
} | ||
let dataPoint8 = UserDefaults.standard.integer(forKey: "grid_eight_preference") | ||
let gridButton8 = CPGridButton(titleVariants: [padString(MotorcycleData.getValue(dataPoint: dataPoint8))], | ||
image: MotorcycleData.getIcon(dataPoint: dataPoint8)) { button in | ||
} | ||
let gridTemplate = CPGridTemplate(title: NSLocalizedString("product", comment: ""), gridButtons: [gridButton1,gridButton2,gridButton3,gridButton4,gridButton5,gridButton6,gridButton7,gridButton8]) | ||
|
||
interfaceController?.setRootTemplate(gridTemplate, | ||
animated: true, | ||
completion: nil) | ||
} else { | ||
// Fallback for iOS 13 | ||
interfaceController?.setRootTemplate(self.listTemplate(), | ||
animated: true) | ||
} | ||
} | ||
|
||
func startRefreshTimer() { | ||
refreshTimer?.invalidate() // Invalidate any existing timer | ||
refreshTimer = Timer.scheduledTimer(timeInterval: 10.0, target: self, selector: #selector(updateGridTemplate), userInfo: nil, repeats: true) | ||
} | ||
|
||
func listTemplate() -> CPListTemplate { | ||
let item = CPListItem(text: NSLocalizedString("carplay_ios14_warning_text", comment: ""), detailText: NSLocalizedString("carplay_ios14_warning_detail", comment: "")) | ||
|
||
if #available(iOS 14.0, *) { | ||
item.handler = { item, completion in | ||
NSLog("Item selected") | ||
completion() | ||
} | ||
} | ||
|
||
let section = CPListSection(items: [item]) | ||
let listTemplate = CPListTemplate(title: NSLocalizedString("product", comment: ""), sections: [section]) | ||
|
||
if #available(iOS 14.0, *) { | ||
// Do nothing, handler is already set | ||
} else { | ||
listTemplate.delegate = self | ||
} | ||
|
||
return listTemplate | ||
} | ||
|
||
func templateApplicationScene(_ templateApplicationScene: CPTemplateApplicationScene, didDisconnectInterfaceController interfaceController: CPInterfaceController) { | ||
self.interfaceController = nil | ||
refreshTimer?.invalidate() // Invalidate the timer when disconnected | ||
} | ||
|
||
// Delegate method for CPListTemplateDelegate (iOS 13) | ||
func listTemplate(_ listTemplate: CPListTemplate, didSelect item: CPListItem, completionHandler: @escaping () -> Void) { | ||
NSLog("Item selected") | ||
completionHandler() | ||
} | ||
|
||
func padString(_ input: String) -> String { | ||
let minimumLength = 10 | ||
|
||
// If the string is already of sufficient length, return it as is | ||
if input.count >= minimumLength { | ||
return input | ||
} | ||
|
||
// Calculate the number of spaces needed | ||
let totalPadding = minimumLength - input.count | ||
let leadingPadding = totalPadding / 2 | ||
let trailingPadding = totalPadding - leadingPadding | ||
|
||
// Create the padded string | ||
let paddedString = String(repeating: " ", count: leadingPadding) + input + String(repeating: " ", count: trailingPadding) | ||
|
||
return paddedString | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
WunderLINQ Client Application | ||
Copyright (C) 2020 Keith Conger, Black Box Embedded, LLC | ||
|
||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
|
||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import UIKit | ||
|
||
class SceneDelegate: UIResponder, UIWindowSceneDelegate { | ||
|
||
var window: UIWindow? | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<!-- | ||
Entitlements.plist | ||
WunderLINQ | ||
Created by Keith Conger on 8/29/24. | ||
Copyright (c) 2024 Black Box Embedded, LLC. All rights reserved. | ||
--> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>com.apple.developer.carplay-driving-task</key> | ||
<true/> | ||
</dict> | ||
</plist> |
Oops, something went wrong.