Ray Zhang 12 年 前
コミット
66138c8ec6
52 ファイル変更2993 行追加121 行削除
  1. 1 1
      Apex Mobile/AboutViewController.h
  2. 11 11
      Apex Mobile/AboutViewController.m
  3. 14 0
      Apex Mobile/Apex Mobile/ApexHistoryViewController.h
  4. 58 0
      Apex Mobile/Apex Mobile/ApexHistoryViewController.m
  5. 2 0
      Apex Mobile/Apex Mobile/ApexMobileDB.h
  6. 39 3
      Apex Mobile/Apex Mobile/ApexMobileDB.m
  7. 7 1
      Apex Mobile/Apex Mobile/ApexMobileNetwork.h
  8. 186 37
      Apex Mobile/Apex Mobile/ApexMobileNetwork.m
  9. 15 0
      Apex Mobile/Apex Mobile/CellItemHistory.h
  10. 34 0
      Apex Mobile/Apex Mobile/CellItemHistory.m
  11. 2 0
      Apex Mobile/Apex Mobile/Constant.h
  12. 1 0
      Apex Mobile/Apex Mobile/CustomizeFieldViewController.m
  13. 1 1
      Apex Mobile/Apex Mobile/DetailTabBarController.h
  14. 65 0
      Apex Mobile/Apex Mobile/DetailTabBarController.m
  15. 16 0
      Apex Mobile/Apex Mobile/FavoritesData.h
  16. 70 0
      Apex Mobile/Apex Mobile/FavoritesData.m
  17. 5 2
      Apex Mobile/Apex Mobile/FunctionSelectViewController.h
  18. 71 34
      Apex Mobile/Apex Mobile/FunctionSelectViewController.m
  19. 16 0
      Apex Mobile/Apex Mobile/HistoryData.h
  20. 70 0
      Apex Mobile/Apex Mobile/HistoryData.m
  21. 15 0
      Apex Mobile/Apex Mobile/HistoryTabBarController.h
  22. 150 0
      Apex Mobile/Apex Mobile/HistoryTabBarController.m
  23. 17 0
      Apex Mobile/Apex Mobile/HistoryViewController.h
  24. 112 0
      Apex Mobile/Apex Mobile/HistoryViewController.m
  25. 16 0
      Apex Mobile/Apex Mobile/MyAutocompleteItemsSource.h
  26. 95 0
      Apex Mobile/Apex Mobile/MyAutocompleteItemsSource.m
  27. 26 0
      Apex Mobile/Apex Mobile/MyAutocompleteView.h
  28. 218 0
      Apex Mobile/Apex Mobile/MyAutocompleteView.m
  29. 20 0
      Apex Mobile/Apex Mobile/MyAutocompletionCellFactory.h
  30. 57 0
      Apex Mobile/Apex Mobile/MyAutocompletionCellFactory.m
  31. 18 0
      Apex Mobile/Apex Mobile/MySuggestion.h
  32. 25 0
      Apex Mobile/Apex Mobile/MySuggestion.m
  33. 19 0
      Apex Mobile/Apex Mobile/NewsData.h
  34. 57 0
      Apex Mobile/Apex Mobile/NewsData.m
  35. 18 0
      Apex Mobile/Apex Mobile/NewsTableViewCell.h
  36. 34 0
      Apex Mobile/Apex Mobile/NewsTableViewCell.m
  37. 23 0
      Apex Mobile/Apex Mobile/NewsViewController.h
  38. 251 0
      Apex Mobile/Apex Mobile/NewsViewController.m
  39. 52 0
      Apex Mobile/Apex Mobile/PulldownMenu.h
  40. 457 0
      Apex Mobile/Apex Mobile/PulldownMenu.m
  41. 5 2
      Apex Mobile/Apex Mobile/ResultViewController.h
  42. 188 25
      Apex Mobile/Apex Mobile/ResultViewController.m
  43. 1 1
      Apex Mobile/Apex Mobile/SearchViewController.h
  44. 18 1
      Apex Mobile/Apex Mobile/SearchViewController.m
  45. 13 0
      Apex Mobile/Apex Mobile/SimpleMenu.h
  46. 42 0
      Apex Mobile/Apex Mobile/SimpleMenu.m
  47. 2 2
      Apex Mobile/Apex Mobile/TableCellEdit.h
  48. 20 0
      Apex Mobile/Apex Mobile/ToolsPanelViewController.h
  49. 195 0
      Apex Mobile/Apex Mobile/ToolsPanelViewController.m
  50. 18 0
      Apex Mobile/FavoritesViewController.h
  51. 127 0
      Apex Mobile/FavoritesViewController.m
  52. BIN
      Apex Mobile/GoogleMaps.framework/.DS_Store

+ 1 - 1
Apex Mobile/AboutViewController.h

@@ -9,7 +9,7 @@
 #import <UIKit/UIKit.h>
 
 @interface AboutViewController : UIViewController
-@property (strong, nonatomic) IBOutlet UIWebView *webview;
+//@property (strong, nonatomic) IBOutlet UIWebView *webview;
 //@property (strong, nonatomic) IBOutlet UILabel *verLabel;
 @property (strong, nonatomic) IBOutlet UITextView *infoText;
 

+ 11 - 11
Apex Mobile/AboutViewController.m

@@ -44,11 +44,11 @@
     versionNum = [NSString stringWithFormat:@"A%@",versionNum];
     
     self.infoText.text = [NSString stringWithFormat:@"Version:%@\nSupport:\nusairedadt@united-us.net",versionNum];
- 
-    NSString *filePath = [[NSBundle mainBundle]pathForResource:@"about" ofType:@"htm"];
-    NSString *htmlString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
-    [self.webview loadHTMLString:htmlString baseURL:[NSURL URLWithString:filePath]];
-    
+// 
+//    NSString *filePath = [[NSBundle mainBundle]pathForResource:@"about" ofType:@"htm"];
+//    NSString *htmlString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
+//    [self.webview loadHTMLString:htmlString baseURL:[NSURL URLWithString:filePath]];
+//    
 	// Do any additional setup after loading the view.
 }
 
@@ -57,10 +57,10 @@
     [super didReceiveMemoryWarning];
     // Dispose of any resources that can be recreated.
 }
-- (void)webViewDidFinishLoad:(UIWebView *)webView
-{
-    // finished loading, hide the activity indicator in the status bar
-    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
-    [self.webview stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '350%'"];
-}
+//- (void)webViewDidFinishLoad:(UIWebView *)webView
+//{
+//    // finished loading, hide the activity indicator in the status bar
+//    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
+//    [self.webview stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '350%'"];
+//}
 @end

+ 14 - 0
Apex Mobile/Apex Mobile/ApexHistoryViewController.h

@@ -0,0 +1,14 @@
+//
+//  ApexHistoryViewController.h
+//  Apex Mobile
+//
+//  Created by Ray on 14-4-22.
+//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface ApexHistoryViewController : UIViewController
+@property (strong, nonatomic) IBOutlet UIWebView *webview;
+
+@end

+ 58 - 0
Apex Mobile/Apex Mobile/ApexHistoryViewController.m

@@ -0,0 +1,58 @@
+//
+//  ApexHistoryViewController.m
+//  Apex Mobile
+//
+//  Created by Ray on 14-4-22.
+//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
+//
+
+#import "ApexHistoryViewController.h"
+
+@interface ApexHistoryViewController ()
+
+@end
+
+@implementation ApexHistoryViewController
+
+- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
+{
+    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
+    if (self) {
+        // Custom initialization
+    }
+    return self;
+}
+
+- (void)viewDidLoad
+{
+    [super viewDidLoad];
+    NSString *filePath = [[NSBundle mainBundle]pathForResource:@"about" ofType:@"htm"];
+    NSString *htmlString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
+    [self.webview loadHTMLString:htmlString baseURL:[NSURL URLWithString:filePath]];
+}
+
+- (void)didReceiveMemoryWarning
+{
+    [super didReceiveMemoryWarning];
+    // Dispose of any resources that can be recreated.
+}
+
+//- (void)webViewDidFinishLoad:(UIWebView *)webView
+//{
+//    // finished loading, hide the activity indicator in the status bar
+//    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
+//    [self.webview stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '350%'"];
+//}
+
+/*
+#pragma mark - Navigation
+
+// In a storyboard-based application, you will often want to do a little preparation before navigation
+- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
+{
+    // Get the new view controller using [segue destinationViewController].
+    // Pass the selected object to the new view controller.
+}
+*/
+
+@end

+ 2 - 0
Apex Mobile/Apex Mobile/ApexMobileDB.h

@@ -16,6 +16,8 @@
 + (BOOL) initializeDb;
 + (sqlite3*) get_db;
 +(void)execSql:(NSString *)sql db:(sqlite3 *)db;
+
 + (int) get_recordid:(sqlite3*)db table:(NSString*) tablename where:(NSString*) whereclause order:(NSString*) orderby;
 + (int) get_recordid:(sqlite3*)db table:(NSString*) tablename where:(NSString*) whereclause;
++(BOOL)checkForField:(NSString *)table field:(NSString *)field db:(sqlite3 *)db;
 @end

+ 39 - 3
Apex Mobile/Apex Mobile/ApexMobileDB.m

@@ -64,9 +64,30 @@
     if (sqlite3_exec(db, [sql UTF8String], NULL, NULL, &err) != SQLITE_OK) {
         sqlite3_close(db);
          DebugLog(@"sqlite3_exec failed msg:%s",sqlite3_errmsg(db));
+        DebugLog(@"sqlite3_exec failed sql:%@",sql);
+
     }
 }
++(BOOL)checkForField:(NSString *)table field:(NSString *)field db:(sqlite3 *)db
+{
 
+    sqlite3_stmt *stmt;
+        NSString *sql = [NSString stringWithFormat:@"PRAGMA table_info(%@)",table];
+    if (sqlite3_prepare_v2(db, [sql UTF8String], -1, &stmt, NULL) != SQLITE_OK)
+    {
+        return NO;
+    }
+    
+    while(sqlite3_step(stmt) == SQLITE_ROW)
+    {
+        
+        NSString *fieldName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(stmt, 1)];
+        if([field isEqualToString:fieldName])
+            return YES;
+    }
+    
+    return NO;
+}
 + (BOOL) initializeDb {
      DebugLog (@"initializeDB");
     
@@ -91,7 +112,7 @@
     
     sqlite3 *db;  
   
-    if (! [[NSFileManager defaultManager] fileExistsAtPath: database_path])
+    if (true)//! [[NSFileManager defaultManager] fileExistsAtPath: database_path])
     {
         
         if (sqlite3_open([database_path UTF8String], &db) != SQLITE_OK) {
@@ -100,14 +121,29 @@
             return NO;
         }
         NSString *create_actions_info = @"CREATE TABLE IF NOT EXISTS actions_info (_id integer PRIMARY KEY,name varchar(20),function_name varchar(20),priority integer,abandon boolean,user varchar(20));";
-         NSString *create_fields_info = @"CREATE TABLE IF NOT EXISTS fields_info (_id integer PRIMARY KEY,name varchar(20),aname varchar(20),field_type integer,function_name varchar(20),behavior integer,priority integer,show boolean,abandon boolean,user varchar(20));";
-        NSString *create_search_history = @"CREATE TABLE IF NOT EXISTS search_history (_id integer PRIMARY KEY,h_val varchar(20),h_field varchar(20),h_time timestamp,user varchar(20));";
+       
+        NSString *create_fields_info = @"CREATE TABLE IF NOT EXISTS fields_info (_id integer PRIMARY KEY,name varchar(20),aname varchar(20),field_type integer,function_name varchar(20),behavior integer,priority integer,show boolean,abandon boolean,user varchar(20));";
+        
+        NSString *create_search_history = @"CREATE TABLE IF NOT EXISTS search_history (_id integer PRIMARY KEY,h_val varchar(20),h_field varchar(20),h_time timestamp default (datetime('now', 'localtime')),user varchar(20));";
+     
+        NSString* create_push_message =@"CREATE TABLE IF NOT EXISTS push_message (_id INTEGER PRIMARY KEY, s_id VARCHAR(20), e_id VARCHAR(20), msgcount INTEGER, message VARCHAR(20), h_time timestamp default (datetime('now', 'localtime')), create_time timestamp default (datetime('now', 'localtime')), user VARCHAR(20), read BOOLEAN);";
         
+		NSString* create_favorites =@"CREATE TABLE IF NOT EXISTS favorites (_id INTEGER PRIMARY KEY, name VARCHAR(20), params VARCHAR(20), action VARCHAR(20), module_name VARCHAR(20), create_time timestamp default (datetime('now', 'localtime')), user VARCHAR(20));";
+		NSString* create_history=@"CREATE TABLE IF NOT EXISTS history ( _id INTEGER PRIMARY KEY, name VARCHAR(20), params VARCHAR(20), action VARCHAR(20), module_name VARCHAR(20), create_time timestamp default (datetime('now', 'localtime')), user VARCHAR(20));";
         
 //        CREATE TABLE users (_id integer PRIMARY KEY,name varchar(20),pass varchar(20));
         [self execSql:create_actions_info db:db];
         [self execSql:create_fields_info db:db];
         [self execSql:create_search_history db:db];
+        [self execSql:create_push_message db:db];
+        [self execSql:create_favorites db:db];
+        [self execSql:create_history db:db];
+       
+       if( ![self checkForField:@"search_history" field:@"level" db:db])
+       {
+        NSString* alter_search_history = @"ALTER TABLE search_history ADD level INTEGER";
+            [self execSql:alter_search_history db:db];
+       }
         sqlite3_close(db);
     }
     return YES;

+ 7 - 1
Apex Mobile/Apex Mobile/ApexMobileNetwork.h

@@ -7,7 +7,7 @@
 //
 
 #import <Foundation/Foundation.h>
-#import <sqlite3.h> 
+#import <sqlite3.h>
 #import "ApexMobileAppDelegate.h"
 #import "ApexMobileDB.h"
 #import "Constant.h"
@@ -16,9 +16,15 @@
 #import "DetailContent.h"
 
 @interface ApexMobileNetwork : NSObject
++(void)Logout ;
 +(int)Authorize : (NSString*) user password:(NSString*) password ;
 +(int)parse_authinfo : (NSData *) json user:(NSString*) user password:(NSString*) password;
 +(NSData*)get_json : (NSString*) url parameters:(NSMutableDictionary *) params;// delegate:(id < NSURLConnectionDelegate >)delegate;
+//+(int) get_announcements: (NSString*)lastid limit:int limit ;//delegate:(id < NSURLConnectionDelegate >)delegate;
+
++(NSData*)get_announcements : (NSString*) id limit: (int) limit ;
++(NSData*)get_marketnews : (NSString*) id limit: (int) limit ;
++(void)post_without_return : (NSString*) url parameters:(NSMutableDictionary *) params;
 +(int) get_recordcount: (NSMutableDictionary *) params ;//delegate:(id < NSURLConnectionDelegate >)delegate;
 +(PageData*) get_pagedata: (NSMutableDictionary *) params;
 +(DetailContent*) get_detailcontent: (NSMutableDictionary *) params;

+ 186 - 37
Apex Mobile/Apex Mobile/ApexMobileNetwork.m

@@ -6,7 +6,7 @@
 //  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
 //
 
- 
+
 
 
 #import "ApexMobileNetwork.h"
@@ -27,7 +27,7 @@
         return RESULT_NET_NOTAVAILABLE;
     
     ApexMobileAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
-
+    
     
     NSMutableDictionary * params = [[NSMutableDictionary alloc] init];
     [params setValue:user forKey:@"user"];
@@ -37,11 +37,11 @@
     [params setValue:@"handset_search" forKey:@"action"];
     [params setValue:appDelegate.sessionid forKey:@"sessionid"];
     NSData* json=[ApexMobileNetwork get_json:URL_RETRIEVE_PASS parameters:params];
-
+    
     
     if (json==nil)
     {
-          DebugLog(@"json is wrong");
+        DebugLog(@"json is wrong");
         return RESULT_NET_ERROR;
     }
     
@@ -52,7 +52,7 @@
         int result = [[jsobj valueForKey:@"result"] intValue];
         if(result!=AP_USER_AUTH)
         {
-              DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
+            DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
             return RESULT_FALSE;
             
         }
@@ -60,8 +60,8 @@
         
     }
     return RESULT_NET_ERROR;
