diff --git a/matrixConsole.xcodeproj/project.pbxproj b/matrixConsole.xcodeproj/project.pbxproj index 256279a36..46b33bc57 100644 --- a/matrixConsole.xcodeproj/project.pbxproj +++ b/matrixConsole.xcodeproj/project.pbxproj @@ -8,6 +8,9 @@ /* Begin PBXBuildFile section */ 3198D9E11A68338B00556695 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 3198D9E31A68338B00556695 /* Localizable.strings */; }; + 710CA4BF1A7FBEDB00EEFB96 /* RageShakableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 710CA4BE1A7FBEDB00EEFB96 /* RageShakableViewController.m */; }; + 710CA4C21A7FBFED00EEFB96 /* RageShakableUIResponder.m in Sources */ = {isa = PBXBuildFile; fileRef = 710CA4C11A7FBFED00EEFB96 /* RageShakableUIResponder.m */; }; + 710CA4C51A7FC27100EEFB96 /* RageShakableTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 710CA4C41A7FC27100EEFB96 /* RageShakableTableViewController.m */; }; 710CC3BF1A6E9F14006EE973 /* matrixUser.png in Resources */ = {isa = PBXBuildFile; fileRef = 710CC3BE1A6E9F14006EE973 /* matrixUser.png */; }; 710CC3C21A70F28F006EE973 /* MXCContactField.m in Sources */ = {isa = PBXBuildFile; fileRef = 710CC3C11A70F28F006EE973 /* MXCContactField.m */; }; 71193D241A6D64F900E59A9E /* AddressBook.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 71193D231A6D64F900E59A9E /* AddressBook.framework */; }; @@ -86,6 +89,12 @@ /* Begin PBXFileReference section */ 13057A57E74FD5504196F47F /* Pods-matrixConsole.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-matrixConsole.release.xcconfig"; path = "Pods/Target Support Files/Pods-matrixConsole/Pods-matrixConsole.release.xcconfig"; sourceTree = ""; }; 3198D9E21A68338B00556695 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = ""; }; + 710CA4BD1A7FBEDB00EEFB96 /* RageShakableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RageShakableViewController.h; sourceTree = ""; }; + 710CA4BE1A7FBEDB00EEFB96 /* RageShakableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RageShakableViewController.m; sourceTree = ""; }; + 710CA4C01A7FBFED00EEFB96 /* RageShakableUIResponder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RageShakableUIResponder.h; sourceTree = ""; }; + 710CA4C11A7FBFED00EEFB96 /* RageShakableUIResponder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RageShakableUIResponder.m; sourceTree = ""; }; + 710CA4C31A7FC27100EEFB96 /* RageShakableTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RageShakableTableViewController.h; sourceTree = ""; }; + 710CA4C41A7FC27100EEFB96 /* RageShakableTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RageShakableTableViewController.m; sourceTree = ""; }; 710CC3BE1A6E9F14006EE973 /* matrixUser.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = matrixUser.png; sourceTree = ""; }; 710CC3C01A70F28F006EE973 /* MXCContactField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MXCContactField.h; sourceTree = ""; }; 710CC3C11A70F28F006EE973 /* MXCContactField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MXCContactField.m; sourceTree = ""; }; @@ -299,6 +308,10 @@ F03EF5EF19F171EB00A0EE52 /* MasterTabBarController.m */, 71DB9DBF1A495B6400504A09 /* MemberViewController.h */, 71DB9DC01A495B6400504A09 /* MemberViewController.m */, + 710CA4C31A7FC27100EEFB96 /* RageShakableTableViewController.h */, + 710CA4C41A7FC27100EEFB96 /* RageShakableTableViewController.m */, + 710CA4BD1A7FBEDB00EEFB96 /* RageShakableViewController.h */, + 710CA4BE1A7FBEDB00EEFB96 /* RageShakableViewController.m */, F03EF5F019F171EB00A0EE52 /* RecentsViewController.h */, F03EF5F119F171EB00A0EE52 /* RecentsViewController.m */, F03EF5F219F171EB00A0EE52 /* RoomViewController.h */, @@ -353,6 +366,8 @@ 71193D331A6E49F000E59A9E /* MXCEmail.m */, 71193D341A6E49F000E59A9E /* MXCPhoneNumber.h */, 71193D351A6E49F000E59A9E /* MXCPhoneNumber.m */, + 710CA4C01A7FBFED00EEFB96 /* RageShakableUIResponder.h */, + 710CA4C11A7FBFED00EEFB96 /* RageShakableUIResponder.m */, F0D942F41A31F3A300826CC1 /* RecentRoom.h */, F0D942F51A31F3A300826CC1 /* RecentRoom.m */, F0465AF81A251F85003639F9 /* RoomMessage.h */, @@ -586,6 +601,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 710CA4BF1A7FBEDB00EEFB96 /* RageShakableViewController.m in Sources */, 7176294F1A77FED800927125 /* ContactDetailsTableCell.m in Sources */, F04A8AD81A3B3DF4008AC915 /* RoomTitleView.m in Sources */, F07A80DB19DD9DE700B621A1 /* AppDelegate.m in Sources */, @@ -603,6 +619,8 @@ F01A0FF31A27314B009FAE2F /* RoomMessageComponent.m in Sources */, F03EF5FA19F171EB00A0EE52 /* RoomViewController.m in Sources */, F03EF5F819F171EB00A0EE52 /* MasterTabBarController.m in Sources */, + 710CA4C21A7FBFED00EEFB96 /* RageShakableUIResponder.m in Sources */, + 710CA4C51A7FC27100EEFB96 /* RageShakableTableViewController.m in Sources */, F03EF5F619F171EB00A0EE52 /* HomeViewController.m in Sources */, 71DB9DC11A495B6400504A09 /* MemberViewController.m in Sources */, F0D942F61A31F3A300826CC1 /* RecentRoom.m in Sources */, diff --git a/matrixConsole/AppDelegate.h b/matrixConsole/AppDelegate.h index 3257c6483..df45e65e0 100644 --- a/matrixConsole/AppDelegate.h +++ b/matrixConsole/AppDelegate.h @@ -28,6 +28,8 @@ @property (strong, nonatomic) MXCAlert *errorNotification; +@property (nonatomic) BOOL isAppForeground; + + (AppDelegate*)theDelegate; - (void)registerUserNotificationSettings; diff --git a/matrixConsole/AppDelegate.m b/matrixConsole/AppDelegate.m index 66c5477a5..99209a7d5 100644 --- a/matrixConsole/AppDelegate.m +++ b/matrixConsole/AppDelegate.m @@ -70,6 +70,8 @@ recents.tabBarItem.image = [[UIImage imageNamed:@"tab_recents"] imageWithRenderingMode:UIImageRenderingModeAutomatic]; } + _isAppForeground = NO; + // Retrieve custom configuration NSString* userDefaults = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UserDefaults"]; NSString *defaultsPathFromApp = [[NSBundle mainBundle] pathForResource:userDefaults ofType:@"plist"]; @@ -110,12 +112,16 @@ // clear the notifications counter [self clearNotifications]; + + _isAppForeground = NO; } - (void)applicationWillEnterForeground:(UIApplication *)application { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. // clear the notifications counter [self clearNotifications]; + + _isAppForeground = YES; } - (void)applicationDidBecomeActive:(UIApplication *)application { @@ -125,6 +131,8 @@ // refresh the contacts list [[ContactManager sharedManager] fullRefresh]; + + _isAppForeground = YES; } - (void)applicationWillTerminate:(UIApplication *)application { diff --git a/matrixConsole/Base.lproj/Main.storyboard b/matrixConsole/Base.lproj/Main.storyboard index eff2cc03e..65e43176c 100644 --- a/matrixConsole/Base.lproj/Main.storyboard +++ b/matrixConsole/Base.lproj/Main.storyboard @@ -1,5 +1,5 @@ - + diff --git a/matrixConsole/Model/RageShakableUIResponder.h b/matrixConsole/Model/RageShakableUIResponder.h new file mode 100644 index 000000000..c012a93d7 --- /dev/null +++ b/matrixConsole/Model/RageShakableUIResponder.h @@ -0,0 +1,28 @@ +/* + Copyright 2014 OpenMarket Ltd + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#import + +#import + +@interface RageShakableUIResponder : UIResponder + ++ (void)startShaking:(UIResponder*)controller; ++ (void)stopShaking:(UIResponder*)controller; ++ (void)cancel:(UIResponder*)controller; ++ (void)applicationBecomesActive; + +@end diff --git a/matrixConsole/Model/RageShakableUIResponder.m b/matrixConsole/Model/RageShakableUIResponder.m new file mode 100644 index 000000000..8fd3b0521 --- /dev/null +++ b/matrixConsole/Model/RageShakableUIResponder.m @@ -0,0 +1,179 @@ +/* + Copyright 2014 OpenMarket Ltd + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#import "RageShakableUIResponder.h" + +#import "AppDelegate.h" + +#import "MXCAlert.h" + +@interface RageShakableUIResponder() { + MXCAlert *confirmationAlert; + double startShakingTimeStamp; + bool isShaking; + bool ignoreShakeEnd; + + UIViewController* parentViewController; + MFMailComposeViewController* mailComposer; +} +@end + +@implementation RageShakableUIResponder + +static RageShakableUIResponder* sharedInstance = nil; + +- (id) init { + self = [super init]; + + if (self) { + mailComposer = nil; + confirmationAlert = nil; + startShakingTimeStamp = 0; + isShaking = NO; + ignoreShakeEnd = NO; + } + + return self; +} + ++ (void)startShaking:(UIResponder*)responder { + + if (!sharedInstance) { + sharedInstance = [[RageShakableUIResponder alloc] init]; + } + + RageShakableUIResponder* rageShakableUIResponder = [responder isKindOfClass:[RageShakableUIResponder class]] ? (RageShakableUIResponder*)responder : sharedInstance; + + // only start if the application is in foreground + if ([AppDelegate theDelegate].isAppForeground && !rageShakableUIResponder->confirmationAlert) { + rageShakableUIResponder->startShakingTimeStamp = [[NSDate date] timeIntervalSince1970]; + + rageShakableUIResponder->isShaking = YES; + rageShakableUIResponder->ignoreShakeEnd = NO; + } +} + ++ (void)stopShaking:(UIResponder*)responder +{ + if (!sharedInstance) { + sharedInstance = [[RageShakableUIResponder alloc] init]; + } + + NSLog(@"stopShaking with [%@]", [responder class]); + + RageShakableUIResponder* rageShakableUIResponder = [responder isKindOfClass:[RageShakableUIResponder class]] ? (RageShakableUIResponder*)responder : sharedInstance; + + if (rageShakableUIResponder && [AppDelegate theDelegate].isAppForeground && (([[NSDate date] timeIntervalSince1970] - rageShakableUIResponder->startShakingTimeStamp) > 1.5) && !rageShakableUIResponder->confirmationAlert) { + if (!rageShakableUIResponder->ignoreShakeEnd) { + rageShakableUIResponder->startShakingTimeStamp = [[NSDate date] timeIntervalSince1970]; + + if ([responder isKindOfClass:[UIViewController class]]) { + rageShakableUIResponder->confirmationAlert = [[MXCAlert alloc] initWithTitle:@"You seem to be shaking the phone in frustration. Would you like to submit a bug report?" message:nil style:MXCAlertStyleAlert]; + + [rageShakableUIResponder->confirmationAlert addActionWithTitle:@"Cancel" style:MXCAlertActionStyleDefault handler:^(MXCAlert *alert) { + sharedInstance->confirmationAlert = nil; + }]; + + [rageShakableUIResponder->confirmationAlert addActionWithTitle:@"OK" style:MXCAlertActionStyleDefault handler:^(MXCAlert *alert) { + sharedInstance->confirmationAlert = nil; + [RageShakableUIResponder takeScreenshot:(UIViewController*)responder]; + }]; + + [rageShakableUIResponder->confirmationAlert showInViewController:(UIViewController*)responder]; + } + } else { + [RageShakableUIResponder takeScreenshot:nil]; + } + } + + rageShakableUIResponder->isShaking = NO; + rageShakableUIResponder->ignoreShakeEnd = NO; +} + ++ (void)cancel:(UIResponder*)responder { + + if (!sharedInstance) { + sharedInstance = [[RageShakableUIResponder alloc] init]; + } + + RageShakableUIResponder* rageShakableUIResponder = [responder isKindOfClass:[RageShakableUIResponder class]] ? (RageShakableUIResponder*)responder : sharedInstance; + + // Arathorn succeeded to shake the device and to put the application in background at the same time (magic finders) + // it should prevent any screenshot alert in this crazy case + rageShakableUIResponder->startShakingTimeStamp = [[NSDate date] timeIntervalSince1970]; + + if (rageShakableUIResponder->isShaking) { + rageShakableUIResponder->ignoreShakeEnd = YES; + } +} + ++ (void)applicationBecomesActive { + [RageShakableUIResponder cancel:nil]; +} + ++ (void)takeScreenshot:(UIViewController*)controller { + AppDelegate* theDelegate = [AppDelegate theDelegate]; + UIGraphicsBeginImageContext(theDelegate.window.bounds.size); + + // Iterate over every window from back to front + for (UIWindow *window in [[UIApplication sharedApplication] windows]) + { + if (![window respondsToSelector:@selector(screen)] || [window screen] == [UIScreen mainScreen]) + { + // -renderInContext: renders in the coordinate space of the layer, + // so we must first apply the layer's geometry to the graphics context + CGContextSaveGState(UIGraphicsGetCurrentContext()); + // Center the context around the window's anchor point + CGContextTranslateCTM(UIGraphicsGetCurrentContext(), [window center].x, [window center].y); + // Apply the window's transform about the anchor point + CGContextConcatCTM(UIGraphicsGetCurrentContext(), [window transform]); + // Offset by the portion of the bounds left of and above the anchor point + CGContextTranslateCTM(UIGraphicsGetCurrentContext(), + -[window bounds].size.width * [[window layer] anchorPoint].x, + -[window bounds].size.height * [[window layer] anchorPoint].y); + + // Render the layer hierarchy to the current context + [[window layer] renderInContext:UIGraphicsGetCurrentContext()]; + + // Restore the context + CGContextRestoreGState(UIGraphicsGetCurrentContext()); + } + } + UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + + // the image is copied in the clipboard + [UIPasteboard generalPasteboard].image = image; + + if (controller) { + sharedInstance->parentViewController = controller; + sharedInstance->mailComposer = [[MFMailComposeViewController alloc] init]; + + [sharedInstance->mailComposer setSubject:@"Matrix bug report"]; + [sharedInstance->mailComposer setToRecipients:[NSArray arrayWithObject:@"rageshake@matrix.org"]]; + [sharedInstance->mailComposer setMessageBody:@"Something went wrong on my Matrix client." isHTML:NO]; + [sharedInstance->mailComposer addAttachmentData:UIImageJPEGRepresentation(image, 1.0) mimeType:@"image/jpg" fileName:@"screenshot.jpg"]; + sharedInstance->mailComposer.mailComposeDelegate = sharedInstance; + [controller presentViewController:sharedInstance->mailComposer animated:YES completion:nil]; + } +} + +#pragma mark - MFMailComposeViewControllerDelegate delegate +- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error { + [controller dismissViewControllerAnimated:NO completion:nil]; +} + +@end diff --git a/matrixConsole/ViewController/ContactDetailsViewController.h b/matrixConsole/ViewController/ContactDetailsViewController.h index 3238bde27..2e95563f9 100644 --- a/matrixConsole/ViewController/ContactDetailsViewController.h +++ b/matrixConsole/ViewController/ContactDetailsViewController.h @@ -14,11 +14,11 @@ limitations under the License. */ -#import +#import "RageShakableTableViewController.h" #import "MXCContact.h" -@interface ContactDetailsViewController : UITableViewController +@interface ContactDetailsViewController : RageShakableTableViewController @property (strong, nonatomic) MXCContact* contact; @end diff --git a/matrixConsole/ViewController/ContactsViewController.h b/matrixConsole/ViewController/ContactsViewController.h index b0e759a8c..507b661e9 100644 --- a/matrixConsole/ViewController/ContactsViewController.h +++ b/matrixConsole/ViewController/ContactsViewController.h @@ -14,7 +14,7 @@ limitations under the License. */ -#import +#import "RageShakableViewController.h" // SMS #import @@ -22,7 +22,7 @@ #import "SectionedContacts.h" -@interface ContactsViewController : UIViewController { +@interface ContactsViewController : RageShakableViewController { NSArray* collationTitles; } diff --git a/matrixConsole/ViewController/HomeViewController.h b/matrixConsole/ViewController/HomeViewController.h index 81eca6534..086f1d50e 100644 --- a/matrixConsole/ViewController/HomeViewController.h +++ b/matrixConsole/ViewController/HomeViewController.h @@ -14,9 +14,9 @@ limitations under the License. */ -#import +#import "RageShakableTableViewController.h" -@interface HomeViewController : UITableViewController +@interface HomeViewController : RageShakableTableViewController @end diff --git a/matrixConsole/ViewController/LoginViewController.h b/matrixConsole/ViewController/LoginViewController.h index cf5b84442..754971418 100644 --- a/matrixConsole/ViewController/LoginViewController.h +++ b/matrixConsole/ViewController/LoginViewController.h @@ -14,9 +14,9 @@ limitations under the License. */ -#import +#import "RageShakableViewController.h" -@interface LoginViewController : UIViewController +@interface LoginViewController : RageShakableViewController @end diff --git a/matrixConsole/ViewController/MemberViewController.h b/matrixConsole/ViewController/MemberViewController.h index dd3cddc02..140718291 100644 --- a/matrixConsole/ViewController/MemberViewController.h +++ b/matrixConsole/ViewController/MemberViewController.h @@ -14,11 +14,11 @@ limitations under the License. */ -#import +#import "RageShakableTableViewController.h" #import "MatrixSDKHandler.h" -@interface MemberViewController : UITableViewController +@interface MemberViewController : RageShakableTableViewController @property (strong, nonatomic) MXRoomMember *mxRoomMember; @property (strong, nonatomic) MXRoom *mxRoom; diff --git a/matrixConsole/ViewController/RageShakableTableViewController.h b/matrixConsole/ViewController/RageShakableTableViewController.h new file mode 100644 index 000000000..3a226211d --- /dev/null +++ b/matrixConsole/ViewController/RageShakableTableViewController.h @@ -0,0 +1,22 @@ +/* + Copyright 2014 OpenMarket Ltd + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#import + +@interface RageShakableTableViewController : UITableViewController + +@end + diff --git a/matrixConsole/ViewController/RageShakableTableViewController.m b/matrixConsole/ViewController/RageShakableTableViewController.m new file mode 100644 index 000000000..0e5f76d51 --- /dev/null +++ b/matrixConsole/ViewController/RageShakableTableViewController.m @@ -0,0 +1,55 @@ +/* + Copyright 2014 OpenMarket Ltd + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ +#import "RageShakableTableViewController.h" + +#import "RageShakableUIResponder.h" + +@implementation RageShakableTableViewController + +- (void)viewWillAppear:(BOOL)animated { + [super viewWillAppear:animated]; + [RageShakableUIResponder cancel:self]; +} + +- (void)viewWillDisappear:(BOOL)animated { + [super viewWillDisappear:animated]; + [RageShakableUIResponder cancel:self]; +} + +#pragma mark - rageshake : screenshot +- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event { + if (motion == UIEventSubtypeMotionShake) { + [RageShakableUIResponder startShaking:self]; + } +} + +- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event { + [self motionEnded:motion withEvent:event]; +} + +- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { + if (motion == UIEventSubtypeMotionShake) { + [RageShakableUIResponder stopShaking:self]; + } +} + +- (BOOL)canBecomeFirstResponder { + return YES; +} + +@end + + diff --git a/matrixConsole/ViewController/RageShakableViewController.h b/matrixConsole/ViewController/RageShakableViewController.h new file mode 100644 index 000000000..024d277a6 --- /dev/null +++ b/matrixConsole/ViewController/RageShakableViewController.h @@ -0,0 +1,22 @@ +/* + Copyright 2014 OpenMarket Ltd + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#import + +@interface RageShakableViewController : UIViewController + +@end + diff --git a/matrixConsole/ViewController/RageShakableViewController.m b/matrixConsole/ViewController/RageShakableViewController.m new file mode 100644 index 000000000..3ff1b3fea --- /dev/null +++ b/matrixConsole/ViewController/RageShakableViewController.m @@ -0,0 +1,55 @@ +/* + Copyright 2014 OpenMarket Ltd + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ +#import "RageShakableViewController.h" + +#import "RageShakableUIResponder.h" + +@implementation RageShakableViewController + +- (void)viewWillAppear:(BOOL)animated { + [super viewWillAppear:animated]; + [RageShakableUIResponder cancel:self]; +} + +- (void)viewWillDisappear:(BOOL)animated { + [super viewWillDisappear:animated]; + [RageShakableUIResponder cancel:self]; +} + +#pragma mark - rageshake : screenshot +- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event { + if (motion == UIEventSubtypeMotionShake) { + [RageShakableUIResponder startShaking:self]; + } +} + +- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event { + [self motionEnded:motion withEvent:event]; +} + +- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { + if (motion == UIEventSubtypeMotionShake) { + [RageShakableUIResponder stopShaking:self]; + } +} + +- (BOOL)canBecomeFirstResponder { + return YES; +} + +@end + + diff --git a/matrixConsole/ViewController/RecentsViewController.h b/matrixConsole/ViewController/RecentsViewController.h index 553c6d77f..dbb7523db 100644 --- a/matrixConsole/ViewController/RecentsViewController.h +++ b/matrixConsole/ViewController/RecentsViewController.h @@ -14,11 +14,11 @@ limitations under the License. */ -#import +#import "RageShakableTableViewController.h" @class RoomViewController; -@interface RecentsViewController : UITableViewController +@interface RecentsViewController : RageShakableTableViewController @property (strong, nonatomic) NSString *preSelectedRoomId; // set a non-nil value to this property will open room details diff --git a/matrixConsole/ViewController/RoomViewController.h b/matrixConsole/ViewController/RoomViewController.h index 04239bdf3..ef99d3f66 100644 --- a/matrixConsole/ViewController/RoomViewController.h +++ b/matrixConsole/ViewController/RoomViewController.h @@ -14,11 +14,11 @@ limitations under the License. */ -#import +#import "RageShakableViewController.h" #import "HPGrowingTextView.h" -@interface RoomViewController : UIViewController +@interface RoomViewController : RageShakableViewController @property (strong, nonatomic) NSString *roomId; diff --git a/matrixConsole/ViewController/SettingsViewController.h b/matrixConsole/ViewController/SettingsViewController.h index 52c8c79ca..24cc5eaef 100644 --- a/matrixConsole/ViewController/SettingsViewController.h +++ b/matrixConsole/ViewController/SettingsViewController.h @@ -14,9 +14,9 @@ limitations under the License. */ -#import +#import "RageShakableTableViewController.h" -@interface SettingsViewController : UITableViewController +@interface SettingsViewController : RageShakableTableViewController typedef void (^blockSettings_onReadyToLeave)();