7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni/*
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni * The contents of this file are subject to the terms of the Common Development and
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni * Distribution License (the License). You may not use this file except in compliance with the
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni * License.
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni *
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni * specific language governing permission and limitations under the License.
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni *
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni * When distributing Covered Software, include this CDDL Header Notice in each file and include
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni * Header, with the fields enclosed by brackets [] replaced by your own identifying
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni * information: "Portions copyright [year] [name of copyright owner]".
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni *
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni * Copyright 2016 ForgeRock AS.
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni */
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni#import "FRAActivityIndicator.h"
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni@interface FRAActivityIndicator ()
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni@property (strong, nonatomic) UIBlurEffect *blurEffect;
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni@property (strong, nonatomic) UIVisualEffectView *vibrancyView;
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni@property (strong, nonatomic) UIActivityIndicatorView *activityIndicator;
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni@property (strong, nonatomic) UILabel *label;
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni@end
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni@implementation FRAActivityIndicator
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni#pragma mark -
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni#pragma mark Lifecyle
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni- (instancetype)init:(NSString *)message {
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni self.activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni self.blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni self.vibrancyView = [[UIVisualEffectView alloc] initWithEffect:[UIVibrancyEffect effectForBlurEffect:self.blurEffect]];
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni self = [super initWithEffect:self.blurEffect];
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni if (self) {
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni [self setUp:message];
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni }
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni return self;
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni}
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni- (void)setUp:(NSString *)message {
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni self.label = [[UILabel alloc] init];
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni self.label.text = message;
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni [self.contentView addSubview:self.vibrancyView];
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni [self.vibrancyView.contentView addSubview:self.activityIndicator];
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni [self.vibrancyView.contentView addSubview:self.label];
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni [self.activityIndicator startAnimating];
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni}
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni- (void)didMoveToSuperview {
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni [super didMoveToSuperview];
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni if (self.superview) {
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni CGFloat width = self.superview.frame.size.width / 1.5;
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni CGFloat height = (CGFloat)50.0;
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni self.frame = CGRectMake(self.superview.frame.size.width / 2 - width / 2,
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni self.superview.frame.size.height / 2 - height / 2,
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni width,
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni height);
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni self.vibrancyView.frame = self.bounds;
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni CGFloat activityIndicatorSize = (CGFloat)40;
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni self.activityIndicator.frame = CGRectMake(5, height / 2 - activityIndicatorSize / 2,
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni activityIndicatorSize,
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni activityIndicatorSize);
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni self.layer.cornerRadius = 8.0;
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni self.layer.masksToBounds = true;
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni self.label.textAlignment = NSTextAlignmentCenter;
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni self.label.frame = CGRectMake(activityIndicatorSize + 5, 0, width - activityIndicatorSize - 15, height);
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni self.label.textColor = [UIColor grayColor];
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni self.label.font = [UIFont systemFontOfSize:16];
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni }
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni}
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni@end