-
-
+    
+    
 }
 +(int) RetrievePassword : (NSString*) user  email:(NSString*) email
 {
@@ -76,7 +76,7 @@
     NSData* json=[ApexMobileNetwork get_json:URL_RETRIEVE_PASS parameters:params];
     if (json==nil)
     {
-          DebugLog(@"json is wrong");
+        DebugLog(@"json is wrong");
         return RESULT_NET_ERROR;
     }
     
@@ -87,20 +87,20 @@
         int result = [[jsobj valueForKey:@"result"] intValue];
         if(result!=AP_USER_AUTH)
         {
-              DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
+            DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
             return RESULT_FALSE;
             
         }
         return RESULT_TRUE;
         
-     }
+    }
     return RESULT_NET_ERROR;
     
- 
+    
 }
 +(int)parse_authinfo : (NSData *) json user:(NSString*) user password:(NSString*) password
 {
-      DebugLog(@"parse_authinfo");
+    DebugLog(@"parse_authinfo");
     NSError *error=nil;
     
     sqlite3 *db =[ApexMobileDB get_db];
@@ -114,14 +114,14 @@
         int result = [[jsobj valueForKey:@"result"] intValue];
         if(result!=AP_USER_AUTH)
         {
-              DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
+            DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
             return RESULT_FALSE;
             
         }
         NSDictionary* objheader = [jsobj objectForKey:@"header"];
         ApexMobileAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
         NSString* required_ver=[objheader objectForKey:@"client_ver"] ;
-          DebugLog(@"required_ver=%@ ",required_ver);
+        DebugLog(@"required_ver=%@ ",required_ver);
         NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
         NSString* versionNum =[infoDict objectForKey:@"CFBundleVersion"];
         versionNum = [NSString stringWithFormat:@"A%@",versionNum];
@@ -132,7 +132,7 @@
         appDelegate.sessionid = [objheader valueForKey:@"sessionid"];
         appDelegate.user = user;
         appDelegate.password = password;
-          DebugLog(@"sessionid=%@ ",appDelegate.sessionid);
+        DebugLog(@"sessionid=%@ ",appDelegate.sessionid);
         if ([[objheader valueForKey:@"update"] boolValue]==false)
         {
             // no update on the server;
@@ -297,7 +297,7 @@
 }
 +(DetailContent*) get_detailcontent: (NSMutableDictionary *) params
 {
-      DebugLog(@"get_detailcontent");
+    DebugLog(@"get_detailcontent");
     DetailContent * detailContent = [[DetailContent alloc] init];
     NSMutableArray* segments = [[NSMutableArray alloc] init];
     detailContent.segments = segments;
@@ -307,12 +307,12 @@
         return detailContent;
     }
     ApexMobileAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
-//    [params setValue:@"handset_search" forKey:@"action"];
+    //    [params setValue:@"handset_search" forKey:@"action"];
     [params setValue:appDelegate.sessionid forKey:@"sessionid"];
     NSData* json=[ApexMobileNetwork get_json:URL_REQUEST_RECORDS parameters:params];
     if (json==nil)
     {
-          DebugLog(@"json is wrong");
+        DebugLog(@"json is wrong");
         detailContent.result_code = RESULT_NET_ERROR;
         return detailContent;
     }
@@ -324,7 +324,7 @@
         int result = [[jsobj valueForKey:@"result"] intValue];
         if(result!=AP_USER_AUTH)
         {
-              DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
+            DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
             detailContent.result_code = result;
             return detailContent;
             
@@ -337,7 +337,7 @@
             
             return detailContent;
         }
-
+        
         for(int i=0;i<count;i++)
         {
             
@@ -361,8 +361,8 @@
         
         //   NSDictionary* objrecords = [jsobj objectForKey:@"records"];
         
-
-
+        
+        
         return detailContent;
         
     }
@@ -372,7 +372,7 @@
 +(PageData*) get_pagedata: (NSMutableDictionary *) params
 {
     
-      DebugLog(@"get_pagedata");
+    DebugLog(@"get_pagedata");
     if(![ApexMobileNetwork IsNetworkAvailable])
         return nil;
     ApexMobileAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
@@ -381,7 +381,7 @@
     NSData* json=[ApexMobileNetwork get_json:URL_REQUEST_RECORDS parameters:params];
     if (json==nil)
     {
-          DebugLog(@"json is wrong");
+        DebugLog(@"json is wrong");
         return nil;
     }
     
@@ -392,7 +392,7 @@
         int result = [[jsobj valueForKey:@"result"] intValue];
         if(result!=AP_USER_AUTH)
         {
-              DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
+            DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
             return nil;
             
         }
@@ -408,7 +408,7 @@
 }
 +(int) get_recordcount: (NSMutableDictionary *) params// delegate:(id < NSURLConnectionDelegate >)delegate
 {
-      DebugLog(@"get_recordcount");
+    DebugLog(@"get_recordcount");
     if(![ApexMobileNetwork IsNetworkAvailable])
         return -1;
     ApexMobileAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
@@ -418,7 +418,7 @@
     NSData* json=[ApexMobileNetwork get_json:URL_REQUEST_COUNT parameters:params];
     if (json==nil)
     {
-          DebugLog(@"json is wrong");
+        DebugLog(@"json is wrong");
         return RESULT_NET_ERROR;
     }
     
@@ -429,7 +429,7 @@
         int result = [[jsobj valueForKey:@"result"] intValue];
         if(result!=AP_USER_AUTH)
         {
-              DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
+            DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
             return RESULT_FALSE;
             
         }
@@ -456,6 +456,141 @@
     return true;
 }
 
++(void)post_without_return : (NSString*) url parameters:(NSMutableDictionary *) params //delegate:(id < NSURLConnectionDelegate >)delegate
+{
+    ApexMobileAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
+    //分界线的标识符
+    NSString *TWITTERFON_FORM_BOUNDARY = @"AaB03x";
+    //根据url初始化request
+    NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]
+                                                           cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
+                                                       timeoutInterval:30];
+    //分界线 --AaB03x
+    NSString *MPboundary=[[NSString alloc]initWithFormat:@"--%@",TWITTERFON_FORM_BOUNDARY];
+    //结束符 AaB03x--
+    NSString *endMPboundary=[[NSString alloc]initWithFormat:@"%@--",MPboundary];
+    //要上传的图片
+    //    UIImage *image=[params objectForKey:@"pic"];
+    //得到图片的data
+    //    NSData* data = UIImagePNGRepresentation(image);
+    //http body的字符串
+    NSMutableString *body=[[NSMutableString alloc]init];
+    
+    //    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
+    //     [params setValue:@"handset_login" forKey:@"action"];
+    //    [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
+    
+    [params setValue:appDelegate.sessionid forKey:@"sessionid"];
+    //   [params setValue:password forKey:@"password"];
+    //    [params setValue:[NSString stringWithFormat:@"%d",ver]  forKey:@"auth_ver"];
+    
+    
+    
+    //    [headers setValue:headQuerlString forKey:@"param"];
+    
+    //参数的集合的所有key的集合
+    NSArray *keys= [params allKeys];
+    DebugLog(@"================parms==================");
+    //遍历keys
+    for(int i=0;i<[keys count];i++)
+    {
+        //得到当前key
+        NSString *key=[keys objectAtIndex:i];
+        //如果key不是pic,说明value是字符类型,比如name:Boris
+        if(![key isEqualToString:@"pic"])
+        {
+            //添加分界线,换行
+            [body appendFormat:@"%@\r\n",MPboundary];
+            //添加字段名称,换2行
+            [body appendFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n",key];
+            //添加字段的值
+            [body appendFormat:@"%@\r\n",[params objectForKey:key]];
+            DebugLog(@"parameter: key=%@   value=%@",key,[params objectForKey:key]);
+        }
+    }
+    DebugLog(@"================parms==================");
+    ////添加分界线,换行
+    [body appendFormat:@"%@\r\n",MPboundary];
+    //声明pic字段,文件名为boris.png
+    [body appendFormat:@"Content-Disposition: form-data; name=\"pic\"; filename=\"boris.png\"\r\n"];
+    //声明上传文件的格式
+    [body appendFormat:@"Content-Type: image/png\r\n\r\n"];
+    
+    //声明结束符:--AaB03x--
+    NSString *end=[[NSString alloc]initWithFormat:@"\r\n%@",endMPboundary];
+    //声明myRequestData,用来放入http body
+    NSMutableData *myRequestData=[NSMutableData data];
+    //将body字符串转化为UTF8格式的二进制
+    [myRequestData appendData:[body dataUsingEncoding:NSUTF8StringEncoding]];
+    //将image的data加入
+    //    [myRequestData appendData:data];
+    //加入结束符--AaB03x--
+    [myRequestData appendData:[end dataUsingEncoding:NSUTF8StringEncoding]];
+    
+    //设置HTTPHeader中Content-Type的值
+    NSString *content=[[NSString alloc]initWithFormat:@"multipart/form-data; boundary=%@",TWITTERFON_FORM_BOUNDARY];
+    //设置HTTPHeader
+    [request setValue:content forHTTPHeaderField:@"Content-Type"];
+    //设置Content-Length
+    [request setValue:[NSString stringWithFormat:@"%lu", (unsigned long)[myRequestData length]] forHTTPHeaderField:@"Content-Length"];
+    //设置http body
+    [request setHTTPBody:myRequestData];
+    //http method
+    [request setHTTPMethod:@"POST"];
+    
+    
+    NSHTTPURLResponse* urlResponse = nil;
+    
+    NSError *error = [[NSError alloc] init];
+    
+    [NSURLConnection sendAsynchronousRequest:request queue:nil completionHandler:^(NSURLResponse *response,NSData *data,NSError *error){}];
+//    NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:request delegate:nil];
+
+    
+    
+}
++(NSData*)get_marketnews : (NSString*) id limit: (int) limit
+{
+    NSString* ret = nil;
+    
+    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
+    [params setValue:@"Market News" forKey:@"module_name"];
+    [params setValue:@"search" forKey:@"action_type"];
+    [params setValue:id forKey:@"id"];
+    [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
+    
+    NSData* json=[ApexMobileNetwork get_json:URL_ANNOUNCEMENTS parameters:params];
+    if (json==nil)
+    {
+        DebugLog(@"json is wrong");
+        return nil;
+    }
+    return json;
+    
+    
+    
+}
++(NSData*)get_announcements : (NSString*) id limit: (int) limit
+{
+    NSString* ret = nil;
+    
+    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
+    [params setValue:@"Announcements" forKey:@"module_name"];
+[params setValue:@"search" forKey:@"action_type"];
+    [params setValue:id forKey:@"id"];
+    [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
+    
+    NSData* json=[ApexMobileNetwork get_json:URL_ANNOUNCEMENTS parameters:params];
+    if (json==nil)
+    {
+        DebugLog(@"json is wrong");
+        return nil;
+    }
+    return json;
+
+
+    
+}
 +(NSData*)get_json : (NSString*) url parameters:(NSMutableDictionary *) params //delegate:(id < NSURLConnectionDelegate >)delegate
 {
     ApexMobileAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
@@ -490,7 +625,7 @@
     
     //参数的集合的所有key的集合
     NSArray *keys= [params allKeys];
-      DebugLog(@"================parms==================");
+    DebugLog(@"================parms==================");
     //遍历keys
     for(int i=0;i<[keys count];i++)
     {
@@ -505,10 +640,10 @@
             [body appendFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n",key];
             //添加字段的值
             [body appendFormat:@"%@\r\n",[params objectForKey:key]];
-              DebugLog(@"parameter: key=%@   value=%@",key,[params objectForKey:key]);
+            DebugLog(@"parameter: key=%@   value=%@",key,[params objectForKey:key]);
         }
     }
-      DebugLog(@"================parms==================");
+    DebugLog(@"================parms==================");
     ////添加分界线,换行
     [body appendFormat:@"%@\r\n",MPboundary];
     //声明pic字段,文件名为boris.png
@@ -545,36 +680,50 @@
     
     NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
     
-      DebugLog(@"response: %@",[NSHTTPURLResponse localizedStringForStatusCode:urlResponse.statusCode]);
+    DebugLog(@"response: %@",[NSHTTPURLResponse localizedStringForStatusCode:urlResponse.statusCode]);
     
     if (responseData==nil) {
         
-          DebugLog(@"move failed:%@", [error localizedDescription]);
+        DebugLog(@"move failed:%@", [error localizedDescription]);
     }
     else
     {
         NSMutableString *result = [[NSMutableString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
         
-          DebugLog(@"result: %@",result);
+        DebugLog(@"result: %@",result);
         
         
     }
     return responseData;
     
 }
++(void)Logout
+{
+    if(![ApexMobileNetwork IsNetworkAvailable])
+        return ;//RESULT_NET_NOTAVAILABLE;
+    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
+    ApexMobileAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
+    if(appDelegate.duid !=nil)
+        [params setValue:appDelegate.duid forKey:@"udid"];
+    [params setValue:@"handset_logout" forKey:@"action"];
 
+    [ApexMobileNetwork post_without_return :URL_UPDATE_AUTH parameters:params];
+}
 +(int)Authorize : (NSString*) user password:(NSString*) password{
     
     if(![ApexMobileNetwork IsNetworkAvailable])
         return RESULT_NET_NOTAVAILABLE;
-//    if(![ApexMobileNetwork IsHostAvailable:URL_UPDATE_AUTH])
-//        return RESULT_NET_ERROR;
+    //    if(![ApexMobileNetwork IsHostAvailable:URL_UPDATE_AUTH])
+    //        return RESULT_NET_ERROR;
     NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
     long ver =[defaults integerForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
     
     
     
     NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
+    ApexMobileAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
+    if(appDelegate.duid !=nil)
+        [params setValue:appDelegate.duid forKey:@"udid"];
     [params setValue:@"handset_login" forKey:@"action"];
     //    [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
     
@@ -586,7 +735,7 @@
         return RESULT_NET_ERROR;
     
     int ret = [ApexMobileNetwork parse_authinfo:json user:user password:password];
-      DebugLog(@"parse_authinfo return %d ",ret);
+    DebugLog(@"parse_authinfo return %d ",ret);
     
     
     return ret;

+ 15 - 0
Apex Mobile/Apex Mobile/CellItemHistory.h

@@ -0,0 +1,15 @@
+//
+//  CellItemHistory.h
+//  Apex Mobile
+//
+//  Created by Ray on 14-4-24.
+//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface CellItemHistory : UITableViewCell
+@property (strong, nonatomic) IBOutlet UILabel *name;
+@property (strong, nonatomic) IBOutlet UILabel *time;
+
+@end

+ 34 - 0
Apex Mobile/Apex Mobile/CellItemHistory.m

@@ -0,0 +1,34 @@
+//
+//  CellItemHistory.m
+//  Apex Mobile
+//
+//  Created by Ray on 14-4-24.
+//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
+//
+
+#import "CellItemHistory.h"
+
+@implementation CellItemHistory
+
+- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
+{
+    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
+    if (self) {
+        // Initialization code
+    }
+    return self;
+}
+
+- (void)awakeFromNib
+{
+    // Initialization code
+}
+
+- (void)setSelected:(BOOL)selected animated:(BOOL)animated
+{
+    [super setSelected:selected animated:animated];
+
+    // Configure the view for the selected state
+}
+
+@end

+ 2 - 0
Apex Mobile/Apex Mobile/Constant.h

@@ -22,6 +22,8 @@
 #define URL_REQUEST_RECORDS @"https://ra.apexshipping.com/main.php"
 #define URL_RETRIEVE_PASS @"https://ra.apexshipping.com/main.php"
 #define URL_REQUEST_DETAIL @"https://ra.apexshipping.com/main.php"
+#define URL_ANNOUNCEMENTS @"https://ra.apexshipping.com/mobile_news.php"
+#define URL_NEWS	@"https://ra.apexshipping.com/mobile_news.php"
 #define COLOR(R,G,B,A) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:A]
 extern const int MAX_ROW;
 extern const int MAX_COLUMN;

+ 1 - 0
Apex Mobile/Apex Mobile/CustomizeFieldViewController.m

@@ -331,6 +331,7 @@
         aname = self.hidefields[indexPath.row];
     cell.textLabel.text = aname;
  
+    
     return cell;
     
     

+ 1 - 1
Apex Mobile/Apex Mobile/DetailTabBarController.h

@@ -11,7 +11,7 @@
 #import "SearchViewController.h"
 #import "Constant.h"
 
-@interface DetailTabBarController : UITabBarController
+@interface DetailTabBarController : UITabBarController<UIAlertViewDelegate>
 @property (strong,nonatomic) NSString* function_name;
 @property (strong,nonatomic) NSMutableDictionary* params;
 @property (strong,nonatomic) NSArray * actions;

+ 65 - 0
Apex Mobile/Apex Mobile/DetailTabBarController.m

@@ -151,10 +151,75 @@
     return self;
 }
 
+- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
+{
+    
+    if(buttonIndex!=alertView.cancelButtonIndex)
+    {
+        UITextField * txt=[alertView textFieldAtIndex:0];
+        NSString* name = txt.text;
+        NSString * actions = [self.actions componentsJoinedByString:@","];
+//        NSString* param = [self.params description];
+        
+        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self.params
+                                                           options:0
+                                                             error:nil];
+        NSString* param = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
+//        NSData *myData = [NSKeyedArchiver archivedDataWithRootObject:self.params];
+//        
+//        NSString* param = [[NSString alloc] initWithData:myData
+//                                                encoding:NSUTF8StringEncoding];
+        ApexMobileAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
+        NSString* user = appDelegate.user;
+        
+        sqlite3 *db =[ApexMobileDB get_db];
+        
+        [ApexMobileDB execSql: [NSString stringWithFormat: @"insert into favorites(params,name,module_name,user,action) values('%@','%@','%@','%@','%@')",param,name,self.function_name,user,actions] db:db];
+        
+        sqlite3_close(db);
+        
+     
+        
+    }
+    
+    
+}
+
+-(void)saveDetail:(UIBarButtonItem*)sender
+{
+    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Create a tag to save" message:@"You can find saved Detail at tools->Save Detail/Search" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Save",nil];
+    alert.alertViewStyle = UIAlertViewStylePlainTextInput;
+    
+    UITextField * txt = [[UITextField alloc] init];
+    
+    txt.backgroundColor = [UIColor yellowColor];
+    
+    txt.frame = CGRectMake(alert.center.x+65,alert.center.y+48, 150,23);
+    //        [alert addSubview:txt];
+    [alert show];
+}
+
 - (void)viewDidLoad
 {
     [super viewDidLoad];
+    UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithTitle:@"Save" style:UIBarButtonItemStylePlain target:self action:@selector(saveDetail:)];
+    saveButton.title = @"Save";
+    
+    self.navigationItem.rightBarButtonItem = saveButton;
+    
+    // self.navigationController.view.frame.size.height;
     
+    //    NSMutableArray * items = [[NSMutableArray alloc]init];
+    //    UIBarButtonItem *item1 = [[UIBarButtonItem alloc] init];
+    //    item1.title = @"item1";
+    //    item1.image = [UIImage imageNamed:@"rect_setting"];
+    //    UIBarButtonItem *item2 = [[UIBarButtonItem alloc] init];
+    //    item2.image = [UIImage imageNamed:@"rect_about"];
+    //    item2.title = @"item2";
+    //    [items addObject:item1];
+    //    [items addObject:item2];
+    //    self.navigationItem.rightBarButtonItems=items;
+//    self.navigationItem.backBarButtonItem = backButton;
 
 
 }

+ 16 - 0
Apex Mobile/Apex Mobile/FavoritesData.h

@@ -0,0 +1,16 @@
+//
+//  FavoritesData.h
+//  Apex Mobile
+//
+//  Created by Ray on 14-4-25.
+//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import <sqlite3.h>
+#import "ApexMobileDB.h"
+#import "ApexMobileAppDelegate.h"
+@interface FavoritesData : NSObject
+@property (strong,nonatomic) NSMutableArray* pagedata;
+-(long) get_count;
+@end

+ 70 - 0
Apex Mobile/Apex Mobile/FavoritesData.m

@@ -0,0 +1,70 @@
+//
+//  FavoritesData.m
+//  Apex Mobile
+//
+//  Created by Ray on 14-4-25.
+//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
+//
+
+#import "FavoritesData.h"
+
+@implementation FavoritesData
+
+-(long) get_count
+{
+    return self.pagedata.count;
+}
+
+- (id)init
+{
+    self = [super init];
+    if (self) {
+        self.pagedata =[[NSMutableArray alloc]init];
+        
+        ApexMobileAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
+        //    NSString* required_ver=[objheader objectForKey:@"client_ver"] ;
+        //
+        //    appDelegate.sessionid = [objheader valueForKey:@"sessionid"];
+        //    appDelegate.user = user;
+        //    appDelegate.password = password;
+        
+        sqlite3 *db =[ApexMobileDB get_db];
+        NSString *quary = [NSString stringWithFormat:@"select _id,create_time,params,module_name,action,name from favorites where user='%@' order by _id desc",appDelegate.user];
+        
+        
+        
+        sqlite3_stmt *stmt;
+        if (sqlite3_prepare_v2(db, [quary UTF8String], -1, &stmt, nil) == SQLITE_OK) {
+            DebugLog(@"sql:%@",quary);
+            while (sqlite3_step(stmt)==SQLITE_ROW)
+            {
+                //                NSString *aname = [[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(stmt, 0)];
+                int _id = sqlite3_column_int(stmt, 0);
+                //                NSString* str_time = sqlite3
+                NSString* create_time = [NSString stringWithUTF8String:(char *)sqlite3_column_text(stmt, 1)];
+                NSString* params =[NSString stringWithUTF8String:(char *)sqlite3_column_text(stmt, 2)];
+                NSString* module_name =[NSString stringWithUTF8String:(char *)sqlite3_column_text(stmt, 3)];
+                NSString* action =[NSString stringWithUTF8String:(char *)sqlite3_column_text(stmt, 4)];
+                NSString* name =[NSString stringWithUTF8String:(char *)sqlite3_column_text(stmt, 5)];
+                NSMutableDictionary * map = [[NSMutableDictionary alloc] init];
+                [map setValue:[NSString stringWithFormat:@"%d",_id] forKey:@"_id"];
+                [map setValue:[NSString stringWithFormat:create_time,create_time] forKey:@"create_time"];
+                [map setValue:params forKey:@"params"];
+                [map setValue:module_name forKey:@"module_name"];
+                [map setValue:name forKey:@"name"];
+                [map setValue:action forKey:@"action"];
+                
+                [self.pagedata addObject:map];
+                
+                
+            }
+            
+            sqlite3_finalize(stmt);
+        }
+        //用完了一定记得关闭,释放内存
+        sqlite3_close(db);
+        
+    }
+    return self;
+}
+@end

+ 5 - 2
Apex Mobile/Apex Mobile/FunctionSelectViewController.h

@@ -9,11 +9,14 @@
 #import <UIKit/UIKit.h>
 #import "SearchViewController.h"
 #import "DetailTabBarController.h"
-
+#import "ToolsPanelViewController.h"
+#import "MyAutocompleteView.h"
+#import "MyAutocompleteItemsSource.h"
+#import "MyAutocompletionCellFactory.h"
 @interface FunctionSelectViewController : UIViewController<UITextFieldDelegate>
 @property (strong,nonatomic) NSString * content;
 @property (strong, nonatomic) IBOutlet UIButton *radioHbol;
 @property (strong, nonatomic) IBOutlet UIButton *radioContainer;
 @property (strong, nonatomic) IBOutlet UITextField *edit;
-
+@property (strong,nonatomic) MyAutocompleteView * autocompleteView;
 @end

+ 71 - 34
Apex Mobile/Apex Mobile/FunctionSelectViewController.m

@@ -5,7 +5,7 @@
 //  Created by Ray on 14-2-25.
 //  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
 //
- 
+
 #import "FunctionSelectViewController.h"
 
 @interface FunctionSelectViewController ()
@@ -24,8 +24,8 @@
 }
 - (IBAction)onButtonClick:(UIButton *)sender {
     
-     DebugLog(@"onButtonClick%@",sender.restorationIdentifier);
-//    sender.restorationIdentifier
+    DebugLog(@"onButtonClick%@",sender.restorationIdentifier);
+    //    sender.restorationIdentifier
     
     
     
@@ -52,13 +52,20 @@
     SearchViewController *searchViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SearchViewController"];
     searchViewController.function_name = function_name;
     [self.navigationController pushViewController:searchViewController animated:YES];
-
+    
     
 }
 - (BOOL)shouldAutorotate
 {
     return YES;
 }
+- (IBAction)onToolsClick:(UIButton *)sender {
+    
+    ToolsPanelViewController *toolsViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"ToolsPanel"];
+    toolsViewController.showNavigation = true;
+    [self.navigationController pushViewController:toolsViewController animated:YES];
+    
+}
 - (IBAction)onResetClick:(UIButton *)sender {
     self.edit.text=@"";
 }
