diff options
| author | Teddy Wing | 2012-09-29 16:15:01 -0400 |
|---|---|---|
| committer | Teddy Wing | 2012-09-29 16:15:01 -0400 |
| commit | 033f9053ada0a7f2a9ef7e6652746cd3cbb8f300 (patch) | |
| tree | ee0a8c2127d189098e18e0078418359d40e41759 /Classes | |
| parent | d02256dc49356e6dc1769cc0fb4737a7f013cbed (diff) | |
| download | babblr-iOS-033f9053ada0a7f2a9ef7e6652746cd3cbb8f300.tar.bz2 | |
Integrated multi-line SMS-style text box for chat pane. Added a tableView for chat messages.
Diffstat (limited to 'Classes')
| -rw-r--r-- | Classes/ChatViewController.h | 23 | ||||
| -rw-r--r-- | Classes/ChatViewController.m | 210 | ||||
| -rw-r--r-- | Classes/ChatViewController.xib | 150 | ||||
| -rw-r--r-- | Classes/RootViewController.h | 2 | ||||
| -rw-r--r-- | Classes/RootViewController.m | 14 |
5 files changed, 397 insertions, 2 deletions
diff --git a/Classes/ChatViewController.h b/Classes/ChatViewController.h new file mode 100644 index 0000000..ee52715 --- /dev/null +++ b/Classes/ChatViewController.h @@ -0,0 +1,23 @@ +// +// ChatViewController.h +// NearMe +// +// Created by TW on 9/29/12. +// Copyright 2012 __MyCompanyName__. All rights reserved. +// + +#import <UIKit/UIKit.h> +#import "HPGrowingTextView.h" + + +@interface ChatViewController : UIViewController <HPGrowingTextViewDelegate, UITableViewDelegate, UITableViewDataSource> { + UITableView *chatTableView; + UIView *containerView; + HPGrowingTextView *textView; +} + +@property (nonatomic, retain) UITableView *chatTableView; + +-(void)resignTextView; + +@end diff --git a/Classes/ChatViewController.m b/Classes/ChatViewController.m new file mode 100644 index 0000000..aee79c8 --- /dev/null +++ b/Classes/ChatViewController.m @@ -0,0 +1,210 @@ +// +// ChatViewController.m +// NearMe +// +// Created by TW on 9/29/12. +// Copyright 2012 __MyCompanyName__. All rights reserved. +// + +#import "ChatViewController.h" + + +@implementation ChatViewController + +@synthesize chatTableView = _chatTableView; + +-(id)init +{ + self = [super init]; + if(self){ + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(keyboardWillShow:) + name:UIKeyboardWillShowNotification + object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(keyboardWillHide:) + name:UIKeyboardWillHideNotification + object:nil]; + } + + return self; +} + + + +// Implement loadView to create a view hierarchy programmatically, without using a nib. +- (void)loadView { + self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]; + self.view.backgroundColor = [UIColor colorWithRed:219.0f/255.0f green:226.0f/255.0f blue:237.0f/255.0f alpha:1]; + + chatTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain]; + [self.view addSubview:chatTableView]; + + containerView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 40, 320, 40)]; + + textView = [[HPGrowingTextView alloc] initWithFrame:CGRectMake(6, 3, 240, 40)]; + textView.contentInset = UIEdgeInsetsMake(0, 5, 0, 5); + + textView.minNumberOfLines = 1; + textView.maxNumberOfLines = 6; + textView.returnKeyType = UIReturnKeyGo; //just as an example + textView.font = [UIFont systemFontOfSize:15.0f]; + textView.delegate = self; + textView.internalTextView.scrollIndicatorInsets = UIEdgeInsetsMake(5, 0, 5, 0); + textView.backgroundColor = [UIColor whiteColor]; + + // textView.text = @"test\n\ntest"; + // textView.animateHeightChange = NO; //turns off animation + + [self.view addSubview:containerView]; + + UIImage *rawEntryBackground = [UIImage imageNamed:@"MessageEntryInputField.png"]; + UIImage *entryBackground = [rawEntryBackground stretchableImageWithLeftCapWidth:13 topCapHeight:22]; + UIImageView *entryImageView = [[[UIImageView alloc] initWithImage:entryBackground] autorelease]; + entryImageView.frame = CGRectMake(5, 0, 248, 40); + entryImageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; + + UIImage *rawBackground = [UIImage imageNamed:@"MessageEntryBackground.png"]; + UIImage *background = [rawBackground stretchableImageWithLeftCapWidth:13 topCapHeight:22]; + UIImageView *imageView = [[[UIImageView alloc] initWithImage:background] autorelease]; + imageView.frame = CGRectMake(0, 0, containerView.frame.size.width, containerView.frame.size.height); + imageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; + + textView.autoresizingMask = UIViewAutoresizingFlexibleWidth; + + // view hierachy + [containerView addSubview:imageView]; + [containerView addSubview:textView]; + [containerView addSubview:entryImageView]; + + UIImage *sendBtnBackground = [[UIImage imageNamed:@"MessageEntrySendButton.png"] stretchableImageWithLeftCapWidth:13 topCapHeight:0]; + UIImage *selectedSendBtnBackground = [[UIImage imageNamed:@"MessageEntrySendButton.png"] stretchableImageWithLeftCapWidth:13 topCapHeight:0]; + + UIButton *doneBtn = [UIButton buttonWithType:UIButtonTypeCustom]; + doneBtn.frame = CGRectMake(containerView.frame.size.width - 69, 8, 63, 27); + doneBtn.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin; + [doneBtn setTitle:@"Done" forState:UIControlStateNormal]; + + [doneBtn setTitleShadowColor:[UIColor colorWithWhite:0 alpha:0.4] forState:UIControlStateNormal]; + doneBtn.titleLabel.shadowOffset = CGSizeMake (0.0, -1.0); + doneBtn.titleLabel.font = [UIFont boldSystemFontOfSize:18.0f]; + + [doneBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; + [doneBtn addTarget:self action:@selector(resignTextView) forControlEvents:UIControlEventTouchUpInside]; + [doneBtn setBackgroundImage:sendBtnBackground forState:UIControlStateNormal]; + [doneBtn setBackgroundImage:selectedSendBtnBackground forState:UIControlStateSelected]; + [containerView addSubview:doneBtn]; + containerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin; +} + +-(void)resignTextView +{ + [textView resignFirstResponder]; +} + +//Code from Brett Schumann +-(void) keyboardWillShow:(NSNotification *)note{ + // get keyboard size and loctaion + CGRect keyboardBounds; + [[note.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] getValue: &keyboardBounds]; + NSNumber *duration = [note.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey]; + NSNumber *curve = [note.userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey]; + + // Need to translate the bounds to account for rotation. + keyboardBounds = [self.view convertRect:keyboardBounds toView:nil]; + + // get a rect for the textView frame + CGRect containerFrame = containerView.frame; + containerFrame.origin.y = self.view.bounds.size.height - (keyboardBounds.size.height + containerFrame.size.height); + // animations settings + [UIView beginAnimations:nil context:NULL]; + [UIView setAnimationBeginsFromCurrentState:YES]; + [UIView setAnimationDuration:[duration doubleValue]]; + [UIView setAnimationCurve:[curve intValue]]; + + // set views with new info + containerView.frame = containerFrame; + + // commit animations + [UIView commitAnimations]; +} + +-(void) keyboardWillHide:(NSNotification *)note{ + NSNumber *duration = [note.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey]; + NSNumber *curve = [note.userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey]; + + // get a rect for the textView frame + CGRect containerFrame = containerView.frame; + containerFrame.origin.y = self.view.bounds.size.height - containerFrame.size.height; + + // animations settings + [UIView beginAnimations:nil context:NULL]; + [UIView setAnimationBeginsFromCurrentState:YES]; + [UIView setAnimationDuration:[duration doubleValue]]; + [UIView setAnimationCurve:[curve intValue]]; + + // set views with new info + containerView.frame = containerFrame; + + // commit animations + [UIView commitAnimations]; +} + +- (void)growingTextView:(HPGrowingTextView *)growingTextView willChangeHeight:(float)height +{ + float diff = (growingTextView.frame.size.height - height); + + CGRect r = containerView.frame; + r.size.height -= diff; + r.origin.y += diff; + containerView.frame = r; +} + +-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation +{ + return YES; +} + +- (void)didReceiveMemoryWarning { + // Releases the view if it doesn't have a superview. + [super didReceiveMemoryWarning]; + + // Release any cached data, images, etc that aren't in use. +} + +- (void)viewDidUnload { + // Release any retained subviews of the main view. + // e.g. self.myOutlet = nil; +} + + +- (void)dealloc { + [chatTableView release]; + [textView release]; + [containerView release]; + [super dealloc]; +} + +# pragma mark UITableViewDelegate methods + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + return 5; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + static NSString *CellIdentifier = @"ChatCell"; + + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; + if (cell == nil) { + cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; + } + + // Set up the cell... + NSString *cellValue = @"test"; + cell.textLabel.text = cellValue; + + return cell; +} + +@end diff --git a/Classes/ChatViewController.xib b/Classes/ChatViewController.xib new file mode 100644 index 0000000..909c93e --- /dev/null +++ b/Classes/ChatViewController.xib @@ -0,0 +1,150 @@ +<?xml version="1.0" encoding="UTF-8"?> +<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="7.10"> + <data> + <int key="IBDocument.SystemTarget">784</int> + <string key="IBDocument.SystemVersion">10B500</string> + <string key="IBDocument.InterfaceBuilderVersion">732</string> + <string key="IBDocument.AppKitVersion">1038.2</string> + <string key="IBDocument.HIToolboxVersion">437.00</string> + <object class="NSMutableDictionary" key="IBDocument.PluginVersions"> + <string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string> + <string key="NS.object.0">62</string> + </object> + <object class="NSMutableArray" key="IBDocument.EditedObjectIDs"> + <bool key="EncodedWithXMLCoder">YES</bool> + <integer value="1"/> + </object> + <object class="NSArray" key="IBDocument.PluginDependencies"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string> + </object> + <object class="NSMutableDictionary" key="IBDocument.Metadata"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSArray" key="dict.sortedKeys" id="0"> + <bool key="EncodedWithXMLCoder">YES</bool> + </object> + <object class="NSMutableArray" key="dict.values"> + <bool key="EncodedWithXMLCoder">YES</bool> + </object> + </object> + <object class="NSMutableArray" key="IBDocument.RootObjects" id="1000"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="IBProxyObject" id="372490531"> + <string key="IBProxiedObjectIdentifier">IBFilesOwner</string> + </object> + <object class="IBProxyObject" id="975951072"> + <string key="IBProxiedObjectIdentifier">IBFirstResponder</string> + </object> + <object class="IBUIView" id="191373211"> + <reference key="NSNextResponder"/> + <int key="NSvFlags">274</int> + <string key="NSFrameSize">{320, 460}</string> + <reference key="NSSuperview"/> + <object class="NSColor" key="IBUIBackgroundColor"> + <int key="NSColorSpace">3</int> + <bytes key="NSWhite">MQA</bytes> + <object class="NSColorSpace" key="NSCustomColorSpace"> + <int key="NSID">2</int> + </object> + </object> + <object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics"/> + </object> + </object> + <object class="IBObjectContainer" key="IBDocument.Objects"> + <object class="NSMutableArray" key="connectionRecords"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="IBConnectionRecord"> + <object class="IBCocoaTouchOutletConnection" key="connection"> + <string key="label">view</string> + <reference key="source" ref="372490531"/> + <reference key="destination" ref="191373211"/> + </object> + <int key="connectionID">3</int> + </object> + </object> + <object class="IBMutableOrderedSet" key="objectRecords"> + <object class="NSArray" key="orderedObjects"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="IBObjectRecord"> + <int key="objectID">0</int> + <reference key="object" ref="0"/> + <reference key="children" ref="1000"/> + <nil key="parent"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">1</int> + <reference key="object" ref="191373211"/> + <reference key="parent" ref="0"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">-1</int> + <reference key="object" ref="372490531"/> + <reference key="parent" ref="0"/> + <string key="objectName">File's Owner</string> + </object> + <object class="IBObjectRecord"> + <int key="objectID">-2</int> + <reference key="object" ref="975951072"/> + <reference key="parent" ref="0"/> + </object> + </object> + </object> + <object class="NSMutableDictionary" key="flattenedProperties"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSArray" key="dict.sortedKeys"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>-1.CustomClassName</string> + <string>-2.CustomClassName</string> + <string>1.IBEditorWindowLastContentRect</string> + <string>1.IBPluginDependency</string> + </object> + <object class="NSMutableArray" key="dict.values"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>ChatViewController</string> + <string>UIResponder</string> + <string>{{556, 412}, {320, 480}}</string> + <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string> + </object> + </object> + <object class="NSMutableDictionary" key="unlocalizedProperties"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference key="dict.sortedKeys" ref="0"/> + <object class="NSMutableArray" key="dict.values"> + <bool key="EncodedWithXMLCoder">YES</bool> + </object> + </object> + <nil key="activeLocalization"/> + <object class="NSMutableDictionary" key="localizations"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference key="dict.sortedKeys" ref="0"/> + <object class="NSMutableArray" key="dict.values"> + <bool key="EncodedWithXMLCoder">YES</bool> + </object> + </object> + <nil key="sourceID"/> + <int key="maxID">3</int> + </object> + <object class="IBClassDescriber" key="IBDocument.Classes"> + <object class="NSMutableArray" key="referencedPartialClassDescriptions"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="IBPartialClassDescription"> + <string key="className">ChatViewController</string> + <string key="superclassName">UIViewController</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBProjectSource</string> + <string key="minorKey">ChatViewController.h</string> + </object> + </object> + </object> + </object> + <int key="IBDocument.localizationMode">0</int> + <object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies"> + <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3</string> + <integer value="3000" key="NS.object.0"/> + </object> + <bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool> + <nil key="IBDocument.LastKnownRelativeProjectPath"/> + <int key="IBDocument.defaultPropertyAccessControl">3</int> + <string key="IBCocoaTouchPluginVersion">3.1</string> + </data> +</archive> diff --git a/Classes/RootViewController.h b/Classes/RootViewController.h index 96d27bb..4125de9 100644 --- a/Classes/RootViewController.h +++ b/Classes/RootViewController.h @@ -9,7 +9,7 @@ #import <UIKit/UIKit.h> -@interface RootViewController : UIViewController { +@interface RootViewController : UIViewController <UIWebViewDelegate> { IBOutlet UIWebView *webView; } diff --git a/Classes/RootViewController.m b/Classes/RootViewController.m index 053242c..f647a5e 100644 --- a/Classes/RootViewController.m +++ b/Classes/RootViewController.m @@ -28,7 +28,7 @@ - (void)viewDidLoad { [super viewDidLoad]; - [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://google-developers.appspot.com/maps/documentation/javascript/examples/map-simple"]]]; + [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://google-developers.appspot.com/maps/documentation/javascript/examples/event-closure"]]]; } @@ -60,4 +60,16 @@ } +# pragma mark UIWebViewDelegate methods + +- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { + if (navigationType == UIWebViewNavigationTypeLinkClicked) { + // Flip and open chat view + NSLog(@"UIWebView item clicked"); + } + + return YES; +} + + @end |
