"ALL ON" and "ALL OFF" switches
This commit is contained in:
@@ -19,7 +19,7 @@
|
|||||||
0C41EF541C34BC9800AF847F /* XIONLogoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C41EF531C34BC9800AF847F /* XIONLogoView.swift */; };
|
0C41EF541C34BC9800AF847F /* XIONLogoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C41EF531C34BC9800AF847F /* XIONLogoView.swift */; };
|
||||||
0C41EF561C35ABCD00AF847F /* ConnectionStatusView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C41EF551C35ABCD00AF847F /* ConnectionStatusView.swift */; };
|
0C41EF561C35ABCD00AF847F /* ConnectionStatusView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C41EF551C35ABCD00AF847F /* ConnectionStatusView.swift */; };
|
||||||
0C4315001C35B1E700164559 /* WemoDevice.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C4314FF1C35B1E700164559 /* WemoDevice.swift */; };
|
0C4315001C35B1E700164559 /* WemoDevice.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C4314FF1C35B1E700164559 /* WemoDevice.swift */; };
|
||||||
0C4315061C35E67600164559 /* WemoDeviceCellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C4315051C35E67600164559 /* WemoDeviceCellView.swift */; };
|
0C4315061C35E67600164559 /* WemoCellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C4315051C35E67600164559 /* WemoCellView.swift */; };
|
||||||
0C63A8731C337381007E4B52 /* CubletsTechnique.plist in Resources */ = {isa = PBXBuildFile; fileRef = 0C63A8721C337381007E4B52 /* CubletsTechnique.plist */; };
|
0C63A8731C337381007E4B52 /* CubletsTechnique.plist in Resources */ = {isa = PBXBuildFile; fileRef = 0C63A8721C337381007E4B52 /* CubletsTechnique.plist */; };
|
||||||
0C63A8761C3373D1007E4B52 /* HorizontalBlur.vsh in Resources */ = {isa = PBXBuildFile; fileRef = 0C63A8751C3373D1007E4B52 /* HorizontalBlur.vsh */; };
|
0C63A8761C3373D1007E4B52 /* HorizontalBlur.vsh in Resources */ = {isa = PBXBuildFile; fileRef = 0C63A8751C3373D1007E4B52 /* HorizontalBlur.vsh */; };
|
||||||
0C63A8781C3373D9007E4B52 /* HorizontalBlur.fsh in Resources */ = {isa = PBXBuildFile; fileRef = 0C63A8771C3373D9007E4B52 /* HorizontalBlur.fsh */; };
|
0C63A8781C3373D9007E4B52 /* HorizontalBlur.fsh in Resources */ = {isa = PBXBuildFile; fileRef = 0C63A8771C3373D9007E4B52 /* HorizontalBlur.fsh */; };
|
||||||
@@ -49,7 +49,7 @@
|
|||||||
0C41EF531C34BC9800AF847F /* XIONLogoView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XIONLogoView.swift; sourceTree = "<group>"; };
|
0C41EF531C34BC9800AF847F /* XIONLogoView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XIONLogoView.swift; sourceTree = "<group>"; };
|
||||||
0C41EF551C35ABCD00AF847F /* ConnectionStatusView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConnectionStatusView.swift; sourceTree = "<group>"; };
|
0C41EF551C35ABCD00AF847F /* ConnectionStatusView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConnectionStatusView.swift; sourceTree = "<group>"; };
|
||||||
0C4314FF1C35B1E700164559 /* WemoDevice.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WemoDevice.swift; sourceTree = "<group>"; };
|
0C4314FF1C35B1E700164559 /* WemoDevice.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WemoDevice.swift; sourceTree = "<group>"; };
|
||||||
0C4315051C35E67600164559 /* WemoDeviceCellView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WemoDeviceCellView.swift; sourceTree = "<group>"; };
|
0C4315051C35E67600164559 /* WemoCellView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WemoCellView.swift; sourceTree = "<group>"; };
|
||||||
0C63A8721C337381007E4B52 /* CubletsTechnique.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = CubletsTechnique.plist; sourceTree = "<group>"; };
|
0C63A8721C337381007E4B52 /* CubletsTechnique.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = CubletsTechnique.plist; sourceTree = "<group>"; };
|
||||||
0C63A8751C3373D1007E4B52 /* HorizontalBlur.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = HorizontalBlur.vsh; sourceTree = "<group>"; };
|
0C63A8751C3373D1007E4B52 /* HorizontalBlur.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = HorizontalBlur.vsh; sourceTree = "<group>"; };
|
||||||
0C63A8771C3373D9007E4B52 /* HorizontalBlur.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = HorizontalBlur.fsh; sourceTree = "<group>"; };
|
0C63A8771C3373D9007E4B52 /* HorizontalBlur.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = HorizontalBlur.fsh; sourceTree = "<group>"; };
|
||||||
@@ -121,7 +121,7 @@
|
|||||||
0C41EF4F1C34B97700AF847F /* HeaderView.swift */,
|
0C41EF4F1C34B97700AF847F /* HeaderView.swift */,
|
||||||
0CF9A48D1C35E9C800276F13 /* SwitchIndicatorView.swift */,
|
0CF9A48D1C35E9C800276F13 /* SwitchIndicatorView.swift */,
|
||||||
0C41EF531C34BC9800AF847F /* XIONLogoView.swift */,
|
0C41EF531C34BC9800AF847F /* XIONLogoView.swift */,
|
||||||
0C4315051C35E67600164559 /* WemoDeviceCellView.swift */,
|
0C4315051C35E67600164559 /* WemoCellView.swift */,
|
||||||
);
|
);
|
||||||
path = Views;
|
path = Views;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@@ -290,7 +290,7 @@
|
|||||||
0C20E2BB1C33529700BA789B /* MainViewController.swift in Sources */,
|
0C20E2BB1C33529700BA789B /* MainViewController.swift in Sources */,
|
||||||
0C41EF501C34B97700AF847F /* HeaderView.swift in Sources */,
|
0C41EF501C34B97700AF847F /* HeaderView.swift in Sources */,
|
||||||
0C41EF541C34BC9800AF847F /* XIONLogoView.swift in Sources */,
|
0C41EF541C34BC9800AF847F /* XIONLogoView.swift in Sources */,
|
||||||
0C4315061C35E67600164559 /* WemoDeviceCellView.swift in Sources */,
|
0C4315061C35E67600164559 /* WemoCellView.swift in Sources */,
|
||||||
0CF9A48E1C35E9C800276F13 /* SwitchIndicatorView.swift in Sources */,
|
0CF9A48E1C35E9C800276F13 /* SwitchIndicatorView.swift in Sources */,
|
||||||
0C4315001C35B1E700164559 /* WemoDevice.swift in Sources */,
|
0C4315001C35B1E700164559 /* WemoDevice.swift in Sources */,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ class MainViewController: UIViewController, SwitchesViewControllerDelegate {
|
|||||||
|
|
||||||
// MARK: SwitchesViewControllerDelegate
|
// MARK: SwitchesViewControllerDelegate
|
||||||
|
|
||||||
func switchesViewControllerDidToggleDevice(controller: SwitchesViewController, device: WemoDevice)
|
func switchesViewControllerDidToggleDevices(controller: SwitchesViewController, devices: [WemoDevice])
|
||||||
{
|
{
|
||||||
_updateVisualization(true)
|
_updateVisualization(true)
|
||||||
}
|
}
|
||||||
@@ -120,6 +120,8 @@ class MainViewController: UIViewController, SwitchesViewControllerDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let percentageActivated = Float(activatedDevicesCount) / Float(self.devices.count)
|
let percentageActivated = Float(activatedDevicesCount) / Float(self.devices.count)
|
||||||
_visualizationController.setPercentActivated(percentageActivated, animated: animated)
|
if (percentageActivated != _visualizationController.percentActivated) {
|
||||||
|
_visualizationController.setPercentActivated(percentageActivated, animated: animated)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,32 +11,53 @@ import Foundation
|
|||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
protocol SwitchesViewControllerDelegate: class {
|
protocol SwitchesViewControllerDelegate: class {
|
||||||
func switchesViewControllerDidToggleDevice(controller: SwitchesViewController, device: WemoDevice)
|
func switchesViewControllerDidToggleDevices(controller: SwitchesViewController, devices: [WemoDevice])
|
||||||
}
|
}
|
||||||
|
|
||||||
extension SwitchesViewControllerDelegate {
|
extension SwitchesViewControllerDelegate {
|
||||||
func switchesViewControllerDidToggleDevice(controller: SwitchesViewController, device: WemoDevice) {}
|
func switchesViewControllerDidToggleDevices(controller: SwitchesViewController, devices: [WemoDevice]) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
class SwitchesViewController: UIViewController,
|
class SwitchesViewController: UIViewController,
|
||||||
UICollectionViewDataSource,
|
UICollectionViewDataSource,
|
||||||
UICollectionViewDelegateFlowLayout
|
UICollectionViewDelegateFlowLayout
|
||||||
{
|
{
|
||||||
weak var delegate: SwitchesViewControllerDelegate?
|
weak var delegate: SwitchesViewControllerDelegate?
|
||||||
|
|
||||||
private var _collectionView: UICollectionView = UICollectionView(frame: CGRectZero,
|
private var _collectionView: UICollectionView = UICollectionView(frame: CGRectZero,
|
||||||
collectionViewLayout: UICollectionViewFlowLayout())
|
collectionViewLayout: UICollectionViewFlowLayout())
|
||||||
private var _currentDevicesHash: UInt = 0
|
|
||||||
|
|
||||||
static private let collectionViewCellReuseIdentifier = "SwitchesCollectionViewReuseID"
|
static private let collectionViewDeviceSwitchCellReuseIdentifier = "DeviceSwitchReuseID"
|
||||||
|
static private let collectionViewActionCellReuseIdentifier = "ActionCellReuseID"
|
||||||
static private let collectionViewCellsSpacing: CGFloat = 5.0
|
static private let collectionViewCellsSpacing: CGFloat = 5.0
|
||||||
static private let collectionViewCellsPerRow = 3
|
static private let collectionViewCellsPerRow = 3
|
||||||
|
|
||||||
|
private enum ActionCell: Int {
|
||||||
|
case AllOn
|
||||||
|
case AllOff
|
||||||
|
|
||||||
|
func name() -> String
|
||||||
|
{
|
||||||
|
switch self {
|
||||||
|
case .AllOn:
|
||||||
|
return "All On"
|
||||||
|
case .AllOff:
|
||||||
|
return "All Off"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static let count: Int = {
|
||||||
|
var max = 0
|
||||||
|
while let _ = ActionCell(rawValue: max) { ++max }
|
||||||
|
return max
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
override func viewDidLoad()
|
override func viewDidLoad()
|
||||||
{
|
{
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|
||||||
let reuseID = SwitchesViewController.collectionViewCellReuseIdentifier
|
let deviceCellReuseID = SwitchesViewController.collectionViewDeviceSwitchCellReuseIdentifier
|
||||||
|
let actionCellReuseID = SwitchesViewController.collectionViewActionCellReuseIdentifier
|
||||||
let layout = _collectionView.collectionViewLayout as! UICollectionViewFlowLayout
|
let layout = _collectionView.collectionViewLayout as! UICollectionViewFlowLayout
|
||||||
layout.scrollDirection = .Vertical
|
layout.scrollDirection = .Vertical
|
||||||
layout.minimumLineSpacing = SwitchesViewController.collectionViewCellsSpacing
|
layout.minimumLineSpacing = SwitchesViewController.collectionViewCellsSpacing
|
||||||
@@ -45,7 +66,8 @@ class SwitchesViewController: UIViewController,
|
|||||||
_collectionView.backgroundColor = UIColor.blackColor()
|
_collectionView.backgroundColor = UIColor.blackColor()
|
||||||
_collectionView.delegate = self
|
_collectionView.delegate = self
|
||||||
_collectionView.dataSource = self
|
_collectionView.dataSource = self
|
||||||
_collectionView.registerClass(WemoDeviceCellView.self, forCellWithReuseIdentifier: reuseID)
|
_collectionView.registerClass(WemoDeviceCellView.self, forCellWithReuseIdentifier: deviceCellReuseID)
|
||||||
|
_collectionView.registerClass(WemoActionCellView.self, forCellWithReuseIdentifier: actionCellReuseID)
|
||||||
self.view.addSubview(_collectionView)
|
self.view.addSubview(_collectionView)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,15 +85,7 @@ class SwitchesViewController: UIViewController,
|
|||||||
{
|
{
|
||||||
didSet
|
didSet
|
||||||
{
|
{
|
||||||
var devicesHash: UInt = 0
|
_collectionView.reloadData()
|
||||||
for device in devices {
|
|
||||||
devicesHash += UInt(device.serial.hash)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_currentDevicesHash != devicesHash) {
|
|
||||||
_collectionView.reloadData()
|
|
||||||
_currentDevicesHash = devicesHash
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,19 +93,28 @@ class SwitchesViewController: UIViewController,
|
|||||||
|
|
||||||
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
|
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
|
||||||
{
|
{
|
||||||
return self.devices.count
|
return self.devices.count + ActionCell.count
|
||||||
}
|
}
|
||||||
|
|
||||||
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
|
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
|
||||||
{
|
{
|
||||||
let reuseID = SwitchesViewController.collectionViewCellReuseIdentifier
|
if (indexPath.item < ActionCell.count) {
|
||||||
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseID, forIndexPath: indexPath) as! WemoDeviceCellView
|
let reuseID = SwitchesViewController.collectionViewActionCellReuseIdentifier
|
||||||
|
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseID, forIndexPath: indexPath) as! WemoActionCellView
|
||||||
let device = self.devices[indexPath.row]
|
cell.textLabel.text = ActionCell(rawValue: indexPath.item)?.name().uppercaseString
|
||||||
cell.device = device
|
|
||||||
cell.ordinal = indexPath.row + 1
|
return cell
|
||||||
|
} else {
|
||||||
return cell
|
let reuseID = SwitchesViewController.collectionViewDeviceSwitchCellReuseIdentifier
|
||||||
|
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseID, forIndexPath: indexPath) as! WemoDeviceCellView
|
||||||
|
|
||||||
|
let deviceIdx = indexPath.item - ActionCell.count
|
||||||
|
let device = self.devices[deviceIdx]
|
||||||
|
cell.device = device
|
||||||
|
cell.ordinal = deviceIdx + 1
|
||||||
|
|
||||||
|
return cell
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func collectionView(collectionView: UICollectionView,
|
func collectionView(collectionView: UICollectionView,
|
||||||
@@ -101,17 +124,44 @@ class SwitchesViewController: UIViewController,
|
|||||||
let spacing = SwitchesViewController.collectionViewCellsSpacing
|
let spacing = SwitchesViewController.collectionViewCellsSpacing
|
||||||
let cellsPerRow = CGFloat(SwitchesViewController.collectionViewCellsPerRow)
|
let cellsPerRow = CGFloat(SwitchesViewController.collectionViewCellsPerRow)
|
||||||
let dimensions = rint(collectionView.bounds.size.width / cellsPerRow) - spacing
|
let dimensions = rint(collectionView.bounds.size.width / cellsPerRow) - spacing
|
||||||
return CGSize(width: dimensions, height: dimensions)
|
|
||||||
|
if (indexPath.item < ActionCell.count) {
|
||||||
|
return CGSize(width: collectionView.bounds.size.width, height: rint(dimensions / 2.0))
|
||||||
|
} else {
|
||||||
|
return CGSize(width: dimensions, height: dimensions)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath)
|
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath)
|
||||||
{
|
{
|
||||||
let cell = collectionView.cellForItemAtIndexPath(indexPath) as! WemoDeviceCellView
|
if (indexPath.item < ActionCell.count) {
|
||||||
cell.toggled = !cell.toggled
|
let tappedActionCell = ActionCell(rawValue: indexPath.item)
|
||||||
|
|
||||||
let device = self.devices[indexPath.row]
|
var currentDelay: NSTimeInterval = 0.0
|
||||||
device.state = (cell.toggled ? .On : .Off)
|
for var i = ActionCell.count; i < collectionView.numberOfItemsInSection(indexPath.section); ++i {
|
||||||
|
let cell = collectionView.cellForItemAtIndexPath(NSIndexPath(forItem: i, inSection: indexPath.section)) as! WemoDeviceCellView
|
||||||
self.delegate?.switchesViewControllerDidToggleDevice(self, device: device)
|
|
||||||
|
UIView.animateWithDuration(0.3, delay: currentDelay, options: UIViewAnimationOptions(), animations: { () -> Void in
|
||||||
|
cell.toggled = (tappedActionCell == .AllOn)
|
||||||
|
}, completion: nil)
|
||||||
|
|
||||||
|
currentDelay += 0.05
|
||||||
|
}
|
||||||
|
|
||||||
|
for device in self.devices {
|
||||||
|
device.state = (tappedActionCell == .AllOn ? .On : .Off)
|
||||||
|
}
|
||||||
|
|
||||||
|
self.delegate?.switchesViewControllerDidToggleDevices(self, devices: self.devices)
|
||||||
|
} else {
|
||||||
|
let cell = collectionView.cellForItemAtIndexPath(indexPath) as! WemoDeviceCellView
|
||||||
|
cell.toggled = !cell.toggled
|
||||||
|
|
||||||
|
let deviceIdx = indexPath.item - ActionCell.count
|
||||||
|
let device = self.devices[deviceIdx]
|
||||||
|
device.state = (cell.toggled ? .On : .Off)
|
||||||
|
|
||||||
|
self.delegate?.switchesViewControllerDidToggleDevices(self, devices: [device])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,11 +15,12 @@ import UIKit
|
|||||||
let π = CGFloat(M_PI)
|
let π = CGFloat(M_PI)
|
||||||
|
|
||||||
class VisualizationViewController: UIViewController {
|
class VisualizationViewController: UIViewController {
|
||||||
private var _scene: SCNScene = SCNScene()
|
private var _scene: SCNScene = SCNScene()
|
||||||
private var _sceneView: SCNView?
|
private var _sceneView: SCNView?
|
||||||
private var _cameraNode: SCNNode = SCNNode()
|
private var _cameraNode: SCNNode = SCNNode()
|
||||||
private var _cubletsNode: SCNNode = SCNNode()
|
private var _cubletsNode: SCNNode = SCNNode()
|
||||||
private var _cublets: [SCNNode] = []
|
private var _cublets: [SCNNode] = []
|
||||||
|
private var _percentActivated: Float = 0.0
|
||||||
|
|
||||||
static private let cubletsDimensions = 5
|
static private let cubletsDimensions = 5
|
||||||
static private let cubletsSize = 1.0
|
static private let cubletsSize = 1.0
|
||||||
@@ -63,6 +64,19 @@ class VisualizationViewController: UIViewController {
|
|||||||
|
|
||||||
// MARK: API
|
// MARK: API
|
||||||
|
|
||||||
|
var percentActivated: Float
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _percentActivated
|
||||||
|
}
|
||||||
|
|
||||||
|
set(percentage)
|
||||||
|
{
|
||||||
|
self.setPercentActivated(percentage, animated: false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func setPercentActivated(percentage: Float, animated: Bool)
|
func setPercentActivated(percentage: Float, animated: Bool)
|
||||||
{
|
{
|
||||||
let cubletsCount = _cublets.count
|
let cubletsCount = _cublets.count
|
||||||
@@ -98,6 +112,8 @@ class VisualizationViewController: UIViewController {
|
|||||||
|
|
||||||
_cubletsNode.runAction(rotAction)
|
_cubletsNode.runAction(rotAction)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_percentActivated = percentage
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Internal
|
// MARK: Internal
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// WemoDeviceCellView.swift
|
// WemoDeviceView.swift
|
||||||
// XIONControlPanel
|
// XIONControlPanel
|
||||||
//
|
//
|
||||||
// Created by Charles Magahern on 12/31/15.
|
// Created by Charles Magahern on 12/31/15.
|
||||||
@@ -8,16 +8,58 @@
|
|||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
class WemoDeviceCellView: UICollectionViewCell {
|
public class WemoCellView: UICollectionViewCell {
|
||||||
|
private var _selectionOverlayView: UIView = UIView()
|
||||||
|
|
||||||
|
static private var disabledBackgroundColor = UIColor(white: 0.2, alpha: 1.0)
|
||||||
|
static private var enabledBackgroundColor = UIColor(red: 0.0, green: 0.8, blue: 0.0, alpha: 1.0)
|
||||||
|
|
||||||
|
override init(frame: CGRect)
|
||||||
|
{
|
||||||
|
super.init(frame: frame)
|
||||||
|
|
||||||
|
self.contentView.backgroundColor = WemoCellView.disabledBackgroundColor
|
||||||
|
|
||||||
|
_selectionOverlayView.backgroundColor = UIColor.clearColor()
|
||||||
|
self.contentView.addSubview(_selectionOverlayView)
|
||||||
|
}
|
||||||
|
|
||||||
|
required public init?(coder aDecoder: NSCoder)
|
||||||
|
{
|
||||||
|
fatalError("unsupported")
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: Overrides
|
||||||
|
|
||||||
|
override public func layoutSubviews()
|
||||||
|
{
|
||||||
|
super.layoutSubviews()
|
||||||
|
|
||||||
|
let bounds = self.contentView.bounds
|
||||||
|
_selectionOverlayView.frame = bounds
|
||||||
|
}
|
||||||
|
|
||||||
|
override public var highlighted: Bool {
|
||||||
|
didSet
|
||||||
|
{
|
||||||
|
if (self.highlighted) {
|
||||||
|
_selectionOverlayView.backgroundColor = UIColor(white: 0.8, alpha: 1.0)
|
||||||
|
} else {
|
||||||
|
UIView.animateWithDuration(1.0, animations: { () -> Void in
|
||||||
|
self._selectionOverlayView.backgroundColor = UIColor.clearColor()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class WemoDeviceCellView: WemoCellView {
|
||||||
private var _device: WemoDevice?
|
private var _device: WemoDevice?
|
||||||
private var _ordinal: Int = 0
|
private var _ordinal: Int = 0
|
||||||
private var _selectionOverlayView: UIView = UIView()
|
|
||||||
private var _nameLabel: UILabel = UILabel()
|
private var _nameLabel: UILabel = UILabel()
|
||||||
private var _ordinalLabel: UILabel = UILabel()
|
private var _ordinalLabel: UILabel = UILabel()
|
||||||
private var _indicator: SwitchIndicatorView = SwitchIndicatorView()
|
private var _indicator: SwitchIndicatorView = SwitchIndicatorView()
|
||||||
|
|
||||||
static private var disabledBackgroundColor = UIColor(white: 0.2, alpha: 1.0)
|
|
||||||
static private var enabledBackgroundColor = UIColor(red: 0.0, green: 0.8, blue: 0.0, alpha: 1.0)
|
|
||||||
static private var disabledAnnotationsColor = UIColor.darkGrayColor()
|
static private var disabledAnnotationsColor = UIColor.darkGrayColor()
|
||||||
static private var enabledAnnotationsColor = UIColor.blackColor()
|
static private var enabledAnnotationsColor = UIColor.blackColor()
|
||||||
|
|
||||||
@@ -25,11 +67,6 @@ class WemoDeviceCellView: UICollectionViewCell {
|
|||||||
{
|
{
|
||||||
super.init(frame: frame)
|
super.init(frame: frame)
|
||||||
|
|
||||||
self.contentView.backgroundColor = WemoDeviceCellView.disabledBackgroundColor
|
|
||||||
|
|
||||||
_selectionOverlayView.backgroundColor = UIColor.clearColor()
|
|
||||||
self.contentView.addSubview(_selectionOverlayView)
|
|
||||||
|
|
||||||
_nameLabel.font = UIFont(name: "Orbitron-Medium", size: 16.0)
|
_nameLabel.font = UIFont(name: "Orbitron-Medium", size: 16.0)
|
||||||
_nameLabel.numberOfLines = 3
|
_nameLabel.numberOfLines = 3
|
||||||
_nameLabel.textColor = UIColor.whiteColor()
|
_nameLabel.textColor = UIColor.whiteColor()
|
||||||
@@ -44,22 +81,20 @@ class WemoDeviceCellView: UICollectionViewCell {
|
|||||||
self.contentView.addSubview(_indicator)
|
self.contentView.addSubview(_indicator)
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder aDecoder: NSCoder)
|
required public init?(coder aDecoder: NSCoder)
|
||||||
{
|
{
|
||||||
fatalError("unsupported")
|
fatalError("unsupported")
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Overrides
|
// MARK: Overrides
|
||||||
|
|
||||||
override func layoutSubviews()
|
override public func layoutSubviews()
|
||||||
{
|
{
|
||||||
super.layoutSubviews()
|
super.layoutSubviews()
|
||||||
|
|
||||||
let bounds = self.contentView.bounds
|
let bounds = self.contentView.bounds
|
||||||
let padding: CGFloat = 10.0
|
let padding: CGFloat = 10.0
|
||||||
|
|
||||||
_selectionOverlayView.frame = bounds
|
|
||||||
|
|
||||||
_indicator.frame = CGRect(
|
_indicator.frame = CGRect(
|
||||||
x: padding,
|
x: padding,
|
||||||
y: padding,
|
y: padding,
|
||||||
@@ -84,19 +119,6 @@ class WemoDeviceCellView: UICollectionViewCell {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override var highlighted: Bool {
|
|
||||||
didSet
|
|
||||||
{
|
|
||||||
if (self.highlighted) {
|
|
||||||
_selectionOverlayView.backgroundColor = UIColor(white: 0.8, alpha: 1.0)
|
|
||||||
} else {
|
|
||||||
UIView.animateWithDuration(1.0, animations: { () -> Void in
|
|
||||||
self._selectionOverlayView.backgroundColor = UIColor.clearColor()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: API
|
// MARK: API
|
||||||
|
|
||||||
var device: WemoDevice?
|
var device: WemoDevice?
|
||||||
@@ -140,14 +162,39 @@ class WemoDeviceCellView: UICollectionViewCell {
|
|||||||
_indicator.status = toggled
|
_indicator.status = toggled
|
||||||
|
|
||||||
if (toggled) {
|
if (toggled) {
|
||||||
self.contentView.backgroundColor = WemoDeviceCellView.enabledBackgroundColor
|
self.contentView.backgroundColor = WemoCellView.enabledBackgroundColor
|
||||||
_indicator.foregroundColor = WemoDeviceCellView.enabledAnnotationsColor
|
_indicator.foregroundColor = WemoDeviceCellView.enabledAnnotationsColor
|
||||||
_ordinalLabel.textColor = WemoDeviceCellView.enabledAnnotationsColor
|
_ordinalLabel.textColor = WemoDeviceCellView.enabledAnnotationsColor
|
||||||
} else {
|
} else {
|
||||||
self.contentView.backgroundColor = WemoDeviceCellView.disabledBackgroundColor
|
self.contentView.backgroundColor = WemoCellView.disabledBackgroundColor
|
||||||
_indicator.foregroundColor = WemoDeviceCellView.disabledAnnotationsColor
|
_indicator.foregroundColor = WemoDeviceCellView.disabledAnnotationsColor
|
||||||
_ordinalLabel.textColor = WemoDeviceCellView.disabledAnnotationsColor
|
_ordinalLabel.textColor = WemoDeviceCellView.disabledAnnotationsColor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class WemoActionCellView: WemoCellView {
|
||||||
|
public var textLabel: UILabel = UILabel()
|
||||||
|
|
||||||
|
override init(frame: CGRect)
|
||||||
|
{
|
||||||
|
super.init(frame: frame)
|
||||||
|
|
||||||
|
self.textLabel.font = UIFont(name: "Orbitron-Medium", size: 21.0)
|
||||||
|
self.textLabel.textColor = UIColor.whiteColor()
|
||||||
|
self.textLabel.textAlignment = .Center
|
||||||
|
self.addSubview(self.textLabel)
|
||||||
|
}
|
||||||
|
|
||||||
|
required public init?(coder aDecoder: NSCoder)
|
||||||
|
{
|
||||||
|
fatalError("unsupported")
|
||||||
|
}
|
||||||
|
|
||||||
|
override public func layoutSubviews()
|
||||||
|
{
|
||||||
|
super.layoutSubviews()
|
||||||
|
self.textLabel.frame = self.bounds
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user