@@ -87,39 +94,44 @@
     DetailTabBarController *detailViewController=[[DetailTabBarController alloc] init:@"Cargo Tracking" actions:[NSArray arrayWithObjects:@"Tracking",nil] params:params];
     [self.navigationController pushViewController:detailViewController animated:YES];
     
-
-/*
- 
- Intent intent = new Intent();
- intent.setClass(this, DetailActivity.class);
- 
- intent.putExtra("action0", );
- intent.putExtra("function_name", );
- 
- intent.putExtra("cargo_criterion", cargo_criterion);
- intent.putExtra("actions_count", 1);
- intent.putExtra("_id", "dumb");
- String h_field;
- RadioGroup rg = (RadioGroup) findViewById(R.id.radioGroup1);
- if (rg.getCheckedRadioButtonId() == R.id.radio0)
- {
- intent.putExtra("criterion_type", 0);
- h_field = "hbol";
- }
- else
- {
- intent.putExtra("criterion_type", 1);
- h_field = "container_no";
- }
- String user = ApexTrackingApplication.get_user();
-
- startActivity(intent);
- */
+    
+    /*
+     
+     Intent intent = new Intent();
+     intent.setClass(this, DetailActivity.class);
+     
+     intent.putExtra("action0", );
+     intent.putExtra("function_name", );
+     
+     intent.putExtra("cargo_criterion", cargo_criterion);
+     intent.putExtra("actions_count", 1);
+     intent.putExtra("_id", "dumb");
+     String h_field;
+     RadioGroup rg = (RadioGroup) findViewById(R.id.radioGroup1);
+     if (rg.getCheckedRadioButtonId() == R.id.radio0)
+     {
+     intent.putExtra("criterion_type", 0);
+     h_field = "hbol";
+     }
+     else
+     {
+     intent.putExtra("criterion_type", 1);
+     h_field = "container_no";
+     }
+     String user = ApexTrackingApplication.get_user();
+     
+     startActivity(intent);
+     */
     
     
 }
 - (IBAction)onExit:(UIButton *)sender {
-    exit(0);
+    ApexMobileAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
+    [appDelegate Logout];
+    [self performSegueWithIdentifier:@"LOGIN" sender:self];
+
+    
+   // exit(0);
 }
 -(BOOL)textFieldShouldReturn:(UITextField *)textField {
     
@@ -139,7 +151,24 @@
 {
     return UIInterfaceOrientationPortrait;
 }
-
+-(void)viewWillAppear:(BOOL)animated
+{
+    self.autocompleteView = [MyAutocompleteView autocompleteViewBindedTo:self.edit
+                                                             usingSource:[[MyAutocompleteItemsSource alloc]
+                                                                          initWithMinimumCharactersToTrigger:1
+                                                                          ]
+                                                             cellFactory:[[MyAutocompletionCellFactory alloc]
+                                                                          initWithCellTextColor:[UIColor blackColor]
+                                                                          fontSize:14]
+                                                            presentingIn:self];
+    self.autocompleteView.topMargin = 0;
+    //    self.autocompleteView.backgroundColor = [UIColor ui];
+    
+    self.autocompleteView.didAutocompleteWith = ^(MySuggestion* item)
+    {
+        NSLog(@"Autocompleted with: %@",  item.completionText);
+    };
+}
 - (void)viewDidLoad
 {
     [super viewDidLoad];
@@ -157,6 +186,14 @@
     [self.radioHbol setImage:[UIImage imageNamed:@"unchecked_32.png"] forState:UIControlStateNormal];
     [self.radioHbol setImage:[UIImage imageNamed:@"checked_32.png"] forState:UIControlStateSelected];
 	// Do any additional setup after loading the view.
+    
+    NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
+    bool autologin =[defaults boolForKey:@"autologin"];
+    if(!autologin)
+    {
+        [self performSegueWithIdentifier:@"LOGIN" sender:self];
+    }
+    
 }
 
 - (void)didReceiveMemoryWarning

+ 16 - 0
Apex Mobile/Apex Mobile/HistoryData.h

@@ -0,0 +1,16 @@
+//
+//  HistoryData.h
+//  Apex Mobile
+//
+//  Created by Ray on 14-4-24.
+//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import <sqlite3.h>
+#import "ApexMobileDB.h"
+#import "ApexMobileAppDelegate.h"
+@interface HistoryData : NSObject
+@property (strong,nonatomic) NSMutableArray* pagedata;
+-(long) get_count;
+@end

+ 70 - 0
Apex Mobile/Apex Mobile/HistoryData.m

@@ -0,0 +1,70 @@
+//
+//  HistoryData.m
+//  Apex Mobile
+//
+//  Created by Ray on 14-4-24.
+//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
+//
+
+#import "HistoryData.h"
+
+@implementation HistoryData
+
+-(long) get_count
+{
+    return self.pagedata.count;
+}
+
+- (id)init
+{
+    self = [super init];
+    if (self) {
+        self.pagedata =[[NSMutableArray alloc]init];
+        
+        ApexMobileAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
+        //    NSString* required_ver=[objheader objectForKey:@"client_ver"] ;
+        //
+        //    appDelegate.sessionid = [objheader valueForKey:@"sessionid"];
+        //    appDelegate.user = user;
+        //    appDelegate.password = password;
+        
+        sqlite3 *db =[ApexMobileDB get_db];
+        NSString *quary = [NSString stringWithFormat:@"select _id,create_time,params,module_name,name from history where user='%@' order by _id desc",appDelegate.user];
+        
+        
+        
+        sqlite3_stmt *stmt;
+        if (sqlite3_prepare_v2(db, [quary UTF8String], -1, &stmt, nil) == SQLITE_OK) {
+            DebugLog(@"sql:%@",quary);
+            while (sqlite3_step(stmt)==SQLITE_ROW)
+            {
+//                NSString *aname = [[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(stmt, 0)];
+                int _id = sqlite3_column_int(stmt, 0);
+//                NSString* str_time = sqlite3
+                NSString* create_time = [NSString stringWithUTF8String:(char *)sqlite3_column_text(stmt, 1)];
+                NSString* params =[NSString stringWithUTF8String:(char *)sqlite3_column_text(stmt, 2)];
+                NSString* module_name =[NSString stringWithUTF8String:(char *)sqlite3_column_text(stmt, 3)];
+                
+                NSString* name =[NSString stringWithUTF8String:(char *)sqlite3_column_text(stmt, 4)];
+                NSMutableDictionary * map = [[NSMutableDictionary alloc] init];
+                [map setValue:[NSString stringWithFormat:@"%d",_id] forKey:@"_id"];
+                [map setValue:[NSString stringWithFormat:create_time,create_time] forKey:@"create_time"];
+                [map setValue:params forKey:@"params"];
+                [map setValue:module_name forKey:@"module_name"];
+                [map setValue:name forKey:@"name"];
+                
+                [self.pagedata addObject:map];
+                
+                
+            }
+            
+            sqlite3_finalize(stmt);
+        }
+        //用完了一定记得关闭,释放内存
+        sqlite3_close(db);
+        
+    }
+    return self;
+}
+
+@end

+ 15 - 0
Apex Mobile/Apex Mobile/HistoryTabBarController.h

@@ -0,0 +1,15 @@
+//
+//  HistoryTabBarController.h
+//  Apex Mobile
+//
+//  Created by Ray on 14-4-24.
+//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+#import "HistoryViewController.h"
+#import "FavoritesViewController.h"
+#import "Constant.h"
+@interface HistoryTabBarController : UITabBarController
+
+@end

+ 150 - 0
Apex Mobile/Apex Mobile/HistoryTabBarController.m

@@ -0,0 +1,150 @@
+//
+//  HistoryTabBarController.m
+//  Apex Mobile
+//
+//  Created by Ray on 14-4-24.
+//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
+//
+
+#import "HistoryTabBarController.h"
+
+@interface HistoryTabBarController ()
+
+@end
+
+@implementation HistoryTabBarController
+
+- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
+{
+    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
+    if (self) {
+        // Custom initialization
+    }
+    return self;
+}
+- (id)init
+{
+    self = [super init];
+    if (self) {
+        
+        DebugLog(@"DetailTabBarController init.................");
+        
+        
+        
+        //        UITabBar *tabBar = self.tabBar;
+        //        [tabBar setTintColor:[UIColor redColor]];
+        
+        //        [tabBar setTintColor:[UIColor colorWithRed:0.0
+        //                                             green:176.0/255.0
+        //                                              blue:226.0/255.0
+        //                                             alpha:1.0]];
+        //        tabBar.selectedImageTintColor = [UIColor clearColor];
+        //        UITabBarItem *item = [tabBar.items objectAtIndex:0];
+        //        NSString *homePath = [[NSBundle mainBundle] pathForResource:@"btn_home_highlight" ofType:@"png"];
+        //        if(item.tag == 1)
+        //        {
+        //            [item setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
+        //                                          [UIColor lightGrayColor], UITextAttributeTextColor, nil]
+        //                                forState:UIControlStateNormal];
+        //            item.selectedImage = [UIImage imageWithContentsOfFile:homePath];
+        //        }
+        
+        
+        self.navigationItem.title = @"Saved Detail/Search";
+        
+        NSMutableArray* controllers = [[NSMutableArray alloc]init];
+        
+        
+        
+        
+        NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
+        
+        
+        
+        
+        //            testViewController * one = [[testViewController alloc] init];
+        
+        UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:[NSBundle mainBundle]];
+        
+        UIOffset offset;
+        offset.horizontal = 0;
+        offset.vertical = -15;
+        
+        FavoritesViewController *detail = [storyboard instantiateViewControllerWithIdentifier:@"FavoritesViewController"];
+        
+        
+        
+        //                  [one setTitle:self.actions[i]];
+        detail.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Saved detail" image:nil tag:1];//[[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:0];
+        [detail.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
+                                                   [UIFont systemFontOfSize:12.0], NSFontAttributeName, nil]
+                                         forState:UIControlStateNormal];
+//        detail.module_name = @"Saved detail";
+        //   one.tabBarItem set
+        //            [one.tabBarItem setSelectedImage:[UIImage imageNamed:@"tag-3.png"]];
+        
+        [detail.tabBarItem setTitlePositionAdjustment:offset];
+        
+        
+        
+        
+        HistoryViewController *search = [storyboard instantiateViewControllerWithIdentifier:@"HistoryViewController"];
+        
+        
+        
+        //                  [one setTitle:self.actions[i]];
+        search.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Saved search" image:nil tag:1];//[[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:0];
+        [search.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
+                                                   [UIFont systemFontOfSize:12.0], NSFontAttributeName, nil]
+                                         forState:UIControlStateNormal];
+        
+//        search.module_name = @"Saved search";
+        //   one.tabBarItem set
+        //            [one.tabBarItem setSelectedImage:[UIImage imageNamed:@"tag-3.png"]];
+        [search.tabBarItem setTitlePositionAdjustment:offset];
+        //            one.tabBarItem set
+        
+        
+        [controllers addObject:search];
+        [controllers addObject:detail];
+        
+        
+        
+        self.viewControllers = controllers;
+        UIImage* img = [UIImage imageNamed:@"test1.png"];
+        UIImage * idimage=[img resizableImageWithCapInsets:UIEdgeInsetsMake(1.0f, 30.0f, 300.0f, 30.0f)];
+        //tabBarController.tabBar.selectionIndicatorImage = idicImage;
+        //        [self.tabBar setTintColor:[UIColor redColor]];
+        //        [self.tabBar setItemSpacing:0];
+        //        [self.tabBar setBarTintColor:[UIColor greenColor]];
+        //        [self.tabBar setSelectedImageTintColor:[UIColor purpleColor]];
+        self.tabBar.selectionIndicatorImage =idimage;
+        
+        
+    }
+    return self;
+}
+- (void)viewDidLoad
+{
+    [super viewDidLoad];
+    // Do any additional setup after loading the view.
+}
+
+- (void)didReceiveMemoryWarning
+{
+    [super didReceiveMemoryWarning];
+    // Dispose of any resources that can be recreated.
+}
+
+/*
+ #pragma mark - Navigation
+ 
+ // In a storyboard-based application, you will often want to do a little preparation before navigation
+ - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
+ {
+ // Get the new view controller using [segue destinationViewController].
+ // Pass the selected object to the new view controller.
+ }
+ */
+
+@end

