Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixes some issues with the passcode lock

- Now works properly on iPad (including rotation)
- Covers the whole screen on iPad
- Passcode lock is shown immediately when the app resigns active status,
  so that the previous screen doesn't flash briefly before the lock appears
- Passcode lock now works when another modal view controller is already
  visible (like settings or "About")
- Adjusted the coding style to the rest of the project (spaces are now tabs)
- It is no longer possible to irreversibly dismiss the keyboard on iPad
  (Tapping the main passcode view brings it up again if it was dismissed)
  • Loading branch information...
commit fd918a94fb2c76501b7315d9091b8cdbfdeb7068 1 parent 9154c11
Ole Zorn authored
View
24 AppSales.xcodeproj/project.pbxproj
@@ -1403,6 +1403,7 @@
7FDF601D13DD2125005F1E2D /* Dashboard */,
7FDF602013DD21D5005F1E2D /* Common UI */,
7F7F1D0413F63F7F00F18143 /* Promo Code Download */,
+ 7F88897A14CD4C9A007604D7 /* Passcode Lock */,
7F1499D113BE312100D89064 /* Report Download */,
7F89BCDA13DFA43E001C607F /* Review Download */,
7F709D9013BD06570008DBAD /* Model */,
@@ -1643,6 +1644,21 @@
name = Payments;
sourceTree = "<group>";
};
+ 7F88897A14CD4C9A007604D7 /* Passcode Lock */ = {
+ isa = PBXGroup;
+ children = (
+ 6D81574814CB3C2B005E8F3F /* KKKeychain.h */,
+ 6D81574914CB3C2B005E8F3F /* KKKeychain.m */,
+ 6D81574A14CB3C2B005E8F3F /* KKPasscodeLock.h */,
+ 6D81574B14CB3C2B005E8F3F /* KKPasscodeLock.m */,
+ 6D81574C14CB3C2B005E8F3F /* KKPasscodeSettingsViewController.h */,
+ 6D81574D14CB3C2B005E8F3F /* KKPasscodeSettingsViewController.m */,
+ 6D81574E14CB3C2B005E8F3F /* KKPasscodeViewController.h */,
+ 6D81574F14CB3C2B005E8F3F /* KKPasscodeViewController.m */,
+ );
+ name = "Passcode Lock";
+ sourceTree = "<group>";
+ };
7F89BCDA13DFA43E001C607F /* Review Download */ = {
isa = PBXGroup;
children = (
@@ -1677,14 +1693,6 @@
7FDF601C13DD2107005F1E2D /* Helpers */ = {
isa = PBXGroup;
children = (
- 6D81574814CB3C2B005E8F3F /* KKKeychain.h */,
- 6D81574914CB3C2B005E8F3F /* KKKeychain.m */,
- 6D81574A14CB3C2B005E8F3F /* KKPasscodeLock.h */,
- 6D81574B14CB3C2B005E8F3F /* KKPasscodeLock.m */,
- 6D81574C14CB3C2B005E8F3F /* KKPasscodeSettingsViewController.h */,
- 6D81574D14CB3C2B005E8F3F /* KKPasscodeSettingsViewController.m */,
- 6D81574E14CB3C2B005E8F3F /* KKPasscodeViewController.h */,
- 6D81574F14CB3C2B005E8F3F /* KKPasscodeViewController.m */,
7F7F4A0313E4F4AD006C6651 /* JSONKit.h */,
7F7F4A0413E4F4AD006C6651 /* JSONKit.m */,
7F454F9E13D5C24F00AE47D1 /* UIColor+Extensions.h */,
View
1  Classes/AppSalesAppDelegate.h
@@ -38,5 +38,6 @@
- (NSURL *)applicationSupportDirectory;
- (void)loadAccount:(ASAccount *)account;
- (void)selectAccount:(id)sender;
+- (void)showPasscodeLockIfNeeded;
@end
View
88 Classes/AppSalesAppDelegate.m
@@ -26,9 +26,9 @@ @implementation AppSalesAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
- [[KKPasscodeLock sharedLock] setDefaultSettings];
- [[KKPasscodeLock sharedLock] setEraseOption:NO];
-
+ [[KKPasscodeLock sharedLock] setDefaultSettings];
+ [[KKPasscodeLock sharedLock] setEraseOption:NO];
+
srandom(time(NULL));
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
@@ -49,7 +49,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
- } else {
+ } else {
self.accountsViewController = [[[AccountsViewController alloc] initWithStyle:UITableViewStyleGrouped] autorelease];
self.accountsViewController.managedObjectContext = self.managedObjectContext;
self.accountsViewController.contentSizeForViewInPopover = CGSizeMake(320, 480);
@@ -59,7 +59,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
self.accountsPopover = [[[UIPopoverController alloc] initWithContentViewController:accountsNavController] autorelease];
[self loadAccount:nil];
[self.window makeKeyAndVisible];
- [self selectAccount:nil];
}
BOOL migrating = [self migrateDataIfNeeded];
@@ -81,12 +80,19 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[self.accountsViewController performSelector:@selector(downloadReports:) withObject:nil afterDelay:0.0];
}
+ [self showPasscodeLockIfNeeded];
+ if (iPad) {
+ [self selectAccount:nil];
+ }
+
return YES;
}
- (void)selectAccount:(id)sender
{
- [self.accountsPopover presentPopoverFromRect:CGRectMake(50, 50, 1, 1) inView:self.window.rootViewController.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
+ if (!self.window.rootViewController.modalViewController) {
+ [self.accountsPopover presentPopoverFromRect:CGRectMake(50, 50, 1, 1) inView:self.window.rootViewController.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
+ }
}
- (void)accountsViewController:(AccountsViewController *)viewController didSelectAccount:(ASAccount *)account
@@ -135,7 +141,7 @@ - (void)loadAccount:(ASAccount *)account
UITabBarController *tabController = [[[UITabBarController alloc] initWithNibName:nil bundle:nil] autorelease];
[tabController setViewControllers:[NSArray arrayWithObjects:salesNavController, reviewsNavController, paymentsNavController, promoNavController, nil]];
- self.window.rootViewController = tabController;
+ self.window.rootViewController = tabController;
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
@@ -208,30 +214,50 @@ - (void)applicationWillEnterForeground:(UIApplication *)application
- (void)applicationDidBecomeActive:(UIApplication *)application
{
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
-
- if ([[KKPasscodeLock sharedLock] isPasscodeRequired]) {
- KKPasscodeViewController *vc = [[[KKPasscodeViewController alloc] initWithNibName:nil bundle:nil] autorelease];
- vc.mode = KKPasscodeModeEnter;
- vc.delegate = self;
-
- dispatch_async(dispatch_get_main_queue(),^ {
- UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
-
- if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
- nav.modalPresentationStyle = UIModalPresentationFormSheet;
- nav.navigationBar.barStyle = UIBarStyleBlack;
- nav.navigationBar.opaque = NO;
- } else {
- nav.navigationBar.tintColor = accountsViewController.navigationController.navigationBar.tintColor;
- nav.navigationBar.translucent = accountsViewController.navigationController.navigationBar.translucent;
- nav.navigationBar.opaque = accountsViewController.navigationController.navigationBar.opaque;
- nav.navigationBar.barStyle = accountsViewController.navigationController.navigationBar.barStyle;
- }
-
- [accountsViewController presentModalViewController:nav animated:YES];
- });
-
- }
+}
+
+- (void)applicationWillResignActive:(UIApplication *)application
+{
+ [self showPasscodeLockIfNeeded];
+}
+
+- (void)showPasscodeLockIfNeeded
+{
+ if ([[KKPasscodeLock sharedLock] isPasscodeRequired]) {
+
+ KKPasscodeViewController *vc = [[[KKPasscodeViewController alloc] initWithNibName:nil bundle:nil] autorelease];
+ vc.mode = KKPasscodeModeEnter;
+ vc.delegate = self;
+
+ UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
+ if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
+ nav.modalPresentationStyle = UIModalPresentationFullScreen;
+ nav.navigationBar.barStyle = UIBarStyleBlack;
+ nav.navigationBar.opaque = NO;
+ } else {
+ nav.navigationBar.tintColor = accountsViewController.navigationController.navigationBar.tintColor;
+ nav.navigationBar.translucent = accountsViewController.navigationController.navigationBar.translucent;
+ nav.navigationBar.opaque = accountsViewController.navigationController.navigationBar.opaque;
+ nav.navigationBar.barStyle = accountsViewController.navigationController.navigationBar.barStyle;
+ }
+ UIViewController *viewControllerForPresentingPasscode = nil;
+ if (self.window.rootViewController.modalViewController) {
+ if ([self.window.rootViewController.modalViewController isKindOfClass:[UINavigationController class]]
+ && [[[(UINavigationController *)self.window.rootViewController.modalViewController viewControllers] objectAtIndex:0] isKindOfClass:[KKPasscodeViewController class]]) {
+ //The passcode dialog is already shown...
+ return;
+ }
+ //We're in the settings or add account dialog...
+ viewControllerForPresentingPasscode = self.window.rootViewController.modalViewController;
+ } else {
+ viewControllerForPresentingPasscode = self.window.rootViewController;
+ }
+ if (self.accountsPopover.popoverVisible) {
+ [self.accountsPopover dismissPopoverAnimated:NO];
+ }
+ [[NSNotificationCenter defaultCenter] postNotificationName:ASWillShowPasscodeLockNotification object:self];
+ [viewControllerForPresentingPasscode presentModalViewController:nav animated:NO];
+ }
}
- (void)applicationWillTerminate:(UIApplication *)application
View
4 Classes/DashboardViewController.h
@@ -30,6 +30,8 @@
UIActivityIndicatorView *activityIndicator;
UILabel *statusLabel;
UIProgressView *progressBar;
+
+ UIActionSheet *activeSheet;
}
@property (nonatomic, retain) ASAccount *account;
@@ -45,8 +47,10 @@
@property (nonatomic, retain) UIActivityIndicatorView *activityIndicator;
@property (nonatomic, retain) UILabel *statusLabel;
@property (nonatomic, retain) UIProgressView *progressBar;
+@property (nonatomic, retain) UIActionSheet *activeSheet;
- (id)initWithAccount:(ASAccount *)anAccount;
+- (void)willShowPasscodeLock:(NSNotification *)notification;
- (NSSet *)entityNamesTriggeringReload;
- (void)reloadData;
- (void)reloadTableView;
View
14 Classes/DashboardViewController.m
@@ -17,7 +17,7 @@ @implementation DashboardViewController
@synthesize account, products, visibleProducts, selectedProduct;
@synthesize productsTableView, topView, shadowView, colorPopover, statusToolbar, stopButtonItem, activityIndicator, statusLabel, progressBar;
-
+@synthesize activeSheet;
- (id)initWithAccount:(ASAccount *)anAccount
{
@@ -26,10 +26,21 @@ - (id)initWithAccount:(ASAccount *)anAccount
self.account = anAccount;
self.hidesBottomBarWhenPushed = [[UIDevice currentDevice] userInterfaceIdiom] != UIUserInterfaceIdiomPad;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(contextDidChange:) name:NSManagedObjectContextObjectsDidChangeNotification object:[account managedObjectContext]];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willShowPasscodeLock:) name:ASWillShowPasscodeLockNotification object:nil];
}
return self;
}
+- (void)willShowPasscodeLock:(NSNotification *)notification
+{
+ if (self.colorPopover.popoverVisible) {
+ [self.colorPopover dismissPopoverAnimated:NO];
+ }
+ if (self.activeSheet.visible) {
+ [self.activeSheet dismissWithClickedButtonIndex:self.activeSheet.cancelButtonIndex animated:NO];
+ }
+}
+
- (void)contextDidChange:(NSNotification *)notification
{
NSSet *relevantEntityNames = [self entityNamesTriggeringReload];
@@ -362,6 +373,7 @@ - (void)dealloc
[statusLabel release];
[progressBar release];
[colorPopover release];
+ [activeSheet release];
[super dealloc];
}
View
1  Classes/KKKeychain.h
@@ -18,6 +18,7 @@
#import <Foundation/Foundation.h>
@interface KKKeychain : NSObject {
+
}
+ (BOOL)setString:(NSString*)string forKey:(NSString*)key;
View
38 Classes/KKKeychain.m
@@ -18,34 +18,28 @@
#import "KKKeychain.h"
#import <Security/Security.h>
-///////////////////////////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////////////////////////
@implementation KKKeychain
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-+ (NSString*)appName {
++ (NSString*)appName
+{
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
-
NSString *appName = [bundle objectForInfoDictionaryKey:@"CFBundleDisplayName"];
if (!appName) {
appName = [bundle objectForInfoDictionaryKey:@"CFBundleName"];
}
- return appName;
+ return appName;
}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-+ (BOOL)setString:(NSString*)string forKey:(NSString*)key {
++ (BOOL)setString:(NSString*)string forKey:(NSString*)key
+{
if (string == nil || key == nil) {
return NO;
}
+
+ key = [NSString stringWithFormat:@"%@ - %@", [KKKeychain appName], key];
- key = [NSString stringWithFormat:@"%@ - %@", [KKKeychain appName], key];
-
- // First check if it already exists, by creating a search dictionary and requesting that
- // nothing be returned, and performing the search anyway.
+ // First check if it already exists, by creating a search dictionary and requesting that
+ // nothing be returned, and performing the search anyway.
NSMutableDictionary *existsQueryDictionary = [NSMutableDictionary dictionary];
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
@@ -69,25 +63,18 @@ + (BOOL)setString:(NSString*)string forKey:(NSString*)key {
// Modify an existing one
// Actually pull it now of the keychain at this point.
NSDictionary *attributeDict = [NSDictionary dictionaryWithObject:data forKey:(id)kSecValueData];
-
res = SecItemUpdate((CFDictionaryRef)existsQueryDictionary, (CFDictionaryRef)attributeDict);
NSAssert1(res == errSecSuccess, @"SecItemUpdated returned %d!", res);
-
} else {
NSAssert1(NO, @"Received %d from SecItemCopyMatching!", res);
}
-
return YES;
}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-+ (NSString*)getStringForKey:(NSString*)key {
-
- key = [NSString stringWithFormat:@"%@ - %@", [KKKeychain appName], key];
-
++ (NSString*)getStringForKey:(NSString*)key
+{
+ key = [NSString stringWithFormat:@"%@ - %@", [KKKeychain appName], key];
NSMutableDictionary *existsQueryDictionary = [NSMutableDictionary dictionary];
-
[existsQueryDictionary setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass];
// Add the keys to the search dict
@@ -112,5 +99,4 @@ + (NSString*)getStringForKey:(NSString*)key {
}
-
@end
View
6 Classes/KKPasscodeLock.h
@@ -6,7 +6,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@@ -19,8 +19,8 @@
#import "KKPasscodeViewController.h"
@interface KKPasscodeLock : NSObject {
- BOOL _eraseOption;
- NSUInteger _attemptsAllowed;
+ BOOL _eraseOption;
+ NSUInteger _attemptsAllowed;
}
+ (KKPasscodeLock*)sharedLock;
View
44 Classes/KKPasscodeLock.m
@@ -6,7 +6,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@@ -22,48 +22,38 @@
static KKPasscodeLock *sharedLock = nil;
-///////////////////////////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////////////////////////
@implementation KKPasscodeLock
-
@synthesize eraseOption = _eraseOption;
@synthesize attemptsAllowed = _attemptsAllowed;
-///////////////////////////////////////////////////////////////////////////////////////////////////
+ (KKPasscodeLock*)sharedLock
{
- @synchronized(self) {
- if (sharedLock == nil) {
- sharedLock = [[self alloc] init];
- sharedLock.eraseOption = YES;
- sharedLock.attemptsAllowed = 5;
- }
- }
- return sharedLock;
+ @synchronized(self) {
+ if (sharedLock == nil) {
+ sharedLock = [[self alloc] init];
+ sharedLock.eraseOption = YES;
+ sharedLock.attemptsAllowed = 5;
+ }
+ }
+ return sharedLock;
}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
- (BOOL)isPasscodeRequired
{
- return [[KKKeychain getStringForKey:@"passcode_on"] isEqualToString:@"YES"];
+ return [[KKKeychain getStringForKey:@"passcode_on"] isEqualToString:@"YES"];
}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)setDefaultSettings
{
- if (![KKKeychain getStringForKey:@"passcode_on"]) {
- [KKKeychain setString:@"NO" forKey:@"passcode_on"];
- }
-
- if (![KKKeychain getStringForKey:@"erase_data_on"]) {
- [KKKeychain setString:@"NO" forKey:@"erase_data_on"];
- }
+ if (![KKKeychain getStringForKey:@"passcode_on"]) {
+ [KKKeychain setString:@"NO" forKey:@"passcode_on"];
+ }
+
+ if (![KKKeychain getStringForKey:@"erase_data_on"]) {
+ [KKKeychain setString:@"NO" forKey:@"erase_data_on"];
+ }
}
-
@end
View
16 Classes/KKPasscodeSettingsViewController.h
@@ -6,7 +6,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@@ -29,13 +29,13 @@
@end
@interface KKPasscodeSettingsViewController : UITableViewController <UIActionSheetDelegate, KKPasscodeViewControllerDelegate> {
-
- id <KKPasscodeSettingsViewControllerDelegate> _delegate;
-
- UISwitch* _eraseDataSwitch;
-
- BOOL _passcodeLockOn;
- BOOL _eraseDataOn;
+
+ id <KKPasscodeSettingsViewControllerDelegate> _delegate;
+
+ UISwitch* _eraseDataSwitch;
+
+ BOOL _passcodeLockOn;
+ BOOL _eraseDataOn;
}
@property (nonatomic, assign) id <KKPasscodeSettingsViewControllerDelegate> delegate;
View
343 Classes/KKPasscodeSettingsViewController.m
@@ -6,7 +6,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@@ -21,260 +21,215 @@
#import "KKPasscodeLock.h"
-///////////////////////////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////////////////////////
@implementation KKPasscodeSettingsViewController
@synthesize delegate = _delegate;
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark UIViewController
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)viewDidLoad
{
- [super viewDidLoad];
- self.navigationItem.title = @"Passcode Lock";
-
- _eraseDataSwitch = [[UISwitch alloc] init];
- [_eraseDataSwitch addTarget:self action:@selector(eraseDataSwitchChanged:) forControlEvents:UIControlEventValueChanged];
+ [super viewDidLoad];
+ self.navigationItem.title = @"Passcode Lock";
+
+ _eraseDataSwitch = [[UISwitch alloc] init];
+ [_eraseDataSwitch addTarget:self action:@selector(eraseDataSwitchChanged:) forControlEvents:UIControlEventValueChanged];
}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)viewWillAppear:(BOOL)animated
{
- [super viewWillAppear:animated];
- _passcodeLockOn = [[KKKeychain getStringForKey:@"passcode_on"] isEqualToString:@"YES"];
- _eraseDataOn = [[KKKeychain getStringForKey:@"erase_data_on"] isEqualToString:@"YES"];
- _eraseDataSwitch.on = _eraseDataOn;
+ [super viewWillAppear:animated];
+ _passcodeLockOn = [[KKKeychain getStringForKey:@"passcode_on"] isEqualToString:@"YES"];
+ _eraseDataOn = [[KKKeychain getStringForKey:@"erase_data_on"] isEqualToString:@"YES"];
+ _eraseDataSwitch.on = _eraseDataOn;
}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
- return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) || (toInterfaceOrientation == UIInterfaceOrientationPortrait);
+ return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) || (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark UIActionSheetDelegate
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
- if (buttonIndex == 0) {
- _eraseDataOn = YES;
- [KKKeychain setString:@"YES" forKey:@"erase_data_on"];
- } else {
- _eraseDataOn = NO;
- [KKKeychain setString:@"NO" forKey:@"erase_data_on"];
- }
- [_eraseDataSwitch setOn:_eraseDataOn animated:YES];
+ if (buttonIndex == 0) {
+ _eraseDataOn = YES;
+ [KKKeychain setString:@"YES" forKey:@"erase_data_on"];
+ } else {
+ _eraseDataOn = NO;
+ [KKKeychain setString:@"NO" forKey:@"erase_data_on"];
+ }
+ [_eraseDataSwitch setOn:_eraseDataOn animated:YES];
}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-- (void)eraseDataSwitchChanged:(id)sender {
- if (_eraseDataSwitch.on) {
- NSString* title = [NSString stringWithFormat:@"All data in this app will be erased after %d failed passcode attempts.", [[KKPasscodeLock sharedLock] attemptsAllowed]];
-
- UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:title delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Enable" otherButtonTitles:nil];
- [sheet showInView:self.view];
- [sheet release];
- } else {
- _eraseDataOn = NO;
- [KKKeychain setString:@"NO" forKey:@"erase_data_on"];
- }
+- (void)eraseDataSwitchChanged:(id)sender
+{
+ if (_eraseDataSwitch.on) {
+ NSString* title = [NSString stringWithFormat:@"All data in this app will be erased after %d failed passcode attempts.", [[KKPasscodeLock sharedLock] attemptsAllowed]];
+
+ UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:title delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Enable" otherButtonTitles:nil];
+ [sheet showInView:self.view];
+ [sheet release];
+ } else {
+ _eraseDataOn = NO;
+ [KKKeychain setString:@"NO" forKey:@"erase_data_on"];
+ }
}
-
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark Table view data source
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
- if ([[KKPasscodeLock sharedLock] eraseOption]) {
- return 3;
- }
-
- return 2;
+ if ([[KKPasscodeLock sharedLock] eraseOption]) {
+ return 3;
+ }
+
+ return 2;
}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
- return 1;
+ return 1;
}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
- if (section == 2) {
- return [NSString stringWithFormat:@"Erase all data in this app after %d failed passcode attempts.", [[KKPasscodeLock sharedLock] attemptsAllowed]];;
- } else {
- return @"";
- }
+ if (section == 2) {
+ return [NSString stringWithFormat:@"Erase all data in this app after %d failed passcode attempts.", [[KKPasscodeLock sharedLock] attemptsAllowed]];;
+ } else {
+ return @"";
+ }
}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-- (UITableViewCell *)tableView:(UITableView *)tableView
- cellForRowAtIndexPath:(NSIndexPath *)indexPath
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
-
- static NSString *CellIdentifier = @"Cell";
-
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- if (cell == nil) {
- cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
- }
-
- if (indexPath.section == 0) {
- if (_passcodeLockOn) {
- cell.textLabel.text = @"Turn Passcode Off";
- } else {
- cell.textLabel.text = @"Turn Passcode On";
- }
- cell.textLabel.textColor = [UIColor blackColor];
- cell.textLabel.textAlignment = UITextAlignmentCenter;
- cell.accessoryView = nil;
- cell.selectionStyle = UITableViewCellSelectionStyleBlue;
- } else if (indexPath.section == 1) {
- cell.textLabel.text = @"Change Passcode";
- if (_passcodeLockOn) {
- cell.textLabel.textColor = [UIColor blackColor];
- cell.selectionStyle = UITableViewCellSelectionStyleBlue;
- } else {
- cell.textLabel.textColor = [UIColor grayColor];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- }
- cell.textLabel.textAlignment = UITextAlignmentCenter;
- cell.accessoryView = nil;
- } else if (indexPath.section == 2) {
- cell.textLabel.text = @"Erase Data";
- cell.textLabel.textAlignment = UITextAlignmentLeft;
- cell.accessoryView = _eraseDataSwitch;
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- if (_passcodeLockOn) {
- cell.textLabel.textColor = [UIColor blackColor];
- _eraseDataSwitch.enabled = YES;
- } else {
- cell.textLabel.textColor = [UIColor grayColor];
- _eraseDataSwitch.enabled = NO;
- }
- }
-
- return cell;
+ static NSString *CellIdentifier = @"Cell";
+
+ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
+ if (cell == nil) {
+ cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
+ }
+
+ if (indexPath.section == 0) {
+ if (_passcodeLockOn) {
+ cell.textLabel.text = @"Turn Passcode Off";
+ } else {
+ cell.textLabel.text = @"Turn Passcode On";
+ }
+ cell.textLabel.textColor = [UIColor blackColor];
+ cell.textLabel.textAlignment = UITextAlignmentCenter;
+ cell.accessoryView = nil;
+ cell.selectionStyle = UITableViewCellSelectionStyleBlue;
+ } else if (indexPath.section == 1) {
+ cell.textLabel.text = @"Change Passcode";
+ if (_passcodeLockOn) {
+ cell.textLabel.textColor = [UIColor blackColor];
+ cell.selectionStyle = UITableViewCellSelectionStyleBlue;
+ } else {
+ cell.textLabel.textColor = [UIColor grayColor];
+ cell.selectionStyle = UITableViewCellSelectionStyleNone;
+ }
+ cell.textLabel.textAlignment = UITextAlignmentCenter;
+ cell.accessoryView = nil;
+ } else if (indexPath.section == 2) {
+ cell.textLabel.text = @"Erase Data";
+ cell.textLabel.textAlignment = UITextAlignmentLeft;
+ cell.accessoryView = _eraseDataSwitch;
+ cell.selectionStyle = UITableViewCellSelectionStyleNone;
+ if (_passcodeLockOn) {
+ cell.textLabel.textColor = [UIColor blackColor];
+ _eraseDataSwitch.enabled = YES;
+ } else {
+ cell.textLabel.textColor = [UIColor grayColor];
+ _eraseDataSwitch.enabled = NO;
+ }
+ }
+
+ return cell;
}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark Table view delegate
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
- if (indexPath.section == 0) {
- KKPasscodeViewController *vc = [[[KKPasscodeViewController alloc] initWithNibName:nil
- bundle:nil] autorelease];
- vc.delegate = self;
-
- if (_passcodeLockOn) {
- vc.mode = KKPasscodeModeDisabled;
- } else {
- vc.mode = KKPasscodeModeSet;
- }
-
- UINavigationController *nav = [[[UINavigationController alloc] initWithRootViewController:vc] autorelease];
-
-
- if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
- nav.modalPresentationStyle = UIModalPresentationFormSheet;
- nav.navigationBar.barStyle = UIBarStyleBlack;
- nav.navigationBar.opaque = NO;
- } else {
- nav.navigationBar.tintColor = self.navigationController.navigationBar.tintColor;
- nav.navigationBar.translucent = self.navigationController.navigationBar.translucent;
- nav.navigationBar.opaque = self.navigationController.navigationBar.opaque;
- nav.navigationBar.barStyle = self.navigationController.navigationBar.barStyle;
- }
-
- [self.navigationController presentModalViewController:nav animated:YES];
-
-
- } else if (indexPath.section == 1 && _passcodeLockOn) {
- KKPasscodeViewController *vc = [[[KKPasscodeViewController alloc] initWithNibName:nil bundle:nil] autorelease];
- vc.delegate = self;
-
- vc.mode = KKPasscodeModeChange;
-
- UINavigationController *nav = [[[UINavigationController alloc] initWithRootViewController:vc] autorelease];
-
-
- if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
- nav.modalPresentationStyle = UIModalPresentationFormSheet;
- nav.navigationBar.barStyle = UIBarStyleBlack;
- nav.navigationBar.opaque = NO;
- } else {
- nav.navigationBar.tintColor = self.navigationController.navigationBar.tintColor;
- nav.navigationBar.translucent = self.navigationController.navigationBar.translucent;
- nav.navigationBar.opaque = self.navigationController.navigationBar.opaque;
- nav.navigationBar.barStyle = self.navigationController.navigationBar.barStyle;
- }
-
- [self.navigationController presentModalViewController:nav animated:YES];
- }
+ if (indexPath.section == 0) {
+ KKPasscodeViewController *vc = [[[KKPasscodeViewController alloc] initWithNibName:nil
+ bundle:nil] autorelease];
+ vc.delegate = self;
+
+ if (_passcodeLockOn) {
+ vc.mode = KKPasscodeModeDisabled;
+ } else {
+ vc.mode = KKPasscodeModeSet;
+ }
+
+ UINavigationController *nav = [[[UINavigationController alloc] initWithRootViewController:vc] autorelease];
+
+ if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
+ nav.modalPresentationStyle = UIModalPresentationFormSheet;
+ nav.navigationBar.barStyle = UIBarStyleBlack;
+ nav.navigationBar.opaque = NO;
+ } else {
+ nav.navigationBar.tintColor = self.navigationController.navigationBar.tintColor;
+ nav.navigationBar.translucent = self.navigationController.navigationBar.translucent;
+ nav.navigationBar.opaque = self.navigationController.navigationBar.opaque;
+ nav.navigationBar.barStyle = self.navigationController.navigationBar.barStyle;
+ }
+
+ [self.navigationController presentModalViewController:nav animated:YES];
+
+
+ } else if (indexPath.section == 1 && _passcodeLockOn) {
+ KKPasscodeViewController *vc = [[[KKPasscodeViewController alloc] initWithNibName:nil bundle:nil] autorelease];
+ vc.delegate = self;
+
+ vc.mode = KKPasscodeModeChange;
+
+ UINavigationController *nav = [[[UINavigationController alloc] initWithRootViewController:vc] autorelease];
+
+
+ if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
+ nav.modalPresentationStyle = UIModalPresentationFormSheet;
+ nav.navigationBar.barStyle = UIBarStyleBlack;
+ nav.navigationBar.opaque = NO;
+ } else {
+ nav.navigationBar.tintColor = self.navigationController.navigationBar.tintColor;
+ nav.navigationBar.translucent = self.navigationController.navigationBar.translucent;
+ nav.navigationBar.opaque = self.navigationController.navigationBar.opaque;
+ nav.navigationBar.barStyle = self.navigationController.navigationBar.barStyle;
+ }
+
+ [self.navigationController presentModalViewController:nav animated:YES];
+ }
}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-- (void)didSettingsChanged:(KKPasscodeViewController*)viewController {
- _passcodeLockOn = [[KKKeychain getStringForKey:@"passcode_on"] isEqualToString:@"YES"];
- _eraseDataOn = [[KKKeychain getStringForKey:@"erase_data_on"] isEqualToString:@"YES"];
- _eraseDataSwitch.on = _eraseDataOn;
-
- [self.tableView reloadData];
-
- if ([_delegate respondsToSelector:@selector(didSettingsChanged:)]) {
- [_delegate performSelector:@selector(didSettingsChanged:) withObject:self];
- }
-
+- (void)didSettingsChanged:(KKPasscodeViewController*)viewController
+{
+ _passcodeLockOn = [[KKKeychain getStringForKey:@"passcode_on"] isEqualToString:@"YES"];
+ _eraseDataOn = [[KKKeychain getStringForKey:@"erase_data_on"] isEqualToString:@"YES"];
+ _eraseDataSwitch.on = _eraseDataOn;
+
+ [self.tableView reloadData];
+
+ if ([_delegate respondsToSelector:@selector(didSettingsChanged:)]) {
+ [_delegate performSelector:@selector(didSettingsChanged:) withObject:self];
+ }
+
}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark Memory management
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)dealloc
{
- [_eraseDataSwitch release];
-
- [super dealloc];
+ [_eraseDataSwitch release];
+ [super dealloc];
}
View
82 Classes/KKPasscodeViewController.h
@@ -6,7 +6,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@@ -19,10 +19,10 @@
enum {
- KKPasscodeModeEnter = 0,
- KKPasscodeModeSet = 1,
- KKPasscodeModeDisabled = 2,
- KKPasscodeModeChange = 3
+ KKPasscodeModeEnter = 0,
+ KKPasscodeModeSet = 1,
+ KKPasscodeModeDisabled = 2,
+ KKPasscodeModeChange = 3
};
typedef NSUInteger KKPasscodeMode;
@@ -34,57 +34,53 @@ typedef NSUInteger KKPasscodeMode;
@optional
- (void)didPasscodeEnteredCorrectly:(KKPasscodeViewController*)viewController;
-
- (void)didPasscodeEnteredIncorrectly:(KKPasscodeViewController*)viewController;
-
- (void)shouldEraseApplicationData:(KKPasscodeViewController*)viewController;
-
- (void)didSettingsChanged:(KKPasscodeViewController*)viewController;
@end
-@interface KKPasscodeViewController : UIViewController <UITextFieldDelegate,
- UITableViewDelegate,
- UITableViewDataSource> {
-
-
- id<KKPasscodeViewControllerDelegate> _delegate;
-
- UILabel* _passcodeConfirmationWarningLabel;
- UIView* _failedAttemptsView;
- UILabel* _failedAttemptsLabel;
- NSInteger _failedAttemptsCount;
-
- NSUInteger _tableIndex;
- NSMutableArray* _tableViews;
- NSMutableArray* _textFields;
- NSMutableArray* _squares;
-
- UITableView* _enterPasscodeTableView;
- UITextField* _enterPasscodeTextField;
- NSArray* _enterPasscodeSquareImageViews;
-
- UITableView* _setPasscodeTableView;
- UITextField* _setPasscodeTextField;
- NSArray* _setPasscodeSquareImageViews;
-
- UITableView* _confirmPasscodeTableView;
- UITextField* _confirmPasscodeTextField;
- NSArray* _confirmPasscodeSquareImageViews;
-
- KKPasscodeMode _mode;
-
- BOOL _passcodeLockOn;
- BOOL _eraseData;
-
- CGFloat _viewWidth;
+@interface KKPasscodeViewController : UIViewController <UITextFieldDelegate, UITableViewDelegate, UITableViewDataSource> {
+
+ id<KKPasscodeViewControllerDelegate> _delegate;
+
+ UILabel* _passcodeConfirmationWarningLabel;
+ UIView* _failedAttemptsView;
+ UILabel* _failedAttemptsLabel;
+ NSInteger _failedAttemptsCount;
+
+ NSUInteger _tableIndex;
+ NSMutableArray* _tableViews;
+ NSMutableArray* _textFields;
+ NSMutableArray* _squares;
+
+ UITableView* _enterPasscodeTableView;
+ UITextField* _enterPasscodeTextField;
+ NSArray* _enterPasscodeSquareImageViews;
+
+ UITableView* _setPasscodeTableView;
+ UITextField* _setPasscodeTextField;
+ NSArray* _setPasscodeSquareImageViews;
+
+ UITableView* _confirmPasscodeTableView;
+ UITextField* _confirmPasscodeTextField;
+ NSArray* _confirmPasscodeSquareImageViews;
+
+ KKPasscodeMode _mode;
+
+ BOOL _passcodeLockOn;
+ BOOL _eraseData;
}
@property (nonatomic, assign) id <KKPasscodeViewControllerDelegate> delegate;
@property (nonatomic, assign) KKPasscodeMode mode;
+@property (nonatomic, retain) UITableView *enterPasscodeTableView;
+@property (nonatomic, retain) UITableView *setPasscodeTableView;
+@property (nonatomic, retain) UITableView *confirmPasscodeTableView;
+
@end
View
1,346 Classes/KKPasscodeViewController.m
@@ -6,7 +6,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@@ -21,12 +21,9 @@
#import "KKPasscodeLock.h"
#import <QuartzCore/QuartzCore.h>
-///////////////////////////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////////////////////////
@interface KKPasscodeViewController(Private)
-- (UITextField*)allocAndInitPasscodeTextField;
+- (UITextField*)newPasscodeTextField;
- (NSArray*)squares;
- (UIView*)passwordHeaderViewForTextField:(UITextField*)textField;
- (void)moveToNextTableView;
@@ -35,794 +32,741 @@ - (void)moveToPreviousTableView;
@end
-///////////////////////////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////////////////////////
@implementation KKPasscodeViewController
@synthesize delegate = _delegate;
@synthesize mode;
+@synthesize enterPasscodeTableView=_enterPasscodeTableView, setPasscodeTableView=_setPasscodeTableView, confirmPasscodeTableView=_confirmPasscodeTableView;
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark UIViewController
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
+- (void)loadView
{
- if (self == [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
- self.modalPresentationStyle = UIModalPresentationFormSheet;
-
- _enterPasscodeTableView = [[UITableView alloc] initWithFrame:self.view.bounds];
- _enterPasscodeTableView.delegate = self;
- _enterPasscodeTableView.dataSource = self;
- _enterPasscodeTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _enterPasscodeTableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
- [self.view addSubview:_enterPasscodeTableView];
-
- _setPasscodeTableView = [[UITableView alloc] initWithFrame:self.view.bounds];
- _setPasscodeTableView.delegate = self;
- _setPasscodeTableView.dataSource = self;
- _setPasscodeTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _setPasscodeTableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
- [self.view addSubview:_setPasscodeTableView];
-
- _confirmPasscodeTableView = [[UITableView alloc] initWithFrame:self.view.bounds];
- _confirmPasscodeTableView.delegate = self;
- _confirmPasscodeTableView.dataSource = self;
- _confirmPasscodeTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _confirmPasscodeTableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
- [self.view addSubview:_confirmPasscodeTableView];
- }
-
- return self;
+ [super loadView];
+
+ self.view.backgroundColor = [UIColor whiteColor];
+
+ self.enterPasscodeTableView = [[[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped] autorelease];
+ _enterPasscodeTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
+ _enterPasscodeTableView.delegate = self;
+ _enterPasscodeTableView.dataSource = self;
+ _enterPasscodeTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
+ _enterPasscodeTableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
+ [self.view addSubview:_enterPasscodeTableView];
+
+ self.setPasscodeTableView = [[[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped] autorelease];
+ _setPasscodeTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
+ _setPasscodeTableView.delegate = self;
+ _setPasscodeTableView.dataSource = self;
+ _setPasscodeTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
+ _setPasscodeTableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
+ [self.view addSubview:_setPasscodeTableView];
+
+ self.confirmPasscodeTableView = [[[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped] autorelease];
+ _confirmPasscodeTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
+ _confirmPasscodeTableView.delegate = self;
+ _confirmPasscodeTableView.dataSource = self;
+ _confirmPasscodeTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
+ _confirmPasscodeTableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
+ [self.view addSubview:_confirmPasscodeTableView];
+
+ [self.view addGestureRecognizer:[[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped:)] autorelease]];
}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
- return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) || (toInterfaceOrientation == UIInterfaceOrientationPortrait);
+ return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) || (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)viewDidLoad
{
- [super viewDidLoad];
-
- _passcodeLockOn = [[KKKeychain getStringForKey:@"passcode_on"] isEqualToString:@"YES"];
- _eraseData = [[KKPasscodeLock sharedLock] eraseOption] && [[KKKeychain getStringForKey:@"erase_data_on"] isEqualToString:@"YES"];
-
- if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
- _viewWidth = 540.0f;
- } else {
- _viewWidth = 320.0f;
- }
+ [super viewDidLoad];
+
+ _passcodeLockOn = [[KKKeychain getStringForKey:@"passcode_on"] isEqualToString:@"YES"];
+ _eraseData = [[KKPasscodeLock sharedLock] eraseOption] && [[KKKeychain getStringForKey:@"erase_data_on"] isEqualToString:@"YES"];
+
}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-- (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
-
- _enterPasscodeTextField = [self allocAndInitPasscodeTextField];
- _setPasscodeTextField = [self allocAndInitPasscodeTextField];
- _confirmPasscodeTextField = [self allocAndInitPasscodeTextField];
-
- _tableViews = [[NSMutableArray alloc] init];
- _textFields = [[NSMutableArray alloc] init];
- _squares = [[NSMutableArray alloc] init];
-
- if (mode == KKPasscodeModeSet || mode == KKPasscodeModeChange) {
- if (_passcodeLockOn) {
- _enterPasscodeTableView.tableHeaderView = [self passwordHeaderViewForTextField:_enterPasscodeTextField];
- [_tableViews addObject:_enterPasscodeTableView];
- [_textFields addObject:_enterPasscodeTextField];
- [_squares addObject:[self squares]];
- for (int i = 0; i < [[_squares lastObject] count]; i++) {
- [_enterPasscodeTableView.tableHeaderView addSubview:[[_squares lastObject] objectAtIndex:i]];
- }
- }
-
- _setPasscodeTableView.tableHeaderView = [self passwordHeaderViewForTextField:_setPasscodeTextField];
- [_tableViews addObject:_setPasscodeTableView];
- [_textFields addObject:_setPasscodeTextField];
- [_squares addObject:[self squares]];
- for (int i = 0; i < [[_squares lastObject] count]; i++) {
- [_setPasscodeTableView.tableHeaderView addSubview:[[_squares lastObject] objectAtIndex:i]];
- }
- _confirmPasscodeTableView.tableHeaderView = [self passwordHeaderViewForTextField:_confirmPasscodeTextField];
- [_tableViews addObject:_confirmPasscodeTableView];
- [_textFields addObject:_confirmPasscodeTextField];
- [_squares addObject:[self squares]];
- for (int i = 0; i < [[_squares lastObject] count]; i++) {
- [_confirmPasscodeTableView.tableHeaderView addSubview:[[_squares lastObject] objectAtIndex:i]];
- }
- } else {
- _enterPasscodeTableView.tableHeaderView = [self passwordHeaderViewForTextField:_enterPasscodeTextField];
- [_tableViews addObject:_enterPasscodeTableView];
- [_textFields addObject:_enterPasscodeTextField];
- [_squares addObject:[self squares]];
- for (int i = 0; i < [[_squares lastObject] count]; i++) {
- [_enterPasscodeTableView.tableHeaderView addSubview:[[_squares lastObject] objectAtIndex:i]];
- }
- }
-
- [self.view addSubview:[_tableViews objectAtIndex:0]];
-
- // shift any extra table views away
- for (int i = 1; i < [_tableViews count]; i++) {
- UITableView *tableView = [_tableViews objectAtIndex:i];
- tableView.frame = CGRectMake(tableView.frame.origin.x + _viewWidth, tableView.frame.origin.y, tableView.frame.size.width, tableView.frame.size.height);
- [self.view addSubview:tableView];
- }
-
-
- [[_textFields objectAtIndex:0] becomeFirstResponder];
- [[_tableViews objectAtIndex:0] reloadData];
- [[_textFields objectAtIndex:[_tableViews count] - 1] setReturnKeyType:UIReturnKeyDone];
-
- if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
- if ([_tableViews count] > 1) {
- [self moveToNextTableView];
- [self moveToPreviousTableView];
- } else {
- UITableView *tv = [_tableViews objectAtIndex:0];
- tv.frame = CGRectMake(tv.frame.origin.x, tv.frame.origin.y, 768.0, 960.0);
- }
- }
+- (void)viewWillAppear:(BOOL)animated
+{
+ [super viewWillAppear:animated];
+
+ _enterPasscodeTextField = [self newPasscodeTextField];
+ _setPasscodeTextField = [self newPasscodeTextField];
+ _confirmPasscodeTextField = [self newPasscodeTextField];
+
+ _tableViews = [[NSMutableArray alloc] init];
+ _textFields = [[NSMutableArray alloc] init];
+ _squares = [[NSMutableArray alloc] init];
+
+ if (mode == KKPasscodeModeSet || mode == KKPasscodeModeChange) {
+ if (_passcodeLockOn) {
+ _enterPasscodeTableView.tableHeaderView = [self passwordHeaderViewForTextField:_enterPasscodeTextField];
+ [_tableViews addObject:_enterPasscodeTableView];
+ [_textFields addObject:_enterPasscodeTextField];
+ [_squares addObject:[self squares]];
+ UIView *squaresView = [[[UIView alloc] initWithFrame:CGRectMake(self.view.bounds.size.width * 0.5 - 71.0 * 4 * 0.5, 0, 71.0 * 4, 53)] autorelease];
+ squaresView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
+ for (int i = 0; i < [[_squares lastObject] count]; i++) {
+ [squaresView addSubview:[[_squares lastObject] objectAtIndex:i]];
+ }
+ [_enterPasscodeTableView.tableHeaderView addSubview:squaresView];
+ }
+
+ _setPasscodeTableView.tableHeaderView = [self passwordHeaderViewForTextField:_setPasscodeTextField];
+ [_tableViews addObject:_setPasscodeTableView];
+ [_textFields addObject:_setPasscodeTextField];
+ [_squares addObject:[self squares]];
+ UIView *squaresView = [[[UIView alloc] initWithFrame:CGRectMake(self.view.bounds.size.width * 0.5 - 71.0 * 4 * 0.5, 0, 71.0 * 4, 53)] autorelease];
+ squaresView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
+ for (int i = 0; i < [[_squares lastObject] count]; i++) {
+ [squaresView addSubview:[[_squares lastObject] objectAtIndex:i]];
+ }
+ [_setPasscodeTableView.tableHeaderView addSubview:squaresView];
+
+ _confirmPasscodeTableView.tableHeaderView = [self passwordHeaderViewForTextField:_confirmPasscodeTextField];
+ [_tableViews addObject:_confirmPasscodeTableView];
+ [_textFields addObject:_confirmPasscodeTextField];
+ [_squares addObject:[self squares]];
+ UIView *squaresConfirmView = [[[UIView alloc] initWithFrame:CGRectMake(self.view.bounds.size.width * 0.5 - 71.0 * 4 * 0.5, 0, 71.0 * 4, 53)] autorelease];
+ squaresConfirmView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
+ for (int i = 0; i < [[_squares lastObject] count]; i++) {
+ [squaresConfirmView addSubview:[[_squares lastObject] objectAtIndex:i]];
+ }
+ [_confirmPasscodeTableView.tableHeaderView addSubview:squaresConfirmView];
+ } else {
+ _enterPasscodeTableView.tableHeaderView = [self passwordHeaderViewForTextField:_enterPasscodeTextField];
+ [_tableViews addObject:_enterPasscodeTableView];
+ [_textFields addObject:_enterPasscodeTextField];
+ [_squares addObject:[self squares]];
+ UIView *squaresView = [[[UIView alloc] initWithFrame:CGRectMake(self.view.bounds.size.width * 0.5 - 71.0 * 4 * 0.5, 0, 71.0 * 4, 53)] autorelease];
+ squaresView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
+ for (int i = 0; i < [[_squares lastObject] count]; i++) {
+ [squaresView addSubview:[[_squares lastObject] objectAtIndex:i]];
+ }
+ [_enterPasscodeTableView.tableHeaderView addSubview:squaresView];
+ }
+
+ [self.view addSubview:[_tableViews objectAtIndex:0]];
+
+ // shift any extra table views away
+ for (int i = 1; i < [_tableViews count]; i++) {
+ UITableView *tableView = [_tableViews objectAtIndex:i];
+ tableView.frame = CGRectMake(tableView.frame.origin.x + self.view.bounds.size.width, tableView.frame.origin.y, tableView.frame.size.width, tableView.frame.size.height);
+ [self.view addSubview:tableView];
+ }
+
+ [[_textFields objectAtIndex:0] becomeFirstResponder];
+ [[_tableViews objectAtIndex:0] reloadData];
+ [[_textFields objectAtIndex:[_tableViews count] - 1] setReturnKeyType:UIReturnKeyDone];
+
+ if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
+ if ([_tableViews count] > 1) {
+ [self moveToNextTableView];
+ [self moveToPreviousTableView];
+ } else {
+ UITableView *tv = [_tableViews objectAtIndex:0];
+ tv.frame = CGRectMake(tv.frame.origin.x, tv.frame.origin.y, self.view.bounds.size.width, self.view.bounds.size.height);
+ }
+ }
}
+- (void)viewTapped:(UITapGestureRecognizer *)recognizer
+{
+ [[_textFields objectAtIndex:_tableIndex] becomeFirstResponder];
+}
-///////////////////////////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark Private
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-- (UITextField*)allocAndInitPasscodeTextField
+- (UITextField*)newPasscodeTextField
{
- UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(29.0, 18.0, 271.0, 24.0)];
- textField.font = [UIFont systemFontOfSize:14];
- textField.text = @"";
- textField.textColor = [UIColor blackColor];
- textField.secureTextEntry = YES;
- textField.delegate = self;
-
- textField.keyboardAppearance = UIKeyboardAppearanceAlert;
-
- return textField;
+ UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(29.0, 18.0, 271.0, 24.0)];
+ textField.font = [UIFont systemFontOfSize:14];
+ textField.text = @"";
+ textField.textColor = [UIColor blackColor];
+ textField.secureTextEntry = YES;
+ textField.delegate = self;
+ textField.keyboardAppearance = UIKeyboardAppearanceAlert;
+ return textField;
}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)cancelButtonPressed:(id)sender
{
- if ([_delegate respondsToSelector:@selector(didSettingsChanged:)]) {
- [_delegate performSelector:@selector(didSettingsChanged:) withObject:self];
- }
-
+ if ([_delegate respondsToSelector:@selector(didSettingsChanged:)]) {
+ [_delegate performSelector:@selector(didSettingsChanged:) withObject:self];
+ }
+
[self dismissModalViewControllerAnimated:YES];
}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)incrementAndShowFailedAttemptsLabel
{
- _enterPasscodeTextField.text = @"";
- for (int i = 0; i < 4; i++) {
- [[[_squares objectAtIndex:_tableIndex] objectAtIndex:i] setImage:[UIImage imageNamed:@"passcode_square_empty.png"]];
- }
-
- _failedAttemptsCount += 1;
- if (_failedAttemptsCount == 1) {
- _failedAttemptsLabel.text = @"1 Failed Passcode Attempt";
- } else {
- _failedAttemptsLabel.text = [NSString stringWithFormat:@"%i Failed Passcode Attempts", _failedAttemptsCount];
- }
- CGSize size = [_failedAttemptsLabel.text sizeWithFont:[UIFont boldSystemFontOfSize:14.0]];
- _failedAttemptsView.frame = CGRectMake((_viewWidth - (size.width + 36.0)) / 2, 147.5, size.width + 36.0, size.height + 10.0);
- _failedAttemptsLabel.frame = CGRectMake((_viewWidth - (size.width + 36.0)) / 2, 147.5, size.width + 36.0, size.height + 10.0);
-
- CAGradientLayer *gradient = [CAGradientLayer layer];
- gradient.frame = _failedAttemptsView.bounds;
- gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithRed:0.714 green:0.043 blue:0.043 alpha:1.0] CGColor],
- (id)[[UIColor colorWithRed:0.761 green:0.192 blue:0.192 alpha:1.0] CGColor], nil];
- [_failedAttemptsView.layer insertSublayer:gradient atIndex:0];
- _failedAttemptsView.layer.masksToBounds = YES;
-
- _failedAttemptsLabel.hidden = NO;
- _failedAttemptsView.hidden = NO;
-
- if (_failedAttemptsCount == [[KKPasscodeLock sharedLock] attemptsAllowed]) {
-
- _enterPasscodeTextField.delegate = nil;
-
- if (_eraseData) {
- if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
- [UIView beginAnimations:@"fadeIn" context:nil];
- [UIView setAnimationDelay:0.25];
- [UIView setAnimationDuration:0.5];
-
- [UIView commitAnimations];
- }
-
- if ([_delegate respondsToSelector:@selector(shouldEraseApplicationData:)]) {
- [_delegate shouldEraseApplicationData:self];
- }
- } else {
- if ([_delegate respondsToSelector:@selector(didPasscodeEnteredIncorrectly:)]) {
- [_delegate didPasscodeEnteredIncorrectly:self];
- }
- }
- }
-
+ _enterPasscodeTextField.text = @"";
+ for (int i = 0; i < 4; i++) {
+ [[[_squares objectAtIndex:_tableIndex] objectAtIndex:i] setImage:[UIImage imageNamed:@"passcode_square_empty.png"]];
+ }
+
+ _failedAttemptsCount += 1;
+ if (_failedAttemptsCount == 1) {
+ _failedAttemptsLabel.text = @"1 Failed Passcode Attempt";
+ } else {
+ _failedAttemptsLabel.text = [NSString stringWithFormat:@"%i Failed Passcode Attempts", _failedAttemptsCount];
+ }
+ CGSize size = [_failedAttemptsLabel.text sizeWithFont:[UIFont boldSystemFontOfSize:14.0]];
+ _failedAttemptsView.frame = CGRectMake((self.view.bounds.size.width - (size.width + 36.0)) / 2, 147.5, size.width + 36.0, size.height + 10.0);
+ _failedAttemptsLabel.frame = CGRectMake((self.view.bounds.size.width - (size.width + 36.0)) / 2, 147.5, size.width + 36.0, size.height + 10.0);
+
+ CAGradientLayer *gradient = [CAGradientLayer layer];
+ gradient.frame = _failedAttemptsView.bounds;
+ gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithRed:0.714 green:0.043 blue:0.043 alpha:1.0] CGColor],
+ (id)[[UIColor colorWithRed:0.761 green:0.192 blue:0.192 alpha:1.0] CGColor], nil];
+ [_failedAttemptsView.layer insertSublayer:gradient atIndex:0];
+ _failedAttemptsView.layer.masksToBounds = YES;
+
+ _failedAttemptsLabel.hidden = NO;
+ _failedAttemptsView.hidden = NO;
+
+ if (_failedAttemptsCount == [[KKPasscodeLock sharedLock] attemptsAllowed]) {
+
+ _enterPasscodeTextField.delegate = nil;
+
+ if (_eraseData) {
+ if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
+ [UIView beginAnimations:@"fadeIn" context:nil];
+ [UIView setAnimationDelay:0.25];
+ [UIView setAnimationDuration:0.5];
+
+ [UIView commitAnimations];
+ }
+
+ if ([_delegate respondsToSelector:@selector(shouldEraseApplicationData:)]) {
+ [_delegate shouldEraseApplicationData:self];
+ }
+ } else {
+ if ([_delegate respondsToSelector:@selector(didPasscodeEnteredIncorrectly:)]) {
+ [_delegate didPasscodeEnteredIncorrectly:self];
+ }
+ }
+ }
+
}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)moveToNextTableView
{
- _tableIndex += 1;
- UITableView *oldTableView = [_tableViews objectAtIndex:_tableIndex - 1];
- UITableView *newTableView = [_tableViews objectAtIndex:_tableIndex];
- newTableView.frame = CGRectMake(oldTableView.frame.origin.x + _viewWidth, oldTableView.frame.origin.y, oldTableView.frame.size.width, oldTableView.frame.size.height);
-
- for (int i = 0; i < 4; i++) {
- [[[_squares objectAtIndex:_tableIndex] objectAtIndex:i] setImage:[UIImage imageNamed:@"passcode_square_empty.png"]];
- }
-
- [UIView beginAnimations:@"" context:nil];
- [UIView setAnimationDuration:0.25];
- oldTableView.frame = CGRectMake(oldTableView.frame.origin.x - _viewWidth, oldTableView.frame.origin.y, oldTableView.frame.size.width, oldTableView.frame.size.height);
- newTableView.frame = self.view.frame;
- [UIView commitAnimations];
-
-
- [[_textFields objectAtIndex:_tableIndex - 1] resignFirstResponder];
- [[_textFields objectAtIndex:_tableIndex] becomeFirstResponder];
+ _tableIndex += 1;
+ UITableView *oldTableView = [_tableViews objectAtIndex:_tableIndex - 1];
+ UITableView *newTableView = [_tableViews objectAtIndex:_tableIndex];
+ newTableView.frame = CGRectMake(oldTableView.frame.origin.x + self.view.bounds.size.width, oldTableView.frame.origin.y, oldTableView.frame.size.width, oldTableView.frame.size.height);
+
+ for (int i = 0; i < 4; i++) {
+ [[[_squares objectAtIndex:_tableIndex] objectAtIndex:i] setImage:[UIImage imageNamed:@"passcode_square_empty.png"]];
+ }
+
+ [UIView beginAnimations:@"" context:nil];
+ [UIView setAnimationDuration:0.25];
+ oldTableView.frame = CGRectMake(oldTableView.frame.origin.x - self.view.bounds.size.width, oldTableView.frame.origin.y, oldTableView.frame.size.width, oldTableView.frame.size.height);
+ newTableView.frame = self.view.frame;
+ [UIView commitAnimations];
+
+
+ [[_textFields objectAtIndex:_tableIndex - 1] resignFirstResponder];
+ [[_textFields objectAtIndex:_tableIndex] becomeFirstResponder];
}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)moveToPreviousTableView
{
- _tableIndex -= 1;
- UITableView *oldTableView = [_tableViews objectAtIndex:_tableIndex + 1];
- UITableView *newTableView = [_tableViews objectAtIndex:_tableIndex];
- newTableView.frame = CGRectMake(oldTableView.frame.origin.x - _viewWidth, oldTableView.frame.origin.y, oldTableView.frame.size.width, oldTableView.frame.size.height);
-
- for (int i = 0; i < 4; i++) {
- [[[_squares objectAtIndex:_tableIndex] objectAtIndex:i] setImage:[UIImage imageNamed:@"passcode_square_empty.png"]];
- }
-
- [UIView beginAnimations:@"" context:nil];
- [UIView setAnimationDuration:0.25];
- oldTableView.frame = CGRectMake(oldTableView.frame.origin.x + _viewWidth, oldTableView.frame.origin.y, oldTableView.frame.size.width, oldTableView.frame.size.height);
- newTableView.frame = self.view.frame;
- [UIView commitAnimations];
-
-
-
- [[_textFields objectAtIndex:_tableIndex + 1] resignFirstResponder];
- [[_textFields objectAtIndex:_tableIndex] becomeFirstResponder];
+ _tableIndex -= 1;
+ UITableView *oldTableView = [_tableViews objectAtIndex:_tableIndex + 1];
+ UITableView *newTableView = [_tableViews objectAtIndex:_tableIndex];
+ newTableView.frame = CGRectMake(oldTableView.frame.origin.x - self.view.bounds.size.width, oldTableView.frame.origin.y, oldTableView.frame.size.width, oldTableView.frame.size.height);
+
+ for (int i = 0; i < 4; i++) {
+ [[[_squares objectAtIndex:_tableIndex] objectAtIndex:i] setImage:[UIImage imageNamed:@"passcode_square_empty.png"]];
+ }
+
+ [UIView beginAnimations:@"" context:nil];
+ [UIView setAnimationDuration:0.25];
+ oldTableView.frame = CGRectMake(oldTableView.frame.origin.x + self.view.bounds.size.width, oldTableView.frame.origin.y, oldTableView.frame.size.width, oldTableView.frame.size.height);
+ newTableView.frame = self.view.frame;
+ [UIView commitAnimations];
+
+ [[_textFields objectAtIndex:_tableIndex + 1] resignFirstResponder];
+ [[_textFields objectAtIndex:_tableIndex] becomeFirstResponder];
}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)nextDigitPressed
{
-
- UITextField *textField = [_textFields objectAtIndex:_tableIndex];
-
- if (![textField.text isEqualToString:@""]) {
-
- if (mode == KKPasscodeModeSet) {
- if ([textField isEqual:_setPasscodeTextField]) {
- [self moveToNextTableView];
- } else if ([textField isEqual:_confirmPasscodeTextField]) {
- if (![_confirmPasscodeTextField.text isEqualToString:_setPasscodeTextField.text]) {
- _confirmPasscodeTextField.text = @"";
- _setPasscodeTextField.text = @"";
- _passcodeConfirmationWarningLabel.text = @"Passcodes did not match. Try again.";
- [self moveToPreviousTableView];
- } else {
- if ([KKKeychain setString:_setPasscodeTextField.text forKey:@"passcode"]) {
- [KKKeychain setString:@"YES" forKey:@"passcode_on"];
- }
-
- if ([_delegate respondsToSelector:@selector(didSettingsChanged:)]) {
- [_delegate performSelector:@selector(didSettingsChanged:) withObject:self];
- }
-
- [self dismissModalViewControllerAnimated:YES];
- }
- }
- } else if (mode == KKPasscodeModeChange) {
- NSString *passcode = [KKKeychain getStringForKey:@"passcode"];
- if ([textField isEqual:_enterPasscodeTextField]) {
- if ([passcode isEqualToString:_enterPasscodeTextField.text]) {
- [self moveToNextTableView];
- } else {
- [self incrementAndShowFailedAttemptsLabel];
- }
- } else if ([textField isEqual:_setPasscodeTextField]) {
- if ([passcode isEqualToString:_setPasscodeTextField.text]) {
- _setPasscodeTextField.text = @"";
- _passcodeConfirmationWarningLabel.text = @"Enter a different passcode. You cannot re-use the same passcode.";
- _passcodeConfirmationWarningLabel.frame = CGRectMake(0.0, 131.5, _viewWidth, 60.0);
- } else {
- _passcodeConfirmationWarningLabel.text = @"";
- _passcodeConfirmationWarningLabel.frame = CGRectMake(0.0, 146.5, _viewWidth, 30.0);
- [self moveToNextTableView];
- }
- } else if ([textField isEqual:_confirmPasscodeTextField]) {
- if (![_confirmPasscodeTextField.text isEqualToString:_setPasscodeTextField.text]) {
- _confirmPasscodeTextField.text = @"";
- _setPasscodeTextField.text = @"";
- _passcodeConfirmationWarningLabel.text = @"Passcodes did not match. Try again.";
- [self moveToPreviousTableView];
- } else {
- if ([KKKeychain setString:_setPasscodeTextField.text forKey:@"passcode"]) {
- [KKKeychain setString:@"YES" forKey:@"passcode_on"];
- }
-
- if ([_delegate respondsToSelector:@selector(didSettingsChanged:)]) {
- [_delegate performSelector:@selector(didSettingsChanged:) withObject:self];
- }
-
- [self dismissModalViewControllerAnimated:YES];
- }
- }
- }
- }
+ UITextField *textField = [_textFields objectAtIndex:_tableIndex];
+
+ if (![textField.text isEqualToString:@""]) {
+
+ if (mode == KKPasscodeModeSet) {
+ if ([textField isEqual:_setPasscodeTextField]) {
+ [self moveToNextTableView];
+ } else if ([textField isEqual:_confirmPasscodeTextField]) {
+ if (![_confirmPasscodeTextField.text isEqualToString:_setPasscodeTextField.text]) {
+ _confirmPasscodeTextField.text = @"";
+ _setPasscodeTextField.text = @"";
+ _passcodeConfirmationWarningLabel.text = @"Passcodes did not match. Try again.";
+ [self moveToPreviousTableView];
+ } else {
+ if ([KKKeychain setString:_setPasscodeTextField.text forKey:@"passcode"]) {
+ [KKKeychain setString:@"YES" forKey:@"passcode_on"];
+ }
+
+ if ([_delegate respondsToSelector:@selector(didSettingsChanged:)]) {
+ [_delegate performSelector:@selector(didSettingsChanged:) withObject:self];
+ }
+
+ [self dismissModalViewControllerAnimated:YES];
+ }
+ }
+ } else if (mode == KKPasscodeModeChange) {
+ NSString *passcode = [KKKeychain getStringForKey:@"passcode"];
+ if ([textField isEqual:_enterPasscodeTextField]) {
+ if ([passcode isEqualToString:_enterPasscodeTextField.text]) {
+ [self moveToNextTableView];
+ } else {
+ [self incrementAndShowFailedAttemptsLabel];
+ }
+ } else if ([textField isEqual:_setPasscodeTextField]) {
+ if ([passcode isEqualToString:_setPasscodeTextField.text]) {
+ _setPasscodeTextField.text = @"";
+ _passcodeConfirmationWarningLabel.text = @"Enter a different passcode. You cannot re-use the same passcode.";
+ _passcodeConfirmationWarningLabel.frame = CGRectMake(0.0, 131.5, self.view.bounds.size.width, 60.0);
+ } else {
+ _passcodeConfirmationWarningLabel.text = @"";
+ _passcodeConfirmationWarningLabel.frame = CGRectMake(0.0, 146.5, self.view.bounds.size.width, 30.0);
+ [self moveToNextTableView];
+ }
+ } else if ([textField isEqual:_confirmPasscodeTextField]) {
+ if (![_confirmPasscodeTextField.text isEqualToString:_setPasscodeTextField.text]) {
+ _confirmPasscodeTextField.text = @"";
+ _setPasscodeTextField.text = @"";
+ _passcodeConfirmationWarningLabel.text = @"Passcodes did not match. Try again.";
+ [self moveToPreviousTableView];
+ } else {
+ if ([KKKeychain setString:_setPasscodeTextField.text forKey:@"passcode"]) {
+ [KKKeychain setString:@"YES" forKey:@"passcode_on"];
+ }
+
+ if ([_delegate respondsToSelector:@selector(didSettingsChanged:)]) {
+ [_delegate performSelector:@selector(didSettingsChanged:) withObject:self];
+ }
+
+ [self dismissModalViewControllerAnimated:YES];
+ }
+ }
+ }
+ }
}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)doneButtonPressed
-{
-
- UITextField *textField = [_textFields objectAtIndex:_tableIndex];
-
- if (mode == KKPasscodeModeEnter) {
- NSString *passcode = [KKKeychain getStringForKey:@"passcode"];
- if ([_enterPasscodeTextField.text isEqualToString:passcode]) {
- if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
- [UIView beginAnimations:@"fadeIn" context:nil];
- [UIView setAnimationDelay:0.25];
- [UIView setAnimationDuration:0.5];
-
- [UIView commitAnimations];
- }
-
- if ([_delegate respondsToSelector:@selector(didPasscodeEnteredCorrectly::)]) {
- [_delegate didPasscodeEnteredCorrectly:self];
- }
-
- [self dismissModalViewControllerAnimated:YES];
- } else {
- [self incrementAndShowFailedAttemptsLabel];
- }
- } else if (mode == KKPasscodeModeSet) {
- if ([textField isEqual:_setPasscodeTextField]) {
- [self moveToNextTableView];
- } else if ([textField isEqual:_confirmPasscodeTextField]) {
- if (![_confirmPasscodeTextField.text isEqualToString:_setPasscodeTextField.text]) {
- _confirmPasscodeTextField.text = @"";
- _setPasscodeTextField.text = @"";
- _passcodeConfirmationWarningLabel.text = @"Passcodes did not match. Try again.";
- [self moveToPreviousTableView];
- } else {
- if ([KKKeychain setString:_setPasscodeTextField.text forKey:@"passcode"]) {
- [KKKeychain setString:@"YES" forKey:@"passcode_on"];
- }
-
- if ([_delegate respondsToSelector:@selector(didSettingsChanged:)]) {
- [_delegate performSelector:@selector(didSettingsChanged:) withObject:self];
- }
-
- [self dismissModalViewControllerAnimated:YES];
- }
- }
- } else if (mode == KKPasscodeModeChange) {
- NSString *passcode = [KKKeychain getStringForKey:@"passcode"];
- if ([textField isEqual:_enterPasscodeTextField]) {
- if ([passcode isEqualToString:_enterPasscodeTextField.text]) {
- [self moveToNextTableView];
- } else {
- [self incrementAndShowFailedAttemptsLabel];
- }
- } else if ([textField isEqual:_setPasscodeTextField]) {
- if ([passcode isEqualToString:_setPasscodeTextField.text]) {
- _setPasscodeTextField.text = @"";
- _passcodeConfirmationWarningLabel.text = @"Enter a different passcode. Cannot re-use the same passcode.";
- _passcodeConfirmationWarningLabel.frame = CGRectMake(0.0, 131.5, _viewWidth, 60.0);
- } else {
- _passcodeConfirmationWarningLabel.text = @"";
- _passcodeConfirmationWarningLabel.frame = CGRectMake(0.0, 146.5, _viewWidth, 30.0);
- [self moveToNextTableView];
- }
- } else if ([textField isEqual:_confirmPasscodeTextField]) {
- if (![_confirmPasscodeTextField.text isEqualToString:_setPasscodeTextField.text]) {
- _confirmPasscodeTextField.text = @"";
- _setPasscodeTextField.text = @"";
- _passcodeConfirmationWarningLabel.text = @"Passcodes did not match. Try again.";
- [self moveToPreviousTableView];
- } else {
- if ([KKKeychain setString:_setPasscodeTextField.text forKey:@"passcode"]) {
- [KKKeychain setString:@"YES" forKey:@"passcode_on"];
- }
-
- if ([_delegate respondsToSelector:@selector(didSettingsChanged:)]) {
- [_delegate performSelector:@selector(didSettingsChanged:) withObject:self];
- }
-
- [self dismissModalViewControllerAnimated:YES];
- }
- }
- } else if (mode == KKPasscodeModeDisabled) {
- NSString *passcode = [KKKeychain getStringForKey:@"passcode"];
- if ([_enterPasscodeTextField.text isEqualToString:passcode]) {
- if ([KKKeychain setString:@"NO" forKey:@"passcode_on"]) {
- [KKKeychain setString:@"" forKey:@"passcode"];
- }
-
- if ([_delegate respondsToSelector:@selector(didSettingsChanged:)]) {
- [_delegate performSelector:@selector(didSettingsChanged:) withObject:self];
- }
-
- [self dismissModalViewControllerAnimated:YES];
- } else {
- [self incrementAndShowFailedAttemptsLabel];
- }
- }
+{
+ UITextField *textField = [_textFields objectAtIndex:_tableIndex];
+
+ if (mode == KKPasscodeModeEnter) {
+ NSString *passcode = [KKKeychain getStringForKey:@"passcode"];
+ if ([_enterPasscodeTextField.text isEqualToString:passcode]) {
+ if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
+ [UIView beginAnimations:@"fadeIn" context:nil];
+ [UIView setAnimationDelay:0.25];
+ [UIView setAnimationDuration:0.5];
+
+ [UIView commitAnimations];
+ }
+
+ if ([_delegate respondsToSelector:@selector(didPasscodeEnteredCorrectly::)]) {
+ [_delegate didPasscodeEnteredCorrectly:self];
+ }
+
+ [self dismissModalViewControllerAnimated:YES];
+ } else {
+ [self incrementAndShowFailedAttemptsLabel];
+ }
+ } else if (mode == KKPasscodeModeSet) {
+ if ([textField isEqual:_setPasscodeTextField]) {
+ [self moveToNextTableView];
+ } else if ([textField isEqual:_confirmPasscodeTextField]) {
+ if (![_confirmPasscodeTextField.text isEqualToString:_setPasscodeTextField.text]) {
+ _confirmPasscodeTextField.text = @"";
+ _setPasscodeTextField.text = @"";
+ _passcodeConfirmationWarningLabel.text = @"Passcodes did not match. Try again.";
+ [self moveToPreviousTableView];
+ } else {
+ if ([KKKeychain setString:_setPasscodeTextField.text forKey:@"passcode"]) {
+ [KKKeychain setString:@"YES" forKey:@"passcode_on"];
+ }
+
+ if ([_delegate respondsToSelector:@selector(didSettingsChanged:)]) {
+ [_delegate performSelector:@selector(didSettingsChanged:) withObject:self];
+ }
+
+ [self dismissModalViewControllerAnimated:YES];
+ }
+ }
+ } else if (mode == KKPasscodeModeChange) {
+ NSString *passcode = [KKKeychain getStringForKey:@"passcode"];
+ if ([textField isEqual:_enterPasscodeTextField]) {
+ if ([passcode isEqualToString:_enterPasscodeTextField.text]) {
+ [self moveToNextTableView];
+ } else {
+ [self incrementAndShowFailedAttemptsLabel];
+ }
+ } else if ([textField isEqual:_setPasscodeTextField]) {
+ if ([passcode isEqualToString:_setPasscodeTextField.text]) {
+ _setPasscodeTextField.text = @"";
+ _passcodeConfirmationWarningLabel.text = @"Enter a different passcode. Cannot re-use the same passcode.";
+ _passcodeConfirmationWarningLabel.frame = CGRectMake(0.0, 131.5, self.view.bounds.size.width, 60.0);
+ } else {
+ _passcodeConfirmationWarningLabel.text = @"";
+ _passcodeConfirmationWarningLabel.frame = CGRectMake(0.0, 146.5, self.view.bounds.size.width, 30.0);
+ [self moveToNextTableView];
+ }
+ } else if ([textField isEqual:_confirmPasscodeTextField]) {
+ if (![_confirmPasscodeTextField.text isEqualToString:_setPasscodeTextField.text]) {
+ _confirmPasscodeTextField.text = @"";
+ _setPasscodeTextField.text = @"";
+ _passcodeConfirmationWarningLabel.text = @"Passcodes did not match. Try again.";
+ [self moveToPreviousTableView];
+ } else {
+ if ([KKKeychain setString:_setPasscodeTextField.text forKey:@"passcode"]) {
+ [KKKeychain setString:@"YES" forKey:@"passcode_on"];
+ }
+
+ if ([_delegate respondsToSelector:@selector(didSettingsChanged:)]) {
+ [_delegate performSelector:@selector(didSettingsChanged:) withObject:self];
+ }
+
+ [self dismissModalViewControllerAnimated:YES];
+ }
+ }
+ } else if (mode == KKPasscodeModeDisabled) {
+ NSString *passcode = [KKKeychain getStringForKey:@"passcode"];
+ if ([_enterPasscodeTextField.text isEqualToString:passcode]) {
+ if ([KKKeychain setString:@"NO" forKey:@"passcode_on"]) {
+ [KKKeychain setString:@"" forKey:@"passcode"];
+ }
+
+ if ([_delegate respondsToSelector:@selector(didSettingsChanged:)]) {
+ [_delegate performSelector:@selector(didSettingsChanged:) withObject:self];
+ }
+
+ [self dismissModalViewControllerAnimated:YES];
+ } else {
+ [self incrementAndShowFailedAttemptsLabel];
+ }
+ }
}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
- (UIView*)passwordHeaderViewForTextField:(UITextField*)textField
{
-
- textField.keyboardType = UIKeyboardTypeNumberPad;
-
- textField.hidden = YES;
- [self.view addSubview:textField];
-
- UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, _viewWidth, 70.0)] autorelease];
- UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 27.5, _viewWidth, 30.0)];
- headerLabel.textColor = [UIColor colorWithRed:0.298 green:0.337 blue:0.424 alpha:1.0];
- headerLabel.backgroundColor = [UIColor clearColor];
- headerLabel.textAlignment = UITextAlignmentCenter;
- headerLabel.font = [UIFont boldSystemFontOfSize:17.0];
- headerLabel.shadowOffset = CGSizeMake(0, 1.0);
- headerLabel.shadowColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
-
- if ([textField isEqual:_setPasscodeTextField]) {
- _passcodeConfirmationWarningLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 146.5, _viewWidth, 30.0)];
- _passcodeConfirmationWarningLabel.textColor = [UIColor colorWithRed:0.298 green:0.337 blue:0.424 alpha:1.0];
- _passcodeConfirmationWarningLabel.backgroundColor = [UIColor clearColor];
- _passcodeConfirmationWarningLabel.textAlignment = UITextAlignmentCenter;
- _passcodeConfirmationWarningLabel.font = [UIFont systemFontOfSize:14.0];
- _passcodeConfirmationWarningLabel.shadowOffset = CGSizeMake(0, 1.0);
- _passcodeConfirmationWarningLabel.shadowColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
- _passcodeConfirmationWarningLabel.text = @"";
- _passcodeConfirmationWarningLabel.numberOfLines = 0;
- _passcodeConfirmationWarningLabel.lineBreakMode = UILineBreakModeWordWrap;
- [headerView addSubview:_passcodeConfirmationWarningLabel];
- }
-
- if ([textField isEqual:_enterPasscodeTextField]) {
-
- NSString *text = @"1 Failed Passcode Attempt";
- CGSize size = [text sizeWithFont:[UIFont boldSystemFontOfSize:14.0]];
- _failedAttemptsView = [[UIView alloc] initWithFrame:CGRectMake((_viewWidth - (size.width + 36.0)) / 2, 147.5, size.width + 36.0, size.height + 10.0)];
- _failedAttemptsLabel = [[UILabel alloc] initWithFrame:CGRectMake((_viewWidth - (size.width + 36.0)) / 2, 147.5, size.width + 36.0, size.height + 10.0)];
- _failedAttemptsLabel.backgroundColor = [UIColor clearColor];
- _failedAttemptsLabel.textColor = [UIColor whiteColor];
- _failedAttemptsLabel.text = text;
- _failedAttemptsLabel.font = [UIFont boldSystemFontOfSize:14.0];
- _failedAttemptsLabel.textAlignment = UITextAlignmentCenter;
- _failedAttemptsLabel.shadowOffset = CGSizeMake(0, -1.0);
- _failedAttemptsLabel.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0];
- _failedAttemptsView.layer.cornerRadius = 14;
- _failedAttemptsView.layer.borderWidth = 1.0;
- _failedAttemptsView.layer.borderColor = [[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.25] CGColor];
-
- _failedAttemptsLabel.hidden = YES;
- _failedAttemptsView.hidden = YES;
-
- CAGradientLayer *gradient = [CAGradientLayer layer];
- gradient.frame = _failedAttemptsView.bounds;
- gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithRed:0.714 green:0.043 blue:0.043 alpha:1.0] CGColor],
- (id)[[UIColor colorWithRed:0.761 green:0.192 blue:0.192 alpha:1.0] CGColor], nil];
- [_failedAttemptsView.layer insertSublayer:gradient atIndex:1];
- _failedAttemptsView.layer.masksToBounds = YES;
-
- [headerView addSubview:_failedAttemptsView];
- [headerView addSubview:_failedAttemptsLabel];
-
- [_failedAttemptsView release];
- [_failedAttemptsLabel release];
- }
-
- if (mode == KKPasscodeModeSet) {
- self.navigationItem.title = @"Set Passcode";
- UIBarButtonItem *cancel = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonPressed:)];
- self.navigationItem.leftBarButtonItem = cancel;
- [cancel release];
-
-
- if ([textField isEqual:_enterPasscodeTextField]) {
- headerLabel.text = @"Enter your passcode";
- } else if ([textField isEqual:_setPasscodeTextField]) {
- headerLabel.text = @"Enter a passcode";
- UIBarButtonItem *cancel = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonPressed:)];
- self.navigationItem.leftBarButtonItem = cancel;
- [cancel release];
-
- } else if ([textField isEqual:_confirmPasscodeTextField]) {
- headerLabel.text = @"Re-enter your passcode";
- }
- } else if (mode == KKPasscodeModeDisabled) {
- self.navigationItem.title = @"Turn off Passcode";
- UIBarButtonItem *cancel = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonPressed:)];
- self.navigationItem.leftBarButtonItem = cancel;
- [cancel release];
-
- headerLabel.text = @"Enter your passcode";
- } else if (mode == KKPasscodeModeChange) {
- self.navigationItem.title = @"Change Passcode";
- UIBarButtonItem *cancel = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonPressed:)];
- self.navigationItem.leftBarButtonItem = cancel;
- [cancel release];
-
- if ([textField isEqual:_enterPasscodeTextField]) {
- headerLabel.text = @"Enter your old passcode";
- } else if ([textField isEqual:_setPasscodeTextField]) {
- headerLabel.text = @"Enter your new passcode";
- } else {
- headerLabel.text = @"Re-enter your new passcode";
- }
- } else {
- self.navigationItem.title = @"Enter Passcode";
- headerLabel.text = @"Enter your passcode";
- }
-
- [headerView addSubview:headerLabel];
- [headerLabel release];
-
- return headerView;
+ textField.keyboardType = UIKeyboardTypeNumberPad;
+
+ textField.hidden = YES;
+ [self.view addSubview:textField];
+
+ UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.bounds.size.width, 70.0)] autorelease];
+ UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 27.5, self.view.bounds.size.width, 30.0)];
+ headerLabel.textColor = [UIColor colorWithRed:0.298 green:0.337 blue:0.424 alpha:1.0];
+ headerLabel.backgroundColor = [UIColor clearColor];
+ headerLabel.textAlignment = UITextAlignmentCenter;
+ headerLabel.font = [UIFont boldSystemFontOfSize:17.0];
+ headerLabel.shadowOffset = CGSizeMake(0, 1.0);
+ headerLabel.shadowColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
+
+ if ([textField isEqual:_setPasscodeTextField]) {
+ _passcodeConfirmationWarningLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 146.5, self.view.bounds.size.width, 30.0)];
+ _passcodeConfirmationWarningLabel.textColor = [UIColor colorWithRed:0.298 green:0.337 blue:0.424 alpha:1.0];
+ _passcodeConfirmationWarningLabel.backgroundColor = [UIColor clearColor];
+ _passcodeConfirmationWarningLabel.textAlignment = UITextAlignmentCenter;
+ _passcodeConfirmationWarningLabel.font = [UIFont systemFontOfSize:14.0];
+ _passcodeConfirmationWarningLabel.shadowOffset = CGSizeMake(0, 1.0);
+ _passcodeConfirmationWarningLabel.shadowColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
+ _passcodeConfirmationWarningLabel.text = @"";
+ _passcodeConfirmationWarningLabel.numberOfLines = 0;
+ _passcodeConfirmationWarningLabel.lineBreakMode = UILineBreakModeWordWrap;
+ [headerView addSubview:_passcodeConfirmationWarningLabel];
+ }
+
+ if ([textField isEqual:_enterPasscodeTextField]) {
+ NSString *text = @"1 Failed Passcode Attempt";
+ CGSize size = [text sizeWithFont:[UIFont boldSystemFontOfSize:14.0]];
+ _failedAttemptsView = [[UIView alloc] initWithFrame:CGRectMake((self.view.bounds.size.width - (size.width + 36.0)) / 2, 147.5, size.width + 36.0, size.height + 10.0)];
+ _failedAttemptsLabel = [[UILabel alloc] initWithFrame:CGRectMake((self.view.bounds.size.width - (size.width + 36.0)) / 2, 147.5, size.width + 36.0, size.height + 10.0)];
+ _failedAttemptsLabel.backgroundColor = [UIColor clearColor];
+ _failedAttemptsLabel.textColor = [UIColor whiteColor];
+ _failedAttemptsLabel.text = text;
+ _failedAttemptsLabel.font = [UIFont boldSystemFontOfSize:14.0];
+ _failedAttemptsLabel.textAlignment = UITextAlignmentCenter;
+ _failedAttemptsLabel.shadowOffset = CGSizeMake(0, -1.0);
+ _failedAttemptsLabel.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0];
+ _failedAttemptsView.layer.cornerRadius = 14;
+ _failedAttemptsView.layer.borderWidth = 1.0;
+ _failedAttemptsView.layer.borderColor = [[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.25] CGColor];
+
+ _failedAttemptsLabel.hidden = YES;
+ _failedAttemptsView.hidden = YES;
+
+ CAGradientLayer *gradient = [CAGradientLayer layer];
+ gradient.frame = _failedAttemptsView.bounds;
+ gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithRed:0.714 green:0.043 blue:0.043 alpha:1.0] CGColor],
+ (id)[[UIColor colorWithRed:0.761 green:0.192 blue:0.192 alpha:1.0] CGColor], nil];
+ [_failedAttemptsView.layer insertSublayer:gradient atIndex:1];
+ _failedAttemptsView.layer.masksToBounds = YES;
+
+ [headerView addSubview:_failedAttemptsView];
+ [headerView addSubview:_failedAttemptsLabel];
+
+ [_failedAttemptsView release];
+ [_failedAttemptsLabel release];
+ }
+
+ if (mode == KKPasscodeModeSet) {
+ self.navigationItem.title = @"Set Passcode";
+ UIBarButtonItem *cancel = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonPressed:)];
+ self.navigationItem.leftBarButtonItem = cancel;
+ [cancel release];
+
+
+ if ([textField isEqual:_enterPasscodeTextField]) {
+ headerLabel.text = @"Enter your passcode";
+ } else if ([textField isEqual:_setPasscodeTextField]) {
+ headerLabel.text = @"Enter a passcode";
+ UIBarButtonItem *cancel = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonPressed:)];
+ self.navigationItem.leftBarButtonItem = cancel;
+ [cancel release];
+
+ } else if ([textField isEqual:_confirmPasscodeTextField]) {
+ headerLabel.text = @"Re-enter your passcode";
+ }
+ } else if (mode == KKPasscodeModeDisabled) {
+ self.navigationItem.title = @"Turn off Passcode";
+ UIBarButtonItem *cancel = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonPressed:)];
+ self.navigationItem.leftBarButtonItem = cancel;
+ [cancel release];
+
+ headerLabel.text = @"Enter your passcode";
+ } else if (mode == KKPasscodeModeChange) {
+ self.navigationItem.title = @"Change Passcode";
+ UIBarButtonItem *cancel = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonPressed:)];
+ self.navigationItem.leftBarButtonItem = cancel;
+ [cancel release];
+
+ if ([textField isEqual:_enterPasscodeTextField]) {
+ headerLabel.text = @"Enter your old passcode";
+ } else if ([textField isEqual:_setPasscodeTextField]) {
+ headerLabel.text = @"Enter your new passcode";
+ } else {
+ headerLabel.text = @"Re-enter your new passcode";
+ }
+ } else {
+ self.navigationItem.title = @"Enter Passcode";
+ headerLabel.text = @"Enter your passcode";
+ }
+ headerLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin;
+
+ [headerView addSubview:headerLabel];
+ [headerLabel release];
+
+ return headerView;
}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
- (NSArray*)squares
{
- NSMutableArray *squareViews = [[NSMutableArray alloc] initWithCapacity:4];
- NSInteger squareX = 23.0;
- if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
- squareX = 133.0;
- }
-
- for (int i = 0; i < 4; i++) {
- UIImageView *square = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"passcode_square_empty.png"]];
- square.frame = CGRectMake(squareX, 74.0, 61.0, 53.0);
- [squareViews addObject:square];
- [square release];
- squareX += 71.0;
- }
- return [[NSArray alloc] initWithArray:squareViews];
+ NSMutableArray *squareViews = [NSMutableArray array];
+
+ CGFloat squareX = 0.0;
+
+ for (int i = 0; i < 4; i++) {
+ UIImageView *square = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"passcode_square_empty.png"]];
+ square.frame = CGRectMake(squareX, 74.0, 61.0, 53.0);
+ [squareViews addObject:square];
+ [square release];
+ squareX += 71.0;
+ }
+ return [NSArray arrayWithArray:squareViews];
}
-
-
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark Table view data source
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
- return 0;
+ return 0;
}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
- return 1;
+ return 1;
}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
-
- static NSString *CellIdentifier = @"Cell";
-
- UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
- if (cell == nil) {
- cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- }
-
- if ([aTableView isEqual:_enterPasscodeTableView]) {
- cell.accessoryView = _enterPasscodeTextField;
- } else if ([aTableView isEqual:_setPasscodeTableView]) {
- cell.accessoryView = _setPasscodeTextField;
- } else if ([aTableView isEqual:_confirmPasscodeTableView]) {
- cell.accessoryView = _confirmPasscodeTextField;
- }
-
- return cell;
+
+ static NSString *CellIdentifier = @"Cell";
+
+ UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
+ if (cell == nil) {
+ cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
+ cell.selectionStyle = UITableViewCellSelectionStyleNone;
+ }
+
+ if ([aTableView isEqual:_enterPasscodeTableView]) {
+ cell.accessoryView = _enterPasscodeTextField;
+ } else if ([aTableView isEqual:_setPasscodeTableView]) {
+ cell.accessoryView = _setPasscodeTextField;
+ } else if ([aTableView isEqual:_confirmPasscodeTableView]) {
+ cell.accessoryView = _confirmPasscodeTextField;
+ }
+
+ return cell;
}
-///////////////////////////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark UITextFieldDelegate
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
- if ([textField isEqual:[_textFields lastObject]]) {
- [self doneButtonPressed];
- } else {
- [self nextDigitPressed];
- }
- return NO;
+ if ([textField isEqual:[_textFields lastObject]]) {
+ [self doneButtonPressed];
+ } else {
+ [self nextDigitPressed];
+ }
+ return NO;