├── .gitignore ├── Twitter ├── LWETUserDB.xcdatamodel │ ├── elements │ └── layout ├── LWETAuthenticationViewProtocol.h ├── LWETRequestDelegate.h ├── LWETDefaultAuthenticationViewController.h ├── LWETXAuthViewProtocol.h ├── LWETUserDB.h ├── LWETDelegates.h ├── LWETUser.h ├── LWETUser.m ├── LWETwitterOAuth.h ├── LWETwitterEngine.h └── LWETDefaultAuthenticationViewController.m ├── .gitmodules ├── Core ├── LWEError.h ├── LWEError.m ├── LWECrashUtils.h ├── LWELocalNotifications.h ├── LWEMacros.h ├── LWEDebug.h ├── LWERetinaUtils.m ├── LWERetinaUtils.h ├── LWEAnalytics.h ├── LWEFile.h ├── LWECrashUtils.m ├── LWELocalNotifications.m ├── LWEImageUtils.h └── LWEAnalytics.m ├── Categories ├── NSString+LWEExtensions.h ├── NSURL+LWEUtilities.h ├── UIWebView+LWENoBounces.h ├── NSDate+LWEUtilities.h ├── NSArray+FindNearestIndexInOtherArray.h ├── NSBlock+PerformWithDelay.h ├── NSFetchedResultsController+MultibyteSectionIndexes.h ├── NSBlock+PerformWithDelay.m ├── UIScrollView+LWEUtilities.h ├── NSDate+LWEUtilities.m ├── NSArray+LWEBlocks.h ├── NSString+LWEExtensions.m ├── UIBarButtonItem+LWEAdditions.h ├── UILabel+LWEUtilities.h ├── NSArray+LWEBlocks.m ├── UIWebView+LWENoBounces.m ├── NSString+LWEResolutionHelpers.h ├── NSArray+LWEEnums.m ├── UIColor+LWEUtilities.h ├── UIBarButtonItem+LWEAdditions.m ├── NSFetchedResultsController+MultibyteSectionIndexes.m ├── NSString+LWEResolutionHelpers.m ├── NSURL+LWEUtilities.m ├── NSArray+LWEEnums.h ├── UIScrollView+LWEUtilities.m ├── UILabel+LWEUtilities.m ├── NSString+LWETextValidator.m ├── NSArray+FindNearestIndexInOtherArray.m ├── NSString+LWETextValidator.h └── UIColor+LWEUtilities.m ├── README ├── UI ├── Views │ ├── LWETooltipView │ │ ├── LWERoundedRectView.h │ │ ├── LWETooltipConstants.h │ │ ├── LWETooltipParams.m │ │ ├── LWECalloutView.h │ │ ├── LWETooltipView.h │ │ ├── LWERoundedRectView.m │ │ ├── LWETooltipParams.h │ │ └── LWETooltipViewOld.h │ ├── LWELoadingView.h │ ├── LWEFormDatePickerField.h │ ├── LWECloseButtonView.h │ ├── LWEFormDatePickerField.m │ ├── LWEFormView.h │ ├── LWECloseButtonView.m │ └── LWELoadingView.m ├── LWEViewAnimationUtils.h ├── LWEUITableUtils.h ├── Controllers │ ├── LWEPagingScrollViewDatasource.m │ └── LWEPagingScrollViewDatasource.h ├── LWEUIAlertView.h ├── LWEViewAnimationUtils.m ├── LWEUITableUtils.m └── LWEUIAlertView.m ├── Network ├── LWES3Package.h ├── LWENetworkUtils.h ├── LWEDecompressor.h ├── LWELongRunningTaskProtocol.h ├── LWES3Package.m ├── LWEPackage.h ├── LWEPackage.m └── LWEPackageDownloader.h ├── Keychain ├── MTKeychainWrapper.h └── KeychainItemWrapper.h └── Data ├── LWEDatabase.h └── LWECoreData.h /.gitignore: -------------------------------------------------------------------------------- 1 | LWETools.h 2 | -------------------------------------------------------------------------------- /Twitter/LWETUserDB.xcdatamodel/elements: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LongWeekend/Long-Weekend-Dev-Tools/HEAD/Twitter/LWETUserDB.xcdatamodel/elements -------------------------------------------------------------------------------- /Twitter/LWETUserDB.xcdatamodel/layout: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LongWeekend/Long-Weekend-Dev-Tools/HEAD/Twitter/LWETUserDB.xcdatamodel/layout -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "External/json-framework"] 2 | path = External/json-framework 3 | url = git://github.com/stig/json-framework.git 4 | [submodule "External/Reachability"] 5 | path = External/Reachability 6 | url = git@github.com:moneytree/Reachability.git 7 | -------------------------------------------------------------------------------- /Core/LWEError.h: -------------------------------------------------------------------------------- 1 | // LWEError.h 2 | #import 3 | 4 | extern NSString * const LWEErrorDomain; 5 | 6 | @interface NSError (LWEAdditions) 7 | 8 | + (NSError *) errorWithCode:(NSInteger)code localizedDescription:(NSString*)reason; 9 | 10 | @end -------------------------------------------------------------------------------- /Categories/NSString+LWEExtensions.h: -------------------------------------------------------------------------------- 1 | // NSString+LWEExtensions.h 2 | 3 | #import 4 | 5 | 6 | @interface NSString (LWEExtensions) 7 | 8 | //! Returns YES if the receiver is not nil and is not only whitespace 9 | - (BOOL) isNotBlank; 10 | - (NSString*) MD5; 11 | - (NSString *) urlEncodeUsingEncoding:(NSStringEncoding)encoding; 12 | @end 13 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Welcome to the Long Weekend Dev Tools 2 | ===================================== 3 | 4 | Hi, we're Long Weekend. 5 | 6 | Sure, there are lots of frameworks out there like Three20, Touch-something-or-other, and so on - but we developed our own code-saving helper classes and decided to share them with the 'net. 7 | 8 | This is maintained by Mark, Ross, and/or Paul of LWE: 9 | 10 | http://longweekendmobile.com/ 11 | -------------------------------------------------------------------------------- /Core/LWEError.m: -------------------------------------------------------------------------------- 1 | #import "LWEError.h" 2 | 3 | NSString * const LWEErrorDomain = @"LWEErrorDomain"; 4 | 5 | @implementation NSError (LWEAdditions) 6 | 7 | + (NSError *) errorWithCode:(NSInteger)code localizedDescription:(NSString*)reason 8 | { 9 | NSDictionary *userInfo = [NSDictionary dictionaryWithObject:reason forKey:NSLocalizedDescriptionKey]; 10 | return [NSError errorWithDomain:LWEErrorDomain code:code userInfo:userInfo]; 11 | } 12 | 13 | @end -------------------------------------------------------------------------------- /Twitter/LWETAuthenticationViewProtocol.h: -------------------------------------------------------------------------------- 1 | // 2 | // LWETAuthenticationViewProtocol.h 3 | // TweetSimulationWithLWE 4 | // 5 | // Created by Rendy Pranata on 18/07/10. 6 | // Copyright 2010 Long Weekend LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "LWETDelegates.h" 12 | 13 | @protocol LWETAuthenticationViewProtocol 14 | @required 15 | - (UIWebView *)webView; 16 | - (void)setDelegate:(id )aDelegate; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /UI/Views/LWETooltipView/LWERoundedRectView.h: -------------------------------------------------------------------------------- 1 | // 2 | // RoundedRectView.h 3 | // 4 | // Created by Jeff LaMarche on 11/13/08. 5 | 6 | #import 7 | #import "LWETooltipConstants.h" 8 | 9 | @interface LWERoundedRectView : UIView 10 | { 11 | UIColor *strokeColor; 12 | UIColor *rectColor; 13 | CGFloat strokeWidth; 14 | CGFloat cornerRadius; 15 | CGSize shadowOffset; 16 | } 17 | @property (nonatomic, retain) UIColor *strokeColor; 18 | @property (nonatomic, retain) UIColor *rectColor; 19 | @property CGFloat strokeWidth; 20 | @property CGSize shadowOffset; 21 | @property CGFloat cornerRadius; 22 | @end 23 | -------------------------------------------------------------------------------- /UI/Views/LWELoadingView.h: -------------------------------------------------------------------------------- 1 | // 2 | // LWELoadingView.h 3 | // jFlash 4 | // 5 | // Created by Rendy Pranata on 29/07/10. 6 | // Copyright 2010 Long Weekend LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #define DEFAULT_LABEL_WIDTH 280.0 12 | #define DEFAULT_LABEL_HEIGHT 50.0 13 | #define DEFAULT_OFFSET_WIDTH 2.0 14 | #define DEFAULT_OFFSET_HEIGHT 10.0 15 | 16 | @interface LWELoadingView : UIView 17 | { 18 | } 19 | 20 | + (id)loadingView:(UIView *)aSuperview withText:(NSString *)text; 21 | + (id)loadingView:(UIView *)aSuperview withText:(NSString *)text calculateNavigationBar:(BOOL)calculateNavigationBar; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /Twitter/LWETRequestDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // LWETRequestDelegate.h 3 | // TweetSimulationWithLWE 4 | // 5 | // Created by Rendy Pranata on 18/07/10. 6 | // Copyright 2010 Long Weekend LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | /** 12 | * This request delegate is the protocol that has to be conformed to, as a twitter engine 13 | * request delegate. All of the request given to the twitter engine, the result (whether it fails) 14 | * or succeed, it will goes in these methods. 15 | * 16 | */ 17 | @protocol LWETRequestDelegate 18 | @optional 19 | - (void)didFinishProcessWithData:(NSData *)data; 20 | - (void)didFailedWithError:(NSError *) error; 21 | - (void)didFinishAuth; 22 | - (void)didFailedAuth:(NSError *)error; 23 | @end -------------------------------------------------------------------------------- /Twitter/LWETDefaultAuthenticationViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // LWETDefaultAuthenticationViewController.h 3 | // TrialConsumerOAuthforIPhone 4 | // 5 | // Created by Rendy Pranata on 15/07/10. 6 | // Copyright 2010 Long Weekend LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LWETAuthenticationViewProtocol.h" 11 | 12 | @interface LWETDefaultAuthenticationViewController : UIViewController 13 | { 14 | id delegate; 15 | UIWebView *webView; 16 | UIBarButtonItem *_doneBtn; 17 | UIBarButtonItem *_cancelBtn; 18 | } 19 | 20 | @property (nonatomic, retain) id delegate; 21 | @property (nonatomic, retain) IBOutlet UIWebView *webView; 22 | 23 | -(IBAction) doneButtonTouchedUp:(id)sender; 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /UI/Views/LWEFormDatePickerField.h: -------------------------------------------------------------------------------- 1 | // 2 | // LWEFormDatePickerField.h 3 | // Swinburne 4 | // 5 | // Created by Mark Makdad on 7/26/11. 6 | // Copyright 2011 th. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | /** 12 | * Custom subclass that replaces the standard keyboard of 13 | * a UITextField and replaces it with a UIDatePicker 14 | */ 15 | @interface LWEFormDatePickerField : UITextField 16 | 17 | - (void) setDate:(NSDate*)date animated:(BOOL)animated; 18 | 19 | @property (retain) NSDate *maximumDate; 20 | @property (retain) NSDate *minimumDate; 21 | @property (retain) NSDate *date; 22 | 23 | @property (retain) UIBarButtonItem *doneButton; 24 | 25 | // We need to re-define these as read-write (they are readonly properties on UIResponder) 26 | @property (readwrite, retain) UIView *inputView; 27 | @property (readwrite, retain) UIView *inputAccessoryView; 28 | 29 | @end -------------------------------------------------------------------------------- /UI/Views/LWECloseButtonView.h: -------------------------------------------------------------------------------- 1 | // 2 | // LWECloseButtonView.h 3 | // jFlash 4 | // 5 | // Created by Mark Makdad on 12/12/11. 6 | // Copyright (c) 2011 Long Weekend LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol LWECloseButtonViewDelegate 12 | @required 13 | - (void) dismiss; 14 | @end 15 | 16 | // The width in points of the border around the view 17 | #define CLOSE_BUTTON_VIEW_BORDER_WIDTH 1.5f 18 | 19 | // The % (between 0-1, where 1 = 100%) of the view that is a margin around the X at the center 20 | // This value seems to be very sensitive between .25-.4 21 | #define CLOSE_BUTTON_VIEW_X_SIZE 0.315f 22 | 23 | // A CGSize saying how far the shadow should go 24 | #define CLOSE_BUTTON_SHADOW_OFFSET CGSizeMake(2.0f, 2.0f) 25 | 26 | // Blur value for the shadow. 27 | #define CLOSE_BUTTON_SHADOW_BLUR 0.5f 28 | 29 | // Stroke width of the "X" 30 | #define CLOSE_BUTTON_X_WIDTH 3.0f 31 | 32 | @interface LWECloseButtonView : UIView 33 | 34 | @property (assign) IBOutlet id delegate; 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /Twitter/LWETXAuthViewProtocol.h: -------------------------------------------------------------------------------- 1 | // 2 | // LWETXAuthViewProtocol.h 3 | // jFlash 4 | // 5 | // Created by Rendy Pranata on 21/07/10. 6 | // Copyright 2010 Long Weekend LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class LWETwitterOAuth; 12 | 13 | /** 14 | * LWE Twitter XAuth View Protocol (LWETXAuthViewProtocol) is a protocol that has to be conformed with any 15 | * of the view controller that hooked with the Twitter Engine, and is designed to work with the XAuth 16 | * methodology. It has to have LWETwitterOAuth object (assigned is more preferable than retained), and 17 | * it has to have fail authentication method that is going to be called by whoever instantiate it, 18 | * to report back if authentication does not go through. 19 | * 20 | * This View Controller protocol is only intended for XAuth methodology, for OAuth methodology, refer to 21 | * LWETAuthentication View Protocol 22 | */ 23 | @protocol LWETXAuthViewProtocol 24 | 25 | - (void)setAuthEngine:(LWETwitterOAuth *)authEngine; 26 | - (void)didFailAuthentication:(NSError *)error; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /Twitter/LWETUserDB.h: -------------------------------------------------------------------------------- 1 | // 2 | // LWETUserDB.h 3 | // TweetSimulationWithLWE 4 | // 5 | // Created by Rendy Pranata on 18/07/10. 6 | // Copyright 2010 Long Weekend LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import 12 | 13 | #define kUserProfileTable @"userProfile" 14 | #define kUserTokenTable @"userToken" 15 | #define kUserProfileID @"profileID" 16 | #define kTokenKey @"tokenKey" 17 | #define kTokenSecret @"tokenSecret" 18 | 19 | @interface LWETUserDB : NSObject 20 | { 21 | @private 22 | NSManagedObjectContext *managedObjectContext_; 23 | NSManagedObjectModel *managedObjectModel_; 24 | NSPersistentStoreCoordinator *persistentStoreCoordinator_; 25 | } 26 | 27 | @property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext; 28 | @property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel; 29 | @property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator; 30 | 31 | // RENDY: we have an LWE method for this ;) 32 | - (NSString *)applicationDocumentsDirectory; 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /Core/LWECrashUtils.h: -------------------------------------------------------------------------------- 1 | // LWECrashUtils.h 2 | // 3 | // Copyright (c) 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import 21 | 22 | void LWEUncaughtExceptionHandler(NSException *exception); -------------------------------------------------------------------------------- /Categories/NSURL+LWEUtilities.h: -------------------------------------------------------------------------------- 1 | // NSURL+LWEUtilities.h 2 | // 3 | // Copyright (c) 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import 21 | 22 | @interface NSURL (LWEUtilities) 23 | 24 | - (NSDictionary *)queryStrings; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /Categories/UIWebView+LWENoBounces.h: -------------------------------------------------------------------------------- 1 | // UIWebView+LWENoBounces.h 2 | // 3 | // Copyright (c) 2010 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | 21 | #import 22 | 23 | @interface UIWebView (LWENoBounces) 24 | 25 | -(void)shutOffBouncing; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Categories/NSDate+LWEUtilities.h: -------------------------------------------------------------------------------- 1 | // NSDate+LWEUtilities.h 2 | // 3 | // Copyright (c) 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | 21 | #import 22 | 23 | 24 | @interface NSDate (LWEUtilities) 25 | 26 | - (NSDate *)addDay; 27 | - (NSDate *)addDays:(NSInteger)days; 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /UI/Views/LWETooltipView/LWETooltipConstants.h: -------------------------------------------------------------------------------- 1 | // 2 | // LWETooltipConstants.h 3 | // LocationBasedMessaging 4 | // 5 | // Created by Mark Makdad on 7/15/10. 6 | // Copyright 2010 Long Weekend Inc. All rights reserved. 7 | // 8 | 9 | enum 10 | { 11 | LWETooltipCalloutPositionTop, 12 | LWETooltipCalloutPositionBottom, 13 | LWETooltipCalloutPositionLeft, 14 | LWETooltipCalloutPositionRight 15 | }; 16 | typedef NSUInteger LWETooltipCalloutPosition; 17 | 18 | enum 19 | { 20 | LWETooltipCalloutDirectionLeftToRight, 21 | LWETooltipCalloutDirectionRightToLeft, 22 | LWETooltipCalloutDirectionStraight 23 | }; 24 | typedef NSUInteger LWETooltipCalloutDirection; 25 | 26 | enum 27 | { 28 | LWETooltipCalloutOffsetNone, 29 | LWETooltipCalloutOffsetLeft, 30 | LWETooltipCalloutOffsetRight 31 | }; 32 | typedef NSUInteger LWETooltipCalloutOffset; 33 | 34 | enum 35 | { 36 | LWETooltipCloseButtonPositionTopLeft, 37 | LWETooltipCloseButtonPositionTopRight, 38 | LWETooltipCloseButtonPositionBottomLeft, 39 | LWETooltipCloseButtonPositionBottomRight 40 | }; 41 | typedef NSUInteger LWETooltipCloseButtonPosition; 42 | 43 | #define kDefaultStrokeColor [UIColor clearColor] 44 | #define kDefaultBackgroundColor [UIColor clearColor] 45 | #define kDefaultRectColor [UIColor blueColor] 46 | #define kDefaultStrokeWidth 1.0f 47 | #define kDefaultCornerRadius 20.0 48 | #define kDefaultShadowBlur 2.5 -------------------------------------------------------------------------------- /Twitter/LWETDelegates.h: -------------------------------------------------------------------------------- 1 | // 2 | // LWETAuthenticationProtocol.h 3 | // TrialConsumerOAuthforIPhone 4 | // 5 | // Created by Rendy Pranata on 15/07/10. 6 | // Copyright 2010 Long Weekend LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class OAToken; 12 | 13 | /** 14 | * This LWE Twitter Authentication View Delegate ia a delegate 15 | * used with the OAuth proccess, as the delegate of the Web-Twitter-Server View Controller 16 | * and who the view controller reports to after it gets the PIN for user OOB Authentication. 17 | * (It should be conformed by the LWETwitterOAuth class. 18 | */ 19 | @protocol LWETAuthenticationViewDelegate 20 | @required 21 | - (void)didFinishAuthorizationWithPin:(NSString *)pin; 22 | - (void)didFailedAuthorization; 23 | 24 | @end 25 | 26 | /** 27 | * This LWE Twitter Auth Proccess Delegate protocol, which has to be conformed 28 | * by the LWETwitterOAuth class, and used as a callback after each requests process 29 | * for OAuth authentication method 30 | * has finished 31 | */ 32 | @protocol LWETAuthProccessDelegate 33 | @optional 34 | - (void)didFinishAuthProcessWithAccessToken:(OAToken *)userToken; 35 | - (void)didFailAuthProcessWithError:(NSError *)error; 36 | - (void)didFinishXAuthProcessWithAccessToken:(OAToken *)userToken; 37 | - (void)didFailXAuthProcessWithError:(NSError *)error; 38 | @required 39 | - (UIViewController *)parentForUserAuthenticationView; 40 | 41 | @end -------------------------------------------------------------------------------- /Categories/NSArray+FindNearestIndexInOtherArray.h: -------------------------------------------------------------------------------- 1 | // NSArray+FindNearestIndexInOtherArray.h 2 | // 3 | // Copyright (c) 2012 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import 21 | 22 | @interface NSArray (FindNearestIndexInOtherArray) 23 | 24 | -(NSInteger)findNearestIndex:(NSInteger)index inOtherArray:(NSArray*)otherArray; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /Categories/NSBlock+PerformWithDelay.h: -------------------------------------------------------------------------------- 1 | // NSBlock+PerformWithDelay.h 2 | // 3 | // Copyright (c) 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import 21 | /* 22 | * Adds method for using blocks as a delayed selector 23 | */ 24 | @interface NSObject (PerformAfterDelay) 25 | - (void)performBlock:(void (^)(void))block afterDelay:(NSTimeInterval)delay; 26 | @end 27 | -------------------------------------------------------------------------------- /Categories/NSFetchedResultsController+MultibyteSectionIndexes.h: -------------------------------------------------------------------------------- 1 | // NSFetchedResultsController+MultibyteSectionIndexes.h 2 | // 3 | // Copyright (c) 2012 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import 21 | 22 | @interface NSFetchedResultsController (MultibyteSectionIndexes) 23 | 24 | /** Overrides sectionIndexTitles property to return a multibyte safe list of indexes (indices) */ 25 | - (NSArray*)sectionIndexTitles; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Network/LWES3Package.h: -------------------------------------------------------------------------------- 1 | // 2 | // LWES3Package.h 3 | // dtcstyle 4 | // 5 | // Created by Rendy Pranata on 11/04/12. 6 | // Copyright (c) 2012 Long Weekend LLC. All rights reserved. 7 | // 8 | 9 | #import "LWEPackage.h" 10 | 11 | @interface LWES3Package : LWEPackage 12 | 13 | //! This secret key is used by ASIS3ObjectRequest for authentication purposes. 14 | @property (nonatomic, retain) NSString *secretKey; 15 | 16 | //! This access/public key is used by ASIS3ObjectRequest for authentication purposes. 17 | @property (nonatomic, retain) NSString *accessKey; 18 | 19 | //! This bucket is also used by the ASIS3ObjectRequest framework to make request to the Amazon S3 Server. 20 | @property (nonatomic, retain) NSString *bucket; 21 | 22 | //! Path-to-object on the server. 23 | @property (nonatomic, retain) NSString *pathToObject; 24 | 25 | /** 26 | * Designated instance initializer. Pass it a URL and a local filename. 27 | * This method will automatically call its super implementation of designated 28 | * initialiser. Also this method will try to unpack the bucket and pathToObject initialisation. 29 | */ 30 | - (id) initWithUrl:(NSURL*)url destinationFilepath:(NSString*)filepath; 31 | 32 | /** 33 | * Designated class initializer. Pass it a URL and a local filename. 34 | * This method will automatically call its super implementation of designated 35 | * initialiser. Also this method will try to unpack the bucket and pathToObject initialisation. 36 | */ 37 | + (id) packageWithUrl:(NSURL*)url destinationFilepath:(NSString*)filepath; 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /Categories/NSBlock+PerformWithDelay.m: -------------------------------------------------------------------------------- 1 | // NSBlock+PerformWithDelay.m 2 | // 3 | // Copyright (c) 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import "NSBlock+PerformWithDelay.h" 21 | 22 | @implementation NSObject(PerformAfterDelay) 23 | - (void)performBlock:(void (^)(void))block afterDelay:(NSTimeInterval)delay 24 | { 25 | int64_t delta = (int64_t)(1.0e9 * delay); 26 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delta), dispatch_get_main_queue(), block); 27 | } 28 | @end 29 | -------------------------------------------------------------------------------- /Categories/UIScrollView+LWEUtilities.h: -------------------------------------------------------------------------------- 1 | // LWEScrollView.h 2 | // 3 | // Copyright (c) 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import 21 | 22 | @interface UIScrollView (LWEUtilities) 23 | - (void) resizeScrollViewWithContentView:(UIView *)view; 24 | - (void)setupWithDelegate:(id)theDelegate forViews:(NSArray *)views withTopPadding:(float)topPadding withBottomPadding:(float)bottomPadding withLeftPadding:(float)leftPadding withRightPadding:(float)rightPadding; 25 | @end 26 | -------------------------------------------------------------------------------- /Keychain/MTKeychainWrapper.h: -------------------------------------------------------------------------------- 1 | // 2 | // LWEKeychainWrapper.h 3 | // 4 | // Copyright (c) 2012 Long Weekend LLC 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 7 | // associated documentation files (the "Software"), to deal in the Software without restriction, 8 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 10 | // subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all copies or substantial 13 | // portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 16 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 18 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 19 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | 21 | #import 22 | #import 23 | 24 | @interface MTKeychainWrapper : NSObject 25 | 26 | - (void)setObject:(id)object forKey:(NSString *)key; 27 | - (id)objectForKey:(NSString *)key; 28 | - (void)resetKeychainItem; 29 | 30 | - (id)initWithIdentifier:(NSString *)identifier accessGroup:(NSString *)accessGroup; 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /Twitter/LWETUser.h: -------------------------------------------------------------------------------- 1 | // 2 | // LWETUser.h 3 | // TweetSimulationWithLWE 4 | // 5 | // Created by Rendy Pranata on 16/07/10. 6 | // Copyright 2010 Long Weekend LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @class OAToken; 13 | 14 | /** 15 | * This class symbolize a user, which are intended to be used for logging in 16 | * with the twitter engine. 17 | * 18 | * There are a lot of way to initialize this class, one of them are using managed object, and init this class 19 | * Also, this class holds all the information needed to sign the request on behalf of this user 20 | * to twitter. 21 | */ 22 | @interface LWETUser : NSObject 23 | { 24 | NSString *key; 25 | NSString *secret; 26 | NSString *userID; 27 | BOOL isAuthenticated; 28 | 29 | OAToken *userAccessToken; 30 | } 31 | 32 | @property (nonatomic, retain) NSString *key; 33 | @property (nonatomic, retain) NSString *secret; 34 | @property (nonatomic, retain) NSString *userID; 35 | @property (nonatomic, retain) OAToken *userAccessToken; 36 | @property (nonatomic, readwrite) BOOL isAuthenticated; 37 | 38 | - (id)init; 39 | 40 | - (id)initFromManagedObject:(NSManagedObject *)managedObject 41 | keyforKey:(NSString *)aKeyKey 42 | keyForSecret:(NSString *)aSecretKey; 43 | 44 | - (id)initWithKey:(NSString *)aKey 45 | secret:(NSString *)aSecret; 46 | 47 | - (id)initWithUserID:(NSString *)aUserID 48 | key:(NSString *)aKey 49 | secret:(NSString *)aSecret; 50 | 51 | + (LWETUser *)userWithID:(NSString *)aUserID; 52 | 53 | - (OAToken *)OAuthToken; 54 | 55 | @end -------------------------------------------------------------------------------- /Categories/NSDate+LWEUtilities.m: -------------------------------------------------------------------------------- 1 | // NSDate+LWEUtilities.m 2 | // 3 | // Copyright (c) 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import "NSDate+LWEUtilities.h" 21 | 22 | 23 | @implementation NSDate (LWEUtilities) 24 | 25 | - (NSDate *)addDay 26 | { 27 | return [self addDays:1]; 28 | } 29 | 30 | - (NSDate *)addDays:(NSInteger)days 31 | { 32 | double updatePeriod = days * 3600 * 24; 33 | double result = [self timeIntervalSince1970] + updatePeriod; 34 | NSDate *date = nil; 35 | date = [NSDate dateWithTimeIntervalSince1970:result]; 36 | 37 | return date; 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /Categories/NSArray+LWEBlocks.h: -------------------------------------------------------------------------------- 1 | // NSArray+LWEBlocks.h 2 | // 3 | // Copyright (c) 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | 21 | #import 22 | 23 | /** 24 | * Category of NSArray to extend the capabilities 25 | * to do some commonly used task in a functional way. 26 | * 27 | * It adds some method to use or utilise block to do 28 | * day-to-day NSArray operation. 29 | * 30 | */ 31 | @interface NSArray (LWEBlocks) 32 | 33 | - (void)each:(void (^)(id))block; 34 | 35 | - (void)eachWithIdx:(void (^)(id, NSUInteger))block; 36 | 37 | - (void)reversedEach:(void (^)(id))block; 38 | 39 | @end -------------------------------------------------------------------------------- /Categories/NSString+LWEExtensions.m: -------------------------------------------------------------------------------- 1 | // NSString+LWEExtensions.m 2 | 3 | 4 | #import "NSString+LWEExtensions.h" 5 | #import 6 | 7 | 8 | @implementation NSString (LWEExtensions) 9 | 10 | - (BOOL) isNotBlank 11 | { 12 | if ([[self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] isEqualToString:@""]) 13 | { 14 | return NO; 15 | } 16 | else 17 | { 18 | return YES; 19 | } 20 | } 21 | 22 | /** 23 | * This code first found on: 24 | * http://iphonedevelopertips.com/core-services/create-md5-hash-from-nsstring-nsdata-or-file.html 25 | */ 26 | - (NSString*) MD5 27 | { 28 | // Create pointer to the string as UTF8 29 | const char *ptr = [self UTF8String]; 30 | 31 | // Create byte array of unsigned chars 32 | unsigned char md5Buffer[CC_MD5_DIGEST_LENGTH]; 33 | 34 | // Create 16 byte MD5 hash value, store in buffer 35 | CC_MD5(ptr, strlen(ptr), md5Buffer); 36 | 37 | // Convert MD5 value in the buffer to NSString of hex values 38 | NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2]; 39 | for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) 40 | [output appendFormat:@"%02x",md5Buffer[i]]; 41 | 42 | return output; 43 | } 44 | 45 | /** 46 | * This code found on: 47 | * http://simonwoodside.com/weblog/2009/4/22/how_to_really_url_encode/ 48 | * Example call [mystring urlEncodeUsingEncoding:kCFStringEncodingUTF8]; 49 | */ 50 | -(NSString *)urlEncodeUsingEncoding:(NSStringEncoding)encoding 51 | { 52 | return (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)self, NULL, (CFStringRef)@"!*'\"();:@&=+$,/?%#[]% ", CFStringConvertNSStringEncodingToEncoding(encoding)); 53 | } 54 | @end 55 | -------------------------------------------------------------------------------- /Categories/UIBarButtonItem+LWEAdditions.h: -------------------------------------------------------------------------------- 1 | // UIBarButtonItem+LWEAdditions.h 2 | // 3 | // Copyright (c) 2012 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import 21 | 22 | @interface UIBarButtonItem (LWEAdditions) 23 | 24 | /** 25 | Creates a custom UIBarButtonItem with a tappable image. 26 | @param buttonImage The image to display. The button will be sized to this image. 27 | @param target The target to be invoked for UIControlEventTouchUpInside. 28 | @param action The selector to be invoked on the target. 29 | */ 30 | + (UIBarButtonItem *) barButtonWithImage:(UIImage *)buttonImage target:(id)target action:(SEL)action; 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /Categories/UILabel+LWEUtilities.h: -------------------------------------------------------------------------------- 1 | // LWEUILabelUtils.h 2 | // 3 | // Copyright (c) 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import 21 | 22 | #define READING_MIN_FONTSIZE 14.0 23 | #define READING_MAX_FONTSIZE 20.0 24 | #define READING_DEF_FONTSIZE 14.0 25 | 26 | #define HEADWORD_MIN_FONTSIZE 20.0 27 | #define HEADWORD_MAX_FONTSIZE 38.0 28 | #define HEADWORD_DEF_FONTSIZE 14.0 29 | 30 | @interface UILabel (LWEUtilities) 31 | 32 | - (void) resizeWithMinFontSize:(NSInteger)minFontSize maxFontSize:(NSInteger)maxFontSize; 33 | - (void) adjustFrameWithFontSize:(NSInteger)fontSize cellWidth:(NSInteger)width cellMargin:(NSInteger)margin; 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /UI/LWEViewAnimationUtils.h: -------------------------------------------------------------------------------- 1 | // LWEViewAnimationUtils.h 2 | // 3 | // Copyright (c) 2010, 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import 21 | #import 22 | 23 | @interface LWEViewAnimationUtils : NSObject 24 | 25 | + (void) translateView:(UIView*)view byPoint:(CGPoint)point withInterval:(float)delay; 26 | + (void) doViewTransition:(NSString *)transition direction:(NSString *)direction duration:(float)duration objectToTransition:(UIViewController *)controllerToTransition; 27 | + (void) fadeOutView:(UIView*)theView fadeDuration:(CGFloat)duration; 28 | + (void) fadeInView:(UIView*)theView intoView:(UIView*)superview fadeDuration:(CGFloat)duration; 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /Network/LWENetworkUtils.h: -------------------------------------------------------------------------------- 1 | // LWENetworkUtils.h 2 | // 3 | // Copyright (c) 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import "Reachability.h" 21 | 22 | 23 | @interface LWENetworkUtils : NSObject 24 | 25 | /** 26 | * Given some NSData object, returns a string of Base64-encoded data for that NSData. 27 | * This was ripped off from: http://www.cocoadev.com/index.pl?BaseSixtyFour 28 | */ 29 | + (NSString*) base64forData:(NSData*)theData; 30 | 31 | + (BOOL) networkAvailable; 32 | + (BOOL) networkAvailableFor:(NSString*)hostURL; 33 | + (BOOL) networkReachableForHost:(NSString*)hostURLOrNil showAlert:(BOOL) showAlert; 34 | - (void) followLinkshareURL:(NSString*)linkShareUrlString; 35 | 36 | @property (nonatomic, retain) NSURL* iTunesURL; 37 | 38 | @end -------------------------------------------------------------------------------- /Categories/NSArray+LWEBlocks.m: -------------------------------------------------------------------------------- 1 | // NSArray+LWEBlocks.m 2 | // 3 | // Copyright (c) 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | 21 | #import "NSArray+LWEBlocks.h" 22 | 23 | 24 | @implementation NSArray (LWEBlocks) 25 | 26 | - (void)each:(void (^)(id))block 27 | { 28 | for (id obj in self) 29 | { 30 | block(obj); 31 | } 32 | } 33 | 34 | - (void)eachWithIdx:(void (^)(id, NSUInteger))block 35 | { 36 | NSUInteger max = [self count]; 37 | for (NSUInteger i=0; i=0; i--) 47 | { 48 | id obj = [self objectAtIndex:i]; 49 | block(obj); 50 | } 51 | } 52 | 53 | @end -------------------------------------------------------------------------------- /Categories/UIWebView+LWENoBounces.m: -------------------------------------------------------------------------------- 1 | // UIWebView+LWENoBounces.m 2 | // 3 | // Copyright (c) 2010 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | 21 | #import "UIWebView+LWENoBounces.h" 22 | 23 | 24 | @implementation UIWebView (LWENoBounces) 25 | 26 | /*! 27 | @method 28 | @abstract Turns off bouncing on UIWebViews 29 | */ 30 | 31 | -(void)shutOffBouncing 32 | { 33 | UIScrollView *scrollView = [self.subviews objectAtIndex:0]; 34 | 35 | SEL aSelector = NSSelectorFromString(@"setAllowsRubberBanding:"); 36 | if([scrollView respondsToSelector:aSelector]) 37 | { 38 | [scrollView performSelector:aSelector withObject:NO]; 39 | } 40 | else if ([scrollView respondsToSelector:@selector(setBounces:)]) 41 | { 42 | [scrollView setBounces:NO]; 43 | } 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /Network/LWEDecompressor.h: -------------------------------------------------------------------------------- 1 | // 2 | // LWEDecompressor.h 3 | // phone 4 | // 5 | // Created by Mark Makdad on 6/20/11. 6 | // Copyright 2011 Long Weekend LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class LWEDecompressor; 12 | 13 | /** 14 | * Protocol for any class wanting to use the decompressor. 15 | * You must implement both methods. 16 | */ 17 | @protocol LWEDecompressorDelegate 18 | @required 19 | - (void)decompressFinished:(LWEDecompressor*)decompressor; 20 | - (void)decompressFailed:(LWEDecompressor*)decompressor error:(NSError*)error; 21 | @end 22 | 23 | @interface LWEDecompressor : NSObject 24 | { 25 | BOOL _isDecompressing; 26 | } 27 | 28 | /** 29 | * Factory initialzier, sets |delegate|, but returns the new object autoreleased.s 30 | */ 31 | + (id) decompressorWithDelegate:(id)aDelegate; 32 | 33 | /** 34 | * Standard initializer, sets |delegate|. 35 | */ 36 | - (id) initWithDelegate:(id)delegate; 37 | 38 | /** 39 | * Decompresses (unzips) the zip file located at |zippedPath|, optionally asynchronously 40 | * The files will be unzipped directly into the |unzippedPath| folder -- so make sure 41 | * to pass an empty folder name at the end of the path if that's what you want. 42 | */ 43 | - (void)decompressContentAtPath:(NSString*)zippedPath toPath:(NSString*)unzippedPath asynchronously:(BOOL)asynch; 44 | 45 | //! User dictionary 46 | @property (retain) NSDictionary *userInfo; 47 | 48 | //! If asynchronous, it could be useful to know if this object is busy. 49 | @property (readonly) BOOL isDecompressing; 50 | 51 | //! Location of the zipped content 52 | @property (retain) NSString *compressedContentFilepath; 53 | 54 | //! Where the content is after being unzipped 55 | @property (retain) NSString *decompressedContentPath; 56 | 57 | @property (assign) id delegate; 58 | 59 | @end 60 | -------------------------------------------------------------------------------- /Categories/NSString+LWEResolutionHelpers.h: -------------------------------------------------------------------------------- 1 | // NSString+LWEResolutionHelpers.h 2 | // 3 | // Copyright (c) 2012 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import 21 | 22 | /** 23 | In some environments, it is useful to manually create retina & HD filenames on your 24 | own. This is a category of helpers on NSString that will take regular filenames and 25 | create their associated HD and @2x components. 26 | 27 | TODO: Does not yet support the new iPad 3 (@HD@2x?). 28 | */ 29 | @interface NSString (LWEResolutionHelpers) 30 | /** 31 | Creates a filename for the iPad 1/2 by appending `@-hd` before the file extension. 32 | */ 33 | - (NSString*)stringByAddingHDSpecifier; 34 | 35 | /** 36 | Creates a filename for a Retina device by appending `@2x` before the file extension. 37 | */ 38 | - (NSString*)stringByAddingRetinaSpecifier; 39 | @end 40 | -------------------------------------------------------------------------------- /Twitter/LWETUser.m: -------------------------------------------------------------------------------- 1 | // 2 | // LWETUser.m 3 | // TweetSimulationWithLWE 4 | // 5 | // Created by Rendy Pranata on 16/07/10. 6 | // Copyright 2010 Long Weekend LLC. All rights reserved. 7 | // 8 | 9 | #import "LWETUser.h" 10 | 11 | #import "OAToken.h" 12 | 13 | @implementation LWETUser 14 | 15 | @synthesize key; 16 | @synthesize secret; 17 | @synthesize userID; 18 | @synthesize userAccessToken; 19 | @synthesize isAuthenticated; 20 | 21 | #pragma mark - Constructors & Deconstructors 22 | 23 | - (id)init 24 | { 25 | self = [super init]; 26 | if (self) 27 | { 28 | /*place for future customazation*/ 29 | } 30 | return self; 31 | } 32 | 33 | - (id)initFromManagedObject:(NSManagedObject *)managedObject keyforKey:(NSString *)aKeyKey keyForSecret:(NSString *)aSecretKey 34 | { 35 | return [self initWithKey:[managedObject valueForKey:aKeyKey] secret:[managedObject valueForKey:aSecretKey]]; 36 | } 37 | 38 | - (id)initWithKey:(NSString *)aKey secret:(NSString *)aSecret 39 | { 40 | self = [self init]; 41 | if (self) 42 | { 43 | self.key = aKey; 44 | self.secret = aSecret; 45 | self.userAccessToken = [self OAuthToken]; 46 | self.isAuthenticated = YES; 47 | } 48 | return self; 49 | } 50 | 51 | - (id)initWithUserID:(NSString *)aUserID key:(NSString *)aKey secret:(NSString *)aSecret 52 | { 53 | self = [self initWithKey:aKey secret:aSecret]; 54 | if (self) 55 | { 56 | self.userID = aUserID; 57 | } 58 | return self; 59 | } 60 | 61 | + (LWETUser *)userWithID:(NSString *)aUserID 62 | { 63 | LWETUser *user = [[[LWETUser alloc] init] autorelease]; 64 | user.userID = aUserID; 65 | user.isAuthenticated = NO; 66 | return user; 67 | } 68 | 69 | - (void)dealloc 70 | { 71 | [userID release]; 72 | [key release]; 73 | [secret release]; 74 | [super dealloc]; 75 | } 76 | 77 | #pragma mark - Core Method 78 | 79 | - (OAToken *)OAuthToken 80 | { 81 | return [[[OAToken alloc] initWithKey:self.key secret:self.secret] autorelease]; 82 | } 83 | 84 | @end 85 | -------------------------------------------------------------------------------- /UI/LWEUITableUtils.h: -------------------------------------------------------------------------------- 1 | // LWEUITabelUtils.h 2 | // 3 | // Copyright (c) 2010, 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import 21 | 22 | #define LWE_UITABLE_CELL_FONT_SIZE 14.0f 23 | #define LWE_UITABLE_CELL_CONTENT_WIDTH 300.0f 24 | #define LWE_UITABLE_CELL_CONTENT_MARGIN 10.0f 25 | 26 | @interface LWEUITableUtils : NSObject 27 | 28 | + (UITableViewCell*) reuseCellForIdentifier: (NSString*) identifier onTable:(UITableView*) lclTableView usingStyle:(UITableViewCellStyle)style; 29 | + (void)autosizeFrameForBlankLabel:(UILabel*)label forText:(NSString*)text; 30 | + (CGFloat) autosizeHeightForCellWithText:(NSString *)text; 31 | + (CGFloat) autosizeHeightForCellWithText:(NSString *)text fontSize:(NSInteger)fontSize; 32 | + (CGFloat) autosizeHeightForCellWithText:(NSString*)text fontSize:(NSInteger)fontSize cellWidth:(NSInteger)width cellMargin:(NSInteger)margin; 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /UI/Controllers/LWEPagingScrollViewDatasource.m: -------------------------------------------------------------------------------- 1 | // LWEPagingScrollViewDataSource.m 2 | // 3 | // Copyright (c) 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import "LWEPagingScrollViewDataSource.h" 21 | 22 | @implementation LWEPagingScrollViewDataSource 23 | 24 | @synthesize dataPages; 25 | 26 | - (id) init 27 | { 28 | [NSException raise:@"Invalid Initializer" format:@"Use initWithDataPages instead"]; 29 | return nil; 30 | } 31 | 32 | - (id) initWithDataPages:(NSArray *)data 33 | { 34 | if ((self = [super init])) 35 | { 36 | self.dataPages = data; 37 | } 38 | return self; 39 | } 40 | 41 | - (void) dealloc 42 | { 43 | [dataPages release]; 44 | [super dealloc]; 45 | } 46 | 47 | - (NSInteger)numDataPages 48 | { 49 | return [self.dataPages count]; 50 | } 51 | 52 | - (NSDictionary *)dataForPage:(NSInteger)pageIndex 53 | { 54 | return [self.dataPages objectAtIndex:pageIndex]; 55 | } 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /UI/Views/LWETooltipView/LWETooltipParams.m: -------------------------------------------------------------------------------- 1 | // 2 | // LWETooltipParams.m 3 | // LocationBasedMessaging 4 | // 5 | // Created by Rendy Pranata on 26/08/10. 6 | // Copyright 2010 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import "LWETooltipParams.h" 10 | #import "LWEDebug.h" 11 | 12 | @implementation LWETooltipParams 13 | 14 | @synthesize closeButtonPosition, closeButtonImage; 15 | @synthesize shadowOffset, shadowBlur, showDropShadow, alpha, shouldResize; 16 | @synthesize rectColor, backgroundColor, strokeColor, strokeWidth; 17 | @synthesize cornerRadius; 18 | @synthesize calloutPosition, calloutDirection, calloutOffset, calloutSize, showCallout; 19 | 20 | - (id)init 21 | { 22 | LWE_LOG(@"Please be advised, this is not the designated initialiser, please use the default value"); 23 | return nil; 24 | } 25 | 26 | 27 | - (id)initWithDefaultValue; 28 | { 29 | if ((self = [super init])) 30 | { 31 | // Default options 32 | self.closeButtonPosition = LWETooltipCloseButtonPositionTopRight; 33 | self.closeButtonImage = [UIImage imageNamed:@"overlay-btn-close.png"]; 34 | 35 | self.shadowOffset = CGSizeMake(3, 5); 36 | self.showDropShadow = YES; 37 | self.shadowBlur = kDefaultShadowBlur; 38 | self.alpha = 1.0f; 39 | 40 | self.rectColor = kDefaultRectColor; 41 | backgroundColor = kDefaultBackgroundColor; 42 | self.strokeColor = kDefaultStrokeColor; 43 | self.strokeWidth = kDefaultStrokeWidth; 44 | 45 | self.cornerRadius = kDefaultCornerRadius; 46 | 47 | self.calloutPosition = LWETooltipCalloutPositionTop; 48 | self.calloutDirection = LWETooltipCalloutDirectionStraight; 49 | self.calloutOffset = LWETooltipCalloutOffsetLeft; 50 | self.calloutSize = 0.15f; 51 | self.showCallout = YES; 52 | self.shouldResize = NO; 53 | } 54 | return self; 55 | } 56 | 57 | 58 | - (void)dealloc 59 | { 60 | self.closeButtonImage = nil; 61 | self.rectColor = nil; 62 | [backgroundColor release]; 63 | self.strokeColor = nil; 64 | [super dealloc]; 65 | } 66 | 67 | 68 | @end 69 | -------------------------------------------------------------------------------- /UI/Controllers/LWEPagingScrollViewDatasource.h: -------------------------------------------------------------------------------- 1 | // LWEPagingScrollViewDataSource.h 2 | // 3 | // Copyright (c) 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import 21 | #import "LWEPagingScrollViewController.h" 22 | 23 | /** 24 | * This class is a default implementation of the LWEPageViewControllerDataSource 25 | * protocol. 26 | * 27 | * Your needs may vary based on the implementation, but if you need to supply a 28 | * dictionary of data for a given page, it could work well. 29 | */ 30 | @interface LWEPagingScrollViewDataSource : NSObject 31 | 32 | @property (nonatomic, retain) NSArray *dataPages; 33 | 34 | /** 35 | * Designated initializer. 36 | */ 37 | - (id) initWithDataPages:(NSArray*)data; 38 | 39 | /** 40 | * Returns the number of pages in the datasource. 41 | */ 42 | - (NSInteger)numDataPages; 43 | 44 | /** 45 | * Returns the dictionary of data for a given page 46 | */ 47 | - (NSDictionary *)dataForPage:(NSInteger)pageIndex; 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /Core/LWELocalNotifications.h: -------------------------------------------------------------------------------- 1 | // LWELocalNotifications.h 2 | // 3 | // Copyright (c) 2010 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import 21 | 22 | @interface LWELocalNotifications : NSObject 23 | 24 | /** 25 | * \brief Set the numeric badge to show for the application 26 | * \param badgeNumber The new badge number for the application 27 | */ 28 | + (void)setApplicationBadgeNumber:(NSInteger)badgeNumber; 29 | 30 | /** 31 | * \brief Schedules a notification on the user's phone 32 | * \param message The text to be displayed 33 | * \param buttonTitleOrNil A title for the action button. If nil, no action button is displayed 34 | * \param interval How long to wait before displaying, or nil for immediately 35 | */ 36 | + (void) scheduleLocalNotificationWithMessage:(NSString *)message buttonTitle:(NSString*)buttonTitleOrNil inTimeIntervalSinceNow:(NSTimeInterval)interval; 37 | + (void) presentLocalNotificationWithMessage:(NSString*)message buttonTitle:(NSString*)buttonTitleOrNil; 38 | 39 | @end -------------------------------------------------------------------------------- /Categories/NSArray+LWEEnums.m: -------------------------------------------------------------------------------- 1 | // NSArray+LWEEnums.m 2 | // 3 | // Copyright (c) 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | @implementation NSArray (LWEEnumExtensions) 21 | 22 | //! Converts a string to an enumVal 23 | - (NSString*) stringWithEnum:(NSInteger)enumVal 24 | { 25 | NSString *retVal = nil; 26 | if([self objectAtIndex:enumVal]) 27 | { 28 | retVal = [self objectAtIndex:enumVal]; 29 | } 30 | else 31 | { 32 | //[NSException raise:NSInternalInconsistencyException format:@"Enum value does not match index in array!"]; 33 | // Decided this shouldn't fail noisily 34 | } 35 | return retVal; 36 | } 37 | 38 | //! Converts a string from an enumVal and supports passing in a default 39 | - (NSInteger) enumFromString:(NSString*)strVal default:(NSInteger)def 40 | { 41 | NSInteger n = [self indexOfObject:strVal]; 42 | if(n==NSNotFound) 43 | { 44 | n = def; 45 | } 46 | return n; 47 | } 48 | 49 | //! Converts a string from an enumVal 50 | - (NSInteger) enumFromString:(NSString*)strVal 51 | { 52 | return [self enumFromString:strVal default:0]; 53 | } 54 | 55 | @end -------------------------------------------------------------------------------- /Twitter/LWETwitterOAuth.h: -------------------------------------------------------------------------------- 1 | // 2 | // LWETwitterOAuth.h 3 | // TrialConsumerOAuthforIPhone 4 | // 5 | // Created by Rendy Pranata on 16/07/10. 6 | // Copyright 2010 Long Weekend LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "LWETDelegates.h" 12 | #import "LWETAuthenticationViewProtocol.h" 13 | #import "LWETXAuthViewProtocol.h" 14 | 15 | #define kServerNameSecure @"https://api.twitter.com/oauth" 16 | #define kRequestTokenMethod @"request_token" 17 | #define kAuthenticationMethod @"authorize" 18 | #define kAccessTokenMethod @"access_token" 19 | 20 | #define kClientAuth @"client_auth" 21 | 22 | @class OAConsumer; 23 | @class OAToken; 24 | @class OAMutableURLRequest; 25 | @class OAServiceTicket; 26 | 27 | typedef enum 28 | { 29 | LWET_REQUEST, 30 | LWET_AUTHORIZE, 31 | LWET_ACCESS_TOKEN 32 | } LWETwitterAuthType; 33 | 34 | /** 35 | * This class takes care of all the authentication method. Imagine this is the Authentication Agent which is used for signing in. 36 | * 37 | */ 38 | @interface LWETwitterOAuth : NSObject 39 | { 40 | BOOL isAuthenticated; 41 | } 42 | 43 | @property (nonatomic, assign) id delegate; 44 | @property (nonatomic, retain) OAConsumer *consumer; 45 | @property (nonatomic, retain) OAToken *accessToken; 46 | @property (nonatomic, retain) UIViewController *authenticationView; 47 | 48 | - (id)initWithConsumer:(OAConsumer *)aConsumer 49 | delegate:(id )aDelegate; 50 | 51 | - (void)startXAuthProcessWithUsername:(NSString *)uname 52 | password:(NSString *)password; 53 | 54 | - (void)startAuthProccess; 55 | 56 | /** 57 | * This method is used for translating the LWETwitterAuthType enum type, to the string it coresponds to. 58 | */ 59 | - (NSString *)methodNameForAuthType:(LWETwitterAuthType)lwet; 60 | 61 | - (OAMutableURLRequest *)prepareURLForAuthType:(LWETwitterAuthType)lwet 62 | withTicket:(OAServiceTicket *)ticket 63 | responseData:(NSData *)data; 64 | 65 | - (void)updateAccessTokenWithTicket:(OAServiceTicket *)ticket 66 | data:(NSData *)data; 67 | 68 | @end 69 | -------------------------------------------------------------------------------- /Categories/UIColor+LWEUtilities.h: -------------------------------------------------------------------------------- 1 | // UIColor+LWEUtilities.m 2 | // 3 | // Copyright (c) 2010-2 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import 21 | 22 | #pragma mark - UIColor 23 | 24 | @interface UIColor (LWEUtilities) 25 | 26 | //! This method will initialize a color object with the provided hexadecimal number. (Currently it only supports 24 bits color) 27 | - (id)initWithHex:(NSInteger)hex; 28 | 29 | //! This is the class method, that will call the method above, and give the autorelease object. It will transform the hexadecimal color, into individual red, green, blue color. 30 | + (id)colorWithHex:(NSInteger)hex; 31 | 32 | //! This method will initialize a color object with the provided hexadecimal number, and alpha (0.0-1.0). (Currently it only supports 24 bits color) 33 | - (id)initWithHex:(NSInteger)hex alpha:(CGFloat)alpha; 34 | 35 | //! This is the class method, that will call the method above, and give the autorelease object. It will transform the hexadecimal color, into individual red, green, blue color. 36 | + (id)colorWithHex:(NSInteger)hex alpha:(CGFloat)alpha; 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /Categories/UIBarButtonItem+LWEAdditions.m: -------------------------------------------------------------------------------- 1 | // UIBarButtonItem+LWEAdditions.m 2 | // 3 | // Copyright (c) 2012 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | 21 | #import "UIBarButtonItem+LWEAdditions.h" 22 | 23 | @implementation UIBarButtonItem (LWEAdditions) 24 | 25 | + (UIBarButtonItem *) barButtonWithImage:(UIImage *)buttonImage target:(id)target action:(SEL)action 26 | { 27 | UIButton *menuBtn = [UIButton buttonWithType:UIButtonTypeCustom]; 28 | menuBtn.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height); 29 | [menuBtn setBackgroundImage:buttonImage forState:UIControlStateNormal]; 30 | [menuBtn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside]; 31 | 32 | // It's ridiculous that we have to bury the UIButton inside a UIView to get it to work, but. 33 | UIView *customView = [[UIView alloc] initWithFrame:menuBtn.frame]; 34 | [customView addSubview:menuBtn]; 35 | 36 | // Finally create the button w/ the custom view 37 | UIBarButtonItem *barBtn = [[UIBarButtonItem alloc] initWithCustomView:customView]; 38 | return [barBtn autorelease]; 39 | } 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /Categories/NSFetchedResultsController+MultibyteSectionIndexes.m: -------------------------------------------------------------------------------- 1 | // NSFetchedResultsController+MultibyteSectionIndexes.m 2 | // 3 | // Copyright (c) 2012 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import "NSFetchedResultsController+MultibyteSectionIndexes.h" 21 | 22 | @implementation NSFetchedResultsController (MultibyteSectionIndexes) 23 | 24 | /** Overrides sectionIndexTitles property to return a multibyte safe list of indexes (indices) */ 25 | -(NSArray*)sectionIndexTitles 26 | { 27 | // This code avoids outputting mojibake proof 28 | // Reference: http://hitoshiohtubo.blog.fc2.com/blog-entry-3.html 29 | NSMutableArray *indexArray = [NSMutableArray array]; 30 | for (id s in [self sections]) 31 | { 32 | NSString *name = [s name]; 33 | if([name length] > 0) 34 | { 35 | if([name canBeConvertedToEncoding:NSASCIIStringEncoding]) 36 | { 37 | // convert to uppercase if romaji 38 | name = [name uppercaseString]; 39 | } 40 | [indexArray addObject:[name substringFromIndex:0]]; 41 | } 42 | } 43 | return (NSArray*)indexArray; 44 | } 45 | @end 46 | -------------------------------------------------------------------------------- /Data/LWEDatabase.h: -------------------------------------------------------------------------------- 1 | // LWEDatabase.h 2 | // 3 | // Copyright (c) 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import 21 | #import "FMDatabase.h" 22 | #import "FMDatabaseAdditions.h" 23 | #import "FMResultSet.h" 24 | #import "LWEFile.h" 25 | #import "Constants.h" 26 | 27 | extern NSString * const LWEDatabaseTempAttachName; 28 | 29 | //! LWE Database singleton, maintains active connections 30 | @interface LWEDatabase : NSObject 31 | 32 | + (LWEDatabase *)sharedLWEDatabase; 33 | - (void) asynchCopyDatabaseFromBundle:(NSString *)filename completionBlock:(dispatch_block_t)completionBlock; 34 | - (BOOL) openDatabase:(NSString*) pathToDatabase; 35 | - (BOOL) closeDatabase; 36 | - (NSString*) databaseVersion; 37 | - (NSString*) databaseVersionForDatabase:(NSString*)dbName; 38 | - (BOOL) attachDatabase:(NSString*) pathToDatabase withName:(NSString*) name; 39 | - (BOOL) detachDatabase:(NSString*) name; 40 | - (BOOL) tableExists:(NSString*) tableName; 41 | 42 | // For passthru to FMDatabase object 43 | - (FMResultSet*) executeQuery:(NSString*)sql; 44 | - (BOOL) executeUpdate:(NSString*)sql; 45 | 46 | @property (nonatomic, readonly, retain) FMDatabase *dao; 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /Core/LWEMacros.h: -------------------------------------------------------------------------------- 1 | // LWEMacros.h 2 | // 3 | // Copyright (c) 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #pragma mark - Delegate Stuff 21 | 22 | #define LWE_DELEGATE_CALL(SELECTOR,OBJ) do { \ 23 | if (self.delegate && ([self.delegate respondsToSelector:SELECTOR])) \ 24 | {\ 25 | [self.delegate performSelector:SELECTOR withObject:OBJ];\ 26 | }\ 27 | } while(0) 28 | 29 | #pragma mark - Timers 30 | 31 | //! Use this one in the dealloc method 32 | #define LWE_DEALLOC_TIMER(OBJ) do { \ 33 | [OBJ invalidate];\ 34 | [OBJ release];\ 35 | } while(0) 36 | 37 | //! Use this in other methods with a "self." timer - don't use with a non-retain synthesized retain setter timer (self.something) otherwise it will leak! 38 | #define LWE_STOP_TIMER(OBJ) do { \ 39 | if (OBJ)\ 40 | {\ 41 | if ([OBJ isValid]) {\ 42 | [OBJ invalidate];\ 43 | }\ 44 | else\ 45 | {\ 46 | NSLog(@"Tried to stop timer: %@ but it is not valid, setting to nil",OBJ);\ 47 | }\ 48 | OBJ = nil;\ 49 | }\ 50 | } while(0) 51 | 52 | #pragma mark - NSString 53 | 54 | //Convert a preprocessor symbol to an NSString 55 | //EXAMPLE// NSString *version = CONVERT_SYMBOL_TO_NSSTRING(SRC_ROOT); 56 | 57 | #define CONVERT_SYMBOL_TO_NSSTRING_2(x) @#x 58 | #define CONVERT_SYMBOL_TO_NSSTRING(x) CONVERT_SYMBOL_TO_NSSTRING_2(x) 59 | -------------------------------------------------------------------------------- /Network/LWELongRunningTaskProtocol.h: -------------------------------------------------------------------------------- 1 | // LWELongRunningTaskProtocol.h 2 | // 3 | // Copyright (c) 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import 21 | 22 | /** 23 | * Any class that implements this protocol can be used as a long running task. 24 | */ 25 | @protocol LWELongRunningTaskProtocol 26 | @required 27 | //! The task should cancel whatever it isi doing when receiving this message. 28 | - (void) cancel; 29 | 30 | //! The task should begin executing after receiving this message. 31 | - (void) start; 32 | 33 | //! Returns YES if the task is in a successful terminal state. 34 | - (BOOL) isSuccessState; 35 | 36 | //! Returns YES if the task is in a failed terminal state. 37 | - (BOOL) isFailureState; 38 | 39 | //! Brief description that can be displayed to the user of what the task is currently doing. 40 | - (NSString*) taskMessage; 41 | 42 | //! Brief 0-1 reference of how far along the task is to completion. 43 | - (CGFloat) progress; 44 | 45 | @optional 46 | //! If YES, the task is running 47 | - (BOOL) isActive; 48 | 49 | //! If YES, it is possible to call -cancel. May change, and is not thread safe. 50 | - (BOOL) canCancelTask; 51 | 52 | //! If YES, it is possible to call -start. May change, and is not thread safe. 53 | - (BOOL) canStartTask; 54 | @end 55 | -------------------------------------------------------------------------------- /Categories/NSString+LWEResolutionHelpers.m: -------------------------------------------------------------------------------- 1 | // NSString+LWEResolutionHelpers.m 2 | // 3 | // Copyright (c) 2012 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import "NSString+LWEResolutionHelpers.h" 21 | 22 | @implementation NSString (LWEResolutionHelpers) 23 | 24 | //! converts filename string into HD 25 | -(NSString*)stringByAddingHDSpecifier 26 | { 27 | NSArray *filenameComponents = [self componentsSeparatedByString:@"."]; 28 | NSString *newFilename = [NSString stringWithFormat:@"%@-hd", [filenameComponents objectAtIndex:0]]; 29 | if ([filenameComponents count] > 1) 30 | { 31 | newFilename = [NSString stringWithFormat:@"%@.%@", newFilename, [filenameComponents objectAtIndex:1]]; 32 | } 33 | return newFilename; 34 | } 35 | 36 | 37 | //! Converts filename string into Retina (@2x) 38 | - (NSString*)stringByAddingRetinaSpecifier 39 | { 40 | NSString *retinaName = nil; 41 | NSRange lastPeriod = [self rangeOfString:@"." options:NSBackwardsSearch]; 42 | if (lastPeriod.location == NSNotFound) 43 | { 44 | // Append only - there is no extension (ticket #568) 45 | retinaName = [self stringByAppendingString:@"@2x"]; 46 | } 47 | else 48 | { 49 | retinaName = [self stringByReplacingCharactersInRange:lastPeriod withString:@"@2x."]; 50 | } 51 | return retinaName; 52 | } 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /Core/LWEDebug.h: -------------------------------------------------------------------------------- 1 | // LWEDebug.h 2 | // 3 | // Copyright (c) 2010, 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | 21 | // Assertions - for app store do nothing, otherwise assert! 22 | #if defined(LWE_RELEASE_APP_STORE) 23 | #define LWE_ASSERT(STATEMENT) do { (void) sizeof(STATEMENT); } while(0) 24 | #else 25 | #define LWE_ASSERT(STATEMENT) do { assert(STATEMENT); } while(0) 26 | #endif 27 | 28 | // Errors - do nothing in production, crash otherwise 29 | #if defined(LWE_RELEASE_APP_STORE) || defined(LWE_RELEASE_ADHOC) 30 | #define LWE_LOG_ERROR(MSG,...); 31 | #else 32 | #define LWE_LOG_ERROR(MSG,...) do {\ 33 | [NSException raise:NSGenericException format:MSG,## __VA_ARGS__];\ 34 | } while (0) 35 | #endif 36 | 37 | // Exceptions - for app store, do nothing, otherwise throw! 38 | #if defined(LWE_RELEASE_APP_STORE) 39 | #define LWE_ASSERT_EXC(STATEMENT,MSG,...) do { (void) sizeof(STATEMENT); } while(0) 40 | #else 41 | #define LWE_ASSERT_EXC(STATEMENT,MSG,...) do {\ 42 | if (!(STATEMENT)) {\ 43 | [NSException raise:NSGenericException format:MSG,## __VA_ARGS__];\ 44 | }\ 45 | } while (0) 46 | #endif 47 | 48 | // For dumping anything to the console 49 | #if defined(LWE_RELEASE_APP_STORE) 50 | #define LWE_LOG(format, ...); 51 | #else 52 | #define LWE_LOG(format, ...) NSLog(format, ## __VA_ARGS__); 53 | #endif -------------------------------------------------------------------------------- /Core/LWERetinaUtils.m: -------------------------------------------------------------------------------- 1 | // LWERetinaUtils.m 2 | // 3 | // Copyright (c) 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import "LWERetinaUtils.h" 21 | #import "LWEUniversalAppHelpers.h" 22 | #import "NSString+LWEResolutionHelpers.h" 23 | 24 | @implementation LWERetinaUtils 25 | 26 | + (BOOL) isRetinaDisplay 27 | { 28 | BOOL returnVal = NO; 29 | // 1. Does the screen respond to "scale"? 30 | // 2. Is the scale 2? 31 | // 3. Is it not an iPad-type device (i.e. it could be scale = 2 because of iPhone app scaling) 32 | if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] && 33 | [[UIScreen mainScreen] scale] == 2) 34 | // ([LWEUniversalAppHelpers deviceType] & kLWEDeviceClassIPad) == 0) 35 | { 36 | returnVal = YES; 37 | } 38 | return returnVal; 39 | } 40 | 41 | + (NSString*) retinaFilenameForName: (NSString *) name 42 | { 43 | return [name stringByAddingRetinaSpecifier]; 44 | } 45 | 46 | // This method tests for Retina before changing the name 47 | // While iOS handles this on reading for us, when we write an image, we need to know 48 | // the right name to name the file (e.g. if we create two versions) 49 | + (NSString*) retinaSafeImageName:(NSString*)name 50 | { 51 | if ([LWERetinaUtils isRetinaDisplay]) 52 | { 53 | return [name stringByAddingRetinaSpecifier]; 54 | } 55 | else 56 | { 57 | return name; 58 | } 59 | } 60 | 61 | @end 62 | -------------------------------------------------------------------------------- /Core/LWERetinaUtils.h: -------------------------------------------------------------------------------- 1 | // LWERetinaUtils.h 2 | // 3 | // Copyright (c) 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import 21 | 22 | 23 | /** 24 | * \brief Utilities for helping work with HD/Retina resolution (iPhone4) 25 | * \details Abstracts a lot of the hard work - so our apps can just use correct images 26 | * depending on their device. 27 | */ 28 | @interface LWERetinaUtils : NSObject 29 | 30 | /** 31 | * \brief Tells you whether or not the device has a retina display 32 | * \return YES if iPhone 4 33 | */ 34 | + (BOOL) isRetinaDisplay; 35 | 36 | /** 37 | * \brief Returns a retina filename for any file name provided 38 | 39 | -- DEPRECATED -- use NSString+LWEResolutionHelpers category method `-stringByAddingRetinaSpecifier` instead. 40 | 41 | * \details Note this method does NO checking for files or retina devices, it is a string processing method ONLY. 42 | * @param name Filename to retina-icize 43 | * @return Filename in retina terms -- e.g. image.png => image@2x.png 44 | */ 45 | + (NSString*) retinaFilenameForName:(NSString *)name __attribute__ ((deprecated)); 46 | 47 | /** 48 | * \brief Returns a filename with the retina naming convention if we have iPhone 4 49 | * \param name Filename of an image 50 | * \return Filename of retina-ready image (if not iPhone 4, returns same as param) 51 | */ 52 | + (NSString*) retinaSafeImageName:(NSString*)name; 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /Network/LWES3Package.m: -------------------------------------------------------------------------------- 1 | // 2 | // LWES3Package.m 3 | // dtcstyle 4 | // 5 | // Created by Rendy Pranata on 11/04/12. 6 | // Copyright (c) 2012 Long Weekend LLC. All rights reserved. 7 | // 8 | 9 | #import "LWES3Package.h" 10 | 11 | @interface LWES3Package () 12 | - (void)setupBucketAndKeyForURL:(NSURL *)url; 13 | @end 14 | 15 | @implementation LWES3Package 16 | @synthesize accessKey, secretKey; 17 | @synthesize bucket, pathToObject; 18 | 19 | #pragma mark - Privates 20 | 21 | - (void)setupBucketAndKeyForURL:(NSURL *)url 22 | { 23 | static NSString * const kAmazonS3URLPattern = @"s3.amazonaws.com"; 24 | 25 | //Make sure that the s3.amazonaws.com is there 26 | NSString *host = [url host]; 27 | LWE_ASSERT_EXC((host), @"host cannot be null. URL passed in as a parameter needs to have http:// in a full path format."); 28 | 29 | NSUInteger startIndex = 0; 30 | NSArray *pathComponents = [url pathComponents]; 31 | NSRange range = [host rangeOfString:kAmazonS3URLPattern]; 32 | NSString *_bucket = nil; 33 | LWE_ASSERT_EXC((range.location != NSNotFound), @"The url pattern doesnt really mimics the s3.amazonaws.com"); 34 | if (range.location != 0) 35 | { 36 | //The bucket is put at front. 37 | //bucket-name.s3.amazon.com 38 | _bucket = [host substringWithRange:(NSRange){0, range.location-1}]; 39 | startIndex = 1; 40 | } 41 | else 42 | { 43 | //Meaning the bucket is in the part of the url. 44 | //s3.amazonaws.com/bucket-name/ 45 | _bucket = [pathComponents objectAtIndex:1]; 46 | startIndex = 2; 47 | } 48 | 49 | NSArray *keys = [pathComponents subarrayWithRange:(NSRange){startIndex, pathComponents.count-startIndex}]; 50 | self.pathToObject = [keys componentsJoinedByString:@"/"]; 51 | self.bucket = _bucket; 52 | } 53 | 54 | #pragma mark - Class Plumbing 55 | 56 | //! Instance method initialiser 57 | - (id) initWithUrl:(NSURL*)url destinationFilepath:(NSString*)filepath 58 | { 59 | self = [super initWithUrl:url destinationFilepath:filepath]; 60 | { 61 | [self setupBucketAndKeyForURL:url]; 62 | } 63 | return self; 64 | } 65 | 66 | //! Initializer, conveninence method autoreleased 67 | + (id) packageWithUrl:(NSURL*)url destinationFilepath:(NSString*)filepath 68 | { 69 | return [[[self alloc] initWithUrl:url destinationFilepath:filepath] autorelease]; 70 | } 71 | 72 | - (void)dealloc 73 | { 74 | self.accessKey = nil; 75 | self.secretKey = nil; 76 | self.bucket = nil; 77 | self.pathToObject = nil; 78 | 79 | [super dealloc]; 80 | } 81 | 82 | @end 83 | -------------------------------------------------------------------------------- /Core/LWEAnalytics.h: -------------------------------------------------------------------------------- 1 | // LWEAnalyticsHelper.h 2 | // 3 | // Copyright (c) 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | 21 | // Uncomment the following lines to enable various analytics trackers 22 | //#define LWE_USE_FLURRY 1 23 | //#define LWE_USE_GAN 1 24 | 25 | #import 26 | 27 | @interface LWEAnalytics : NSObject 28 | 29 | + (void) startSessionWithKey:(NSString *)key; 30 | 31 | /** 32 | * Logs a non-timed event 33 | */ 34 | + (void) logEvent:(NSString *)eventName; 35 | 36 | /** 37 | * Logs a non-timed event with parameters 38 | */ 39 | + (void) logEvent:(NSString*)eventName parameters:(NSDictionary*)userInfo; 40 | 41 | /** 42 | * Logs an error 43 | */ 44 | + (void) logError:(NSString *)errorName message:(NSString *)errorMsg; 45 | 46 | /** 47 | * TODO: DOCME 48 | */ 49 | + (void)setVariableAtIndex:(NSInteger)index withName:(NSString*)name andValue:(NSString*)valueString; 50 | 51 | /** 52 | * wrapper for calling the stop tracker method 53 | * NOOP if not using Google Analytics 54 | */ 55 | + (void) stopTracker; 56 | 57 | /* 58 | log events or errors after session has started 59 | */ 60 | + (void)logEvent:(NSString *)eventName withAction:(NSString*)actionString withLabel:(NSString*)label andValue:(NSInteger)intValue; 61 | 62 | /* 63 | return correct Flurry Class object for 2.x and 3.x API versions 64 | */ 65 | #if defined(LWE_USE_FLURRY) 66 | +(Class)versionSafeFlurryClass; 67 | #endif 68 | 69 | @end -------------------------------------------------------------------------------- /Categories/NSURL+LWEUtilities.m: -------------------------------------------------------------------------------- 1 | // NSURL+LWEUtilities.m 2 | // 3 | // Copyright (c) 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import "NSURL+LWEUtilities.h" 21 | 22 | 23 | @implementation NSURL (LWEUtilities) 24 | 25 | - (NSDictionary *)queryStrings 26 | { 27 | NSString *q = self.query; 28 | LWE_LOG(@"Query String : %@", q); 29 | if ((q != nil)&&([q rangeOfString:@"="].location != NSNotFound)) 30 | { 31 | NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; 32 | BOOL more = NO; 33 | do 34 | { 35 | NSRange section = [q rangeOfString:@"&"]; 36 | more = (section.location != NSNotFound); 37 | NSString *sectionStr = nil; 38 | if (more) 39 | { 40 | sectionStr = [q substringToIndex:section.location]; 41 | q = [q substringFromIndex:section.location + 1]; 42 | } 43 | else 44 | { 45 | sectionStr = q; 46 | } 47 | 48 | NSRange range = [sectionStr rangeOfString:@"="]; 49 | NSString *key = [[NSString alloc] 50 | initWithString:[sectionStr substringToIndex:range.location]]; 51 | NSString *value = [[NSString alloc] 52 | initWithString:[sectionStr substringFromIndex:range.location + 1]]; 53 | 54 | //LWE_LOG(@"key = %@, value = %@", key, value); 55 | [dict setValue:value forKey:key]; 56 | [value release]; 57 | [key release]; 58 | } while (more); 59 | 60 | NSDictionary *result = [NSDictionary dictionaryWithDictionary:dict]; 61 | [dict release]; 62 | return result; 63 | } 64 | return nil; 65 | } 66 | 67 | @end 68 | -------------------------------------------------------------------------------- /Categories/NSArray+LWEEnums.h: -------------------------------------------------------------------------------- 1 | // NSArray+LWEEnums.h 2 | // 3 | // Copyright (c) 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | 21 | /******************************************************** 22 | * NSArray Category for adding enum helper methods 23 | ******************************************************** 24 | * 25 | * How to Use This? 26 | 27 | // 1. In your header file, place an enum declaration in a header file like this 28 | typedef enum { 29 | JPG, 30 | PNG, 31 | GIF, 32 | PVR 33 | } kImageType; 34 | 35 | // 2. Add a macro array of strings corresponding to the enum above 36 | #define kImageTypeArray @"JPEG", @"PNG", @"GIF", @"PowerVR", nil 37 | 38 | // 3. In your implementation add a property to hold the string array 39 | self.imageTypeArray = [NSArray arrayWithObjects:kImageTypeArray]; 40 | 41 | // 4A. You can now do cool things like this ... 42 | [imageTypeArray stringWithEnum:GIF]; // returns @"GIF" 43 | [imageTypeArray enumFromString:@"GIF"]; // returns GIF 44 | [imageTypeArray enumFromString:@"MOV" default:PNG]; // returns PNG 45 | 46 | **/ 47 | 48 | @interface NSArray (LWEEnumExtensions) 49 | 50 | //! Converts a string to an enumVal 51 | - (NSString*) stringWithEnum:(NSInteger)enumVal; 52 | 53 | //! Converts a string from an enumVal and supports passing in a default 54 | - (NSInteger) enumFromString:(NSString*)strVal default: (NSInteger) def; 55 | 56 | //! Converts a string from an enumVal 57 | - (NSInteger) enumFromString:(NSString*)strVal; 58 | 59 | @end 60 | -------------------------------------------------------------------------------- /Core/LWEFile.h: -------------------------------------------------------------------------------- 1 | // LWEFile.h 2 | // 3 | // Copyright (c) 2010, 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | 21 | #import 22 | 23 | typedef enum 24 | { 25 | kLWEFileLocationBundle = 0, // the file is in the bundle 26 | kLWEFileLocationDocuments = 1 // the file is in the documents directory 27 | } kLWEFileLocation; 28 | 29 | @interface LWEFile : NSObject 30 | 31 | + (NSString*) createBundlePathWithFilename:(NSString*) filename; 32 | + (NSString*) createDocumentPathWithFilename:(NSString*) filename; 33 | + (NSString*) createLibraryPathWithFilename:(NSString*) filename; 34 | + (NSString*) createCachesPathWithFilename:(NSString*)filename; 35 | + (NSString*) createTemporaryPathWithFilename:(NSString*) filename; 36 | + (NSString*) applicationDirectory; 37 | 38 | + (BOOL) createDirectoryIfNotExisting:(NSString*)path withIntermediateDirectories:(BOOL)createIntermediates attributes:(NSDictionary *)attributes error:(NSError **)error; 39 | + (BOOL) createDirectory:(NSString*)pathname error:(NSError**)error; 40 | + (BOOL) deleteFile:(NSString*)filename; 41 | + (BOOL) fileExists:(NSString*)filename; 42 | + (BOOL) copyFromBundleWithFilename:(NSString *)source toDocumentsWithFilename:(NSString *)dest shouldOverwrite:(BOOL)overwrite; 43 | + (BOOL) copyFromMainBundleToDocuments:(NSString*)filename shouldOverwrite:(BOOL)overwrite; 44 | + (NSInteger) getTotalDiskSpaceInBytes; 45 | + (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL; 46 | + (BOOL)addSkipBackupAttributeToItemAtPath:(NSString *)path; 47 | 48 | #if defined (LWE_DEBUG) 49 | + (void) printFilesInDirectory:(NSString*)dir; 50 | #endif 51 | @end 52 | -------------------------------------------------------------------------------- /Network/LWEPackage.h: -------------------------------------------------------------------------------- 1 | // LWEPackage.h 2 | // 3 | // Copyright (c) 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import 21 | 22 | @interface LWEPackage : NSObject 23 | 24 | /** 25 | * Designated instance initializer. Pass it a URL and a local filename. 26 | * This method will automatically infer a value for unpackagePath, 27 | * the same directory as the local filepath. 28 | */ 29 | - (id) initWithUrl:(NSURL*)url destinationFilepath:(NSString*)filepath; 30 | 31 | /** 32 | * Designated class initializer. Pass it a URL and a local filename. 33 | * This method will automatically infer a value for unpackagePath, 34 | * the same directory as the local filepath. 35 | */ 36 | + (id) packageWithUrl:(NSURL*)url destinationFilepath:(NSString*)filepath; 37 | 38 | //! The filename of the package, no path. This is the final part of the URL. 39 | - (NSString *) packageFilename; 40 | 41 | //! The name of the package. This is the final part of the URL, stripping the extension. 42 | - (NSString *) packageName; 43 | 44 | //! LWEPackageDownloader sets this to YES if this package has already been unwrapped (downloaded & decompressed). 45 | @property BOOL isUnwrapped; 46 | 47 | //! The URL of the content before downloading 48 | @property (retain) NSURL *packageUrl; 49 | 50 | //! The local filepath where the content will be downloaded to (e.g. this is a local .zip file) 51 | @property (retain) NSString *destinationFilepath; 52 | 53 | //! The local path where the content will be decompressed to (e.g. this is a folder) 54 | @property (retain) NSString *unpackagePath; 55 | 56 | //! A userinfo dictionary, put anything you want in here. 57 | @property (retain) NSDictionary *userInfo; 58 | 59 | @end 60 | -------------------------------------------------------------------------------- /Network/LWEPackage.m: -------------------------------------------------------------------------------- 1 | // LWEPackage.m 2 | // 3 | // Copyright (c) 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import "LWEPackage.h" 21 | 22 | @implementation LWEPackage 23 | 24 | @synthesize packageUrl, destinationFilepath, unpackagePath, isUnwrapped, userInfo; 25 | 26 | //! Instance method initialiser 27 | - (id) initWithUrl:(NSURL*)url destinationFilepath:(NSString*)filepath 28 | { 29 | self = [super init]; 30 | { 31 | self.destinationFilepath = filepath; 32 | self.packageUrl = url; 33 | self.isUnwrapped = NO; 34 | 35 | // This sets the unpackaging to happen as the same dir as the destination file, default behavior 36 | self.unpackagePath = [filepath stringByDeletingLastPathComponent]; 37 | } 38 | return self; 39 | } 40 | 41 | //! Initializer, conveninence method autoreleased 42 | + (id) packageWithUrl:(NSURL*)url destinationFilepath:(NSString*)filepath 43 | { 44 | return [[[self alloc] initWithUrl:url destinationFilepath:filepath] autorelease]; 45 | } 46 | 47 | //! Trims out everything but the filename of the URL to be unwrapped 48 | - (NSString *) packageFilename 49 | { 50 | NSString *returnVal = nil; 51 | NSString *urlString = [self.packageUrl path]; 52 | NSRange range = [urlString rangeOfString:@"/" options:NSBackwardsSearch]; 53 | if (range.location != NSNotFound) 54 | { 55 | returnVal = [urlString substringFromIndex:(range.location+1)]; 56 | } 57 | return returnVal; 58 | } 59 | 60 | //! Trims the extension off of -packageFilename 61 | - (NSString *) packageName 62 | { 63 | return [[self packageFilename] stringByDeletingPathExtension]; 64 | } 65 | 66 | - (void) dealloc 67 | { 68 | [userInfo release]; 69 | [packageUrl release]; 70 | [unpackagePath release]; 71 | [destinationFilepath release]; 72 | [super dealloc]; 73 | } 74 | 75 | @end 76 | -------------------------------------------------------------------------------- /UI/Views/LWEFormDatePickerField.m: -------------------------------------------------------------------------------- 1 | // 2 | // LWEFormDatePickerField.m 3 | // Swinburne 4 | // 5 | // Created by Mark Makdad on 7/26/11. 6 | // Copyright 2011 th. All rights reserved. 7 | // 8 | 9 | #import "LWEFormDatePickerField.h" 10 | 11 | @implementation LWEFormDatePickerField 12 | 13 | @synthesize inputView, inputAccessoryView, doneButton, maximumDate, minimumDate, date; 14 | 15 | #pragma mark - Class Plumbing (init & dealloc) 16 | 17 | - (void) dealloc 18 | { 19 | // Another case where we HAVE to nil out the pointers 20 | self.maximumDate = nil; 21 | self.minimumDate = nil; 22 | self.date = nil; 23 | self.inputView = nil; 24 | self.inputAccessoryView = nil; 25 | self.doneButton = nil; 26 | [super dealloc]; 27 | } 28 | 29 | - (id) initWithCoder:(NSCoder *)aDecoder 30 | { 31 | self = [super initWithCoder:aDecoder]; 32 | if (self) 33 | { 34 | self.date = [NSDate date]; 35 | 36 | UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; 37 | toolbar.barStyle = UIBarStyleBlack; 38 | self.inputAccessoryView = toolbar; 39 | [toolbar release]; 40 | 41 | UIDatePicker *picker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 0, 320, 216)]; 42 | picker.datePickerMode = UIDatePickerModeDate; 43 | [picker addTarget:self action:@selector(pickerValueChanged:) forControlEvents:UIControlEventValueChanged]; 44 | 45 | self.inputView = picker; 46 | [picker release]; 47 | } 48 | return self; 49 | } 50 | 51 | - (void) pickerValueChanged:(UIDatePicker*)sender 52 | { 53 | // Format the date string 54 | NSDate *aDate = [sender date]; 55 | 56 | // IPAD friendly (3.2) 57 | NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 58 | [formatter setDateStyle:NSDateFormatterMediumStyle]; 59 | [formatter setTimeStyle:NSDateFormatterNoStyle]; 60 | self.text = [formatter stringFromDate:aDate]; 61 | [formatter release]; 62 | // iOS4+ 63 | // self.text = [NSDateFormatter localizedStringFromDate:date dateStyle:NSDateFormatterMediumStyle timeStyle:NSDateFormatterNoStyle]; 64 | } 65 | 66 | - (void) setDate:(NSDate *)aDate animated:(BOOL)animated 67 | { 68 | self.date = aDate; 69 | UIDatePicker *picker = (UIDatePicker*)self.inputView; 70 | [picker setDate:aDate animated:animated]; 71 | } 72 | 73 | - (BOOL) becomeFirstResponder 74 | { 75 | // Put the done button on the right side. 76 | UIBarButtonItem *blankSpace = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] autorelease]; 77 | 78 | UIToolbar *toolbar = (UIToolbar*)self.inputAccessoryView; 79 | toolbar.items = [NSArray arrayWithObjects:blankSpace,self.doneButton,nil]; 80 | 81 | // Pass along these attributes before showing the picker 82 | UIDatePicker *picker = (UIDatePicker*)self.inputView; 83 | picker.maximumDate = self.maximumDate; 84 | picker.minimumDate = self.minimumDate; 85 | picker.date = self.date; 86 | 87 | return [super becomeFirstResponder]; 88 | } 89 | 90 | @end 91 | -------------------------------------------------------------------------------- /UI/Views/LWETooltipView/LWECalloutView.h: -------------------------------------------------------------------------------- 1 | // 2 | // LWECalloutView.h 3 | // LocationBasedMessaging 4 | // 5 | // Created by Mark Makdad on 7/15/10. 6 | // Copyright 2010 Long Weekend Inc. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LWETooltipConstants.h" 11 | 12 | /** 13 | * \class LWECalloutView 14 | * \brief Draws a callout view (a triangle), intended to be used by LWETooltipView 15 | * \details This class should not be instantiated directly, but used as part of LWETooltipView 16 | */ 17 | @interface LWECalloutView : UIView 18 | { 19 | //! Color to stroke with 20 | UIColor *strokeColor; 21 | 22 | //! Color to fill path with 23 | UIColor *rectColor; 24 | 25 | //! Width of the path stroke 26 | CGFloat strokeWidth; 27 | 28 | //! Width & height offset of the shadow (should be positive values, negative doesn't seem to work yet) 29 | CGSize shadowOffset; 30 | 31 | @private 32 | LWETooltipCalloutDirection calloutDirection; 33 | LWETooltipCalloutPosition calloutPosition; 34 | LWETooltipCalloutOffset calloutOffset; 35 | } 36 | 37 | /** 38 | * \brief Sets the position of the callout in reference to the tooltip 39 | * \param position Enum value in LWETooltipCalloutPosition 40 | * \details Sets the direction that the callout "points" in/from. If you want 41 | the tooltip to appear above the content you're referring to, set this to "bottom" for example. 42 | */ 43 | - (void) setCalloutPosition:(LWETooltipCalloutPosition)position; 44 | 45 | /** 46 | * \brief Sets an arbitrary offset for the callout's location 47 | * \param offset Enum value in LWETooltipCalloutOffset 48 | * \details By default, the callout will be drawn coming from the 49 | 1/4 length, 1/2 length, and/or 3/4 length points on the relevant edge of the tooltip. 50 | If you specify an offset, these points will be shifted left or right 51 | to slightly change where the callout "pointer" points to. 52 | */ 53 | - (void) setCalloutOffset:(LWETooltipCalloutOffset)offset; 54 | 55 | /** 56 | * \brief Sets the angle of the callout graphic 57 | * \param direction Enum value in LWETooltipCalloutDirection 58 | * \details If straight, the callout will be an isoceles triangle pointing straight up. 59 | If one of the other settings, it will be scalene, appearing to 60 | point to the left or the right. 61 | */ 62 | - (void) setCalloutDirection:(LWETooltipCalloutDirection)direction; 63 | 64 | /** 65 | * \brief Sets the fill color 66 | * \param color Any UIColor 67 | */ 68 | - (void) setCalloutFillColor:(UIColor*) color; 69 | 70 | /** 71 | * \brief Sets the shadow's offset from the callout 72 | * \param size Should be a CGSize with positive height/width values 73 | * \details For some reason, we are not yet friendly with negative values (we haven't done it yet) 74 | */ 75 | - (void) setShadowOffset:(CGSize)size; 76 | 77 | @property (nonatomic, retain) UIColor *strokeColor; 78 | @property (nonatomic, retain) UIColor *rectColor; 79 | @property CGFloat strokeWidth; 80 | @property CGSize shadowOffset; 81 | 82 | @end 83 | -------------------------------------------------------------------------------- /Core/LWECrashUtils.m: -------------------------------------------------------------------------------- 1 | // LWECrashUtils.m 2 | // 3 | // Copyright (c) 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import "LWECrashUtils.h" 21 | #import "LWEDebug.h" 22 | #import "LWEUniversalAppHelpers.h" 23 | #import "LWEAnalytics.h" 24 | 25 | #pragma mark - C Functions for FlurryAPI 26 | 27 | /** 28 | * Unhandled exception handler (only installed in adhoc and final app store version) 29 | * Makes the assumption that you're using Flurry in the project. 30 | * For clients running iOS4.0+, it will send a stack trace for all stack frames containing the name 31 | * of your app. 32 | */ 33 | void LWEUncaughtExceptionHandler(NSException *exception) 34 | { 35 | NSString *appBinaryName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleExecutable"]; 36 | NSMutableString *debugInfoStr = [NSMutableString string]; 37 | 38 | // Get device (HW) & version information 39 | [debugInfoStr appendFormat:@"%@,%@;",[LWEUniversalAppHelpers deviceModelString],[[UIDevice currentDevice] systemVersion]]; 40 | 41 | // callStackSymbols only available in iOS4.0+ 42 | if ([exception respondsToSelector:@selector(callStackSymbols)]) 43 | { 44 | NSArray *callstack = [exception callStackSymbols]; 45 | for (NSString *stackFrame in callstack) 46 | { 47 | // We have very limited space on Flurry, so don't log any stack frame that's not our code / hex addresses 48 | NSRange range = [stackFrame rangeOfString:appBinaryName]; 49 | if (range.location != NSNotFound) 50 | { 51 | // Trim out the app name as well as the whitespace 52 | NSString *stackFrameHexOnly = [stackFrame substringFromIndex:(range.location+range.length)]; 53 | NSString *trimmedStackFrame = [stackFrameHexOnly stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; 54 | [debugInfoStr appendFormat:@"%@;",trimmedStackFrame]; 55 | } 56 | } 57 | } 58 | [LWEAnalytics logError:exception.name message:debugInfoStr]; 59 | } 60 | -------------------------------------------------------------------------------- /Core/LWELocalNotifications.m: -------------------------------------------------------------------------------- 1 | // LWELocalNotifications.m 2 | // 3 | // Copyright (c) 2010 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import "LWELocalNotifications.h" 21 | 22 | //! Private 23 | @interface LWELocalNotifications () 24 | + (UILocalNotification*) _prepareNotificationWithMessage:(NSString*)message buttonTitle:(NSString*)buttonTitleOrNil; 25 | @end 26 | 27 | @implementation LWELocalNotifications 28 | 29 | + (void)setApplicationBadgeNumber:(NSInteger)badgeNumber 30 | { 31 | if(badgeNumber < 0) 32 | { 33 | [NSException raise:@"ApplicationBadgeNumberCannotBeZero" format:@""]; 34 | } 35 | 36 | //Set badge number 37 | [[UIApplication sharedApplication] setApplicationIconBadgeNumber:badgeNumber]; 38 | } 39 | 40 | + (UILocalNotification*) _prepareNotificationWithMessage:(NSString*)message buttonTitle:(NSString*)buttonTitleOrNil 41 | { 42 | UILocalNotification *note = [[[UILocalNotification alloc] init] autorelease]; 43 | note.alertBody = message; 44 | note.soundName = UILocalNotificationDefaultSoundName; 45 | // Show action button if we have a title 46 | if (buttonTitleOrNil) 47 | { 48 | note.hasAction = YES; 49 | note.alertAction = buttonTitleOrNil; 50 | } 51 | else 52 | { 53 | note.hasAction = NO; 54 | } 55 | return note; 56 | } 57 | 58 | + (void) scheduleLocalNotificationWithMessage:(NSString *)message buttonTitle:(NSString*)buttonTitleOrNil inTimeIntervalSinceNow:(NSTimeInterval)interval 59 | { 60 | UILocalNotification *note = [LWELocalNotifications _prepareNotificationWithMessage:message buttonTitle:buttonTitleOrNil]; 61 | note.fireDate = [NSDate dateWithTimeIntervalSinceNow:interval]; 62 | [[UIApplication sharedApplication] scheduleLocalNotification:note]; 63 | } 64 | 65 | 66 | + (void) presentLocalNotificationWithMessage:(NSString*)message buttonTitle:(NSString*)buttonTitleOrNil 67 | { 68 | UILocalNotification *note = [LWELocalNotifications _prepareNotificationWithMessage:message buttonTitle:buttonTitleOrNil]; 69 | [[UIApplication sharedApplication] presentLocalNotificationNow:note]; 70 | } 71 | 72 | @end 73 | -------------------------------------------------------------------------------- /UI/LWEUIAlertView.h: -------------------------------------------------------------------------------- 1 | // LWEUIAlertView.h 2 | // 3 | // Copyright (c) 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | 21 | #import 22 | 23 | #define LWE_ALERT_CANCEL_BTN 0 24 | #define LWE_ALERT_OK_BTN 1 25 | 26 | /** 27 | * \brief Helper functions for making standard types of UIAlertViews 28 | * \details Use the static methods in this class to create and then 29 | * immediately show/release different types of UIAlertViews. Also, 30 | * you can use the LWE_ALERT_CANCEL_BTN and LWE_ALERT_OK_BTN constants 31 | * to avoid hard-coding integers into your delegate methods for UIAlertView 32 | */ 33 | @interface LWEUIAlertView : NSObject 34 | 35 | /** 36 | * \brief Shows standard no-network alert view 37 | */ 38 | + (UIAlertView*) noNetworkAlert; 39 | 40 | /** 41 | * \brief Shows standard no-network alert view with delegate 42 | */ 43 | + (UIAlertView*) noNetworkAlertWithDelegate:(id)delegate; 44 | 45 | /** 46 | * \brief Shows an "OK" alert notification 47 | */ 48 | + (UIAlertView*) notificationAlertWithTitle:(NSString*)title message:(NSString*)message; 49 | 50 | /** 51 | * \brief Shows an "OK" alert notification (with delegate) 52 | */ 53 | + (UIAlertView*) notificationAlertWithTitle:(NSString*)title message:(NSString*)message delegate:(id)delegate; 54 | 55 | /** 56 | * \brief Shows a Cancel/OK confirmation alert with standard OK/Cancel 57 | */ 58 | + (UIAlertView*) confirmationAlertWithTitle:(NSString*)title message:(NSString*)message delegate:(id)delegate; 59 | 60 | /** 61 | * \brief Shows a Cancel/OK confirmation alert with customized OK/Cancel 62 | */ 63 | + (UIAlertView*) confirmationAlertWithTitle:(NSString*)title message:(NSString*)message ok:(NSString*)ok cancel:(NSString*)cancel delegate:(id)delegate; 64 | 65 | /** 66 | * \brief Shows a Cancel/OK confirmation alert with customized OK/Cancel and takes an optional tag for the alert view 67 | */ 68 | + (UIAlertView*) confirmationAlertWithTitle:(NSString*)title message:(NSString*)message ok:(NSString*)ok cancel:(NSString*)cancel delegate:(id)delegate tag:(int)tag; 69 | 70 | @end 71 | -------------------------------------------------------------------------------- /UI/Views/LWEFormView.h: -------------------------------------------------------------------------------- 1 | // 2 | // LWEFormView.h 3 | // phone 4 | // 5 | // Created by Mark Makdad on 7/19/11. 6 | // Copyright 2011 Long Weekend LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "NSString+LWETextValidator.h" 11 | 12 | @class LWEFormView; 13 | 14 | /** 15 | * Any object that you try to add as a "field" must conform to 16 | * this protocol (specifically, it has a delegate) 17 | */ 18 | @protocol LWEFormViewFieldProtocol 19 | - (id) delegate; 20 | - (void) setDelegate:(id)aDelegate; 21 | @end 22 | 23 | /** 24 | * Any client of the LWEFormView needs to implement this protocol 25 | * to tell the form view what view it should be adjusting. We could 26 | * theoretically get this data through the view hierarchy, but there 27 | * are way too many permutations -- table views, scroll views, et al - 28 | * let the end customer decide. 29 | * 30 | * If the client does not implement this protocol, the LWEFormView itself is scrolled. 31 | */ 32 | @protocol LWEFormViewDelegate 33 | @optional 34 | - (UIView*) scrollingViewForFormView:(LWEFormView*)formView; 35 | - (BOOL) formShouldBeginEditing:(LWEFormView *)formView; 36 | - (void) formWillBeginEditing:(LWEFormView*)formView; 37 | - (void) formDidFinishEditing:(LWEFormView*)formView; 38 | - (void) formDidChangeFirstResponder:(LWEFormView*)formView; 39 | - (BOOL) formField:(id)field shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString*)text; 40 | 41 | - (LWETextValidationTypes) validationTypesForField:(UIControl*)field; 42 | - (NSInteger) maximumLengthForField:(UIControl*)field; 43 | @end 44 | 45 | /** 46 | * View container that holds 1 or more UITextView or UITextField views. 47 | * If you put those text views inside of the LWEFormView, this class will 48 | * automatically scroll the superview to make sure that the form controls 49 | * are always visible above the keyboard. 50 | * 51 | * To set the "tab stops" (form order), either (a) set the .tag property 52 | * of each field in numeric order, or (b) add the fields as subviews 53 | * in the order that you want to "tab" through them. 54 | */ 55 | @interface LWEFormView : UIScrollView 56 | { 57 | BOOL _formIsDirty; 58 | } 59 | 60 | - (void) hideKeyboard; 61 | - (void) hideKeyboardAndResetScroll; 62 | - (void) scrollToOrigin; 63 | 64 | //! Delegate for asking about which view to scroll 65 | @property (assign) IBOutlet id delegate; 66 | 67 | //! Returns YES if any of the form items have been edited - even if they've been restored 68 | @property (readonly) BOOL formIsDirty; 69 | 70 | //! Order of the form elements, sorted by tag and/or the order the subview was added. 71 | @property (retain) NSArray *fieldsSortedByTag; 72 | 73 | //! How long the animation should last. The default is 0.5 seconds. 74 | @property CGFloat animationInterval; 75 | 76 | //! How many points the view should pad at the top of the scrolling (more = active form field is down farther) 77 | @property CGFloat topPadding; 78 | 79 | @end 80 | 81 | #define kLWEMaxCharacters 255 82 | //#define kLWEMaxDescriptionCharacters 500 -------------------------------------------------------------------------------- /Categories/UIScrollView+LWEUtilities.m: -------------------------------------------------------------------------------- 1 | // LWEScrollView.m 2 | // 3 | // Copyright (c) 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import "UIScrollView+LWEUtilities.h" 21 | 22 | @implementation UIScrollView (LWEUtilities) 23 | 24 | - (void) resizeScrollViewWithContentView:(UIView *)view 25 | { 26 | // Sets the scroll view content size to be the same as the content view & reset view 27 | self.contentSize = view.frame.size; 28 | self.contentOffset = CGPointZero; 29 | 30 | // Vertically align the view 31 | if (view.frame.size.height < self.frame.size.height) 32 | { 33 | CGFloat yOffset = ((self.frame.size.height - view.frame.size.height) / 2); 34 | view.frame = CGRectMake(view.frame.origin.x, 35 | yOffset, 36 | view.frame.size.width, 37 | view.frame.size.height); 38 | } 39 | } 40 | 41 | 42 | 43 | /*! 44 | @method 45 | @abstract Sets up a scrollview to scoll horizontally through an array of views 46 | @discussion Assumes you have provided views that will fit within the scrollview provided. 47 | */ 48 | - (void)setupWithDelegate:(id)theDelegate forViews:(NSArray *)views withTopPadding:(float)topPadding withBottomPadding:(float)bottomPadding withLeftPadding:(float)leftPadding withRightPadding:(float)rightPadding; 49 | { 50 | self.delegate = theDelegate; 51 | 52 | self.canCancelContentTouches = NO; 53 | 54 | self.clipsToBounds = YES; 55 | self.scrollEnabled = YES; 56 | 57 | CGFloat cx = 0.0f; 58 | 59 | for (UIView *viewToAddToScrollView in views) 60 | { 61 | CGRect rect = viewToAddToScrollView.frame; 62 | cx += leftPadding; 63 | rect.origin.x = cx; 64 | rect.origin.y = ((self.frame.size.height - viewToAddToScrollView.frame.size.height) / 2); 65 | viewToAddToScrollView.frame = rect; 66 | cx += rect.size.width; 67 | 68 | // add the new view as a subview for the scroll view to handle 69 | [self addSubview:viewToAddToScrollView]; 70 | } 71 | cx += rightPadding; 72 | 73 | self.contentSize = CGSizeMake(cx, self.bounds.size.height - topPadding - bottomPadding); 74 | } 75 | 76 | @end 77 | -------------------------------------------------------------------------------- /Categories/UILabel+LWEUtilities.m: -------------------------------------------------------------------------------- 1 | // LWEUILabelUtils.m 2 | // 3 | // Copyright (c) 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import "UILabel+LWEUtilities.h" 21 | 22 | //! Contains static convenience methods for dealing with UILabels 23 | @implementation UILabel (LWEUtilities) 24 | 25 | //! Resize font within constraints, works with multi-line labels. 26 | - (void) resizeWithMinFontSize:(NSInteger)minFontSize maxFontSize:(NSInteger)maxFontSize 27 | { 28 | LWE_ASSERT_EXC(minFontSize <= maxFontSize, @"Min font size must be less or equal to max font size."); 29 | UIFont *newFont = self.font; 30 | CGRect newFrame = self.frame; 31 | CGSize expectedLabelSize = CGSizeZero; 32 | CGSize parentViewSize = self.superview.frame.size; 33 | 34 | // Initialize 35 | expectedLabelSize.height = 0; 36 | 37 | // Loop from Max Font to Min Font Size until one fits, or scrolling is inevitable 38 | for (NSInteger i = maxFontSize; i > minFontSize; i=i-2) 39 | { 40 | // Set next font size - constraining the width & passing unlimited height is the way to get good values 41 | newFont = [newFont fontWithSize:i]; 42 | CGSize constraintSize = self.frame.size; 43 | constraintSize.width = constraintSize.width; 44 | constraintSize.height = CGFLOAT_MAX; 45 | expectedLabelSize = [self.text sizeWithFont:newFont constrainedToSize:constraintSize lineBreakMode:self.lineBreakMode]; 46 | 47 | // Break if this fontsize fits within the available scrollable height? 48 | if (expectedLabelSize.height < parentViewSize.height) 49 | { 50 | break; 51 | } 52 | } 53 | newFrame.size.height = expectedLabelSize.height; 54 | self.frame = newFrame; 55 | self.font = newFont; 56 | [self setNeedsDisplay]; 57 | } 58 | 59 | //! Makes a frame for a text based on provided width, margin, and font size 60 | - (void) adjustFrameWithFontSize:(NSInteger)fontSize cellWidth:(NSInteger)width cellMargin:(NSInteger)margin 61 | { 62 | CGSize constraint = CGSizeMake(width - (margin * 2), CGFLOAT_MAX); 63 | CGSize size = [self.text sizeWithFont:[UIFont systemFontOfSize:fontSize] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap]; 64 | self.frame = CGRectMake(margin, margin, width - (margin * 2), MAX(size.height, 44.0f)); 65 | [self setNeedsDisplay]; 66 | } 67 | 68 | @end -------------------------------------------------------------------------------- /Core/LWEImageUtils.h: -------------------------------------------------------------------------------- 1 | // LWEImageUtils.h 2 | // 3 | // Copyright (c) 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import 21 | 22 | /** 23 | * \brief Simple struct to hold a size and a transform matrix 24 | * \field transform CGAffineTransform matrix that should be applied 25 | * \field size New CGSIze of the image after orientation transformation 26 | */ 27 | typedef struct LWEOrientationTransform 28 | { 29 | CGAffineTransform transform; 30 | CGSize size; 31 | } LWEOrientationTransform; 32 | 33 | @interface LWEImageUtils : NSObject 34 | 35 | /** 36 | * \brief Resizes a UIImage to the given dimensions 37 | * \param image A UIImage to resize 38 | * \param width New width of the image 39 | * \param height New height of the image 40 | * \param quality integer/constant defining resize quality 41 | * \return A new UIImage object at the new dimensons 42 | * \details Uses a very low quality interpolation to resize quickly 43 | */ 44 | + (UIImage *)resizeImage:(UIImage *)image width:(CGFloat)width height:(CGFloat)height withQuality:(int)quality; 45 | 46 | 47 | /** 48 | * \brief Alias to resizer that does not require a quality setting (defaults to medium) 49 | * \param image A UIImage to resize 50 | * \param width New width of the image 51 | * \param height New height of the image 52 | * \return A new UIImage object at the new dimensons 53 | * \details Uses a very low quality interpolation to resize quickly 54 | */ 55 | + (UIImage *)resizeImage:(UIImage *)image width:(CGFloat)width height:(CGFloat)height; 56 | 57 | 58 | /** 59 | * \brief Alias to resizer that crops if the image scale doesn't match 60 | */ 61 | + (UIImage*)resizeImage:(UIImage*)image byScalingAndCroppingForSize:(CGSize)targetSize; 62 | 63 | /** 64 | * \brief Detects the orientation of an image and returns a transformation struct that will rotate/scale it to "up" (normal orientation) 65 | * \param image A UIImage 66 | * \return A struct containing the CGAffineTransform matrix struct and the new CGSize struct 67 | */ 68 | + (LWEOrientationTransform) orientationTransformForImage:(UIImage *)image; 69 | 70 | 71 | /** 72 | * \brief Rotates a UIImage 73 | * \param image An image to rotate 74 | * \return Another UIImage, rotated 75 | */ 76 | + (UIImage *) rotateImage:(UIImage *)image; 77 | 78 | 79 | @end 80 | -------------------------------------------------------------------------------- /Categories/NSString+LWETextValidator.m: -------------------------------------------------------------------------------- 1 | // NSString+LWETextValidator.m 2 | // 3 | // Copyright (c) 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import "NSString+LWETextValidator.h" 21 | 22 | @implementation NSString (LWETextValidator) 23 | 24 | #pragma mark - Validation 25 | 26 | - (BOOL) containsOnlyCharactersInString:(NSString*)characterString 27 | { 28 | NSCharacterSet *invalidCharSet = [[NSCharacterSet characterSetWithCharactersInString:characterString] invertedSet]; 29 | NSString *filtered = [[self componentsSeparatedByCharactersInSet:invalidCharSet] componentsJoinedByString:@""]; 30 | return [self isEqualToString:filtered]; 31 | } 32 | 33 | - (BOOL) isWithinCharacterCount:(NSInteger)maxLen 34 | { 35 | return (maxLen >= self.length); 36 | } 37 | 38 | - (BOOL) passesValidationType:(LWETextValidationTypes)validationTypes 39 | { 40 | return [self passesValidationType:validationTypes maxLength:kLWETextValidatorDefaultMaxLength]; 41 | } 42 | 43 | - (BOOL) passesValidationType:(LWETextValidationTypes)validationTypes maxLength:(NSInteger)charCount 44 | { 45 | BOOL result = YES; 46 | if ((validationTypes & LWETextValidationTypeAlphaOnly)) 47 | { 48 | // TODO: MMA - this should be localized for languages other than English 49 | BOOL newResult = [self containsOnlyCharactersInString:@"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz- "]; 50 | result = (result && newResult); 51 | } 52 | 53 | if ((validationTypes & LWETextValidationTypeNumericOnly)) 54 | { 55 | BOOL newResult = [self containsOnlyCharactersInString:@"0123456789"]; 56 | result = (result && newResult); 57 | } 58 | 59 | if ((validationTypes & LWETextValidationTypeEmail)) 60 | { 61 | NSString *regex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}"; 62 | NSPredicate *regexTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex]; 63 | result = (result && [regexTest evaluateWithObject:self]); 64 | } 65 | 66 | if ((validationTypes & LWETextValidationTypePhone)) 67 | { 68 | BOOL newResult = [self containsOnlyCharactersInString:@".+()-0123456789 "]; 69 | result = (result && newResult); 70 | } 71 | 72 | if ((validationTypes & LWETextValidationTypeLength)) 73 | { 74 | BOOL newResult = [self isWithinCharacterCount:charCount]; 75 | result = (result && newResult); 76 | } 77 | 78 | return result; 79 | } 80 | 81 | @end 82 | -------------------------------------------------------------------------------- /UI/Views/LWETooltipView/LWETooltipView.h: -------------------------------------------------------------------------------- 1 | // 2 | // LWETooltipView.h 3 | // LocationBasedMessaging 4 | // 5 | // Created by Rendy Pranata on 26/08/10. 6 | // Copyright 2010 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LWETooltipConstants.h" 11 | #import "LWETooltipParams.h" 12 | 13 | /** 14 | * \class LWETooltipView 15 | * \brief Creates a tooltip-like view with a close button and an optional callout graphic 16 | * \details This view is most similar to the callout view used (privately) in the Maps application. 17 | It is more customizable and extendable, and allows for a custom content view. 18 | It is cofigurable with the LWETooltipParams object which is passed in the init method. 19 | It also consist of the content view which can be constructed with the method calling, and 20 | instantiating this class. 21 | 22 | */ 23 | //! LWE implementation of the tooltip view. It is cofigurable with the LWETooltipParams object which is passed in the init method. It also consist of the content view which can be constructed with the method calling, and instantiating this class. 24 | @interface LWETooltipView : UIView 25 | { 26 | LWETooltipParams *params; //! Object which hold of all the parameter needed in the tool tip, like shadow, stroke width, etc. 27 | UIView *contentView; //! Reference to the tooltip content UIView 28 | id delegate; //! Delegate of this tooltip view, when event in this view fires, it will continue the event through this delegate. 29 | 30 | @private 31 | UIButton *_closeButton; //! Memory representation of the close button in this tooltip view 32 | CGRect _roundRectFrame; //! The rectangle frame of the rounded rectangle of a tooltip 33 | CGRect _calloutRectFrame; //! The rectangle frame of the callout 34 | } 35 | 36 | @property (nonatomic, retain) LWETooltipParams *params; 37 | @property (nonatomic, retain) UIView *contentView; 38 | @property (nonatomic, assign) id delegate; 39 | 40 | /** 41 | * \brief Initialize this tooltip with some parameters required to draw this tooltip, delegate, and its content view 42 | */ 43 | - (id)initWithFrame:(CGRect)frame toolTipParameters:(LWETooltipParams *)toolTipParameters delegate:(id) aDelegate contentView:(UIView *)aContentView; 44 | 45 | /** 46 | * \brief Sets the image for the close button 47 | * \param image A standard UIImage 48 | * \details Also resets the frame for the button based on the image size 49 | */ 50 | - (void)_setCloseButtonImage:(UIImage*)image; 51 | 52 | /** 53 | * \brief Draw the callout in the view with the contecxt ref provided 54 | * \details Takes two parameter which are the context needed to draw the callout 55 | and the callout bases which is the points of the callout. 56 | */ 57 | - (void)_drawCalloutWithContext:(CGContextRef)context andBases:(LWECalloutBases)calloutBases; 58 | 59 | /** 60 | * \brief Draw the rounded rectangle part of a tooltip 61 | * \details Takes the context for drawing as a parameter 62 | */ 63 | - (void)_drawRoundRectWithContext:(CGContextRef)context; 64 | 65 | // Private helper methods 66 | - (LWECalloutBases)_calculateCalloutBases; 67 | - (CGRect)_makeCalloutRectFrame; 68 | - (CGRect)_makeNewRoundRectFrame; 69 | - (CGRect)_makeCloseButtonRectFrame; 70 | - (CGRect)_makeContentViewRect; 71 | - (CGRect)_calibrateRoundedRectBasedOnShadow; 72 | 73 | @end 74 | -------------------------------------------------------------------------------- /UI/LWEViewAnimationUtils.m: -------------------------------------------------------------------------------- 1 | // LWEViewAnimationUtils.m 2 | // 3 | // Copyright (c) 2010, 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import "LWEViewAnimationUtils.h" 21 | 22 | // TODO: make this a string constant instead of a #define MMA 23 | #define kAnimationKey @"transitionViewAnimation" 24 | 25 | //! Helper class to take some of the heavy lifting out of animating views 26 | @implementation LWEViewAnimationUtils 27 | 28 | 29 | //! Translation animate a view from current location to new location by adding the values contained in point 30 | + (void) translateView:(UIView*)view byPoint:(CGPoint)point withInterval:(float)delay 31 | { 32 | [UIView beginAnimations:nil context:nil]; 33 | [UIView setAnimationDuration:delay]; 34 | CGAffineTransform transform = CGAffineTransformMakeTranslation(point.x, point.y); 35 | view.transform = transform; 36 | [UIView commitAnimations]; 37 | } 38 | 39 | // Transition between cards after a button has been pressed 40 | + (void) doViewTransition:(NSString *)transition direction:(NSString *)direction duration:(float)duration objectToTransition:(UIViewController *)controllerToTransition 41 | { 42 | UIView *theWindow = [controllerToTransition.view superview]; 43 | [UIView beginAnimations:nil context:NULL]; 44 | 45 | // set up an animation for the transition between the views 46 | CATransition *animation = [CATransition animation]; 47 | [animation setDelegate:controllerToTransition]; 48 | [animation setDuration:duration]; 49 | [animation setType:transition]; 50 | [animation setSubtype:direction]; 51 | [animation setRemovedOnCompletion:YES]; 52 | [[theWindow layer] addAnimation:animation forKey:kAnimationKey ]; 53 | [UIView commitAnimations]; 54 | } 55 | 56 | //! Fades in a given view over a given duration. The view ends up with an alpha of 1 and IS added to the superview 57 | + (void) fadeInView:(UIView*)theView intoView:(UIView*)superview fadeDuration:(CGFloat)duration 58 | { 59 | [superview addSubview:theView]; 60 | [theView setAlpha:0]; 61 | [UIView beginAnimations:nil context:NULL]; 62 | [UIView setAnimationDuration:duration]; 63 | [theView setAlpha:1]; 64 | [UIView commitAnimations]; 65 | } 66 | 67 | //! Fades out a given view over a given duration. The view ends up with an alpha of 0 but is NOT removed from the superview 68 | + (void) fadeOutView:(UIView*)theView fadeDuration:(CGFloat)duration 69 | { 70 | // fade the view out to alpha 0 over a duration 71 | [UIView beginAnimations:nil context:NULL]; 72 | [UIView setAnimationDuration:duration]; 73 | [theView setAlpha:0]; 74 | [UIView commitAnimations]; 75 | } 76 | 77 | 78 | 79 | 80 | @end 81 | -------------------------------------------------------------------------------- /Keychain/KeychainItemWrapper.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: KeychainItemWrapper.h 3 | Abstract: 4 | Objective-C wrapper for accessing a single keychain item. 5 | 6 | Version: 1.2 7 | 8 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 9 | Inc. ("Apple") in consideration of your agreement to the following 10 | terms, and your use, installation, modification or redistribution of 11 | this Apple software constitutes acceptance of these terms. If you do 12 | not agree with these terms, please do not use, install, modify or 13 | redistribute this Apple software. 14 | 15 | In consideration of your agreement to abide by the following terms, and 16 | subject to these terms, Apple grants you a personal, non-exclusive 17 | license, under Apple's copyrights in this original Apple software (the 18 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 19 | Software, with or without modifications, in source and/or binary forms; 20 | provided that if you redistribute the Apple Software in its entirety and 21 | without modifications, you must retain this notice and the following 22 | text and disclaimers in all such redistributions of the Apple Software. 23 | Neither the name, trademarks, service marks or logos of Apple Inc. may 24 | be used to endorse or promote products derived from the Apple Software 25 | without specific prior written permission from Apple. Except as 26 | expressly stated in this notice, no other rights or licenses, express or 27 | implied, are granted by Apple herein, including but not limited to any 28 | patent rights that may be infringed by your derivative works or by other 29 | works in which the Apple Software may be incorporated. 30 | 31 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 32 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 33 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 34 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 35 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 36 | 37 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 38 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 39 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 40 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 41 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 42 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 43 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 44 | POSSIBILITY OF SUCH DAMAGE. 45 | 46 | Copyright (C) 2010 Apple Inc. All Rights Reserved. 47 | 48 | */ 49 | 50 | #import 51 | 52 | /* 53 | The KeychainItemWrapper class is an abstraction layer for the iPhone Keychain communication. It is merely a 54 | simple wrapper to provide a distinct barrier between all the idiosyncracies involved with the Keychain 55 | CF/NS container objects. 56 | */ 57 | @interface KeychainItemWrapper : NSObject 58 | { 59 | NSMutableDictionary *keychainItemData; // The actual keychain item data backing store. 60 | NSMutableDictionary *genericPasswordQuery; // A placeholder for the generic keychain item query used to locate the item. 61 | } 62 | 63 | @property (nonatomic, retain) NSMutableDictionary *keychainItemData; 64 | @property (nonatomic, retain) NSMutableDictionary *genericPasswordQuery; 65 | 66 | // Designated initializer. 67 | - (id)initWithIdentifier: (NSString *)identifier accessGroup:(NSString *) accessGroup; 68 | - (void)setObject:(id)inObject forKey:(id)key; 69 | - (id)objectForKey:(id)key; 70 | 71 | // Initializes and resets the default generic keychain item data. 72 | - (void)resetKeychainItem; 73 | 74 | @end -------------------------------------------------------------------------------- /UI/LWEUITableUtils.m: -------------------------------------------------------------------------------- 1 | // LWEUITabelUtils.m 2 | // 3 | // Copyright (c) 2010, 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import "LWEUITableUtils.h" 21 | 22 | //! Helper class containing static methods to help manage UITableViews 23 | @implementation LWEUITableUtils 24 | 25 | //! Returns a new UITableViewCell - automatically determines whether new or off the queue 26 | + (UITableViewCell*) reuseCellForIdentifier: (NSString*) identifier onTable:(UITableView*) lclTableView usingStyle:(UITableViewCellStyle)style 27 | { 28 | UITableViewCell *cell = [lclTableView dequeueReusableCellWithIdentifier:identifier]; 29 | if (cell == nil) 30 | { 31 | cell = [[[UITableViewCell alloc] initWithStyle:style reuseIdentifier:identifier] autorelease]; 32 | } 33 | return cell; 34 | } 35 | 36 | 37 | //! Sets the frame to the hieght needed for a given text size. Used in conjunction with reuseBlankLabelCellForIdentifier 38 | + (void)autosizeFrameForBlankLabel:(UILabel*)label forText:(NSString*)text 39 | { 40 | CGFloat height = [LWEUITableUtils autosizeHeightForCellWithText:text] - (LWE_UITABLE_CELL_CONTENT_MARGIN * 2); 41 | [label setFrame:CGRectMake(LWE_UITABLE_CELL_CONTENT_MARGIN, LWE_UITABLE_CELL_CONTENT_MARGIN, LWE_UITABLE_CELL_CONTENT_WIDTH - (LWE_UITABLE_CELL_CONTENT_MARGIN * 2), MAX(height, 44.0f))]; 42 | } 43 | 44 | /** 45 | * Called autosizeHeightForCellWithText:fontSize:cellWidth:cellMargin: with default parameters for everything 46 | */ 47 | + (CGFloat) autosizeHeightForCellWithText:(NSString *)text 48 | { 49 | return [LWEUITableUtils autosizeHeightForCellWithText:text fontSize:LWE_UITABLE_CELL_FONT_SIZE cellWidth:LWE_UITABLE_CELL_CONTENT_WIDTH cellMargin:LWE_UITABLE_CELL_CONTENT_MARGIN]; 50 | } 51 | 52 | /** 53 | * Called autosizeHeightForCellWithText:fontSize:cellWidth:cellMargin: with default parameters for 54 | * cellWidth & cellMargin 55 | */ 56 | + (CGFloat) autosizeHeightForCellWithText:(NSString *)text fontSize:(NSInteger)fontSize 57 | { 58 | return [LWEUITableUtils autosizeHeightForCellWithText:text fontSize:fontSize cellWidth:LWE_UITABLE_CELL_CONTENT_WIDTH cellMargin:LWE_UITABLE_CELL_CONTENT_MARGIN]; 59 | } 60 | 61 | /** 62 | * Returns the assumed proper height for a cell to fit all text at a given size 63 | * \param text NSString containing the text to be sized 64 | * \param fontSize Integer with the font size in points 65 | * \param width Total width of the cell 66 | * \param margin Margin to use inside the cell (padding) 67 | */ 68 | + (CGFloat) autosizeHeightForCellWithText:(NSString*)text fontSize:(NSInteger)fontSize cellWidth:(NSInteger)width cellMargin:(NSInteger)margin 69 | { 70 | CGSize constraint = CGSizeMake(width - (margin * 2), 20000.0f); 71 | CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:fontSize] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap]; 72 | CGFloat height = MAX(size.height, 44.0f); 73 | return height + (margin * 2); 74 | } 75 | 76 | @end 77 | -------------------------------------------------------------------------------- /Categories/NSArray+FindNearestIndexInOtherArray.m: -------------------------------------------------------------------------------- 1 | // NSArray+FindNearestIndexInOtherArray.m 2 | // 3 | // Copyright (c) 2012 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import "NSArray+FindNearestIndexInOtherArray.h" 21 | 22 | @implementation NSArray (FindNearestIndexInOtherArray) 23 | 24 | /** 25 | * Finds nearest object in one array (self) that exists in another given array (otherArray). 26 | * Useful for UITableView indexes that display more section letters than there are sections for. 27 | * Searches forward or backward from the specified index and chooses the "closest" one. 28 | * 29 | * Returns NSNotFound is no match was found. Uses [NSObject isEqual:] method for comparison. 30 | * 31 | * @params object The index in array "self" to the object we want matched in the other array 32 | * @params otherArray The other array, containing potentially fewer objects, fro which we want the nearest match 33 | */ 34 | -(NSInteger)findNearestIndex:(NSInteger)index inOtherArray:(NSArray*)otherArray 35 | { 36 | NSArray *sourceArray = self; 37 | NSString *targetObject = [self objectAtIndex:index]; // the object we want 38 | NSInteger startIdx = index; // index of letter we want (e.g. @"D") 39 | 40 | NSInteger fwdSteps = 0; 41 | NSInteger fwdMatchIdx = NSIntegerMax; 42 | 43 | // loop forwards until we find a matching letter 44 | for (int targetIdx = startIdx; targetIdx < [sourceArray count]; targetIdx++) 45 | { 46 | targetObject = [sourceArray objectAtIndex:targetIdx]; 47 | if([otherArray containsObject:targetObject]) 48 | { 49 | fwdMatchIdx = [otherArray indexOfObject:targetObject]; 50 | break; 51 | } 52 | fwdSteps++; 53 | } 54 | 55 | NSInteger bkwdSteps = 0; 56 | NSInteger bkwdMatchIdx = NSIntegerMax; 57 | 58 | if(startIdx-1 > 0) 59 | { 60 | // loop backwards until we find a matching letter 61 | for (int targetIdx = startIdx-1; targetIdx >= 0; targetIdx--) 62 | { 63 | targetObject = [sourceArray objectAtIndex:targetIdx]; 64 | if([otherArray containsObject:targetObject]) 65 | { 66 | bkwdMatchIdx = [otherArray indexOfObject:targetObject]; 67 | break; 68 | } 69 | bkwdSteps++; 70 | } 71 | } 72 | 73 | BOOL bkwdMatchFound = (bkwdMatchIdx != NSIntegerMax); 74 | BOOL fwdMatchFound = (fwdMatchIdx != NSIntegerMax); 75 | BOOL fwdMatchNearest = (fwdSteps <= bkwdSteps); 76 | 77 | // if a fwd match is found in less/equal steps, show it 78 | if((fwdMatchFound && fwdMatchNearest) || (fwdMatchFound && bkwdMatchFound == NO)) 79 | { 80 | //LWE_LOG(@"** fwd match used (in %d steps) **", fwdSteps); 81 | return fwdMatchIdx; 82 | } 83 | // otherwise show a backwards match 84 | else if(bkwdMatchFound) 85 | { 86 | //LWE_LOG(@"** bkwd match used (in %d steps) **", bkwdSteps); 87 | return bkwdMatchIdx; 88 | } 89 | 90 | // otherwise return NSNotFound 91 | return NSNotFound; 92 | } 93 | 94 | @end 95 | -------------------------------------------------------------------------------- /UI/Views/LWETooltipView/LWERoundedRectView.m: -------------------------------------------------------------------------------- 1 | // 2 | // RoundedRectView.m 3 | // 4 | // Created by Jeff LaMarche on 11/13/08. 5 | 6 | #import "LWERoundedRectView.h" 7 | 8 | @implementation LWERoundedRectView 9 | 10 | @synthesize strokeColor; 11 | @synthesize rectColor; 12 | @synthesize strokeWidth; 13 | @synthesize cornerRadius; 14 | @synthesize shadowOffset; 15 | 16 | - (id)initWithCoder:(NSCoder *)decoder 17 | { 18 | if (self = [super initWithCoder:decoder]) 19 | { 20 | self.strokeColor = kDefaultStrokeColor; 21 | self.shadowOffset = CGSizeZero; 22 | self.backgroundColor = [UIColor clearColor]; 23 | self.strokeWidth = kDefaultStrokeWidth; 24 | self.rectColor = kDefaultRectColor; 25 | self.cornerRadius = kDefaultCornerRadius; 26 | } 27 | return self; 28 | } 29 | 30 | - (id)initWithFrame:(CGRect)frame 31 | { 32 | if (self = [super initWithFrame:frame]) 33 | { 34 | // Initialization code 35 | self.opaque = NO; 36 | self.shadowOffset = CGSizeZero; 37 | self.strokeColor = kDefaultStrokeColor; 38 | self.backgroundColor = [UIColor clearColor]; 39 | self.rectColor = kDefaultRectColor; 40 | self.strokeWidth = kDefaultStrokeWidth; 41 | self.cornerRadius = kDefaultCornerRadius; 42 | } 43 | return self; 44 | } 45 | 46 | - (void)drawRect:(CGRect)rect 47 | { 48 | CGFloat shadowX = self.shadowOffset.width; 49 | CGFloat shadowY = self.shadowOffset.height; 50 | 51 | CGContextRef context = UIGraphicsGetCurrentContext(); 52 | CGContextSetLineWidth(context, strokeWidth); 53 | CGContextSetStrokeColorWithColor(context, self.strokeColor.CGColor); 54 | CGContextSetFillColorWithColor(context, self.rectColor.CGColor); 55 | 56 | CGRect rrect = self.bounds; 57 | 58 | // TODO: find out why this matters when we have a stroke? 59 | // rrect.origin.x = rrect.origin.x + 1; 60 | // rrect.origin.y = rrect.origin.y + 1; 61 | // rrect.size.height = rrect.size.height - 1; 62 | // rrect.size.width = rrect.size.width - 1; 63 | 64 | // If we have a shadow other than zero, offset either the size or the origin (move the box) 65 | if (shadowX > 0) 66 | { 67 | rrect.size.width = rrect.size.width - (2 * shadowX); 68 | } 69 | else if (shadowX < 0) 70 | { 71 | rrect.origin.x = rrect.origin.x - (2 * shadowX); 72 | rrect.size.width = rrect.size.width - (2 * shadowX); 73 | } 74 | 75 | if (shadowY > 0) 76 | { 77 | rrect.size.height = rrect.size.height - ( 2 * shadowY); 78 | } 79 | else if (shadowY < 0) 80 | { 81 | rrect.origin.y = rrect.origin.y - ( 2 * shadowY); 82 | rrect.size.height = rrect.size.height - ( 2 * shadowY); 83 | } 84 | 85 | 86 | CGFloat radius = cornerRadius; 87 | CGFloat width = CGRectGetWidth(rrect); 88 | CGFloat height = CGRectGetHeight(rrect); 89 | 90 | // Make sure corner radius isn't larger than half the shorter side 91 | if (radius > width/2.0) 92 | radius = width/2.0; 93 | if (radius > height/2.0) 94 | radius = height/2.0; 95 | 96 | CGFloat minx = CGRectGetMinX(rrect); 97 | CGFloat midx = CGRectGetMidX(rrect); 98 | CGFloat maxx = CGRectGetMaxX(rrect); 99 | CGFloat miny = CGRectGetMinY(rrect); 100 | CGFloat midy = CGRectGetMidY(rrect); 101 | CGFloat maxy = CGRectGetMaxY(rrect); 102 | 103 | CGContextSaveGState(context); 104 | CGContextSetShadow(context, CGSizeMake(shadowX, shadowY), kDefaultShadowBlur); 105 | 106 | CGContextMoveToPoint(context, minx, midy); 107 | CGContextAddArcToPoint(context, minx, miny, midx, miny, radius); 108 | CGContextAddArcToPoint(context, maxx, miny, maxx, midy, radius); 109 | CGContextAddArcToPoint(context, maxx, maxy, midx, maxy, radius); 110 | CGContextAddArcToPoint(context, minx, maxy, minx, midy, radius); 111 | CGContextClosePath(context); 112 | CGContextDrawPath(context, kCGPathFillStroke); 113 | 114 | CGContextRestoreGState(context); 115 | } 116 | 117 | - (void)dealloc 118 | { 119 | [strokeColor release]; 120 | [rectColor release]; 121 | [super dealloc]; 122 | } 123 | 124 | @end 125 | -------------------------------------------------------------------------------- /Categories/NSString+LWETextValidator.h: -------------------------------------------------------------------------------- 1 | // NSString+LWETextValidator.h 2 | // 3 | // Copyright (c) 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import 21 | 22 | // If no vaidation length is specified by the user, but the class is asked to validate length, it will use this value. 23 | #define kLWETextValidatorDefaultMaxLength 50 24 | 25 | /** 26 | * These enums are meant to be bitwise OR'ed together to achieve the desired validation 27 | * scheme. For example, to validate a string as a phone number of less than 20 characters, 28 | * you can call: 29 | * LWETextValidationTypes types = (LWETextValidationTypeLength | LWETextValidationTypePhone); 30 | * [LWETextValidator text:yourText passesValidationTypes:types maxLength:20]; 31 | */ 32 | typedef enum LWETextValidationType 33 | { 34 | LWETextValidationTypeNone = 0, //! No validation performed, the validator returns YES with any string 35 | LWETextValidationTypeLength = 1, //! Validates that the length is equal to or less than a certain count 36 | LWETextValidationTypeAlphaOnly = 2, //! Checks that a string ONLY contains A-Za-z, and hyphen (-) and space. 37 | LWETextValidationTypeNumericOnly = 4, //! Checks that a string ONLY contains 0-9 38 | LWETextValidationTypeEmail = 8, //! Checks the string is a valid email address 39 | LWETextValidationTypePhone = 16, //! Checks that the string contains ONLY 0-9, plus ".+-()" and a space 40 | } LWETextValidationType; 41 | 42 | // When the enums are OR'ed together, they will make some number (NSInteger) - but instead of using 43 | // NSInteger throughout the code we give it a name to make its use clearer (0 or more enum values) 44 | typedef NSInteger LWETextValidationTypes; 45 | 46 | /** 47 | * Helper category to validate text strings against certain predefined validations. 48 | * For example, you can use this class to determine if an email address is valid, or if 49 | * a string contains non-numeric values. 50 | */ 51 | @interface NSString (LWETextValidator) 52 | 53 | /** 54 | * Returns YES if the -length value of the string is equal or less than the number specified by maxLen . 55 | */ 56 | - (BOOL) isWithinCharacterCount:(NSInteger)maxLen; 57 | 58 | /** 59 | * Returns YES if the string contains only characters inside the string passed as a parameter. 60 | */ 61 | - (BOOL) containsOnlyCharactersInString:(NSString*)characterString; 62 | 63 | /** 64 | * Returns YES if the text passes the validators specified by the types passed in (see enum declaration for details) 65 | * If you call this method with a length validation type, it will use the default max length value constant. 66 | */ 67 | - (BOOL) passesValidationType:(LWETextValidationTypes)validationType; 68 | 69 | /** 70 | * Returns YES if the text passes the validators specified by the types passed in (see enum declaration for details) 71 | * If you wish to validate length and specify a max length for the string, use this method. 72 | */ 73 | - (BOOL) passesValidationType:(LWETextValidationTypes)validationType maxLength:(NSInteger)charCount; 74 | 75 | 76 | @end 77 | -------------------------------------------------------------------------------- /UI/Views/LWECloseButtonView.m: -------------------------------------------------------------------------------- 1 | // 2 | // LWECloseButtonView.m 3 | // jFlash 4 | // 5 | // Created by Mark Makdad on 12/12/11. 6 | // Copyright (c) 2011 Long Weekend LLC. All rights reserved. 7 | // 8 | 9 | #import "LWECloseButtonView.h" 10 | 11 | @interface LWECloseButtonView () 12 | //! Is YES when the user is tapping the button 13 | @property BOOL isSelected; 14 | @end 15 | 16 | @implementation LWECloseButtonView 17 | @synthesize isSelected, delegate; 18 | 19 | - (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 20 | { 21 | // Set a bit so we re-draw the button in a selected state 22 | self.isSelected = YES; 23 | [self setNeedsDisplay]; 24 | } 25 | 26 | - (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event 27 | { 28 | // Clear the bit 29 | self.isSelected = NO; 30 | [self setNeedsDisplay]; 31 | } 32 | 33 | - (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 34 | { 35 | if (self.delegate && [self.delegate respondsToSelector:@selector(dismiss)]) 36 | { 37 | [self.delegate dismiss]; 38 | } 39 | // Call -dismiss on the responder chain -- the parent should respond to this (Progress Bar) 40 | [[UIApplication sharedApplication] sendAction:@selector(dismiss) to:nil from:self forEvent:event]; 41 | self.isSelected = NO; 42 | [self setNeedsDisplay]; 43 | } 44 | 45 | #pragma mark - Drawing Code 46 | 47 | - (void)drawRect:(CGRect)rect 48 | { 49 | // Change the color of the button to give it that "pressed" feel when tapped 50 | CGColorRef lightColor = NULL; 51 | if (self.isSelected) 52 | { 53 | lightColor = [[UIColor grayColor] CGColor]; 54 | } 55 | else 56 | { 57 | lightColor = [[UIColor whiteColor] CGColor]; 58 | } 59 | 60 | CGContextRef ctx = UIGraphicsGetCurrentContext(); 61 | 62 | // Because we are stroking, we need a slightly smaller rect so our full border fits 63 | CGRect newRect = CGRectMake(rect.origin.x + CLOSE_BUTTON_VIEW_BORDER_WIDTH, 64 | rect.origin.y + CLOSE_BUTTON_VIEW_BORDER_WIDTH, 65 | rect.size.width - (CLOSE_BUTTON_VIEW_BORDER_WIDTH * 2), 66 | rect.size.height - (CLOSE_BUTTON_VIEW_BORDER_WIDTH * 2)); 67 | 68 | // Set a shadow so our round button has a shadow 69 | CGContextSetShadow(ctx, CLOSE_BUTTON_SHADOW_OFFSET, CLOSE_BUTTON_SHADOW_BLUR); 70 | 71 | // Paint the background black color 72 | CGContextSetFillColorWithColor(ctx, [[UIColor blackColor] CGColor]); 73 | CGContextFillEllipseInRect(ctx, newRect); 74 | 75 | // Now add an ellipse path in the rect for the border 76 | CGContextBeginPath(ctx); 77 | CGContextAddEllipseInRect(ctx, newRect); 78 | CGContextClosePath(ctx); 79 | 80 | // Stroke the path with a white border 81 | CGContextSetLineWidth(ctx, CLOSE_BUTTON_VIEW_BORDER_WIDTH); 82 | CGContextSetStrokeColorWithColor(ctx, lightColor); 83 | CGContextStrokePath(ctx); 84 | 85 | // Set the shadow color to clear so it doesn't show on the text 86 | CGContextSetShadowWithColor(ctx, CGSizeMake(0, 0), 0, [[UIColor clearColor] CGColor]); 87 | 88 | // Figure out where to draw the text - we want it to occupy the center x % of the area 89 | CGFloat yOffset = rect.size.height * CLOSE_BUTTON_VIEW_X_SIZE; 90 | CGFloat xOffset = rect.size.width * CLOSE_BUTTON_VIEW_X_SIZE; 91 | CGRect xRect = CGRectMake(rect.origin.x + xOffset, 92 | rect.origin.y + yOffset, 93 | rect.size.width - (xOffset * 2), 94 | rect.size.height - (yOffset * 2)); 95 | 96 | 97 | // Now draw the X path 98 | CGContextBeginPath(ctx); 99 | CGContextMoveToPoint(ctx, xRect.origin.x, xRect.origin.y); 100 | CGContextAddLineToPoint(ctx, xRect.origin.x+xRect.size.width, xRect.origin.y+xRect.size.height); 101 | CGContextMoveToPoint(ctx, xRect.origin.x, xRect.origin.y+xRect.size.height); 102 | CGContextAddLineToPoint(ctx, xRect.origin.x+xRect.size.width, xRect.origin.y); 103 | 104 | // Stroke it with rounded corners 105 | CGContextSetLineCap(ctx, kCGLineCapRound); 106 | CGContextSetLineWidth(ctx, CLOSE_BUTTON_X_WIDTH); 107 | CGContextStrokePath(ctx); 108 | 109 | } 110 | 111 | @end 112 | -------------------------------------------------------------------------------- /Categories/UIColor+LWEUtilities.m: -------------------------------------------------------------------------------- 1 | // UIColor+LWEUtilities.m 2 | // 3 | // Copyright (c) 2010 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import "UIColor+LWEUtilities.h" 21 | 22 | 23 | @implementation UIColor (LWEUtilities) 24 | 25 | /** 26 | This is the method that will initialize a UIColor with the hexadecimal value. 27 | 28 | This method is currently only supports 24bits color, so please dont give 12bits color 29 | like 0xFFF but instead give it 0xFFFFFF. It might be upgraded, or extended in the future. 30 | But now it is nice to have a 24 bits color converter from hexa to RGB. 31 | 32 | @param hex The color code in hexadecimal, "0x123456". 33 | */ 34 | - (id)initWithHex:(NSInteger)hex 35 | { 36 | return [self initWithHex:hex alpha:1.0f]; 37 | } 38 | 39 | /** 40 | * @brief This is the method that will initialize a UIColor with the hexadecimal NSNumber, and also returns a autorelease color object. 41 | * Keep in mind that the parameter is the hexadecimal so it will be something like [NSNumber numberWithInt:0xFFFFFF] 42 | * @param Color code in hexadecimal 43 | * @details This method is currently only supports 24bits color, so please dont give 12bits color like 0xFFF but instead give it 0xFFFFFF. It might be 44 | * upgraded, or extended in the future. But now it is nice to have a 24 bits color converter from hexa to RGB. 45 | */ 46 | + (id)colorWithHex:(NSInteger)hex 47 | { 48 | UIColor *tmpColor = [[[UIColor alloc] initWithHex:hex alpha:1.0f] autorelease]; 49 | return tmpColor; 50 | } 51 | 52 | //! This method will initialize a color object with the provided hexadecimal number, and alpha (0.0-1.0). (Currently it only supports 24 bits color) 53 | - (id)initWithHex:(NSInteger)hex alpha:(CGFloat)alpha 54 | { 55 | //What it does here is, whatever (and) F should return itself, and whatever (and) 0 should return 0. So first it tries to 56 | //do and (&) operator to take the first two digit for red. second two digit for green, and the rest is for blue. after that, cause 2 digits hexa is 57 | //8 digits binary, we only want the value for those red, green or blue component. so for red, we shift the binary by 16 digits, green by 8 digit, and the 58 | //rest should be blue. (Does not need to shift the binary). By the end of the calculation, it will need to divide the number by 255 (maximum byte), so it will gets 59 | //value between 0.0, and 1.0 (float) 60 | float red = (float) ((hex & 0xFF0000) >> 16) / 255.0f; 61 | float green = (float) ((hex & 0x00FF00) >> 8) / 255.0f; 62 | float blue = (float) ((hex & 0x000FF) >> 0) / 255.0f; 63 | 64 | //after getting the individual color component, it calls the initWithRed:green:blue:alpha: method, and it will return itself. 65 | if (self = [self initWithRed:red green:green blue:blue alpha:alpha]) 66 | { 67 | //possible future customization after initialization 68 | } 69 | return self; 70 | 71 | } 72 | 73 | //! This is the class method, that will call the method above, and give the autorelease object. It will transform the hexadecimal color, into individual red, green, blue color. 74 | + (id)colorWithHex:(NSInteger)hex alpha:(CGFloat)alpha 75 | { 76 | UIColor *tmpColor = [[[UIColor alloc] initWithHex:hex alpha:alpha] autorelease]; 77 | return tmpColor; 78 | } 79 | 80 | @end 81 | -------------------------------------------------------------------------------- /Twitter/LWETwitterEngine.h: -------------------------------------------------------------------------------- 1 | // 2 | // LWETwitterEngine.h 3 | // TrialConsumerOAuthforIPhone 4 | // 5 | // Created by Rendy Pranata on 16/07/10. 6 | // Copyright 2010 Long Weekend LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | #import "LWETDelegates.h" 13 | #import "LWETwitterOAuth.h" 14 | #import "LWETAuthenticationViewProtocol.h" 15 | #import "LWETRequestDelegate.h" 16 | 17 | #import "OAConsumer.h" 18 | #import "OAToken.h" 19 | #import "OARequestParameter.h" 20 | #import "OAMutableURLRequest.h" 21 | #import "OAServiceTicket.h" 22 | #import "OADataFetcher.h" 23 | #import "LWEDebug.h" 24 | #import "LWETUser.h" 25 | #import "LWETUserDB.h" 26 | #import "LWETXAuthViewProtocol.h" 27 | #import "JSON.h" 28 | 29 | #define kServerName @"http://api.twitter.com" 30 | #define kStatusUpdateMethod @"statuses/update" 31 | #define kSearchMethod @"users/search" 32 | #define kFollowMethod @"friendships/create/" 33 | 34 | #define kJSONreturnType @"json" 35 | #define kXMLreturnType @"xml" 36 | #define kTwitterVersion @"1" 37 | 38 | #define kOAUTH @"OAUTH" 39 | #define kXAUTH @"XAUTH" 40 | 41 | extern NSString * const LWETwitterErrorDomain; 42 | 43 | typedef enum 44 | { 45 | LWETwitterErrorUnknown = -1, 46 | LWETwitterErrorUnableToSendTweet = 1 47 | } LWETwitterErrorCode; 48 | 49 | @class OAConsumer; 50 | @class OAToken; 51 | @class OAServiceTicket; 52 | @class OAMutableURLRequest; 53 | @class LWETUser; 54 | @class LWETUserDB; 55 | 56 | //! Twitter request enum type for preparing the request object. 57 | typedef enum 58 | { 59 | LWET_STATUS_UPDATE, 60 | LWET_USER_SEARCH, 61 | LWET_FRIENDSHIP_MAKE 62 | } LWETwitterRequestType; 63 | 64 | //! Possible authentication method. XAuth, or OAuth 65 | typedef enum 66 | { 67 | LWET_AUTH_OAUTH, 68 | LWET_AUTH_XAUTH 69 | } LWETAuthMode; 70 | 71 | /** 72 | * This is the twitter agent class, which is going to be instantiated with the user consumer key, and its 73 | * secret key. It has most of the required twitter capability, like status udate (tweet), search for people, 74 | * or following people. It will gets updated in the near future with heaps of other twitter capability. 75 | * 76 | * It also conforms with the LWETAuthProcessDelegate as the protocol of being the Auth engine delegate, and 77 | * it will gets report from the auth engine whether the auth has finishes, or failed. 78 | */ 79 | @interface LWETwitterEngine : NSObject 80 | 81 | @property (nonatomic, retain) LWETwitterOAuth *authObj; 82 | @property (nonatomic, retain, readonly) LWETUser *loggedUser; 83 | @property (nonatomic, retain) OAConsumer *consumer; 84 | @property (nonatomic, retain) LWETUserDB *db; 85 | @property (nonatomic, retain) NSManagedObjectContext *context; 86 | @property (nonatomic, retain) NSString *tmpForUserID; 87 | @property (nonatomic, retain) UIViewController *authenticationView; 88 | @property (nonatomic, assign) UIViewController *parentForUserAuthenticationView; 89 | @property (nonatomic, assign) NSObject *delegate; 90 | 91 | /** 92 | * Set the user, and logged them on. Check with the core data, wether they have been 93 | * logged in, and has their credential on it, or the engine has to authenticate them by having 94 | * preferred auth mode as the OAuth, or XAuth. 95 | */ 96 | - (void)setLoggedUser:(LWETUser *)aUser authMode:(LWETAuthMode)authMode; 97 | 98 | - (id)initWithConsumerKey:(NSString *)consumerKey privateKey:(NSString *)privateKey; 99 | 100 | - (id)initWithConsumerKey:(NSString *)consumerKey privateKey:(NSString *)privateKey authenticationView:(UIViewController *) controller; 101 | 102 | - (NSString *)methodNameForTwitterRequestType:(LWETwitterRequestType)lwet; 103 | 104 | - (OAMutableURLRequest *)prepareURLForRequestType:(LWETwitterRequestType)lwet 105 | relatedID:(NSString *)str 106 | returnType:(NSString *)retType; 107 | 108 | - (void)statusRequestTokenTicket:(OAServiceTicket *)ticket 109 | didFailWithError:(NSError *)error; 110 | 111 | - (BOOL)_persistUserToken:(OAToken *)userToken; 112 | 113 | //Twitter Core Methods 114 | 115 | - (void)tweet:(NSString *)words; 116 | 117 | - (void)search:(NSString *)people; 118 | 119 | - (void)follow:(NSString *)people; 120 | 121 | - (void)signOutForTheCurrentUser; 122 | 123 | @end 124 | -------------------------------------------------------------------------------- /Data/LWECoreData.h: -------------------------------------------------------------------------------- 1 | // LWECoreData.h 2 | // 3 | // Copyright (c) 2010, 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import 21 | #import 22 | 23 | extern NSString * const LWECoreDataObjectId; 24 | 25 | //! Abstracts common Core Data static method calls 26 | @interface LWECoreData : NSObject 27 | 28 | //! Creates an autoreleased MOC associated with a store coordinator 29 | + (NSManagedObjectContext*) managedObjectContextWithStoreCoordinator:(NSPersistentStoreCoordinator*)coordinator; 30 | 31 | //! Creates an autoreleased persistent store coordinator using the pathname. 32 | + (NSPersistentStoreCoordinator*) persistentStoreCoordinatorFromPath:(NSString*)storePath; 33 | 34 | //! Creates an autoreleased persistent store coordinator using the pathname for a versioned model. 35 | + (NSPersistentStoreCoordinator*) persistentStoreCoordinatorFromPathForVersionedModel:(NSString*)storePath modelNameOrNil:(NSString*)modelName; 36 | 37 | //! Returns 1 object - useful for when you are pulling things out by an ID or something where you are sure there will be one or none. Returns nil if not found. 38 | + (NSManagedObject*) fetchOne:(NSString*)entityName managedObjectContext:(NSManagedObjectContext*)managedObjectContext predicate:(id)stringOrPredicate, ...; 39 | 40 | //! Returns all entities of a given type from a given context (SELECT * FROM x) 41 | + (NSArray *) fetchAll:(NSString *)entityName managedObjectContext:(NSManagedObjectContext *)managedObjectContext; 42 | 43 | //! Returns entities of a given type from a given context with predicate (SELECT * FROM x WHERE y) 44 | + (NSArray *) fetch:(NSString *)entityName managedObjectContext:(NSManagedObjectContext *)managedObjectContext withSortDescriptors:(NSArray *)sortDescriptors predicate:(id)stringOrPredicate, ...; 45 | 46 | //! Returns entities of a given type from a given context with predicate & limit (SELECT * FROM x WHERE y LIMIT z) 47 | + (NSArray *) fetch:(NSString *)entityName managedObjectContext:(NSManagedObjectContext *)managedObjectContext withSortDescriptors:(NSArray *)sortDescriptorsOrNil withLimit:(int)limitOrNil predicate:(id)stringOrPredicate, ...; 48 | 49 | //! Returns the count of entities of a given type from a given context with predicate (SELECT * FROM x WHERE y) 50 | + (NSUInteger) count:(NSString *)entityName managedObjectContext:(NSManagedObjectContext *)managedObjectContext withSortDescriptors:(NSArray *)sortDescriptors predicate:(id)stringOrPredicate, ...; 51 | 52 | //! Returns a NSFetchRequest for entities of a given type from a given context with predicate & limit (SELECT * FROM x WHERE y LIMIT z) 53 | + (NSFetchRequest *) fetchRequest: (NSManagedObjectContext *) managedObjectContext entityName: (NSString *) entityName limitOrNil: (int) limitOrNil sortDescriptorsOrNil: (NSArray *) sortDescriptorsOrNil stringOrPredicate: (id) stringOrPredicate, ...; 54 | 55 | //! Creates or overwrites the attributes of an entity from a plist, returns the saved entity. 56 | + (id) addPlist:(NSString*)path toEntity:(NSString *)entityName identifiedByAttribute:(NSString *)attributeName inManagedContext:(NSManagedObjectContext *)managedObjectContext save:(BOOL)shouldSave; 57 | 58 | //! Saves the current context 59 | + (BOOL) save:(NSManagedObjectContext *)managedObjectContext; 60 | 61 | //! Deletes the provided entity from the object's context 62 | + (BOOL) delete:(NSManagedObject*)entity; 63 | 64 | //! Deletes the provided entity from the provided context 65 | + (BOOL) delete:(NSManagedObject*)entity fromContext:(NSManagedObjectContext *)context; 66 | 67 | @end -------------------------------------------------------------------------------- /Core/LWEAnalytics.m: -------------------------------------------------------------------------------- 1 | // LWEAnalyticsHelper.m 2 | // 3 | // Copyright (c) 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | 21 | #import "LWEAnalytics.h" 22 | #import "LWEDebug.h" 23 | 24 | #if defined(LWE_USE_FLURRY) 25 | #import "FlurryAnalytics.h" 26 | #endif 27 | 28 | #if defined(LWE_USE_GAN) 29 | #import "GANTracker.h" 30 | #endif 31 | 32 | static const NSInteger kGANDispatchPeriodSec = 10; 33 | 34 | @implementation LWEAnalytics 35 | 36 | + (void) startSessionWithKey:(NSString *)key 37 | { 38 | #if defined(LWE_DEBUG) 39 | // Don't do this if we are in DEBUG environment 40 | return; 41 | #endif 42 | 43 | #if defined(LWE_USE_FLURRY) 44 | // start Flurry analytics if live 45 | [[[self class] versionSafeFlurryClass] startSession:key]; 46 | #endif 47 | #if defined(LWE_USE_GAN) 48 | // start Google analytics if live 49 | [[GANTracker sharedTracker] startTrackerWithAccountID:apiKey dispatchPeriod:kGANDispatchPeriodSec delegate:nil]; 50 | #endif 51 | } 52 | 53 | + (void) logEvent:(NSString *)eventName 54 | { 55 | return [[self class] logEvent:eventName parameters:nil]; 56 | } 57 | 58 | + (void) logEvent:(NSString*)eventName parameters:(NSDictionary*)userInfo 59 | { 60 | #if defined(LWE_RELEASE_APP_STORE) || defined(LWE_RELEASE_ADHOC) 61 | #if defined(LWE_USE_FLURRY) 62 | [[[self class] versionSafeFlurryClass] logEvent:eventName withParameters:userInfo]; 63 | #elif defined(LWE_USE_GAN) 64 | NSError *error = nil; 65 | [[GANTracker sharedTracker] trackPageview:[NSString stringWithFormat:@"\%@", eventName] withError:&error]; 66 | // Some GAN code here 67 | #endif 68 | #else 69 | LWE_LOG(@"LWEAnalytics Event: %@",eventName); 70 | LWE_LOG(@"LWEAnalytics Parameters: %@",userInfo); 71 | #endif 72 | } 73 | 74 | #if defined(LWE_USE_FLURRY) 75 | //! Return correct Flurry Class object for 2.x and 3.x API versions 76 | +(Class)versionSafeFlurryClass 77 | { 78 | if(NSClassFromString(@"FlurryAPI")) 79 | { 80 | // Flurry 2.x class type 81 | return NSClassFromString(@"FlurryAPI"); 82 | } 83 | else 84 | { 85 | // Flurry 3.x class type 86 | return NSClassFromString(@"FlurryAnalytics"); 87 | } 88 | } 89 | #endif 90 | 91 | + (void) logError:(NSString *)errorName message:(NSString *)errorMsg 92 | { 93 | #if defined(LWE_RELEASE_APP_STORE) || defined(LWE_RELEASE_ADHOC) 94 | #if defined(LWE_USE_FLURRY) 95 | [[[self class] versionSafeFlurryClass] logError:errorName message:errorMsg exception:nil]; 96 | #elif defined(LWE_USE_GAN) 97 | [[GANTracker sharedTracker] trackPageview:[NSString stringWithFormat:@"\%@", errorName] withError:NULL]; 98 | #endif 99 | #else 100 | LWE_LOG(@"LWEAnalytics ERROR: %@ MSG : %@",errorName,errorMsg); 101 | #endif 102 | } 103 | 104 | //! Log a GAN Event with all details provided 105 | + (void)logEvent:(NSString *)eventName withAction:(NSString*)actionString withLabel:(NSString*)label andValue:(NSInteger)intValue 106 | { 107 | #if defined(LWE_USE_GAN) 108 | [[GANTracker sharedTracker] trackEvent:eventName action:actionString label:label value:intValue withError:NULL] 109 | #endif 110 | } 111 | 112 | //! Set a custom GAN variable, not sure how to use these?!?! 113 | + (void)setVariableAtIndex:(NSInteger)index withName:(NSString*)name andValue:(NSString*)valueString 114 | { 115 | #if defined(LWE_USE_GAN) 116 | [[GANTracker sharedTracker] setCustomVariableAtIndex:index name:name value:valueString withError:NULL]) 117 | #endif 118 | } 119 | 120 | //! Simple wrapper for stopping the tracker 121 | + (void) stopTracker 122 | { 123 | #if defined(LWE_USE_GAN) 124 | [[GANTracker sharedTracker] stopTracker]; 125 | #endif 126 | } 127 | 128 | @end -------------------------------------------------------------------------------- /Twitter/LWETDefaultAuthenticationViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // LWETDefaultAuthenticationViewController.m 3 | // TrialConsumerOAuthforIPhone 4 | // 5 | // Created by Rendy Pranata on 15/07/10. 6 | // Copyright 2010 Long Weekend LLC. All rights reserved. 7 | // 8 | 9 | #import "LWETDefaultAuthenticationViewController.h" 10 | #import "LWEDebug.h" 11 | 12 | @implementation LWETDefaultAuthenticationViewController 13 | 14 | #pragma mark - 15 | #pragma mark LWETAuthenticationView 16 | 17 | @synthesize webView; 18 | @synthesize delegate; 19 | 20 | #pragma mark - 21 | #pragma mark UIWebViewDelegate 22 | 23 | - (void) webView:(UIWebView *)webView 24 | didFailLoadWithError:(NSError *)error 25 | { 26 | LWE_LOG(@"ERROR"); 27 | LWE_LOG(@"%@", [error userInfo]); 28 | } 29 | 30 | - (void) webViewDidFinishLoad:(UIWebView *)aWebView 31 | { 32 | 33 | NSString *script; 34 | script = @"(function() { return document.getElementById(\"oauth_pin\").firstChild.textContent; } ())"; 35 | 36 | NSString *pin = [self.webView stringByEvaluatingJavaScriptFromString:script]; 37 | 38 | if ([pin length] > 0) { 39 | NSLog(@"pin %@", pin); 40 | 41 | if ([delegate respondsToSelector:@selector(didFinishAuthorizationWithPin:)]) 42 | [delegate didFinishAuthorizationWithPin:pin]; 43 | 44 | [self dismissModalViewControllerAnimated:NO]; 45 | } 46 | else 47 | { 48 | [aWebView stringByEvaluatingJavaScriptFromString:@"window.scrollTo(0,350);"]; 49 | } 50 | } 51 | 52 | - (void) webViewDidStartLoad:(UIWebView *)webView 53 | { 54 | LWE_LOG(@"Start Load"); 55 | } 56 | 57 | 58 | 59 | #pragma mark - 60 | #pragma mark UIViewController life cycle 61 | 62 | 63 | // The designated initializer. 64 | // Override if you create the controller programmatically and 65 | // want to perform customization 66 | // that is not appropriate for viewDidLoad. 67 | - (id)initWithNibName:(NSString *)nibNameOrNil 68 | bundle:(NSBundle *)nibBundleOrNil 69 | { 70 | if ((self = [super initWithNibName:nibNameOrNil 71 | bundle:nibBundleOrNil])) 72 | { 73 | // Custom initialization 74 | } 75 | return self; 76 | } 77 | 78 | // Implement viewDidLoad to do additional setup after 79 | // loading the view, typically from a nib. 80 | - (void)viewDidLoad 81 | { 82 | [super viewDidLoad]; 83 | _doneBtn = [[UIBarButtonItem alloc] 84 | initWithTitle:@"Done" 85 | style:UIBarButtonItemStyleDone 86 | target:self 87 | action:@selector(doneButtonTouchedUp:)]; 88 | 89 | _cancelBtn = [[UIBarButtonItem alloc] 90 | initWithTitle:@"Cancel" 91 | style:UIBarButtonItemStylePlain 92 | target:self 93 | action:@selector(cancelBtnTouchedUp:)]; 94 | 95 | self.title = @"Authentication"; 96 | self.navigationItem.leftBarButtonItem = _cancelBtn; 97 | } 98 | 99 | 100 | // Override to allow orientations other than 101 | // the default portrait orientation. 102 | - (BOOL)shouldAutorotateToInterfaceOrientation: 103 | (UIInterfaceOrientation)interfaceOrientation 104 | { 105 | // Return YES for supported orientations 106 | return (interfaceOrientation == UIInterfaceOrientationPortrait); 107 | } 108 | 109 | 110 | - (void)didReceiveMemoryWarning 111 | { 112 | // Releases the view if it doesn't have a superview. 113 | [super didReceiveMemoryWarning]; 114 | 115 | // Release any cached data, images, etc that aren't in use. 116 | } 117 | 118 | - (void)viewDidUnload 119 | { 120 | [super viewDidUnload]; 121 | self.webView = nil; 122 | } 123 | 124 | 125 | - (void)dealloc 126 | { 127 | [webView release]; 128 | [_doneBtn release]; 129 | [_cancelBtn release]; 130 | [super dealloc]; 131 | } 132 | 133 | #pragma mark - 134 | #pragma mark Header File Implementation 135 | 136 | - (void)doneButtonTouchedUp:(id)sender 137 | { 138 | NSString *script; 139 | script = @"(function() { return document.getElementById(\"oauth_pin\").firstChild.textContent; } ())"; 140 | 141 | NSString *pin = [self.webView stringByEvaluatingJavaScriptFromString:script]; 142 | 143 | if ([pin length] > 0) { 144 | NSLog(@"pin %@", pin); 145 | 146 | if ([delegate respondsToSelector:@selector(didFinishAuthorizationWithPin:)]) 147 | [delegate didFinishAuthorizationWithPin:pin]; 148 | 149 | } 150 | else { 151 | NSLog(@"no pin"); 152 | if ([delegate respondsToSelector:@selector(didFailedAuthorization)]) 153 | [delegate didFailedAuthorization]; 154 | } 155 | 156 | [self dismissModalViewControllerAnimated:NO]; 157 | } 158 | 159 | - (void)cancelBtnTouchedUp:(id)sender 160 | { 161 | if ([delegate respondsToSelector:@selector(didFailedAuthorization)]) 162 | [delegate didFailedAuthorization]; 163 | [self dismissModalViewControllerAnimated:NO]; 164 | } 165 | 166 | #pragma mark - 167 | 168 | 169 | @end 170 | -------------------------------------------------------------------------------- /UI/Views/LWETooltipView/LWETooltipParams.h: -------------------------------------------------------------------------------- 1 | // 2 | // LWETooltipParams.h 3 | // LocationBasedMessaging 4 | // 5 | // Created by Rendy Pranata on 26/08/10. 6 | // Copyright 2010 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LWETooltipConstants.h" 11 | 12 | //! This structure is used in a callout properties. Callout can be thought of a triangle which has 3 points, the first base, midpoin, and the pointOnBase. (The term used here MAY not be correct) but just to give the idea, it also has a height of the triangle (callout). 13 | struct LWECalloutBases 14 | { 15 | CGFloat firstBase; 16 | CGFloat pointOnBase; 17 | CGFloat midpointOnBase; 18 | CGFloat height; 19 | }; 20 | 21 | typedef struct LWECalloutBases LWECalloutBases; 22 | 23 | //Avoid the circular dependencies between tooltip view, and its params. 24 | @class LWETooltipView; 25 | 26 | //! Protocol that can be conformed by a class which going to have an LWETooltip, and acts as a delegate for all the action in the LWETooltip. Currently it only supports touch up inside event, but this opens to a future implementation. 27 | @protocol LWETooltipViewDelegate 28 | @optional 29 | - (void)tooltipView:(LWETooltipView *)tooltipView closeButtonDidReceiveAction:(UIControlEvents)action; 30 | @end 31 | 32 | /** 33 | * \class LWETooltipParams 34 | * \brief Object that represents the customizable parameters in the LWETooltip 35 | * \details This object acts like a helper to host all of the cutomizable parameters that can be set in order to draw an LWETooltip. 36 | */ 37 | @interface LWETooltipParams : NSObject 38 | { 39 | //Tooltip close button related parameter 40 | LWETooltipCloseButtonPosition closeButtonPosition; //! Determines in which corner the close button should appear inside the tooltip 41 | UIImage *closeBtnImage; //! Reference to the UIButton close button for the tooltip 42 | 43 | //Tooltip view look and feel related parameter 44 | BOOL showDropShadow; //! If YES, draw a dropshadow 45 | CGSize shadowOffset; //! Size of the drop shadow - should be positive values (negative not yet supported) 46 | CGFloat shadowBlur; //! Non negative number, specifiying the amount of the blur 47 | CGFloat alpha; //! opacity of the tooltip 48 | BOOL shouldResize; //! boolean to indicate that the tolltip will resize based on the content view provided. 49 | 50 | //Background colour, and stroke related properties (Color, and width of the lines) 51 | UIColor *rectColor; //! Color to fill path with 52 | UIColor *backgroundColor; //! Background color (The rest of the view) 53 | UIColor *strokeColor; //! Color to stroke with 54 | CGFloat strokeWidth; //! Width of the path stroke 55 | 56 | //Round rectangle parameter 57 | CGFloat cornerRadius; //! radius of the rounded rectangle 58 | 59 | //Callout related parameters (The speech buble guy that is going to attached with the tooltip. 60 | BOOL showCallout; //! If YES, the view will show a callout (like a speech bubble) 61 | CGFloat calloutSize; //! Value between 0-1 indicating how big/long the callout should be 62 | LWETooltipCalloutPosition calloutPosition; //! Determines where the callout is displayed in reference to the tooltip (left, right, top, bottom) 63 | LWETooltipCalloutDirection calloutDirection; //! Determines the angle of the callout graphic 64 | LWETooltipCalloutOffset calloutOffset; //! Sets the callout graphic to be slightly offset from the standard position 65 | } 66 | 67 | //Tooltip close buttont related parameter 68 | @property LWETooltipCloseButtonPosition closeButtonPosition; 69 | @property (nonatomic, retain) UIImage *closeButtonImage; 70 | 71 | ////Tooltip view look and feel related parameter 72 | @property BOOL showDropShadow; 73 | @property CGSize shadowOffset; 74 | @property CGFloat shadowBlur; 75 | @property CGFloat alpha; 76 | @property BOOL shouldResize; 77 | 78 | //Strokes properties with background colour 79 | @property (nonatomic, retain) UIColor *rectColor; 80 | // user does not really want to change our view's bg color - then the alpha won't work. 81 | @property (nonatomic, retain, readonly) UIColor *backgroundColor; 82 | @property (nonatomic, retain) UIColor *strokeColor; 83 | @property CGFloat strokeWidth; 84 | 85 | //Round rectangle parameter 86 | @property CGFloat cornerRadius; 87 | 88 | //Callout properties 89 | @property LWETooltipCalloutPosition calloutPosition; 90 | @property LWETooltipCalloutDirection calloutDirection; 91 | @property LWETooltipCalloutOffset calloutOffset; 92 | @property CGFloat calloutSize; 93 | @property BOOL showCallout; 94 | 95 | // TODO: RENDY, please doc these ;) 96 | /** 97 | * \brief <#(brief description)#> 98 | * \return <#(description)#> 99 | * \details <#(comprehensive description)#> 100 | */ 101 | - (id)initWithDefaultValue; 102 | 103 | @end 104 | -------------------------------------------------------------------------------- /Network/LWEPackageDownloader.h: -------------------------------------------------------------------------------- 1 | // LWEPackageDownloader.h 2 | // 3 | // Copyright (c) 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import 21 | #import "ASINetworkQueue.h" 22 | #import "ASIHTTPRequest.h" 23 | #import "ASIS3ObjectRequest.h" 24 | #import "LWEPackage.h" 25 | #import "LWES3Package.h" 26 | #import "LWEDecompressor.h" 27 | #import "LWELongRunningTaskProtocol.h" 28 | 29 | @class LWEPackageDownloader; 30 | @protocol LWEPackageDownloaderDelegate 31 | @optional 32 | - (void) packageDownloaderStarted:(LWEPackageDownloader *)packageDownloader; 33 | - (void) packageDownloaderFinished:(LWEPackageDownloader *)packageDownloader; 34 | - (void) unpackageFinished:(LWEPackage*)package; 35 | - (void) unpackageFailed:(LWEPackage*)package withError:(NSError*)error; 36 | @end 37 | 38 | @protocol LWEPackageDownloaderProgressDelegate 39 | @optional 40 | - (void) packageDownloader:(LWEPackageDownloader *)downloader progressDidUpdate:(CGFloat)progress; 41 | - (void) packageDownloader:(LWEPackageDownloader *)downloader statusDidUpdate:(NSString *)string; 42 | @end 43 | 44 | /** 45 | * This class downloads & unzips "packages". Any time you have a ZIP file available 46 | * via HTTP that you want to download, unzip, and do osmething with, this is your class. 47 | * You can define what is to be downloaded and where it should be unzipped to by 48 | * using the LWEPackage class. 49 | */ 50 | @interface LWEPackageDownloader : NSObject 51 | 52 | //! Implement this to receive events when a package unwrap succeeds or fails 53 | @property (assign) id delegate; 54 | 55 | //! Implement this to receive events as the progress completes 56 | @property (assign) id progressDelegate; 57 | 58 | //! The underlying network queue for HTTP requests to get the packages 59 | @property (retain) ASINetworkQueue *queue; 60 | 61 | //! List of packages this class is handling. Packages are removed from this array after unwrapping/error. 62 | @property (retain) NSArray *packages; 63 | 64 | /** 65 | * Designated initializer. 66 | */ 67 | - (id) initWithDownloaderDelegate:(id)aDelegate; 68 | 69 | /** 70 | * Call this method to remove an LWEPackage object. NOTE that 71 | * after a package is unwrapped, this method is called automatically 72 | * by the class *BEFORE* the delegate callbacks to -unpackageFinished: or 73 | * -unpackageFailed:. Failed unpackages should be re-queued. 74 | */ 75 | - (void) dequeuePackage:(LWEPackage*)package; 76 | 77 | /** 78 | * Call this method to add an LWEPackage object to the end of the 79 | * downloader queue. Calling this method alone will not start 80 | * downloading - you must call -startUnwrapping to start the 81 | * process. 82 | */ 83 | - (void) queuePackage:(LWEPackage*)package; 84 | 85 | /** 86 | * Starts the queue, downloading & unwrapping each package 87 | */ 88 | - (void) start; 89 | 90 | /** 91 | * Cancels the queue - note that if something is actively downloading, this will not stop it 92 | */ 93 | - (void) cancel; 94 | 95 | /** 96 | * Returns YES if it is possible to call -cancel. 97 | */ 98 | - (BOOL) canCancelTask; 99 | 100 | /** 101 | * Returns YES if it is possible to call -start 102 | */ 103 | - (BOOL) canStartTask; 104 | 105 | //! Returns YES if the task is in a successful terminal state. 106 | - (BOOL) isSuccessState; 107 | 108 | //! Returns YES if the task is in a failed terminal state. 109 | - (BOOL) isFailureState; 110 | 111 | 112 | /** 113 | * Call this method to begin downloading immediately and then 114 | * unwrap the package. This bypasses the queue. 115 | * TODO: consider taking this internal? 116 | */ 117 | - (void) unwrapPackage:(LWEPackage*)package; 118 | 119 | @end 120 | -------------------------------------------------------------------------------- /UI/LWEUIAlertView.m: -------------------------------------------------------------------------------- 1 | // LWEUIAlertView.m 2 | // 3 | // Copyright (c) 2011 Long Weekend LLC 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | // associated documentation files (the "Software"), to deal in the Software without restriction, 7 | // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | // subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all copies or substantial 12 | // portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | #import "LWEUIAlertView.h" 21 | 22 | @implementation LWEUIAlertView 23 | 24 | /** 25 | * Shows standard no-network alert view w/o delegate setting 26 | * Note that this method just calls noNetworkAlertWithDelegate:nil 27 | */ 28 | + (UIAlertView*) noNetworkAlert 29 | { 30 | return [LWEUIAlertView noNetworkAlertWithDelegate:nil]; 31 | } 32 | 33 | /** 34 | * \param delegate the delegate of the alert view, if any 35 | * Note that this method just calls notificationAlertWithTitle:message:delegate with a custom title & message 36 | */ 37 | + (UIAlertView*) noNetworkAlertWithDelegate:(id)delegate 38 | { 39 | return [LWEUIAlertView notificationAlertWithTitle:NSLocalizedString(@"No Network Access",@"Network.UnableToConnect_AlertViewTitle") 40 | message:NSLocalizedString(@"Please check your network connection and try again.",@"Network.UnableToConnect_AlertViewMessage") 41 | delegate:delegate]; 42 | } 43 | 44 | /** 45 | * Shows a default "OK" button alert with no delegate 46 | * \param title Title of the UIAlertView 47 | * \param message Message content of the UIAlertView 48 | */ 49 | + (UIAlertView*) notificationAlertWithTitle:(NSString*)title message:(NSString*)message 50 | { 51 | return [LWEUIAlertView notificationAlertWithTitle:title message:message delegate:nil]; 52 | } 53 | 54 | /** 55 | * \param title Title of the UIAlertView 56 | * \param message Message content of the UIAlertView 57 | * \param delegate Delegate of the UIAlertView, if any 58 | */ 59 | + (UIAlertView*) notificationAlertWithTitle:(NSString*)title message:(NSString*)message delegate:(id)delegate 60 | { 61 | return [LWEUIAlertView confirmationAlertWithTitle:title message:message ok:nil cancel:NSLocalizedString(@"OK",@"Global.OK") delegate:delegate]; 62 | } 63 | 64 | /** 65 | * Note that this just calls confirmationAlertWithTitle:message:ok:cancel:delegate with default parameters for ok and cancel. 66 | * \param title Title of the UIAlertView 67 | * \param message Message content of the UIAlertView 68 | * \param delegate Delegate of the UIAlertView, if any 69 | */ 70 | + (UIAlertView*) confirmationAlertWithTitle:(NSString*)title message:(NSString*)message delegate:(id)delegate 71 | { 72 | return [LWEUIAlertView confirmationAlertWithTitle:title message:message ok:NSLocalizedString(@"OK",@"Global.OK") cancel:NSLocalizedString(@"Cancel",@"Global.Cancel") delegate:delegate]; 73 | } 74 | 75 | /** 76 | * \param title Title of the UIAlertView 77 | * \param message Message content of the UIAlertView 78 | * \param ok Text for the "OK" action 79 | * \param cancel Text for the "Cancel" action 80 | * \param delegate Delegate of the UIAlertView, if any 81 | */ 82 | + (UIAlertView*) confirmationAlertWithTitle:(NSString*)title message:(NSString*)message ok:(NSString*)ok cancel:(NSString*)cancel delegate:(id)delegate 83 | { 84 | return [LWEUIAlertView confirmationAlertWithTitle:title message:message ok:ok cancel:cancel delegate:delegate tag:0]; 85 | } 86 | 87 | /** 88 | * \param title Title of the UIAlertView 89 | * \param message Message content of the UIAlertView 90 | * \param ok Text for the "OK" action 91 | * \param cancel Text for the "Cancel" action 92 | * \param delegate Delegate of the UIAlertView, if any 93 | * \param tag Tag for the alert view to use in delegate, if any 94 | */ 95 | + (UIAlertView*) confirmationAlertWithTitle:(NSString*)title message:(NSString*)message ok:(NSString*)ok cancel:(NSString*)cancel delegate:(id)delegate tag:(int)tag 96 | { 97 | UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:message delegate:delegate 98 | cancelButtonTitle:cancel 99 | otherButtonTitles:ok,nil]; 100 | alert.tag = tag; 101 | [alert show]; 102 | return [alert autorelease]; 103 | } 104 | 105 | @end -------------------------------------------------------------------------------- /UI/Views/LWELoadingView.m: -------------------------------------------------------------------------------- 1 | // 2 | // LWELoadingView.m 3 | // jFlash 4 | // 5 | // Created by Rendy Pranata on 29/07/10. 6 | // Copyright 2010 Long Weekend LLC. All rights reserved. 7 | // 8 | 9 | #import "LWELoadingView.h" 10 | #import "LWEViewUtility.h" 11 | 12 | @implementation LWELoadingView 13 | 14 | //@synthesize totalHeight; 15 | 16 | + (id)loadingView:(UIView *)aSuperview withText:(NSString *)text 17 | { 18 | return [LWELoadingView loadingView:aSuperview withText:text calculateNavigationBar:NO]; 19 | } 20 | 21 | + (id)loadingView:(UIView *)aSuperview withText:(NSString *)text calculateNavigationBar:(BOOL)calculateNavigationBar 22 | { 23 | CGFloat _totalHeight; 24 | CGRect borderFrame = [[UIScreen mainScreen] bounds]; //[aSuperview bounds]; 25 | LWELoadingView *loadingView = [[[LWELoadingView alloc] initWithFrame:borderFrame] autorelease]; 26 | if (!loadingView) 27 | { 28 | return nil; 29 | } 30 | 31 | const CGSize DEFAULT_OFFSET_VIEW = CGSizeMake(DEFAULT_OFFSET_WIDTH, DEFAULT_OFFSET_HEIGHT); 32 | 33 | // configure the label 34 | CGRect labelFrame = CGRectMake(0, 0, DEFAULT_LABEL_WIDTH, DEFAULT_LABEL_HEIGHT); 35 | UILabel *loadingLabel = [[UILabel alloc] initWithFrame:labelFrame]; 36 | loadingLabel.text = text; 37 | loadingLabel.numberOfLines = 3; 38 | loadingLabel.textColor = [UIColor whiteColor]; 39 | loadingLabel.backgroundColor = [UIColor clearColor]; //[UIColor yellowColor];// 40 | loadingLabel.textAlignment = UITextAlignmentCenter; 41 | loadingLabel.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; 42 | 43 | // configure the activity indicator 44 | UIActivityIndicatorView *activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 45 | [activityIndicatorView startAnimating]; 46 | [loadingView addSubview:activityIndicatorView]; 47 | 48 | _totalHeight = loadingLabel.frame.size.height + activityIndicatorView.frame.size.height; 49 | 50 | // size and center the loading view 51 | borderFrame.size.width = DEFAULT_LABEL_WIDTH + (DEFAULT_OFFSET_VIEW.width*2); 52 | borderFrame.size.height = _totalHeight + (DEFAULT_OFFSET_VIEW.height*2); 53 | borderFrame.origin.x = floor(0.5 * (loadingView.frame.size.width - borderFrame.size.width)); 54 | borderFrame.origin.y = floor(0.5 * (loadingView.frame.size.height - borderFrame.size.height)); 55 | //If calculate navigation bar, adjust 44px for nav bar hieght. 56 | if (calculateNavigationBar) 57 | { 58 | borderFrame.origin.y = borderFrame.origin.y - 44.0; 59 | } 60 | loadingView.frame = borderFrame; 61 | 62 | // position activity indicator 63 | CGRect activityIndicatorRect = activityIndicatorView.frame; 64 | activityIndicatorRect.origin.x = 0.5 * (loadingView.frame.size.width - activityIndicatorRect.size.width); 65 | activityIndicatorRect.origin.y = loadingLabel.frame.origin.y + loadingLabel.frame.size.height-5; 66 | activityIndicatorView.frame = activityIndicatorRect; 67 | 68 | // position the label 69 | labelFrame.origin.x = floor(0.5 * (loadingView.frame.size.width - DEFAULT_LABEL_WIDTH)); 70 | labelFrame.origin.y = floor((0.5 * (loadingView.frame.size.height - _totalHeight)*0.1)); 71 | [loadingLabel sizeToFit]; 72 | loadingLabel.frame = labelFrame; 73 | [loadingView addSubview:loadingLabel]; 74 | 75 | [activityIndicatorView release]; 76 | [loadingLabel release]; 77 | 78 | loadingView.opaque = NO; 79 | [aSuperview addSubview:loadingView]; 80 | 81 | // animate 82 | CATransition *animation = [CATransition animation]; 83 | [animation setType:kCATransitionFade]; 84 | [[aSuperview layer] addAnimation:animation forKey:@"layerAnimation"]; 85 | 86 | return loadingView; 87 | } 88 | 89 | /** 90 | * Subclass the UIView method to add a fade 91 | */ 92 | - (void) removeFromSuperview 93 | { 94 | // Set up the animation 95 | CATransition *animation = [CATransition animation]; 96 | [animation setType:kCATransitionFade]; 97 | 98 | UIView *aSuperview = [self superview]; 99 | [[aSuperview layer] addAnimation:animation forKey:@"layerAnimation"]; 100 | 101 | // Run the normal UI removeFromSuperview 102 | [super removeFromSuperview]; 103 | } 104 | 105 | /* 106 | * Draw the view. 107 | */ 108 | - (void)drawRect:(CGRect)rect 109 | { 110 | //WE_LOG(@"total height : %f, inset height : %f", _totalHeight, _totalHeight*2); 111 | //rect = CGRectInset(rect, 30, _totalHeight*2); //170); 112 | const CGFloat ROUND_RECT_CORNER_RADIUS = 10.0; 113 | CGPathRef roundRectPath = NewPathWithRoundRect(rect, ROUND_RECT_CORNER_RADIUS); 114 | 115 | CGContextRef context = UIGraphicsGetCurrentContext(); 116 | 117 | const CGFloat BACKGROUND_OPACITY = 0.65; 118 | CGContextSetRGBFillColor(context, 0, 0, 0, BACKGROUND_OPACITY); 119 | CGContextAddPath(context, roundRectPath); 120 | CGContextFillPath(context); 121 | 122 | const CGFloat STROKE_OPACITY = 0.25; 123 | CGContextSetRGBStrokeColor(context, 1, 1, 1, STROKE_OPACITY); 124 | CGContextAddPath(context, roundRectPath); 125 | CGContextStrokePath(context); 126 | 127 | CGPathRelease(roundRectPath); 128 | } 129 | 130 | @end -------------------------------------------------------------------------------- /UI/Views/LWETooltipView/LWETooltipViewOld.h: -------------------------------------------------------------------------------- 1 | // 2 | // LWETooltipView.h 3 | // LocationBasedMessaging 4 | // 5 | // Created by Mark Makdad on 7/15/10. 6 | // Copyright 2010 Long Weekend Inc. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LWETooltipConstants.h" 11 | #import "LWERoundedRectView.h" 12 | #import "LWECalloutView.h" 13 | 14 | /** 15 | * \class LWETooltipView 16 | * \brief Creates a tooltip-like view with a close button and an optional callout graphic 17 | * \details This view is most similar to the callout view used (privately) in the Maps application. 18 | It is more customizable and extendable, and allows for a custom content view. 19 | */ 20 | @interface LWETooltipViewOld : UIView 21 | { 22 | //! If YES, the view will show a callout (like a speech bubble) 23 | BOOL showCallout; 24 | 25 | //! If YES, draw a dropshadow 26 | BOOL showDropShadow; 27 | 28 | //! Determines where the callout is displayed in reference to the tooltip (left, right, top, bottom) 29 | LWETooltipCalloutPosition calloutPosition; 30 | 31 | //! Determines the angle of the callout graphic 32 | LWETooltipCalloutDirection calloutDirection; 33 | 34 | //! Determines in which corner the close button should appear inside the tooltip 35 | LWETooltipCloseButtonPosition closeButtonPosition; 36 | 37 | //! Sets the callout graphic to be slightly offset from the standard position 38 | LWETooltipCalloutOffset calloutOffset; 39 | 40 | //! Value between 0-1 indicating how big/long the callout should be 41 | CGFloat calloutSize; 42 | 43 | //! Size of the drop shadow - should be positive values (negative not yet supported) 44 | CGSize shadowOffset; 45 | 46 | //! Reference to the UIButton close button for the tooltip 47 | UIButton *closeButton; 48 | 49 | //! Reference to the tooltip content UIView 50 | UIView *tooltipView; 51 | 52 | @private 53 | LWERoundedRectView *roundedRectView; 54 | LWECalloutView *calloutView; 55 | } 56 | 57 | /** 58 | * \brief Sets the image for the close button 59 | * \param image A standard UIImage 60 | * \details Also resets the frame for the button based on the image size 61 | */ 62 | - (void) setCloseButtonImage:(UIImage*)image; 63 | 64 | /** 65 | * \brief Sets the action target when the close button is clicked 66 | * \param sender Who will receive the action 67 | * \param action What action is to be sent 68 | * \details Use this method to specify the callback that will dismiss the tooltip 69 | */ 70 | - (void) setCloseButtonTarget:(id)sender action:(SEL)action; 71 | 72 | /** 73 | * \brief Sets the location of the close button inside the tooltip 74 | * \details Set to one of the values of enum LWETooltipCloseButtonPosition 75 | */ 76 | - (void) setCloseButtonPosition:(LWETooltipCloseButtonPosition)position; 77 | 78 | /** 79 | * \brief Sets the position of the callout in reference to the tooltip 80 | * \param position Enum value in LWETooltipCalloutPosition 81 | * \details Sets the direction that the callout "points" in/from. If you want 82 | the tooltip to appear above the content you're referring to, set this to "bottom" for example. 83 | */ 84 | - (void) setCalloutPosition:(LWETooltipCalloutPosition)position; 85 | 86 | /** 87 | * \brief Sets an arbitrary offset for the callout's location 88 | * \param offset Enum value in LWETooltipCalloutOffset 89 | * \details By default, the callout will be drawn coming from the 90 | 1/4 length, 1/2 length, and/or 3/4 length points on the relevant edge of the tooltip. 91 | If you specify an offset, these points will be shifted left or right 92 | to slightly change where the callout "pointer" points to. 93 | */ 94 | - (void) setCalloutOffset:(LWETooltipCalloutOffset)offset; 95 | 96 | /** 97 | * \brief Sets the angle of the callout graphic 98 | * \param direction Enum value in LWETooltipCalloutDirection 99 | * \details If straight, the callout will be an isoceles triangle pointing straight up. 100 | If one of the other settings, it will be scalene, appearing to 101 | point to the left or the right. 102 | */ 103 | - (void) setCalloutDirection:(LWETooltipCalloutDirection)direction; 104 | 105 | /** 106 | * \brief Sets the size of the callout, relative to the total frame (percentage). 107 | * \param size Value between 0 and 1 108 | * \details For example, if set to 0.15f, the callout will occupy 15% of the frame, giving 109 | the tooltip the remaining 85% to draw itself. 110 | */ 111 | - (void) setCalloutSize:(CGFloat)size; 112 | 113 | 114 | /** 115 | * \brief Sets the shadow offset size for the subviews 116 | * \param size Should be a positive-valued CGSize struct 117 | * \details Blurring is set in LWETooltipConstants.h 118 | */ 119 | - (void) setShadowOffset:(CGSize)size; 120 | 121 | - (void) layoutTooltip; 122 | 123 | // Private helper methods 124 | - (CGRect) _makeNewRoundRectFrame; 125 | - (CGRect) _makeCloseButtonRectFrame; 126 | - (CGRect) _makeCalloutRectFrame; 127 | - (CGRect) _makeContentViewRect; 128 | 129 | @property (nonatomic, retain) UIButton *closeButton; 130 | @property (nonatomic, retain) UIView *contentView; 131 | @property BOOL showCallout; 132 | @property BOOL showDropShadow; 133 | 134 | @property (nonatomic, retain) LWERoundedRectView *roundedRectView; 135 | @property (nonatomic, retain) LWECalloutView *calloutView; 136 | 137 | @end 138 | --------------------------------------------------------------------------------