Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI Updates #26

Merged
merged 3 commits into from
Oct 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lumina/Lumina/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.10.0</string>
<string>0.10.1</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down
58 changes: 39 additions & 19 deletions Lumina/Lumina/LuminaButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,11 @@ final class LuminaButton: UIButton {
self.frame = CGRect(origin: CGPoint(x: 10, y: UIScreen.main.bounds.maxY - 50), size: CGSize(width: self.cancelButtonWidth, height: self.cancelButtonHeight))
break
case .shutter:
self.backgroundColor = UIColor.white
self.backgroundColor = UIColor.normalState
self.frame = CGRect(origin: CGPoint(x: UIScreen.main.bounds.midX - 35, y: UIScreen.main.bounds.maxY - 80), size: CGSize(width: self.shutterButtonDimension, height: self.shutterButtonDimension))
self.alpha = 0.65
self.layer.cornerRadius = CGFloat(self.shutterButtonDimension / 2)

let border = UIView(frame: self.frame)
border.backgroundColor = UIColor.blue
border.layer.cornerRadius = self.layer.cornerRadius
border.layer.borderWidth = 3.0
border.layer.borderColor = UIColor.white.cgColor
self.border = border
self.addSubview(border)

self.layer.borderWidth = 3
self.layer.borderColor = UIColor.borderNormalState
break
default:
break
Expand All @@ -101,8 +93,8 @@ final class LuminaButton: UIButton {
if style == .shutter {
DispatchQueue.main.async {
UIView.animate(withDuration: 0.1, animations: {
self.backgroundColor = UIColor.red
self.border?.backgroundColor = UIColor.red
self.backgroundColor = UIColor.recordingState
self.layer.borderColor = UIColor.borderRecordingState
self.transform = CGAffineTransform(scaleX: 1.3, y: 1.3)
})
}
Expand All @@ -113,8 +105,8 @@ final class LuminaButton: UIButton {
if style == .shutter {
DispatchQueue.main.async {
UIView.animate(withDuration: 0.1, animations: {
self.backgroundColor = UIColor.white
self.border?.backgroundColor = UIColor.white
self.backgroundColor = UIColor.normalState
self.layer.borderColor = UIColor.borderNormalState
self.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
})
}
Expand All @@ -125,12 +117,12 @@ final class LuminaButton: UIButton {
if style == .shutter {
DispatchQueue.main.async {
UIView.animate(withDuration: 0.1, animations: {
self.backgroundColor = UIColor.lightGray
self.border?.backgroundColor = UIColor.lightGray
self.backgroundColor = UIColor.takePhotoState
self.layer.borderColor = UIColor.borderTakePhotoState
}) { complete in
UIView.animate(withDuration: 0.1, animations: {
self.backgroundColor = UIColor.white
self.border?.backgroundColor = UIColor.white
self.backgroundColor = UIColor.normalState
self.layer.borderColor = UIColor.borderNormalState
})
}
}
Expand All @@ -141,3 +133,31 @@ final class LuminaButton: UIButton {
super.init(coder: aDecoder)
}
}

fileprivate extension UIColor {
class var normalState: UIColor {
return UIColor(white: 1.0, alpha: 0.65)
}

class var recordingState: UIColor {
return UIColor.red.withAlphaComponent(0.65)
}

class var takePhotoState: UIColor {
return UIColor.lightGray.withAlphaComponent(0.65)
}

class var borderNormalState: CGColor {
return UIColor.gray.cgColor
}

class var borderRecordingState: CGColor {
return UIColor.red.cgColor
}

class var borderTakePhotoState: CGColor {
return UIColor.darkGray.cgColor
}


}
12 changes: 11 additions & 1 deletion Lumina/Lumina/LuminaCamera.swift
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ final class LuminaCamera: NSObject {
if let connection = self.videoFileOutput.connection(with: AVMediaType.video), let videoConnection = self.videoDataOutput.connection(with: AVMediaType.video) {
connection.videoOrientation = videoConnection.videoOrientation
connection.isVideoMirrored = self.position == .front ? true : false
if connection.isVideoStabilizationSupported {
connection.preferredVideoStabilizationMode = .cinematic
}
self.session.commitConfiguration()
}
let fileName = NSTemporaryDirectory().appending(Date().iso8601 + ".mov")
self.videoFileOutput.startRecording(to: URL(fileURLWithPath: fileName), recordingDelegate: self)
Expand Down Expand Up @@ -338,6 +342,7 @@ final class LuminaCamera: NSObject {
if self.streamFrames {
self.session.addOutput(self.videoDataOutput)
}

self.session.addOutput(self.photoOutput)
if self.recordsVideo {
// adding this invalidates the video data output
Expand All @@ -346,6 +351,11 @@ final class LuminaCamera: NSObject {
return
}
self.session.addOutput(self.videoFileOutput)
if let connection = self.videoFileOutput.connection(with: .video) {
if connection.isVideoStabilizationSupported {
connection.preferredVideoStabilizationMode = .auto
}
}
}
if self.trackMetadata {
self.session.addOutput(self.metadataOutput)
Expand Down Expand Up @@ -461,7 +471,7 @@ extension LuminaCamera {
}
if input.device.isFocusModeSupported(.continuousAutoFocus) {
try input.device.lockForConfiguration()
input.device.focusMode = .continuousAutoFocus
input.device.focusMode = .autoFocus
if input.device.isExposureModeSupported(.continuousAutoExposure) {
input.device.exposureMode = .continuousAutoExposure
}
Expand Down
7 changes: 5 additions & 2 deletions Lumina/Lumina/LuminaDeviceUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ final class LuminaHapticFeedbackGenerator {
private let impactGeneratorSharedInstance = UIImpactFeedbackGenerator(style: .medium)
private let notificationGeneratorSharedInstance = UINotificationFeedbackGenerator()

func prepare() {
impactGeneratorSharedInstance.prepare()
notificationGeneratorSharedInstance.prepare()
}

func startRecordingVideoFeedback() {
if UIDevice.current.hasHapticFeedback {
impactGeneratorSharedInstance.impactOccurred()
Expand All @@ -26,7 +31,6 @@ final class LuminaHapticFeedbackGenerator {

func endRecordingVideoFeedback() {
if UIDevice.current.hasHapticFeedback {
notificationGeneratorSharedInstance.prepare()
notificationGeneratorSharedInstance.notificationOccurred(.success)
} else if UIDevice.current.hasTapticEngine {
let pop = SystemSoundID(1520)
Expand All @@ -37,7 +41,6 @@ final class LuminaHapticFeedbackGenerator {

func errorFeedback() {
if UIDevice.current.hasHapticFeedback {
notificationGeneratorSharedInstance.prepare()
notificationGeneratorSharedInstance.notificationOccurred(.error)
} else if UIDevice.current.hasTapticEngine {
let tryAgain = SystemSoundID(1102)
Expand Down
10 changes: 9 additions & 1 deletion Lumina/Lumina/LuminaViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,12 @@ public final class LuminaViewController: UIViewController {
}
}

/// override with caution
public override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
feedbackGenerator.prepare()
}

public override var shouldAutorotate: Bool {
guard let camera = self.camera else {
return true
Expand Down Expand Up @@ -744,11 +750,13 @@ extension LuminaViewController {
let focusView: UIImageView = UIImageView(image: UIImage(named: "cameraFocus", in: Bundle(for: LuminaViewController.self), compatibleWith: nil))
focusView.contentMode = .scaleAspectFit
focusView.frame = CGRect(x: 0, y: 0, width: 50, height: 50)
focusView.transform = CGAffineTransform(scaleX: 1.7, y: 1.7)
focusView.center = at
focusView.alpha = 0.0
self.view.addSubview(focusView)
UIView.animate(withDuration: 0.2, animations: {
UIView.animate(withDuration: 0.3, animations: {
focusView.alpha = 1.0
focusView.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
}, completion: { complete in
UIView.animate(withDuration: 1.0, animations: {
focusView.alpha = 0.0
Expand Down
12 changes: 6 additions & 6 deletions LuminaSample/LuminaSample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
500FA3011F9D1FAB004467BA /* Lumina.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 500FA3001F9D1F5B004467BA /* Lumina.framework */; };
500FA3021F9D1FAB004467BA /* Lumina.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 500FA3001F9D1F5B004467BA /* Lumina.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
509FF6611FA0AC8000FD62CD /* Lumina.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 509FF6601FA0AC1B00FD62CD /* Lumina.framework */; };
509FF6621FA0AC8000FD62CD /* Lumina.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 509FF6601FA0AC1B00FD62CD /* Lumina.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
534C1E9E1F7C3C59001127BC /* ResolutionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 534C1E9D1F7C3C59001127BC /* ResolutionViewController.swift */; };
5365BFD41F79829800B8F338 /* ImageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5365BFD31F79829800B8F338 /* ImageViewController.swift */; };
5365BFDA1F79AAA800B8F338 /* MobileNet.mlmodel in Sources */ = {isa = PBXBuildFile; fileRef = 5365BFD91F79AA9B00B8F338 /* MobileNet.mlmodel */; };
Expand All @@ -26,15 +26,15 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
500FA3021F9D1FAB004467BA /* Lumina.framework in Embed Frameworks */,
509FF6621FA0AC8000FD62CD /* Lumina.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
500FA3001F9D1F5B004467BA /* Lumina.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Lumina.framework; path = "../../../../Library/Developer/Xcode/DerivedData/Lumina-ahdbulwlusgxemcxeqxwjhqgazwd/Build/Products/Debug-iphoneos/Lumina.framework"; sourceTree = "<group>"; };
509FF6601FA0AC1B00FD62CD /* Lumina.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Lumina.framework; path = "../../../../Library/Developer/Xcode/DerivedData/Lumina-ahdbulwlusgxemcxeqxwjhqgazwd/Build/Products/Debug-iphoneos/Lumina.framework"; sourceTree = "<group>"; };
534C1E9D1F7C3C59001127BC /* ResolutionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResolutionViewController.swift; sourceTree = "<group>"; };
5365BFD31F79829800B8F338 /* ImageViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageViewController.swift; sourceTree = "<group>"; };
5365BFD91F79AA9B00B8F338 /* MobileNet.mlmodel */ = {isa = PBXFileReference; lastKnownFileType = file.mlmodel; name = MobileNet.mlmodel; path = LuminaSample/MobileNet.mlmodel; sourceTree = "<group>"; };
Expand All @@ -52,7 +52,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
500FA3011F9D1FAB004467BA /* Lumina.framework in Frameworks */,
509FF6611FA0AC8000FD62CD /* Lumina.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -94,7 +94,7 @@
53B829081EAAA16D00E3A624 /* Frameworks */ = {
isa = PBXGroup;
children = (
500FA3001F9D1F5B004467BA /* Lumina.framework */,
509FF6601FA0AC1B00FD62CD /* Lumina.framework */,
5365BFD91F79AA9B00B8F338 /* MobileNet.mlmodel */,
);
name = Frameworks;
Expand Down
3 changes: 2 additions & 1 deletion LuminaSample/LuminaSample/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.10.0</string>
<string>0.10.1</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
Expand All @@ -37,6 +37,7 @@
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
Expand Down