Skip to content

Commit

Permalink
Refactor load template function of wrapper view
Browse files Browse the repository at this point in the history
  • Loading branch information
Torin Nguyen committed Jul 5, 2012
1 parent 9e5b17c commit 727e52f
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 49 deletions.
4 changes: 0 additions & 4 deletions WTMGlyphDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
/* Begin PBXBuildFile section */
4249137A15A5422B001F58DD /* WTMGlyphDetectorView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4249137915A5422B001F58DD /* WTMGlyphDetectorView.m */; };
4249138615A5544E001F58DD /* circle.json in Resources */ = {isa = PBXBuildFile; fileRef = 4249138015A5544E001F58DD /* circle.json */; };
4249138715A5544E001F58DD /* L.json in Resources */ = {isa = PBXBuildFile; fileRef = 4249138115A5544E001F58DD /* L.json */; };
4249138815A5544E001F58DD /* square.json in Resources */ = {isa = PBXBuildFile; fileRef = 4249138215A5544E001F58DD /* square.json */; };
4249138915A5544E001F58DD /* triangle.json in Resources */ = {isa = PBXBuildFile; fileRef = 4249138315A5544E001F58DD /* triangle.json */; };
4249138A15A5544E001F58DD /* V.json in Resources */ = {isa = PBXBuildFile; fileRef = 4249138415A5544E001F58DD /* V.json */; };
Expand Down Expand Up @@ -49,7 +48,6 @@
4249137815A5422B001F58DD /* WTMGlyphDetectorView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WTMGlyphDetectorView.h; sourceTree = "<group>"; };
4249137915A5422B001F58DD /* WTMGlyphDetectorView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WTMGlyphDetectorView.m; sourceTree = "<group>"; };
4249138015A5544E001F58DD /* circle.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = circle.json; sourceTree = "<group>"; };
4249138115A5544E001F58DD /* L.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = L.json; sourceTree = "<group>"; };
4249138215A5544E001F58DD /* square.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = square.json; sourceTree = "<group>"; };
4249138315A5544E001F58DD /* triangle.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = triangle.json; sourceTree = "<group>"; };
4249138415A5544E001F58DD /* V.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = V.json; sourceTree = "<group>"; };
Expand Down Expand Up @@ -127,7 +125,6 @@
isa = PBXGroup;
children = (
4249138015A5544E001F58DD /* circle.json */,
4249138115A5544E001F58DD /* L.json */,
4249138215A5544E001F58DD /* square.json */,
4249138315A5544E001F58DD /* triangle.json */,
4249138415A5544E001F58DD /* V.json */,
Expand Down Expand Up @@ -321,7 +318,6 @@
42E35A3415A5372500C9A3F3 /* P.json in Resources */,
42E35A3615A5372500C9A3F3 /* T.json in Resources */,
4249138615A5544E001F58DD /* circle.json in Resources */,
4249138715A5544E001F58DD /* L.json in Resources */,
4249138815A5544E001F58DD /* square.json in Resources */,
4249138915A5544E001F58DD /* triangle.json in Resources */,
4249138A15A5544E001F58DD /* V.json in Resources */,
Expand Down
5 changes: 3 additions & 2 deletions WTMGlyphDemo/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ - (void)viewDidLoad
self.gestureDetectorView = [[WTMGlyphDetectorView alloc] initWithFrame:self.view.bounds];
self.gestureDetectorView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.gestureDetectorView.delegate = self;
[self.gestureDetectorView loadTemplatesWithNames:@"N", @"T", @"W", @"V", @"circle", @"square", @"triangle", nil];
[self.view addSubview:self.gestureDetectorView];
}

Expand All @@ -36,7 +37,7 @@ - (void)viewDidAppear:(BOOL)animated

NSString *glyphNames = [self.gestureDetectorView getGlyphNamesString];
if ([glyphNames length] > 0) {
NSString *statusText = [NSString stringWithFormat:@"Loaded with %@ templates.\nWait 2 seconds between gestures.\n\nStart drawing.", [self.gestureDetectorView getGlyphNamesString]];
NSString *statusText = [NSString stringWithFormat:@"Loaded with %@ templates.\n\nStart drawing.", [self.gestureDetectorView getGlyphNamesString]];
self.lblStatus.text = statusText;
}
}
Expand Down Expand Up @@ -68,7 +69,7 @@ - (void)wtmGlyphDetectorView:(WTMGlyphDetectorView*)theView glyphDetected:(WTMGl

NSString *glyphNames = [self.gestureDetectorView getGlyphNamesString];
if ([glyphNames length] > 0)
statusString = [statusString stringByAppendingFormat:@"Loaded with %@ templates.\nWait 2 seconds between gestures.\n\n", glyphNames];
statusString = [statusString stringByAppendingFormat:@"Loaded with %@ templates.\n\n", glyphNames];

statusString = [statusString stringByAppendingFormat:@"Last gesture detected: %@\nScore: %.3f", glyph.name, score];

Expand Down
2 changes: 2 additions & 0 deletions WTMGlyphDemo/WTMGlyphDetectorView.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
@interface WTMGlyphDetectorView : UIView
@property (nonatomic, strong) id delegate;

- (void)loadTemplatesWithNames:(NSString*)firstTemplate, ... NS_REQUIRES_NIL_TERMINATION;

- (NSString *)getGlyphNamesString;

@end
38 changes: 28 additions & 10 deletions WTMGlyphDemo/WTMGlyphDetectorView.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ - (id)initWithFrame:(CGRect)frame
return self;
}

