Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
Material
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
Material
Commits
6802a94d
Commit
6802a94d
authored
Nov 23, 2015
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated CapturePreviewView to be asynchronous
parent
b957aa1e
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
210 additions
and
23 deletions
+210
-23
MaterialKit.xcodeproj/project.pbxproj
+4
-0
Source/BasicCaptureView.swift
+156
-0
Source/CaptureSession.swift
+26
-23
Source/MaterialTheme.swift
+24
-0
No files found.
MaterialKit.xcodeproj/project.pbxproj
View file @
6802a94d
...
...
@@ -74,6 +74,7 @@
96D26BFD1BC23649006478BD
/* ImageCardView.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96D26BFC1BC23649006478BD
/* ImageCardView.swift */
;
};
96DF18211C02A2F7008A2D19
/* CaptureSession.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96DF18201C02A2F7008A2D19
/* CaptureSession.swift */
;
};
96DF18231C02B813008A2D19
/* CapturePreviewView.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96DF18221C02B813008A2D19
/* CapturePreviewView.swift */
;
};
96DF58A91C03BD690020F65E
/* BasicCaptureView.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96DF58A81C03BD690020F65E
/* BasicCaptureView.swift */
;
};
9A94D0FA1B895EA500F586A5
/* LICENSE in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
963832631B88E5BF0015F710
/* LICENSE */
;
};
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 */
;
};
...
...
@@ -132,6 +133,7 @@
96D26BFC1BC23649006478BD
/* ImageCardView.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
ImageCardView.swift
;
sourceTree
=
"<group>"
;
};
96DF18201C02A2F7008A2D19
/* CaptureSession.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
CaptureSession.swift
;
sourceTree
=
"<group>"
;
};
96DF18221C02B813008A2D19
/* CapturePreviewView.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
CapturePreviewView.swift
;
sourceTree
=
"<group>"
;
};
96DF58A81C03BD690020F65E
/* BasicCaptureView.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
BasicCaptureView.swift
;
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>"
;
};
9AAC38591B8956E300FE6B2D
/* Roboto-Regular.ttf */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
file
;
path
=
"Roboto-Regular.ttf"
;
sourceTree
=
"<group>"
;
};
...
...
@@ -337,6 +339,7 @@
children
=
(
96DF18201C02A2F7008A2D19
/* CaptureSession.swift */
,
96DF18221C02B813008A2D19
/* CapturePreviewView.swift */
,
96DF58A81C03BD690020F65E
/* BasicCaptureView.swift */
,
);
name
=
Capture
;
sourceTree
=
"<group>"
;
...
...
@@ -509,6 +512,7 @@
964B17B41BBA447F002A9CA0
/* MaterialLayout.swift in Sources */
,
962F3E531BACA68C0004B8AD
/* NavigationBarView.swift in Sources */
,
65BDD14F1BB5EE4A006F7F2B
/* MaterialGravity.swift in Sources */
,
96DF58A91C03BD690020F65E
/* BasicCaptureView.swift in Sources */
,
65BDD1541BB6F473006F7F2B
/* MaterialDepth.swift in Sources */
,
65BDD1571BB6FC82006F7F2B
/* MaterialButton.swift in Sources */
,
65BDD17C1BB99E29006F7F2B
/* FabButton.swift in Sources */
,
...
...
Source/BasicCaptureView.swift
0 → 100644
View file @
6802a94d
//
// 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
public
class
BasicCaptureView
:
MaterialView
,
CaptureSessionDelegate
{
/**
:name: previewView
*/
public
private(set)
lazy
var
previewView
:
CapturePreviewView
=
CapturePreviewView
()
/**
:name: switchCamerasButton
*/
public
var
switchCamerasButton
:
MaterialButton
?
{
didSet
{
if
let
v
:
MaterialButton
=
switchCamerasButton
{
v
.
translatesAutoresizingMaskIntoConstraints
=
false
}
reloadView
()
}
}
/**
:name: switchCamerasButtonSize
*/
public
var
switchCamerasButtonSize
:
CGSize
=
CGSizeMake
(
48
,
48
)
{
didSet
{
reloadView
()
}
}
/**
:name: contentInsets
*/
public
var
contentInsets
:
MaterialInsets
=
.
None
{
didSet
{
contentInsetsRef
=
MaterialInsetsToValue
(
contentInsets
)
}
}
/**
:name: contentInsetsRef
*/
public
var
contentInsetsRef
:
MaterialInsetsType
=
MaterialTheme
.
basicCardView
.
contentInsetsRef
{
didSet
{
reloadView
()
}
}
/**
:name: init
*/
public
required
init
?(
coder
aDecoder
:
NSCoder
)
{
super
.
init
(
coder
:
aDecoder
)
}
/**
:name: init
*/
public
override
init
(
frame
:
CGRect
)
{
super
.
init
(
frame
:
frame
)
}
/**
:name: init
*/
public
convenience
init
()
{
self
.
init
(
frame
:
CGRectNull
)
}
/**
:name: layoutSublayersOfLayer
*/
public
override
func
layoutSublayersOfLayer
(
layer
:
CALayer
)
{
super
.
layoutSublayersOfLayer
(
layer
)
if
self
.
layer
==
layer
{
}
}
/**
:name: prepareView
*/
public
override
func
prepareView
()
{
super
.
prepareView
()
preparePreviewView
()
reloadView
()
}
/**
:name: reloadView
*/
public
func
reloadView
()
{
// clear constraints so new ones do not conflict
removeConstraints
(
constraints
)
for
v
in
subviews
{
v
.
removeFromSuperview
()
}
// var verticalFormat: String = "V:|"
// var views: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
// var metrics: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
addSubview
(
previewView
)
MaterialLayout
.
alignToParent
(
self
,
child
:
previewView
)
if
let
v
:
MaterialButton
=
switchCamerasButton
{
addSubview
(
v
)
MaterialLayout
.
alignFromBottomRight
(
self
,
child
:
v
,
bottom
:
16
,
right
:
16
)
MaterialLayout
.
size
(
self
,
child
:
v
,
width
:
switchCamerasButtonSize
.
width
,
height
:
switchCamerasButtonSize
.
height
)
v
.
removeTarget
(
self
,
action
:
"handleSwitchCameras"
,
forControlEvents
:
.
TouchUpInside
)
v
.
addTarget
(
self
,
action
:
"handleSwitchCameras"
,
forControlEvents
:
.
TouchUpInside
)
}
// if 0 < views.count {
// addConstraints(MaterialLayout.constraint(verticalFormat, options: [], metrics: metrics, views: views))
// }
}
/**
:name: captureSessionFailedWithError
*/
public
func
captureSessionFailedWithError
(
capture
:
CaptureSession
,
error
:
NSError
)
{
print
(
error
)
}
internal
func
handleSwitchCameras
()
{
previewView
.
captureSession
.
switchCameras
()
}
//
// :name: preparePreviewView
//
private
func
preparePreviewView
()
{
previewView
.
translatesAutoresizingMaskIntoConstraints
=
false
previewView
.
captureSession
.
delegate
=
self
previewView
.
captureSession
.
startSession
()
}
}
\ No newline at end of file
Source/CaptureSession.swift
View file @
6802a94d
...
...
@@ -59,14 +59,14 @@ public class CaptureSession : NSObject {
private
lazy
var
audioDevice
:
AVCaptureDevice
=
AVCaptureDevice
.
defaultDeviceWithMediaType
(
AVMediaTypeAudio
)
//
// :name:
v
ideoInput
// :name:
activeV
ideoInput
//
private
var
v
ideoInput
:
AVCaptureDeviceInput
?
private
var
activeV
ideoInput
:
AVCaptureDeviceInput
?
//
// :name: audioInput
// :name: a
ctiveA
udioInput
//
private
var
audioInput
:
AVCaptureDeviceInput
?
private
var
a
ctiveA
udioInput
:
AVCaptureDeviceInput
?
//
// :name: imageOutput
...
...
@@ -92,7 +92,7 @@ public class CaptureSession : NSObject {
:name: activeCamera
*/
public
var
activeCamera
:
AVCaptureDevice
?
{
return
v
ideoInput
?
.
device
return
activeV
ideoInput
?
.
device
}
/**
...
...
@@ -111,7 +111,7 @@ public class CaptureSession : NSObject {
if
1
<
cameraCount
{
if
activeCamera
?
.
position
==
.
Back
{
device
=
cameraWithPosition
(
.
Front
)
}
else
if
activeCamera
?
.
position
==
.
Front
{
}
else
{
device
=
cameraWithPosition
(
.
Back
)
}
}
...
...
@@ -169,23 +169,26 @@ public class CaptureSession : NSObject {
/**
:name: switchCameras
*/
public
func
switchCameras
()
->
Bool
{
public
func
switchCameras
()
{
if
canSwitchCameras
{
dispatch_async
(
videoQueue
)
{
do
{
let
vi
:
AVCaptureDeviceInput
?
=
try
AVCaptureDeviceInput
(
device
:
inactiveCamera
!
)
if
session
.
canAddInput
(
vi
)
{
session
.
beginConfiguration
()
session
.
removeInput
(
videoInput
)
session
.
addInput
(
vi
)
videoInput
=
vi
session
.
commitConfiguration
()
return
true
let
videoInput
:
AVCaptureDeviceInput
?
=
try
AVCaptureDeviceInput
(
device
:
self
.
inactiveCamera
!
)
self
.
session
.
beginConfiguration
()
self
.
session
.
removeInput
(
self
.
activeVideoInput
)
if
self
.
session
.
canAddInput
(
videoInput
)
{
self
.
session
.
addInput
(
videoInput
)
self
.
activeVideoInput
=
videoInput
}
else
{
self
.
session
.
addInput
(
self
.
activeVideoInput
)
}
self
.
session
.
commitConfiguration
()
}
catch
let
e
as
NSError
{
delegate
?
.
captureSessionFailedWithError
?(
self
,
error
:
e
)
self
.
delegate
?
.
captureSessionFailedWithError
?(
self
,
error
:
e
)
}
}
}
return
false
}
//
...
...
@@ -204,9 +207,9 @@ public class CaptureSession : NSObject {
//
private
func
prepareVideoInput
()
{
do
{
v
ideoInput
=
try
AVCaptureDeviceInput
(
device
:
videoDevice
)
if
session
.
canAddInput
(
v
ideoInput
)
{
session
.
addInput
(
v
ideoInput
)
activeV
ideoInput
=
try
AVCaptureDeviceInput
(
device
:
videoDevice
)
if
session
.
canAddInput
(
activeV
ideoInput
)
{
session
.
addInput
(
activeV
ideoInput
)
}
}
catch
let
e
as
NSError
{
delegate
?
.
captureSessionFailedWithError
?(
self
,
error
:
e
)
...
...
@@ -218,9 +221,9 @@ public class CaptureSession : NSObject {
//
private
func
prepareAudioInput
()
{
do
{
audioInput
=
try
AVCaptureDeviceInput
(
device
:
audioDevice
)
if
session
.
canAddInput
(
audioInput
)
{
session
.
addInput
(
audioInput
)
a
ctiveA
udioInput
=
try
AVCaptureDeviceInput
(
device
:
audioDevice
)
if
session
.
canAddInput
(
a
ctiveA
udioInput
)
{
session
.
addInput
(
a
ctiveA
udioInput
)
}
}
catch
let
e
as
NSError
{
delegate
?
.
captureSessionFailedWithError
?(
self
,
error
:
e
)
...
...
Source/MaterialTheme.swift
View file @
6802a94d
...
...
@@ -24,6 +24,7 @@ public struct MaterialTheme {
public
struct
basicCardView
{}
public
struct
imageCardView
{}
public
struct
navigationBarView
{}
public
struct
basicCaptureView
{}
public
struct
textLayer
{}
public
struct
label
{}
public
struct
flatButton
{}
...
...
@@ -204,6 +205,29 @@ public extension MaterialTheme.navigationBarView {
public
static
var
zPosition
:
CGFloat
=
100
}
// basicCaptureView
public
extension
MaterialTheme
.
basicCaptureView
{
// shadow
public
static
var
shadowDepth
:
MaterialDepth
=
.
Depth2
public
static
var
shadowColor
:
UIColor
=
MaterialColor
.
black
// shape
public
static
var
contentInsetsRef
:
MaterialInsetsType
=
MaterialInsetsToValue
(
.
Square2
)
// border
public
static
var
borderWidth
:
MaterialBorder
=
.
None
public
static
var
bordercolor
:
UIColor
=
MaterialColor
.
black
// color
public
static
var
backgroundColor
:
UIColor
=
MaterialColor
.
black
// interaction
public
static
var
userInteractionEnabled
:
Bool
=
true
// position
public
static
var
zPosition
:
CGFloat
=
0
}
// textLayer
public
extension
MaterialTheme
.
textLayer
{
// scale
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment