Skip to content

Commit

Permalink
merge upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
stcui committed Nov 22, 2012
2 parents 0cbf49d + 9d53634 commit 0da938f
Show file tree
Hide file tree
Showing 16 changed files with 1,471 additions and 202 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ build/*
xcuserdata
profile
*.moved-aside
.DS_Store
.DS_Store
2 changes: 2 additions & 0 deletions BeeDebugger/Bee_Debug.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#import "Bee_DebugMemoryModel.h"
#import "Bee_DebugMessageModel.h"
#import "Bee_DebugNetworkModel.h"
#import "Bee_DebugHeatmapModel.h"

@implementation BeeDebugger

Expand All @@ -48,6 +49,7 @@ + (void)show
[BeeDebugMemoryModel sharedInstance];
[BeeDebugMessageModel sharedInstance];
[BeeDebugNetworkModel sharedInstance];
[BeeDebugHeatmapModel sharedInstance];
#endif
}

Expand Down
63 changes: 63 additions & 0 deletions BeeDebugger/Bee_DebugHeatmapModel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//
// ______ ______ ______
// /\ __ \ /\ ___\ /\ ___\
// \ \ __< \ \ __\_ \ \ __\_
// \ \_____\ \ \_____\ \ \_____\
// \/_____/ \/_____/ \/_____/
//
// Copyright (c) 2012 BEE creators
// http://www.whatsbug.com
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//
//
// Bee_DebugHeatmapModel.h
//

#if __BEE_DEBUGGER__

#import "Bee.h"

#pragma mark -

@interface BeeDebugHeatmapModel : BeeModel
{
NSUInteger _rowCount;
NSUInteger _colCount;
NSUInteger _peakValueTap;
NSUInteger _peakValueDrag;
NSUInteger * _heatmapTap;
NSUInteger * _heatmapDrag;
}

@property (nonatomic, readonly) NSUInteger rowCount;
@property (nonatomic, readonly) NSUInteger colCount;
@property (nonatomic, readonly) NSUInteger peakValueTap;
@property (nonatomic, readonly) NSUInteger peakValueDrag;
@property (nonatomic, readonly) NSUInteger * heatmapTap;
@property (nonatomic, readonly) NSUInteger * heatmapDrag;

AS_SINGLETON( BeeDebugHeatmapModel )

- (void)recordTapAtLocation:(CGPoint)location;
- (void)recordDragAtLocation:(CGPoint)location;

@end

#endif // #if __BEE_DEBUGGER__
303 changes: 303 additions & 0 deletions BeeDebugger/Bee_DebugHeatmapModel.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,303 @@
//
// ______ ______ ______
// /\ __ \ /\ ___\ /\ ___\
// \ \ __< \ \ __\_ \ \ __\_
// \ \_____\ \ \_____\ \ \_____\
// \/_____/ \/_____/ \/_____/
//
// Copyright (c) 2012 BEE creators
// http://www.whatsbug.com
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//
//
// Bee_DebugHeatmapModel.h
//

#if __BEE_DEBUGGER__

#import <objc/runtime.h>
#import "Bee_DebugHeatmapModel.h"

#pragma mark -

@interface BeeDebugTapIndicator : UIImageView
@end

#pragma mark -

@implementation BeeDebugTapIndicator

static inline float radians(double degrees) { return degrees * M_PI / 180.0f; }

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if ( self )
{
self.backgroundColor = [UIColor clearColor];
self.userInteractionEnabled = NO;
self.contentMode = UIViewContentModeCenter;
self.image = [UIImage imageNamed:@"tap.png"];
}
return self;
}

- (void)startAnimation
{
self.alpha = 1.0f;
self.transform = CGAffineTransformMakeScale( 0.8f, 0.8f );

[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDuration:1.0f];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(didAppearingAnimationStopped)];

self.alpha = 0.0f;
self.transform = CGAffineTransformIdentity;

[UIView commitAnimations];
}

- (void)didAppearingAnimationStopped
{
[self removeFromSuperview];
}

- (void)dealloc
{
[super dealloc];
}

@end

#pragma mark -

@interface BeeDebugBorder : UIImageView
@end

#pragma mark -

@implementation BeeDebugBorder

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if ( self )
{
self.backgroundColor = [UIColor clearColor];
self.userInteractionEnabled = NO;
self.layer.borderWidth = 3.0f;
self.layer.borderColor = [UIColor redColor].CGColor;
}
return self;
}

- (void)startAnimation
{
self.alpha = 1.0f;

[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDuration:1.0f];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(didAppearingAnimationStopped)];

self.alpha = 0.0f;

[UIView commitAnimations];
}

- (void)didAppearingAnimationStopped
{
[self removeFromSuperview];
}

- (void)dealloc
{
[super dealloc];
}

@end

#pragma mark -

@interface UIWindow(BeeDebugger)
- (void)mySendEvent:(UIEvent *)event;
@end

#pragma mark -

@implementation UIWindow(BeeDebugger)

static void (* _origSendEvent)( id, SEL, UIEvent * );

+ (void)swizzle
{
static BOOL __swizzled = NO;
if ( NO == __swizzled )
{
Method method;
IMP implement;

method = class_getInstanceMethod( [UIWindow class], @selector(sendEvent:) );
_origSendEvent = (void *)method_getImplementation( method );

implement = class_getMethodImplementation( [UIWindow class], @selector(mySendEvent:) );
method_setImplementation( method, implement );

__swizzled = YES;
}
}

- (void)mySendEvent:(UIEvent *)event
{
static NSTimeInterval __timeStamp = 0.0;

if ( _origSendEvent )
{
_origSendEvent( self, _cmd, event );
}

UIWindow * keyWindow = [UIApplication sharedApplication].keyWindow;
if ( self != keyWindow )
return;

BeeDebugHeatmapModel * model = [BeeDebugHeatmapModel sharedInstance];

if ( UIEventTypeTouches == event.type )
{
NSSet * allTouches = [event allTouches];
if ( 1 == [allTouches count] )
{
UITouch * touch = [[allTouches allObjects] objectAtIndex:0];
if ( 1 == [touch tapCount] )
{
CGPoint location = [touch locationInView:keyWindow];

CC( @"touch.phase = %d", touch.phase );

if ( UITouchPhaseBegan == touch.phase )
{
__timeStamp = touch.timestamp;

BeeDebugBorder * border = [[[BeeDebugBorder alloc] initWithFrame:touch.view.bounds] autorelease];
[touch.view addSubview:border];
[border startAnimation];
}
else if ( UITouchPhaseMoved == touch.phase )
{
[model recordDragAtLocation:location];
}
else if ( UITouchPhaseEnded == touch.phase || UITouchPhaseCancelled == touch.phase )
{
BeeDebugTapIndicator * indicator = [[[BeeDebugTapIndicator alloc] initWithFrame:CGRectMake(0, 0, 50.0f, 50.0f)] autorelease];
indicator.center = location;
[keyWindow addSubview:indicator];
[indicator startAnimation];

NSTimeInterval diff = touch.timestamp - __timeStamp;
if ( diff <= 0.3f )
{
[model recordTapAtLocation:location];
}
}
}
}
}
}

@end

#pragma mark -

@implementation BeeDebugHeatmapModel

@synthesize rowCount = _rowCount;
@synthesize colCount = _colCount;
@synthesize peakValueTap = _peakValueTap;
@synthesize peakValueDrag = _peakValueDrag;
@synthesize heatmapTap = _heatmapTap;
@synthesize heatmapDrag = _heatmapDrag;

DEF_SINGLETON( BeeDebugHeatmapModel )

- (void)load
{
[super load];

UIWindow * keyWindow = [UIApplication sharedApplication].keyWindow;

_colCount = (NSUInteger)((keyWindow.bounds.size.width + 15.0f) / 16.0f);
_rowCount = (NSUInteger)((keyWindow.bounds.size.height + 15.0f) / 16.0f);

_peakValueTap = 1;
_peakValueDrag = 1;

size_t alloc_size = sizeof(NSUInteger) * _rowCount * _colCount;

_heatmapTap = (NSUInteger *)malloc( alloc_size );
memset( _heatmapTap, 0x0, alloc_size );

_heatmapDrag = (NSUInteger *)malloc( alloc_size );
memset( _heatmapDrag, 0x0, alloc_size );

[UIWindow swizzle];
}

- (void)unload
{
free( _heatmapTap );
free( _heatmapDrag );

[super unload];
}

- (void)recordTapAtLocation:(CGPoint)location
{
NSUInteger col = (NSUInteger)(location.x / 16.0f);
NSUInteger row = (NSUInteger)(location.y / 16.0f);
NSUInteger index = _colCount * row + col;

_heatmapTap[index] += 1;

if ( _heatmapTap[index] > _peakValueTap )
{
_peakValueTap = _heatmapTap[index];
}
}

- (void)recordDragAtLocation:(CGPoint)location
{
NSUInteger col = (NSUInteger)(location.x / 16.0f);
NSUInteger row = (NSUInteger)(location.y / 16.0f);
NSUInteger index = _colCount * row + col;

_heatmapDrag[index] += 1;

if ( _heatmapDrag[index] > _peakValueDrag )
{
_peakValueDrag = _heatmapDrag[index];
}
}

@end

#endif // #if __BEE_DEBUGGER__
Loading

0 comments on commit 0da938f

Please sign in to comment.