+ 17 - 0
Apex Mobile/Apex Mobile/HistoryViewController.h

@@ -0,0 +1,17 @@
+//
+//  HistoryViewController.h
+//  Apex Mobile
+//
+//  Created by Ray on 14-4-24.
+//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+#import "HistoryData.h"
+#import "CellItemHistory.h"
+#import "ResultViewController.h"
+@interface HistoryViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>
+//@property (strong,nonatomic) NSString* module_name;
+@property (strong, nonatomic) IBOutlet UITableView *tableview;
+@property (strong,nonatomic) HistoryData* data;
+@end

+ 112 - 0
Apex Mobile/Apex Mobile/HistoryViewController.m

@@ -0,0 +1,112 @@
+//
+//  HistoryViewController.m
+//  Apex Mobile
+//
+//  Created by Ray on 14-4-24.
+//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
+//
+
+#import "HistoryViewController.h"
+
+@interface HistoryViewController ()
+
+@end
+
+@implementation HistoryViewController
+
+- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
+{
+    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
+    if (self) {
+        // Custom initialization
+    }
+    return self;
+}
+
+- (void)viewDidLoad
+{
+    [super viewDidLoad];
+
+    
+    // Do any additional setup after loading the view.
+}
+-(void)viewWillAppear:(BOOL)animated
+{
+    self.data =[[HistoryData alloc]init];
+    [self.tableview reloadData];
+}
+- (void)didReceiveMemoryWarning
+{
+    [super didReceiveMemoryWarning];
+    // Dispose of any resources that can be recreated.
+}
+
+/*
+#pragma mark - Navigation
+
+// In a storyboard-based application, you will often want to do a little preparation before navigation
+- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
+{
+    // Get the new view controller using [segue destinationViewController].
+    // Pass the selected object to the new view controller.
+}
+*/
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
+{
+    
+    return 1;
+}
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
+{
+    
+    return [self.data get_count];
+    
+    
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    DebugLog(@"cellForRowAtIndexPath");
+    
+    NSString *CellIdentifier = @"cell_item_history";
+    CellItemHistory *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
+    NSString* name = [self.data.pagedata[indexPath.row] valueForKey:@"name"];
+    NSString* create_time = [self.data.pagedata[indexPath.row] valueForKey:@"create_time"];
+
+    
+    cell.name.text = name;
+    [cell.name sizeToFit];
+    
+    cell.time.text =create_time;
+    [cell.time sizeToFit];
+    
+    //    cell.imageView.image = [UIImage imageNamed:[self.toolsinfo[indexPath.row] valueForKey:@"img"]];
+    
+    return cell;
+    
+    
+}
+
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    
+    ResultViewController *resultViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"ResultViewController"];
+    
+    resultViewController.function_name = [self.data.pagedata[indexPath.row] valueForKey:@"module_name"];
+
+    NSString* str_params =[self.data.pagedata[indexPath.row] valueForKey:@"params"];
+    NSData* data_params = [str_params dataUsingEncoding:NSUTF8StringEncoding];
+    
+    
+    
+    NSMutableDictionary* params = [[NSMutableDictionary alloc] initWithDictionary:[NSJSONSerialization
+                                                                                   JSONObjectWithData:data_params
+                                                                                   options:NSJSONReadingMutableLeaves
+                                                                                   error:nil] copyItems:true];
+
+    resultViewController.params =params;
+    [self.navigationController pushViewController:resultViewController animated:YES];
+}
+
+@end

+ 16 - 0
Apex Mobile/Apex Mobile/MyAutocompleteItemsSource.h

@@ -0,0 +1,16 @@
+//
+//  MyAutocompleteItemsSource.h
+//  testautocomplete
+//
+//  Created by Ray on 14-4-29.
+//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+//#import "TRAutocompleteItemsSource.h"
+@interface MyAutocompleteItemsSource : NSObject//<TRAutocompleteItemsSource>
+- (id)initWithMinimumCharactersToTrigger:(NSUInteger)minimumCharactersToTrigger;
+//- (id)initWithMinimumCharactersToTrigger:(NSUInteger)minimumCharactersToTrigger
+- (NSUInteger)minimumCharactersToTrigger;
+- (void)itemsFor:(NSString *)query whenReady:(void (^)(NSArray *))suggestionsReady;
+@end

+ 95 - 0
Apex Mobile/Apex Mobile/MyAutocompleteItemsSource.m

@@ -0,0 +1,95 @@
+//
+//  MyAutocompleteItemsSource.m
+//  testautocomplete
+//
+//  Created by Ray on 14-4-29.
+//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
+//
+
+#import "MyAutocompleteItemsSource.h"
+#import "MySuggestion.h"
+@implementation MyAutocompleteItemsSource
+{
+    //    NSString *_apiKey;
+    //    NSString *_language;
+    NSUInteger _minimumCharactersToTrigger;
+    
+    BOOL _requestToReload;
+    BOOL _loading;
+}
+- (id)initWithMinimumCharactersToTrigger:(NSUInteger)minimumCharactersToTrigger
+//                                language:(NSString *)language
+//                                  apiKey:(NSString *)apiKey
+{
+    self = [super init];
+    if (self)
+    {
+        
+        _minimumCharactersToTrigger = minimumCharactersToTrigger;
+        //        _apiKey = apiKey;
+        //        _language = language;
+        
+        //        self.location = kCLLocationCoordinate2DInvalid;
+        //        self.radiusMeters = -1;
+    }
+    
+    return self;
+}
+
+//- (id)initWithMinimumCharactersToTrigger:(NSUInteger)minimumCharactersToTrigger
+//
+//{
+//    return [self initWithMinimumCharactersToTrigger:minimumCharactersToTrigger language:@"en" apiKey:apiKey];
+//}
+- (NSUInteger)minimumCharactersToTrigger
+{
+    return _minimumCharactersToTrigger;
+}
+- (void)itemsFor:(NSString *)query whenReady:(void (^)(NSArray *))suggestionsReady
+{
+    @synchronized (self)
+    {
+        if (_loading)
+        {
+            _requestToReload = YES;
+            return;
+        }
+        
+        _loading = YES;
+        [self requestSuggestionsFor:query whenReady:suggestionsReady];
+    }
+}
+
+- (void)requestSuggestionsFor:(NSString *)query whenReady:(void (^)(NSArray *))suggestionsReady
+{
+    
+    NSMutableArray *suggestions = [[NSMutableArray alloc] init];
+    NSArray *predictions =[[NSArray alloc] initWithObjects:@"aa",@"aab",@"bbc",@"bbbd",nil];
+    
+    for (int i=0;i<predictions.count;i++)
+    {
+        if([predictions[i] rangeOfString:query].location==0)
+        {
+            MySuggestion *suggestion = [[MySuggestion alloc] initWith:predictions[i]];
+            [suggestions addObject:suggestion];
+        }
+    }
+    
+    if (suggestionsReady)
+        suggestionsReady(suggestions);
+    
+    @synchronized (self)
+    {
+        _loading = NO;
+        
+        if (_requestToReload)
+        {
+            _requestToReload = NO;
+            [self itemsFor:query whenReady:suggestionsReady];
+        }
+    }
+    
+}
+
+
+@end

+ 26 - 0
Apex Mobile/Apex Mobile/MyAutocompleteView.h

@@ -0,0 +1,26 @@
+
+
+#import <Foundation/Foundation.h>
+#import "MyAutocompleteItemsSource.h"
+#import "MyAutocompletionCellFactory.h"
+#import "MySuggestion.h"
+
+
+@interface MyAutocompleteView : UIView
+
+@property(readonly)MySuggestion* selectedSuggestion;
+@property(readonly) NSArray *suggestions;
+
+@property(copy) void (^didAutocompleteWith)(MySuggestion *);
+
+@property(nonatomic) UIColor *separatorColor;
+@property(nonatomic) UITableViewCellSeparatorStyle separatorStyle;
+
+@property(nonatomic) CGFloat topMargin;
+
++ (MyAutocompleteView *)autocompleteViewBindedTo:(UITextField *)textField
+                                     usingSource:(MyAutocompleteItemsSource*) itemsSource
+                                     cellFactory:(MyAutocompletionCellFactory*)factory
+                                    presentingIn:(UIViewController *)controller;
+
+@end

+ 218 - 0
Apex Mobile/Apex Mobile/MyAutocompleteView.m

