Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisChares committed Jun 3, 2014
0 parents commit bc076a8
Show file tree
Hide file tree
Showing 17 changed files with 1,523 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Xcode
.DS_Store
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
!default.xcworkspace
xcuserdata
profile
*.moved-aside
DerivedData
.idea/

*.ipa
472 changes: 472 additions & 0 deletions alarm.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions alarm.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions alarm/Alarm.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// Alarm.swift
// alarm
//
// Created by Chris Chares on 6/2/14.
// Copyright (c) 2014 eunoia. All rights reserved.
//

import UIKit
import CoreLocation
import MediaPlayer

class Alarm: NSObject {

var region:CLCircularRegion
var media:MPMediaItem

init( _region:CLCircularRegion, _media:MPMediaItem ) {
region = _region
media = _media

}

}
126 changes: 126 additions & 0 deletions alarm/AlarmViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
//
// AlarmViewController.swift
// alarm
//
// Created by Chris Chares on 6/2/14.
// Copyright (c) 2014 eunoia. All rights reserved.
//

import UIKit
import MediaPlayer
import CoreLocation

class AlarmViewController: UITableViewController, MPMediaPickerControllerDelegate, MapViewControllerDelegate {

/*
Cells & their views
*/
@IBOutlet var mapCell : UITableViewCell

@IBOutlet var mediaCell : UITableViewCell
@IBOutlet var mediaImageView : UIImageView

@IBOutlet var alarmOnEntranceCell : UITableViewCell
@IBOutlet var alarmOnExitCell : UITableViewCell


/*
Properties
*/

var _mediaItem:MPMediaItem?
var _region:CLCircularRegion?


init(style: UITableViewStyle) {
super.init(style: style)
// Custom initialization
}
init(coder aDecoder: NSCoder!) {
super.init(coder: aDecoder)
}

override func viewDidLoad() {
super.viewDidLoad()

}


@IBAction func cancel(sender : AnyObject) {

navigationController.presentingViewController .dismissViewControllerAnimated(true, completion: {});

}

@IBAction func save(sender : AnyObject) {


navigationController.presentingViewController .dismissViewControllerAnimated(true, completion: {});
}

/*
#pragma mark - UITableViewDelegate
*/

override func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {

let cell = tableView.cellForRowAtIndexPath(indexPath)
if ( cell == mediaCell ) {

let mediaPicker = MPMediaPickerController(mediaTypes: .Music)
mediaPicker.delegate = self
mediaPicker.prompt = "Select any song!"
mediaPicker.allowsPickingMultipleItems = false
presentViewController(mediaPicker, animated: true, completion: {})

} else if ( cell == alarmOnEntranceCell ) {

} else if ( cell == alarmOnExitCell ) {

//alarmOnExitCell.accessoryType = .None
}

}

// #pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue?, sender: AnyObject?) {

if ( segue!.identifier == "map" ) {
var mapVC = segue!.destinationViewController as MapViewController;
mapVC.delegate = self;
}
}

/*
MapViewControllerDelegate
*/
func returnedRegion(region: CLCircularRegion) {

_region = region;
self.navigationController.popViewControllerAnimated(true);
}


/*
MPMediaPickerControllerDelegate
*/
func mediaPicker(mediaPicker: MPMediaPickerController, didPickMediaItems mediaItems:MPMediaItemCollection) -> Void
{
var aMediaItem = mediaItems.items[0] as MPMediaItem
if ( aMediaItem.artwork ) {
mediaImageView.image = aMediaItem.artwork.imageWithSize(mediaCell.contentView.bounds.size);
mediaImageView.hidden = false;
}

_mediaItem = aMediaItem;
//fillData(aMediaItem);
self.dismissViewControllerAnimated(true, completion: {});
}

func mediaPickerDidCancel(mediaPicker: MPMediaPickerController) {
self.dismissViewControllerAnimated(true, completion: {});
}

}
92 changes: 92 additions & 0 deletions alarm/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
//
// AppDelegate.swift
// alarm
//
// Created by Chris Chares on 6/2/14.
// Copyright (c) 2014 eunoia. All rights reserved.
//

import UIKit
import CoreLocation

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate {

var window: UIWindow?
let defaults: NSUserDefaults = NSUserDefaults.standardUserDefaults()
var alarms: Alarm[] = []
let locationManager: CLLocationManager = CLLocationManager()

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {


locationManager.delegate = self;


if let array = defaults.objectForKey("alarms") as? Alarm[] {
for alarm:Alarm in array {
locationManager.startMonitoringForRegion(alarm.region)
alarms.append(alarm)
}
}

return true
}

func applicationWillResignActive(application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
// defaults.setObject(alarms, forKey: "alarms")
// defaults.synchronize()
}


//New Stuff
func addAlarm(alarm:Alarm!) {
alarms.append(alarm)
locationManager.startMonitoringForRegion(alarm.region)
}







//CLLocationManagerDelegate

func locationManager(manager:CLLocationManager, didEnterRegion region:CLRegion) {

println("Entered Region " + region.identifier );

}

func locationManager(manager:CLLocationManager, didExitRegion region:CLRegion) {

println("Exited Region " + region.identifier );

}

func locationManager(manager:CLLocationManager, didUpdateLocations locations:AnyObject[]) {

}

}

Loading

0 comments on commit bc076a8

Please sign in to comment.