Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
EjayJanis authored and EjayJanis committed Nov 29, 2014
1 parent 2f0d8b9 commit 2c69c6f
Show file tree
Hide file tree
Showing 18 changed files with 972 additions and 0 deletions.
472 changes: 472 additions & 0 deletions Camera.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

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

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

15 changes: 15 additions & 0 deletions Camera/BIDAppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// BIDAppDelegate.h
// Camera
//
// Created by Ejay on 11/29/14.
// Copyright (c) 2014 Apress. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface BIDAppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end
46 changes: 46 additions & 0 deletions Camera/BIDAppDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// BIDAppDelegate.m
// Camera
//
// Created by Ejay on 11/29/14.
// Copyright (c) 2014 Apress. All rights reserved.
//

#import "BIDAppDelegate.h"

@implementation BIDAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
// 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.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
// 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.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
// 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.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
// 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.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
13 changes: 13 additions & 0 deletions Camera/BIDViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// BIDViewController.h
// Camera
//
// Created by Ejay on 11/29/14.
// Copyright (c) 2014 Apress. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface BIDViewController : UIViewController

@end
159 changes: 159 additions & 0 deletions Camera/BIDViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
//
// BIDViewController.m
// Camera
//
// Created by Ejay on 11/29/14.
// Copyright (c) 2014 Apress. All rights reserved.
//

#import "BIDViewController.h"
#import <MediaPlayer/MediaPlayer.h>

#import <MobileCoreServices/UTCoreTypes.h>

@interface BIDViewController ()
<UIImagePickerControllerDelegate, UINavigationControllerDelegate>


@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UIButton *takePictureButton;


@property(strong, nonatomic) MPMoviePlayerController *moviePlayerController;
@property (strong,nonatomic) UIImageView *image;
@property (strong,nonatomic) NSURL *movieURL;
@property (copy, nonatomic) NSString *lastChosenMediaType;

@end

@implementation BIDViewController



- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
if(![UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera])
{
self.takePictureButton.hidden =YES;
}
}


-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self updateDisplay];
}
- (IBAction)shootPictureOrVideo:(id)sender
{
[self pickMediaFromSource:UIImagePickerControllerSourceTypeCamera];
}

- (IBAction)selectExistingPictureOrVideo:(id)sender
{
[self pickMediaFromSource:UIImagePickerControllerSourceTypePhotoLibrary];
}

- (void)updateDisplay
{
if ([self.lastChosenMediaType isEqual:(NSString *)kUTTypeImage]) {
self.imageView.image = self.image;
self.imageView.hidden = NO;
self.moviePlayerController.view.hidden = YES;
} else if ([self.lastChosenMediaType isEqual:(NSString *)kUTTypeMovie]) {
[self.moviePlayerController.view removeFromSuperview];
self.moviePlayerController = [[MPMoviePlayerController alloc]
initWithContentURL:self.movieURL];
[self.moviePlayerController play];
UIView *movieView = self.moviePlayerController.view;
movieView.frame = self.imageView.frame;
movieView.clipsToBounds = YES;
[self.view addSubview:movieView];
self.imageView.hidden = YES;
}
}

- (void)pickMediaFromSource:(UIImagePickerControllerSourceType)sourceType
{
NSArray *mediaTypes = [UIImagePickerController
availableMediaTypesForSourceType:sourceType];
if ([UIImagePickerController
isSourceTypeAvailable:sourceType] && [mediaTypes count] > 0) {
NSArray *mediaTypes = [UIImagePickerController
availableMediaTypesForSourceType:sourceType];
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.mediaTypes = mediaTypes;
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = sourceType;
[self presentViewController:picker animated:YES completion:NULL];
} else {
UIAlertView *alert =
[[UIAlertView alloc] initWithTitle:@"Error accessing media"
message:@"Unsupported media source."
delegate:nil
cancelButtonTitle:@"Drat!"
otherButtonTitles:nil];
[alert show];
}
}

- (UIImageView *)shrinkImage:(UIImage *)original toSize:(CGSize)size
{
UIGraphicsBeginImageContextWithOptions(size, YES, 0);

CGFloat originalAspect = original.size.width / original.size.height;
CGFloat targetAspect = size.width / size.height;
CGRect targetRect;

if (originalAspect > targetAspect) {
// original is wider than target
targetRect.size.width = size.width;
targetRect.size.height = size.height * targetAspect / originalAspect;
targetRect.origin.x = 0;
targetRect.origin.y = (size.height - targetRect.size.height) * 0.5;
} else if (originalAspect < targetAspect) {
// original is narrower than target
targetRect.size.width = size.width * originalAspect / targetAspect;
targetRect.size.height = size.height;
targetRect.origin.x = (size.width - targetRect.size.width) * 0.5;
targetRect.origin.y = 0;
} else {
// original and target have same aspect ratio
targetRect = CGRectMake(0, 0, size.width, size.height);
}

[original drawInRect:targetRect];
UIImage *final = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView* finalImageView = [[UIImageView alloc]init];
finalImageView.layer.cornerRadius = final.size.width / 2;
finalImageView.clipsToBounds = YES;
return finalImageView;
}

#pragma mark - Image Picker Controller delegate methods
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
self.lastChosenMediaType = info[UIImagePickerControllerMediaType];
if ([self.lastChosenMediaType isEqual:(NSString *)kUTTypeImage]) {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.image = [self shrinkImage:chosenImage
toSize:self.imageView.bounds.size];
} else if ([self.lastChosenMediaType isEqual:(NSString *)kUTTypeMovie]) {
self.movieURL = info[UIImagePickerControllerMediaURL];
}
[picker dismissViewControllerAnimated:YES completion:NULL];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissViewControllerAnimated:YES completion:NULL];
}

@end

63 changes: 63 additions & 0 deletions Camera/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="5056" systemVersion="13F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="vXZ-lx-hvc">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3733"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="ufC-wZ-h7g">
<objects>
<viewController id="vXZ-lx-hvc" customClass="BIDViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="jyV-Pf-zRb"/>
<viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="MKX-El-dUh">
<rect key="frame" x="56" y="377" width="202" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal" title="New Photo or Video">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="shootPictureOrVideo:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="or7-8d-jnB"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Poy-LG-ZMI">
<rect key="frame" x="99" y="415" width="117" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal" title="Pick from Library">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="selectExistingPictureOrVideo:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="T4v-mN-8KY"/>
</connections>
</button>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" image="mask" translatesAutoresizingMaskIntoConstraints="NO" id="Ij7-Mw-Bv3">
<rect key="frame" x="56" y="124" width="205" height="190"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</imageView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
<connections>
<outlet property="imageView" destination="Ij7-Mw-Bv3" id="hRy-Hx-cUf"/>
<outlet property="takePictureButton" destination="MKX-El-dUh" id="xr0-Gm-kNK"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
</objects>
</scene>
</scenes>
<resources>
<image name="mask" width="193" height="193"/>
</resources>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination" type="retina4"/>
</simulatedMetricsContainer>
</document>
40 changes: 40 additions & 0 deletions Camera/Camera-Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>com.apress.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
16 changes: 16 additions & 0 deletions Camera/Camera-Prefix.pch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// Prefix header
//
// The contents of this file are implicitly included at the beginning of every source file.
//

#import <Availability.h>

#ifndef __IPHONE_5_0
#warning "This project uses features only available in iOS SDK 5.0 and later."
#endif

#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
23 changes: 23 additions & 0 deletions Camera/Images.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading

0 comments on commit 2c69c6f

Please sign in to comment.