@@ -0,0 +1,218 @@
+
+
+#import "MyAutocompleteView.h"
+
+
+@interface MyAutocompleteView () <UITableViewDelegate, UITableViewDataSource>
+
+@property(readwrite)MySuggestion* selectedSuggestion;
+@property(readwrite) NSArray *suggestions;
+
+@end
+
+@implementation MyAutocompleteView
+{
+    BOOL _visible;
+
+    __weak UITextField *_queryTextField;
+    __weak UIViewController *_contextController;
+
+    UITableView *_table;
+    MyAutocompleteItemsSource* _itemsSource;
+    MyAutocompletionCellFactory* _cellFactory;
+}
+
++ (MyAutocompleteView *)autocompleteViewBindedTo:(UITextField *)textField
+                                     usingSource:(MyAutocompleteItemsSource*) itemsSource
+                                     cellFactory:(MyAutocompletionCellFactory*) factory
+                                    presentingIn:(UIViewController *)controller
+{
+    return [[MyAutocompleteView alloc] initWithFrame:CGRectZero
+                                           textField:textField
+                                         itemsSource:itemsSource
+                                         cellFactory:factory
+                                          controller:controller];
+}
+
+- (id)initWithFrame:(CGRect)frame
+          textField:(UITextField *)textField
+        itemsSource:(MyAutocompleteItemsSource*) itemsSource
+        cellFactory:(MyAutocompletionCellFactory*) factory
+         controller:(UIViewController *)controller
+{
+    self = [super initWithFrame:frame];
+    if (self)
+    {
+        [self loadDefaults];
+
+        _queryTextField = textField;
+        _itemsSource = itemsSource;
+        _cellFactory = factory;
+        _contextController = controller;
+
+        _table = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
+        _table.backgroundColor = [UIColor whiteColor];
+        _table.separatorColor = self.separatorColor;
+        _table.separatorStyle = self.separatorStyle;
+        
+        _table.delegate = self;
+        _table.dataSource = self;
+
+        [[NSNotificationCenter defaultCenter]
+                               addObserver:self
+                                  selector:@selector(queryChanged:)
+                                      name:UITextFieldTextDidChangeNotification
+                                    object:_queryTextField];
+        [[NSNotificationCenter defaultCenter] addObserver:self
+                                                 selector:@selector(keyboardWasShown:)
+                                                     name:UIKeyboardDidShowNotification
+                                                   object:nil];
+        [[NSNotificationCenter defaultCenter] addObserver:self
+                                                 selector:@selector(keyboardWillHide:)
+                                                     name:UIKeyboardWillHideNotification
+                                                   object:nil];
+
+        [self addSubview:_table];
+    }
+
+    return self;
+}
+
+- (void)loadDefaults
+{
+    self.backgroundColor = [UIColor lightGrayColor];
+
+    self.separatorColor = [UIColor lightGrayColor];
+    self.separatorStyle = UITableViewCellSeparatorStyleSingleLine;// uitableviewcellsep UITableViewCellSeparatorStyleNone;
+
+    self.topMargin = 0;
+}
+
+- (void)keyboardWasShown:(NSNotification *)notification
+{
+    NSDictionary *info = [notification userInfo];
+    CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
+
+    CGFloat contextViewHeight = 0;
+    CGFloat kbHeight = 0;
+    if (UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation))
+    {
+        contextViewHeight = _contextController.view.frame.size.height;
+        kbHeight = kbSize.height;
+    }
+    else if (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation))
+    {
+        contextViewHeight = _contextController.view.frame.size.width;
+        kbHeight = kbSize.width;
+    }
+
+    CGPoint textPosition = [_queryTextField convertPoint:_queryTextField.bounds.origin toView:nil]; //Taking in account Y position of queryTextField relatively to it's Window
+    CGRect textfieldFrame = _queryTextField.frame;
+    CGFloat calculatedY = textPosition.y + _queryTextField.frame.size.height + self.topMargin;
+    CGFloat calculatedHeight = 130;//150;//contextViewHeight - calculatedY - kbHeight;
+
+    calculatedHeight += _contextController.tabBarController.tabBar.frame.size.height; //keyboard is shown over it, need to compensate
+
+    self.frame = CGRectMake(_queryTextField.frame.origin.x,
+                            calculatedY,
+                            _queryTextField.frame.size.width,
+                            calculatedHeight);
+    _table.frame = CGRectMake(0+0.5, 0+0.5, self.frame.size.width-1, self.frame.size.height-1);
+}
+
+- (void)keyboardWillHide:(NSNotification *)notification
+{
+    [self removeFromSuperview];
+    _visible = NO;
+}
+
+- (void)queryChanged:(id)sender
+{
+    if ([_queryTextField.text length] >= _itemsSource.minimumCharactersToTrigger)
+    {
+        [_itemsSource itemsFor:_queryTextField.text whenReady:
+                                                            ^(NSArray *suggestions)
+                                                            {
+                                                                if (_queryTextField.text.length
+                                                                    < _itemsSource.minimumCharactersToTrigger)
+                                                                {
+                                                                    self.suggestions = nil;
+                                                                    [_table reloadData];
+                                                                }
+                                                                else
+                                                                {
+                                                                    self.suggestions = suggestions;
+                                                                    [_table reloadData];
+
+                                                                    if (self.suggestions.count > 0 && !_visible)
+                                                                    {
+                                                                        [_contextController.view addSubview:self];
+                                                                        _visible = YES;
+                                                                    }
+                                                                }
+                                                            }];
+    }
+    else
+    {
+        self.suggestions = nil;
+        [_table reloadData];
+    }
+}
+
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
+{
+    return self.suggestions.count;
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    static NSString *identifier = @"TRAutocompleteCell";
+
+    id cell = [tableView dequeueReusableCellWithIdentifier:identifier];
+    if (cell == nil)
+        cell = [_cellFactory createReusableCellWithIdentifier:identifier];
+
+    NSAssert([cell isKindOfClass:[UITableViewCell class]], @"Cell must inherit from UITableViewCell");
+//    NSAssert([cell conformsToProtocol:@protocol(TRAutocompletionCell)], @"Cell must conform TRAutocompletionCell");
+   MyAutocompletionCell *completionCell = (MyAutocompletionCell *) cell;
+
+    id suggestion = self.suggestions[(NSUInteger) indexPath.row];
+//    NSAssert([suggestion conformsToProtocol:@protocol(TRSuggestionItem)], @"Suggestion item must conform TRSuggestionItem");
+   MySuggestion* suggestionItem = (MySuggestion *) suggestion;
+
+    [completionCell updateWith:suggestionItem];
+
+    return cell;
+}
+
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    id suggestion = self.suggestions[(NSUInteger) indexPath.row];
+   // NSAssert([suggestion conformsToProtocol:@protocol(TRSuggestionItem)], @"Suggestion item must conform TRSuggestionItem");
+
+    self.selectedSuggestion = (MySuggestion *) suggestion;
+
+    _queryTextField.text = self.selectedSuggestion.completionText;
+    [_queryTextField resignFirstResponder];
+
+    if (self.didAutocompleteWith)
+        self.didAutocompleteWith(self.selectedSuggestion);
+}
+
+- (void)dealloc
+{
+    [[NSNotificationCenter defaultCenter]
+                           removeObserver:self
+                                     name:UITextFieldTextDidChangeNotification
+                                   object:nil];
+    [[NSNotificationCenter defaultCenter]
+                           removeObserver:self
+                                     name:UIKeyboardDidShowNotification
+                                   object:nil];
+    [[NSNotificationCenter defaultCenter]
+                           removeObserver:self
+                                     name:UIKeyboardWillHideNotification
+                                   object:nil];
+}
+
+@end

+ 20 - 0
Apex Mobile/Apex Mobile/MyAutocompletionCellFactory.h

@@ -0,0 +1,20 @@
+//
+//  MyAutocompletionCellFactory.h
+//  testautocomplete
+//
+//  Created by Ray on 14-4-29.
+//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import "MySuggestion.h"
+//#import "TRAutocompletionCellFactory.h"
+
+@interface MyAutocompletionCell : UITableViewCell //<TRAutocompletionCell>
+- (void)updateWith:(MySuggestion *)item;
+@end
+@interface MyAutocompletionCellFactory : NSObject//<TRAutocompletionCellFactory>
+- (id)initWithCellTextColor:(UIColor *)textColor fontSize:(CGFloat)fontSize;
+- (MyAutocompletionCell *)createReusableCellWithIdentifier:(NSString *)identifier;
+
+@end

+ 57 - 0
Apex Mobile/Apex Mobile/MyAutocompletionCellFactory.m

@@ -0,0 +1,57 @@
+//
+//  MyAutocompletionCellFactory.m
+//  testautocomplete
+//
+//  Created by Ray on 14-4-29.
+//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
+//
+
+#import "MyAutocompletionCellFactory.h"
+#import "MySuggestion.h"
+//#import "TRAutocompleteItemsSource.h"
+
+
+
+@implementation MyAutocompletionCell
+
+- (void)updateWith:(MySuggestion*)item
+{
+    self.textLabel.text = item.completionText;
+}
+
+@end
+
+
+@implementation MyAutocompletionCellFactory
+{
+    UIColor *_foregroundColor;
+    CGFloat _fontSize;
+}
+
+- (id)initWithCellTextColor:(UIColor *)textColor fontSize:(CGFloat)fontSize
+{
+    self = [super init];
+    if (self)
+    {
+        _foregroundColor = textColor;
+        _fontSize = fontSize;
+    }
+    
+    return self;
+}
+
+- (MyAutocompletionCell *)createReusableCellWithIdentifier:(NSString *)identifier
+{
+    MyAutocompletionCell *cell = [[MyAutocompletionCell alloc]
+                                            initWithStyle:UITableViewCellStyleDefault
+                                            reuseIdentifier:identifier];
+    cell.textLabel.font = [UIFont systemFontOfSize:_fontSize];
+    cell.textLabel.textColor = _foregroundColor;
+    
+    cell.backgroundColor = [UIColor clearColor];
+    cell.selectionStyle = UITableViewCellSelectionStyleNone;
+    
+    return cell;
+    
+}
+@end

+ 18 - 0
Apex Mobile/Apex Mobile/MySuggestion.h

@@ -0,0 +1,18 @@
+//
+//  MySuggestion.h
+//  testautocomplete
+//
+//  Created by Ray on 14-4-29.
+//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+//#import "TRAutocompleteItemsSource.h"
+@interface MySuggestion :  NSObject //<TRSuggestionItem>
+
+@property(nonatomic) NSString *address;
+
+- (id)initWith:(NSString *)address;
+- (NSString *)completionText;
+
+@end

+ 25 - 0
Apex Mobile/Apex Mobile/MySuggestion.m

@@ -0,0 +1,25 @@
+//
+//  MySuggestion.m
+//  testautocomplete
+//
+//  Created by Ray on 14-4-29.
+//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
+//
+
+#import "MySuggestion.h"
+
+@implementation MySuggestion
+- (id)initWith:(NSString *)address
+{
+    self = [super init];
+    if (self)
+        self.address = address;
+    
+    return self;
+}
+
+- (NSString *)completionText
+{
+    return self.address;
+}
+@end

+ 19 - 0
Apex Mobile/Apex Mobile/NewsData.h

@@ -0,0 +1,19 @@
+//
+//  NewsData.h
+//  Apex Mobile
+//
+//  Created by Ray on 14-4-21.
+//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface NewsData : NSObject
+@property (strong,nonatomic) NSMutableArray* pagedata;
+@property int limit;
+@property bool finishload;
+@property (strong,nonatomic) NSString* _id;
+-(void) appenddata : (NSData*) data;
+-(long) get_count;
+-(id)init : (int) limit;
+@end

+ 57 - 0
Apex Mobile/Apex Mobile/NewsData.m

@@ -0,0 +1,57 @@
+//
+//  NewsData.m
+//  Apex Mobile
+//
+//  Created by Ray on 14-4-21.
+//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
+//
+
+#import "NewsData.h"
+
+@implementation NewsData
+-(id)init : (int) limit
+{
+    self = [super init];
+    if(self)
+    {
+        self.pagedata =  [[NSMutableArray alloc]init];
+        self.limit = limit;
+        self.finishload = false;
+    }
+    return self;
+}
+-(void) appenddata : (NSData*) data
+{
+    NSError *error=nil;
+    NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];
+    if(jsobj)
+    {
+        int count =  [[jsobj valueForKey:@"total" ] intValue];
+        if(count<self.limit)
+            self.finishload = true;
+        NSDictionary * objrecords = [jsobj objectForKey:@"records"];
+        for(int i=0;i<count;i++)
+        {
+            NSDictionary* objrec = [objrecords objectForKey:[NSString stringWithFormat:@"record%d",i ]];
+//            NSString* title = [objrec valueForKey:@"title"];
+//            NSString* content  = [objrec valueForKey:@"content"];
+//            NSString* image  = [objrec valueForKey:@"image"];
+//            NSString* _id  = [objrec valueForKey:@"id"];
+//            NSString* url  = [objrec valueForKey:@"url"];
+//            
+//            NSMutableDictionary * map = [[NSMutableDictionary alloc] init];
+//            map setValue:title forKey:@"title"
+            self._id =[objrec valueForKey:@"id"];
+            [self.pagedata addObject:objrec];
+            
+        }
+        
+    }
+    
+    
+}
+-(long) get_count
+{
+    return self.pagedata.count;
+}
+@end

+ 18 - 0
Apex Mobile/Apex Mobile/NewsTableViewCell.h

@@ -0,0 +1,18 @@
+//
+//  NewsTableViewCell.h
+//  Apex Mobile
+//
+//  Created by Ray on 14-4-21.
+//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface NewsTableViewCell : UITableViewCell
+
+@property (strong, nonatomic) IBOutlet UILabel *title;
+@property (strong, nonatomic) IBOutlet UIImageView *image;
+@property (strong, nonatomic) IBOutlet UILabel *content;
+
+
+@end

+ 34 - 0
Apex Mobile/Apex Mobile/NewsTableViewCell.m

@@ -0,0 +1,34 @@
+//
+//  NewsTableViewCell.m
+//  Apex Mobile
+//
+//  Created by Ray on 14-4-21.
+//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
+//
+
+#import "NewsTableViewCell.h"
+
+@implementation NewsTableViewCell
+
+- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
+{
+    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
+    if (self) {
+        // Initialization code
+    }
+    return self;
+}
+
+- (void)awakeFromNib
+{
+    // Initialization code
+}
+
+- (void)setSelected:(BOOL)selected animated:(BOOL)animated
+{
+    [super setSelected:selected animated:animated];
+
+    // Configure the view for the selected state
+}
+
+@end

+ 23 - 0
Apex Mobile/Apex Mobile/NewsViewController.h

@@ -0,0 +1,23 @@
+//
+//  NewsViewController.h
+//  Apex Mobile
+//
+//  Created by Ray on 14-4-18.
+//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+#import "NewsData.h"
+#import "NewsTableViewCell.h"
+#import "ApexMobileNetwork.h"
+
+@interface NewsViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>
+-(id) init :(NSString*) title ;
+@property (strong,nonatomic) NSString* module_name;
+@property int limit;
+@property (strong,nonatomic) NSString* lastid;
+@property (strong,nonatomic) NewsData* data;
+@property (strong, nonatomic) IBOutlet UIActivityIndicatorView *mum;
+@property (strong,nonatomic) UIButton* btnrefresh;
+@property (strong, nonatomic) IBOutlet UITableView *tableview;
+@end

+ 251 - 0
Apex Mobile/Apex Mobile/NewsViewController.m

