admobViewController.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. //
  2. // admobViewController.m
  3. // sjvodios
  4. //
  5. // Created by on 11-12-6.
  6. // Copyright (c) 2011年 __MyCompanyName__. All rights reserved.
  7. //
  8. #import "admobViewController.h"
  9. #import "AppDelegate.h"
  10. #import "versionManage.h"
  11. #import "JXImageView.h"
  12. #import "JXLabel.h"
  13. #import "UIImage+Tint.h"
  14. @implementation admobViewController
  15. @synthesize heightFooter,heightHeader,leftBarButtonItem,rightBarButtonItem,tableHeader,tableFooter,isGotoBack,tableBody,footerBtnLeft,footerBtnMid,footerBtnRight,headerTitle,isFreeOnClose;
  16. #define AdMob_REFRESH_PERIOD 60.0 // display fresh ads once per second
  17. -(id)init{
  18. self = [super init];
  19. heightHeader=JX_SCREEN_TOP;
  20. heightFooter=JX_SCREEN_BOTTOM;
  21. isFreeOnClose = YES;
  22. [g_window endEditing:YES];
  23. //self.view.frame = CGRectMake(JX_SCREEN_WIDTH, 0, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT);
  24. return self;
  25. }
  26. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
  27. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  28. if (self) {
  29. heightHeader=JX_SCREEN_TOP;
  30. heightFooter=49;
  31. isFreeOnClose = YES;
  32. }
  33. return self;
  34. }
  35. - (void)viewDidLoad
  36. {
  37. [super viewDidLoad];
  38. if (self.isGotoBack) {
  39. // self.view.frame = CGRectMake(JX_SCREEN_WIDTH, 0, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT);
  40. // [self screenEdgePanGestureRecognizer];
  41. }
  42. _wait = [ATMHud sharedInstance];
  43. if (THESIMPLESTYLE) {
  44. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
  45. }else {
  46. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
  47. }
  48. // _pSelf = self;
  49. }
  50. //创建边缘手势
  51. -(void)screenEdgePanGestureRecognizer
  52. {
  53. UIScreenEdgePanGestureRecognizer *screenPan = [[UIScreenEdgePanGestureRecognizer alloc]initWithTarget:self action:@selector(screenPanAction:)];
  54. screenPan.edges = UIRectEdgeLeft;
  55. [self.view addGestureRecognizer:screenPan];
  56. [self.tableBody.panGestureRecognizer requireGestureRecognizerToFail:screenPan];
  57. }
  58. //边缘手势事件
  59. -(void)screenPanAction:(UIScreenEdgePanGestureRecognizer *)screenPan
  60. {
  61. CGPoint p = [screenPan translationInView:self.view];
  62. NSLog(@"p = %@",NSStringFromCGPoint(p));
  63. self.view.frame = CGRectMake(p.x, 0, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT);
  64. if (screenPan.state == UIGestureRecognizerStateEnded) {
  65. if (p.x > JX_SCREEN_WIDTH/2) {
  66. [self actionQuit];
  67. }else {
  68. [self resetViewFrame];
  69. }
  70. }
  71. }
  72. - (void)dealloc {
  73. NSLog(@"dealloc - %@",[self class]);
  74. self.title = nil;
  75. self.headerTitle = nil;
  76. // [super dealloc];
  77. }
  78. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  79. {
  80. return (interfaceOrientation == UIInterfaceOrientationPortrait);
  81. }
  82. - (void)viewWillAppear:(BOOL)animated{
  83. [super viewWillAppear:animated];
  84. NSLog(@"CurrentController = %@",[self class]);
  85. //页面zuo移
  86. // if (self.isGotoBack) {
  87. // if (self.view.frame.origin.x != 0) {
  88. //// UIView *view = g_window.subviews.lastObject;
  89. // [UIView animateWithDuration:0.3 animations:^{
  90. //// view.frame = CGRectMake(-85, 0, JX_SCREEN_WIDTH, self.view.frame.size.height);
  91. // //自己归位
  92. // [self resetViewFrame];
  93. // }];
  94. // }
  95. // }
  96. }
  97. - (void)viewDidAppear:(BOOL)animated
  98. {
  99. [super viewDidAppear:animated];
  100. }
  101. - (void)viewWillDisappear:(BOOL)animated
  102. {
  103. [super viewWillDisappear:animated];
  104. }
  105. -(void)createHeaderView{
  106. tableHeader = [[UIView alloc]initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, heightHeader)];
  107. UIImageView* iv = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, heightHeader)];
  108. if (THESIMPLESTYLE) {
  109. iv.image = [[UIImage imageNamed:@"navBarBackground"] imageWithTintColor:[UIColor whiteColor]];
  110. // [self LX_SetShadowPathWith:HEXCOLOR(0xD9D9D9) shadowOpacity:0.3 shadowRadius:2 shadowPathWidth:10 view:tableHeader];
  111. }else {
  112. iv.image = [g_theme themeTintImage:@"navBarBackground"];//[UIImage imageNamed:@"navBarBackground"];
  113. }
  114. iv.userInteractionEnabled = YES;
  115. [tableHeader addSubview:iv];
  116. JXLabel* p = [[JXLabel alloc]initWithFrame:CGRectMake(60, JX_SCREEN_TOP -15- 17, JX_SCREEN_WIDTH-60*2, 20)];
  117. p.backgroundColor = [UIColor clearColor];
  118. p.textAlignment = NSTextAlignmentCenter;
  119. p.textColor = THESIMPLESTYLE ? [UIColor blackColor] : [UIColor whiteColor];;
  120. p.text = self.title;
  121. p.font = [UIFont systemFontOfSize:18.0];
  122. p.userInteractionEnabled = YES;
  123. p.didTouch = @selector(actionTitle:);
  124. p.delegate = self;
  125. p.changeAlpha = NO;
  126. [tableHeader addSubview:p];
  127. // [p release];
  128. self.headerTitle = p;
  129. if(isGotoBack){
  130. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, JX_SCREEN_TOP - 46, 46, 46)];
  131. [btn setBackgroundImage:[UIImage imageNamed:@"title_back_black_big"] forState:UIControlStateNormal];
  132. [btn addTarget:self action:@selector(actionQuit) forControlEvents:UIControlEventTouchUpInside];
  133. [self.tableHeader addSubview:btn];
  134. }
  135. }
  136. -(void)createFooterView{
  137. tableFooter = [[UIView alloc]initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, heightFooter)];
  138. tableFooter.backgroundColor = [UIColor whiteColor];
  139. UIView* line = [[UIView alloc]initWithFrame:CGRectMake(0,0,JX_SCREEN_WIDTH,LINE_WH)];
  140. line.backgroundColor = THE_LINE_COLOR;
  141. [tableFooter addSubview:line];
  142. UIButton* btn;
  143. if(isGotoBack)
  144. return;
  145. btn = [UIButton buttonWithType:UIButtonTypeCustom];
  146. btn.frame = CGRectMake((JX_SCREEN_WIDTH-76)/2, (49-36)/2, 152/2, 72/2);
  147. // btn.showsTouchWhenHighlighted = YES;
  148. [btn setBackgroundImage:[UIImage imageNamed:@"singing_button_normal"] forState:UIControlStateNormal];
  149. [btn setBackgroundImage:[UIImage imageNamed:@"singing_button_press"] forState:UIControlStateHighlighted];
  150. [btn addTarget:self action:@selector(onSing) forControlEvents:UIControlEventTouchUpInside];
  151. [tableFooter addSubview:btn];
  152. // [btn release];
  153. self.footerBtnMid = btn;
  154. btn = [UIButton buttonWithType:UIButtonTypeCustom];
  155. btn.frame = CGRectMake(JX_SCREEN_WIDTH-53-5, (49-33)/2, 53, 66/2);
  156. // btn.showsTouchWhenHighlighted = YES;
  157. [btn setBackgroundImage:[UIImage imageNamed:@"nearby_button_normal"] forState:UIControlStateNormal];
  158. [btn setBackgroundImage:[UIImage imageNamed:@"nearby_button_press"] forState:UIControlStateHighlighted];
  159. [btn addTarget:self action:@selector(onBtnRight) forControlEvents:UIControlEventTouchUpInside];
  160. [tableFooter addSubview:btn];
  161. // [btn release];
  162. self.footerBtnRight = btn;
  163. }
  164. -(void)createHeadAndFoot{
  165. int heightTotal = self.view.frame.size.height;
  166. if(heightHeader>0){
  167. [self createHeaderView];
  168. [self.view addSubview:tableHeader];
  169. // [tableHeader release];
  170. }
  171. if(heightFooter>0){
  172. [self createFooterView];
  173. [self.view addSubview:tableFooter];
  174. // [tableFooter release];
  175. tableFooter.frame = CGRectMake(0,heightTotal-heightFooter,self_width,heightFooter);
  176. }
  177. tableBody = [[UIScrollView alloc]init];
  178. tableBody.userInteractionEnabled = YES;
  179. tableBody.backgroundColor = [UIColor whiteColor];
  180. tableBody.showsVerticalScrollIndicator = NO;
  181. tableBody.showsHorizontalScrollIndicator = NO;
  182. tableBody.frame =CGRectMake(0,heightHeader,self_width,heightTotal-heightHeader-heightFooter);
  183. tableBody.contentSize = CGSizeMake(self_width, tableBody.frame.size.height + LINE_WH);
  184. // [self.view addSubview:tableBody];
  185. [self.view insertSubview:tableBody atIndex:0];
  186. // [tableBody release];
  187. }
  188. -(void) onGotoHome{
  189. if(self.view.frame.origin.x == 260){
  190. // [g_App.leftView onClick];
  191. return;
  192. }
  193. CGContextRef context = UIGraphicsGetCurrentContext();
  194. [UIView beginAnimations:nil context:context];
  195. [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
  196. [UIView setAnimationDuration:0.3];
  197. self.view.frame = CGRectMake (260, 0, self_width, self.view.frame.size.height);
  198. [UIView commitAnimations];
  199. }
  200. -(void)actionQuit{
  201. [_wait stop];
  202. [g_server stopConnection:self];
  203. [g_window endEditing:YES];
  204. [g_notify removeObserver:self];
  205. // CGContextRef context = UIGraphicsGetCurrentContext();
  206. // [UIView beginAnimations:nil context:context];
  207. // [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
  208. // [UIView setAnimationDuration:0.2];
  209. // [UIView setAnimationDelegate:self];
  210. // [UIView setAnimationDidStopSelector:@selector(doQuit)];
  211. [g_navigation dismissViewController:self animated:YES];
  212. // self.view.frame = CGRectMake (JX_SCREEN_WIDTH, 0, self_width, self.view.frame.size.height);
  213. // NSInteger index = g_window.subviews.count;
  214. // if (index - 2 >= 0) {
  215. // UIView *view = g_window.subviews[index - 2];
  216. // view.frame = CGRectMake (0, 0, self_width, self.view.frame.size.height);
  217. // }
  218. // [UIView commitAnimations];
  219. }
  220. -(void)doQuit{
  221. [self.view removeFromSuperview];
  222. // if(isFreeOnClose)
  223. // _pSelf = nil;
  224. }
  225. -(void) setLeftBarButtonItem:(UIBarButtonItem*)button{
  226. leftBarButtonItem = button;
  227. // button.customView.frame = CGRectMake(7, 7, 65, 30);
  228. button.customView.frame = CGRectMake(25, JX_SCREEN_TOP - 38, 65, 30);
  229. [tableHeader addSubview:button.customView];
  230. // [button release];
  231. }
  232. -(void) setRightBarButtonItem:(UIBarButtonItem*)button{
  233. rightBarButtonItem = button;
  234. button.customView.frame = CGRectMake(self_width-65, JX_SCREEN_TOP - 38, 65, 30);
  235. [tableHeader addSubview:button.customView];
  236. // [button release];
  237. }
  238. -(void)onSing{
  239. // [g_App.leftView onSing];
  240. }
  241. -(void)onBtnRight{
  242. // [g_App.leftView onNear];
  243. }
  244. -(void)actionTitle:(JXLabel*)sender{
  245. }
  246. -(void)setTitle:(NSString *)value{
  247. self.headerTitle.text = value;
  248. [super setTitle:value];
  249. }
  250. //归位
  251. - (void)resetViewFrame{
  252. [UIView animateWithDuration:0.3 animations:^{
  253. self.view.frame = CGRectMake(0, 0, JX_SCREEN_WIDTH, self.view.frame.size.height);
  254. }];
  255. }
  256. -(void)LX_SetShadowPathWith:(UIColor *)shadowColor shadowOpacity:(CGFloat)shadowOpacity shadowRadius:(CGFloat)shadowRadius shadowPathWidth:(CGFloat)shadowPathWidth
  257. view:(UIView *)view {
  258. view.layer.masksToBounds = NO;
  259. view.layer.shadowColor = shadowColor.CGColor;
  260. view.layer.shadowOpacity = shadowOpacity;
  261. view.layer.shadowRadius = shadowRadius;
  262. view.layer.shadowOffset = CGSizeZero;
  263. CGRect shadowRect;
  264. CGFloat originX = 0;
  265. CGFloat originW = view.bounds.size.width;
  266. CGFloat originH = view.bounds.size.height;
  267. shadowRect = CGRectMake(originX, originH -shadowPathWidth/2, originW, shadowPathWidth);
  268. UIBezierPath *path =[UIBezierPath bezierPathWithRect:shadowRect];
  269. view.layer.shadowPath = path.CGPath;
  270. }
  271. @end