Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

adding new elements and fixing issues in existing

  • Loading branch information...
commit 1b2c1fff4602ff15e3de362dec9bc04063e516f5 1 parent 4d409e4
jsmilani jsmilani authored
52 QuickDialog.xcodeproj/project.pbxproj
@@ -43,6 +43,19 @@
43 43 2C5423DD145ADF2B0026A152 /* QWebElement.m in Sources */ = {isa = PBXBuildFile; fileRef = D811F8BD13EC905B00E3922B /* QWebElement.m */; };
44 44 2C5423DF145ADF2B0026A152 /* QWebViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D811F8BF13EC905B00E3922B /* QWebViewController.m */; };
45 45 2CE450B3145AE43D00B77D0E /* libQuickDialog.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2C542393145ADEBD0026A152 /* libQuickDialog.a */; };
  46 + CCF8140915BE1EC70099940B /* QBetterSegmentedElement.h in Headers */ = {isa = PBXBuildFile; fileRef = CCF813FC15BE1EC70099940B /* QBetterSegmentedElement.h */; };
  47 + CCF8140A15BE1EC70099940B /* QBetterSegmentedElement.m in Sources */ = {isa = PBXBuildFile; fileRef = CCF813FD15BE1EC70099940B /* QBetterSegmentedElement.m */; };
  48 + CCF8140B15BE1EC70099940B /* QDistanceValueParser.h in Headers */ = {isa = PBXBuildFile; fileRef = CCF813FE15BE1EC70099940B /* QDistanceValueParser.h */; };
  49 + CCF8140C15BE1EC70099940B /* QDistanceValueParser.m in Sources */ = {isa = PBXBuildFile; fileRef = CCF813FF15BE1EC70099940B /* QDistanceValueParser.m */; };
  50 + CCF8140D15BE1EC70099940B /* QDualEntryElement.h in Headers */ = {isa = PBXBuildFile; fileRef = CCF8140015BE1EC70099940B /* QDualEntryElement.h */; };
  51 + CCF8140E15BE1EC70099940B /* QDualEntryElement.m in Sources */ = {isa = PBXBuildFile; fileRef = CCF8140115BE1EC70099940B /* QDualEntryElement.m */; };
  52 + CCF8140F15BE1EC70099940B /* QDualEntryTableViewCell.h in Headers */ = {isa = PBXBuildFile; fileRef = CCF8140215BE1EC70099940B /* QDualEntryTableViewCell.h */; };
  53 + CCF8141015BE1EC70099940B /* QDualEntryTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = CCF8140315BE1EC70099940B /* QDualEntryTableViewCell.m */; };
  54 + CCF8141115BE1EC70099940B /* QImageElement.h in Headers */ = {isa = PBXBuildFile; fileRef = CCF8140415BE1EC70099940B /* QImageElement.h */; };
  55 + CCF8141215BE1EC70099940B /* QImageElement.m in Sources */ = {isa = PBXBuildFile; fileRef = CCF8140515BE1EC70099940B /* QImageElement.m */; };
  56 + CCF8141315BE1EC70099940B /* QImageTableViewCell.h in Headers */ = {isa = PBXBuildFile; fileRef = CCF8140615BE1EC70099940B /* QImageTableViewCell.h */; };
  57 + CCF8141415BE1EC70099940B /* QImageTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = CCF8140715BE1EC70099940B /* QImageTableViewCell.m */; };
  58 + CCF8141515BE1EC70099940B /* QuickDialogDualEntryElementDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = CCF8140815BE1EC70099940B /* QuickDialogDualEntryElementDelegate.h */; };
46 59 D80B0E3813E052DF00FA85CA /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D80B0E3713E052DF00FA85CA /* UIKit.framework */; };
47 60 D80B0E3A13E052DF00FA85CA /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D80B0E3913E052DF00FA85CA /* Foundation.framework */; };
48 61 D80B0E3C13E052DF00FA85CA /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D80B0E3B13E052DF00FA85CA /* CoreGraphics.framework */; };
@@ -174,6 +187,19 @@
174 187 194C3FC114EDF0510036C9E7 /* DOAutocompleteTextField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = DOAutocompleteTextField.m; path = quickdialog/DOAutocompleteTextField.m; sourceTree = SOURCE_ROOT; };
175 188 2C542393145ADEBD0026A152 /* libQuickDialog.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libQuickDialog.a; sourceTree = BUILT_PRODUCTS_DIR; };
176 189 2CE450A9145ADFAC00B77D0E /* libQuickDialog-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "libQuickDialog-Prefix.pch"; path = "libQuickDialog/libQuickDialog-Prefix.pch"; sourceTree = SOURCE_ROOT; };
  190 + CCF813FC15BE1EC70099940B /* QBetterSegmentedElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = QBetterSegmentedElement.h; path = quickdialog/QBetterSegmentedElement.h; sourceTree = SOURCE_ROOT; };
  191 + CCF813FD15BE1EC70099940B /* QBetterSegmentedElement.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = QBetterSegmentedElement.m; path = quickdialog/QBetterSegmentedElement.m; sourceTree = SOURCE_ROOT; };
  192 + CCF813FE15BE1EC70099940B /* QDistanceValueParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = QDistanceValueParser.h; path = quickdialog/QDistanceValueParser.h; sourceTree = SOURCE_ROOT; };
  193 + CCF813FF15BE1EC70099940B /* QDistanceValueParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = QDistanceValueParser.m; path = quickdialog/QDistanceValueParser.m; sourceTree = SOURCE_ROOT; };
  194 + CCF8140015BE1EC70099940B /* QDualEntryElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = QDualEntryElement.h; path = quickdialog/QDualEntryElement.h; sourceTree = SOURCE_ROOT; };
  195 + CCF8140115BE1EC70099940B /* QDualEntryElement.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = QDualEntryElement.m; path = quickdialog/QDualEntryElement.m; sourceTree = SOURCE_ROOT; };
  196 + CCF8140215BE1EC70099940B /* QDualEntryTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = QDualEntryTableViewCell.h; path = quickdialog/QDualEntryTableViewCell.h; sourceTree = SOURCE_ROOT; };
  197 + CCF8140315BE1EC70099940B /* QDualEntryTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = QDualEntryTableViewCell.m; path = quickdialog/QDualEntryTableViewCell.m; sourceTree = SOURCE_ROOT; };
  198 + CCF8140415BE1EC70099940B /* QImageElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = QImageElement.h; path = quickdialog/QImageElement.h; sourceTree = SOURCE_ROOT; };
  199 + CCF8140515BE1EC70099940B /* QImageElement.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = QImageElement.m; path = quickdialog/QImageElement.m; sourceTree = SOURCE_ROOT; };
  200 + CCF8140615BE1EC70099940B /* QImageTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = QImageTableViewCell.h; path = quickdialog/QImageTableViewCell.h; sourceTree = SOURCE_ROOT; };
  201 + CCF8140715BE1EC70099940B /* QImageTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = QImageTableViewCell.m; path = quickdialog/QImageTableViewCell.m; sourceTree = SOURCE_ROOT; };
  202 + CCF8140815BE1EC70099940B /* QuickDialogDualEntryElementDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = QuickDialogDualEntryElementDelegate.h; path = quickdialog/QuickDialogDualEntryElementDelegate.h; sourceTree = SOURCE_ROOT; };
177 203 D80B0E3313E052DF00FA85CA /* QuickDialogExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = QuickDialogExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
178 204 D80B0E3713E052DF00FA85CA /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
179 205 D80B0E3913E052DF00FA85CA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
@@ -495,6 +521,19 @@
495 521 D8F180E813F0599A009B0CC7 /* NSMutableArray+MoveObject.m */,
496 522 D87B4FC314F16197006DA833 /* DOAutocompleteTextField.h */,
497 523 D87B4FC414F16197006DA833 /* DOAutocompleteTextField.m */,
  524 + CCF813FC15BE1EC70099940B /* QBetterSegmentedElement.h */,
  525 + CCF813FD15BE1EC70099940B /* QBetterSegmentedElement.m */,
  526 + CCF813FE15BE1EC70099940B /* QDistanceValueParser.h */,
  527 + CCF813FF15BE1EC70099940B /* QDistanceValueParser.m */,
  528 + CCF8140015BE1EC70099940B /* QDualEntryElement.h */,
  529 + CCF8140115BE1EC70099940B /* QDualEntryElement.m */,
  530 + CCF8140215BE1EC70099940B /* QDualEntryTableViewCell.h */,
  531 + CCF8140315BE1EC70099940B /* QDualEntryTableViewCell.m */,
  532 + CCF8140415BE1EC70099940B /* QImageElement.h */,
  533 + CCF8140515BE1EC70099940B /* QImageElement.m */,
  534 + CCF8140615BE1EC70099940B /* QImageTableViewCell.h */,
  535 + CCF8140715BE1EC70099940B /* QImageTableViewCell.m */,
  536 + CCF8140815BE1EC70099940B /* QuickDialogDualEntryElementDelegate.h */,
