Commit 7c4aa92f by Daniel Dahan

editor: updated access type for Capture

parent 6b7cede3
...@@ -284,46 +284,46 @@ open class Capture: View { ...@@ -284,46 +284,46 @@ open class Capture: View {
open weak var delegate: CaptureDelegate? open weak var delegate: CaptureDelegate?
/// A reference to the CapturePreview view. /// A reference to the CapturePreview view.
open internal(set) var preview: CapturePreview! open fileprivate(set) var preview: CapturePreview!
/// A Timer reference for when recording is enabled. /// A Timer reference for when recording is enabled.
open internal(set) var timer: Timer? open fileprivate(set) var timer: Timer?
/// A tap gesture reference for focus events. /// A tap gesture reference for focus events.
internal var tapToFocusGesture: UITapGestureRecognizer? fileprivate var tapToFocusGesture: UITapGestureRecognizer?
/// A tap gesture reference for exposure events. /// A tap gesture reference for exposure events.
internal var tapToExposeGesture: UITapGestureRecognizer? fileprivate var tapToExposeGesture: UITapGestureRecognizer?
/// A tap gesture reference for reset events. /// A tap gesture reference for reset events.
internal var tapToResetGesture: UITapGestureRecognizer? fileprivate var tapToResetGesture: UITapGestureRecognizer?
/// A reference to the session DispatchQueue. /// A reference to the session DispatchQueue.
internal var sessionQueue: DispatchQueue! fileprivate var sessionQueue: DispatchQueue!
/// A reference to the active video input. /// A reference to the active video input.
internal var activeVideoInput: AVCaptureDeviceInput? fileprivate var activeVideoInput: AVCaptureDeviceInput?
/// A reference to the active audio input. /// A reference to the active audio input.
internal var activeAudioInput: AVCaptureDeviceInput? fileprivate var activeAudioInput: AVCaptureDeviceInput?
/// A reference to the image output. /// A reference to the image output.
internal var imageOutput: AVCaptureStillImageOutput! fileprivate var imageOutput: AVCaptureStillImageOutput!
/// A reference to the movie output. /// A reference to the movie output.
internal var movieOutput: AVCaptureMovieFileOutput! fileprivate var movieOutput: AVCaptureMovieFileOutput!
/// A reference to the movie output URL. /// A reference to the movie output URL.
internal var movieOutputURL: URL? fileprivate var movieOutputURL: URL?
/// A reference to the AVCaptureSession. /// A reference to the AVCaptureSession.
internal var session: AVCaptureSession! fileprivate var session: AVCaptureSession!
/// A boolean indicating if the session is running. /// A boolean indicating if the session is running.
open internal(set) var isRunning = false open fileprivate(set) var isRunning = false
/// A boolean indicating if the session is recording. /// A boolean indicating if the session is recording.
open internal(set) var isRecording = false open fileprivate(set) var isRecording = false
/// A reference to the recorded time duration. /// A reference to the recorded time duration.
open var recordedDuration: CMTime { open var recordedDuration: CMTime {
...@@ -481,7 +481,7 @@ open class Capture: View { ...@@ -481,7 +481,7 @@ open class Capture: View {
} }
/// A reference to the previous AVCaptureVideoOrientation. /// A reference to the previous AVCaptureVideoOrientation.
open internal(set) var previousVideoOrientation: AVCaptureVideoOrientation! open fileprivate(set) var previousVideoOrientation: AVCaptureVideoOrientation!
/// The capture video orientation. /// The capture video orientation.
open var videoOrientation: AVCaptureVideoOrientation { open var videoOrientation: AVCaptureVideoOrientation {
...@@ -626,14 +626,15 @@ open class Capture: View { ...@@ -626,14 +626,15 @@ open class Capture: View {
} }
} }
extension Capture { extension Capture {
internal func prepareOrientationNotifications() { /// Prepares self to observe orientation change notifications.
fileprivate func prepareOrientationNotifications() {
UIDevice.current.beginGeneratingDeviceOrientationNotifications() UIDevice.current.beginGeneratingDeviceOrientationNotifications()
NotificationCenter.default.addObserver(self, selector: #selector(handleOrientationNotifications(_:)), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(handleOrientationNotifications(_:)), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
} }
internal func removeOrientationNotifications() { /// Removes self from observing orientation change notifications.
fileprivate func removeOrientationNotifications() {
UIDevice.current.endGeneratingDeviceOrientationNotifications() UIDevice.current.endGeneratingDeviceOrientationNotifications()
NotificationCenter.default.removeObserver(self) NotificationCenter.default.removeObserver(self)
} }
...@@ -643,7 +644,7 @@ extension Capture { ...@@ -643,7 +644,7 @@ extension Capture {
- Parameter button: A UIButton that is associated with the event. - Parameter button: A UIButton that is associated with the event.
*/ */
@objc @objc
internal func handleOrientationNotifications(_ notification: Notification) { fileprivate func handleOrientationNotifications(_ notification: Notification) {
delegate?.capture?(capture: self, didChangeFrom: previousVideoOrientation, to: videoOrientation) delegate?.capture?(capture: self, didChangeFrom: previousVideoOrientation, to: videoOrientation)
previousVideoOrientation = videoOrientation previousVideoOrientation = videoOrientation
} }
...@@ -651,7 +652,7 @@ extension Capture { ...@@ -651,7 +652,7 @@ extension Capture {
extension Capture { extension Capture {
/// Prepares the preview. /// Prepares the preview.
internal func preparePreview() { fileprivate func preparePreview() {
preview = CapturePreview() preview = CapturePreview()
layout(preview).edges() layout(preview).edges()
...@@ -660,37 +661,37 @@ extension Capture { ...@@ -660,37 +661,37 @@ extension Capture {
} }
/// Prepares the captureButton. /// Prepares the captureButton.
internal func prepareCaptureButton() { fileprivate func prepareCaptureButton() {
captureButton?.addTarget(self, action: #selector(handleCaptureButton(button:)), for: .touchUpInside) captureButton?.addTarget(self, action: #selector(handleCaptureButton(button:)), for: .touchUpInside)
} }
/// Prepares the cameraButton. /// Prepares the cameraButton.
internal func prepareChangeModeButton() { fileprivate func prepareChangeModeButton() {
changeModeButton?.addTarget(self, action: #selector(handleChangeModeButton(button:)), for: .touchUpInside) changeModeButton?.addTarget(self, action: #selector(handleChangeModeButton(button:)), for: .touchUpInside)
} }
/// Prepares the changeCameraButton. /// Prepares the changeCameraButton.
internal func prepareChangeCameraButton() { fileprivate func prepareChangeCameraButton() {
changeCameraButton?.addTarget(self, action: #selector(handleChangeCameraButton(button:)), for: .touchUpInside) changeCameraButton?.addTarget(self, action: #selector(handleChangeCameraButton(button:)), for: .touchUpInside)
} }
/// Prepares the flashButton. /// Prepares the flashButton.
internal func prepareFlashButton() { fileprivate func prepareFlashButton() {
flashButton?.addTarget(self, action: #selector(handleFlashButton(button:)), for: .touchUpInside) flashButton?.addTarget(self, action: #selector(handleFlashButton(button:)), for: .touchUpInside)
} }
/// Prepares the sessionQueue. /// Prepares the sessionQueue.
internal func prepareSessionQueue() { fileprivate func prepareSessionQueue() {
sessionQueue = DispatchQueue(label: "com.cosmicmind.material.capture", attributes: .concurrent, target: nil) sessionQueue = DispatchQueue(label: "com.cosmicmind.material.capture", attributes: .concurrent, target: nil)
} }
/// Prepares the session. /// Prepares the session.
internal func prepareSession() { fileprivate func prepareSession() {
session = AVCaptureSession() session = AVCaptureSession()
} }
/// Prepares the activeVideoInput. /// Prepares the activeVideoInput.
internal func prepareActiveVideoInput() { fileprivate func prepareActiveVideoInput() {
do { do {
activeVideoInput = try AVCaptureDeviceInput(device: AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo)) activeVideoInput = try AVCaptureDeviceInput(device: AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo))
...@@ -705,7 +706,7 @@ extension Capture { ...@@ -705,7 +706,7 @@ extension Capture {
} }
/// Prepares the activeAudioInput. /// Prepares the activeAudioInput.
internal func prepareActiveAudioInput() { fileprivate func prepareActiveAudioInput() {
do { do {
activeAudioInput = try AVCaptureDeviceInput(device: AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeAudio)) activeAudioInput = try AVCaptureDeviceInput(device: AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeAudio))
...@@ -720,7 +721,7 @@ extension Capture { ...@@ -720,7 +721,7 @@ extension Capture {
} }
/// Prepares the imageOutput. /// Prepares the imageOutput.
internal func prepareImageOutput() { fileprivate func prepareImageOutput() {
imageOutput = AVCaptureStillImageOutput() imageOutput = AVCaptureStillImageOutput()
guard session.canAddOutput(imageOutput) else { guard session.canAddOutput(imageOutput) else {
...@@ -732,7 +733,7 @@ extension Capture { ...@@ -732,7 +733,7 @@ extension Capture {
} }
/// Prepares the movieOutput. /// Prepares the movieOutput.
internal func prepareMovieOutput() { fileprivate func prepareMovieOutput() {
movieOutput = AVCaptureMovieFileOutput() movieOutput = AVCaptureMovieFileOutput()
guard session.canAddOutput(movieOutput) else { guard session.canAddOutput(movieOutput) else {
...@@ -1051,7 +1052,7 @@ extension Capture { ...@@ -1051,7 +1052,7 @@ extension Capture {
- Parameter at: An AVCaptureDevicePosition. - Parameter at: An AVCaptureDevicePosition.
- Returns: An AVCaptureDevice if one exists, or nil otherwise. - Returns: An AVCaptureDevice if one exists, or nil otherwise.
*/ */
internal func camera(at position: AVCaptureDevicePosition) -> AVCaptureDevice? { fileprivate func camera(at position: AVCaptureDevicePosition) -> AVCaptureDevice? {
let devices = AVCaptureDevice.devices(withMediaType: AVMediaTypeVideo) as! [AVCaptureDevice] let devices = AVCaptureDevice.devices(withMediaType: AVMediaTypeVideo) as! [AVCaptureDevice]
for device in devices { for device in devices {
if device.position == position { if device.position == position {
...@@ -1065,7 +1066,7 @@ extension Capture { ...@@ -1065,7 +1066,7 @@ extension Capture {
Creates a unique URL if possible. Creates a unique URL if possible.
- Returns: A NSURL if it is possible to create one. - Returns: A NSURL if it is possible to create one.
*/ */
internal func uniqueURL() -> URL? { fileprivate func uniqueURL() -> URL? {
do { do {
let directory = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true) let directory = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
let dateFormatter = DateFormatter() let dateFormatter = DateFormatter()
...@@ -1088,7 +1089,7 @@ extension Capture { ...@@ -1088,7 +1089,7 @@ extension Capture {
- Parameter button: A UIButton that is associated with the event. - Parameter button: A UIButton that is associated with the event.
*/ */
@objc @objc
internal func handleCaptureButton(button: UIButton) { fileprivate func handleCaptureButton(button: UIButton) {
switch mode { switch mode {
case .photo: case .photo:
captureStillImage() captureStillImage()
...@@ -1110,7 +1111,7 @@ extension Capture { ...@@ -1110,7 +1111,7 @@ extension Capture {
- Parameter button: A UIButton that is associated with the event. - Parameter button: A UIButton that is associated with the event.
*/ */
@objc @objc
internal func handleChangeModeButton(button: UIButton) { fileprivate func handleChangeModeButton(button: UIButton) {
changeMode() changeMode()
delegate?.capture?(capture: self, didPressChangeMode: button) delegate?.capture?(capture: self, didPressChangeMode: button)
} }
...@@ -1120,7 +1121,7 @@ extension Capture { ...@@ -1120,7 +1121,7 @@ extension Capture {
- Parameter button: A UIButton that is associated with the event. - Parameter button: A UIButton that is associated with the event.
*/ */
@objc @objc
internal func handleChangeCameraButton(button: UIButton) { fileprivate func handleChangeCameraButton(button: UIButton) {
changeCamera() changeCamera()
delegate?.capture?(capture: self, didPressChangeCamera: button) delegate?.capture?(capture: self, didPressChangeCamera: button)
} }
...@@ -1130,7 +1131,7 @@ extension Capture { ...@@ -1130,7 +1131,7 @@ extension Capture {
- Parameter button: A UIButton that is associated with the event. - Parameter button: A UIButton that is associated with the event.
*/ */
@objc @objc
internal func handleFlashButton(button: UIButton) { fileprivate func handleFlashButton(button: UIButton) {
delegate?.capture?(capture: self, didPressFlash: button) delegate?.capture?(capture: self, didPressFlash: button)
} }
...@@ -1139,7 +1140,7 @@ extension Capture { ...@@ -1139,7 +1140,7 @@ extension Capture {
- Parameter recognizer: A UITapGestureRecognizer that is associated with the event. - Parameter recognizer: A UITapGestureRecognizer that is associated with the event.
*/ */
@objc @objc
internal func handleTapToFocusGesture(recognizer: UITapGestureRecognizer) { fileprivate func handleTapToFocusGesture(recognizer: UITapGestureRecognizer) {
guard isTapToFocusEnabled && isFocusPointOfInterestSupported else { guard isTapToFocusEnabled && isFocusPointOfInterestSupported else {
return return
} }
...@@ -1154,7 +1155,7 @@ extension Capture { ...@@ -1154,7 +1155,7 @@ extension Capture {
- Parameter recognizer: A UITapGestureRecognizer that is associated with the event. - Parameter recognizer: A UITapGestureRecognizer that is associated with the event.
*/ */
@objc @objc
internal func handleTapToExposeGesture(recognizer: UITapGestureRecognizer) { fileprivate func handleTapToExposeGesture(recognizer: UITapGestureRecognizer) {
guard isTapToExposeEnabled && isExposurePointOfInterestSupported else { guard isTapToExposeEnabled && isExposurePointOfInterestSupported else {
return return
} }
...@@ -1169,7 +1170,7 @@ extension Capture { ...@@ -1169,7 +1170,7 @@ extension Capture {
- Parameter recognizer: A UITapGestureRecognizer that is associated with the event. - Parameter recognizer: A UITapGestureRecognizer that is associated with the event.
*/ */
@objc @objc
internal func handleTapToResetGesture(recognizer: UITapGestureRecognizer) { fileprivate func handleTapToResetGesture(recognizer: UITapGestureRecognizer) {
guard isTapToResetEnabled else { guard isTapToResetEnabled else {
return return
} }
...@@ -1183,7 +1184,7 @@ extension Capture { ...@@ -1183,7 +1184,7 @@ extension Capture {
extension Capture { extension Capture {
/// Starts the timer for recording. /// Starts the timer for recording.
internal func startTimer() { fileprivate func startTimer() {
timer?.invalidate() timer?.invalidate()
timer = Timer(timeInterval: 0.5, target: self, selector: #selector(updateTimer), userInfo: nil, repeats: true) timer = Timer(timeInterval: 0.5, target: self, selector: #selector(updateTimer), userInfo: nil, repeats: true)
...@@ -1193,7 +1194,8 @@ extension Capture { ...@@ -1193,7 +1194,8 @@ extension Capture {
} }
/// Updates the timer when recording. /// Updates the timer when recording.
internal func updateTimer() { @objc
fileprivate func updateTimer() {
let duration = recordedDuration let duration = recordedDuration
let time = CMTimeGetSeconds(duration) let time = CMTimeGetSeconds(duration)
let hours = Int(time / 3600) let hours = Int(time / 3600)
...@@ -1204,7 +1206,7 @@ extension Capture { ...@@ -1204,7 +1206,7 @@ extension Capture {
} }
/// Stops the timer when recording. /// Stops the timer when recording.
internal func stopTimer() { fileprivate func stopTimer() {
let duration = recordedDuration let duration = recordedDuration
let time = CMTimeGetSeconds(duration) let time = CMTimeGetSeconds(duration)
let hours = Int(time / 3600) let hours = Int(time / 3600)
...@@ -1229,7 +1231,7 @@ extension Capture: UIGestureRecognizerDelegate { ...@@ -1229,7 +1231,7 @@ extension Capture: UIGestureRecognizerDelegate {
required to activate the gesture. required to activate the gesture.
- Parameter selector: A Selector to handle the event. - Parameter selector: A Selector to handle the event.
*/ */
internal func prepareTapGesture(gesture: inout UITapGestureRecognizer?, numberOfTapsRequired: Int, numberOfTouchesRequired: Int, selector: Selector) { fileprivate func prepareTapGesture(gesture: inout UITapGestureRecognizer?, numberOfTapsRequired: Int, numberOfTouchesRequired: Int, selector: Selector) {
guard nil == gesture else { guard nil == gesture else {
return return
} }
...@@ -1245,7 +1247,7 @@ extension Capture: UIGestureRecognizerDelegate { ...@@ -1245,7 +1247,7 @@ extension Capture: UIGestureRecognizerDelegate {
Removes a given tap gesture. Removes a given tap gesture.
- Parameter gesture: An optional UITapGestureRecognizer to remove. - Parameter gesture: An optional UITapGestureRecognizer to remove.
*/ */
internal func removeTapGesture(gesture: inout UITapGestureRecognizer?) { fileprivate func removeTapGesture(gesture: inout UITapGestureRecognizer?) {
guard let v = gesture else { guard let v = gesture else {
return return
} }
......
...@@ -54,8 +54,8 @@ public enum CharacterAttribute: String { ...@@ -54,8 +54,8 @@ public enum CharacterAttribute: String {
case verticalGlyphForm = "NSVerticalGlyphFormAttributeName" case verticalGlyphForm = "NSVerticalGlyphFormAttributeName"
} }
public func CharacterAttributeToValue(preset: CharacterAttribute) -> String { public func CharacterAttributeToValue(attribute: CharacterAttribute) -> String {
switch preset { switch attribute {
case .font: case .font:
return NSFontAttributeName return NSFontAttributeName
case .paragraphStyle: case .paragraphStyle:
...@@ -152,6 +152,78 @@ public protocol EditorDelegate { ...@@ -152,6 +152,78 @@ public protocol EditorDelegate {
} }
open class Editor: View { open class Editor: View {
/// A reference to the Text.
open internal(set) var text: Text!
/// A reference to the NSTextContainer.
open internal(set) var textContainer: NSTextContainer!
/// A reference to the NSLayoutManager.
open internal(set) var layoutManager: NSLayoutManager!
/// Reference to the TextView.
open internal(set) var textView: TextView!
/// A reference to an EditorDelegate. /// A reference to an EditorDelegate.
open weak var delegate: EditorDelegate? open weak var delegate: EditorDelegate?
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepare method
to initialize property values and other setup operations.
The super.prepare method should always be called immediately
when subclassing.
*/
open override func prepare() {
super.prepare()
prepareTextContainer()
prepareLayoutManager()
prepareText()
prepareTextView()
}
}
extension Editor {
/// Prepares the textContainer.
fileprivate func prepareTextContainer() {
textContainer = NSTextContainer(size: bounds.size)
}
/// Prepares the layoutManager.
fileprivate func prepareLayoutManager() {
layoutManager = NSLayoutManager()
layoutManager.addTextContainer(textContainer)
}
/// PRepares the text.
fileprivate func prepareText() {
text = Text()
text.delegate = self
text.textStorage.addLayoutManager(layoutManager)
}
/// Prepares the textView.
fileprivate func prepareTextView() {
textView = TextView(textContainer: textContainer)
layout(textView).edges()
}
}
extension Editor: TextDelegate {
/**
When changes in the textView text are made, this delegation method
is executed with the added text string and range.
*/
public func textWillProcessEdit(text: Text, textStorage: TextStorage, string: String, range: NSRange) {
textStorage.removeAttribute(CharacterAttribute.font.rawValue, range: range)
textStorage.addAttribute(CharacterAttribute.font.rawValue, value: RobotoFont.regular, range: range)
}
/**
When a match is detected within the textView text, this delegation
method is executed with the added text string and range.
*/
public func textDidProcessEdit(text: Text, textStorage: TextStorage, string: String, result: NSTextCheckingResult?, flags: NSRegularExpression.MatchingFlags, stop: UnsafeMutablePointer<ObjCBool>) {
textStorage.addAttribute(CharacterAttribute.font.rawValue, value: RobotoFont.bold, range: result!.range)
}
} }
...@@ -63,22 +63,14 @@ open class EditorController: ToolbarController { ...@@ -63,22 +63,14 @@ open class EditorController: ToolbarController {
*/ */
open override func prepare() { open override func prepare() {
super.prepare() super.prepare()
display = .full view.backgroundColor = .white
view.backgroundColor = .black
prepareStatusBar()
prepareToolbar() prepareToolbar()
prepareEditor() prepareEditor()
} }
/// Prepares the statusBar.
private func prepareStatusBar() {
statusBar.backgroundColor = .clear
}
/// Prepares the toolbar. /// Prepares the toolbar.
private func prepareToolbar() { private func prepareToolbar() {
toolbar.backgroundColor = .clear
toolbar.depthPreset = .none toolbar.depthPreset = .none
} }
......
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