Expanded open file functionality to use available apps.
[pithos-ios] / Classes / LBAlgorithmAnimationViewController.m
1 //
2 //  LBAlgorithmAnimationViewController.m
3 //  OpenStack
4 //
5 //  Created by Mike Mayo on 6/2/11.
6 //  Copyright 2011 __MyCompanyName__. All rights reserved.
7 //
8
9 #import "LBAlgorithmAnimationViewController.h"
10
11
12 @implementation LBAlgorithmAnimationViewController
13
14 @synthesize algorithm, imageView, navigationBar;
15
16 - (id)initWithAlgorithm:(NSString *)a {
17     self = [super initWithNibName:@"LBAlgorithmAnimationViewController" bundle:nil];
18     if (self) {
19         self.algorithm = a;
20     }
21     return self;
22 }
23
24 - (void)dealloc {
25     [algorithm release];
26     [imageView release];
27     [navigationBar release];
28     [super dealloc];
29 }
30
31 #pragma mark - View lifecycle
32
33 - (void)loadAnimation {
34     NSInteger imageCount = 0;
35     NSString *abbreviation = @"";
36     
37     if ([algorithm isEqualToString:@"Round Robin"]) {
38         imageCount = 17;
39         abbreviation = @"rr";
40     } else if ([algorithm isEqualToString:@"Weighted Round Robin"]) {
41         imageCount = 24;
42         abbreviation = @"wrr";
43     } else if ([algorithm isEqualToString:@"Weighted Least Connections"]) {
44         imageCount = 21;
45         abbreviation = @"wlc";
46     } else if ([algorithm isEqualToString:@"Random"]) {
47         imageCount = 17;
48         abbreviation = @"random";
49     } else if ([algorithm isEqualToString:@"Least Connections"]) {
50         imageCount = 14;
51         abbreviation = @"lc";
52     }
53     
54     NSMutableArray *images = [[NSMutableArray alloc] initWithCapacity:imageCount];
55     for (int i = 1; i < imageCount + 1; i++) {
56         NSString *filename = [NSString stringWithFormat:@"%@-%02d_s%02d.png", abbreviation, i, i];
57         [images addObject:[UIImage imageNamed:filename]];
58     }
59     self.imageView.animationImages = [NSArray arrayWithArray:images];
60     self.imageView.animationRepeatCount = 0;
61     self.imageView.animationDuration = imageCount * .4;
62     [self.imageView startAnimating];
63     
64     [images release];
65 }
66
67 - (void)viewDidLoad {
68     [super viewDidLoad];    
69     self.navigationBar.topItem.title = self.algorithm;
70     [self loadAnimation];
71 }
72
73 - (void)viewDidUnload {
74     [super viewDidUnload];
75     self.imageView = nil;
76     self.navigationBar = nil;
77 }
78
79 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
80     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
81         return YES;
82     } else {
83         return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
84     }
85 }
86
87 #pragma mark - Button Handlers
88
89 - (IBAction)doneButtonPressed:(id)sender {
90     [self dismissModalViewControllerAnimated:YES];
91 }
92
93 @end