diff options
author | NicoleYarroch <nicole@livio.io> | 2020-09-03 10:44:02 -0400 |
---|---|---|
committer | NicoleYarroch <nicole@livio.io> | 2020-09-03 10:44:02 -0400 |
commit | 8603e615be1e6c5047b579fb10c1168071634912 (patch) | |
tree | be171641cf0ae2f9c2544f1cfd1799fe9af519ea /Example Apps | |
parent | 7b4202909c417680bff185d136326479299b8996 (diff) | |
parent | 3ec4d8109bb536df0c5afcc0c0ec826e6845af77 (diff) | |
download | sdl_ios-8603e615be1e6c5047b579fb10c1168071634912.tar.gz |
Merge branch 'develop' into feature/0312_update_min_required_iOS_version_to_10
Signed-off-by: NicoleYarroch <nicole@livio.io>
# Conflicts:
# SmartDeviceLinkTests/SDLSystemCapabilityManagerSpec.m
Diffstat (limited to 'Example Apps')
4 files changed, 144 insertions, 1 deletions
diff --git a/Example Apps/Example ObjC/SubscribeButtonManager.h b/Example Apps/Example ObjC/SubscribeButtonManager.h new file mode 100644 index 000000000..07ecc4c87 --- /dev/null +++ b/Example Apps/Example ObjC/SubscribeButtonManager.h @@ -0,0 +1,25 @@ +// +// SubscribeButtonManager.h +// SmartDeviceLink-Example-ObjC +// +// Created by Nicole on 6/19/20. +// Copyright © 2020 smartdevicelink. All rights reserved. +// + +#import <Foundation/Foundation.h> + +@class SDLManager; + +NS_ASSUME_NONNULL_BEGIN + +@interface SubscribeButtonManager : NSObject + +- (instancetype)init NS_UNAVAILABLE; +- (instancetype)initWithManager:(SDLManager *)manager; + +/// Subscribe to all available preset buttons. An alert will be shown when a preset button is short pressed or long pressed. +- (void)subscribeToAllPresetButtons; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Example Apps/Example ObjC/SubscribeButtonManager.m b/Example Apps/Example ObjC/SubscribeButtonManager.m new file mode 100644 index 000000000..cbe819288 --- /dev/null +++ b/Example Apps/Example ObjC/SubscribeButtonManager.m @@ -0,0 +1,68 @@ +// +// SubscribeButtonManager.m +// SmartDeviceLink-Example-ObjC +// +// Created by Nicole on 6/19/20. +// Copyright © 2020 smartdevicelink. All rights reserved. +// + +#import "SubscribeButtonManager.h" + +#import "AlertManager.h" +#import "SmartDeviceLink.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface SubscribeButtonManager() + +@property (strong, nonatomic) SDLManager *sdlManager; + +@end + +@implementation SubscribeButtonManager + +- (instancetype)initWithManager:(SDLManager *)manager { + self = [super init]; + if (!self) { + return nil; + } + + _sdlManager = manager; + + return self; +} + +- (void)subscribeToAllPresetButtons { + if (self.sdlManager.systemCapabilityManager.defaultMainWindowCapability.numCustomPresetsAvailable.intValue == 0) { + SDLLogW(@"The module does not support preset buttons"); + return; + } + + for (SDLButtonName buttonName in [self.class sdlex_allPresetButtons]) { + [self.sdlManager.screenManager subscribeButton:buttonName withObserver:self selector:@selector(sdlex_buttonPressEventWithButtonName:error:buttonPress:)]; + } +} + +- (void)sdlex_buttonPressEventWithButtonName:(SDLButtonName)buttonName error:(NSError *)error buttonPress:(SDLOnButtonPress *)buttonPress { + if (error != nil) { + SDLLogE(@"There was an error subscribing to the preset button: %@", error.localizedDescription); + return; + } + + NSString *alertMessage = nil; + if ([buttonPress.buttonPressMode isEqualToEnum:SDLButtonPressModeShort]) { + alertMessage = [NSString stringWithFormat:@"%@ short pressed", buttonName]; + } else { + alertMessage = [NSString stringWithFormat:@"%@ long pressed", buttonName]; + } + + [AlertManager sendAlertWithManager:self.sdlManager image:nil textField1:alertMessage textField2:nil]; +} + ++ (NSArray<SDLButtonName> *)sdlex_allPresetButtons { + return @[SDLButtonNamePreset0, SDLButtonNamePreset1, SDLButtonNamePreset2, SDLButtonNamePreset3, SDLButtonNamePreset4, SDLButtonNamePreset5, SDLButtonNamePreset6, SDLButtonNamePreset7]; +} + +@end + +NS_ASSUME_NONNULL_END diff --git a/Example Apps/Example ObjC/VehicleDataManager.m b/Example Apps/Example ObjC/VehicleDataManager.m index e7a8b0079..3f6c57e15 100644 --- a/Example Apps/Example ObjC/VehicleDataManager.m +++ b/Example Apps/Example ObjC/VehicleDataManager.m @@ -144,7 +144,7 @@ NS_ASSUME_NONNULL_BEGIN SDLLogD(@"App has permission to access vehicle data. Requesting vehicle data..."); - SDLGetVehicleData *getAllVehicleData = [[SDLGetVehicleData alloc] initWithGps:@YES speed:@YES rpm:@YES instantFuelConsumption:@YES fuelRange:@YES externalTemperature:@YES turnSignal:@YES vin:@YES gearStatus:@YES tirePressure:@YES odometer:@YES beltStatus:@YES bodyInformation:@YES deviceStatus:@YES driverBraking:@YES wiperStatus:@YES headLampStatus:@YES engineTorque:@YES accPedalPosition:@YES steeringWheelAngle:@YES engineOilLife:@YES electronicParkBrakeStatus:@YES cloudAppVehicleID:@YES eCallInfo:@YES airbagStatus:@YES emergencyEvent:@YES clusterModeStatus:@YES myKey:@YES handsOffSteering:@YES windowStatus:@YES]; + SDLGetVehicleData *getAllVehicleData = [[SDLGetVehicleData alloc] initWithGps:@YES speed:@YES rpm:@YES instantFuelConsumption:@YES fuelRange:@YES externalTemperature:@YES turnSignal:@YES vin:@YES gearStatus:@YES tirePressure:@YES odometer:@YES beltStatus:@YES bodyInformation:@YES deviceStatus:@YES driverBraking:@YES wiperStatus:@YES headLampStatus:@YES engineTorque:@YES accPedalPosition:@YES steeringWheelAngle:@YES engineOilLife:@YES electronicParkBrakeStatus:@YES cloudAppVehicleID:@YES stabilityControlsStatus:@YES eCallInfo:@YES airbagStatus:@YES emergencyEvent:@YES clusterModeStatus:@YES myKey:@YES handsOffSteering:@YES windowStatus:@YES]; #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" getAllVehicleData.fuelLevel = @YES; diff --git a/Example Apps/Example Swift/SubscribeButtonManager.swift b/Example Apps/Example Swift/SubscribeButtonManager.swift new file mode 100644 index 000000000..1bf128c1d --- /dev/null +++ b/Example Apps/Example Swift/SubscribeButtonManager.swift @@ -0,0 +1,50 @@ +// +// SubscribeButtonManager.swift +// SmartDeviceLink +// +// Created by Nicole on 6/19/20. +// Copyright © 2020 smartdevicelink. All rights reserved. +// + +import Foundation +import SmartDeviceLink +import SmartDeviceLinkSwift + +class SubscribeButtonManager: NSObject { + private let sdlManager: SDLManager! + private let presetButtons: [SDLButtonName] = [.preset0, .preset1, .preset2, .preset3, .preset4, .preset5, .preset6, .preset7] + + init(sdlManager: SDLManager) { + self.sdlManager = sdlManager + } + + /// Subscribe to all available preset buttons. An alert will be shown when a preset button is short pressed or long pressed. + func subscribeToPresetButtons() { + guard (sdlManager.systemCapabilityManager.defaultMainWindowCapability?.numCustomPresetsAvailable?.intValue ?? 0) > 0 else { + SDLLog.w("The module does not support preset buttons") + return + } + + presetButtons.forEach { buttonName in + sdlManager.screenManager.subscribeButton(buttonName, withObserver: self, selector: #selector(buttonPressEvent(buttonName:error:buttonPress:))) + } + } + + @objc private func buttonPressEvent(buttonName: SDLButtonName, error: Error?, buttonPress: SDLOnButtonPress?) { + if let error = error { + SDLLog.e("There was an error subscribing to the preset button: \(error)") + return + } + + guard let buttonPress = buttonPress else { return } + + let buttonNameString = buttonName.rawValue.rawValue + switch buttonPress.buttonPressMode { + case .short: + AlertManager.sendAlert(textField1: "\(buttonNameString) short pressed", sdlManager: sdlManager) + case .long: + AlertManager.sendAlert(textField1: "\(buttonNameString) long pressed", sdlManager: sdlManager) + default: fatalError() + } + } +} |