Beginning work on device cells
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
//
|
||||
// ArcadeMachinesViewController.swift
|
||||
// XIONControlPanel
|
||||
//
|
||||
// Created by Charles Magahern on 12/30/15.
|
||||
// Copyright © 2015 XION. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class ArcadeMachinesViewController: UIViewController {
|
||||
override func viewDidLoad()
|
||||
{
|
||||
super.viewDidLoad()
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import UIKit
|
||||
|
||||
class MainViewController: UIViewController {
|
||||
private var _visualizationController: VisualizationViewController = VisualizationViewController()
|
||||
private var _machinesController: ArcadeMachinesViewController = ArcadeMachinesViewController()
|
||||
private var _switchesController: SwitchesViewController = SwitchesViewController()
|
||||
private var _headerView: HeaderView = HeaderView()
|
||||
|
||||
// MARK: Overrides
|
||||
@@ -24,8 +24,8 @@ class MainViewController: UIViewController {
|
||||
self.addChildViewController(_visualizationController)
|
||||
self.view.addSubview(_visualizationController.view)
|
||||
|
||||
self.addChildViewController(_machinesController)
|
||||
self.view.addSubview(_machinesController.view)
|
||||
self.addChildViewController(_switchesController)
|
||||
self.view.addSubview(_switchesController.view)
|
||||
|
||||
self.view.addSubview(_headerView)
|
||||
}
|
||||
@@ -53,18 +53,18 @@ class MainViewController: UIViewController {
|
||||
let visualizationFrame = CGRect(
|
||||
x: bodyBounds.origin.x,
|
||||
y: bodyBounds.origin.y,
|
||||
width: rint((5.0 / 8.0) * bodyBounds.size.width),
|
||||
width: rint(0.6 * bodyBounds.size.width),
|
||||
height: bodyBounds.size.height
|
||||
)
|
||||
_visualizationController.view.frame = visualizationFrame
|
||||
|
||||
let machinesControllerFrame = CGRect(
|
||||
let switchesControllerFrame = CGRect(
|
||||
x: CGRectGetMaxX(visualizationFrame),
|
||||
y: bodyBounds.origin.y,
|
||||
width: bodyBounds.size.width - visualizationFrame.size.width,
|
||||
height: bodyBounds.size.height
|
||||
)
|
||||
_machinesController.view.frame = machinesControllerFrame
|
||||
_switchesController.view.frame = switchesControllerFrame
|
||||
}
|
||||
|
||||
override func viewDidAppear(animated: Bool)
|
||||
|
||||
74
XIONControlPanel/Controllers/SwitchesViewController.swift
Normal file
74
XIONControlPanel/Controllers/SwitchesViewController.swift
Normal file
@@ -0,0 +1,74 @@
|
||||
//
|
||||
// SwitchesViewController.swift
|
||||
// XIONControlPanel
|
||||
//
|
||||
// Created by Charles Magahern on 12/30/15.
|
||||
// Copyright © 2015 XION. All rights reserved.
|
||||
//
|
||||
|
||||
import Darwin
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
class SwitchesViewController: UIViewController,
|
||||
UICollectionViewDataSource,
|
||||
UICollectionViewDelegateFlowLayout
|
||||
{
|
||||
private var _collectionView: UICollectionView = UICollectionView(frame: CGRectZero,
|
||||
collectionViewLayout: UICollectionViewFlowLayout())
|
||||
|
||||
static private let collectionViewCellReuseIdentifier = "SwitchesCollectionViewReuseID"
|
||||
static private let collectionViewCellsSpacing: CGFloat = 5.0
|
||||
static private let collectionViewCellsPerRow = 3
|
||||
|
||||
override func viewDidLoad()
|
||||
{
|
||||
super.viewDidLoad()
|
||||
|
||||
let reuseID = SwitchesViewController.collectionViewCellReuseIdentifier
|
||||
let layout = _collectionView.collectionViewLayout as! UICollectionViewFlowLayout
|
||||
layout.scrollDirection = .Vertical
|
||||
layout.minimumLineSpacing = SwitchesViewController.collectionViewCellsSpacing
|
||||
layout.minimumInteritemSpacing = SwitchesViewController.collectionViewCellsSpacing
|
||||
|
||||
_collectionView.backgroundColor = UIColor.blackColor()
|
||||
_collectionView.delegate = self
|
||||
_collectionView.dataSource = self
|
||||
_collectionView.registerClass(WemoDeviceCellView.self, forCellWithReuseIdentifier: reuseID)
|
||||
self.view.addSubview(_collectionView)
|
||||
}
|
||||
|
||||
override func viewDidLayoutSubviews()
|
||||
{
|
||||
super.viewDidLayoutSubviews()
|
||||
|
||||
let bounds = self.view.bounds
|
||||
_collectionView.frame = bounds
|
||||
}
|
||||
|
||||
// MARK: UICollectionView
|
||||
|
||||
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
|
||||
{
|
||||
return 10
|
||||
}
|
||||
|
||||
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
|
||||
{
|
||||
let reuseID = SwitchesViewController.collectionViewCellReuseIdentifier
|
||||
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseID, forIndexPath: indexPath) as! WemoDeviceCellView
|
||||
cell.ordinal = indexPath.row + 1
|
||||
|
||||
return cell
|
||||
}
|
||||
|
||||
func collectionView(collectionView: UICollectionView,
|
||||
layout collectionViewLayout: UICollectionViewLayout,
|
||||
sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize
|
||||
{
|
||||
let spacing = SwitchesViewController.collectionViewCellsSpacing
|
||||
let cellsPerRow = CGFloat(SwitchesViewController.collectionViewCellsPerRow)
|
||||
let dimensions = rint(collectionView.bounds.size.width / cellsPerRow) - spacing
|
||||
return CGSize(width: dimensions, height: dimensions)
|
||||
}
|
||||
}
|
||||
62
XIONControlPanel/Models/WemoDevice.swift
Normal file
62
XIONControlPanel/Models/WemoDevice.swift
Normal file
@@ -0,0 +1,62 @@
|
||||
//
|
||||
// WemoDevice.swift
|
||||
// XIONControlPanel
|
||||
//
|
||||
// Created by Charles Magahern on 12/31/15.
|
||||
// Copyright © 2015 XION. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
struct WemoDevice {
|
||||
enum State {
|
||||
case Off
|
||||
case On
|
||||
}
|
||||
|
||||
enum Type {
|
||||
case Switch
|
||||
}
|
||||
|
||||
var name: String = ""
|
||||
var host: String = ""
|
||||
var model: String = ""
|
||||
var state: State = .Off
|
||||
var type: Type = .Switch
|
||||
var serial: String = ""
|
||||
|
||||
init()
|
||||
{}
|
||||
|
||||
init(_ responseData: NSData)
|
||||
{
|
||||
if let dict = (try? NSJSONSerialization.JSONObjectWithData(responseData, options: NSJSONReadingOptions())) as? NSDictionary {
|
||||
if let name = dict["name"] as? NSString {
|
||||
self.name = String(name)
|
||||
}
|
||||
|
||||
if let host = dict["host"] as? NSString {
|
||||
self.host = String(host)
|
||||
}
|
||||
|
||||
if let model = dict["model"] as? NSString {
|
||||
self.model = String(model)
|
||||
}
|
||||
|
||||
if let state = dict["state"] as? NSNumber {
|
||||
switch (state.integerValue) {
|
||||
case 0:
|
||||
self.state = .Off
|
||||
case 1:
|
||||
self.state = .On
|
||||
default:
|
||||
self.state = .Off
|
||||
}
|
||||
}
|
||||
|
||||
if let serial = dict["serialnumber"] as? NSString {
|
||||
self.serial = String(serial)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
105
XIONControlPanel/Views/SwitchIndicatorView.swift
Normal file
105
XIONControlPanel/Views/SwitchIndicatorView.swift
Normal file
@@ -0,0 +1,105 @@
|
||||
//
|
||||
// SwitchIndicatorView.swift
|
||||
// XIONControlPanel
|
||||
//
|
||||
// Created by Charles Magahern on 12/31/15.
|
||||
// Copyright © 2015 XION. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class SwitchIndicatorView: UIView {
|
||||
private var _status: Bool = false
|
||||
private var _foregroundColor: UIColor = UIColor.whiteColor()
|
||||
private var _outerCircleLayer: CAShapeLayer = CAShapeLayer()
|
||||
private var _offSymbolLayer: CAShapeLayer = CAShapeLayer()
|
||||
private var _onSymbolLayer: CAShapeLayer = CAShapeLayer()
|
||||
|
||||
static private var lineWidth: CGFloat = 2.0
|
||||
|
||||
override init(frame: CGRect)
|
||||
{
|
||||
super.init(frame: frame)
|
||||
|
||||
_outerCircleLayer.fillColor = UIColor.clearColor().CGColor
|
||||
_outerCircleLayer.lineWidth = SwitchIndicatorView.lineWidth
|
||||
|
||||
_offSymbolLayer.fillColor = UIColor.clearColor().CGColor
|
||||
_offSymbolLayer.lineWidth = SwitchIndicatorView.lineWidth
|
||||
|
||||
self.layer.addSublayer(_outerCircleLayer)
|
||||
self.layer.addSublayer(_offSymbolLayer)
|
||||
self.layer.addSublayer(_onSymbolLayer)
|
||||
|
||||
self.status = false
|
||||
self.foregroundColor = UIColor.whiteColor()
|
||||
}
|
||||
|
||||
required init?(coder aDecoder: NSCoder)
|
||||
{
|
||||
fatalError("unsupported")
|
||||
}
|
||||
|
||||
override func layoutSubviews()
|
||||
{
|
||||
super.layoutSubviews()
|
||||
|
||||
let bounds = self.bounds
|
||||
let lineWidth = SwitchIndicatorView.lineWidth
|
||||
|
||||
_outerCircleLayer.frame = bounds
|
||||
_offSymbolLayer.frame = bounds
|
||||
_onSymbolLayer.frame = bounds
|
||||
|
||||
_outerCircleLayer.path = CGPathCreateWithEllipseInRect(bounds, nil)
|
||||
|
||||
let innerSize = CGSize(width: rint(bounds.size.width / 2.0), height: rint(bounds.size.height / 2.0))
|
||||
let innerBounds = CGRect(
|
||||
x: rint(bounds.size.width / 2.0 - innerSize.width / 2.0),
|
||||
y: rint(bounds.size.height / 2.0 - innerSize.height / 2.0),
|
||||
width: innerSize.width,
|
||||
height: innerSize.height
|
||||
)
|
||||
_offSymbolLayer.path = CGPathCreateWithEllipseInRect(innerBounds, nil)
|
||||
|
||||
let onSymbolSize = CGSize(width: lineWidth, height: innerSize.height)
|
||||
let onSymbolRect = CGRect(
|
||||
x: rint(bounds.size.width / 2.0 - onSymbolSize.width / 2.0),
|
||||
y: rint(bounds.size.height / 2.0 - onSymbolSize.height / 2.0),
|
||||
width: onSymbolSize.width,
|
||||
height: onSymbolSize.height
|
||||
)
|
||||
_onSymbolLayer.path = CGPathCreateWithRect(onSymbolRect, nil)
|
||||
}
|
||||
|
||||
// MARK: API
|
||||
|
||||
var status: Bool {
|
||||
get
|
||||
{
|
||||
return _status
|
||||
}
|
||||
|
||||
set(status)
|
||||
{
|
||||
_status = status
|
||||
_offSymbolLayer.hidden = _status
|
||||
_onSymbolLayer.hidden = !_status
|
||||
}
|
||||
}
|
||||
|
||||
var foregroundColor: UIColor {
|
||||
get
|
||||
{
|
||||
return _foregroundColor
|
||||
}
|
||||
|
||||
set(color)
|
||||
{
|
||||
_foregroundColor = color
|
||||
_outerCircleLayer.strokeColor = _foregroundColor.CGColor
|
||||
_offSymbolLayer.strokeColor = _foregroundColor.CGColor
|
||||
_onSymbolLayer.fillColor = _foregroundColor.CGColor
|
||||
}
|
||||
}
|
||||
}
|
||||
105
XIONControlPanel/Views/WemoDeviceCellView.swift
Normal file
105
XIONControlPanel/Views/WemoDeviceCellView.swift
Normal file
@@ -0,0 +1,105 @@
|
||||
//
|
||||
// WemoDeviceCellView.swift
|
||||
// XIONControlPanel
|
||||
//
|
||||
// Created by Charles Magahern on 12/31/15.
|
||||
// Copyright © 2015 XION. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class WemoDeviceCellView: UICollectionViewCell {
|
||||
private var _device: WemoDevice?
|
||||
private var _ordinal: Int = 0
|
||||
private var _nameLabel: UILabel = UILabel()
|
||||
private var _ordinalLabel: UILabel = UILabel()
|
||||
private var _indicator: SwitchIndicatorView = SwitchIndicatorView()
|
||||
|
||||
override init(frame: CGRect)
|
||||
{
|
||||
super.init(frame: frame)
|
||||
|
||||
let annotationsColor = UIColor.darkGrayColor()
|
||||
self.backgroundColor = UIColor(white: 0.2, alpha: 1.0)
|
||||
|
||||
_nameLabel.font = UIFont(name: "Orbitron-Medium", size: 16.0)
|
||||
_nameLabel.numberOfLines = 3
|
||||
_nameLabel.textColor = UIColor.whiteColor()
|
||||
_nameLabel.text = "beatmania IIDX".uppercaseString
|
||||
self.addSubview(_nameLabel)
|
||||
|
||||
_ordinalLabel.font = UIFont(name: "Orbitron-Medium", size: 21.0)
|
||||
_ordinalLabel.textColor = annotationsColor
|
||||
_ordinalLabel.text = "00"
|
||||
self.addSubview(_ordinalLabel)
|
||||
|
||||
_indicator.foregroundColor = annotationsColor
|
||||
self.addSubview(_indicator)
|
||||
}
|
||||
|
||||
required init?(coder aDecoder: NSCoder)
|
||||
{
|
||||
fatalError("unsupported")
|
||||
}
|
||||
|
||||
// MARK: Overrides
|
||||
|
||||
override func layoutSubviews()
|
||||
{
|
||||
super.layoutSubviews()
|
||||
|
||||
let bounds = self.bounds
|
||||
let padding: CGFloat = 10.0
|
||||
|
||||
_indicator.frame = CGRect(
|
||||
x: padding,
|
||||
y: padding,
|
||||
width: 20.0,
|
||||
height: 20.0
|
||||
)
|
||||
|
||||
let nameLabelSize = _nameLabel.sizeThatFits(CGSize(width: bounds.size.width - padding * 2.0, height: bounds.size.height - padding))
|
||||
_nameLabel.frame = CGRect(
|
||||
x: padding,
|
||||
y: bounds.size.height - nameLabelSize.height - padding,
|
||||
width: nameLabelSize.width,
|
||||
height: nameLabelSize.height
|
||||
)
|
||||
|
||||
let ordinalLabelSize = _ordinalLabel.sizeThatFits(bounds.size)
|
||||
_ordinalLabel.frame = CGRect(
|
||||
x: bounds.size.width - ordinalLabelSize.width - padding,
|
||||
y: padding,
|
||||
width: ordinalLabelSize.width,
|
||||
height: ordinalLabelSize.height
|
||||
)
|
||||
}
|
||||
|
||||
// MARK: API
|
||||
|
||||
var device: WemoDevice? {
|
||||
get
|
||||
{
|
||||
return _device
|
||||
}
|
||||
|
||||
set(device)
|
||||
{
|
||||
_device = device
|
||||
_nameLabel.text = _device?.name
|
||||
}
|
||||
}
|
||||
|
||||
var ordinal: Int {
|
||||
get
|
||||
{
|
||||
return _ordinal
|
||||
}
|
||||
|
||||
set(ordinal)
|
||||
{
|
||||
_ordinal = ordinal
|
||||
_ordinalLabel.text = String(format: "%.2d", _ordinal)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user