Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-11275] (3_0_X) Ignore click events outside the button #3273

Merged
merged 3 commits into from
Oct 17, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions iphone/Classes/LauncherButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#ifdef USE_TI_UIDASHBOARDVIEW

#import <Foundation/Foundation.h>
#import "LauncherView.h"

@class LauncherItem;

Expand All @@ -41,13 +40,10 @@
UIButton *button;
UIButton *closeButton;
UIButton *badge;
LauncherView* launcherView;
}

@property(nonatomic,readwrite,retain) LauncherItem *item;
@property(nonatomic,readonly) UIButton *closeButton;
@property(nonatomic,readonly) UIButton *button;
@property(nonatomic,readwrite,assign) LauncherView* launcherView;

@property(nonatomic) BOOL dragging;
@property(nonatomic) BOOL editing;
Expand Down
108 changes: 47 additions & 61 deletions iphone/Classes/LauncherButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,36 +39,19 @@

@implementation LauncherButton

@synthesize dragging, editing, item, launcherView;
@synthesize dragging, editing, item;

-(id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame])
{
self.backgroundColor = [UIColor clearColor];
if (self = [super initWithFrame:frame])
{
self.backgroundColor = [UIColor clearColor];
button = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
button.backgroundColor = [UIColor clearColor];
[button addTarget:self action:@selector(buttonTouchedUpInside:) forControlEvents:UIControlEventTouchUpInside];
[button addTarget:self action:@selector(buttonTouchedUpOutside:) forControlEvents:UIControlEventTouchUpOutside];
[button addTarget:self action:@selector(buttonTouchedDown:withEvent:) forControlEvents:UIControlEventTouchDown];
button.userInteractionEnabled = NO;
[self addSubview:button];
}
return self;
}

- (void)buttonTouchedUpInside:(UIButton*)button
{
[launcherView buttonTouchedUpInside:self];
}

- (void)buttonTouchedUpOutside:(UIButton*)button
{
[launcherView buttonTouchedUpOutside:self];
}

- (void)buttonTouchedDown:(UIButton*)button withEvent:(UIEvent*)event
{
[launcherView buttonTouchedDown:self withEvent:event];
}
return self;
}

-(void)dealloc
Expand All @@ -81,6 +64,27 @@ -(void)dealloc
[super dealloc];
}

-(UIView *) hitTest:(CGPoint)point withEvent:(UIEvent *)event {
UIView *superResult = [super hitTest:point withEvent:event];
if (!editing && (superResult == self)) {
//TIMOB-11275 Ignore all touches if not in button frame and not editing
CGRect buttonFrame = [button frame];
if (CGRectContainsPoint(buttonFrame, point)) {
return superResult;
}
if (badge != nil) {
buttonFrame = [badge frame];
if (CGRectContainsPoint(buttonFrame, point)) {
return superResult;
}
}
return nil;
}
else {
return superResult;
}
}

-(void)setFrame:(CGRect)frame
{
[super setFrame:frame];
Expand Down Expand Up @@ -130,38 +134,30 @@ -(void)setItem:(LauncherItem *)item_

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event
{
[super touchesBegan:touches withEvent:event];
if (editing) {
[launcherView touchesBegan:touches withEvent:event];
}
else {
[[self nextResponder]touchesBegan:touches withEvent:event];
}
[super touchesBegan:touches withEvent:event];
[[self nextResponder]touchesBegan:touches withEvent:event];
}

- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent *)event
{
[super touchesMoved:touches withEvent:event];
if (editing) {
[launcherView touchesMoved:touches withEvent:event];
}
else {
[[self nextResponder]touchesMoved:touches withEvent:event];
}
[super touchesMoved:touches withEvent:event];
[[self nextResponder]touchesMoved:touches withEvent:event];
}

- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent *)event
{
[super touchesEnded:touches withEvent:event];
if (dragging) {
[launcherView buttonTouchedUpInside:self];
}
if (editing) {
[launcherView touchesEnded:touches withEvent:event];
}
else {
[[self nextResponder]touchesEnded:touches withEvent:event];
}
[super touchesEnded:touches withEvent:event];
[[self nextResponder]touchesEnded:touches withEvent:event];
}

-(void) setSelected:(BOOL)yn {
[super setSelected:yn];
[button setSelected:yn];
}

-(void) setHighlighted:(BOOL)yn {
[super setHighlighted:yn];
[button setHighlighted:yn];
}

- (BOOL)isHighlighted
Expand All @@ -174,10 +170,6 @@ - (BOOL)isSelected
return !dragging && [super isSelected];
}

