1 / 33

Wednesday 2-4, DH 1046

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 9/21/11. Today’s Agenda. Events of the week

lynne
Télécharger la présentation

Wednesday 2-4, DH 1046

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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 9/21/11

  2. Today’s Agenda • Events of the week • Final Project Schedule • Mobile Web Apps (abbreviated) • Memory Management Summary Sheet • Drawing / Views / View Controllers • Review of current assignment • Next Week COMP 446 / ELEC 446 - Week 5

  3. Events of the Week • Microsoft joins the anti-Flash crowd with IE10 • Netflix CEO apologizes for how rate hike was handled • Google turns again to IBM in patent-nabbing spree • RIM woes continue: Q2 earnings hit amid weak demand, product shift • PayPal offers sneak peek of upcoming virtual wallet offering • Google opens Wallet • Amazon Courting Magazine, Book Publishers for Kindle Tablet • Samsung returns fire on Apple patent suits in Australia, Germany COMP 446 / ELEC 446 - Week 5

  4. 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 5

  5. COMP 446 Syllabus • 9/28/11 SQL 101 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 Creating and Consuming Web Services 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 5

  6. 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 5

  7. Final Project Time Line • Submit preliminary concept to website over next two weeks (by 10/5) • Sooner if possible • Determine if you want a solo project or a two person project • OK to pick your partners – you will not be assigned partners • Website will help • Roles and responsibilities must be clear • Encourage iPad + iPhone projects (I think they are cool) • Each person must be responsible for two advanced features • Can target iOS, Android or WP7 device • Time Line: • Short description of project by 10/5 • Feedback and iteration over next two weeks • Proposal submitted by 10/18/11 • Full Spec 10/27/11 • Various milestones including presentation to class on 11/30/11 • Final code for project incorporating comments from presentation due on the official finals date of the course. COMP 446 / ELEC 446 - Week 5

  8. Mobile Web Apps COMP 446 / ELEC 446 - Week 5

  9. Mobile Web Apps (abbreviated) • Quick and dirty way to deliver content to a mobile device • Examples: • pda.continental.com • m.gmail.com • Characteristics • Low bandwidth requirements • Native small screen layout • Minimized keyboard entry COMP 446 / ELEC 446 - Week 5

  10. Detection of Mobile Device • Multiple methods based on server religion • Some examples: • “Request.browser” • WURFL – Wireless Universal Resource File • 51Degrees.mobi COMP 446 / ELEC 446 - Week 5

  11. iUI – Pseudo iPhone Apps • Project started prior to App Store to allow websites to look like a native iPhone app • www.iui-js.org • Based on HTML, javascript, CSS • Apps look and act like TableView applications • Runs on iPhone, Android phones, iPad, most Android tablets, WebOS, RIM OS6 COMP 446 / ELEC 446 - Week 5

  12. iUI Examples • My first iPhone “app” for the 2009 Cliburn Piano Competition: • www.WoodlandsSalonSeries.org/cliburn • Gallery of iUI powered applications: • http://www.iui-js.org/gallery COMP 446 / ELEC 446 - Week 5

  13. Memory Management Cheat Sheet COMP 446 / ELEC 446 - Week 5

  14. Memory Management of iVars • Declare in class header between { } NSArray *myArray; • @property declaration in header after { } @property (nonatomic, retain) NSArray *myArray; • @synthesize iVar in implementation file @synthesize myArray; • Release in dealloc method; [myArray release]; COMP 446 / ELEC 446 - Week 5

  15. @property Memory Attribute • Use (assign) for delegates and other objects not needing memory management • Use (copy) for NSStrings or other object which might get changed by other methods behind your back • Use (retain) for most other objects • Use nothing (equivalent to assign) for non-object iVars like double or for derived properties (properties not based on iVars) assign retain copy @property (assign) id <FooDelegate> delegate; @property (retain) NSArray *myArray; @property (copy) NSString *name; @synthesize delegate; // would create: @ synthesize myArray; // would create: @synthesize name; // would create: • (void)setDelegate: (id) newDelegate • { • delegate= newDelegate; • } //no memory management • (void)setMyArray: (NSArray *)value • { • if (value != myArray) { • [myArray release]; • myArray= [value retain]; } • } //Old released, new retained • (void)setName: (NSString *)value • { • if (value != name) { • [name release]; • name = [value copy]; } • } // Creates a copy which you own COMP 446 / ELEC 446 - Week 5

  16. 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]; COMP 446 / ELEC 446 - Week 5

  17. 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]; • Alternate to 4 & 5self.myLabel=nil; //in viewDidUnload [myLabel release]; //in dealloc COMP 446 / ELEC 446 - Week 5

  18. Objects Created in Methods • For methods that return objects: • iVar objects created in setters or getters should be retained taking care to release any previous values • Methods starting with new, copy or init should return retained objects • Other methods should return autoreleased objects • Objects temporarily created in methods and not returned: • should be released, not autoreleased, before end of method • use autorelease only for temporary objects needed after end of method COMP 446 / ELEC 446 - Week 5

  19. Good, Better Best Good: - (NSDictionary *)testVariableValues {NSMutableDictionary*returnValue = [[NSMutableDictionaryalloc] init]; [returnValuesetObject:[NSNumber numberWithFloat:3.5] forKey:@”x”]; [returnValuesetObject:[NSNumber numberWithFloat:23.8] forKey:@”y”]; return [returnValueautorelease];} Better: - (NSDictionary *)testVariableValues{NSMutableDictionary*returnValue = [NSMutableDictionary dictionary]; [returnValuesetObject:[NSNumber numberWithFloat:3.5] forKey:@”x”]; [returnValuesetObject:[NSNumber numberWithFloat:23.8] forKey:@”y”]; return returnValue;} Best: - (NSDictionary *)testVariableValues{ return [NSDictionarydictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:3.5], @”x”, [NSNumber numberWithFloat:23.8], @”y”, nil];} // Source: CS193P fall 2010 Video #7 COMP 446 / ELEC 446 - Week 5

  20. Videos 5 & 6 summary Slides based on CS 193p fall 2010 iTunes University videos COMP 446 / ELEC 446 - Week 5

  21. Protocols • Definition of methods used by a helper / delegate class. • Good way to add customization to standard object • Similar to @interface, but no implementation • Included in the header file • Can have @optional and @required methods • A class declares that it supports “Foo” protocol by placing <Foo> next to an object: • @interface MyClass : NSObject<Foo> • Id <Foo> obj = [[MYClassalloc] init]; • @property (assign) id <Foo> delegate; COMP 446 / ELEC 446 - Week 5

  22. Application Delegate • Automatically created by Xcode and provides the initial main window instance variable. • Implements the UIApplicationDelegate protocol • Most important method is:application:didFinishLaunchingWithOptions: • Perfect spot for initialization code. • Place to add our own view controllers COMP 446 / ELEC 446 - Week 5

  23. UIView • Top level drawing class with many defined subclasses • Top level rectangular area for drawing. • Often contains multiple subviews and possibly one superview. • Views are ordered with definable transparency. • Memory Management: A superview retains its subviews. COMP 446 / ELEC 446 - Week 5

  24. Drawing Coordinates • C based floats and structs • CGFloat data type • Two CGFloats make up a CGPoint or CGSize. • A CGPoint and a CGSize make a CGRect • CGRectaRect = CGRectMake (5.1, 7, 20, 30); • aRect.size.height =75; COMP 446 / ELEC 446 - Week 5

  25. Drawing Coordinates • Origin (0, 0) in upper left. • Units in points and not Pixels • @property CGFloatcontentScaleFactor;//pixel • Three important @properties: • @property CGRect bounds; • Your view’s “bounding” rectangle • @property CGPoint center; • Your view’s center in superview’s coordinates • @property CGRect frame; • A rectangular area in superview’s coordinates that encompasses your view. COMP 446 / ELEC 446 - Week 5

  26. Custom Views • Views often created in .xib file • Can be created in code with custom class • UIView subclass • Override drawRect: method • You NEVER call drawRect • Call UIView’s –(void)setNeedsDisplay; method • The API is C, not object-oriented. COMP 446 / ELEC 446 - Week 5

  27. Drawing Process • First get a drawing context • Context is fancy word that collects the various drawing parameters. • CGContextRef context = UIGraphicsGetCurrentContext(); • No memory management (no *) • Create paths out of lines, arcs, etc. • Set colors, fonts, textures, etc. • Stroke or fill created paths to draw • Push and Pop context to make temporary changes COMP 446 / ELEC 446 - Week 5

  28. Drawing Text and Images • Text normally drawn through UILabel subclass • NSString has methods to draw text using a UIFont object • -(void) drawAtPoint: withFont:; //NSString method • Images normally drawn through UIImageView subclass • UIImage can be used to create an image from a file or many other things • Can draw one through CGContext • Can extract NSData class bits from UIImages COMP 446 / ELEC 446 - Week 5

  29. UIViewControllers • Many important subclasses • @property (retain) UIView *view; • Is instantiated in one of two ways (not both): • - (id) initWinthNibName: bundle:; • [[UIViewControlleralloc] init];//xib and bundle are nil • After initialized: viewDidLoad is called • Before appearance: viewWillAppear: animated:; called. • Other lifecycle methods: • viewWillDisappear: animated: • “did” versions of above • Methods to handle rotation COMP 446 / ELEC 446 - Week 5

  30. Controller of Controllers • UINavigationController • Extremely common stack of cards views • UITabBarController • Managing separate sections of an app • UISplitViewController • iPad specific Master/Slave view controller • UITableViewController • Efficient way to display a lot of data in a table form. • Most often subclassed COMP 446 / ELEC 446 - Week 5

  31. UINavigationController • Deep Dive view controller • Managed push and pop of views showing more detail • Top level object or as a section of a UITabBarController • Instantiation: • Create with alloc / init • Add controller’s view property to view hierarchy • UIViewControllers under a UINavigationController have a navigationController property used to push new views • Remember that ViewControllers retain their views. COMP 446 / ELEC 446 - Week 5

  32. Protocols and Assignment #3 • The Calculator is an MVC with the CalculatorBrain as the Model • The Graphing MVC is supposed to be generic and use a protocol for its data (valueAtPointX) • Where should the protocol be defined? • Where should the protocol be implemented? COMP 446 / ELEC 446 - Week 5

  33. Week 6 • Watch CS193p lectures #7 and #8 • Preferably before Saturday. Definitely before next class. • Complete CS193p Assignment #4 • Try and complete before next class. Due day after next class. • Submit assignments, review lectures at www.comp446.com • Let me know your thoughts on final project • Preferably fill out final project section of assignment website COMP 446 / ELEC 446 - Week 5

More Related