@@ -0,0 +1,251 @@
+//
+//  NewsViewController.m
+//  Apex Mobile
+//
+//  Created by Ray on 14-4-18.
+//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
+//
+
+#import "NewsViewController.h"
+
+@interface NewsViewController ()
+
+@end
+
+@implementation NewsViewController
+
+-(void) loadpage
+{
+    
+    //    [self.params setValue:[NSString stringWithFormat:@"%ld",self.offset] forKey:@"offset"];
+    self.mum.center = self.view.center;
+    self.btnrefresh.enabled = false;
+    //
+    //    NSTimeInterval animationDuration = 0.30f;
+    //    [UIView beginAnimations:@"ResizeView" context:nil];
+    //    [UIView setAnimationDuration:animationDuration];
+    //    self.prepageButton.enabled=false;
+    //    self.nextpageButton.enabled=false;
+    //    self.mum.hidden = false;
+    //    self.grid.hidden = true;
+    //    self.mum.hidden = false;
+    //    self.tableview.hidden = true;
+    
+    //    [UIView commitAnimations];
+    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+        
+        
+        NSData* data=nil;
+        if([self.module_name isEqualToString:@"Announcements"])
+            data=[ApexMobileNetwork get_announcements:self.lastid limit:self.limit];
+        else
+            data=[ApexMobileNetwork get_marketnews:self.lastid limit:self.limit];
+        
+        
+        dispatch_async(dispatch_get_main_queue(), ^{
+            self.tableview.hidden =false;
+            self.mum.hidden = true;
+            if(data != nil)
+            {
+                [self.data appenddata: data];
+                self.lastid = self.data._id;
+                self.btnrefresh.hidden = false;
+                if(self.data.finishload==true)
+                {
+                    
+                    int i =self.btnrefresh.state;
+                    self.btnrefresh.titleLabel.text =@"No more";
+                    //                    [self.btnrefresh setTitle:@"No more" forState:UIControlStateNormal];
+                }
+                else
+                {
+                    self.btnrefresh.enabled = true;
+                    self.btnrefresh.titleLabel.text =@"Load more";
+                    //                    [self.btnrefresh setTitle:@"Load more" forState:UIControlStateNormal];
+                }
+                [self.tableview reloadData ];
+            }
+            else
+            {
+                self.btnrefresh.enabled = true;
+                [self.btnrefresh setTitle:@"Load more" forState:UIControlStateNormal];
+                
+            }
+            
+            
+            
+            
+            
+        });
+    });
+}
+
+- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
+{
+    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
+    if (self) {
+        
+        self.data = [[NewsData alloc]init];
+        // Custom initialization
+    }
+    return self;
+}
+-(id) init :(NSString*) module_name
+{
+    self = [super init];
+    if(self)
+    {
+        self.module_name = module_name;
+        self.data = [[NewsData alloc]init];
+    }
+    return self;
+}
+
+
+- (void)viewDidLoad
+{
+    [super viewDidLoad];
+    self.navigationItem.title = self.module_name;
+    self.limit = 10;
+    self.data = [[NewsData alloc] init:self.limit];
+    
+    
+    
+    
+    self.btnrefresh = [UIButton buttonWithType:UIButtonTypeCustom];
+    //    self.btnrefresh.titleLabel.text =@"Load more";
+    [self.btnrefresh setTitle:@"Load more" forState:UIControlStateNormal];
+    self.btnrefresh.hidden = true;
+    [self.btnrefresh setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
+    self.btnrefresh.backgroundColor = [UIColor lightGrayColor];
+    [self.btnrefresh addTarget:self action:@selector(loadmore) forControlEvents:UIControlEventTouchUpInside];
+    self.btnrefresh.frame =CGRectMake(0.0f, 0.0f, self.tableview.bounds.size.width, 44.0f);
+    self.tableview.tableFooterView = self.btnrefresh;//tableFooterView;
+    
+    [self loadpage];
+}
+- (void)loadmore
+{
+    self.btnrefresh.enabled = NO;
+    self.btnrefresh.titleLabel.text =@"Loading...";
+    //    [self.btnrefresh setTitle:@"Loading..." forState:UIControlStateNormal];
+    [self loadpage];
+    //    [SVProgressHUD showWithStatus:@"加载中..."];
+    //    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
+    //    double delayInSeconds = 1.5;
+    //    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
+    //    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
+    //        _rowCount += 5;
+    //        [self.tableView reloadData];
+    //        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
+    //        [SVProgressHUD showSuccessWithStatus:@"加载完成"];
+    //        _bottomRefresh.frame = CGRectMake(0, 44+_rowCount*RCellHeight, 320, RCellHeight);
+    //        _bottomRefresh.enabled = YES;
+    //    });
+}
+
+- (void)didReceiveMemoryWarning
+{
+    [super didReceiveMemoryWarning];
+    // Dispose of any resources that can be recreated.
+}
+
+/*
+ #pragma mark - Navigation
+ 
+ // In a storyboard-based application, you will often want to do a little preparation before navigation
+ - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
+ {
+ // Get the new view controller using [segue destinationViewController].
+ // Pass the selected object to the new view controller.
+ }
+ */
+//- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
+//{
+////    if(section==1)
+////        return 44;
+////    else
+//        return 200;
+//}
+//- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
+//{
+////    tableView dequeueReusableHeaderFooterViewWithIdentifier:<#(NSString *)#>
+//    UITableViewHeaderFooterView *view = [[UITableViewHeaderFooterView alloc]initWithFrame:CGRectMake(0, 0, 360, 44.0)];
+//    view.backgroundColor = [UIColor redColor];
+////    UIView* footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 360, 44.0)];
+////    UIButton* btnNextPage = [[UIButton alloc] initWithFrame:footerView.frame];
+////    btnNextPage.titleLabel.text = NSLocalizedString(@"Load more", null);
+////    [footerView addSubview:btnNextPage];
+////    [view addSubview:footerView];
+//    return view;
+//}
+
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
+{
+    
+    return 1;
+}
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
+{
+    
+    return [self.data get_count];
+    
+    
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    DebugLog(@"cellForRowAtIndexPath");
+    
+    NSString *CellIdentifier = @"newsitem";
+    NewsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
+    NSString* title = [self.data.pagedata[indexPath.row] valueForKey:@"title"];
+    NSString* content = [self.data.pagedata[indexPath.row] valueForKey:@"content"];
+    NSString* base64img =[self.data.pagedata[indexPath.row] valueForKey:@"image"];
+    
+    if(base64img.length>0)
+    {
+        NSData *_decodedImageData   = [[NSData alloc] initWithBase64EncodedString:base64img options:NSDataBase64DecodingIgnoreUnknownCharacters];
+        cell.image.image = [UIImage imageWithData:_decodedImageData];
+    }
+    else
+    {
+        UIImage * img =[UIImage imageNamed:@"rect_market_news"];
+        cell.image.image = img;
+        
+    }
+    cell.title.text = title;
+    [cell.title sizeToFit];
+    
+    cell.content.text =content;
+    
+    //    cell.imageView.image = [UIImage imageNamed:[self.toolsinfo[indexPath.row] valueForKey:@"img"]];
+    
+    return cell;
+    
+    
+}
+
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    
+    //    SearchViewController *searchViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SearchViewController"];
+    //    searchViewController.function_name = @"Download Document";
+    //    [self.navigationController pushViewController:searchViewController animated:YES];
+    //    return;
+    
+    //    NSString* title = [self.toolsinfo[indexPath.row] valueForKey:@"title"];
+    //    if([title isEqualToString:@"Market news"])
+    //    {
+    //        NewsViewController *newsview=[[NewsViewController alloc] init:title ];
+    //        [self.navigationController pushViewController:newsview animated:YES];
+    //    }
+    //    else if([title isEqualToString:@"Announcements"])
+    //    {
+    //        NewsViewController *newsview=[[NewsViewController alloc] init:title ];
+    //        [self.navigationController pushViewController:newsview animated:YES];
+    //    }
+}
+
+@end

+ 52 - 0
Apex Mobile/Apex Mobile/PulldownMenu.h

@@ -0,0 +1,52 @@
+//
+//  PulldownMenu.h
+//
+//  Created by Bernard Gatt
+//
+
+#import <UIKit/UIKit.h>
+
+@protocol PulldownMenuDelegate
+    -(void)menuItemSelected:(NSIndexPath *)indexPath;
+    -(void)pullDownAnimated:(BOOL)open;
+@end
+
+@interface PulldownMenu : UIView<UITableViewDataSource, UITableViewDelegate> {
+    UITableView *menuList;
+    NSMutableArray *menuItems;
+    
+    UIView *handle;
+    UIView *masterView;
+    UIPanGestureRecognizer *navigationDragGestureRecognizer;
+    UIPanGestureRecognizer *handleDragGestureRecognizer;
+    UINavigationController *masterNavigationController;
+    UIDeviceOrientation currentOrientation;
+    
+    float topMargin;
+    float tableHeight;
+}
+
+@property (nonatomic, assign) id<PulldownMenuDelegate> delegate;
+@property (nonatomic, retain) UITableView *menuList;
+@property (nonatomic, retain) UIView *handle;
+
+/* Appearance Properties */
+@property (nonatomic) float handleHeight;
+@property (nonatomic) float animationDuration;
+@property (nonatomic) float topMarginPortrait;
+@property (nonatomic) float topMarginLandscape;
+@property (nonatomic) UIColor *cellColor;
+@property (nonatomic) UIColor *cellSelectedColor;
+@property (nonatomic) UIColor *cellTextColor;
+@property (nonatomic) UITableViewCellSelectionStyle cellSelectionStyle;
+@property (nonatomic) UIFont *cellFont;
+@property (nonatomic) float cellHeight;
+@property (nonatomic) BOOL fullyOpen;
+
+- (id)initWithNavigationController:(UINavigationController *)navigationController;
+- (id)initWithView:(UIView *)view;
+- (void)insertButton:(NSString *)title;
+- (void)loadMenu;
+- (void)animateDropDown;
+- (void)animateDropDown:(CGPoint)position;
+@end

+ 457 - 0
Apex Mobile/Apex Mobile/PulldownMenu.m

@@ -0,0 +1,457 @@
+//
+//  PulldownMenu.m
+//
+//  Created by Bernard Gatt
+//
+
+#import "PulldownMenu.h"
+
+@implementation PulldownMenu
+
+@synthesize menuList,
+            handle,
+            cellHeight,
+            handleHeight,
+            animationDuration,
+            topMarginLandscape,
+            topMarginPortrait,
+            cellColor,
+            cellFont,
+            cellTextColor,
+            cellSelectedColor,
+            cellSelectionStyle,
+            fullyOpen,
+            delegate;
+
+- (id)init
+{
+    self = [super init];
+    self.backgroundColor = [UIColor clearColor];
+    menuItems = [[NSMutableArray alloc] init];
+    
+    // Setting defaults
+    cellHeight = 60.0f;
+    handleHeight = 0.0f;
+    animationDuration = 0.3f;
+    topMarginPortrait = 0;
+    topMarginLandscape = 0;
+    cellColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];//[UIColor grayColor];
+    cellSelectedColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.5];//[UIColor blackColor];
+    cellFont = [UIFont fontWithName:@"GillSans-Bold" size:19.0f];
+    cellTextColor = [UIColor whiteColor];
+    cellSelectionStyle = UITableViewCellSelectionStyleDefault;
+    
+    return self;
+}
+
+- (id)initWithNavigationController:(UINavigationController *)navigationController
+{
+    self = [self init];
+    
+    if (self)
+    {
+        [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
+        [[NSNotificationCenter defaultCenter] addObserver: self
+                                                 selector: @selector(deviceOrientationDidChange:)
+                                                     name: UIDeviceOrientationDidChangeNotification
+                                                   object: nil];
+        
+        masterNavigationController = navigationController;
+        
+        navigationDragGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(dragMenu:)];
+        navigationDragGestureRecognizer.minimumNumberOfTouches = 1;
+        navigationDragGestureRecognizer.maximumNumberOfTouches = 1;
+        
+        handleDragGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(dragMenu:)];
+        handleDragGestureRecognizer.minimumNumberOfTouches = 1;
+        handleDragGestureRecognizer.maximumNumberOfTouches = 1;
+        
+        [masterNavigationController.navigationBar addGestureRecognizer:navigationDragGestureRecognizer];
+        
+        masterView = masterNavigationController.view;
+    }
+    
+    return self;
+}
+
+- (id)initWithView:(UIView *)view
+{
+    self = [self init];
+    
+    if (self)
+    {
+        topMargin = 0;
+        masterView = view;
+    }
+    
+    return self;
+}
+
+- (void)loadMenu
+{
+    tableHeight = ([menuItems count] * cellHeight);
+    
+    [self updateValues];
+    
+    [self setFrame:CGRectMake(0, 0, 0, tableHeight+handleHeight)];
+   
+    fullyOpen = NO;
+    
+    menuList = [[UITableView alloc] init];
+    menuList.scrollEnabled = false;
+    menuList.backgroundColor = [UIColor clearColor];
+//     self.backgroundColor = [UIColor yellowColor];
+//    menuList.style
+    [menuList setRowHeight:cellHeight];
+    [menuList setDataSource:self];
+    [menuList setDelegate:self];
+    [self addSubview:menuList];
+    
+    handle = [[UIView alloc] init];
+    [handle setBackgroundColor:[UIColor blackColor]];
+    
+    [self addSubview:handle];
+    
+    handleDragGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(dragMenu:)];
+    handleDragGestureRecognizer.minimumNumberOfTouches = 1;
+    handleDragGestureRecognizer.maximumNumberOfTouches = 1;
+    [handle addGestureRecognizer:handleDragGestureRecognizer];
+    
+    [self setTranslatesAutoresizingMaskIntoConstraints:NO];
+    [handle setTranslatesAutoresizingMaskIntoConstraints:NO];
+    [menuList setTranslatesAutoresizingMaskIntoConstraints:NO];
+    
+    [self createConstraints];
+}
+
+- (void)insertButton:(NSString *)title
+{
+    [menuItems addObject:title];
+}
+
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    [self.delegate menuItemSelected:indexPath];
+}
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
+    return 1;
+}
+
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
+{
+    return [menuItems count];
+}
+
+-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"menuListCell"];
+    
+    if (cell == nil) {
+        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"menuListCell"];
+    }
+    
+    cell.backgroundColor = cellColor;
+    
+//    UIView *cellSelectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame];
+//    cellSelectedBackgroundView.backgroundColor = cellSelectedColor;
+//    cell.selectedBackgroundView = cellSelectedBackgroundView;
+    cell.textLabel.textAlignment=NSTextAlignmentCenter;
+    cell.selectionStyle = cellSelectionStyle;
+    
+    [cell.textLabel setTextColor:cellTextColor];
+    cell.textLabel.font = cellFont;
+    [cell.textLabel setText:[menuItems objectAtIndex:indexPath.item]];
+    
+    return cell;
+}
+
+- (void)dragMenu:(UIPanGestureRecognizer *)sender
+{
+    if ([sender state] == UIGestureRecognizerStateChanged)
+    {
+        CGPoint gesturePosition = [sender translationInView:masterNavigationController.navigationBar];
+        CGPoint newPosition = gesturePosition;
+        
+        newPosition.x = self.frame.size.width / 2;
+        
+        if (fullyOpen)
+        {
+            if (newPosition.y < 0)
+            {
+                newPosition.y += ((self.frame.size.height / 2) + topMargin);
+                
+                [self setCenter:newPosition];
+            }
+        }
+        else
+        {
+            newPosition.y += -((self.frame.size.height / 2) - topMargin);
+            
+            if (newPosition.y <= ((self.frame.size.height / 2) + topMargin))
+            {
+                [self setCenter:newPosition];
+            }
+        }
+    }
+    else if ([sender state] == UIGestureRecognizerStateEnded)
+    {
+        [self animateDropDown];
+    }
+}
+
+- (void)animateDropDown
+{
+    
+    [UIView animateWithDuration: animationDuration
+                          delay: 0.0
+                        options: UIViewAnimationOptionCurveEaseOut
+                     animations:^{
+                         if (fullyOpen)
+                         {
+                             
+                             self.center = CGPointMake(self.frame.size.width / 2, -((self.frame.size.height / 2) + topMargin));
+                             fullyOpen = NO;
+                         }
+                         else
+                         {
+                             self.center = CGPointMake(self.frame.size.width / 2, ((self.frame.size.height / 2) + topMargin));
+                             fullyOpen = YES;
+                         }
+                     }
+                     completion:^(BOOL finished){
+                         [delegate pullDownAnimated:fullyOpen];
+                     }];
+}
+
+- (void)animateDropDown:(CGPoint) position
+{
+    
+    [UIView animateWithDuration: animationDuration
+                          delay: 0.0
+                        options: UIViewAnimationOptionCurveEaseOut
+                     animations:^{
+                         if (fullyOpen)
+                         {
+                             
+                             self.center = CGPointMake(self.frame.size.width / 2+position.x, -((self.frame.size.height / 2)+position.y + topMargin));
+                             fullyOpen = NO;
+                         }
+                         else
+                         {
+                             self.center = CGPointMake(self.frame.size.width / 2+position.x, ((self.frame.size.height / 2)+position.y + topMargin));
+                             fullyOpen = YES;
+                         }
+                     }
+                     completion:^(BOOL finished){
+                         [delegate pullDownAnimated:fullyOpen];
+                     }];
+}
+
+- (void)createConstraints
+{
+    
+    NSLayoutConstraint *pullDownTopPositionConstraint = [NSLayoutConstraint
+                                                         constraintWithItem:self
+                                                         attribute:NSLayoutAttributeTop
+                                                         relatedBy:NSLayoutRelationEqual
+                                                         toItem:masterView
+                                                         attribute:NSLayoutAttributeTop
+                                                         multiplier:1.0
+                                                         constant:-self.frame.size.height];
+    
+    NSLayoutConstraint *pullDownCenterXPositionConstraint = [NSLayoutConstraint
+                                                             constraintWithItem:self
+                                                             attribute:NSLayoutAttributeCenterX
+                                                             relatedBy:NSLayoutRelationEqual
+                                                             toItem:masterView
+                                                             attribute:NSLayoutAttributeCenterX
+                                                             multiplier:1.0
+                                                             constant:0];
+    
+    NSLayoutConstraint *pullDownWidthConstraint = [NSLayoutConstraint
+                                                   constraintWithItem:self
+                                                   attribute:NSLayoutAttributeWidth
+                                                   relatedBy:NSLayoutRelationEqual
+                                                   toItem:masterView
+                                                   attribute:NSLayoutAttributeWidth
+                                                   multiplier:1.0
+                                                   constant:0];
+    
+    NSLayoutConstraint *pullDownHeightMaxConstraint = [NSLayoutConstraint
+                                                       constraintWithItem:self
+                                                       attribute:NSLayoutAttributeHeight
+                                                       relatedBy:NSLayoutRelationLessThanOrEqual
+                                                       toItem:masterView
+                                                       attribute:NSLayoutAttributeHeight
+                                                       multiplier:0.5
+                                                       constant:0];
+    
+    pullDownHeightMaxConstraint.priority = 1000;
+    
+    NSLayoutConstraint *pullDownHeightConstraint = [NSLayoutConstraint
+                                                    constraintWithItem:self
+                                                    attribute:NSLayoutAttributeHeight
+                                                    relatedBy:0
+                                                    toItem:nil
+                                                    attribute:NSLayoutAttributeNotAnAttribute
+                                                    multiplier:1.0
+                                                    constant:tableHeight+handleHeight];
+    
+    pullDownHeightConstraint.priority = 900;
+    
+    NSLayoutConstraint *pullHandleWidthConstraint = [NSLayoutConstraint
+                                                     constraintWithItem:handle
+                                                     attribute:NSLayoutAttributeWidth
+                                                     relatedBy:NSLayoutRelationEqual
+                                                     toItem:masterView
+                                                     attribute:NSLayoutAttributeWidth
+                                                     multiplier:1.0
+                                                     constant:0];
+    
+    NSLayoutConstraint *pullHandleHeightConstraint = [NSLayoutConstraint
+                                                      constraintWithItem:handle
+                                                      attribute:NSLayoutAttributeHeight
+                                                      relatedBy:0
+                                                      toItem:nil
+                                                      attribute:NSLayoutAttributeNotAnAttribute
+                                                      multiplier:1.0
+                                                      constant:handleHeight];
+    
+    NSLayoutConstraint *pullHandleBottomPositionConstraint = [NSLayoutConstraint
+                                                              constraintWithItem:handle
+                                                              attribute:NSLayoutAttributeBottom
+                                                              relatedBy:NSLayoutRelationEqual
+                                                              toItem:self
+                                                              attribute:NSLayoutAttributeBottom
+                                                              multiplier:1.0
+                                                              constant:0];
+    
+    NSLayoutConstraint *pullHandleCenterPositionConstraint = [NSLayoutConstraint
+                                                              constraintWithItem:handle
+                                                              attribute:NSLayoutAttributeCenterX
+                                                              relatedBy:0
+                                                              toItem:self
+                                                              attribute:NSLayoutAttributeCenterX
+                                                              multiplier:1.0
+                                                              constant:0];
+    
+    NSLayoutConstraint *menuListHeightMaxConstraint = [NSLayoutConstraint
+                                                       constraintWithItem:menuList
+                                                       attribute:NSLayoutAttributeHeight
+                                                       relatedBy:NSLayoutRelationLessThanOrEqual
+                                                       toItem:masterView
+                                                       attribute:NSLayoutAttributeHeight
+                                                       multiplier:1.0
+                                                       constant:-topMargin];
+    
+    NSLayoutConstraint *menuListHeightConstraint = [NSLayoutConstraint
+                                                    constraintWithItem:menuList
+                                                    attribute:NSLayoutAttributeHeight
+                                                    relatedBy:NSLayoutRelationEqual
+                                                    toItem:self
+                                                    attribute:NSLayoutAttributeHeight
+                                                    multiplier:1.0
+                                                    constant:-handleHeight];
+    
+    NSLayoutConstraint *menuListWidthConstraint = [NSLayoutConstraint
+                                                   constraintWithItem:menuList
+                                                   attribute:NSLayoutAttributeWidth
+                                                   relatedBy:NSLayoutRelationEqual
+                                                   toItem:self
+                                                   attribute:NSLayoutAttributeWidth
+                                                   multiplier:1.0
+                                                   constant:0];
+    
+    NSLayoutConstraint *menuListCenterXPositionConstraint = [NSLayoutConstraint
+                                                             constraintWithItem:menuList
+                                                             attribute:NSLayoutAttributeCenterX
+                                                             relatedBy:NSLayoutRelationEqual
+                                                             toItem:self
+                                                             attribute:NSLayoutAttributeCenterX
+                                                             multiplier:1.0
+                                                             constant:0];
+    
+    NSLayoutConstraint *menuListTopPositionConstraint = [NSLayoutConstraint
+                                                         constraintWithItem:menuList
+                                                         attribute:NSLayoutAttributeTop
+                                                         relatedBy:NSLayoutRelationEqual
+                                                         toItem:self
+                                                         attribute:NSLayoutAttributeTop
+                                                         multiplier:1.0
+                                                         constant:0];
+    
+    [masterView addConstraint: pullDownTopPositionConstraint];
+    [masterView addConstraint: pullDownCenterXPositionConstraint];
+    [masterView addConstraint: pullDownWidthConstraint];
+    [masterView addConstraint: pullDownHeightConstraint];
+    [masterView addConstraint: pullDownHeightMaxConstraint];
+    
+    [masterView addConstraint: pullHandleHeightConstraint];
+    [masterView addConstraint: pullHandleWidthConstraint];
+    [masterView addConstraint: pullHandleBottomPositionConstraint];
+    [masterView addConstraint: pullHandleCenterPositionConstraint];
+    
+    [masterView addConstraint: menuListHeightMaxConstraint];
+    [masterView addConstraint: menuListHeightConstraint];
+    [masterView addConstraint: menuListWidthConstraint];
+    [masterView addConstraint: menuListCenterXPositionConstraint];
+    [masterView addConstraint: menuListTopPositionConstraint];
+    
+}
+
+- (void)deviceOrientationDidChange:(NSNotification *)notification
+{
+    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
+    
+    if (orientation == UIDeviceOrientationFaceUp || orientation == UIDeviceOrientationFaceDown || orientation == UIDeviceOrientationUnknown || currentOrientation == orientation) {
+        return;
+    }
+    
+    currentOrientation = orientation;
+    
+    [self performSelector:@selector(orientationChanged) withObject:nil afterDelay:0];
+}
+
+- (void)orientationChanged
+{
+    [self updateValues];
+    
+    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
+    if ((UIDeviceOrientationIsPortrait(currentOrientation) && UIDeviceOrientationIsPortrait(orientation)) ||
+        (UIDeviceOrientationIsLandscape(currentOrientation) && UIDeviceOrientationIsLandscape(orientation))) {
+        
+        currentOrientation = orientation;
+        
+        if (fullyOpen)
+        {
+            [self animateDropDown];
+        }
+        
+        return;
+    }
+}
+
+- (void)updateValues
+{
+    topMargin = 0;
+    
+    BOOL isStatusBarShowing = ![[UIApplication sharedApplication] isStatusBarHidden];
+    
+    if (UIInterfaceOrientationIsLandscape(self.window.rootViewController.interfaceOrientation)) {
+        if (isStatusBarShowing) { topMargin = [UIApplication.sharedApplication statusBarFrame].size.width; }
+        topMargin += topMarginLandscape;
+    }
+    else
+    {
+        if (isStatusBarShowing) { topMargin = [UIApplication.sharedApplication statusBarFrame].size.height; }
+        topMargin += topMarginPortrait;
+    }
+    
+    if (masterNavigationController != nil)
+    {
+        topMargin += masterNavigationController.navigationBar.frame.size.height;
+    }
+}
+
+@end