498 537 D87B4FC514F16197006DA833 /* QAutoEntryElement.h */,
499 538 D87B4FC614F16197006DA833 /* QAutoEntryElement.m */,
500 539 D87B4FC714F16197006DA833 /* QAutoEntryTableViewCell.h */,
@@ -684,6 +723,13 @@
684 723 F2F23A26152DD48B00EB6689 /* QuickDialogController+Helpers.h in Headers */,
685 724 D894F38A15559D34000E3C0F /* NSMutableArray+IMSExtensions.h in Headers */,
686 725 F2304357156CDFDD006D0A56 /* QTextField.h in Headers */,
  726 + CCF8140915BE1EC70099940B /* QBetterSegmentedElement.h in Headers */,
  727 + CCF8140B15BE1EC70099940B /* QDistanceValueParser.h in Headers */,
  728 + CCF8140D15BE1EC70099940B /* QDualEntryElement.h in Headers */,
  729 + CCF8140F15BE1EC70099940B /* QDualEntryTableViewCell.h in Headers */,
  730 + CCF8141115BE1EC70099940B /* QImageElement.h in Headers */,
  731 + CCF8141315BE1EC70099940B /* QImageTableViewCell.h in Headers */,
  732 + CCF8141515BE1EC70099940B /* QuickDialogDualEntryElementDelegate.h in Headers */,
687 733 );
688 734 runOnlyForDeploymentPostprocessing = 0;
689 735 };
@@ -841,6 +887,12 @@
841 887 F2F23A26152DD48B00EB6687 /* QuickDialogController+Helpers.m in Sources */,
842 888 D894F38B15559D34000E3C0F /* NSMutableArray+IMSExtensions.m in Sources */,
843 889 F2304358156CDFDD006D0A56 /* QTextField.m in Sources */,
  890 + CCF8140A15BE1EC70099940B /* QBetterSegmentedElement.m in Sources */,
  891 + CCF8140C15BE1EC70099940B /* QDistanceValueParser.m in Sources */,
  892 + CCF8140E15BE1EC70099940B /* QDualEntryElement.m in Sources */,
  893 + CCF8141015BE1EC70099940B /* QDualEntryTableViewCell.m in Sources */,
  894 + CCF8141215BE1EC70099940B /* QImageElement.m in Sources */,
  895 + CCF8141415BE1EC70099940B /* QImageTableViewCell.m in Sources */,
844 896 );
845 897 runOnlyForDeploymentPostprocessing = 0;
846 898 };
21 quickdialog/QBetterSegmentedElement.h
... ... @@ -0,0 +1,21 @@
  1 +//
  2 +// QBetterSegmentedElement.h
  3 +// WalkWithFriends
  4 +//
  5 +// Created by John Smilanick on 6/26/12.
  6 +// Copyright (c) 2012 Jiff Inc. All rights reserved.
  7 +//
  8 +
  9 +#import "QElement.h"
  10 +
  11 +@interface QBetterSegmentedElement : QRadioElement {
  12 +
  13 +}
  14 +- (QBetterSegmentedElement *)initWithItems:(NSArray *)stringArray selected:(NSInteger)selected;
  15 +
  16 +- (QBetterSegmentedElement *)initWithItems:(NSArray *)stringArray selected:(NSInteger)selected title:(NSString *)title;
  17 +
  18 +//- (QBetterSegmentedElement *)init;
  19 +
  20 +
  21 +@end
63 quickdialog/QBetterSegmentedElement.m
... ... @@ -0,0 +1,63 @@
  1 +//
  2 +// QBetterSegmentedElement.m
  3 +// WalkWithFriends
  4 +//
  5 +// Created by John Smilanick on 6/26/12.
  6 +// Copyright (c) 2012 Jiff Inc. All rights reserved.
  7 +//
  8 +
  9 +#import "QBetterSegmentedElement.h"
  10 +
  11 +@implementation QBetterSegmentedElement {
  12 + QuickDialogController *_controller;
  13 +}
  14 +- (void)setItems:(NSArray *)anItems {
  15 + if (_items != anItems) {
  16 + _items = anItems;
  17 + }
  18 +}
  19 +
  20 +- (QBetterSegmentedElement *)initWithItems:(NSArray *)stringArray selected:(NSInteger)selected {
  21 + self = [super initWithItems:stringArray selected:selected title:nil];
  22 + return self;
  23 +}
  24 +
  25 +- (QBetterSegmentedElement *)initWithItems:(NSArray *)stringArray selected:(NSInteger)selected title:(NSString *)title {
  26 + self = [super initWithItems:stringArray selected:selected title:title];
  27 + return self;
  28 +}
  29 +
  30 +- (void)handleSegmentedControlValueChanged:(id)control {
  31 + _selected = ((UISegmentedControl *)control).selectedSegmentIndex;
  32 + [self handleElementSelected:_controller];
  33 +}
  34 +
  35 +- (UITableViewCell *)getCellForTableView:(QuickDialogTableView *)tableView controller:(QuickDialogController *)controller {
  36 + _controller = controller;
  37 + QTableViewCell *cell = [[QTableViewCell alloc] init];
  38 + cell.textLabel.text = self.title;
  39 + cell.accessoryType = UITableViewCellAccessoryNone;
  40 + cell.selectionStyle = UITableViewCellSelectionStyleNone;
  41 + UISegmentedControl *control = [[UISegmentedControl alloc] initWithItems:_items];
  42 + [control addTarget:self action:@selector(handleSegmentedControlValueChanged:) forControlEvents:UIControlEventValueChanged];
  43 + control.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  44 + control.segmentedControlStyle = UISegmentedControlStyleBar;
  45 + control.selectedSegmentIndex = _selected;
  46 + control.tag = 4321;
  47 +
  48 + cell.accessoryView = control;
  49 + [control sizeToFit];
  50 +
  51 + [self performSelector:@selector(segmentedControlFix:) withObject:control afterDelay:0];
  52 +
  53 + return cell;
  54 +}
  55 +
  56 +- (void)segmentedControlFix:(UISegmentedControl*)control {
  57 + control.selectedSegmentIndex = -1;
  58 + control.selectedSegmentIndex = _selected;
  59 + [control setNeedsDisplay];
  60 +}
  61 +
  62 +
  63 +@end
