[sensortag-ios-source-code-example/sensortag-ios-source-code-example.git] / SensorTag_iOS / SensorTag2-Example / siOleAlertView.m
1 /*!
2 * \author Ole A. Torvmark <o.a.torvmark@ti.com , torvmark@stalliance.no>
3 * \brief Custom View for diplay alerts for SensorTag2-Example iOS application
4 * \copyright Copyright (c) 2015 Texas Instruments Incorporated
5 * \file siOleAlertView.m
6 */
8 /*
9 * Copyright (c) 2015 Texas Instruments Incorporated
10 *
11 * All rights reserved not granted herein.
12 * Limited License.
13 *
14 * Texas Instruments Incorporated grants a world-wide, royalty-free,
15 * non-exclusive license under copyrights and patents it now or hereafter
16 * owns or controls to make, have made, use, import, offer to sell and sell ("Utilize")
17 * this software subject to the terms herein. With respect to the foregoing patent
18 *license, such license is granted solely to the extent that any such patent is necessary
19 * to Utilize the software alone. The patent license shall not apply to any combinations which
20 * include this software, other than combinations with devices manufactured by or for TI (“TI Devices”).
21 * No hardware patent is licensed hereunder.
22 *
23 * Redistributions must preserve existing copyright notices and reproduce this license (including the
24 * above copyright notice and the disclaimer and (if applicable) source code license limitations below)
25 * in the documentation and/or other materials provided with the distribution
26 *
27 * Redistribution and use in binary form, without modification, are permitted provided that the following
28 * conditions are met:
29 *
30 * * No reverse engineering, decompilation, or disassembly of this software is permitted with respect to any
31 * software provided in binary form.
32 * * any redistribution and use are licensed by TI for use only with TI Devices.
33 * * Nothing shall obligate TI to provide you with source code for the software licensed and provided to you in object code.
34 *
35 * If software source code is provided to you, modification and redistribution of the source code are permitted
36 * provided that the following conditions are met:
37 *
38 * * any redistribution and use of the source code, including any resulting derivative works, are licensed by
39 * TI for use only with TI Devices.
40 * * any redistribution and use of any object code compiled from the source code and any resulting derivative
41 * works, are licensed by TI for use only with TI Devices.
42 *
43 * Neither the name of Texas Instruments Incorporated nor the names of its suppliers may be used to endorse or
44 * promote products derived from this software without specific prior written permission.
45 *
46 * DISCLAIMER.
47 *
48 * THIS SOFTWARE IS PROVIDED BY TI AND TI’S LICENSORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
49 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
50 * IN NO EVENT SHALL TI AND TI’S LICENSORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
51 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
52 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
53 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
54 * POSSIBILITY OF SUCH DAMAGE.
55 */
57 #import "siOleAlertView.h"
59 @implementation siOleAlertView
61 -(instancetype) initInView:(UIView *)view {
62 self = [super init];
63 if (self) {
64 self.alpha = 0.0f;
65 self.layer.cornerRadius = 15.0f;
66 self.clipsToBounds = YES;
67 self.message = [[autoSizeLabel alloc]init];
68 self.message.textColor = [UIColor whiteColor];
69 self.message.textAlignment = NSTextAlignmentCenter;
70 UIVisualEffect *blurEffect;
71 blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
72 UIVisualEffect *vibranceEffect;
73 vibranceEffect = [UIVibrancyEffect effectForBlurEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
74 self.efView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
75 UIVisualEffectView *vib = [[UIVisualEffectView alloc] initWithEffect:vibranceEffect];
76 [self.efView addSubview:vib];
77 self.efView.frame = view.frame;
78 [self addSubview:self.efView];
79 [self addSubview:self.message];
80 [view addSubview:self];
81 [self setFrame:view.frame];
82 }
83 return self;
84 }
88 -(void) setFrame:(CGRect)frame {
89 #define STD_SIZE_X 300
90 #define STD_SIZE_Y 200
91 [super setFrame:CGRectMake((frame.size.width - STD_SIZE_X) / 2, (frame.size.height - STD_SIZE_Y) / 2, STD_SIZE_X, STD_SIZE_Y)];
92 self.efView.frame = self.bounds;
93 self.message.frame = CGRectMake(20, 20, self.bounds.size.width - 40, self.bounds.size.height - 40);
94 self.message.text = self.message.text;
95 }
98 -(void) blinkMessage:(NSString *) message {
99 self.message.text = message;
101 [UIView animateWithDuration:0.4f delay:0.0f options: UIViewAnimationOptionCurveEaseInOut animations:^{
102 self.alpha = 1.0f;
103 }completion:nil];
105 [UIView animateWithDuration:0.6f delay:0.4f options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat | UIViewAnimationCurveEaseInOut animations:^{
106 self.message.alpha = 0.0f;
107 }completion:^(BOOL finished){
109 }];
111 }
113 -(void) dismissMessage {
114 [UIView animateWithDuration:0.1f animations:^{
115 self.alpha = 0.0f;
116 } completion:^(BOOL finished) {
117 [self removeFromSuperview];
118 }];
119 }
121 @end