Skip to content

Commit

Permalink
General code cleanup.
Browse files Browse the repository at this point in the history
Restored original coding style (documentation, curly brackets, pointers...).
Cleaned up the demo project (removed offset and delay code for now).
  • Loading branch information
matej committed Jan 4, 2010
1 parent d55891f commit 1773289
Show file tree
Hide file tree
Showing 7 changed files with 442 additions and 567 deletions.
11 changes: 1 addition & 10 deletions Demo/Classes/HudDemoViewController.h
Expand Up @@ -9,17 +9,8 @@
#import <UIKit/UIKit.h>
#import "MBProgressHUD.h"

@interface HudDemoViewController : UIViewController <MBProgressHUDDelegate>
{
@interface HudDemoViewController : UIViewController <MBProgressHUDDelegate> {
MBProgressHUD *HUD;

IBOutlet UITextField* xOffsetField;
IBOutlet UITextField* yOffsetField;
IBOutlet UITextField* delayField;

float xOffset;
float yOffset;
NSUInteger delay;
}

- (IBAction)showSimple:(id)sender;
Expand Down
128 changes: 40 additions & 88 deletions Demo/Classes/HudDemoViewController.m
@@ -1,56 +1,42 @@
// HudDemoViewController.m
// HudDemo
//
// Created by Matej Bukovinski on 30.9.09.
// Copyright bukovinski.com 2009. All rights reserved.
// HudDemoViewController.m
// HudDemo
//
// Created by Matej Bukovinski on 30.9.09.
// Copyright bukovinski.com 2009. All rights reserved.
//

#import "HudDemoViewController.h"

@implementation HudDemoViewController

- (BOOL)textFieldShouldReturn:(UITextField*)textField
{
[textField resignFirstResponder];
return YES;
}
#pragma mark -
#pragma mark Lifecycle methods

- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
{
for (UIView* view in self.view.subviews)
{
if ([view isKindOfClass:[UITextField class]])
{
[view resignFirstResponder];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}

- (BOOL)textFieldDidEndEditing:(UITextField*)textField
{
if (textField == xOffsetField)
{
xOffset = [textField.text floatValue];
}
else if (textField == yOffsetField)
{
yOffset = [textField.text floatValue];
}
else if (textField == delayField)
{
delay = [textField.text intValue];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// No autoroation support for the HUD since we aren't using a ViewController but rather adding
// the HUD view as a direct subview of the window.
// You need to explicitly transform the HUD if you need a rotated version (i.g.,
// self.transform = CGAffineTransformMakeRotation(PI / 2); )
return NO;
}

return YES;
- (void)dealloc {
[super dealloc];
}

- (IBAction)showSimple:(id)sender
{
#pragma mark -
#pragma mark IBActions

- (IBAction)showSimple:(id)sender {
// Should be initialized with the windows frame so the HUD disables all user input by covering the entire screen
UIWindow *window = [UIApplication sharedApplication].keyWindow;
HUD = [[MBProgressHUD alloc] initWithWindow:window];
HUD.xOffset = xOffset;
HUD.yOffset = yOffset;
HUD.delay = delay;

// Add HUD to screen
[window addSubview:HUD];
Expand All @@ -62,14 +48,10 @@ - (IBAction)showSimple:(id)sender
[HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES];
}

- (IBAction)showWithLabel:(id)sender
{
- (IBAction)showWithLabel:(id)sender {
// Should be initialized with the windows frame so the HUD disables all user input by covering the entire screen
UIWindow *window = [UIApplication sharedApplication].keyWindow;
HUD = [[MBProgressHUD alloc] initWithWindow:window];
HUD.xOffset = xOffset;
HUD.yOffset = yOffset;
HUD.delay = delay;

// Add HUD to screen
[window addSubview:HUD];
Expand All @@ -83,15 +65,11 @@ - (IBAction)showWithLabel:(id)sender
[HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES];
}

- (IBAction)showWithDetailsLabel:(id)sender
{
- (IBAction)showWithDetailsLabel:(id)sender {

// Should be initialized with the windows frame so the HUD disables all user input by covering the entire screen
UIWindow *window = [UIApplication sharedApplication].keyWindow;
HUD = [[MBProgressHUD alloc] initWithWindow:window];
HUD.xOffset = xOffset;
HUD.yOffset = yOffset;
HUD.delay = delay;

// Add HUD to screen
[window addSubview:HUD];
Expand All @@ -106,15 +84,11 @@ - (IBAction)showWithDetailsLabel:(id)sender
[HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES];
}

- (IBAction)showWithLabelDeterminate:(id)sender
{
- (IBAction)showWithLabelDeterminate:(id)sender {

// Should be initialized with the windows frame so the HUD disables all user input by covering the entire screen
UIWindow *window = [UIApplication sharedApplication].keyWindow;
HUD = [[MBProgressHUD alloc] initWithWindow:window];
HUD.xOffset = xOffset;
HUD.yOffset = yOffset;
HUD.delay = delay;

// Set determinate mode
HUD.mode = MBProgressHUDModeDeterminate;
Expand All @@ -131,15 +105,11 @@ - (IBAction)showWithLabelDeterminate:(id)sender
[HUD showWhileExecuting:@selector(myProgressTask) onTarget:self withObject:nil animated:YES];
}

- (IBAction)showWithLabelMixed:(id)sender
{
- (IBAction)showWithLabelMixed:(id)sender {

// Should be initialized with the windows frame so the HUD disables all user input by covering the entire screen
UIWindow *window = [UIApplication sharedApplication].keyWindow;
HUD = [[MBProgressHUD alloc] initWithWindow:[UIApplication sharedApplication].keyWindow];
HUD.xOffset = xOffset;
HUD.yOffset = yOffset;
HUD.delay = delay;

// Add HUD to screen
[window addSubview:HUD];
Expand All @@ -153,29 +123,28 @@ - (IBAction)showWithLabelMixed:(id)sender
[HUD showWhileExecuting:@selector(myMixedTask) onTarget:self withObject:nil animated:YES];
}

- (void)myTask
{
#pragma mark -
#pragma mark Execution code

- (void)myTask {
// Do something usefull in here instead of sleeping ...
sleep(1 + (delay / 1000));
sleep(1);
// Labels can be changed during the execution
//HUD.detailsLabelText = @"Something";
//sleep(3);
}

- (void)myProgressTask
{
- (void)myProgressTask {
// This just increases the progress indicator in a loop
float progress = 0.0f;
while (progress < 1.0f)
{
while (progress < 1.0f) {
progress += 0.01f;
HUD.progress = progress;
usleep(50000);
}
}

- (void)myMixedTask
{
- (void)myMixedTask {
// Indeterminate mode
sleep(2);
// Switch to determinate mode
Expand All @@ -194,30 +163,13 @@ - (void)myMixedTask
sleep(2);
}

- (void)hudWasHidden
{
#pragma mark -
#pragma mark MBProgressHUDDelegate methods

- (void)hudWasHidden {
// Remove HUD from screen when the HUD was hidded
[HUD removeFromSuperview];
[HUD release];
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// No autoroation support for the HUD since we aren't using a ViewController but rather adding
// the HUD view as a direct subview of the window.
// You need to explicitly transform the HUD if you need a rotated version (i.g.,
// self.transform = CGAffineTransformMakeRotation(PI / 2); )
return NO;
}

- (void)dealloc
{
[super dealloc];
}
@end

0 comments on commit 1773289

Please sign in to comment.