Skip to content

Instantly share code, notes, and snippets.

@LnL7
Created October 24, 2011 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LnL7/1309211 to your computer and use it in GitHub Desktop.
Save LnL7/1309211 to your computer and use it in GitHub Desktop.
libctivator-example
#import "JDAppController.h"
static UIWindow *springBoardWindow;
@interface JDAppController()
@end
@implementation JDAppController
- (id)init
{
if(( self = [super init] ))
{
_configController = [[JDConfigWindowController alloc] init];
[_configController setSpringBoardWindow:springBoardWindow];
//[springBoardWindow setAlpha:0.7f];
}
return self;
}
- (void)dealloc
{
[_configController release];
[super dealloc];
}
+ (void)setSpringBoardWindow:(UIWindow *)window
{
springBoardWindow = window;
[springBoardWindow retain];
}
@synthesize configController = _configController;
+ (void)load
{
[[LAActivator sharedInstance] registerListener:[self new] forName:@"me.lnl.jb-app"];
}
- (void)activator:(LAActivator *)activator receiveEvent:(LAEvent *)event
{
[_configController toggleWindow];
[event setHandled:true];
}
- (void)activator:(LAActivator *)activator receiveDeactivateEvent:(LAEvent *)event
{
if( [_configController hideWindow] )
{
[event setHandled:true];
}
}
- (void)activator:(LAActivator *)activator abortEvent:(LAEvent *)event
{
[_configController hideWindow];
[event setHandled:true];
}
@end
#import "JDConfigWindowController.h"
@interface JDConfigWindowController()
@end
@implementation JDConfigWindowController
- (id)init
{
if(( self = [super init] ))
{
_isWindowVisible = false;
_cRect = CGRectMake(25, 45, 270, 320);
}
return self;
}
- (void)dealloc
{
[self hideWindow];
[super dealloc];
}
@synthesize springBoardWindow = _springBoardWindow;
@synthesize isWindowVisible = _isWindowVisible;
@synthesize window = _window;
- (void)toggleWindow
{
if( !_isWindowVisible )
{
[self showWindow];
}else
{
[self hideWindow];
}
}
- (BOOL)showWindow
{
if( !_isWindowVisible )
{
_window = [[JDConfigWindow alloc] initWithFrame:_cRect];
[_window setAlpha:0.90f];
[_window loadSubviews];
[[_window showButton] setFrame:CGRectMake(10, 10, 64, 64)];
[[_window showButton] addTarget:self action:@selector(showPressed:) forControlEvents:UIControlEventTouchUpInside];
[[_window hideButton] setFrame:CGRectMake(196, 10, 64, 64)];
[[_window hideButton] addTarget:self action:@selector(hidePressed:) forControlEvents:UIControlEventTouchUpInside];
_isWindowVisible = true;
return true;
}
return false;
}
- (BOOL)hideWindow
{
if( _isWindowVisible )
{
[_window unloadSubviews];
[_window release];
_isWindowVisible = false;
return true;
}
return false;
}
- (void)showPressed:(UIButton *)sender
{
[_springBoardWindow setAlpha:0.7];
}
- (void)hidePressed:(UIButton *)sender
{
UIAlertView *a = [[UIAlertView alloc] initWithTitle:@"A" message:@"alert" delegate:nil cancelButtonTitle:@"Yay" otherButtonTitles:nil, nil];
[a show];
[a release];
}
@end
#import <SpringBoard/SpringBoard.h>
#import "JDAppController.h"
%hook SBAppWindow
-(id)initWithFrame:(CGRect)frame
{
UIWindow *window = %orig;
[JDAppController setSpringBoardWindow:window];
return window;
}
%end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment