Skip to content

Instantly share code, notes, and snippets.

@jontelang
Created April 25, 2013 03:56
Show Gist options
  • Save jontelang/5457403 to your computer and use it in GitHub Desktop.
Save jontelang/5457403 to your computer and use it in GitHub Desktop.
sd
#import <AudioToolbox/AudioToolbox.h>
#import <AVFoundation/AVFoundation.h>
@interface JWLPiano : UIView <UIGestureRecognizerDelegate>
{
NSString *PIN;
int PINLength;
UIImageView *whiteKeys;
UIImageView *blackKeys;
UIImageView *whiteDots;
UIImageView *greyDots;
UIView* toggleButton;
}
+(JWLPiano*)sharedInstance;
-(void)addToPIN:(int)number;
@end
@interface key : UIView <UIGestureRecognizerDelegate>
{
UIView *touches;
}
@end
@implementation key
-(id)initWithFrame:(CGRect)frame{
if( (self = [super initWithFrame:frame]) )
{
touches = [[UIView alloc] initWithFrame:self.bounds];
touches.backgroundColor = [UIColor blackColor];
touches.alpha = 0.3;
touches.hidden = YES;
[self addSubview:touches];
}
return self;
}
-(void)touchesBegan:(NSSet *)touchess withEvent:(UIEvent *)event
{
touches.hidden = NO;
AVAudioPlayer *audioPlayer;
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"/x/%i.mp3", self.tag]];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
[audioPlayer play];
[[JWLPiano sharedInstance] addToPIN:self.tag];
}
-(void)touchesEnded:(NSSet *)touchess withEvent:(UIEvent *)event
{
touches.hidden = YES;
}
-(void)touchesCancelled:(NSSet *)touchess withEvent:(UIEvent *)event
{
touches.hidden = YES;
}
@end
static JWLPiano* staticPiano;
@implementation JWLPiano
+(JWLPiano*)sharedInstance
{
if(!staticPiano)
{
staticPiano = [[JWLPiano alloc] initWithFrame:CGRectMake(0,0,320,215)];
staticPiano.backgroundColor = [UIColor redColor];
}
return staticPiano;
}
-(id)initWithFrame:(CGRect)frame
{
if( self = [super initWithFrame:frame] )
{
PIN = @"";
PINLength = 5;
...
for (int i = 0; i < 7; ++i)
{
key *k = [[key alloc] initWithFrame:CGRectMake(6+i*44,21,44,190)];
k.tag = i;
[k setUserInteractionEnabled:YES];
[self addSubview:k];
[k release];
}
}
return self;
}
-(void)togglePiano:(UITapGestureRecognizer*)recognizer
{
self.hidden = YES;
}
-(void)addToPIN:(int)number
{
NSLog(@"---- %@", PIN);
PIN = [NSString stringWithFormat:@"%@%i", PIN, number];
NSLog(@"---- %@", PIN);
}
@end
%hook SBDeviceLockViewWithKeypadPhone
- (id)keypadView
{
id d = %orig;
[JWLPiano sharedInstance].hidden = NO;
[d addSubview:[JWLPiano sharedInstance]];
return d;
}
%end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment