Skip to content

Commit

Permalink
Emoji support for iOS 5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
0xced committed Mar 9, 2012
1 parent 429763a commit 5324568
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 1 deletion.
32 changes: 31 additions & 1 deletion Classes/ArtworkViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "ArtworkViewController.h"
#import "ArtworkDetailViewController.h"
#import "AppDelegate.h"
#import "EmojiImageView.h"
#import "IPAArchive.h"

#import "FindSymbol.h"
Expand Down Expand Up @@ -159,6 +160,33 @@ - (NSDictionary *) artwork
}
@catch (NSException *exception)
{
Class UIKeyboardEmojiCategoryController = NSClassFromString(@"UIKeyboardEmojiCategoryController");
Class UIKeyboardEmojiFactory = NSClassFromString(@"UIKeyboardEmojiFactory");
id emojiController = [[[UIKeyboardEmojiFactory alloc] init] autorelease];
id keyboardEmojiCategoryController = [[UIKeyboardEmojiCategoryController alloc] performSelector:@selector(initWithController:) withObject:emojiController];
NSArray *categories = [NSArray arrayWithObjects:@"People", @"Nature", @"Objects", @"Places", @"Symbols", nil];
for (NSString *category in categories)
{
NSMutableArray *categoryList = [NSMutableArray array];
NSString *categoryKey = [@"UIKeyboardEmojiCategory" stringByAppendingString:category];
id keyboardEmojiCategory = [keyboardEmojiCategoryController performSelector:@selector(categoryForKey:) withObject:categoryKey];
for (id emoji in [keyboardEmojiCategory valueForKey:@"emoji"])
{
NSMutableString *name = (NSMutableString *)CFStringCreateMutableCopy(kCFAllocatorDefault, 0, (CFStringRef)[emoji valueForKey:@"key"]);
CFStringTransform((CFMutableStringRef)name, NULL, kCFStringTransformToUnicodeName, false);
[name replaceOccurrencesOfString:@"\\N" withString:@"" options:0 range:NSMakeRange(0, [name length])];
[name replaceOccurrencesOfString:@"{" withString:@"" options:0 range:NSMakeRange(0, [name length])];
[name replaceOccurrencesOfString:@"}" withString:@"" options:0 range:NSMakeRange(0, [name length])];

UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"EmojiCell"] autorelease];
cell.textLabel.text = [[[(NSMutableString *)name autorelease] capitalizedString] stringByAppendingPathExtension:@"png"];
cell.textLabel.font = [UIFont systemFontOfSize:12];
cell.accessoryView = [[[EmojiImageView alloc] initWithFrame:CGRectMake(0, 0, 24, 24) emoji:emoji] autorelease];

[categoryList addObject:cell];
}
[self.bundles setObject:categoryList forKey:category];
}
}
keys = [emojiMap allKeys];
}
Expand Down Expand Up @@ -413,6 +441,8 @@ - (void) saveImage:(NSDictionary *)imageInfo
NSString *bundleName = [[imageInfo objectForKey:@"bundleName"] stringByReplacingOccurrencesOfString:@"." withString:@" "];
if (self.archive.appName && [[self sectionTitles] count] > 1)
bundleName = [self.archive.appName stringByAppendingPathComponent:bundleName];
else if ([self isEmoji])
bundleName = [@"Emoji" stringByAppendingPathComponent:bundleName];
NSString *imagePath = [[appDelegate saveDirectory:bundleName] stringByAppendingPathComponent:pathWithScale(imageName, [image scale])];
[UIImagePNGRepresentation(image) writeToFile:imagePath atomically:YES];
[self performSelectorOnMainThread:@selector(incrementSaveCounter) withObject:nil waitUntilDone:YES];
Expand Down Expand Up @@ -506,7 +536,7 @@ - (NSArray *) cellsInSection:(NSUInteger)section
- (NSArray *) sectionIndexTitlesForTableView:(UITableView *)tableView
{
NSArray *sectionTitles = [self sectionTitles];
if (tableView == self.tableView && [sectionTitles count] > 1)
if (![self isEmoji] && tableView == self.tableView && [sectionTitles count] > 1)
{
NSMutableArray *sectionIndexTitles = [NSMutableArray array];
for (NSString *title in sectionTitles)
Expand Down
15 changes: 15 additions & 0 deletions Classes/EmojiImageView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// EmojiImageView.h
// UIKit Artwork Extractor
//
// Created by Cédric Luthi on 09.03.12.
// Copyright (c) 2012 Cédric Luthi. All rights reserved.
//

@interface EmojiImageView : UIView

- (id) initWithFrame:(CGRect)frame emoji:(id)emoji;

- (UIImage *) image;

@end
54 changes: 54 additions & 0 deletions Classes/EmojiImageView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// EmojiImageView.m
// UIKit Artwork Extractor
//
// Created by Cédric Luthi on 09.03.12.
// Copyright (c) 2012 Cédric Luthi. All rights reserved.
//

#import "EmojiImageView.h"

@interface EmojiImageView ()
@property (nonatomic, retain) id emoji;
@end

@implementation EmojiImageView

@synthesize emoji = _emoji;

- (id) initWithFrame:(CGRect)frame emoji:(id)emoji
{
if (!(self = [super initWithFrame:frame]))
return nil;

self.backgroundColor = [UIColor clearColor];
self.emoji = emoji;

return self;
}

- (void) dealloc
{
self.emoji = nil;
[super dealloc];
}

- (void) drawRect:(CGRect)rect
{
UIFont *emojiFont = [UIFont fontWithName:@"AppleColorEmoji" size:CGRectGetHeight(self.frame)];
NSString *emojiString = [self.emoji valueForKey:@"emojiString"];
[emojiString drawAtPoint:CGPointZero withFont:emojiFont];
}

- (UIImage *) image
{
UIGraphicsBeginImageContextWithOptions(self.frame.size, NO, 0.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.layer renderInContext:context];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return image;
}

@end
6 changes: 6 additions & 0 deletions UIKit Artwork Extractor.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
DAF387921211AF30003DF2B8 /* UITintedGlassButtonMask@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = DAF3878E1211AF30003DF2B8 /* UITintedGlassButtonMask@2x.png */; };
DAF387931211AF30003DF2B8 /* UITintedGlassButtonShadow@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = DAF3878F1211AF30003DF2B8 /* UITintedGlassButtonShadow@2x.png */; };
DAFA3ECD14ADF53B00C532E9 /* ArtworkViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = DAFA3ECC14ADF53B00C532E9 /* ArtworkViewController.xib */; };
DAFFB59C150A5CF400A4B6DC /* EmojiImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = DAFFB59B150A5CF400A4B6DC /* EmojiImageView.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -141,6 +142,8 @@
DAF3878E1211AF30003DF2B8 /* UITintedGlassButtonMask@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "UITintedGlassButtonMask@2x.png"; sourceTree = "<group>"; };
DAF3878F1211AF30003DF2B8 /* UITintedGlassButtonShadow@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "UITintedGlassButtonShadow@2x.png"; sourceTree = "<group>"; };
DAFA3ECC14ADF53B00C532E9 /* ArtworkViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = ArtworkViewController.xib; path = ../ArtworkViewController.xib; sourceTree = "<group>"; };
DAFFB59A150A5CF400A4B6DC /* EmojiImageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EmojiImageView.h; sourceTree = "<group>"; };
DAFFB59B150A5CF400A4B6DC /* EmojiImageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EmojiImageView.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -170,6 +173,8 @@
DA3C70F81141405200A99F39 /* ArtworkDetailViewController.h */,
DA3C70F91141405200A99F39 /* ArtworkDetailViewController.m */,
DAC7969F11FD71E100A33F28 /* ArtworkDetailViewController.xib */,
DAFFB59A150A5CF400A4B6DC /* EmojiImageView.h */,
DAFFB59B150A5CF400A4B6DC /* EmojiImageView.m */,
DA9AD664138FC4BD00BDC968 /* FindSymbol.h */,
DA9AD658138FC3B200BDC968 /* FindSymbol.c */,
DA8BF5B7112EAC4E0044106B /* GlossyButtonViewController.h */,
Expand Down Expand Up @@ -424,6 +429,7 @@
DAB5337014B3C39D00EDDE37 /* ZKLFHeader.m in Sources */,
DAB5337114B3C39D00EDDE37 /* ZKLog.m in Sources */,
DAD7253F14BB9A80001ED756 /* NSString+IPAArchive.m in Sources */,
DAFFB59C150A5CF400A4B6DC /* EmojiImageView.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
1 change: 1 addition & 0 deletions UIKit_Artwork_Extractor_Prefix.pch
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h>
#import <UIKit/UIKit.h>

#if __IPHONE_OS_VERSION_MAX_ALLOWED < 40000
Expand Down

0 comments on commit 5324568

Please sign in to comment.