+ return allowRotation; /* Deprecated in iOS 6 */
+}
+
+- (BOOL)shouldAutorotate /* Added in iOS 6 */
+{
+ return allowRotation;
+}
+
+- (NSUInteger)supportedInterfaceOrientations /* Added in iOS 6 */
+{
+ return UIInterfaceOrientationMaskAll;
+}
+
+@end
+
+
+@implementation SaverViewController
+
+@synthesize saverName;
+
+- (id)initWithSaverRunner:(SaverRunner *)parent
+{
+ self = [super init];
+ if (self) {
+ _parent = parent;
+ _storedOrientation = UIInterfaceOrientationUnknown;
+
+ self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
+ self.wantsFullScreenLayout = YES;
+ }
+ return self;
+}
+
+
+- (void)dealloc
+{
+ [_saverName release];
+ [_saverView dealloc];
+ [super dealloc];
+}
+
+
+- (void)loadView
+{
+ // The UIViewController's view must never change, so it gets set here to
+ // a plain black background.
+
+ // This background view doesn't block the status bar, but that's probably
+ // OK, because it's never on screen for more than a fraction of a second.
+ UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectNull];
+ backgroundView.backgroundColor = [UIColor blackColor];
+ self.view = backgroundView;
+}
+
+
+- (void)createSaverView
+{
+ UIView *parentView = self.view;
+
+ if (_saverView) {
+ [_saverView removeFromSuperview];
+ [_saverView release];
+ }
+
+ if (_storedOrientation != UIInterfaceOrientationUnknown) {
+ [[UIApplication sharedApplication]
+ setStatusBarOrientation:_storedOrientation
+ animated:NO];
+ }
+
+ _saverView = [_parent makeSaverView:_saverName
+ withSize:parentView.bounds.size];
+
+ if (! _saverView) {
+ [[[UIAlertView alloc] initWithTitle: _saverName
+ message: @"Unable to load!"
+ delegate: nil
+ cancelButtonTitle: @"Bummer"
+ otherButtonTitles: nil]
+ show];
+ return;
+ }
+
+ _saverView.delegate = _parent;
+
+ [self.view addSubview:_saverView];
+
+ // The first responder must be set only after the view was placed in the view
+ // heirarchy.
+ [_saverView becomeFirstResponder]; // For shakes on iOS 6.
+ [_saverView startAnimation];
+ [_parent aboutPanel:_saverView orientation:_storedOrientation];
+}
+
+
+- (void)viewDidAppear:(BOOL)animated
+{
+ [self createSaverView];
+}
+
+
+- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)o
+{
+ return NO; /* Deprecated in iOS 6 */
+}
+
+
+- (BOOL)shouldAutorotate /* Added in iOS 6 */
+{
+ return NO;
+}
+
+
+- (NSUInteger)supportedInterfaceOrientations /* Added in iOS 6 */
+{
+ // Lies from the iOS docs:
+ // "This method is only called if the view controller's shouldAutorotate
+ // method returns YES."
+ return UIInterfaceOrientationMaskPortrait;
+}
+
+
+- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
+{
+ return UIInterfaceOrientationPortrait;
+}
+
+
+- (void)setSaverName:(NSString *)name
+{
+ [name retain];
+ [_saverName release];
+ _saverName = name;
+ _storedOrientation = [UIApplication sharedApplication].statusBarOrientation;
+
+ if (_saverView)
+ [self createSaverView];