- (UIButton*)button
{
return button;
}
- (UIButton*)closeButton
{
if (!closeButton && item.canDelete)
Expand Down Expand Up @@ -220,7 +212,6 @@ - (void)setEditing:(BOOL)editing_
if (editing != editing_)
{
editing = editing_;
[button setUserInteractionEnabled:!editing];
if (editing)
{
if (badge!=nil)
Expand Down Expand Up @@ -263,7 +254,6 @@ - (void)layoutSubviews
buttonBounds.origin.y = (viewBounds.size.height - buttonBounds.size.height)/2;
}
[button setFrame:buttonBounds];

if (item.badgeValue > 0)
{
if (badge==nil)
Expand All @@ -277,10 +267,7 @@ - (void)layoutSubviews
cbutton.titleLabel.font = [UIFont boldSystemFontOfSize:12];
badge = [cbutton retain];
[self addSubview:badge];
[badge addTarget:self action:@selector(buttonTouchedUpInside:) forControlEvents:UIControlEventTouchUpInside];
[badge addTarget:self action:@selector(buttonTouchedUpOutside:) forControlEvents:UIControlEventTouchUpOutside];
[badge addTarget:self action:@selector(buttonTouchedDown:withEvent:) forControlEvents:UIControlEventTouchDown];
//badge.userInteractionEnabled = NO;
badge.userInteractionEnabled = NO;
}

NSInteger value = item.badgeValue;
Expand Down Expand Up @@ -312,10 +299,9 @@ - (void)layoutSubviews
{
if(self.bounds.size.width > 0 && self.bounds.size.height > 0)
{
CGRect buttonFrame = [button frame];
if (badge)
{
CGPoint point = CGPointMake((buttonFrame.origin.x + buttonFrame.size.width) - (badge.bounds.size.width/2),buttonFrame.origin.y-(4*badge.bounds.size.height/5));
CGPoint point = CGPointMake((buttonBounds.origin.x + buttonBounds.size.width) - (badge.bounds.size.width/2),buttonBounds.origin.y-(4*badge.bounds.size.height/5));
if ((point.x + badge.bounds.size.width) > viewBounds.size.width ){
point.x = viewBounds.size.width - badge.bounds.size.width;
}
Expand All @@ -326,7 +312,7 @@ - (void)layoutSubviews
}
if (closeButton)
{
CGPoint point = CGPointMake(buttonFrame.origin.x-(closeButton.bounds.size.width/3),buttonFrame.origin.y-(closeButton.bounds.size.height/3));
CGPoint point = CGPointMake(buttonBounds.origin.x-(closeButton.bounds.size.width/3),buttonBounds.origin.y-(closeButton.bounds.size.height/3));
if (point.x < 0) {
point.x = 0;
}
Expand Down
3 changes: 0 additions & 3 deletions iphone/Classes/LauncherView.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@
- (LauncherItem*)itemForIndex:(NSInteger)index;
- (NSArray*)items;

- (void)buttonTouchedUpInside:(LauncherButton*)button;
- (void)buttonTouchedUpOutside:(LauncherButton*)button;
- (void)buttonTouchedDown:(LauncherButton*)button withEvent:(UIEvent*)event;
@end


Expand Down
22 changes: 9 additions & 13 deletions iphone/Classes/LauncherView.m
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,13 @@ - (void)dealloc

-(LauncherButton*)addButtonWithItem:(LauncherItem*)item
{
LauncherButton *theButton = [[LauncherButton alloc] initWithFrame:CGRectZero];
UIButton* button = [theButton button];
[scrollView addSubview:theButton];
theButton.item = item;
theButton.launcherView = self;
return [theButton autorelease];
LauncherButton *button = [[LauncherButton alloc] initWithFrame:CGRectZero];
[button addTarget:self action:@selector(buttonTouchedUpInside:) forControlEvents:UIControlEventTouchUpInside];
[button addTarget:self action:@selector(buttonTouchedUpOutside:) forControlEvents:UIControlEventTouchUpOutside];
[button addTarget:self action:@selector(buttonTouchedDown:withEvent:) forControlEvents:UIControlEventTouchDown];
[scrollView addSubview:button];
button.item = item;
return [button autorelease];
}

-(NSInteger)rowHeight
Expand Down Expand Up @@ -544,7 +545,7 @@ - (void)removeItem:(LauncherItem*)item animated:(BOOL)animated
}
}

- (void)closeButtonTouchedUpInside:(UIButton*)closeButton
- (void)closeButtonTouchedUpInside:(LauncherButton*)closeButton
{
for (NSArray* buttonPage in buttons)
{
Expand Down Expand Up @@ -601,7 +602,6 @@ - (void)beginEditing
{
button.editing = YES;
[button.closeButton addTarget:self action:@selector(closeButtonTouchedUpInside:) forControlEvents:UIControlEventTouchUpInside];
[button addTarget:self action:@selector(buttonTouchedDown:withEvent:) forControlEvents:UIControlEventTouchDown];
}
}

Expand Down Expand Up @@ -644,7 +644,6 @@ - (void)endEditing
{
button.transform = CGAffineTransformIdentity;
button.closeButton.alpha = 0;
[button removeTarget:self action:@selector(buttonTouchedDown:withEvent:) forControlEvents:UIControlEventTouchDown];
}
}

Expand Down Expand Up @@ -681,9 +680,6 @@ - (void)editHoldTimer:(NSTimer*)timer
NSArray *data = timer.userInfo;
LauncherButton *button = [data objectAtIndex:0];
UIEvent *event = [data objectAtIndex:1];
if (![button isKindOfClass:[LauncherButton class]]) {
button = (LauncherButton*)[button superview];
}
if ( button.item.userData == nil) {
return;
}
Expand All @@ -692,7 +688,7 @@ - (void)editHoldTimer:(NSTimer*)timer

[button setSelected:NO];
[button setHighlighted:NO];
//[self startDraggingButton:button withEvent:event];
[self startDraggingButton:button withEvent:event];
}


Expand Down