- (void)initGestureDetector
{
self.glyphDetector = [WTMGlyphDetector detector];
self.glyphDetector.delegate = self;
self.glyphDetector.timeoutSeconds = 1;

if (self.glyphNamesArray == nil)
self.glyphNamesArray = [[NSMutableArray alloc] init];
}




#pragma mark - Public interfaces

- (NSString *)getGlyphNamesString
{
if (self.glyphNamesArray == nil || [self.glyphNamesArray count] <= 0)
Expand All @@ -36,24 +51,27 @@ - (NSString *)getGlyphNamesString
return [self.glyphNamesArray componentsJoinedByString: @", "];
}

- (void)initGestureDetector
- (void)loadTemplatesWithNames:(NSString*)firstTemplate, ...
{
self.glyphDetector = [WTMGlyphDetector detector];
self.glyphDetector.delegate = self;

//Create your own gesture templates with ShapeEditor: http://lucalaiho.altervista.org/joomla/shape-editor
self.glyphNamesArray = [NSMutableArray arrayWithObjects:@"N", @"T", @"L", @"W", @"V", @"circle", @"square", @"triangle", nil];

// Add initial glyph templates
for (NSString *glyphName in self.glyphNamesArray) {
va_list args;
va_start(args, firstTemplate);
for (NSString *glyphName = firstTemplate; glyphName != nil; glyphName = va_arg(args, id))
{
if (![glyphName isKindOfClass:[NSString class]])
continue;

[self.glyphNamesArray addObject:glyphName];

NSData *jsonData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:glyphName ofType:@"json"]];
[self.glyphDetector addGlyphFromJSON:jsonData name:glyphName];
}

va_end(args);
}





#pragma mark - WTMGlyphDelegate

- (void)glyphDetected:(WTMGlyph *)glyph withScore:(float)score
Expand Down
3 changes: 1 addition & 2 deletions WTMGlyphDemo/en.lproj/ViewController_iPad.xib
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@
<object class="IBUILabel" id="110637317">
<reference key="NSNextResponder" ref="766721923"/>
<int key="NSvFlags">303</int>
<string key="NSFrame">{{0, 452}, {768, 100}}</string>
<string key="NSFrameSize">{768, 1004}</string>
<reference key="NSSuperview" ref="766721923"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
Expand Down
28 changes: 2 additions & 26 deletions WTMGlyphDemo/en.lproj/ViewController_iPhone.xib
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@
<object class="IBUILabel" id="205463313">
<reference key="NSNextResponder" ref="774585933"/>
<int key="NSvFlags">303</int>
<string key="NSFrame">{{0, 180}, {320, 100}}</string>
<string key="NSFrameSize">{320, 460}</string>
<reference key="NSSuperview" ref="774585933"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
Expand Down Expand Up @@ -72,7 +71,6 @@
</array>
<string key="NSFrame">{{0, 20}, {320, 460}}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="205463313"/>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">10</int>
Expand Down Expand Up @@ -4540,29 +4538,7 @@ AAgAAAAIAAIACAACAAAAAgAAAAEAAQABAAE</bytes>
<nil key="sourceID"/>
<int key="maxID">9</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
<object class="IBPartialClassDescription">
<string key="className">ViewController</string>
<string key="superclassName">UIViewController</string>
<object class="NSMutableDictionary" key="outlets">
<string key="NS.key.0">lblStatus</string>
<string key="NS.object.0">UILabel</string>
</object>
<object class="NSMutableDictionary" key="toOneOutletInfosByName">
<string key="NS.key.0">lblStatus</string>
<object class="IBToOneOutletInfo" key="NS.object.0">
<string key="name">lblStatus</string>
<string key="candidateClassName">UILabel</string>
</object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/ViewController.h</string>
</object>
</object>
</array>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes"/>
<int key="IBDocument.localizationMode">0</int>
<string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string>
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencyDefaults">
Expand Down
5 changes: 0 additions & 5 deletions WTMGlyphDemo/gestures/L.json

This file was deleted.

0 comments on commit 727e52f

Please sign in to comment.