Skip to content

Commit

Permalink
- Merging AndreasVerhoeven's use of real app icons installed on the d…
Browse files Browse the repository at this point in the history
…evice;

- Slight code style reorg;
- Using proper UIBezierPath to clip icons instead of lazy UIView renderInContext.
  • Loading branch information
lmmenge committed Oct 28, 2014
1 parent 89b6ceb commit 6896af1
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 68 deletions.
5 changes: 3 additions & 2 deletions LaunchServicesApis/LMApp.h
Expand Up @@ -10,12 +10,13 @@

@interface LMApp : NSObject

+(instancetype)appWithPrivateProxy:(id)privateProxy;
+(instancetype)appWithBundleIdentifier:(NSString*)bundleIdentifier;
@property (nonatomic, readonly) NSString* bundleIdentifier;
@property (nonatomic, readonly) NSString* name;
@property (nonatomic, readonly) UIImage* icon;

@property (nonatomic, readonly) BOOL isHiddenApp;

+ (instancetype)appWithPrivateProxy:(id)privateProxy;
+ (instancetype)appWithBundleIdentifier:(NSString*)bundleIdentifier;

@end
74 changes: 40 additions & 34 deletions LaunchServicesApis/LMApp.m
Expand Up @@ -13,75 +13,81 @@ + (id)_iconForResourceProxy:(id)arg1 variant:(int)arg2 variantsScale:(float)arg3
+ (id)_applicationIconImageForBundleIdentifier:(id)arg1 format:(int)arg2 scale:(double)arg3;
@end

#pragma mark -

@interface PrivateApi_LSApplicationProxy
+(instancetype)applicationProxyForIdentifier:(NSString*)identifier;

+ (instancetype)applicationProxyForIdentifier:(NSString*)identifier;
@property (nonatomic, readonly) NSString* localizedShortName;
@property (nonatomic, readonly) NSString* localizedName;
@property (nonatomic, readonly) NSString* bundleIdentifier;
@property (nonatomic, readonly) NSArray* appTags;

@end

#pragma mark -

@implementation LMApp
{
PrivateApi_LSApplicationProxy* _applicationProxy;
UIImage* _icon;
}

+(instancetype)appWithPrivateProxy:(id)privateProxy
{
return [[self alloc] initWithPrivateProxy:privateProxy];
}

-(id)initWithPrivateProxy:(id)privateProxy
- (NSString*)name
{
self = [super init];
if(self != nil)
{
_applicationProxy = (PrivateApi_LSApplicationProxy*)privateProxy;
}

return self;
return _applicationProxy.localizedName ?: _applicationProxy.localizedShortName;
}

+(instancetype)appWithBundleIdentifier:(NSString*)bundleIdentifier
- (NSString*)bundleIdentifier
{
return [[self alloc] initWithBundleIdentifier:bundleIdentifier];
return [_applicationProxy bundleIdentifier];
}

-(id)initWithBundleIdentifier:(NSString*)bundleIdentifier
- (UIImage*)icon
{
self = [super init];
if(self != nil)
if(nil == _icon)
{
_applicationProxy = [NSClassFromString(@"LSApplicationProxy") applicationProxyForIdentifier:bundleIdentifier];
_icon = [UIImage _applicationIconImageForBundleIdentifier:self.bundleIdentifier format:10 scale:2.0];
}

return self;
return _icon;
}

-(NSString*)name
- (BOOL)isHiddenApp
{
return _applicationProxy.localizedName ?: _applicationProxy.localizedShortName;
return [[_applicationProxy appTags] indexOfObject:@"hidden"] != NSNotFound;
}

-(NSString*)bundleIdentifier
- (id)initWithPrivateProxy:(id)privateProxy
{
return [_applicationProxy bundleIdentifier];
self = [super init];
if(self != nil)
{
_applicationProxy = (PrivateApi_LSApplicationProxy*)privateProxy;
}

return self;
}

-(UIImage*)icon
- (instancetype)initWithBundleIdentifier:(NSString*)bundleIdentifier
{
if(nil == _icon)
{
_icon = [UIImage _applicationIconImageForBundleIdentifier:self.bundleIdentifier format:10 scale:2.0];
}

return _icon;
self = [super init];
if(self != nil)
{
_applicationProxy = [NSClassFromString(@"LSApplicationProxy") applicationProxyForIdentifier:bundleIdentifier];
}

return self;
}