+ 5 - 2
Apex Mobile/Apex Mobile/ResultViewController.h

@@ -12,9 +12,12 @@
 #import "ApexMobileNetwork.h"
 #import "PageData.h"
 #import "DetailTabBarController.h"
+#import "PulldownMenu.h"
 
-
-@interface ResultViewController : UIViewController<SimpleGridDelegate>
+@interface ResultViewController : UIViewController<SimpleGridDelegate,PulldownMenuDelegate,UIAlertViewDelegate>
+{
+    PulldownMenu *pulldownMenu;
+}
 @property (strong, nonatomic) IBOutlet SimpleGrid *grid;
 @property (strong,nonatomic) NSString* function_name;
 @property (strong,nonatomic) NSMutableDictionary* params;

+ 188 - 25
Apex Mobile/Apex Mobile/ResultViewController.m

@@ -48,10 +48,10 @@
             
             if(self.recordCount>=0)
             {
-            if(self.recordCount<2000)
-                self.countView.title = [NSString stringWithFormat:@"%ld records",self.recordCount];
-            else
-                self.countView.title = @"2000+ records";
+                if(self.recordCount<2000)
+                    self.countView.title = [NSString stringWithFormat:@"%ld records",self.recordCount];
+                else
+                    self.countView.title = @"2000+ records";
             }
             else
             {
@@ -66,6 +66,10 @@
             else
                 self.nextpageButton.enabled=true;
             [self.grid initgrid :self.pageData];
+            
+            CGPoint p = self.grid.frame.origin;
+            
+            
             self.mum.hidden = true;
             self.grid.hidden = false;
             [UIView commitAnimations];
@@ -75,7 +79,7 @@
 }
 - (void) showDetail:(UIMenuItem*) sender
 {
-      DebugLog(@"show detail id = %@",self.detail_id);
+    DebugLog(@"show detail id = %@",self.detail_id);
     NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithDictionary:self.params copyItems:true];
     
     
@@ -103,14 +107,132 @@
     else
         return NO;//不显示
 }
+
+-(void)menuItemSelected:(NSIndexPath *)indexPath
+{
+    NSLog(@"%ld",indexPath.item);
+    [pulldownMenu animateDropDown];
+    if(indexPath.item==0)
+    {
+        CustomizeFieldViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"CustomizeFieldViewController"];
+        ViewController.function_name = self.function_name;
+        ViewController.behavior =BEHAVIOR_RESULT;
+        self.dirty=true;
+        //    ViewController.dirty = self.dirty;
+        
+        [self.navigationController pushViewController:ViewController animated:YES];
+    }
+    else
+    {
+        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Create a tag to save" message:@"You can find saved search at tools->Save Detail/Search" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Save",nil];
+        alert.alertViewStyle = UIAlertViewStylePlainTextInput;
+        
+        UITextField * txt = [[UITextField alloc] init];
+        
+        txt.backgroundColor = [UIColor yellowColor];
+        
+        txt.frame = CGRectMake(alert.center.x+65,alert.center.y+48, 150,23);
+        //        [alert addSubview:txt];
+        [alert show];
+        
+    }
+}
+- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
+{
+    
+    if(buttonIndex!=alertView.cancelButtonIndex)
+    {
+        UITextField * txt=[alertView textFieldAtIndex:0];
+        NSString* name = txt.text;
+        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self.params
+                                                           options:0
+                                                             error:nil];
+        NSString* param = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
+        ApexMobileAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
+        NSString* user = appDelegate.user;
+        
+        sqlite3 *db =[ApexMobileDB get_db];
+        
+        [ApexMobileDB execSql: [NSString stringWithFormat: @"insert into history(params,name,module_name,user) values('%@','%@','%@','%@')",param,name,self.function_name,user] db:db];
+        
+        sqlite3_close(db);
+        
+        //NSString *jsonString =
+        /*
+         String name = ((EditText) edit)
+         .getText().toString();
+         String param = getIntent().toUri(0);
+         
+         JSONObject obj = new JSONObject();
+         Set<String> keys = searchParms.keySet();
+         for (String key : keys)
+         {
+         
+         
+         try
+         {
+         obj.put(key, searchParms.get(key).toString());
+         
+         }
+         catch (JSONException e)
+         {
+         // TODO Auto-generated catch block
+         e.printStackTrace();
+         }
+         
+         }
+         obj.toString();
+         
+         SQLiteDatabase db = dbUtil.OpenDB(
+         ApexTrackingApplication.get_instance(), null, true);
+         db.execSQL("insert into history(params,name,criterion,module_name,user,create_time) values('"
+         
+         + param
+         + "','"
+         + name
+         + "','"
+         + obj.toString()
+         + "','"
+         + function_name
+         + "','"
+         + ApexTrackingApplication.get_user()
+         + "',"
+         + System.currentTimeMillis() + ")");
+         dbUtil.CloseDB(db);
+         
+         */
+        
+    }
+    
+    
+}
+-(void)pullDownAnimated:(BOOL)open
+{
+    if (open)
+    {
+        NSLog(@"Pull down menu open!");
+    }
+    else
+    {
+        NSLog(@"Pull down menu closed!");
+    }
+}
+
 - (IBAction)onCustomize:(UIBarButtonItem *)sender {
-    CustomizeFieldViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"CustomizeFieldViewController"];
-    ViewController.function_name = self.function_name;
-    ViewController.behavior =BEHAVIOR_RESULT;
-    self.dirty=true;
-    //    ViewController.dirty = self.dirty;
     
