[Source Code]DoubleTap.app

Discussion in 'iOS Development' started by SkylarEC, Jun 24, 2008.

  1. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    iPhoneDefs.h
    Code:
    /*
     *  iPhoneDefs.h
     *  UITransition
     *
     *  Created by Hardy Macia on 9/21/2007.
     *  Copyright 2007 Catamount Software. All rights reserved.
     *  Ammended by Skylar Cantu 2007 - 2008.  No rights reserved whatsoever.
     *
     */
    
    #define UI_TOP_NAVIGATION_BAR_HEIGHT  48.0f
    #define UI_BOTTOM_NAVIGATION_BAR_HEIGHT 40.0f
    
    // UIButtonBar
    enum UIButtonBarStyle {barstyleBlue = 0, barstyleBlack = 1, barstylTransparent=2};
    
    enum kSwipeDirection {kSwipeDirectionUp=1, kSwipeDirectionDown=2, kSwipeDirectionRight=4, kSwipeDirectionLeft=8};
    
    typedef enum { 
    	kUIControlEventMouseDown = 1 << 0,
     	kUIControlEventMouseMovedInside = 1 << 2,
    	kUIControlEventMouseMovedOutside = 1 << 3,
    	kUIControlEventMouseUpInside = 1 << 6,
    	kUIControlEventMouseUpOutside = 1 << 7,
    	kUIControlAllEvents = (kUIControlEventMouseDown | kUIControlEventMouseMovedInside | kUIControlEventMouseMovedOutside | kUIControlEventMouseUpInside | kUIControlEventMouseUpOutside)
    } UIControlEventMasks;
    
  2. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    main.m
    Code:
    #import <UIKit/UIKit.h>
    
    #import "DTApp.h"
    
    
    
    int main(int argc, char **argv) {
    	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    	int ret = UIApplicationMain(argc, argv, [DTApp class]);
    	[pool release];
    	return ret;
    }
  3. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    DTApp.h
    Code:
    #import <CoreFoundation/CoreFoundation.h>
    #import <Foundation/Foundation.h>
    #import <UIKit/UIKit.h>
    #import <UIKit/UIApplication.h>
    #import <UIKit/UITransitionView.h>
    #import <UIKit/UIView.h>
    
    #import "DTMenuView.h"
    #import "DTAppList.h"
    #import "DTPreviewGrid.h"
    
    
    #import "iPhoneDefs.h"
    
    
    @interface MainView : UIView
    {
    
    }
    
    -(id)initWithApplication:(UIApplication*)app withAppID:(NSString*)appID withFrame:(struct CGRect)rect;
    
    @end
    
    
    
    @interface DTApp : UIApplication 
    {
    	NSString				*applicationID;
    	NSUserDefaults			*userDefaults;
    
    	bool					respring;
    
    	UINavigationBar			*topBar;
    	UINavigationItem		*navTitle;
    	MainView				*mainView;
    	UITransitionView		*transView;
    	DTMenuView				*menuView;
    	DTAppList				*appList;
    	DTPreviewGrid			*previewGrid;
    
    }
    
    -(id)showView:(UIView*)view event:(int)eventNum;
    -(void)transitionToView:(int)view;
    -(void)updateStatusBar:(int)style;
    -(void)addAppToPlist;
    -(void)copyPrefs;
    -(void)applyDT;
    -(void)unapplyDT;
    
    -(void)applicationSuspend:(struct __GSEvent *)event;
    -(void)applicationWillTerminate;
    
    
    
    @end
  4. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    DTApp.m
    Code:
    #import "DTApp.h"
    
    
    @implementation MainView
    -(id)initWithApplication:(UIApplication*)app withAppID:(NSString*)appID withFrame:(struct CGRect)rect{
    
    	if ((self == [ super initWithFrame: rect ]) != nil) {
    	CGRect viewRect;
    		
    	float black[4] = {0.0f, 0.0f, 0.0f, 0.5f};
    
    	UITextLabel *background = [[UITextLabel alloc] initWithFrame:rect];
    	[background setBackgroundColor: CGColorCreate(CGColorSpaceCreateDeviceRGB(), black)];
    	
    	
    	[self addSubview:background];
    	
    	}
    	
    	return self;
    }
    
    
    @end
    
    
    
    @implementation DTApp
    	
    -(void)applicationDidFinishLaunching:(id)unused{
    
    	applicationID = @"com.skylarcantu.dtapp";
    	
    	respring = FALSE;
    	
    	struct CGRect mainRect = [UIHardware fullScreenApplicationContentRect];
    	
    	userDefaults = [NSUserDefaults standardUserDefaults];
    	[userDefaults setFloat:0.0f forKey:@"AppsSelected"];
    	
    	mainRect.origin.x = mainRect.origin.y = 0;
    
    	UIWindow *window = [[UIWindow alloc] initWithContentRect:mainRect];
    	[window orderFront: self];
    	[window makeKey: self];
    	[window _setHidden: false];
    	
    	navTitle = [[UINavigationItem alloc ]initWithTitle:@"DoubleTap"];	
    	topBar = [[UINavigationBar alloc] init];
    	[topBar setFrame:CGRectMake(mainRect.origin.x, mainRect.origin.y, mainRect.size.width,UI_TOP_NAVIGATION_BAR_HEIGHT)];
     	[topBar pushNavigationItem:navTitle];
     	[topBar enableAnimation];
    	[topBar setDelegate:self];
    
    	mainView = [[MainView alloc] initWithApplication:self withAppID:applicationID withFrame:mainRect];
    	transView = [[UITransitionView alloc] initWithFrame:CGRectMake(mainRect.origin.x, UI_TOP_NAVIGATION_BAR_HEIGHT, mainRect.size.width, mainRect.size.height - UI_TOP_NAVIGATION_BAR_HEIGHT)];
    	menuView = [[DTMenuView alloc] initWithApplication:self withAppID:applicationID withFrame:CGRectMake(mainRect.origin.x, mainRect.origin.y, mainRect.size.width, mainRect.size.height - UI_TOP_NAVIGATION_BAR_HEIGHT)];
    	appList = [[DTAppList alloc] initWithApplication:self withAppID:applicationID withFrame:CGRectMake(mainRect.origin.x, mainRect.origin.y, mainRect.size.width, mainRect.size.height - UI_TOP_NAVIGATION_BAR_HEIGHT)];
        [appList setPath:@"/Applications"];
        [appList setExtension:@".app"];
        [appList reloadData];
        previewGrid = [[DTPreviewGrid alloc] initWithApplication:self withAppID:applicationID withFrame:CGRectMake(mainRect.origin.x, mainRect.origin.y, mainRect.size.width, mainRect.size.height - UI_TOP_NAVIGATION_BAR_HEIGHT)];
        
        [mainView addSubview:transView];
        [mainView addSubview:topBar];
    	[window setContentView:mainView];
    	[self transitionToView:0];
    		
    }
    
    -(void)navigationBar:(UINavigationBar*)bar buttonClicked:(int)button
    {
    	if (button == 1) {
    		[self transitionToView:1];
    	}	
    	if (button == 0){
    		int i = [userDefaults floatForKey:@"AppsSelected"];
    		i += 1;
    		[userDefaults setFloat:i forKey:@"AppsSelected"];
    		
    		[self addAppToPlist];
    		[self updateStatusBar:2];
    		
    	}
    }
    
    -(id)showView:(UIView*)view event:(int)eventNum{
    	[transView transition:eventNum toView:view];
    	return self;
    }
    
    -(void)transitionToView:(int)view{
    	
    	int i = [userDefaults floatForKey:@"AppsSelected"];
    	
    	switch(view){
    		case 0:
    			[self updateStatusBar:0];
    			[transView transition:6 toView:menuView];
    			break;
    		case 1:
    			[self updateStatusBar:0];
    			[transView transition:2 toView:menuView];
    			break;
    		case 2:
    			if (i < 9){
    				[self updateStatusBar:1];
    				[transView transition:1 toView:appList];
    				break;
    			}
    			else{
    				[self updateStatusBar:3];
    				[transView transition:1 toView:previewGrid];
    				break;
    			}
    			break;
    		case 3:
    			[self updateStatusBar:3];
    			[previewGrid setGrid];
    			[transView transition:6 toView:previewGrid];
    			break;
    		case 4:
    			[self updateStatusBar:1];
    			[transView transition:6 toView:appList];
    			break;
    	}
    }
    
    -(void)updateStatusBar:(int)style{
    
    	int i = [userDefaults floatForKey:@"AppsSelected"];
    	
    	switch(style){
    		case 0:
    			[navTitle setTitle: @"DoubleTap"];
     			[topBar showLeftButton:nil withStyle:2 rightButton:nil withStyle:0];
    			break;
    		case 1:
    			[navTitle setTitle: @"Select"];
     			[topBar showLeftButton:@"Back" withStyle:2 rightButton:nil withStyle:0];
    			break;
    		case 2:
    			[navTitle setTitle: @"Select"];
    			if (i == 0)
    				[topBar showLeftButton:@"Back" withStyle:2 rightButton:@"Add To Grid" withStyle:0];
    			else if (i <= 9){
     				[topBar showLeftButton:@"Back" withStyle:2 rightButton:[[NSString alloc] initWithFormat:@"Add to grid (%i)", i] withStyle:0];
    				if (i == 9){				
    					[navTitle setTitle: @"Grid Preview"];
    	 				[topBar showLeftButton:nil withStyle:2 rightButton:nil withStyle:0];
    	 			}
    			}
    			else 
    				style = 3;
    			break;
    		case 3:
    			[navTitle setTitle: @"Grid Preview"];
     			[topBar showLeftButton:nil withStyle:2 rightButton:nil withStyle:0];
    			break;
    			
    	}
    }
    
    -(void)addAppToPlist{
    	
    	NSString *file = [userDefaults stringForKey:@"tempFile"];	
    	NSString *fullAppPath = [[NSString alloc] initWithFormat:@"/Applications/%@/icon.png", file];
    	NSString *infoPlistPath = [[NSString alloc] initWithFormat:@"/Applications/%@/Info.plist", file];
    	int i = [userDefaults floatForKey:@"AppsSelected"];
    	
    	
    	NSMutableDictionary *infoPlist = [[NSMutableDictionary alloc] initWithContentsOfFile:infoPlistPath];
    	NSString *bundleIdentifier = [infoPlist objectForKey:@"CFBundleIdentifier"];
    		
    	[userDefaults setObject:fullAppPath forKey:[[NSString alloc] initWithFormat:@"AppIcon%i", i]];
    	[userDefaults setObject:bundleIdentifier forKey:[[NSString alloc] initWithFormat:@"AppIdentifier%i", i]];
    	
    		
    	if (i == 9)
    		[self transitionToView:3];	
    		
    }
    
    -(void)copyPrefs{
    
    	NSString *settingsPlist = [[NSString alloc] initWithString:@"~/Library/Preferences/com.skylarcantu.dtapp.plist"];
    	NSString *expandedSettingsPlist = [[NSString alloc] initWithString:[settingsPlist stringByExpandingTildeInPath]];
    	NSString *altSettingsPlist = [[NSString alloc] initWithString:@"~/Library/Preferences/com.skylarcantu.doubletap.plist"];
    	NSString *expandedAltSettingsPlist = [[NSString alloc] initWithString:[altSettingsPlist stringByExpandingTildeInPath]];
    	
    	NSString *removeCommand = [[NSString alloc] initWithFormat:@"/bin/rm -f %@", expandedAltSettingsPlist];	
    	NSString *copyCommand = [[NSString alloc] initWithFormat:@"/bin/cp %@ %@",expandedSettingsPlist,expandedAltSettingsPlist];	
    
    	system([removeCommand UTF8String]);
    	system([copyCommand UTF8String]);
    
    }
    
    -(void)applyDT{
    	
    	[userDefaults setBool:TRUE forKey:@"AppIsOn"];
    	
    	NSString *springboardPlist = [[NSString alloc] initWithString:@"~/Library/Preferences/com.apple.springboard.plist"];
    	NSString *expandedSpringboardPlist = [[NSString alloc] initWithString:[springboardPlist stringByExpandingTildeInPath]];
    	
    	NSString *chmodString = [[NSString alloc] initWithFormat:@"/bin/chmod 666 %@", expandedSpringboardPlist];
    	system([chmodString UTF8String]);	
    	
    	NSDictionary *springboardDict = [[NSMutableDictionary alloc] initWithContentsOfFile:expandedSpringboardPlist];
    	NSString *doubletapURL = [springboardDict objectForKey:@"SBDoubleTapURL"];	
    	
    	[userDefaults setObject:doubletapURL forKey:@"DefaultDoubletapURL"];
    	[springboardDict setObject:@"doubletap://com.skylarcantu.doubletap" forKey:@"SBDoubleTapURL"];
    	[springboardDict setObject:[[NSNumber alloc] initWithInt:0] forKey:@"SBEnableOverlayControls"];
    	[springboardDict writeToFile:expandedSpringboardPlist atomically:YES];
    	
    	respring = TRUE;
    
    }
    
    -(void)unapplyDT{
    	
    	[userDefaults setBool:FALSE forKey:@"AppIsOn"];
    
    	NSString *springboardPlist = [[NSString alloc] initWithString:@"~/Library/Preferences/com.apple.springboard.plist"];
    	NSString *expandedSpringboardPlist = [[NSString alloc] initWithString:[springboardPlist stringByExpandingTildeInPath]];
    	
    	NSString *chmodString = [[NSString alloc] initWithFormat:@"/bin/chmod 666 %@", expandedSpringboardPlist];
    	system([chmodString UTF8String]);
    	
    	NSDictionary *springboardDict = [[NSMutableDictionary alloc] initWithContentsOfFile:expandedSpringboardPlist];
    	[springboardDict setObject:[userDefaults objectForKey:@"DefaultDoubletapURL"] forKey:@"SBDoubleTapURL"];
    	[springboardDict setObject:[[NSNumber alloc] initWithInt:1] forKey:@"SBEnableOverlayControls"];
    	[springboardDict writeToFile:expandedSpringboardPlist atomically:YES];
    	
    	respring = TRUE;
    	
    }
    
    -(void)applicationSuspend:(struct __GSEvent *)event
    {
    	[self terminate];
    }
    
    -(void)applicationWillTerminate
    {
    	if (respring)
    		system("launchctl stop com.apple.SpringBoard");
    }
    
    
    @end
  5. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    DTMenuView.h
    Code:
    #import <Foundation/Foundation.h>
    #import <GraphicsServices/GraphicsServices.h>
    #import <UIKit/UIKit.h>
    #import <UIKit/UIApplication.h>
    #import <UIKit/UIView.h>
    #import <UIKit/UINavigationItem.h>
    #import <UIKit/UIPreferencesTable.h>
    #import <UIKit/UIPreferencesTableCell.h>
    #import <UIKit/UINavigationItem.h>
    #import <UIKit/UITextField.h>
    
    #import "iPhoneDefs.h"
    #import "DTAppList.h"
    
    
    @interface DTMenuView : UIPreferencesTable {
    
    	UIPreferencesTable			*prefTable;
    	UIPreferencesTableCell		*selectAppsButton;
    	UIPreferencesTableCell		*setAppsButton;
    	UIView						*preferencesTable;
    	UIApplication				*_app;
    	NSUserDefaults				*userDefaults;
    
    	UIPreferencesTableCell		*setButton;
    	UIPreferencesTableCell		*unsetButton;
    }
    
    -(id)init;
    -(id)initWithApplication:(UIApplication*)app withAppID:(NSString*)appID withFrame:(struct CGRect)rect;
    
    //Delegate Methods
    -(void)tableRowSelected:(NSNotification *)notification;
    
    //datasource methods
    -(int)numberOfGroupsInPreferencesTable:(UIPreferencesTable *)table;
    -(int)preferencesTable:(UIPreferencesTable *)table numberOfRowsInGroup:(int)group;
    -(UIPreferencesTableCell *)preferencesTable:(UIPreferencesTable *)table cellForGroup:(int)group;
    -(UIPreferencesTableCell *)preferencesTable:(UIPreferencesTable *)table cellForRow:(int)row inGroup:(int)group;
    
    
    @end
  6. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    DTMenuView.m
    Code:
    #import "DTMenuView.h"
    #import "DTApp.h"
    
    @implementation DTMenuView
    
    -(id)init{
    	struct CGRect rect = [UIHardware fullScreenApplicationContentRect];
        rect.origin.x = rect.origin.y = 0.0f;
    	return [self initWithFrame:rect];	
    }
    
    -(id)initWithApplication:(UIApplication*)app withAppID:(NSString*)appID withFrame:(struct CGRect)rect{
    	
    	self = [super initWithFrame: rect];
    	_app = app;
    	userDefaults = [NSUserDefaults standardUserDefaults];
    	
    	prefTable = [[UIPreferencesTable alloc] initWithFrame:CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)];
    	[prefTable setDataSource:self];
    	[prefTable setDelegate:self];
    	[prefTable reloadData];
    	
    	selectAppsButton = [[UIPreferencesTableCell alloc] init];
    	[selectAppsButton setTitle:@"Choose Apps"];
    	[selectAppsButton setAlignment:2];
    	[selectAppsButton setShowSelection:YES];
    	[selectAppsButton setSelectionStyle:2];
    	[selectAppsButton setShowDisclosure:YES];
    	[selectAppsButton setDisclosureStyle:0];
    	
    	setButton = [[UIPreferencesTableCell alloc] init];
    	[setButton setTitle:@"Turn On"];
    	[setButton setAlignment:2];
    	[setButton setShowSelection:YES];
    	[setButton setSelectionStyle:4];
    	[setButton setEnabled:FALSE];
    	
    	unsetButton = [[UIPreferencesTableCell alloc] init];
    	[unsetButton setTitle:@"Turn Off"];
    	[unsetButton setAlignment:2];
    	[unsetButton setShowSelection:YES];
    	[unsetButton setSelectionStyle:4];
    	[unsetButton setEnabled:FALSE];
    			
    	[self addSubview:prefTable];
    	
    	
    	if ([userDefaults boolForKey:@"AppIsOn"]){
    		[setButton setEnabled:FALSE];
    		[unsetButton setEnabled:TRUE];	
    	}
    	else{
    		[setButton setEnabled:TRUE];
    		[unsetButton setEnabled:FALSE];	
    	}
    		
    		
    	
    	
    	return self;
    }
    
    - (int)numberOfGroupsInPreferencesTable:(UIPreferencesTable *)table
    {
    	return 2;
    }
    
    - (int)preferencesTable:(UIPreferencesTable *)table numberOfRowsInGroup:(int)group
    {
    	switch (group){
    		case 0: 
    			return 1;
    		case 1:
    			return 2;
    	}
    }
    
    - (UIPreferencesTableCell *)preferencesTable:(UIPreferencesTable *)table cellForGroup:(int)group
    {
    	UIPreferencesTableCell *cell = [[UIPreferencesTableCell alloc] init];
    	
    	return [cell autorelease];
    }
    
    - (UIPreferencesTableCell *)preferencesTable:(UIPreferencesTable *)table cellForRow:(int)row inGroup:(int)group
    {
    	if (group == 0)	{
    		switch (row){
    			case 0:
    				return selectAppsButton;
    		}
    	}
    	if (group == 1)	{
    		switch (row){
    			case 0:
    				return setButton;
    			case 1:
    				return unsetButton;
    		}
    	}
    }
    
    -(float)preferencesTable:(UIPreferencesTable *)table heightForRow:(int)row inGroup:(int)group withProposedHeight:(float)proposed
    {
        if (row == -1) {
            if (group == 0)
                return 11;
            if (group == 1)
                return 256;
        }  
    
        return proposed;
    }
    
    
    -(void)tableRowSelected:(NSNotification *)notification
    {
    	switch([prefTable selectedRow]){
    		case 1:
    			[_app transitionToView:2];
    			[prefTable selectRow:-1 byExtendingSelection:NO];
    			break;
    		case 3:
    			[_app applyDT];
    			[prefTable selectRow:-1 byExtendingSelection:NO];
    			[setButton setEnabled:FALSE];
    			[unsetButton setEnabled:TRUE];
    			break;
    		case 4:
    			[_app unapplyDT];
    			[prefTable selectRow:-1 byExtendingSelection:NO];
    			[unsetButton setEnabled:FALSE];
    			[setButton setEnabled:TRUE];
    			break;		
    	}
    	
    	[prefTable reloadData];
    }
    
    @end
    
    
  7. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    DTAppList.h
    Code:
    #import <CoreFoundation/CoreFoundation.h>
    #import <Foundation/Foundation.h>
    #import <UIKit/UIKit.h>
    #import <UIKit/UISectionList.h>
    #import <UIKit/UISectionTable.h>
    #import <UIKit/UIImageAndTextTableCell.h>
    
    @interface DTAppList : UISectionList {
    	UIApplication			*_app;
    	UISectionTable			*table;
    	NSMutableArray			*files;
    	NSMutableArray			*filenames;
    	NSMutableArray			*sections;
    	NSMutableArray			*offsets;
    	NSString				*path;
    	NSString				*extension;
    	
    	NSUserDefaults			*userDefaults;
    
    }
    
    -(id)initWithApplication:(UIApplication*)app withAppID:(NSString*)appID withFrame:(struct CGRect)rect;
    - (void)reloadData;
    - (void)setPath:(NSString *)_path;
    - (void)setExtension:(NSString *)_extension;
    - (void)dealloc;
    - (int)numberOfSectionsInSectionList:(UISectionList *)aSectionList;
    - (NSString *)sectionList:(UISectionList *)aSectionList titleForSection:(int)section;
    - (int)sectionList:(UISectionList *)aSectionList rowForSection:(int)section;
    - (int) numberOfRowsInTable: (UITable *)table;
    - (UITableCell *)table:(UITable *)table cellForRow:(int)row column:(int)col;
    @end
    
  8. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    DTAppList.m
    Code:
    #import "DTAppList.h"
    #import "DTApp.h"
    #import "DTMenuView.h"
    
    @implementation DTAppList
    
    -(id)initWithApplication:(UIApplication*)app withAppID:(NSString*)appID withFrame:(struct CGRect)rect{
        if ((self == [super initWithFrame:rect showSectionIndex:NO]) != nil) {
    		
    		_app = app;
    		userDefaults = [NSUserDefaults standardUserDefaults];
    		
    		path = nil;
    		extension = nil;
    
            files =     [[NSMutableArray alloc] init];
            sections =  [[NSMutableArray alloc] init];
            offsets =   [[NSMutableArray alloc] init];
            filenames = [[NSMutableArray alloc] init];
    
            table = [self table];
            UITableColumn * column = [[UITableColumn alloc] initWithTitle:@"Filename" identifier:@"filename" width:rect.size.width];
            [table addTableColumn:column];
            [table setSeparatorStyle:2];
            [table setRowHeight:65.0];
            [table setDelegate:self];
    
           [self setShouldHideHeaderInShortLists:YES];
           [self setDataSource:self];
                  
        }
    	
        return self;
    }
    
    - (void)reloadData {
        NSString *file;
        NSDirectoryEnumerator *dirEnum;
        char cFileName[256], lastSection[2], mySection[2];
    
        if (path == nil || extension == nil) {
            return;
        }
    
        [files removeAllObjects];
        [sections removeAllObjects];
        [offsets removeAllObjects];
        [filenames removeAllObjects];
    
        dirEnum = [[NSFileManager defaultManager] enumeratorAtPath: path ];
        while ((file = [dirEnum nextObject ])) 
        {
    		if ([ file hasSuffix: extension ] == YES) {
    			UIImageAndTextTableCell *cell = [[UIImageAndTextTableCell alloc]init];
    			[cell setTitle:[file substringToIndex:[file length] - 4]];
    			[cell setImage:[UIImage imageAtPath:[[NSString alloc] initWithFormat:@"/Applications/%@/icon.png",file]]];
    			
    			strlcpy(cFileName, [file cStringUsingEncoding:NSASCIIStringEncoding], sizeof(cFileName));
    			mySection[0] = toupper(cFileName[0]);
    			mySection[1] = 0;
    			if (mySection[0] >= '0' && mySection[0] <= '9') {
    				mySection[0] = '0';
    			}
    
    			if ([sections count] > 0) {
    				NSString *lastSectionName = [sections objectAtIndex:[sections count] - 1];
    				strlcpy(lastSection, [lastSectionName cStringUsingEncoding:NSASCIIStringEncoding], sizeof(lastSection));
    
    				if (mySection[0] != lastSection[0]) {
    					[sections addObject:[[NSString alloc] initWithCString:mySection]];
    					[offsets addObject:[NSNumber numberWithInt:[files count] + 1]];
    				}
                
    			} 
    			else {
    				[sections addObject:[[NSString alloc] initWithCString:mySection]]; 
    				[offsets addObject:[NSNumber numberWithInt:[files count] + 1]];
    			}
            [files addObject: cell];
            [filenames addObject: file];
            }
        }
        [super reloadData];
    }
    
    -(void)setPath:(NSString *)_path {
        path = _path;
    }
    
    -(void)setExtension:(NSString *)_extension {
        extension = _extension;
    }
    
    -(void)dealloc
    {
        [self dealloc];
        [files dealloc];
        [filenames dealloc];
        [sections dealloc];
        [offsets dealloc];
        [super dealloc];
    }
    
    -(int)numberOfSectionsInSectionList:(UISectionList *)aSectionList {
            return [sections count];
    }
            
    -(NSString *)sectionList:(UISectionList *)aSectionList titleForSection:(int)section {
        return [sections objectAtIndex:section];
    }       
            
    -(int)sectionList:(UISectionList *)aSectionList rowForSection:(int)section {
            return ([[offsets objectAtIndex:section] intValue] - 1);
    }
     
    -(int)numberOfRowsInTable: (UITable *)table{
        return [files count];
    }
    
    -(UITableCell *)table:(UITable *)table cellForRow:(int)row column:(int)col {
        return [files objectAtIndex:row];
    }
    
    -(UITableCell *)table: (UITable *)table cellForRow:(int)row column:(int)col reusing:(BOOL) reusing {
        return [files objectAtIndex:row];
    }
    
    -(void)tableRowSelected:(NSNotification *)notification {
        NSString *file = [filenames objectAtIndex:[table selectedRow]];
        
        [userDefaults setObject:file forKey:@"tempFile"];
        [_app updateStatusBar:2];
    }
    
    @end
    
  9. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    DTPreviewGrid.h
    Code:
    #import <CoreFoundation/CoreFoundation.h>
    #import <Foundation/Foundation.h>
    #import <UIKit/UIImageView.h>
    #import <UIKit/UIKit.h>
    #import <UIKit/UINavigationBar.h>
    #import <UIKit/UIView.h>
    
    
    #import "iPhoneDefs.h"
    
    
    
    @interface DTPreviewGrid : UIView
    {
    	UIApplication			*_app;
    	UINavigationBar			*bottomBar;
    
    	NSUserDefaults			*userDefaults;
    	struct CGRect			viewRect;
    
    	UIImageView				*image[10];
    
    	NSTimer					*transTimer;
    }
    
    -(id)initWithApplication:(UIApplication*)app withAppID:(NSString*)appID withFrame:(struct CGRect)rect;
    
    -(void)setGrid;
    
    @end
  10. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    DTPreviewGrid.m
    Code:
    #import "DTPreviewGrid.h"
    
    @implementation DTPreviewGrid
    -(id)initWithApplication:(UIApplication*)app withAppID:(NSString*)appID withFrame:(struct CGRect)rect{
    	if ((self == [ super initWithFrame: rect ]) != nil) {
    	
    	_app = app;
    	userDefaults = [NSUserDefaults standardUserDefaults];
    	
    	struct CGRect viewRect = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height -  UI_BOTTOM_NAVIGATION_BAR_HEIGHT) ;
    		
    	float black[4] = {0.2f, 0.2f, 0.2f, 0.80f};
    	
    	UITextLabel *background = [[UITextLabel alloc] initWithFrame:rect];
    	[background setBackgroundColor: CGColorCreate(CGColorSpaceCreateDeviceRGB(), black)];
    	
    	bottomBar = [[UINavigationBar alloc] init];
    	[bottomBar setFrame:CGRectMake(rect.origin.x, rect.size.height - UI_BOTTOM_NAVIGATION_BAR_HEIGHT, rect.size.width,UI_BOTTOM_NAVIGATION_BAR_HEIGHT)];
    	[bottomBar showLeftButton:@"Reset" withStyle:0 rightButton:@"Save" withStyle:0];
    	[bottomBar enableAnimation];
    	[bottomBar setDelegate:self];	
    	
    	[self addSubview:background];
    	[self addSubview:bottomBar];
    	
    	}
    	
    	return self;
    }
    
    -(void)setGrid{
    	CGRect _rect = viewRect;
    	
    	int i = 0;
    
    	CGRect box[9];	
    	
    	//TODO: Set up a for loop for this:
    	box[1].size.height = box[2].size.height = box[3].size.height = box[4].size.height = box[5].size.height = box[6].size.height = box[7].size.height = box[8].size.height = box[9].size.height = _rect.size.height / 3;
    	box[1].size.width = box[2].size.width = box[3].size.width = box[4].size.width = box[5].size.width = box[6].size.height = box[7].size.width = box[8].size.width = box[9].size.width = _rect.size.width / 3;
    	
    
    	
    
    	for(i = 1; i <= 9; i++) {
    		
    		NSString *iconPath = [userDefaults objectForKey:[[NSString alloc] initWithFormat:@"AppIcon%i", i]];
    		UIImage *tempImage = [UIImage imageAtPath:iconPath];
    		
    		image[i] = [[UIImageView alloc] initWithFrame:box[i]];
    		[image[i] setImage:tempImage];
    		
    		switch(i){
    			case 1:
    				[image[i] setOrigin: CGPointMake(51,68)];
    				break;
    			case 2:
    				[image[i] setOrigin: CGPointMake(131,68)];
    				break;
    			case 3:
    				[image[i] setOrigin: CGPointMake(211,68)];
    				break;
    			case 4:
    				[image[i] setOrigin: CGPointMake(51,148)];
    				break;
    			case 5:
    				[image[i] setOrigin: CGPointMake(131,148)];
    				break;
    			case 6:
    				[image[i] setOrigin: CGPointMake(211,148)];
    				break;
    			case 7:
    				[image[i] setOrigin: CGPointMake(51,228)];
    				break;
    			case 8:
    				[image[i] setOrigin: CGPointMake(131,228)];
    				break;
    			case 9:
    				[image[i] setOrigin: CGPointMake(211,228)];
    				break;
    		}
    		
    		
    		[self addSubview:image[i]];
    			
    	}
    
    }
    
    
    -(void)navigationBar:(UINavigationBar*)bar buttonClicked:(int)button{
    	int i;
    	for(i = 1; i <= 9; i++){
    		[image[i] removeFromSuperview];	
    	}
    
    	if (button == 0){
    		
    		[_app copyPrefs];
    		
    		[userDefaults setFloat:0.0f forKey:@"AppsSelected"];		
    		
    		[_app transitionToView:4];
    		NSTimer *transTimer = [NSTimer scheduledTimerWithTimeInterval:.66 target:self selector:@selector(performSecondTransition:) userInfo:nil repeats:NO];	
    	}
    	
    	if (button == 1){		
    		int i;		
    		
    		for(i = 0; i <= 9; i++){
    			[userDefaults removeObjectForKey:[[NSString alloc] initWithFormat:@"AppIcon%i", i]];
    			[userDefaults removeObjectForKey:[[NSString alloc] initWithFormat:@"AppIdentifier%i", i]];
    		}
    		[userDefaults setFloat:0.0f forKey:@"AppsSelected"];	
    		
    		[_app transitionToView:4];
    	}
    }
    
    -(void)performSecondTransition:(NSTimer *)timer{
    	[_app transitionToView:1];
    }
    
    
    @end

Share This Page