5 quickdialog/QBindingEvaluator.m
@@ -120,8 +120,9 @@ - (void)fetchValueFromObject:(QElement *)element toData:(id)data {
120 120 NSArray *bindingParams = [each componentsSeparatedByString:@":"];
121 121 NSString *propName = [((NSString *) [bindingParams objectAtIndex:0]) stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
122 122 NSString *valueName = [((NSString *) [bindingParams objectAtIndex:1]) stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
123   -
124   - [data setValue:[element valueForKey:propName] forKey:valueName];
  123 +
  124 + id value = [element valueForKey:propName];
  125 + [data setValue:value forKey:valueName];
125 126 }
126 127
127 128 }
7 quickdialog/QDecimalElement.h
@@ -19,10 +19,11 @@
19 19
20 20 }
21 21
22   -@property(nonatomic, assign) float floatValue;
  22 +@property(nonatomic, strong) NSNumber *decimalValue;
23 23 @property(nonatomic, assign) NSUInteger fractionDigits;
24 24
25   -- (QDecimalElement *)initWithTitle:(NSString *)string value:(float)value;
26   -- (QDecimalElement *)initWithValue:(float)value;
  25 +- (QDecimalElement *)initWithTitle:(NSString *)string value:(NSNumber*)value;
  26 +- (QDecimalElement *)initWithTitle:(NSString *)string value:(NSNumber*)value placeholder:(NSString*)placeholder;
  27 +- (QDecimalElement *)initWithValue:(NSNumber*)value;
27 28
28 29 @end
20 quickdialog/QDecimalElement.m
@@ -22,23 +22,29 @@ @implementation QDecimalElement {
22 22 NSUInteger _fractionDigits;
23 23 }
24 24
25   -@synthesize floatValue = _floatValue;
  25 +@synthesize decimalValue = _decimalValue;
