400 likes | 502 Views
Wednesday 2-4, DH 1046. COMP 446 / ELEC 446 Mobile Device Applications. Scott Cutler Professor in the Practice of Computer Technology Department of Computer Science Department of Electrical and Computer Engineering cutler@rice.edu 10/05/11. Today’s Agenda. Events of the week
E N D
Wednesday 2-4, DH 1046 COMP 446 / ELEC 446 Mobile Device Applications Scott Cutler Professor in the Practice of Computer Technology Department of Computer Science Department of Electrical and Computer Engineering cutler@rice.edu 10/05/11
Today’s Agenda • Events of the week • Final Project Schedule • Web Services(abbreviated) • Memory Management Summary Sheet • Controllers of Controllers, Gesture Recognizers • Review of current assignment • Next Week COMP 446 / ELEC 446 - Week 7
Events of the Week • Rhapsody to acquire Napster (scoop) • Microsoft falsely labels Chrome as malware • Chrome could unseat Firefox as No. 2 browser • Windows Phone Mango Sweetens Microsoft's Mobile Chances • Amazon Silk Browser Sets Tech's Teeth on Edge • Apple's iPhone 4S is swell, but pricing is the real killer app • iPhone 4S, Not iPhone 5, Debuts at Apple Event • I Am Number 4S? — No Sparkly iPhone 5 Disappoints Apple Fans (and Wall Street) • iOS 5 available October 12th COMP 446 / ELEC 446 - Week 7
COMP 446 Syllabus • 8/24/11 Introduction / What makes mobile apps special Videos: Lecture 1. Introduction to Cocoa Touch, Objective-C, Tools, and MVC (September 21, 2010) Lecture 2. Building a Simple Calculator (September 23, 2010) Assignment: #1 and #1 Walkthrough - Calculator Due: Preferably watch videos this week, definitely by 8/30. Assignment due 9/1/11. • 8/31/11 Discussion of first applications, Development Environment Videos: Lecture 3. Objective-C and Foundation Frameworks (September 28, 2010) Lecture 4. Foundation and Memory Management (September 30, 2010) Assignment: #2 Function Calculator (Due 9/15/11) • 9/7/11 Intro to Cocoa Touch, Objective-C, Using Objective-C, Foundation framework Videos: Assignment: • 9/14/11Memory Management Videos: Lecture 5. Protocols and Views (October 5, 2010) Lecture 6. Application & View Controller Lifecycle, Navigation Controller (October 7, 2010) Assignment: #3 Graphing Calculator (Due 9/22/11) • 9/21/11 iPhone (pseudo) Web Apps / ASP.Net / Browser Capabilities Videos: Lecture 7. More Controllers of Controllers, iPad, Universal Applications (October 12, 2010) Lecture 8. Gesture Recognizers (October 14, 2010) Assignment: #4 Universal Calculator (Due 9/29/11) COMP 446 / ELEC 446 - Week 7
COMP 446 Syllabus • 9/28/11 Creating and Consuming Web Services Videos: Lecture 9. Image View, Web View, and Scroll View (October 19, 2010) Lecture 10. Table View (October 21, 2010)Assignment: #5 Pictures Places (Due 10/13/11) • 10/5/11 SQL 101 Videos: Lecture 11. Persistence (October 26, 2010) Lecture 12. Core Data and Table Views (October 28, 2010) Assignment: #6 Core Data Places (Due 10/20/11, but watch lectures prior to 10/12/11 class) • 10/12/11 Final Project discussion and Pairing Videos: Debugging Tools (October 22, 2010)Kleiner Perkins iFund (October 15, 2010) Assignment: Final Project Proposal (Due 10/18/11 along with Core Data Places due 10/20/11) • 10/19/11 iOS 5 Videos: Lecture 13. Blocks and Multithreading (November 2, 2010) Lecture 14. Core Location and Map Kit (November 9, 2010) Assignment: Final Project, Stage 1 (Due 10/27/11) • 10/26/11 Android Videos: Lecture 15. Editable Text, Modal View Controllers, and View Animation (Nov 11, 2010) Lecture 16. Core Motion, Segmented Control, and Alerts (November 16, 2010) Assignment: Advanced Feature App (Due 11/03/11) COMP 446 / ELEC 446 - Week 7
COMP 446 Syllabus • 11/2/11 Windows Phone 7, Final Project Prep Videos: Lecture 17. Media (November 18, 2010) Lecture 18. Accessibility on iOS: Make an App for Everyone (November 30, 2010) Assignment: Final Project, Stage 2 (Due 11/10/2011) • 11/09/11 Final Project Prep / iPhone v. Android v. Windows Phone 7 group discussion Videos: Lessons from Bezos, Pincus, Young: CEO 2.0 (November 12, 2010) (Optional) LinkedIn: Shipping with CoreData (November 5, 2010) (Optional) Assignment: Final Project, Stage 3 (Due 11/17/2011) • 11/16/11 Final Project Prep Videos: Building Flipboard (November 19, 2010) (Optional) Assignment: Final Project Presentation (Due 11/30/2011) • 11/23/11 Thanksgiving – Continue Final Projects on your own • 11/30/11 Demonstrate Final Projects to class • 12/4/11 Class Offsite – Sunday (tentative) • Finals Submission of final code due by official finals date COMP 446 / ELEC 446 - Week 7
Duncan Hall Kiosk Final Project • Possible Final project for one or two teams of one or two people. • Replace Duncan Hall Kiosk with iPad version • Person Lookup • Location map • Event Database • 911 function (template) • Billboard mode • Management Console • Locked Application • Possible second semester continuation project COMP 446 / ELEC 446 - Week 7
Assignment #4 Comments COMP 446 / ELEC 446 - Week 7
Assignment #4 Comments • High number of memory management issues continue to plague homework • -(void) releaseOutlets {} //deprecated • In – (void) viewDidUnloadinclude: • self.outlet=nil;//for all IBOutlets • [super viewDidUnload]; //should be last thing in method • In – (void) deallocinclude • [iVar release]; //for all iVar Objects • [outlet release]; //for all IBOutlets • [super dealloc]; //should be last thing in method COMP 446 / ELEC 446 - Week 7
Handling IBOutlets • Declare in class header between { } UILabel *myLabel; • @property declaration in header after { } @property (retain) IBOutletUILabel *myLabel; • @synthesize iVar in implementation file @synthesize myLabel; • Create private release method to set values to nil -(void) releaseOutlets {self.myLabel=nil;} • Call releaseOutlets in dealloc AND viewDidUnload [self releaseOutlets]; • Better alternate to 4 & 5self.myLabel=nil; //in viewDidUnload [myLabel release]; //in dealloc COMP 446 / ELEC 446 - Week 7
Calling [super <method>] • When overriding methods it is important to call super to ensure that normal things are done • Exception is when you are changing a behavior that the super class does. Care must be taken! • When should you call super? • For methods that create (init, viewDidLoad, etc), call super first. • For methods that destroy (dealloc, viewDidUnload) call super last. COMP 446 / ELEC 446 - Week 7
Calling Class Methods • You do need to #import <class>.h • No need to instantiate a class if you are only going to call class methods. COMP 446 / ELEC 446 - Week 7
Gesture Recognizers • Most people got this correct • A few people forgot to reset gesture values at end of method. • While this does not crash, it makes gestures feel wrong. COMP 446 / ELEC 446 - Week 7
NSUserDefaults • Remember to synchronize • Where should you save NSUserDefaults? • Recommend against placing them in dealloc or viewDidUnload • Suggest at end of method which responds to a user action • Either in the method itself • Or in something changed once by that method COMP 446 / ELEC 446 - Week 7
Videos 9 & 10 summary Slides based on CS 193p fall 2010 iTunes University videos COMP 446 / ELEC 446 - Week 7
New Classes • UIImage and UIImageView • UIWebView • UIScrollView • UITableView COMP 446 / ELEC 446 - Week 7
UIImage • Easy to create • UIImage *image = [UIImageimageNamed”@foo.jpg”]; • Looks in your Resources folder for file named foo.jpg. • UIImage *image = [UIImageimageWithContentsOfFile:(NSString *)path]; • Path is a path to a file in your application sandbox • UIImage * image = [[UIImagealloc] initWithData: (NSData *)data]; • Creates and image out of a collection of data. • Data in points, not pixels • Shows up as same size on iPhone with or without retina • Does support high definition, retina images COMP 446 / ELEC 446 - Week 7
UIImageView • Subclass of UIView used to display UIImages • Create in: • Interface Builder or • UIImageView *imageView = [[UIImageViewalloc] initWithImage:(UIImage *)image]; • image is a property of UIImageView • @property (retain) UIImage *image; • Many other properties • Highlighted images (i.e. to show selection or press) • Animation (animates through an NSArray of images) • Calls to start, stop and time animations. COMP 446 / ELEC 446 - Week 7
UIWebView • A complete internet browser inside a UIView • Based on Apple started WebKit HTML rendering • Will load HTML, PDF’s, mail and other complex documents • Supports light weight (time limited) JavaScript • Can load from web URL or file URL COMP 446 / ELEC 446 - Week 7
UIScrollView • Handles images bigger than bounds of the UIScrollView • Built in gesture recognizers • Super class of UITextView and UITableView COMP 446 / ELEC 446 - Week 7
UIScrollView COMP 446 / ELEC 446 - Week 7
UIScrollView • Zooming based on affine transform of underlining UIView • scrollView.minimumZoomScale andscrollView.maximumZoomScale must be set • Required delegate method to specify view • -(UIView *)viewForZoomingInScrollView:(UIScrollView *)sender; • With one view, return sender.view • Programmatically use: • -(void)setZoomScale: animated: • -(void)zoomToRect: animated: COMP 446 / ELEC 446 - Week 7
UITableView • The canonical class used for efficiently displaying tables of data. • Creates and reuses UITableViewCells • Delegates • UITableViewDataSource for data • UITableViewDelegate for display information • Both often part of UITableViewController COMP 446 / ELEC 446 - Week 7
UITableView COMP 446 / ELEC 446 - Week 7
UITableView COMP 446 / ELEC 446 - Week 7
UITableViewDataSource • -(NSInteger)numberOfSectionsInTableView:(UITableView *)sender; • Optional method, defaulting to 1 • -(NSInteger)tableView:(UITableView *)sender numberOfRowsInSection:(NSInteger)section; • Required method • - (UITableViewCell *)tableView:(UITableView *) sender cellForRowAtIndexPath:(NSIndexPath *)indexPath; • NSIndexPath has two important properties, ip.section and ip.row. COMP 446 / ELEC 446 - Week 7
UITableViewCell • Standard methods or fully customizable. • Built in properties • (readonly) UILabel *textLabel; • (readonly) UILabel *detailTextLabel; • (readonly) UIImageView *imageView; COMP 446 / ELEC 446 - Week 7
UITableViewCell • - initWithStyle:(UITableViewCellStyle) style reuseIdentifier:(NSString *)reuseId; COMP 446 / ELEC 446 - Week 7
UITableViewCellreuseIdentifier • Creation of TableViewCells is expensive • The desire is for effortless scrolling through hundreds or thousands of cells • Only cells which are actively being displayed need to be fully formed • Cells which go off the edge or not destroyed, but saved for reuse; keyed by reuseIdentifier • DataSource methods for changing content of established cells is very efficient COMP 446 / ELEC 446 - Week 7
UITableViewCellAccessoryType • The disclosure indicator lets the user know that more information can be seen if the cell is clicked. • The Checkmark signifies selection and is managed by your program • The DetailDisclodureButton is a secondary launcher that brings up different details than just selecting the row. COMP 446 / ELEC 446 - Week 7
UITableViewDelegate • Second protocol, often implemented in the same class as the UITableViewDataSource • Most used method: • - (void) tableView:(UITableView *) sender didSelectRowAtIndexPath:(NSIndexPath *)indexPath; • Typically pushes another view controller related to cell selected. • Also has methods for: • Controlling height • Reacting to lifecycle events for the cell • Custom header views and cell selection actions COMP 446 / ELEC 446 - Week 7
UITableViewController • A UIViewController which includes the datasource and delegate protocols of UITableView • Automatically sets up the default load view unless you have a custom .xib file • Helps with editing and other UI niceties COMP 446 / ELEC 446 - Week 7
Videos 11 & 12 Preview Slides based on CS 193p fall 2010 iTunes University videos COMP 446 / ELEC 446 - Week 7
Video 11 • Review old items covered to date. • Discussion on archiving Objects • Explanation about file system and related methods • Brief slide on embedded SQLite • Introduction to Core Data • Interface between database and objects COMP 446 / ELEC 446 - Week 7
Video 12 • Core Data class code • Querying with core data • Sorting with core data • Core Data versions of UITableViewController COMP 446 / ELEC 446 - Week 7
Core Data Uses Big Words • NSManagedObject • Just an object representing something from the database • NSManagedObjectContext • Similar to CGContextRef • Simple call to get via method in App Delegate automatically created if you select Core Data (difficult to add Core Data if not set at beginning) • NSFetchRequest • For getting items from the database • NSSortDescriptor • For describing one layer of sorts • NSArray of NSSortDescriptors given to NSFetchRequest • NSPredicate or NSCompoundPredicate • Condition clause to determine which records match request • NSCompoundPredicate used when there are multiple conditions COMP 446 / ELEC 446 - Week 7
Demo of Core Data in Next Class • Please watch videos 11 and 12 before class • Demo will not make sense without • Desire to show simple example using Xcode 4.1. Fundamentals the same as on video but there are some differences. COMP 446 / ELEC 446 - Week 7
Assignment #5 • No more calculator • Problem involves two major technologies • Getting data from the web (Flickr) • Using a UITableViewController to quickly scroll through items. • Flickr top places • Photos from the top places • Will require you to obtain a free FlickrAPI key. • WATCH THE DEMO IN VIDEO 10 COMP 446 / ELEC 446 - Week 7
Assignment #6 Preview • Staggered overlapping due date with Assignment #5 • Three major parts • Core Data version of Assignment #5 • Addition of Favorite Places • Caching of image data to sandbox • Item 1 required, Items 2 and 3 required if you want possibility of A+ in class • While not required, if you want to create great apps, you should also do Assignment #7 – multi thread • Items 2 and 3 can be submitted at any time before last class • WATCH THE DEMO IN VIDEO 12 COMP 446 / ELEC 446 - Week 7
Week 8 • Watch CS193p lectures #11 and #12 before next class • Class demo will not make sense without it. • Start CS193p Assignment #6 (partial) • Assignment #6 due 10/20/2011. COMP 446 / ELEC 446 - Week 7