Commit dafbde3d by Daniel Dahan

initial code for MaterialCapture and CapturePreviewView

parent 2209f178
...@@ -72,6 +72,8 @@ ...@@ -72,6 +72,8 @@
9699879C1BC5FE49006D678E /* MaterialTextLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9699879B1BC5FE49006D678E /* MaterialTextLayer.swift */; }; 9699879C1BC5FE49006D678E /* MaterialTextLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9699879B1BC5FE49006D678E /* MaterialTextLayer.swift */; };
96C4FABE1BC3168900E4FFC3 /* MaterialTransitionAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96C4FABD1BC3168900E4FFC3 /* MaterialTransitionAnimation.swift */; }; 96C4FABE1BC3168900E4FFC3 /* MaterialTransitionAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96C4FABD1BC3168900E4FFC3 /* MaterialTransitionAnimation.swift */; };
96D26BFD1BC23649006478BD /* ImageCardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D26BFC1BC23649006478BD /* ImageCardView.swift */; }; 96D26BFD1BC23649006478BD /* ImageCardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D26BFC1BC23649006478BD /* ImageCardView.swift */; };
96DF18211C02A2F7008A2D19 /* MaterialCapture.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96DF18201C02A2F7008A2D19 /* MaterialCapture.swift */; };
96DF18231C02B813008A2D19 /* CapturePreviewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96DF18221C02B813008A2D19 /* CapturePreviewView.swift */; };
9A94D0FA1B895EA500F586A5 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = 963832631B88E5BF0015F710 /* LICENSE */; }; 9A94D0FA1B895EA500F586A5 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = 963832631B88E5BF0015F710 /* LICENSE */; };
9A94D0FB1B895EA500F586A5 /* Roboto-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 9AAC38591B8956E300FE6B2D /* Roboto-Regular.ttf */; }; 9A94D0FB1B895EA500F586A5 /* Roboto-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 9AAC38591B8956E300FE6B2D /* Roboto-Regular.ttf */; };
9A94D0FC1B895EA500F586A5 /* Roboto-Medium.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 9AAC38571B8956CF00FE6B2D /* Roboto-Medium.ttf */; }; 9A94D0FC1B895EA500F586A5 /* Roboto-Medium.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 9AAC38571B8956CF00FE6B2D /* Roboto-Medium.ttf */; };
...@@ -128,6 +130,8 @@ ...@@ -128,6 +130,8 @@
9699879B1BC5FE49006D678E /* MaterialTextLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialTextLayer.swift; sourceTree = "<group>"; }; 9699879B1BC5FE49006D678E /* MaterialTextLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialTextLayer.swift; sourceTree = "<group>"; };
96C4FABD1BC3168900E4FFC3 /* MaterialTransitionAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialTransitionAnimation.swift; sourceTree = "<group>"; }; 96C4FABD1BC3168900E4FFC3 /* MaterialTransitionAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialTransitionAnimation.swift; sourceTree = "<group>"; };
96D26BFC1BC23649006478BD /* ImageCardView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageCardView.swift; sourceTree = "<group>"; }; 96D26BFC1BC23649006478BD /* ImageCardView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageCardView.swift; sourceTree = "<group>"; };
96DF18201C02A2F7008A2D19 /* MaterialCapture.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialCapture.swift; sourceTree = "<group>"; };
96DF18221C02B813008A2D19 /* CapturePreviewView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CapturePreviewView.swift; sourceTree = "<group>"; };
9AAC38551B8956C500FE6B2D /* Roboto-Light.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-Light.ttf"; sourceTree = "<group>"; }; 9AAC38551B8956C500FE6B2D /* Roboto-Light.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-Light.ttf"; sourceTree = "<group>"; };
9AAC38571B8956CF00FE6B2D /* Roboto-Medium.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-Medium.ttf"; sourceTree = "<group>"; }; 9AAC38571B8956CF00FE6B2D /* Roboto-Medium.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-Medium.ttf"; sourceTree = "<group>"; };
9AAC38591B8956E300FE6B2D /* Roboto-Regular.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-Regular.ttf"; sourceTree = "<group>"; }; 9AAC38591B8956E300FE6B2D /* Roboto-Regular.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-Regular.ttf"; sourceTree = "<group>"; };
...@@ -248,6 +252,7 @@ ...@@ -248,6 +252,7 @@
964B17D71BBB38E2002A9CA0 /* Card */, 964B17D71BBB38E2002A9CA0 /* Card */,
65BDD1751BB8D44B006F7F2B /* Animation */, 65BDD1751BB8D44B006F7F2B /* Animation */,
964B17B21BBA445D002A9CA0 /* Layout */, 964B17B21BBA445D002A9CA0 /* Layout */,
96DF181F1C02A2CB008A2D19 /* Capture */,
); );
path = Source; path = Source;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -327,6 +332,15 @@ ...@@ -327,6 +332,15 @@
name = Theme; name = Theme;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
96DF181F1C02A2CB008A2D19 /* Capture */ = {
isa = PBXGroup;
children = (
96DF18201C02A2F7008A2D19 /* MaterialCapture.swift */,
96DF18221C02B813008A2D19 /* CapturePreviewView.swift */,
);
name = Capture;
sourceTree = "<group>";
};
9AAC38521B89553800FE6B2D /* Font */ = { 9AAC38521B89553800FE6B2D /* Font */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
...@@ -485,6 +499,7 @@ ...@@ -485,6 +499,7 @@
65BDD1471BB5B916006F7F2B /* MaterialView.swift in Sources */, 65BDD1471BB5B916006F7F2B /* MaterialView.swift in Sources */,
65BDD16C1BB88D1A006F7F2B /* MaterialShape.swift in Sources */, 65BDD16C1BB88D1A006F7F2B /* MaterialShape.swift in Sources */,
65AD15EA1BC05B3A0068AF9C /* MaterialLayer.swift in Sources */, 65AD15EA1BC05B3A0068AF9C /* MaterialLayer.swift in Sources */,
96DF18231C02B813008A2D19 /* CapturePreviewView.swift in Sources */,
65BDD1521BB6EE7C006F7F2B /* RobotoFont.swift in Sources */, 65BDD1521BB6EE7C006F7F2B /* RobotoFont.swift in Sources */,
9693BF991BCDC1450087054A /* SideNavigationViewController.swift in Sources */, 9693BF991BCDC1450087054A /* SideNavigationViewController.swift in Sources */,
9693BF961BCCCB520087054A /* BasicCardView.swift in Sources */, 9693BF961BCCCB520087054A /* BasicCardView.swift in Sources */,
...@@ -503,6 +518,7 @@ ...@@ -503,6 +518,7 @@
65BDD14B1BB5DD02006F7F2B /* MaterialFont.swift in Sources */, 65BDD14B1BB5DD02006F7F2B /* MaterialFont.swift in Sources */,
9699879C1BC5FE49006D678E /* MaterialTextLayer.swift in Sources */, 9699879C1BC5FE49006D678E /* MaterialTextLayer.swift in Sources */,
65BDD16A1BB7146B006F7F2B /* MaterialBorder.swift in Sources */, 65BDD16A1BB7146B006F7F2B /* MaterialBorder.swift in Sources */,
96DF18211C02A2F7008A2D19 /* MaterialCapture.swift in Sources */,
65BDD15B1BB7095E006F7F2B /* MaterialRadius.swift in Sources */, 65BDD15B1BB7095E006F7F2B /* MaterialRadius.swift in Sources */,
65BDD1721BB8CD77006F7F2B /* MaterialLabel.swift in Sources */, 65BDD1721BB8CD77006F7F2B /* MaterialLabel.swift in Sources */,
65BDD1491BB5DC98006F7F2B /* MaterialColor.swift in Sources */, 65BDD1491BB5DC98006F7F2B /* MaterialColor.swift in Sources */,
......
//
// Copyright (C) 2015 GraphKit, Inc. <http://graphkit.io> and other GraphKit contributors.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero 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 Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program located at the root of the software package
// in a file called LICENSE. If not, see <http://www.gnu.org/licenses/>.
//
import UIKit
import AVFoundation
public class CapturePreviewView : MaterialView {
/**
:name: layerClass
*/
public override class func layerClass() -> AnyClass {
return AVCaptureVideoPreviewLayer.self
}
/**
:name: capture
*/
public private(set) lazy var capture: MaterialCapture = MaterialCapture()
/**
:name: prepareView
*/
public override func prepareView() {
super.prepareView()
prepareSession()
}
/**
:name: captureDevicePointOfInterestForPoint
*/
public func captureDevicePointOfInterestForPoint(point: CGPoint) -> CGPoint {
return (layer as! AVCaptureVideoPreviewLayer).captureDevicePointOfInterestForPoint(point)
}
/**
:name: pointForCaptureDevicePointOfInterest
*/
public func pointForCaptureDevicePointOfInterest(point: CGPoint) -> CGPoint {
return (layer as! AVCaptureVideoPreviewLayer).pointForCaptureDevicePointOfInterest(point)
}
//
// :name: prepareSession
//
private func prepareSession() {
(layer as! AVCaptureVideoPreviewLayer).session = capture.session
}
}
\ No newline at end of file
//
// Copyright (C) 2015 GraphKit, Inc. <http://graphkit.io> and other GraphKit contributors.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero 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 Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program located at the root of the software package
// in a file called LICENSE. If not, see <http://www.gnu.org/licenses/>.
//
import UIKit
import AVFoundation
@objc(MaterialCaptureDelegate)
public protocol MaterialCaptureDelegate {
/**
:name: materialCaptureSessionFailedWithError
*/
optional func materialCaptureSessionFailedWithError(capture: MaterialCapture, error: NSError)
}
@objc(MaterialCapture)
public class MaterialCapture : NSObject {
/**
:name: cameraInput
*/
private var cameraInput: AVCaptureDeviceInput?
/**
:name: imageOutput
*/
private lazy var imageOutput: AVCaptureStillImageOutput = AVCaptureStillImageOutput()
/**
:name: session
*/
public private(set) lazy var session: AVCaptureSession = AVCaptureSession()
/**
:name: ccameraDevice
*/
public private(set) lazy var cameraDevice: AVCaptureDevice = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
/**
:name: delegate
*/
public weak var delegate: MaterialCaptureDelegate?
//
// :name: prepareSession
//
public func prepareSession() {
prepareCamera()
}
//
// :name: prepareCamera
//
private func prepareCamera() {
do {
cameraInput = try AVCaptureDeviceInput(device: cameraDevice)
if session.canAddInput(cameraInput) {
session.addInput(cameraInput)
}
if session.canAddOutput(imageOutput) {
session.addOutput(imageOutput)
}
session.startRunning()
} catch let e as NSError {
delegate?.materialCaptureSessionFailedWithError?(self, error: e)
}
}
}
...@@ -131,13 +131,6 @@ public class MaterialPulseView : MaterialView { ...@@ -131,13 +131,6 @@ public class MaterialPulseView : MaterialView {
} }
/** /**
:name: actionForLayer
*/
public override func actionForLayer(layer: CALayer, forKey event: String) -> CAAction? {
return nil // returning nil enables the animations for the layer property that are normally disabled.
}
/**
:name: prepareView :name: prepareView
*/ */
public override func prepareView() { public override func prepareView() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment