From f0aad7c366845f85c894e8238731b67cff48987b Mon Sep 17 00:00:00 2001 From: Keith Lazuka Date: Mon, 21 Dec 2009 16:10:16 -0500 Subject: [PATCH] Better tile touch selection semantics (matches MobileCal behavior) --- Kal/KalGridView.h | 2 ++ Kal/KalGridView.m | 45 +++++++++++++++++++++------------------------ Kal/KalTileView.m | 8 +++++++- 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/Kal/KalGridView.h b/Kal/KalGridView.h index 07cdaa9..b06d620 100644 --- a/Kal/KalGridView.h +++ b/Kal/KalGridView.h @@ -26,11 +26,13 @@ id delegate; // Assigned. KalLogic *logic; KalTileView *selectedTile; + KalTileView *highlightedTile; NSMutableArray *reusableCells; // The pool of reusable cells. If this runs out, the app will crash instead of dynamically allocating more views. So make this just large enough to meet your app needs, but no larger. CGFloat cellHeight; // Every cell must have the same height: specifically, the height stored here. } @property (nonatomic, retain) KalTileView *selectedTile; +@property (nonatomic, retain) KalTileView *highlightedTile; - (id)initWithFrame:(CGRect)frame logic:(KalLogic *)logic delegate:(id)delegate; diff --git a/Kal/KalGridView.m b/Kal/KalGridView.m index 6d55454..d482266 100644 --- a/Kal/KalGridView.m +++ b/Kal/KalGridView.m @@ -25,7 +25,7 @@ - (void)selectTodayIfVisible; @implementation KalGridView -@synthesize selectedTile; +@synthesize selectedTile, highlightedTile; - (id)initWithFrame:(CGRect)frame logic:(KalLogic *)theLogic delegate:(id)theDelegate { @@ -80,16 +80,6 @@ - (void)refresh } } -- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event -{ - UITouch *touch = [touches anyObject]; - CGPoint location = [touch locationInView:self]; - UIView *hitView = [self hitTest:location withEvent:event]; - - if ([hitView isKindOfClass:[KalTileView class]]) - self.selectedTile = (KalTileView*)hitView; -} - - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; @@ -99,8 +89,15 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event if (!hitView) return; - if ([hitView isKindOfClass:[KalTileView class]]) - self.selectedTile = (KalTileView*)hitView; + if ([hitView isKindOfClass:[KalTileView class]]) { + KalTileView *tile = (KalTileView*)hitView; + if (tile.belongsToAdjacentMonth) { + self.highlightedTile = tile; + } else { + self.highlightedTile = nil; + self.selectedTile = tile; + } + } } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event @@ -118,16 +115,9 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event [delegate showPreviousMonth]; } } - self.selectedTile = tile; } -} - -- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event -{ - UITouch *touch = [touches anyObject]; - NSLog(@"cancelled touches at %@", NSStringFromCGPoint([touch locationInView:self])); - self.selectedTile = nil; + self.highlightedTile = nil; } - (void)updateTilesInKeptCell:(UIView*)cell @@ -150,6 +140,15 @@ - (void)sizeToFit self.height = [[self.subviews valueForKeyPath:@"@sum.height"] floatValue]; } +- (void)setHighlightedTile:(KalTileView *)tile +{ + if (highlightedTile != tile) { + highlightedTile.highlighted = NO; + highlightedTile = [tile retain]; + tile.highlighted = YES; + } +} + - (void)setSelectedTile:(KalTileView *)tile { if (selectedTile != tile) { @@ -345,6 +344,7 @@ - (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished c - (void)dealloc { [selectedTile release]; + [highlightedTile release]; [reusableCells release]; [logic release]; [super dealloc]; @@ -352,6 +352,3 @@ - (void)dealloc @end - - - diff --git a/Kal/KalTileView.m b/Kal/KalTileView.m index e8b474d..966ceb0 100644 --- a/Kal/KalTileView.m +++ b/Kal/KalTileView.m @@ -96,6 +96,12 @@ - (void)setSelected:(BOOL)selected [self reloadStyle]; } +- (void)setHighlighted:(BOOL)highlighted +{ + [super setHighlighted:highlighted]; + [self reloadStyle]; +} + #pragma mark UIView and UIResponder - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [[self nextResponder] touchesBegan:touches withEvent:event]; } @@ -154,7 +160,7 @@ - (void)reloadStyle dayLabel.shadowColor = nil; backgroundView.image = [UIImage imageNamed:@"kal_tile.png"]; markerImage = [UIImage imageNamed:@"kal_marker_disabled.png"]; - if (self.selected) { + if (self.highlighted) { self.backgroundColor = [UIColor lightGrayColor]; } break;