Skip to content

Commit

Permalink
Merge pull request #115 from red5pro/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Jessica Palmer authored Nov 28, 2017
2 parents 9c9f73e + a12bac9 commit c9cdf57
Show file tree
Hide file tree
Showing 57 changed files with 3,835 additions and 8 deletions.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions R5ProObjectiveCExamples/R5ProObjectiveCExamples/ALToastView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// ALToastView.h
//
// Created by Alex Leutgöb on 16.01.11.
// Copyright 2011 alexleutgoeb.com. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@interface ALToastView : UIView {
@private
UILabel *_textLabel;
}

+ (void)toastInView:(UIView *)parentView withText:(NSString *)text;

@end
172 changes: 172 additions & 0 deletions R5ProObjectiveCExamples/R5ProObjectiveCExamples/ALToastView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
//
// ALToastView.h
//
// Created by Alex Leutgöb on 17.07.11.
// Copyright 2011 alexleutgoeb.com. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

#import <QuartzCore/QuartzCore.h>
#import "ALToastView.h"


// Set visibility duration
static const CGFloat kDuration = 2;


// Static toastview queue variable
static NSMutableArray *toasts;


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


@interface ALToastView ()

@property (nonatomic, readonly) UILabel *textLabel;

- (void)fadeToastOut;
+ (void)nextToastInView:(UIView *)parentView;

@end


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


@implementation ALToastView

@synthesize textLabel = _textLabel;


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark - NSObject

- (id)initWithText:(NSString *)text {
if ((self = [self initWithFrame:CGRectZero])) {
// Add corner radius
self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:.6];
self.layer.cornerRadius = 5;
self.autoresizingMask = UIViewAutoresizingNone;
self.autoresizesSubviews = NO;

// Init and add label
_textLabel = [[UILabel alloc] init];
_textLabel.text = text;
_textLabel.font = [UIFont systemFontOfSize:14];
_textLabel.textColor = [UIColor whiteColor];
_textLabel.adjustsFontSizeToFitWidth = NO;
_textLabel.backgroundColor = [UIColor clearColor];
[_textLabel sizeToFit];

[self addSubview:_textLabel];
_textLabel.frame = CGRectOffset(_textLabel.frame, 10, 5);
}

return self;
}




////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark - Public

+ (void)toastInView:(UIView *)parentView withText:(NSString *)text {
// Add new instance to queue
ALToastView *view = [[ALToastView alloc] initWithText:text];

CGFloat lWidth = view.textLabel.frame.size.width;
CGFloat lHeight = view.textLabel.frame.size.height;
CGFloat pWidth = parentView.bounds.size.width;
CGFloat pHeight = parentView.bounds.size.height;

// Change toastview frame
view.frame = CGRectMake((pWidth - lWidth - 20) / 2., pHeight - lHeight - 60, lWidth + 20, lHeight + 10);
view.alpha = 0.0f;

if (toasts == nil) {
toasts = [[NSMutableArray alloc] initWithCapacity:1];
[toasts addObject:view];
[ALToastView nextToastInView:parentView];
}
else {
[toasts addObject:view];
}

}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark - Private

- (void)fadeToastOut {
// Fade in parent view
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionAllowUserInteraction

animations:^{
self.alpha = 0.f;
}
completion:^(BOOL finished){
UIView *parentView = self.superview;
[self removeFromSuperview];

// Remove current view from array
[toasts removeObject:self];
if ([toasts count] == 0) {

toasts = nil;
}
else
[ALToastView nextToastInView:parentView];
}];
}


+ (void)nextToastInView:(UIView *)parentView {
if ([toasts count] > 0) {
ALToastView *view = [toasts objectAtIndex:0];

// NSLog(@"Showing toast with text: %@", view.textLabel.text);

CGFloat lWidth = view.textLabel.frame.size.width;
CGFloat lHeight = view.textLabel.frame.size.height;
CGFloat pWidth = parentView.frame.size.width;
CGFloat pHeight = parentView.frame.size.height;

// Change toastview frame
view.frame = CGRectMake((pWidth - lWidth - 20) / 2., pHeight - lHeight - 60, lWidth + 20, lHeight + 10);

// Fade into parent view
[parentView addSubview:view];
[UIView animateWithDuration:.5 delay:0 options:UIViewAnimationOptionAllowUserInteraction
animations:^{
view.alpha = 1.0;
[parentView updateConstraints];
[parentView layoutIfNeeded];

} completion:^(BOOL finished){}];

// Start timer for fade out
[view performSelector:@selector(fadeToastOut) withObject:nil afterDelay:kDuration];
}
}

@end
17 changes: 17 additions & 0 deletions R5ProObjectiveCExamples/R5ProObjectiveCExamples/AppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// AppDelegate.h
// R5ProObjectiveCExamples
//
// Created by David Heimann on 6/5/17.
// Copyright © 2017 Infrared5. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;


@end

71 changes: 71 additions & 0 deletions R5ProObjectiveCExamples/R5ProObjectiveCExamples/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// AppDelegate.m
// R5ProObjectiveCExamples
//
// Created by David Heimann on 6/5/17.
// Copyright © 2017 Infrared5. All rights reserved.
//

#import "AppDelegate.h"
#import "DetailViewController.h"
#import "Testbed.h"

@interface AppDelegate () <UISplitViewControllerDelegate>

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.

[Testbed sharedInstance];

UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
navigationController.topViewController.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem;
splitViewController.delegate = self;
return YES;
}


- (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


#pragma mark - Split view

- (BOOL)splitViewController:(UISplitViewController *)splitViewController collapseSecondaryViewController:(UIViewController *)secondaryViewController ontoPrimaryViewController:(UIViewController *)primaryViewController {
if ([secondaryViewController isKindOfClass:[UINavigationController class]] && [[(UINavigationController *)secondaryViewController topViewController] isKindOfClass:[DetailViewController class]] && ([(DetailViewController *)[(UINavigationController *)secondaryViewController topViewController] detailItem] == nil)) {
// Return YES to indicate that we have handled the collapse by doing nothing; the secondary controller will be discarded.
return YES;
} else {
return NO;
}
}

@end
Loading

0 comments on commit c9cdf57

Please sign in to comment.