-    [self.navigationController pushViewController:ViewController animated:YES];
+    
+    
+    CGRect ff = self.navigationController.navigationBar.frame;
+    //    : CGPointMake(0.0f,self.navigationController.navigationBar.frame.size.height)
+    
+    [pulldownMenu animateDropDown:CGPointMake(0.0f,self.navigationController.navigationBar.frame.size.height)];
+    //    CustomizeFieldViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"CustomizeFieldViewController"];
+    //    ViewController.function_name = self.function_name;
+    //    ViewController.behavior =BEHAVIOR_RESULT;
+    //    self.dirty=true;
+    //    //    ViewController.dirty = self.dirty;
+    //
+    //    [self.navigationController pushViewController:ViewController animated:YES];
 }
 - (BOOL)canBecomeFirstResponder{
     return YES;
@@ -126,7 +248,7 @@
 }
 - (void) LongPress:(UIView*)view _id:(NSString*) _id
 {
-      DebugLog(@"!!!!!!!!!!!!!!!!!");
+    DebugLog(@"!!!!!!!!!!!!!!!!!");
     self.actions = [self getActions];
     
     if(self.actions.count<1)
@@ -158,7 +280,7 @@
 
 -(NSArray*) getActions
 {
-      DebugLog(@"getActions");
+    DebugLog(@"getActions");
     
     ApexMobileAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
     
@@ -172,16 +294,16 @@
     sqlite3_stmt *stmt;
     
     if (sqlite3_prepare_v2(db, [quary UTF8String], -1, &stmt, nil) == SQLITE_OK) {
-          DebugLog(@"sql:%@",quary);
-          DebugLog(@"=======================show fields===================");
+        DebugLog(@"sql:%@",quary);
+        DebugLog(@"=======================show tabs===================");
         while (sqlite3_step(stmt)==SQLITE_ROW)
         {
             
             NSString *name = [[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(stmt, 0)];
             [actions addObject:name];
-              DebugLog(@"action name: %@",name);
+            DebugLog(@"action name: %@",name);
         }
-          DebugLog(@"=======================show fields===================");
+        DebugLog(@"=======================show tabs===================");
         sqlite3_finalize(stmt);
     }
     //用完了一定记得关闭,释放内存
@@ -192,7 +314,7 @@
 {
     //    NSMutableDictionary* header = [[NSMutableDictionary alloc] init];
     //    [header setValue:@"aaa" forKey:@"bbb"];
-      DebugLog(@"initHeader");
+    DebugLog(@"initHeader");
     ApexMobileAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
     
     sqlite3 *db =[ApexMobileDB get_db];
@@ -203,8 +325,8 @@
     sqlite3_stmt *stmt;
     
     if (sqlite3_prepare_v2(db, [quary UTF8String], -1, &stmt, nil) == SQLITE_OK) {
-          DebugLog(@"sql:%@",quary);
-          DebugLog(@"=======================show fields===================");
+        DebugLog(@"sql:%@",quary);
+        DebugLog(@"=======================show fields===================");
         while (sqlite3_step(stmt)==SQLITE_ROW)
         {
             NSString *aname = [[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(stmt, 0)];
@@ -212,10 +334,10 @@
             //            [header setValue:aname forKey:name];
             [header_name addObject:name];
             [header_aname addObject:aname];
-              DebugLog(@"%@",aname);
+            DebugLog(@"%@",aname);
             
         }
-          DebugLog(@"=======================show fields===================");
+        DebugLog(@"=======================show fields===================");
         sqlite3_finalize(stmt);
     }
     //用完了一定记得关闭,释放内存
@@ -252,6 +374,11 @@
 {
     [super viewDidLoad];
     
+    
+    
+    
+    
+    
     NSString* title=@"";
     if([self.function_name isEqualToString:@"Ocean Booking"])
         title = @"Booking Result";
@@ -264,14 +391,49 @@
     self.navigationItem.title = title;
     UIBarButtonItem *backButton = [[UIBarButtonItem alloc] init];
     backButton.title = @"Back";
+    
     self.navigationItem.backBarButtonItem = backButton;
     
+   // self.navigationController.view.frame.size.height;
+    
+    //    NSMutableArray * items = [[NSMutableArray alloc]init];
+    //    UIBarButtonItem *item1 = [[UIBarButtonItem alloc] init];
+    //    item1.title = @"item1";
+    //    item1.image = [UIImage imageNamed:@"rect_setting"];
+    //    UIBarButtonItem *item2 = [[UIBarButtonItem alloc] init];
+    //    item2.image = [UIImage imageNamed:@"rect_about"];
+    //    item2.title = @"item2";
+    //    [items addObject:item1];
+    //    [items addObject:item2];
+    //    self.navigationItem.rightBarButtonItems=items;
+//    self.navigationItem.backBarButtonItem = backButton;
+    
+    
     self.dirty = @"true";
     
     if([self.function_name isEqualToString:@"Download Document"])
         self.fullrow_select =false;
     else
         self.fullrow_select=true;
+    
+    
+    
+    pulldownMenu = [[PulldownMenu alloc] initWithView:self.view];
+    [self.view addSubview:pulldownMenu];
+    
+    [pulldownMenu insertButton:@"Setting"];
+    [pulldownMenu insertButton:@"Save Search"];
+    
+    
+    pulldownMenu.delegate = self;
+    //    self.navigationItem.rightBarButtonItems
+    
+    [pulldownMenu loadMenu];
+    
+    
+    
+    
+    
     UIRefreshControl *ref = [[UIRefreshControl alloc]init];
     ref.tag = 200 ;
     ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"drag to refresh"];
@@ -279,14 +441,14 @@
     //    ref.hidden = true;
     [ref addTarget:self action:@selector(changeCell) forControlEvents:UIControlEventValueChanged];
     [self.grid addSubview:ref];
-   
+    
 }
 -(void)changeCell
 {
     UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
     reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"refreshing"];
     [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
-      DebugLog(@"refresh!!!!!!!!");
+    DebugLog(@"refresh!!!!!!!!");
     
 }
 
@@ -304,7 +466,7 @@
 
 - (void)viewWillAppear:(BOOL)animated
 {
-      DebugLog(@"viewWillAppear");
+    DebugLog(@"viewWillAppear");
     if(self.dirty ==true)
     {
         self.prepageCount=0;
@@ -332,6 +494,7 @@
         
         [self loadpage];
         self.dirty = false;
+        //            [pulldownMenu loadMenu:self.grid.frame.origin];
     }
 }
 //-(NSUInteger)supportedInterfaceOrientations

+ 1 - 1
Apex Mobile/Apex Mobile/SearchViewController.h

@@ -8,7 +8,7 @@
 
 #import <UIKit/UIKit.h>
 #import "CustomizeFieldViewController.h"
-
+#import "MyAutocompleteView.h"
 
 @interface SearchViewController : UIViewController <UITableViewDataSource,UITableViewDelegate,UIActionSheetDelegate,UIAlertViewDelegate>
 @property (strong,nonatomic) NSString* function_name;

+ 18 - 1
Apex Mobile/Apex Mobile/SearchViewController.m

@@ -13,7 +13,7 @@
 #import "TableCellEdit.h"
 #import "TableCellDate.h"
 #import "TableCellBool.h"
-
+#import "MyAutocompleteView.h"
 @interface SearchViewController ()
 @property (strong,nonatomic) SearchTableAdapter* adapter ;
 @end
@@ -215,6 +215,23 @@
         [cell.anameLabel sizeToFit];
         NSString * val = [field valueForKey:@"value"];
         cell.valueEdit.text = val;
+        
+        MyAutocompleteView* autocompleteView = [MyAutocompleteView autocompleteViewBindedTo:cell.valueEdit
+                                                                 usingSource:[[MyAutocompleteItemsSource alloc]
+                                                                              initWithMinimumCharactersToTrigger:1
+                                                                              ]
+                                                                 cellFactory:[[MyAutocompletionCellFactory alloc]
+                                                                              initWithCellTextColor:[UIColor blackColor]
+                                                                              fontSize:14]
+                                                                presentingIn:self];
+        autocompleteView.topMargin = 0;
+        //    self.autocompleteView.backgroundColor = [UIColor ui];
+        
+        autocompleteView.didAutocompleteWith = ^(MySuggestion* item)
+        {
+            NSLog(@"Autocompleted with: %@",  item.completionText);
+        };
+        cell.autocompleteView = autocompleteView;
 //        if(val.length==0)
 
           DebugLog(@"cellForRowAtIndexPath%@",[field valueForKey:@"aname"]);

+ 13 - 0
Apex Mobile/Apex Mobile/SimpleMenu.h

@@ -0,0 +1,13 @@
+//
+//  SimpleMenu.h
+//  Apex Mobile
+//
+//  Created by Ray on 14-4-22.
+//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface SimpleMenu : UIView
+- (void)addItem:(NSString*)text;
+@end

+ 42 - 0
Apex Mobile/Apex Mobile/SimpleMenu.m

@@ -0,0 +1,42 @@
+//
+//  SimpleMenu.m
+//  Apex Mobile
+//
+//  Created by Ray on 14-4-22.
+//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
+//
+
+#import "SimpleMenu.h"
+
+@implementation SimpleMenu
+
+- (id)initWithFrame:(CGRect)frame
+{
+    self = [super initWithFrame:frame];
+    if (self) {
+        // Initialization code
+    }
+    return self;
+}
+- (instancetype)init
+{
+    self = [super init];
+    if (self) {
+        ;
+    }
+    return self;
+}
+- (void)addItem:(NSString*)text
+{
+    
+}
+/*
+// Only override drawRect: if you perform custom drawing.
+// An empty implementation adversely affects performance during animation.
+- (void)drawRect:(CGRect)rect
+{
+    // Drawing code
+}
+*/
+
+@end

+ 2 - 2
Apex Mobile/Apex Mobile/TableCellEdit.h

@@ -7,9 +7,9 @@
 //
 
 #import <UIKit/UIKit.h>
-
+#import "MyAutocompleteView.h"
 @interface TableCellEdit : UITableViewCell
 @property (strong, nonatomic) IBOutlet UILabel *anameLabel;
 @property (strong, nonatomic) IBOutlet UITextField *valueEdit;
-
+@property (strong,nonatomic) MyAutocompleteView * autocompleteView;
 @end

+ 20 - 0
Apex Mobile/Apex Mobile/ToolsPanelViewController.h

@@ -0,0 +1,20 @@
+//
+//  ToolsPanelViewController.h
+//  Apex Mobile
+//
+//  Created by Ray on 14-4-17.
+//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+#import "Constant.h"
+#import "NewsViewController.h"
+#import "SearchViewController.h"
+#import "ChangePasswordViewController.h"
+#import "ApexHistoryViewController.h"
+#import "AboutViewController.h"
+#import "HistoryTabBarController.h"
+@interface ToolsPanelViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>
+@property (strong,nonatomic) NSMutableArray * toolsinfo;
+@property BOOL showNavigation;
+@end

+ 195 - 0
Apex Mobile/Apex Mobile/ToolsPanelViewController.m

@@ -0,0 +1,195 @@
+//
+//  ToolsPanelViewController.m
+//  Apex Mobile
+//
+//  Created by Ray on 14-4-17.
+//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
+//
+
+#import "ToolsPanelViewController.h"
+
+@interface ToolsPanelViewController ()
+
+@end
+
+@implementation ToolsPanelViewController
+
+- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
+{
+    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
+    if (self) {
+        
+        // Custom initialization
+    }
+    return self;
+}
+-(void)initpanel
+{
+    self.toolsinfo = [[NSMutableArray alloc] init];
+    
+    NSMutableDictionary* map = [[NSMutableDictionary alloc] init];
+    
+    [map setValue:@"Market news" forKey:@"title"];
+    [map setValue:@"rect_market_news" forKey:@"img"];
+    [self.toolsinfo addObject:map.copy];
+    
+    [map setValue:@"Announcements" forKey:@"title"];
+    [map setValue:@"rect_announcements" forKey:@"img"];
+    [self.toolsinfo addObject:map.copy];
+    
+    
+    if(true)
+    {
+        
+        [map setValue:@"Saved Detail/Search" forKey:@"title"];
+        [map setValue:@"rect_search_history" forKey:@"img"];
+        [self.toolsinfo addObject:map.copy];
+        
+        
+        [map setValue:@"Change Password" forKey:@"title"];
+        [map setValue:@"rect_change_password" forKey:@"img"];
+        [self.toolsinfo addObject:map.copy];
+        
+        [map setValue:@"Setting" forKey:@"title"];
+        [map setValue:@"rect_setting" forKey:@"img"];
+        [self.toolsinfo addObject:map.copy];
+    }
+
+    
+    [map setValue:@"Apex History" forKey:@"title"];
+    [map setValue:@"rect_history" forKey:@"img"];
+    [self.toolsinfo addObject:map.copy];
+    
+    [map setValue:@"About this App" forKey:@"title"];
+    [map setValue:@"rect_about" forKey:@"img"];
+    [self.toolsinfo addObject:map.copy];
+    
+    
+    //
+    
+}
+
+- (void)viewDidLoad
+{
+    [super viewDidLoad];
+  //
+
+    
+    [self initpanel];
+    // Do any additional setup after loading the view.
+}
+- (void)viewWillAppear:(BOOL)animated
+{
+    if(self.showNavigation==false)
+    [self.navigationController setNavigationBarHidden:true];
+}
+- (void)viewWillDisappear:(BOOL)animated
+{
+    if(self.showNavigation==false)
+    [self.navigationController setNavigationBarHidden:false];
+}
+
+- (void)didReceiveMemoryWarning
+{
+    [super didReceiveMemoryWarning];
+    // Dispose of any resources that can be recreated.
+}
+
+/*
+ #pragma mark - Navigation
+ 
+ // In a storyboard-based application, you will often want to do a little preparation before navigation
+ - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
+ {
+ // Get the new view controller using [segue destinationViewController].
+ // Pass the selected object to the new view controller.
+ }
+ */
+
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
+{
+    
+    return 1;
+}
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
+{
+    
+    return self.toolsinfo.count;
+    
+    
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    DebugLog(@"cellForRowAtIndexPath");
+    
+    NSString *CellIdentifier = @"tools";
+    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
+    NSString* title = [self.toolsinfo[indexPath.row] valueForKey:@"title"];
+    
+    //    UIImageView* iv= [[UIImageView alloc] initWithImage:];
+    cell.textLabel.text = title;
+    cell.imageView.image = [UIImage imageNamed:[self.toolsinfo[indexPath.row] valueForKey:@"img"]];
+    
+    return cell;
+    
+    
+}
+
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    
+//    SearchViewController *searchViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"NewsView"];
+//    searchViewController.function_name = @"Download Document";
+//    [self.navigationController pushViewController:searchViewController animated:YES];
+//    return;
+    
+    NSString* title = [self.toolsinfo[indexPath.row] valueForKey:@"title"];
+    if([title isEqualToString:@"Market news"])
+    {
+        NewsViewController *viewcontroller=[self.storyboard instantiateViewControllerWithIdentifier:@"NewsView"];
+        viewcontroller.module_name = @"Market news";
+        [self.navigationController pushViewController:viewcontroller animated:YES];
+    }
+    else if([title isEqualToString:@"Announcements"])
+    {
+        NewsViewController *viewcontroller=[self.storyboard instantiateViewControllerWithIdentifier:@"NewsView"];
+        viewcontroller.module_name = @"Announcements";
+        [self.navigationController pushViewController:viewcontroller animated:YES];
+    }
+    else if([title isEqualToString:@"Saved Detail/Search"])
+    {
+        
+        HistoryTabBarController *viewcontroller=[[HistoryTabBarController alloc] init];
+        
+        [self.navigationController pushViewController:viewcontroller animated:YES];
+
+    }
+    else if([title isEqualToString:@"Change Password"])
+    {
+        ChangePasswordViewController *viewcontroller=[self.storyboard instantiateViewControllerWithIdentifier:@"ChangePassword"];
+//        newsview.module_name = @"Market news";
+        [self.navigationController pushViewController:viewcontroller animated:YES];
+    }
+//    else if([title isEqualToString:@"Setting"])
+//    {
+//        ChangePasswordViewController *newsview=[self.storyboard instantiateViewControllerWithIdentifier:@"Setting"];
+////        newsview.module_name = @"Market news";
+//        [self.navigationController pushViewController:newsview animated:YES];
+//    }
+    else if([title isEqualToString:@"Apex History"])
+    {
+         ApexHistoryViewController *viewcontroller=[self.storyboard instantiateViewControllerWithIdentifier:@"ApexHistory"];
+//        newsview.module_name = @"Market news";
+        [self.navigationController pushViewController:viewcontroller animated:YES];
+    }
+    else if([title isEqualToString:@"About this App"])
+    {
+        AboutViewController *viewcontroller=[self.storyboard instantiateViewControllerWithIdentifier:@"About"];
+//        newsview.module_name = @"Market news";
+        [self.navigationController pushViewController:viewcontroller animated:YES];
+    }
+}
+
+@end

+ 18 - 0
Apex Mobile/FavoritesViewController.h

@@ -0,0 +1,18 @@
+//
+//  FavoritesViewController.h
+//  Apex Mobile
+//
+//  Created by Ray on 14-4-25.
+//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+#import "FavoritesData.h"
+#import "CellItemHistory.h"
+#import "DetailTabBarController.h"
+@interface FavoritesViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>
+//@property (strong,nonatomic) NSString* module_name;
+@property (strong, nonatomic) IBOutlet UITableView *tableview;
+@property (strong,nonatomic) FavoritesData* data;
+
+@end

+ 127 - 0
Apex Mobile/FavoritesViewController.m

@@ -0,0 +1,127 @@
+//
+//  FavoritesViewController.m
+//  Apex Mobile
+//
+//  Created by Ray on 14-4-25.
+//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
+//
+
+#import "FavoritesViewController.h"
+
+@interface FavoritesViewController ()
+
+@end
+
+@implementation FavoritesViewController
+
+- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
+{
+    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
+    if (self) {
+        // Custom initialization
+    }
+    return self;
+}
+
+- (void)viewDidLoad
+{
+    [super viewDidLoad];
+    
+
+            
+            self.data =[[FavoritesData alloc]init];
+            [self.tableview reloadData];
+
+    
+}
+-(void)viewWillAppear:(BOOL)animated
+{
+
+}
+
+- (void)didReceiveMemoryWarning
+{
+    [super didReceiveMemoryWarning];
+    // Dispose of any resources that can be recreated.
+}
+
+/*
+ #pragma mark - Navigation
+ 
+ // In a storyboard-based application, you will often want to do a little preparation before navigation
+ - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
+ {
+ // Get the new view controller using [segue destinationViewController].
+ // Pass the selected object to the new view controller.
+ }
+ */
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
+{
+    
+    return 1;
+}
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
+{
+    
+    return [self.data get_count];
+    
+    
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    DebugLog(@"cellForRowAtIndexPath");
+    
+    NSString *CellIdentifier = @"cell_item_history";
+    CellItemHistory *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
+    NSString* name = [self.data.pagedata[indexPath.row] valueForKey:@"name"];
+    NSString* create_time = [self.data.pagedata[indexPath.row] valueForKey:@"create_time"];
+    
+    
+    cell.name.text = name;
+    [cell.name sizeToFit];
+    
+    cell.time.text =create_time;
+    [cell.time sizeToFit];
+    
+    //    cell.imageView.image = [UIImage imageNamed:[self.toolsinfo[indexPath.row] valueForKey:@"img"]];
+    
+    return cell;
+    
+    
+}
+
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    
+//    NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithDictionary:self.params copyItems:true];
+    
+    
+    NSString* str_params =[self.data.pagedata[indexPath.row] valueForKey:@"params"];
+    NSData* data_params = [str_params dataUsingEncoding:NSUTF8StringEncoding];
+    
+    
+    
+    NSMutableDictionary* params = [[NSMutableDictionary alloc] initWithDictionary:[NSJSONSerialization
+                                                                                   JSONObjectWithData:data_params
+                                                                                   options:NSJSONReadingMutableLeaves
+                                                                                   error:nil] copyItems:true];
+    
+    
+    NSString * str_actions =[self.data.pagedata[indexPath.row] valueForKey:@"action"];
+    NSArray* actions = [str_actions componentsSeparatedByString:@","];
+    
+    NSString* function_name = [self.data.pagedata[indexPath.row] valueForKey:@"module_name"];
+    
+    DetailTabBarController *detailViewController=[[DetailTabBarController alloc] init:function_name actions:actions params:params];
+    
+    
+    //        DetailTabBarController *detailViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailTabBarController"];
+    //        detailViewController.function_name = self.function_name;
+    //        detailViewController.actions = self.actions;
+    //        detailViewController.params =params;
+    [self.navigationController pushViewController:detailViewController animated:YES];
+
+}
+
+@end

BIN
Apex Mobile/GoogleMaps.framework/.DS_Store