26 26 @synthesize fractionDigits = _fractionDigits;
27 27
28 28
29   -- (QDecimalElement *)initWithTitle:(NSString *)title value:(float)value {
30   - self = [super initWithTitle:title Value:nil] ;
31   - _floatValue = value;
  29 +- (QDecimalElement *)initWithTitle:(NSString *)title value:(NSNumber*)value {
  30 + self = [super initWithTitle:title Value:nil] ;
  31 + _decimalValue = value;
32 32 return self;
33 33 }
34 34
35 35
36   -- (QDecimalElement *)initWithValue:(float)value {
  36 +- (QDecimalElement *)initWithValue:(NSNumber*)value {
37 37 self = [super init];
38   - _floatValue = value;
  38 + _decimalValue = value;
39 39 return self;
40 40 }
41 41
  42 +- (QDecimalElement *)initWithTitle:(NSString *)string value:(NSNumber*)value placeholder:(NSString*)placeholder {
  43 + self = [self initWithTitle:string value:value];
  44 + self.placeholder = placeholder;
  45 + return self;
  46 +}
  47 +
42 48 - (UITableViewCell *)getCellForTableView:(QuickDialogTableView *)tableView controller:(QuickDialogController *)controller {
43 49
44 50 QDecimalTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"QuickformDecimalElement"];
@@ -53,7 +59,7 @@ - (UITableViewCell *)getCellForTableView:(QuickDialogTableView *)tableView contr
53 59 - (void)fetchValueIntoObject:(id)obj {
54 60 if (_key==nil)
55 61 return;
56   - [obj setValue:[NSNumber numberWithFloat:_floatValue] forKey:_key];
  62 + [obj setValue:_decimalValue forKey:_key];
57 63 }
58 64
59 65 @end
11 quickdialog/QDecimalTableViewCell.m
@@ -32,6 +32,7 @@ - (QDecimalTableViewCell *)init {
32 32 - (void)createSubviews {
33 33 _textField = [[QTextField alloc] init];
34 34 [_textField addTarget:self action:@selector(textFieldEditingChanged:) forControlEvents:UIControlEventEditingChanged];
  35 + _textField.textAlignment = UITextAlignmentRight;
35 36 _textField.borderStyle = UITextBorderStyleNone;
36 37 _textField.keyboardType = UIKeyboardTypeDecimalPad;
37 38 _textField.delegate = self;
@@ -50,7 +51,7 @@ - (void)updateTextFieldFromElement {
50 51 [_numberFormatter setMaximumFractionDigits:[self decimalElement].fractionDigits];
51 52 [_numberFormatter setMinimumFractionDigits:[self decimalElement].fractionDigits];
52 53 QDecimalElement *el = (QDecimalElement *)_entryElement;
53   - _textField.text = [_numberFormatter stringFromNumber:[NSNumber numberWithFloat:el.floatValue]];
  54 + _textField.text = [_numberFormatter stringFromNumber:el.decimalValue];
54 55 }
55 56
56 57 - (void)prepareForElement:(QEntryElement *)element inTableView:(QuickDialogTableView *)view {
@@ -60,6 +61,7 @@ - (void)prepareForElement:(QEntryElement *)element inTableView:(QuickDialogTable
60 61 }
61 62
62 63 - (void)updateElementFromTextField:(NSString *)value {
  64 + if (value !=nil) {
63 65 NSMutableString *result = [[NSMutableString alloc] init];
64 66 for (NSUInteger i = 0; i< [value length]; i++){
65 67 unichar c = [value characterAtIndex:i];
@@ -70,8 +72,11 @@ - (void)updateElementFromTextField:(NSString *)value {
70 72 }
71 73 [_numberFormatter setMaximumFractionDigits:[self decimalElement].fractionDigits];
72 74 [_numberFormatter setMinimumFractionDigits:[self decimalElement].fractionDigits];
73   - [self decimalElement].floatValue= [[_numberFormatter numberFromString:result] floatValue];
74   - [self decimalElement].floatValue = (float) (((QDecimalElement *)_entryElement).floatValue / pow(10,[self decimalElement].fractionDigits));
  75 + [self decimalElement].decimalValue= [_numberFormatter numberFromString:result];
  76 + [self decimalElement].decimalValue = [NSNumber numberWithFloat:(float) ([((QDecimalElement *)_entryElement).decimalValue floatValue] / pow(10,[self decimalElement].fractionDigits))];
  77 + } else {
  78 + [self decimalElement].decimalValue = nil;
  79 + }
75 80 }
76 81
77 82 - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)replacement {
14 quickdialog/QDistanceValueParser.h
... ... @@ -0,0 +1,14 @@
  1 +//
  2 +// QDistanceValueParser.h
  3 +// WalkWithFriends
  4 +//
  5 +// Created by John Smilanick on 6/28/12.
  6 +// Copyright (c) 2012 Jiff Inc. All rights reserved.
  7 +//
  8 +
  9 +#import <Foundation/Foundation.h>
  10 +
  11 +@interface QDistanceValueParser : NSObject <QPickerValueParser>
  12 +
  13 +
  14 +@end
43 quickdialog/QDistanceValueParser.m
... ... @@ -0,0 +1,43 @@
  1 +//
  2 +// QDistanceValueParser.m
  3 +// WalkWithFriends
  4 +//
  5 +// Created by John Smilanick on 6/28/12.
  6 +// Copyright (c) 2012 Jiff Inc. All rights reserved.
  7 +//
  8 +
  9 +#import "QDistanceValueParser.h"
  10 +
  11 +
  12 +@implementation QDistanceValueParser
  13 +
  14 +- (id)objectFromComponentsValues:(NSArray *)componentsValues {
  15 + NSNumber *number = nil;
  16 + if (componentsValues) {
  17 + NSNumber *component = [componentsValues objectAtIndex:0];
  18 + NSInteger i = [component integerValue] * 12;
  19 + component = [componentsValues objectAtIndex:1];
  20 + i += [component integerValue];
  21 + number = [NSNumber numberWithFloat:i];
  22 + }
  23 + return number;
  24 +}
  25 +
  26 +- (NSArray *)componentsValuesFromObject:(id)object {
  27 + NSArray *components = nil;
  28 + if (object) {
  29 + NSInteger inches = [object floatValue];
  30 + components = [NSArray arrayWithObjects:[NSNumber numberWithInteger:inches / 12].stringValue, [NSNumber numberWithInteger:inches % 12].stringValue, nil];
  31 + }
  32 + return components;
  33 +}
  34 +
  35 +- (NSString *)presentationOfObject:(id)object {
  36 + NSArray *componentsValues = [self componentsValuesFromObject:object];
  37 + NSString *str = nil;
  38 + if (componentsValues) {
  39 + str = [NSString stringWithFormat:@"%@'%@\"", [componentsValues objectAtIndex:0], [componentsValues objectAtIndex:1]];
  40 + }
  41 + return str;
  42 +}
  43 +@end
50 quickdialog/QDualEntryElement.h
... ... @@ -0,0 +1,50 @@
  1 +//
  2 +// QDualEntryElement.h
  3 +// WalkWithFriends
  4 +//
  5 +// Created by John Smilanick on 6/26/12.
  6 +// Copyright (c) 2012 Jiff Inc. All rights reserved.
  7 +//
  8 +
  9 +#import "QElement.h"
  10 +
  11 +@protocol QuickDialogDualEntryElementDelegate;
  12 +
  13 +@interface QDualEntryElement : QLabelElement <UITextInputTraits> {
  14 +
  15 +@private
  16 +NSString *_secondKey;
  17 +NSString *_firstPlaceholder;
  18 +NSString *_firstTextValue;
  19 +NSString *_secondPlaceholder;
  20 +NSString *_secondTextValue;
  21 +
  22 +BOOL _hiddenToolbar;
  23 +}
  24 +@property(nonatomic, retain) NSString *secondKey;
  25 +
  26 +@property (nonatomic, strong) NSString *firstTextValue;
  27 +@property (nonatomic, strong) NSString *firstPlaceholder;
  28 +@property (nonatomic, strong) NSString *secondTextValue;
  29 +@property (nonatomic, strong) NSString *secondPlaceholder;
  30 +@property (nonatomic, strong) NSString *prefix;
  31 +@property (nonatomic, strong) NSString *suffix;
  32 +@property (assign) BOOL hiddenToolbar;
  33 +
  34 +@property(nonatomic, unsafe_unretained) id<QuickDialogDualEntryElementDelegate> delegate;
  35 +
  36 +@property(nonatomic) UITextAutocapitalizationType autocapitalizationType; // default is UITextAutocapitalizationTypeSentences
  37 +@property(nonatomic) UITextAutocorrectionType autocorrectionType; // default is UITextAutocorrectionTypeDefault
  38 +@property(nonatomic) UIKeyboardType keyboardType; // default is UIKeyboardTypeDefault
  39 +@property(nonatomic) UIKeyboardAppearance keyboardAppearance; // default is UIKeyboardAppearanceDefault
  40 +@property(nonatomic) UIReturnKeyType returnKeyType; // default is UIReturnKeyDefault (See note under UIReturnKeyType enum)
  41 +@property(nonatomic) BOOL enablesReturnKeyAutomatically; // default is NO (when YES, will automatically disable return key when text widget has zero-length contents, and will automatically enable when text widget has non-zero-length contents)
  42 +@property(nonatomic,getter=isSecureTextEntry) BOOL secureTextEntry; // default is NO
  43 +@property(nonatomic, assign) BOOL clearsOnBeginEditing; // default is NO
  44 +
  45 +
  46 +- (QDualEntryElement *)init;
  47 +
  48 +- (QDualEntryElement *)initWithTitle:(NSString *)title firstValue:(NSString *)firstValue firstPlaceholder:(NSString *)firstPlaceholder secondValue:(NSString *)secondValue secondPlaceholder:(NSString *)secondPlaceholder;
  49 +@end
  50 +
83 quickdialog/QDualEntryElement.m
... ... @@ -0,0 +1,83 @@
  1 +//
  2 +// QDualEntryElement.m
  3 +// WalkWithFriends
  4 +//
  5 +// Created by John Smilanick on 6/26/12.
  6 +// Copyright (c) 2012 Jiff Inc. All rights reserved.
  7 +//
  8 +
  9 +#import "QDualEntryElement.h"
  10 +#import "QDualEntryTableViewCell.h"
  11 +
  12 +@implementation QDualEntryElement
  13 +
  14 +@synthesize secondKey;
  15 +@synthesize firstTextValue = _textFirstValue;
  16 +@synthesize firstPlaceholder = _firstPlaceholder;
  17 +@synthesize secondTextValue = _secondTextValue;
  18 +@synthesize secondPlaceholder = _secondPlaceholder;
  19 +
  20 +@synthesize prefix = _prefix;
  21 +@synthesize suffix = _suffix;
  22 +@synthesize hiddenToolbar = _hiddenToolbar;
  23 +
  24 +@synthesize delegate = _delegate;
  25 +
  26 +- (QDualEntryElement *)init {
  27 + self = [super init];
  28 + if (self){
  29 + self.autocapitalizationType = UITextAutocapitalizationTypeSentences;
  30 + self.autocorrectionType = UITextAutocorrectionTypeDefault;
  31 + self.keyboardType = UIKeyboardTypeDefault;
  32 + self.keyboardAppearance = UIKeyboardAppearanceDefault;
  33 + self.returnKeyType = UIReturnKeyDefault;
  34 + self.enablesReturnKeyAutomatically = NO;
  35 + self.secureTextEntry = NO;
  36 + }
  37 + return self;
  38 +}
  39 +
  40 +- (QDualEntryElement *)initWithTitle:(NSString *)title firstValue:(NSString *)firstValue firstPlaceholder:(NSString *)firstPlaceholder secondValue:(NSString *)secondValue secondPlaceholder:(NSString *)secondPlaceholder {
  41 + self = [self init];
  42 + if (self) {
  43 + _title = title;
  44 + _textFirstValue = firstValue;
  45 + _firstPlaceholder = firstPlaceholder;
  46 + _secondTextValue = secondValue;
  47 + _secondPlaceholder = secondPlaceholder;
  48 + }
  49 + return self;
  50 +}
  51 +
  52 +- (UITableViewCell *)getCellForTableView:(QuickDialogTableView *)tableView controller:(QuickDialogController *)controller {
  53 +
  54 + QDualEntryTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"QuickformDualEntryElement"];
  55 + if (cell==nil){
  56 + cell = [[QDualEntryTableViewCell alloc] init];
  57 + }
  58 + cell.selectionStyle = UITableViewCellSelectionStyleNone;
  59 + cell.firstTextField.enabled = YES;
  60 + cell.firstTextField.userInteractionEnabled = YES;
  61 + cell.secondTextField.enabled = YES;
  62 + cell.secondTextField.userInteractionEnabled = YES;
  63 + cell.imageView.image = self.image;
  64 + [cell prepareForElement:self inTableView:tableView];
  65 + return cell;
  66 +}
  67 +
  68 +
  69 +
  70 +#pragma mark - UITextInputTraits
  71 +
  72 +@synthesize autocorrectionType = _autocorrectionType;
  73 +@synthesize autocapitalizationType = _autocapitalizationType;
  74 +@synthesize keyboardType = _keyboardType;
  75 +@synthesize keyboardAppearance = _keyboardAppearance;
  76 +@synthesize returnKeyType = _returnKeyType;
  77 +@synthesize enablesReturnKeyAutomatically = _enablesReturnKeyAutomatically;
  78 +@synthesize secureTextEntry = _secureTextEntry;
  79 +@synthesize clearsOnBeginEditing = _clearsOnBeginEditing;
  80 +@synthesize accessoryType = _accessoryType;
  81 +
  82 +
  83 +@end
50 quickdialog/QDualEntryTableViewCell.h
... ... @@ -0,0 +1,50 @@
  1 +//
  2 +// QDualEntryTableViewCell.h
  3 +// WalkWithFriends
  4 +//
  5 +// Created by John Smilanick on 6/26/12.
  6 +// Copyright (c) 2012 Jiff Inc. All rights reserved.
  7 +//
  8 +
  9 +#import "QTableViewCell.h"
  10 +
  11 +@class QEntryElement;
  12 +@class QuickDialogTableView;
  13 +@class QTextField;
  14 +
  15 +
  16 +@interface QDualEntryTableViewCell : QTableViewCell<UITextFieldDelegate> {
  17 +
  18 + QDualEntryElement *_entryElement;
  19 + QTextField *_firstTextField;
  20 + QTextField *_secondTextField;
  21 +
  22 +@protected
  23 + __unsafe_unretained QuickDialogTableView *_quickformTableView;
  24 +}
  25 +
  26 +@property(nonatomic, strong) QTextField *firstTextField;
  27 +@property(nonatomic, strong) QTextField *secondTextField;
  28 +
  29 +- (void)updatePrevNextStatus;
  30 +
  31 +- (void)prepareForElement:(QDualEntryElement *)element inTableView:(QuickDialogTableView *)tableView;
  32 +
  33 +- (UIToolbar *)createActionBar;
  34 +
  35 +- (void)createSubviews;
  36 +
  37 +- (CGRect)calculateFrameForFirstEntryElement;
  38 +- (CGRect)calculateFrameForSecondEntryElement;
  39 +
  40 +
  41 +- (QEntryElement *)findNextElementToFocusOn;
  42 +
  43 +- (BOOL)handleActionBarDone:(UIBarButtonItem *)doneButton;
  44 +
  45 +- (QEntryElement *)findPreviousElementToFocusOn;
  46 +
  47 +- (void)recalculateEntryFieldPosition;
  48 +
  49 +
  50 +@end
331 quickdialog/QDualEntryTableViewCell.m
... ... @@ -0,0 +1,331 @@
  1 +//
  2 +// QDualEntryTableViewCell.m
  3 +// WalkWithFriends
  4 +//
  5 +// Created by John Smilanick on 6/26/12.
  6 +// Copyright (c) 2012 Jiff Inc. All rights reserved.
  7 +//
  8 +
  9 +#import "QDualEntryTableViewCell.h"
  10 +#import "QuickDialogDualEntryElementDelegate.h"
  11 +
  12 +@interface QDualEntryTableViewCell ()
  13 +- (void)handleActionBarPreviousNext:(UISegmentedControl *)control;
  14 +- (QEntryElement *)findNextElementToFocusOn;
  15 +@end
  16 +
  17 +@implementation QDualEntryTableViewCell {
  18 + UISegmentedControl *_prevNext;
  19 +}
  20 +@synthesize firstTextField = _firstTextField;
  21 +@synthesize secondTextField = _secondTextField;
  22 +
  23 +-(UIToolbar *)createActionBar {
  24 + UIToolbar *actionBar = [[UIToolbar alloc] init];
  25 + actionBar.translucent = YES;
  26 + [actionBar sizeToFit];
  27 + actionBar.barStyle = UIBarStyleBlackTranslucent;
  28 +
  29 + UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Done", @"")
  30 + style:UIBarButtonItemStyleDone target:self
  31 + action:@selector(handleActionBarDone:)];
  32 +
  33 + _prevNext = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:NSLocalizedString(@"Previous", @""), NSLocalizedString(@"Next", @""), nil]];
  34 + _prevNext.momentary = YES;
  35 + _prevNext.segmentedControlStyle = UISegmentedControlStyleBar;
  36 + _prevNext.tintColor = actionBar.tintColor;
  37 + [_prevNext addTarget:self action:@selector(handleActionBarPreviousNext:) forControlEvents:UIControlEventValueChanged];
  38 + UIBarButtonItem *prevNextWrapper = [[UIBarButtonItem alloc] initWithCustomView:_prevNext];
  39 + UIBarButtonItem *flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
  40 + [actionBar setItems:[NSArray arrayWithObjects:prevNextWrapper, flexible, doneButton, nil]];
  41 +
  42 + return actionBar;
  43 +}
  44 +
  45 +- (void)createSubviews {
  46 + _firstTextField = [[QTextField alloc] init];
  47 + _firstTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
  48 + _firstTextField.borderStyle = UITextBorderStyleNone;
  49 + _firstTextField.delegate = self;
  50 + _firstTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
  51 + _firstTextField.autoresizingMask = ( UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
  52 + [_firstTextField addTarget:self action:@selector(textFieldEditingChanged:) forControlEvents:UIControlEventEditingChanged];
  53 + [self.contentView addSubview:_firstTextField];
  54 +
  55 + _secondTextField = [[QTextField alloc] init];
  56 + _secondTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
  57 + _secondTextField.borderStyle = UITextBorderStyleNone;
  58 + _secondTextField.delegate = self;
  59 + _secondTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
  60 + _secondTextField.autoresizingMask = ( UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
  61 + [_secondTextField addTarget:self action:@selector(textFieldEditingChanged:) forControlEvents:UIControlEventEditingChanged];
  62 + [self.contentView addSubview:_secondTextField];
  63 + [self setNeedsLayout];
  64 +}
  65 +
  66 +- (QDualEntryTableViewCell *)init {
  67 + self = [self initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"QuickformDualEntryElement"];
  68 + if (self!=nil){
  69 + self.selectionStyle = UITableViewCellSelectionStyleNone;
  70 +
  71 + [self createSubviews];
  72 + }
  73 + return self;
  74 +}
  75 +
  76 +- (CGRect)calculateFrameForFirstEntryElement {
  77 + int extra = (self.firstTextField.clearButtonMode == UITextFieldViewModeNever) ? 15 :10;
  78 + if (_entryElement.title == NULL && _entryElement.image==NULL) {
  79 + // untested - John
  80 + return CGRectMake(10,10,self.contentView.frame.size.width/2-2*10-2*extra, self.frame.size.height-20);
  81 + }
  82 + if (_entryElement.title == NULL && _entryElement.image!=NULL){
  83 + // untested - John
  84 + return CGRectMake( _entryElement.image.size.width, 10, self.contentView.frame.size.width-2*10-_entryElement.image.size.width/2-2*extra , self.frame.size.height-20);
  85 + }
  86 + CGFloat totalWidth = self.contentView.frame.size.width;
  87 + CGFloat titleWidth = 0;
  88 +
  89 + if (CGRectEqualToRect(CGRectZero, _entryElement.parentSection.entryPosition)) {
  90 + for (QElement *el in _entryElement.parentSection.elements){
  91 + if ([el isKindOfClass:[QEntryElement class]]){
  92 + CGFloat fontSize = self.textLabel.font.pointSize == 0? 17 : self.textLabel.font.pointSize;
  93 + CGSize size = [((QEntryElement *)el).title sizeWithFont:[self.textLabel.font fontWithSize:fontSize] forWidth:CGFLOAT_MAX lineBreakMode:UILineBreakModeWordWrap] ;
  94 + if (size.width>titleWidth)
  95 + titleWidth = size.width;
  96 + }
  97 + }
  98 + _entryElement.parentSection.entryPosition = CGRectMake(titleWidth+20,10,floor((totalWidth-titleWidth-20-2*extra) / 2), self.frame.size.height-20);
  99 + }
  100 +
  101 + return _entryElement.parentSection.entryPosition;
  102 +}
  103 +
  104 +- (CGRect)calculateFrameForSecondEntryElement {
  105 + CGRect firstFrame = [self calculateFrameForFirstEntryElement];
  106 + return CGRectMake(CGRectGetMaxX(firstFrame) + 10, firstFrame.origin.y, firstFrame.size.width, firstFrame.size.height);
  107 +}
  108 +
  109 +- (void)updatePrevNextStatus {
  110 + [_prevNext setEnabled:[self findPreviousElementToFocusOn]!=nil forSegmentAtIndex:0];
  111 + [_prevNext setEnabled:[self findNextElementToFocusOn]!=nil forSegmentAtIndex:1];
  112 +}
  113 +
  114 +- (void)prepareForElement:(QDualEntryElement *)element inTableView:(QuickDialogTableView *)tableView{
  115 + self.textLabel.text = element.title;
  116 +
  117 + _quickformTableView = tableView;
  118 + _entryElement = element;
  119 + _firstTextField.text = _entryElement.firstTextValue;
  120 + _firstTextField.placeholder = _entryElement.firstPlaceholder;
  121 + _firstTextField.prefix = _entryElement.prefix;
  122 + _firstTextField.suffix = _entryElement.suffix;
  123 +
  124 + _firstTextField.autocapitalizationType = _entryElement.autocapitalizationType;
  125 + _firstTextField.autocorrectionType = _entryElement.autocorrectionType;
  126 + _firstTextField.keyboardType = _entryElement.keyboardType;
  127 + _firstTextField.keyboardAppearance = _entryElement.keyboardAppearance;
  128 + _firstTextField.secureTextEntry = _entryElement.secureTextEntry;
  129 + _firstTextField.clearsOnBeginEditing = _entryElement.clearsOnBeginEditing;
  130 +
  131 + _firstTextField.returnKeyType = _entryElement.returnKeyType;
  132 + _firstTextField.enablesReturnKeyAutomatically = _entryElement.enablesReturnKeyAutomatically;
  133 +
  134 + _secondTextField.text = _entryElement.secondTextValue;
  135 + _secondTextField.placeholder = _entryElement.secondPlaceholder;
  136 + _secondTextField.prefix = _entryElement.prefix;
  137 + _secondTextField.suffix = _entryElement.suffix;
  138 +
  139 + _secondTextField.autocapitalizationType = _entryElement.autocapitalizationType;
  140 + _secondTextField.autocorrectionType = _entryElement.autocorrectionType;
  141 + _secondTextField.keyboardType = _entryElement.keyboardType;
  142 + _secondTextField.keyboardAppearance = _entryElement.keyboardAppearance;
  143 + _secondTextField.secureTextEntry = _entryElement.secureTextEntry;
  144 + _secondTextField.clearsOnBeginEditing = _entryElement.clearsOnBeginEditing;
  145 +
  146 + _secondTextField.returnKeyType = _entryElement.returnKeyType;
  147 + _secondTextField.enablesReturnKeyAutomatically = _entryElement.enablesReturnKeyAutomatically;
  148 +
  149 + self.accessoryType = _entryElement.accessoryType;
  150 +
  151 + if (_entryElement.hiddenToolbar){
  152 + _firstTextField.inputAccessoryView = nil;
  153 + _secondTextField.inputAccessoryView = nil;
  154 + } else {
  155 + _firstTextField.inputAccessoryView = [self createActionBar];
  156 + _secondTextField.inputAccessoryView = [self createActionBar];
  157 + }
  158 +
  159 + [self updatePrevNextStatus];
  160 +}
  161 +
  162 +- (void)layoutSubviews {
  163 + [super layoutSubviews];
  164 + [self recalculateEntryFieldPosition];
  165 +}
  166 +
  167 +
  168 +-(void)recalculateEntryFieldPosition {
  169 + _entryElement.parentSection.entryPosition = CGRectZero;
  170 + _firstTextField.frame = [self calculateFrameForFirstEntryElement];
  171 + _secondTextField.frame = [self calculateFrameForSecondEntryElement];
  172 + CGRect labelFrame = self.textLabel.frame;
  173 + self.textLabel.frame = CGRectMake(labelFrame.origin.x, labelFrame.origin.y,
  174 + _entryElement.parentSection.entryPosition.origin.x-20, labelFrame.size.height);
  175 +
  176 +}
  177 +
  178 +- (void)prepareForReuse {
  179 + _quickformTableView = nil;
  180 + _entryElement = nil;
  181 + _firstTextField.textAlignment = UITextAlignmentRight;
  182 + _secondTextField.textAlignment = UITextAlignmentRight;
  183 +}
  184 +
  185 +- (void)textFieldEditingChanged:(UITextField *)textFieldEditingChanged {
  186 + if (textFieldEditingChanged == _firstTextField) {
  187 + _entryElement.firstTextValue = _firstTextField.text;
  188 + } else {
  189 + _entryElement.secondTextValue = _secondTextField.text;
  190 + }
  191 +
  192 + if(_entryElement && _entryElement.delegate && [_entryElement.delegate respondsToSelector:@selector(QEntryEditingChangedForElement:andCell:)]){
  193 + [_entryElement.delegate QEntryEditingChangedForElement:_entryElement andCell:self];
  194 + }
  195 +}
  196 +
  197 +- (void)textFieldDidBeginEditing:(UITextField *)textField {
  198 +// dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 50 * USEC_PER_SEC);
  199 +// dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
  200 +// [_quickformTableView scrollToRowAtIndexPath:[_quickformTableView indexForElement:_entryElement] atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
  201 +// });
  202 +
  203 +
  204 + if (textField.returnKeyType == UIReturnKeyDefault) {
  205 + UIReturnKeyType returnType = ([self findNextElementToFocusOn]!=nil) ? UIReturnKeyNext : UIReturnKeyDone;
  206 + textField.returnKeyType = returnType;
  207 + }
  208 +
  209 + if(_entryElement && _entryElement.delegate && [_entryElement.delegate respondsToSelector:@selector(QEntryDidBeginEditingElement:andCell:)]){
  210 + [_entryElement.delegate QEntryDidBeginEditingElement:_entryElement andCell:self];
  211 + }
  212 +}
  213 +
  214 +- (void)textFieldDidEndEditing:(UITextField *)textField {
  215 + if (textField == _firstTextField) {
  216 + _entryElement.firstTextValue = _firstTextField.text;
  217 + } else {
  218 + _entryElement.secondTextValue = _secondTextField.text;
  219 + }
  220 + if(_entryElement && _entryElement.delegate && [_entryElement.delegate respondsToSelector:@selector(QEntryDidEndEditingElement:andCell:)]){
  221 + [_entryElement.delegate QEntryDidEndEditingElement:_entryElement andCell:self];
  222 + }
  223 +}
  224 +
  225 +- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  226 + if(_entryElement && _entryElement.delegate && [_entryElement.delegate respondsToSelector:@selector(QEntryShouldChangeCharactersInRangeForElement:andCell:)]){
  227 + return [_entryElement.delegate QEntryShouldChangeCharactersInRangeForElement:_entryElement andCell:self];
  228 + }
  229 + return YES;
  230 +}
  231 +
  232 +
  233 +- (BOOL)textFieldShouldReturn:(UITextField *)textField {
  234 +
  235 + QEntryElement *element = [self findNextElementToFocusOn];
  236 + if (element!=nil){
  237 + UITableViewCell *cell = [_quickformTableView cellForElement:element];
  238 + if (cell!=nil){
  239 + [cell becomeFirstResponder];
  240 + }
  241 + } else {
  242 + [textField resignFirstResponder];
  243 + }
  244 +
  245 + if(_entryElement && _entryElement.delegate && [_entryElement.delegate respondsToSelector:@selector(QEntryShouldReturnForElement:andCell:)]){
  246 + return [_entryElement.delegate QEntryShouldReturnForElement:_entryElement andCell:self];
  247 + }
  248 +
  249 + return YES;
  250 +}
  251 +
  252 +- (void) handleActionBarPreviousNext:(UISegmentedControl *)control {
  253 + QEntryElement *element;
  254 + const BOOL isNext = control.selectedSegmentIndex == 1;
  255 + if (isNext){
  256 + element = [self findNextElementToFocusOn];
  257 + } else {
  258 + element = [self findPreviousElementToFocusOn];
  259 + }
  260 + if (element!=nil){
  261 + UITableViewCell *cell = [_quickformTableView cellForElement:element];
  262 + if (cell!=nil){
  263 + [cell becomeFirstResponder];
  264 + } else {
  265 + dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 50 * USEC_PER_SEC);
  266 + dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
  267 + UITableViewCell *c = [_quickformTableView cellForElement:element];
  268 + if (c!=nil){
  269 + [c becomeFirstResponder];
  270 + }
  271 + });
  272 + }
  273 + }
  274 +}
  275 +
  276 +- (BOOL)handleActionBarDone:(UIBarButtonItem *)doneButton {
  277 + [self endEditing:YES];
  278 + [self endEditing:NO];
  279 + [_firstTextField resignFirstResponder];
  280 + [_secondTextField resignFirstResponder];
  281 +
  282 + [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
  283 +
  284 + if(_entryElement && _entryElement.delegate && [_entryElement.delegate respondsToSelector:@selector(QEntryMustReturnForElement:andCell:)]){
  285 + [_entryElement.delegate QEntryMustReturnForElement:_entryElement andCell:self];
  286 + }
  287 +
  288 + return NO;
  289 +}
  290 +
  291 +- (BOOL)becomeFirstResponder {
  292 + [_firstTextField becomeFirstResponder];
  293 + return YES;
  294 +}
  295 +
  296 +- (BOOL)resignFirstResponder {
  297 + return YES;
  298 +}
  299 +
  300 +- (QEntryElement *)findPreviousElementToFocusOn {
  301 + QEntryElement *previousElement = nil;
  302 + for (QSection *section in _entryElement.parentSection.rootElement.sections) {
  303 + for (QElement * e in section.elements){
  304 + if (e == _entryElement) {
  305 + return previousElement;
  306 + }
  307 + else if ([e isKindOfClass:[QEntryElement class]]){
  308 + previousElement = (QEntryElement *)e;
  309 + }
  310 + }
  311 + }
  312 + return nil;
  313 +}
  314 +
  315 +- (QEntryElement *)findNextElementToFocusOn {
  316 + BOOL foundSelf = NO;
  317 + for (QSection *section in _entryElement.parentSection.rootElement.sections) {
  318 + for (QElement * e in section.elements){
  319 + if (e == _entryElement) {
  320 + foundSelf = YES;
  321 + }
  322 + else if (foundSelf && [e isKindOfClass:[QEntryElement class]]){
  323 + return (QEntryElement *) e;
  324 + }
  325 + }
  326 + }
  327 + return nil;
  328 +}
  329 +
  330 +
  331 +@end
5 quickdialog/QEntryTableViewCell.m
@@ -106,7 +106,8 @@ - (void)prepareForElement:(QEntryElement *)element inTableView:(QuickDialogTable
106 106 _textField.placeholder = _entryElement.placeholder;
107 107 _textField.prefix = _entryElement.prefix;
108 108 _textField.suffix = _entryElement.suffix;
109   -
  109 +
  110 + _textField.textAlignment = UITextAlignmentRight;
110 111 _textField.autocapitalizationType = _entryElement.autocapitalizationType;
111 112 _textField.autocorrectionType = _entryElement.autocorrectionType;
112 113 _textField.keyboardType = _entryElement.keyboardType;
@@ -146,7 +147,7 @@ -(void)recalculateEntryFieldPosition {
146 147 - (void)prepareForReuse {
147 148 _quickformTableView = nil;
148 149 _entryElement = nil;
149   - _textField.textAlignment = UITextAlignmentLeft;
  150 + _textField.textAlignment = UITextAlignmentRight;
150 151 }
151 152
152 153 - (void)textFieldEditingChanged:(UITextField *)textFieldEditingChanged {
18 quickdialog/QImageElement.h
... ... @@ -0,0 +1,18 @@
  1 +//
  2 +// QImageElement.h
  3 +// WalkWithFriends
  4 +//
  5 +// Created by John Smilanick on 7/19/12.
  6 +// Copyright (c) 2012 Jiff Inc. All rights reserved.
  7 +//
  8 +
  9 +#import "QLabelElement.h"
  10 +
  11 +@interface QImageElement : QLabelElement
  12 +
  13 +@property (nonatomic, strong) UIImage *placeholderImage;
  14 +@property (nonatomic, assign) CGSize imageSize;
  15 +
  16 +- (QImageElement *)initWithTitle:(NSString *)title image:(UIImage*)anImage;
  17 +- (QImageElement *)initWithTitle:(NSString *)title image:(UIImage*)anImage placeholderImage:(UIImage*)pImage;
  18 +@end
85 quickdialog/QImageElement.m
... ... @@ -0,0 +1,85 @@
  1 +//
  2 +// QImageElement.m
  3 +// WalkWithFriends
  4 +//
  5 +// Created by John Smilanick on 7/19/12.
  6 +// Copyright (c) 2012 Jiff Inc. All rights reserved.
  7 +//
  8 +
  9 +#import "QImageElement.h"
  10 +#import "QImageTableViewCell.h"
  11 +
  12 +@implementation QImageElement
  13 +
  14 +@synthesize placeholderImage;
  15 +@synthesize imageSize;
  16 +
  17 +- (QImageElement *)init {
  18 + self = [super init];
  19 + if (self){
  20 + self.imageSize = CGSizeMake(64,64);
  21 + }
  22 + return self;
  23 +}
  24 +
  25 +- (QImageElement *)initWithTitle:(NSString *)title image:(UIImage*)anImage {
  26 + self = [self init];
  27 + if (self) {
  28 + self.title = title;
  29 + self.image = anImage;
  30 + }
  31 + return self;
  32 +}
  33 +
  34 +- (QImageElement *)initWithTitle:(NSString *)title image:(UIImage*)anImage placeholderImage:(UIImage*)pImage {
  35 + self = [self initWithTitle:title image:anImage];
  36 + if (self) {
  37 + self.placeholderImage = pImage;
  38 + }
  39 + return self;
  40 +}
  41 +
  42 +- (UITableViewCell *)getCellForTableView:(QuickDialogTableView *)tableView controller:(QuickDialogController *)controller {
  43 +
  44 + QImageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"QuickformImageElement"];
  45 + if (cell==nil){
  46 + cell = [[QImageTableViewCell alloc] init];
  47 + }
  48 +// cell.selectionStyle = UITableViewCellSelectionStyleNone;
  49 + [cell prepareForElement:self inTableView:tableView];
  50 + return cell;
  51 +}
  52 +
  53 +- (CGFloat)getRowHeightForTableView:(QuickDialogTableView *)tableView {
  54 + return imageSize.height+8;
  55 +}
  56 +
  57 +- (void)selected:(QuickDialogTableView *)tableView controller:(QuickDialogController *)controller indexPath:(NSIndexPath *)indexPath {
  58 + UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
  59 + QImageTableViewCell *cell = (QImageTableViewCell*)[tableView cellForRowAtIndexPath:indexPath];
  60 + imagePicker.delegate = cell;
  61 + imagePicker.allowsEditing = YES;
  62 + if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
  63 + imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
  64 + if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront]) {
  65 + imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
  66 + }
  67 + } else if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]){
  68 + imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
  69 + } else {
  70 + imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
  71 + }
  72 + imagePicker.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
  73 + [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
  74 + [controller presentViewController:imagePicker animated:YES completion:^(void) {
  75 +
  76 + }];
  77 +
  78 +// [super selected:tableView controller:controller indexPath:indexPath];
  79 + [tableView deselectRowAtIndexPath:indexPath animated:YES];
  80 + [self handleElementSelected:controller];
  81 +}
  82 +
  83 +
  84 +
  85 +@end
