Skip to content

Commit

Permalink
Release 0.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Rupérez committed Apr 4, 2018
1 parent e99f147 commit b2edc72
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 26 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# Release 0.1.4

- [x] cornerRadius IBInspectable property.
- [x] borderColor IBInspectable property.
- [x] borderWidth IBInspectable property.
- [x] selectedColor IBInspectable property.
- [x] highlightedColor IBInspectable property.
- [x] disabledColor IBInspectable property.
- [x] highlightedAlpha IBInspectable property.

# Release 0.1.3

- [x] shouldHideWaveform IBInspectable property.
Expand Down
35 changes: 27 additions & 8 deletions Example/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand All @@ -19,27 +20,45 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="jk2-hB-Uh3" customClass="SFButton" customModule="SpeechRecognizerButton">
<rect key="frame" x="164" y="318" width="46" height="30"/>
<state key="normal" title="Button"/>
<rect key="frame" x="164" y="310.5" width="46" height="46"/>
<color key="backgroundColor" red="1" green="0.14913141730000001" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="width" secondItem="jk2-hB-Uh3" secondAttribute="height" multiplier="1:1" id="Qs7-tj-BVZ"/>
<constraint firstAttribute="width" constant="46" id="aiU-6b-Ytt"/>
</constraints>
<state key="normal">
<color key="titleColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</state>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="color" keyPath="borderColor">
<color key="value" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="borderWidth">
<real key="value" value="5"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="cornerRadius">
<real key="value" value="23"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
<connections>
<outlet property="waveformView" destination="O8X-9j-l5M" id="gIB-4u-bOM"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="2lT-wx-Vzq">
<rect key="frame" x="166" y="289" width="42" height="21"/>
<rect key="frame" x="166" y="282" width="42" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="O8X-9j-l5M" customClass="SFWaveformView" customModule="SpeechRecognizerButton">
<rect key="frame" x="0.0" y="356" width="375" height="128"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<rect key="frame" x="0.0" y="364.5" width="375" height="128"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="height" constant="128" id="057-2H-aLB"/>
</constraints>
</view>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
<constraints>
<constraint firstItem="O8X-9j-l5M" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="1MI-jq-Zag"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="O8X-9j-l5M" secondAttribute="trailing" id="6m7-qO-PZ3"/>
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ button.interactionIdentifier = "..."
button.animationDuration = ...
button.shouldVibrate = ...
button.shouldSound = ...
button.shouldHideWaveform = ...
button.cornerRadius = ...
button.borderColor = ...
button.borderWidth = ...
button.selectedColor = ...
button.highlightedColor = ...
button.disabledColor = ...
button.highlightedAlpha = ...
```

### Customizing SFWaveformView configuration:
Expand Down
2 changes: 1 addition & 1 deletion SpeechRecognizerButton.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'SpeechRecognizerButton'
s.version = '0.1.3'
s.version = '0.1.4'
s.summary = 'UIButton subclass with push to talk recording, speech recognition and Siri-style waveform view'

s.homepage = 'https://github.com/alexruperez/SpeechRecognizerButton'
Expand Down
12 changes: 9 additions & 3 deletions SpeechRecognizerButton.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 0920;
LastUpgradeCheck = 0930;
ORGANIZATIONNAME = alexruperez;
TargetAttributes = {
814DED3420442E4000DCDDE0 = {
Expand Down Expand Up @@ -465,13 +465,15 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand All @@ -485,7 +487,7 @@
CURRENT_PROJECT_VERSION = "$(DYLIB_CURRENT_VERSION)";
DEBUG_INFORMATION_FORMAT = dwarf;
DYLIB_COMPATIBILITY_VERSION = 0.1.0;
DYLIB_CURRENT_VERSION = 0.1.3;
DYLIB_CURRENT_VERSION = 0.1.4;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
Expand Down Expand Up @@ -529,13 +531,15 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand All @@ -549,7 +553,7 @@
CURRENT_PROJECT_VERSION = "$(DYLIB_CURRENT_VERSION)";
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DYLIB_COMPATIBILITY_VERSION = 0.1.0;
DYLIB_CURRENT_VERSION = 0.1.3;
DYLIB_CURRENT_VERSION = 0.1.4;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
Expand All @@ -575,6 +579,7 @@
814DED4A20442E4100DCDDE0 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_IDENTITY = "";
DEFINES_MODULE = YES;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = SpeechRecognizerButton/Info.plist;
Expand All @@ -590,6 +595,7 @@
814DED4B20442E4100DCDDE0 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_IDENTITY = "";
DEFINES_MODULE = YES;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = SpeechRecognizerButton/Info.plist;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0920"
LastUpgradeVersion = "0930"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,9 +26,8 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
codeCoverageEnabled = "YES"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand Down Expand Up @@ -67,7 +66,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0920"
LastUpgradeVersion = "0930"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,9 +26,8 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
codeCoverageEnabled = "YES"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand Down Expand Up @@ -57,7 +56,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
31 changes: 29 additions & 2 deletions SpeechRecognizerButton/SFButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Speech
import AudioToolbox

@IBDesignable
public class SFButton: UIButton {
open class SFButton: UIButton {

public enum SFButtonError: Error {
public enum AuthorizationReason {
Expand Down Expand Up @@ -53,6 +53,13 @@ public class SFButton: UIButton {
@IBInspectable public var shouldVibrate: Bool = true
@IBInspectable public var shouldSound: Bool = true
@IBOutlet public weak var waveformView: SFWaveformView?
@IBInspectable public var cornerRadius: CGFloat = 0
@IBInspectable public var borderColor: UIColor = .black
@IBInspectable public var borderWidth: CGFloat = 0
@IBInspectable public var selectedColor: UIColor?
@IBInspectable public var highlightedColor: UIColor?
@IBInspectable public var disabledColor: UIColor?
@IBInspectable public var highlightedAlpha: CGFloat = 0.5

private var audioPlayer: AVAudioPlayer?
private var audioRecorder: AVAudioRecorder?
Expand All @@ -62,6 +69,7 @@ public class SFButton: UIButton {
private var speechRecognitionTask: SFSpeechRecognitionTask?
private let microphoneUsageDescriptionKey = UsageDescriptionKey("NSMicrophoneUsageDescription")
private let speechRecognitionUsageDescriptionKey = UsageDescriptionKey("NSSpeechRecognitionUsageDescription")
private var defaultColor: UIColor?

public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
Expand All @@ -77,13 +85,32 @@ public class SFButton: UIButton {
addTarget(self, action: #selector(self.touchDown(_:)), for: .touchDown)
addTarget(self, action: #selector(self.touchUpInside(_:)), for: .touchUpInside)
addTarget(self, action: #selector(self.touchUpOutside(_:)), for: .touchUpOutside)
defaultColor = backgroundColor
}

public override func draw(_ rect: CGRect) {
open override func draw(_ rect: CGRect) {
super.draw(rect)
waveformView(show: false, animationDuration: 0)
}

open override func layoutSubviews() {
super.layoutSubviews()
layer.cornerRadius = cornerRadius
layer.masksToBounds = cornerRadius > 0
layer.borderColor = borderColor.cgColor
layer.borderWidth = borderWidth
if let selectedColor = selectedColor, isSelected {
backgroundColor = selectedColor
} else if let highlightedColor = highlightedColor, isHighlighted {
backgroundColor = highlightedColor
} else if let disabledColor = disabledColor, !isEnabled {
backgroundColor = disabledColor
} else if let defaultColor = defaultColor {
backgroundColor = isHighlighted ? defaultColor.withAlphaComponent(highlightedAlpha) : defaultColor
}

}

deinit {
audioRecorderDisplayLink?.invalidate()
audioPlayerDisplayLink?.invalidate()
Expand Down
5 changes: 3 additions & 2 deletions SpeechRecognizerButton/SFWaveformView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Darwin
let pi = Double.pi

@IBDesignable
public class SFWaveformView: UIView {
open class SFWaveformView: UIView {
fileprivate(set) var _phase: CGFloat = 0.0
fileprivate(set) var _amplitude: CGFloat = 0.3

Expand All @@ -37,7 +37,7 @@ public class SFWaveformView: UIView {
setNeedsDisplay()
}

override public func draw(_ rect: CGRect) {
override open func draw(_ rect: CGRect) {
let context = UIGraphicsGetCurrentContext()
context?.clear(bounds)

Expand Down Expand Up @@ -82,4 +82,5 @@ public class SFWaveformView: UIView {
context?.strokePath()
}
}

}

0 comments on commit b2edc72

Please sign in to comment.