Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of git@github.com:Empact/kuler-iphone
- Loading branch information
Showing
9 changed files
with
389 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// RootViewController.h | ||
// kuler-iphone | ||
// | ||
// Created by Benjamin Ortuzar on 02/08/2008. | ||
// Copyright 2008 __MyCompanyName__. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
|
||
@interface RootViewController : UITableViewController { | ||
|
||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
// | ||
// RootViewController.m | ||
// kuler-iphone | ||
// | ||
// Created by Benjamin Ortuzar on 02/08/2008. | ||
// Copyright 2008 __MyCompanyName__. All rights reserved. | ||
// | ||
|
||
#import "RootViewController.h" | ||
#import "kuler_iphoneAppDelegate.h" | ||
#import "TableViewCell.h" | ||
|
||
|
||
@implementation RootViewController | ||
|
||
- (id)initWithStyle:(UITableViewStyle)style { | ||
if (self = [super initWithStyle:style]) { | ||
|
||
NSLog(@"initializing RootViewController"); | ||
self.title = @"Themes"; | ||
self.tableView.delegate = self; | ||
self.tableView.dataSource = self; | ||
self.tableView.rowHeight = 48.0; | ||
self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine; | ||
self.tableView.sectionHeaderHeight = 0; | ||
} | ||
return self; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { | ||
return 1; | ||
} | ||
|
||
|
||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { | ||
kuler_iphoneAppDelegate *appDelegate = (kuler_iphoneAppDelegate *)[[UIApplication sharedApplication] delegate]; | ||
NSUInteger count = [appDelegate countOfList]; | ||
// If no themes were parsed because the RSS feed was not available, | ||
// return a count of 1 so that the data source method tableView:cellForRowAtIndexPath: is called. | ||
// It also calls -[kuler_iphoneAppDelegate isDataSourceAvailable] to determine what to show in the table. | ||
if ([appDelegate isDataSourceAvailable] == NO) { | ||
return 1; | ||
} | ||
return count; | ||
} | ||
|
||
|
||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | ||
|
||
static NSString *MyIdentifier = @"MyIdentifier"; | ||
|
||
TableViewCell *cell = (TableViewCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier]; | ||
if (cell == nil) { | ||
cell = [[[TableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease]; | ||
} | ||
|
||
// Set up the cell. | ||
kuler_iphoneAppDelegate *appDelegate = (kuler_iphoneAppDelegate *)[[UIApplication sharedApplication] delegate]; | ||
|
||
// If the RSS feed isn't accessible (which could happen if the network isn't available), show an informative | ||
// message in the first row of the table. | ||
if ([appDelegate isDataSourceAvailable] == NO) { | ||
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"DefaultTableViewCell"] autorelease]; | ||
cell.text = NSLocalizedString(@"RSS Host Not Available", @"RSS Host Not Available message"); | ||
cell.textColor = [UIColor colorWithWhite:0.5 alpha:0.5]; | ||
cell.accessoryType = UITableViewCellAccessoryNone; | ||
return cell; | ||
} | ||
|
||
Theme *themeForRow = [appDelegate objectInListAtIndex:indexPath.row]; | ||
[cell setTheme:themeForRow]; | ||
return cell; | ||
} | ||
|
||
/* | ||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { | ||
} | ||
*/ | ||
/* | ||
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { | ||
if (editingStyle == UITableViewCellEditingStyleDelete) { | ||
} | ||
if (editingStyle == UITableViewCellEditingStyleInsert) { | ||
} | ||
} | ||
*/ | ||
/* | ||
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { | ||
return YES; | ||
} | ||
*/ | ||
/* | ||
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { | ||
} | ||
*/ | ||
/* | ||
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { | ||
return YES; | ||
} | ||
*/ | ||
|
||
|
||
- (void)dealloc { | ||
[super dealloc]; | ||
} | ||
|
||
|
||
- (void)viewDidLoad { | ||
[super viewDidLoad]; | ||
} | ||
|
||
|
||
- (void)viewWillAppear:(BOOL)animated { | ||
[super viewWillAppear:animated]; | ||
} | ||
|
||
- (void)viewDidAppear:(BOOL)animated { | ||
[super viewDidAppear:animated]; | ||
} | ||
|
||
- (void)viewWillDisappear:(BOOL)animated { | ||
} | ||
|
||
- (void)viewDidDisappear:(BOOL)animated { | ||
} | ||
|
||
- (void)didReceiveMemoryWarning { | ||
[super didReceiveMemoryWarning]; | ||
} | ||
|
||
|
||
@end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
#import <UIKit/UIKit.h> | ||
#import "Theme.h" | ||
|
||
@interface TableViewCell : UITableViewCell { | ||
|
||
@private | ||
Theme *_theme; | ||
UILabel *_themeNameLabel; | ||
UIImageView *_themeImageView; | ||
} | ||
|
||
@property (nonatomic, retain) UILabel *themeNameLabel; | ||
@property (nonatomic, retain) UIImageView *themeImageView; | ||
|
||
|
||
- (Theme *)theme; | ||
- (void)setTheme:(Theme *)newTheme; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
#import "TableViewCell.h" | ||
|
||
|
||
static UIImage *themeImage = nil; | ||
|
||
@interface TableViewCell() | ||
- (UILabel *)newLabelWithPrimaryColor:(UIColor *)primaryColor selectedColor:(UIColor *)selectedColor fontSize:(CGFloat)fontSize bold:(BOOL)bold; | ||
@end | ||
|
||
@implementation TableViewCell | ||
|
||
@synthesize themeNameLabel = _themeNameLabel; | ||
@synthesize themeImageView = _themeImageView; | ||
|
||
+ (void)initialize | ||
{ | ||
//deleted | ||
themeImage = [[UIImage imageNamed:@"theme_sample.png"] retain]; | ||
} | ||
|
||
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier | ||
{ | ||
if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) { | ||
UIView *myContentView = self.contentView; | ||
|
||
// Add an image view to display a waveform image of the earthquake. | ||
self.themeImageView = [[UIImageView alloc] initWithImage:themeImage]; | ||
[myContentView addSubview:self.themeImageView]; | ||
[self.themeImageView release]; | ||
|
||
// A label that displays the name of the theme. | ||
self.themeNameLabel = [self newLabelWithPrimaryColor:[UIColor blackColor] selectedColor:[UIColor whiteColor] fontSize:14.0 bold:YES]; | ||
self.themeNameLabel.textAlignment = UITextAlignmentLeft; // default | ||
[myContentView addSubview:self.themeNameLabel]; | ||
[self.themeNameLabel release]; | ||
|
||
|
||
// Position the magnitudeImageView above all of the other views so | ||
// it's not obscured. It's a transparent image, so any views | ||
// that overlap it will still be visible. | ||
[myContentView bringSubviewToFront:self.themeImageView]; | ||
} | ||
return self; | ||
} | ||
|
||
- (Theme *)theme | ||
{ | ||
return _theme; | ||
} | ||
|
||
// Rather than using one of the standard UITableViewCell content properties like 'text', | ||
// we're using a custom property called 'theme' to populate the table cell. Whenever the | ||
// value of that property changes, we need to call [self setNeedsDisplay] to force the | ||
// cell to be redrawn. | ||
- (void)setTheme:(Theme *)newTheme | ||
{ | ||
[newTheme retain]; | ||
[_theme release]; | ||
_theme = newTheme; | ||
|
||
//self.themeNameLabel.text = newTheme.title; | ||
self.themeNameLabel.text = @"Theme Title"; | ||
self.themeImageView.image = themeImage; | ||
|
||
[self setNeedsDisplay]; | ||
} | ||
|
||
|
||
|
||
- (void)layoutSubviews { | ||
|
||
#define LEFT_COLUMN_OFFSET 10 | ||
#define LEFT_COLUMN_WIDTH 200 | ||
|
||
#define MIDDLE_COLUMN_OFFSET 180 | ||
#define MIDDLE_COLUMN_WIDTH 100 | ||
|
||
#define UPPER_ROW_TOP 4 | ||
#define LOWER_ROW_TOP 28 | ||
|
||
[super layoutSubviews]; | ||
CGRect contentRect = self.contentView.bounds; | ||
|
||
// In this example we will never be editing, but this illustrates the appropriate pattern | ||
if (!self.editing) { | ||
|
||
CGFloat boundsX = contentRect.origin.x; | ||
CGRect frame; | ||
|
||
// Place the title label. | ||
frame = CGRectMake(boundsX + LEFT_COLUMN_OFFSET, UPPER_ROW_TOP, LEFT_COLUMN_WIDTH, 20); | ||
self.themeNameLabel.frame = frame; | ||
|
||
// Place the waveform image. | ||
UIImageView *imageView = self.themeImageView; | ||
frame = [imageView frame]; | ||
frame.origin.x = boundsX + MIDDLE_COLUMN_OFFSET; | ||
frame.origin.y = UPPER_ROW_TOP; | ||
imageView.frame = frame; | ||
|
||
|
||
} | ||
} | ||
|
||
- (void)setSelected:(BOOL)selected animated:(BOOL)animated { | ||
/* | ||
Views are drawn most efficiently when they are opaque and do not have a clear background, so in newLabelForMainText: the labels are made opaque and given a white background. To show selection properly, however, the views need to be transparent (so that the selection color shows through). | ||
*/ | ||
[super setSelected:selected animated:animated]; | ||
|
||
UIColor *backgroundColor = nil; | ||
if (selected) { | ||
backgroundColor = [UIColor clearColor]; | ||
} else { | ||
backgroundColor = [UIColor whiteColor]; | ||
} | ||
|
||
self.themeNameLabel.backgroundColor = backgroundColor; | ||
self.themeNameLabel.highlighted = selected; | ||
self.themeNameLabel.opaque = !selected; | ||
|
||
} | ||
|
||
- (UILabel *)newLabelWithPrimaryColor:(UIColor *)primaryColor selectedColor:(UIColor *)selectedColor fontSize:(CGFloat)fontSize bold:(BOOL)bold | ||
{ | ||
/* | ||
Create and configure a label. | ||
*/ | ||
|
||
UIFont *font; | ||
if (bold) { | ||
font = [UIFont boldSystemFontOfSize:fontSize]; | ||
} else { | ||
font = [UIFont systemFontOfSize:fontSize]; | ||
} | ||
|
||
/* | ||
Views are drawn most efficiently when they are opaque and do not have a clear background, so set these defaults. To show selection properly, however, the views need to be transparent (so that the selection color shows through). This is handled in setSelected:animated:. | ||
*/ | ||
UILabel *newLabel = [[UILabel alloc] initWithFrame:CGRectZero]; | ||
newLabel.backgroundColor = [UIColor whiteColor]; | ||
newLabel.opaque = YES; | ||
newLabel.textColor = primaryColor; | ||
newLabel.highlightedTextColor = selectedColor; | ||
newLabel.font = font; | ||
|
||
return newLabel; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.