Guest User

Untitled

a guest
Dec 9th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.87 KB | None | 0 0
  1. #import "SetAlarm.h"
  2. #import "AlarmRepeat.h"
  3.  
  4.  
  5. @implementation SetAlarm
  6. @synthesize tableView,arrayAlarm,dateTimePicker;
  7. @synthesize scheduleControl;
  8.  
  9.  
  10.  
  11. // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
  12.  
  13.  
  14. -(void)viewWillAppear:(BOOL)animated
  15. {
  16.  
  17.  
  18.  
  19. [self.tableView reloadData];
  20. }
  21.  
  22. // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. tableView.clipsToBounds = YES;
  26. tableView.layer.cornerRadius = 10;
  27.  
  28. tableView.layer.borderWidth = 2.0;
  29. tableView.layer.borderColor = [UIColor blackColor].CGColor;
  30.  
  31. arrayAlarm=[[NSMutableArray alloc]init];
  32. [arrayAlarm addObject:@"Repeat"];
  33. [arrayAlarm addObject:@"Sound"];
  34. [arrayAlarm addObject:@"Snooze"];
  35. [arrayAlarm addObject:@"Label"];
  36.  
  37. dateTimePicker.date=[NSDate date];
  38. scheduleControl.hidden=YES;
  39.  
  40. }
  41.  
  42.  
  43. -(void) presentMessage :(NSString *)message
  44. {
  45. UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Alarm Clock" message:message delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil];
  46. [alert show];
  47. [alert release];
  48. }
  49.  
  50.  
  51.  
  52.  
  53.  
  54. -(void)addNewNotification{
  55.  
  56. iTalkAlarmAppDelegate *ap=[[UIApplication sharedApplication]delegate];
  57.  
  58. UILocalNotification* localNotification = [[UILocalNotification alloc] init];
  59. localNotification.alertBody =@"HI";
  60. localNotification.fireDate = [[NSDate date] dateByAddingTimeInterval:5*60];
  61. localNotification.timeZone = [NSTimeZone localTimeZone];
  62. localNotification.applicationIconBadgeNumber = localNotification.applicationIconBadgeNumber+1;
  63. //localNotification.soundName = UILocalNotificationDefaultSoundName;
  64. if(ap.intrecord==1)
  65. {
  66. //AVAudioPlayer * avPlayer = [[AVAudioPlayer alloc] initWithData:ap.audio error:nil];
  67. //[avPlayer prepareToPlay];
  68. //[avPlayer play];
  69.  
  70. //ap.intrecord=2;
  71.  
  72. }
  73. else {
  74. localNotification.soundName=ap.strAlarmSound;
  75. }
  76.  
  77.  
  78. [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
  79. [localNotification release];
  80. NSLog(@"%@",[[UIApplication sharedApplication] scheduledLocalNotifications]);
  81. }
  82.  
  83.  
  84.  
  85.  
  86.  
  87. - (void)showReminder:(NSString *)text
  88. {
  89. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Reminder"
  90. message:text delegate:self
  91. cancelButtonTitle:@"OK"
  92. otherButtonTitles:@"stop",@"Snooze",nil];
  93. [alertView show];
  94. [alertView release];
  95.  
  96. }
  97. -(void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  98. {
  99.  
  100. NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
  101.  
  102. NSLog(@"%@",title);
  103. if(buttonIndex == 0)
  104. {
  105. [[UIApplication sharedApplication] cancelAllLocalNotifications];
  106. NSLog(@"Button 1 was selected.");
  107. }
  108. else if([title isEqualToString:@"Snooze"])
  109. {
  110. [self addNewNotification];
  111. }
  112.  
  113.  
  114.  
  115. }
  116.  
  117.  
  118.  
  119. -(void) scheduleLocalNotificationWithDate:(NSDate *)fireDate
  120. {
  121. iTalkAlarmAppDelegate *ap=[[UIApplication sharedApplication]delegate];
  122.  
  123. UILocalNotification *notification =[[UILocalNotification alloc]init];
  124.  
  125. notification.fireDate=fireDate;
  126. notification.alertBody=ap.strAlarmTitle;
  127. notification.repeatInterval = 0;
  128. notification.alertAction = NSLocalizedString(@"View", @"View");
  129. //notification.soundName = UILocalNotificationDefaultSoundName;
  130. // notification.soundName =@"Frog.aiff";
  131.  
  132.  
  133.  
  134. if(ap.intrecord==1)
  135. {
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142. notification.soundName=ap.strRecordPath;
  143.  
  144.  
  145.  
  146.  
  147. }
  148. else {
  149. NSLog(@"in notification...%@",ap.strAlarmSound);
  150. notification.soundName=ap.strAlarmSound;
  151.  
  152. }
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160. [ap.arrAlarmName addObject:ap.strAlarmTitle];
  161. [ap.arrAlarmTime addObject:ap.strAlarmTime];
  162.  
  163.  
  164.  
  165.  
  166.  
  167. NSInteger index = ap.segmentValue;// [scheduleControl selectedSegmentIndex];
  168. switch (index) {
  169. case 1:
  170. notification.repeatInterval = NSMinuteCalendarUnit;
  171.  
  172. break;
  173. case 2:
  174. notification.repeatInterval = NSHourCalendarUnit;
  175. break;
  176. case 3:
  177. notification.repeatInterval = NSDayCalendarUnit;
  178. break;
  179. case 4:
  180. notification.repeatInterval = NSWeekCalendarUnit;
  181. break;
  182. default:
  183. notification.repeatInterval = 0;
  184. break;
  185. }
  186.  
  187. NSDictionary *userDict = [NSDictionary dictionaryWithObject:ap.strAlarmTitle
  188. forKey:kRemindMeNotificationDataKey];
  189. notification.userInfo = userDict;
  190.  
  191.  
  192.  
  193. [[UIApplication sharedApplication] scheduleLocalNotification:notification];
  194. [notification release];
  195.  
  196. }
  197.  
  198. -(IBAction)alarmSetButtonTapped:(id)sender
  199. {
  200. //NSLog(@"alarm set button tapped");
  201. iTalkAlarmAppDelegate *ap=[[UIApplication sharedApplication] delegate];
  202.  
  203. NSDateFormatter *dateFormatter=[[NSDateFormatter alloc]init];
  204. //dateFormatter.timeZone=[NSLocale defaultTimeZone];
  205. dateFormatter.locale = [NSLocale systemLocale];
  206. dateFormatter.timeStyle =NSDateFormatterShortStyle;
  207. dateFormatter.dateStyle=NSDateFormatterShortStyle;
  208.  
  209. NSString *dateTimeString=[dateFormatter stringFromDate:dateTimePicker.date];
  210. NSLog(@"date>>>>>%@",dateTimeString);
  211. ap.strAlarmTime=dateTimeString;
  212.  
  213.  
  214. [dateFormatter release];
  215.  
  216. [self scheduleLocalNotificationWithDate:dateTimePicker.date];
  217.  
  218. [self presentMessage:@"Alarm set!"];
  219.  
  220.  
  221.  
  222. }
  223. -(IBAction)alarmCancelButtonTapped:(id)sender
  224. {
  225. NSLog(@"alarm cancel button tapped");
  226.  
  227. [[UIApplication sharedApplication] cancelAllLocalNotifications];
  228.  
  229. [self presentMessage:@"Alarm Cancelled!"];
  230.  
  231.  
  232. }
  233.  
  234.  
  235.  
  236. -(IBAction)btnRecord_Clicked
  237. {
  238. RecordVoice *record=[[RecordVoice alloc]init];
  239.  
  240. record.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
  241. [self presentModalViewController:record animated:NO];
  242.  
  243.  
  244.  
  245. }
  246.  
  247. -(IBAction)btnViewAlarm_Clicked
  248. {
  249.  
  250. ViewAlarm *viewAlarm=[[ViewAlarm alloc]init];
  251.  
  252. viewAlarm.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
  253. [self presentModalViewController:viewAlarm animated:NO];
  254.  
  255.  
  256.  
  257. }
  258.  
  259.  
  260.  
  261.  
  262. #pragma mark Table view methods________________________
  263.  
  264. // To learn about using table views, see the TableViewSuite sample code
  265. // and Table View Programming Guide for iPhone OS.
  266.  
  267. - (NSInteger) tableView: (UITableView *) table numberOfRowsInSection: (NSInteger)section {
  268.  
  269. // RecordVoice *mainViewController = (RecordVoice *) self.delegate;
  270. // MPMediaItemCollection *currentQueue = mainViewController.userMediaItemCollection;
  271. return [arrayAlarm count];//[currentQueue.items count];
  272. }
  273.  
  274. - (UITableViewCell *) tableView: (UITableView *) tableView1 cellForRowAtIndexPath: (NSIndexPath *) indexPath {
  275.  
  276. static NSString *kCellIdentifier = @"Cell";
  277.  
  278. iTalkAlarmAppDelegate *ap=[[UIApplication sharedApplication] delegate];
  279.  
  280. NSInteger row = [indexPath row];
  281. CustomAlarmTable *cell =(CustomAlarmTable *) [tableView dequeueReusableCellWithIdentifier: kCellIdentifier];
  282.  
  283. if (cell == nil) {
  284.  
  285. cell = [[[CustomAlarmTable alloc] initWithFrame: CGRectZero
  286. reuseIdentifier: kCellIdentifier] autorelease];
  287. }
  288.  
  289. // RecordVoice *mainViewController = (RecordVoice *) self.delegate;
  290. // MPMediaItemCollection *currentQueue = mainViewController.userMediaItemCollection;
  291. // MPMediaItem *anItem = (MPMediaItem *)[currentQueue.items objectAtIndex: row];
  292.  
  293. //if (anItem) {
  294. cell.lblCategoryName.text = [arrayAlarm objectAtIndex:row];
  295.  
  296. if(row==1)
  297. cell.lblPicked.text = ap.strSoundName;
  298.  
  299. if(row==3)
  300. {
  301. cell.lblPicked.text = ap.strAlarmTitle;
  302. }
  303.  
  304. //[tableView deselectRowAtIndexPath: indexPath animated: YES];
  305.  
  306. return cell;
  307. }
  308.  
  309. // To conform to the Human Interface Guidelines, selections should not be persistent --
  310. // deselect the row after it has been selected.
  311. - (void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath {
  312.  
  313.  
  314. if(indexPath.row==0)
  315. {
  316.  
  317. //scheduleControl.hidden=NO;
  318. //tableView.hidden=YES;
  319.  
  320. AlarmRepeat *repeat=[[AlarmRepeat alloc]init];
  321. repeat.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
  322. [self presentModalViewController:repeat animated:YES];
  323.  
  324.  
  325. }
  326.  
  327.  
  328. if(indexPath.row==1)
  329. {
  330. setSound *sound=[[setSound alloc]init];
  331.  
  332. sound.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
  333. [self presentModalViewController:sound animated:YES];
  334.  
  335.  
  336. }//[tableView deselectRowAtIndexPath: indexPath animated: YES];
  337.  
  338.  
  339. if(indexPath.row==3)
  340. {
  341. setLabel *lbl=[[setLabel alloc]init];
  342.  
  343. lbl.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
  344. [self presentModalViewController:lbl animated:YES];
  345.  
  346.  
  347. }
  348.  
  349.  
  350. }
  351.  
  352.  
  353. #pragma mark -
  354. #pragma mark Navigation Controller delegate
  355.  
  356.  
  357. /*
  358. // Override to allow orientations other than the default portrait orientation.
  359. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  360. // Return YES for supported orientations.
  361. return (interfaceOrientation == UIInterfaceOrientationPortrait);
  362. }
  363. */
  364.  
  365. - (void)didReceiveMemoryWarning {
  366. // Releases the view if it doesn't have a superview.
  367. [super didReceiveMemoryWarning];
  368.  
  369. // Release any cached data, images, etc. that aren't in use.
  370. }
  371.  
  372. - (void)viewDidUnload {
  373. [super viewDidUnload];
  374. // Release any retained subviews of the main view.
  375. // e.g. self.myOutlet = nil;
  376. }
  377.  
  378.  
  379. - (void)dealloc {
  380. [super dealloc];
  381. }
  382.  
  383.  
  384. @end
Add Comment
Please, Sign In to add comment