-(BOOL)isHiddenApp
+ (instancetype)appWithPrivateProxy:(id)privateProxy
{
return [[_applicationProxy appTags] indexOfObject:@"hidden"] != NSNotFound;
return [[self alloc] initWithPrivateProxy:privateProxy];
}

+ (instancetype)appWithBundleIdentifier:(NSString*)bundleIdentifier
{
return [[self alloc] initWithBundleIdentifier:bundleIdentifier];
}

@end
5 changes: 3 additions & 2 deletions LaunchServicesApis/LMAppController.h
Expand Up @@ -11,9 +11,10 @@

@interface LMAppController : NSObject

+(instancetype)sharedInstance;
@property (nonatomic, readonly) NSArray* installedApplications;

-(BOOL)openAppWithBundleIdentifier:(NSString*)bundleIdentifier;
- (BOOL)openAppWithBundleIdentifier:(NSString*)bundleIdentifier;

+ (instancetype)sharedInstance;

@end
36 changes: 19 additions & 17 deletions LaunchServicesApis/LMAppController.m
Expand Up @@ -9,27 +9,19 @@
#import "LMAppController.h"

@interface PrivateApi_LSApplicationWorkspace
-(NSArray*)allInstalledApplications;
- (NSArray*)allInstalledApplications;
- (bool)openApplicationWithBundleID:(id)arg1;
@end

@implementation LMAppController
{
PrivateApi_LSApplicationWorkspace* _workspace;
NSArray* _installedApplications;
}
#pragma mark -

+(instancetype)sharedInstance
@implementation LMAppController
{
static dispatch_once_t once;
static id sharedInstance;
dispatch_once(&once, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
PrivateApi_LSApplicationWorkspace* _workspace;
NSArray* _installedApplications;
}

-(id)init
- (instancetype)init
{
self = [super init];
if(self != nil)
Expand All @@ -40,7 +32,7 @@ -(id)init
return self;
}

-(NSArray*)readApplications
- (NSArray*)readApplications
{
NSArray* allInstalledApplications = [_workspace allInstalledApplications];
NSMutableArray* applications = [NSMutableArray arrayWithCapacity:allInstalledApplications.count];
Expand All @@ -56,7 +48,7 @@ -(NSArray*)readApplications
return applications;
}

-(NSArray*)installedApplications
- (NSArray*)installedApplications
{
if(nil == _installedApplications)
{
Expand All @@ -66,9 +58,19 @@ -(NSArray*)installedApplications
return _installedApplications;
}

-(BOOL)openAppWithBundleIdentifier:(NSString *)bundleIdentifier
- (BOOL)openAppWithBundleIdentifier:(NSString *)bundleIdentifier
{
return (BOOL)[_workspace openApplicationWithBundleID:bundleIdentifier];
}

+ (instancetype)sharedInstance
{
static dispatch_once_t once;
static id sharedInstance;
dispatch_once(&once, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}

@end
20 changes: 7 additions & 13 deletions WatchSpringboard/LMViewControllerView.m
Expand Up @@ -133,33 +133,27 @@ - (instancetype)initWithCoder:(NSCoder *)aDecoder

// pre-render the known icons
NSMutableArray* images = [NSMutableArray array];
UIView* view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 60)];
UIImageView* maskImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Icon.png"]];
[view addSubview:maskImage];
UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
button.maskView = maskImage;
button.frame = maskImage.frame;
[view addSubview:button];
UIBezierPath* clipPath = [UIBezierPath bezierPathWithOvalInRect:CGRectInset(CGRectMake(0, 0, 60, 60), 0.5,0.5)];
for(LMApp* app in apps)
{
UIImage* image = app.icon;
[button setBackgroundImage:image forState:UIControlStateNormal];
UIImage* image = app.icon;

UIGraphicsBeginImageContextWithOptions(CGSizeMake(60, 60), NO, [UIScreen mainScreen].scale);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
[clipPath addClip];
[image drawInRect:CGRectMake(0, 0, 60, 60)];
UIImage* renderedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

[images addObject:renderedImage];
}

// build out item set
NSInteger index = 0;
NSInteger index = 0;
for(LMApp* app in apps)
{
LMSpringboardItemView* item = [[LMSpringboardItemView alloc] init];
item.bundleIdentifier = app.bundleIdentifier;
[item setTitle:app.name];
item.bundleIdentifier = app.bundleIdentifier;
[item setTitle:app.name];
item.icon.image = images[index++];
[itemViews addObject:item];
}
Expand Down

0 comments on commit 6896af1

Please sign in to comment.