23 quickdialog/QImageTableViewCell.h
... ... @@ -0,0 +1,23 @@
  1 +//
  2 +// QImageTableViewCell.h
  3 +// WalkWithFriends
  4 +//
  5 +// Created by John Smilanick on 7/19/12.
  6 +// Copyright (c) 2012 Jiff Inc. All rights reserved.
  7 +//
  8 +
  9 +#import "QTableViewCell.h"
  10 +
  11 +@class QImageElement;
  12 +
  13 +@interface QImageTableViewCell : QTableViewCell <UINavigationControllerDelegate,UIImagePickerControllerDelegate> {
  14 + QImageElement *_entryElement;
  15 +@protected
  16 + __unsafe_unretained QuickDialogTableView *_quickformTableView;
  17 +}
  18 +
  19 +@property (nonatomic, assign) CGSize imageSize;
  20 +@property (nonatomic, strong) IBOutlet UIImageView *contentImageView;
  21 +
  22 +- (void)prepareForElement:(QImageElement *)element inTableView:(QuickDialogTableView *)tableView;
  23 +@end
91 quickdialog/QImageTableViewCell.m
... ... @@ -0,0 +1,91 @@
  1 +//
  2 +// QImageTableViewCell.m
  3 +// WalkWithFriends
  4 +//
  5 +// Created by John Smilanick on 7/19/12.
  6 +// Copyright (c) 2012 Jiff Inc. All rights reserved.
  7 +//
  8 +
  9 +#import "QImageTableViewCell.h"
  10 +#import "QImageElement.h"
  11 +
  12 +@implementation QImageTableViewCell
  13 +
  14 +@synthesize contentImageView;
  15 +@synthesize imageSize;
  16 +
  17 +- (QImageTableViewCell *)init {
  18 + self = [self initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"QuickformImageElement"];
  19 + if (self!=nil){
  20 + self.selectionStyle = UITableViewCellSelectionStyleNone;
  21 +
  22 + [self createSubviews];
  23 + }
  24 + return self;
  25 +}
  26 +
  27 +- (void)createSubviews {
  28 + self.contentImageView = [[UIImageView alloc] initWithImage:nil];
  29 + self.contentImageView.contentMode = UIViewContentModeScaleAspectFill;
  30 + [self.contentView addSubview:self.contentImageView];
  31 + [self setNeedsLayout];
  32 +}
  33 +
  34 +- (void)prepareForElement:(QImageElement *)element inTableView:(QuickDialogTableView *)tableView{
  35 + _quickformTableView = tableView;
  36 + _entryElement = element;
  37 +
  38 + self.textLabel.text = element.title;
  39 + self.imageSize = element.imageSize;
  40 + if (element.image) {
  41 + self.contentImageView.image = element.image;
  42 + } else if (element.placeholderImage) {
  43 + self.contentImageView.image = element.placeholderImage;
  44 + }
  45 +}
  46 +
  47 +- (void)layoutSubviews {
  48 + [super layoutSubviews];
  49 + [self recalculateImagePosition];
  50 +}
  51 +
  52 +-(void)recalculateImagePosition {
  53 + CGRect imageFrame = CGRectMake(0, 4, imageSize.width, imageSize.height);
  54 + imageFrame.origin.x = self.contentView.frame.size.width - imageFrame.size.width - 5;
  55 + self.contentImageView.frame = imageFrame;
  56 +}
  57 +
  58 +- (void)prepareForReuse {
  59 + self.contentImageView.image = nil;
  60 +}
  61 +
  62 +- (BOOL)becomeFirstResponder {
  63 + return NO;
  64 +}
  65 +
  66 +- (BOOL)resignFirstResponder {
  67 + return YES;
  68 +}
  69 +
  70 +/*********************************************************************************/
  71 +#pragma mark - UIImagePickerControllerDelegate Methods
  72 +/*********************************************************************************/
  73 +
  74 +- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
  75 +{
  76 + [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
  77 + [picker dismissViewControllerAnimated:YES completion:nil];
  78 + UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
  79 +
  80 + _entryElement.image = image;
  81 +// [self prepareForElement:_entryElement inTableView:_quickformTableView];
  82 + [self setNeedsDisplay];
  83 +}
  84 +
  85 +- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
  86 +{
  87 + [picker dismissViewControllerAnimated:YES completion:nil];
  88 + [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
  89 +}
  90 +
  91 +@end
4 quickdialog/QuickDialog.h
@@ -49,6 +49,10 @@
49 49 #import "QSegmentedElement.h"
50 50 #import "QMultilineTextViewController.h"
51 51 #import "QMultilineElement.h"
  52 +#import "QDualEntryElement.h"
  53 +#import "QBetterSegmentedElement.h"
  54 +#import "QDistanceValueParser.h"
  55 +#import "QImageElement.h"
52 56
53 57 #import "QuickDialogStyleProvider.h"
54 58 #import "QuickDialogEntryElementDelegate.h"
16 quickdialog/QuickDialogDualEntryElementDelegate.h
... ... @@ -0,0 +1,16 @@
  1 +#import <Foundation/Foundation.h>