FunctionSelectViewController.m 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. //
  2. // FunctionSelectViewController.m
  3. // Apex Mobile
  4. //
  5. // Created by Ray on 14-2-25.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "FunctionSelectViewController.h"
  9. @interface FunctionSelectViewController ()
  10. @end
  11. @implementation FunctionSelectViewController
  12. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  13. {
  14. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  15. if (self) {
  16. // Custom initialization
  17. }
  18. return self;
  19. }
  20. - (IBAction)onButtonClick:(UIButton *)sender {
  21. DebugLog(@"onButtonClick%@",sender.restorationIdentifier);
  22. // sender.restorationIdentifier
  23. NSString *function_name;
  24. //= [sender currentTitle];
  25. switch (sender.tag) {
  26. case 101:
  27. function_name = @"Ocean Booking";
  28. break;
  29. case 102:
  30. function_name = @"Ocean B/L info.";
  31. break;
  32. case 103:
  33. function_name = @"Container detail";
  34. break;
  35. case 104:
  36. function_name = @"Download Document";
  37. default:
  38. break;
  39. }
  40. SearchViewController *searchViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SearchViewController"];
  41. searchViewController.function_name = function_name;
  42. [self.navigationController pushViewController:searchViewController animated:YES];
  43. }
  44. - (BOOL)shouldAutorotate
  45. {
  46. return YES;
  47. }
  48. - (IBAction)onToolsClick:(UIButton *)sender {
  49. ToolsPanelViewController *toolsViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"ToolsPanel"];
  50. toolsViewController.showNavigation = true;
  51. [self.navigationController pushViewController:toolsViewController animated:YES];
  52. }
  53. - (IBAction)OnDocumentClick:(UIButton *)sender {
  54. DocumentsViewController *documentsViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"DocumentsViewController"];
  55. // toolsViewController.showNavigation = true;
  56. [self.navigationController pushViewController:documentsViewController animated:YES];
  57. }
  58. - (IBAction)onResetClick:(UIButton *)sender {
  59. self.edit.text=@"";
  60. }
  61. - (IBAction)onHbolClick:(UIButton *)sender {
  62. self.radioContainer.selected = false;
  63. sender.selected = true;
  64. NSArray* array = [ApexMobileDB get_searchhistory:@"h_bol"];
  65. [self.autocompleteView.itemsSource put_predictions:array ];
  66. }
  67. - (IBAction)onContainerClick:(UIButton *)sender {
  68. self.radioHbol.selected = false;
  69. sender.selected = true;
  70. NSArray* array = [ApexMobileDB get_searchhistory:@"ctnr"];
  71. [self.autocompleteView.itemsSource put_predictions:array ];
  72. }
  73. - (IBAction)onSearchClick:(UIButton *)sender {
  74. // NSString *filePath = [[NSBundle mainBundle] pathForResource:@"openurltest.txt" ofType:nil inDirectory:nil];
  75. // NSURL *url = [[NSURL alloc] initFileURLWithPath:filePath];
  76. // UIDocumentInteractionController *documentController =[UIDocumentInteractionController interactionControllerWithURL: url];
  77. // [documentController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
  78. //
  79. // return;
  80. NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
  81. [params setObject:@"dumb" forKey:@"id"];
  82. NSString* h_field;
  83. if(self.radioContainer.selected==true)
  84. {
  85. [params setObject:@"1" forKey:@"criterion_type"];
  86. h_field = @"ctnr";
  87. }
  88. else
  89. {
  90. [params setObject:@"0" forKey:@"criterion_type"];
  91. h_field = @"h_bol";
  92. }
  93. NSString * cargo_criterion = self.edit.text;
  94. if(cargo_criterion==nil)
  95. cargo_criterion=@"";
  96. [params setObject:cargo_criterion forKey:@"cargo_criterion"];
  97. [ApexMobileDB savehistory:h_field value:cargo_criterion];
  98. DetailTabBarController *detailViewController=[[DetailTabBarController alloc] init:@"Cargo Tracking" actions:[NSArray arrayWithObjects:@"Tracking",nil] params:params];
  99. [self.navigationController pushViewController:detailViewController animated:YES];
  100. /*
  101. Intent intent = new Intent();
  102. intent.setClass(this, DetailActivity.class);
  103. intent.putExtra("action0", );
  104. intent.putExtra("function_name", );
  105. intent.putExtra("cargo_criterion", cargo_criterion);
  106. intent.putExtra("actions_count", 1);
  107. intent.putExtra("_id", "dumb");
  108. String h_field;
  109. RadioGroup rg = (RadioGroup) findViewById(R.id.radioGroup1);
  110. if (rg.getCheckedRadioButtonId() == R.id.radio0)
  111. {
  112. intent.putExtra("criterion_type", 0);
  113. h_field = "hbol";
  114. }
  115. else
  116. {
  117. intent.putExtra("criterion_type", 1);
  118. h_field = "container_no";
  119. }
  120. String user = ApexTrackingApplication.get_user();
  121. startActivity(intent);
  122. */
  123. }
  124. - (IBAction)onExit:(UIButton *)sender {
  125. ApexMobileAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
  126. [appDelegate Logout];
  127. [self performSegueWithIdentifier:@"LOGIN" sender:self];
  128. // exit(0);
  129. }
  130. -(BOOL)textFieldShouldReturn:(UITextField *)textField {
  131. [textField resignFirstResponder];
  132. return YES;
  133. }
  134. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
  135. [[self view] endEditing:YES];
  136. }
  137. - (NSUInteger)supportedInterfaceOrientations
  138. {
  139. return UIInterfaceOrientationMaskPortrait;
  140. }
  141. - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
  142. {
  143. return UIInterfaceOrientationPortrait;
  144. }
  145. -(void)viewWillAppear:(BOOL)animated
  146. {
  147. NSLog(@"App active");
  148. long i = [UIApplication sharedApplication].applicationIconBadgeNumber;
  149. if(i>0)
  150. self.messageButton.imageView.image = [UIImage imageNamed:@"ic_message_new"];
  151. else
  152. self.messageButton.imageView.image = [UIImage imageNamed:@"ic_message"];
  153. NSString* field = nil;
  154. if(self.radioHbol.selected ==true)
  155. field=@"h_bol";
  156. else
  157. field=@"ctnr";
  158. NSArray* array = [ApexMobileDB get_searchhistory:field] ;
  159. self.autocompleteView = [MyAutocompleteView autocompleteViewBindedTo:self.edit
  160. usingSource:[[MyAutocompleteItemsSource alloc]
  161. initWithMinimumCharactersToTrigger:1 source:array
  162. ]
  163. cellFactory:[[MyAutocompletionCellFactory alloc]
  164. initWithCellTextColor:[UIColor blackColor]
  165. fontSize:14]
  166. // presentingIn:self
  167. parentView:self.view];
  168. self.autocompleteView.topMargin = 0;
  169. // self.autocompleteView.backgroundColor = [UIColor ui];
  170. self.autocompleteView.didAutocompleteWith = ^(MySuggestion* item)
  171. {
  172. NSLog(@"Autocompleted with: %@", item.completionText);
  173. };
  174. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  175. bool autologin =[defaults boolForKey:@"autologin"];
  176. if(!autologin)
  177. {
  178. [self performSegueWithIdentifier:@"LOGIN" sender:self];
  179. }
  180. }
  181. - (void)viewDidLoad
  182. {
  183. [super viewDidLoad];
  184. self.navigationItem.leftBarButtonItem.tintColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0];
  185. UIButton* btn = [UIButton buttonWithType:UIButtonTypeCustom];
  186. btn.frame = CGRectMake(0, 0, 129, 32);
  187. [btn setImage:[UIImage imageNamed:@"apexlogo-2.png"] forState:UIControlStateNormal ];
  188. UIBarButtonItem* aBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
  189. self.navigationItem.leftBarButtonItem = aBarButtonItem;
  190. [self.radioContainer setImage:[UIImage imageNamed:@"unchecked_32.png"] forState:UIControlStateNormal];
  191. [self.radioContainer setImage:[UIImage imageNamed:@"checked_32.png"] forState:UIControlStateSelected];
  192. [self.radioHbol setImage:[UIImage imageNamed:@"unchecked_32.png"] forState:UIControlStateNormal];
  193. [self.radioHbol setImage:[UIImage imageNamed:@"checked_32.png"] forState:UIControlStateSelected];
  194. [[NSNotificationCenter defaultCenter] addObserver:self
  195. selector:@selector(active)
  196. name:UIApplicationDidBecomeActiveNotification object:nil];
  197. [[NSNotificationCenter defaultCenter] addObserver:self
  198. selector:@selector(active)
  199. name:@"new notification" object:nil];
  200. // Do any additional setup after loading the view.
  201. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  202. // bool autologin =[defaults boolForKey:@"autologin"];
  203. // if(!autologin)
  204. // {
  205. // [self performSegueWithIdentifier:@"LOGIN" sender:self];
  206. // }
  207. }
  208. -(void)dealloc
  209. {
  210. [[NSNotificationCenter defaultCenter] removeObserver:self];
  211. }
  212. -(void) active
  213. {
  214. NSLog(@"App active");
  215. long i = [UIApplication sharedApplication].applicationIconBadgeNumber;
  216. if(i>0)
  217. self.messageButton.imageView.image = [UIImage imageNamed:@"ic_message_new"];
  218. else
  219. self.messageButton.imageView.image = [UIImage imageNamed:@"ic_message"];
  220. }
  221. - (void)didReceiveMemoryWarning
  222. {
  223. [super didReceiveMemoryWarning];
  224. // Dispose of any resources that can be recreated.
  225. }
  226. @end