Created
November 10, 2012 07:07
-
-
Save vanbungkring/4050250 to your computer and use it in GitHub Desktop.
NetraSearchbox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NetraSearchBox.m | |
// Trip | |
// | |
// Created by Arie on 11/2/12. | |
#import "NetraSearchBox.h" | |
#import <QuartzCore/QuartzCore.h> | |
#import "AFNetworking.h" | |
NSArray *datasearch; | |
@implementation NetraSearchBox | |
@synthesize price_type_option; | |
@synthesize checkmark; | |
@synthesize deals_type_option; | |
@synthesize location; | |
@synthesize NetraSearch; | |
@synthesize ButtonSearch; | |
@synthesize buttonBackgroundHighlighted; | |
@synthesize buttonBackgroundNormal; | |
@synthesize textfieldBackgroundEditing; | |
@synthesize textfieldBackgroundNormal; | |
@synthesize AllButton,Package; | |
@synthesize labelForBudget; | |
@synthesize splurge_price; | |
@synthesize Flight; | |
@synthesize Hotels; | |
@synthesize All_price; | |
@synthesize backgrondPrice; | |
@synthesize budget_price; | |
@synthesize regular_price; | |
@synthesize All_price_label; | |
@synthesize splurge_price_label; | |
@synthesize regular_price_label; | |
@synthesize budget_price_label; | |
@synthesize image_for_budgetPrice; | |
@synthesize image_for_refularPrice; | |
@synthesize image_for_splurgePrice; | |
@synthesize image_for_allPrice; | |
@synthesize continuesBackground; | |
- (id)initWithFrame:(CGRect)frame { | |
[self fetchSetting]; | |
deals_type_option=@""; | |
price_type_option=@""; | |
self = [super initWithFrame:frame]; | |
if (self) { | |
continuesBackground =[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"pattern"]]; | |
continuesBackground.frame=CGRectMake(0, 56, 320, 102); | |
continuesBackground.layer.zPosition=100; | |
[self animateImageViewFromStartPosition:CGPointMake(0.0f, 56.0f) toEndPosition:CGPointMake(320.0f, 56.0f)]; | |
checkmark=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"tick-checkmark"]]; | |
checkmark.frame=CGRectMake(38.5, 249, 11, 8); | |
checkmark.layer.zPosition=2; | |
ButtonSearch =[UIButton buttonWithType:UIButtonTypeCustom]; | |
ButtonSearch.frame=CGRectMake(0, 288.5, 320, 66.5); | |
[ButtonSearch setImage:[UIImage imageNamed:@"find"] forState:UIControlStateNormal]; | |
[ButtonSearch setImage:[UIImage imageNamed:@"find-up"] forState:UIControlStateHighlighted]; | |
[ButtonSearch addTarget:self action:@selector(test:) forControlEvents:UIControlEventTouchUpInside]; | |
UIView *paddingView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 56)] autorelease]; | |
UIImage *backgorundNormal=[UIImage imageNamed:@"searchNormal"]; | |
NetraSearch =[[UITextField alloc] initWithFrame:CGRectMake(0, 0, 320, 56)]; | |
NetraSearch.leftView = paddingView; | |
NetraSearch.layer.zPosition=100; | |
NetraSearch.placeholder=@"Type your destination here"; | |
NetraSearch.leftViewMode = UITextFieldViewModeAlways; | |
NetraSearch.background=backgorundNormal; | |
NetraSearch.borderStyle = UITextBorderStyleBezel; | |
NetraSearch.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:18]; | |
NetraSearch.autocorrectionType = UITextAutocorrectionTypeNo; | |
NetraSearch.keyboardType = UIKeyboardTypeDefault; | |
NetraSearch.returnKeyType = UIReturnKeyDone; | |
NetraSearch.clearButtonMode = UITextFieldViewModeWhileEditing; | |
NetraSearch.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; | |
NetraSearch.delegate=self; | |
AllButton =[UIButton buttonWithType:UIButtonTypeCustom]; | |
AllButton.frame=CGRectMake(0, 56, 80, 102); | |
[AllButton setImage:[UIImage imageNamed:@"All-active-down"] forState:UIControlStateNormal]; | |
[AllButton setImage:[UIImage imageNamed:@"All-active"] forState:UIControlStateHighlighted]; | |
[AllButton addTarget:self action:@selector(Allbutton:) forControlEvents:UIControlEventTouchUpInside]; | |
AllButton.highlighted=YES; | |
Package =[UIButton buttonWithType:UIButtonTypeCustom]; | |
Package.frame=CGRectMake(80, 56, 80, 102); | |
[Package setImage:[UIImage imageNamed:@"Package"] forState:UIControlStateNormal]; | |
[Package setImage:[UIImage imageNamed:@"Package-active"] forState:UIControlStateHighlighted]; | |
[Package addTarget:self action:@selector(package:) forControlEvents:UIControlEventTouchUpInside]; | |
Flight =[UIButton buttonWithType:UIButtonTypeCustom]; | |
Flight.frame=CGRectMake(160, 56, 80, 102); | |
[Flight setImage:[UIImage imageNamed:@"Flight"] forState:UIControlStateNormal]; | |
[Flight setImage:[UIImage imageNamed:@"Flight-active"] forState:UIControlStateHighlighted]; | |
[Flight addTarget:self action:@selector(flight:) forControlEvents:UIControlEventTouchUpInside]; | |
Hotels =[UIButton buttonWithType:UIButtonTypeCustom]; | |
Hotels.frame=CGRectMake(240, 56, 80, 102); | |
[Hotels setImage:[UIImage imageNamed:@"Hotel"] forState:UIControlStateNormal]; | |
[Hotels setImage:[UIImage imageNamed:@"Hotel-active"] forState:UIControlStateHighlighted]; | |
[Hotels addTarget:self action:@selector(hotel:) forControlEvents:UIControlEventTouchUpInside]; | |
labelForBudget=[[UILabel alloc] initWithFrame:CGRectMake(0, 168, 320, 20)]; | |
labelForBudget.backgroundColor=[UIColor clearColor]; | |
labelForBudget.font=[UIFont fontWithName:@"HelveticaNeue-Bold" size:18]; | |
labelForBudget.textAlignment=NSTextAlignmentCenter; | |
labelForBudget.text=@"Set your budget"; | |
labelForBudget.textColor=[UIColor colorWithRed:0.753 green:0.745 blue:0.745 alpha:1]; | |
All_price_label=[[UILabel alloc] initWithFrame:CGRectMake(28, 200, 30, 20)]; | |
All_price_label.backgroundColor=[UIColor clearColor]; | |
All_price_label.font=[UIFont fontWithName:@"HelveticaNeue-Bold" size:14]; | |
All_price_label.textAlignment=NSTextAlignmentCenter; | |
All_price_label.text=@"All"; | |
All_price_label.textColor=[UIColor colorWithRed:0.431 green:0.443 blue:0.451 alpha:1]; | |
budget_price_label=[[UILabel alloc] initWithFrame:CGRectMake(86, 200, 60, 20)]; | |
budget_price_label.backgroundColor=[UIColor clearColor]; | |
budget_price_label.font=[UIFont fontWithName:@"HelveticaNeue-Bold" size:14]; | |
budget_price_label.textAlignment=NSTextAlignmentCenter; | |
budget_price_label.text=@"Budget"; | |
budget_price_label.textColor=[UIColor colorWithRed:0.431 green:0.443 blue:0.451 alpha:1]; | |
budget_price=[[UIButton alloc]init]; | |
regular_price_label=[[UILabel alloc] initWithFrame:CGRectMake(170, 200, 60, 20)]; | |
regular_price_label.backgroundColor=[UIColor clearColor]; | |
regular_price_label.font=[UIFont fontWithName:@"HelveticaNeue-Bold" size:14]; | |
regular_price_label.textAlignment=NSTextAlignmentCenter; | |
regular_price_label.text=@"Regular"; | |
regular_price_label.textColor=[UIColor colorWithRed:0.431 green:0.443 blue:0.451 alpha:1]; | |
splurge_price_label=[[UILabel alloc] initWithFrame:CGRectMake(245, 200, 60, 20)]; | |
splurge_price_label.backgroundColor=[UIColor clearColor]; | |
splurge_price_label.font=[UIFont fontWithName:@"HelveticaNeue-Bold" size:14]; | |
splurge_price_label.textAlignment=NSTextAlignmentCenter; | |
splurge_price_label.text=@"Splurge"; | |
splurge_price_label.textColor=[UIColor colorWithRed:0.431 green:0.443 blue:0.451 alpha:1]; | |
backgrondPrice=[[UIImageView alloc]initWithFrame:CGRectMake(30.5, 240, 259, 25)]; | |
backgrondPrice.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"Budget-slider"]]; | |
backgrondPrice.layer.zPosition=-1; | |
All_price =[UIButton buttonWithType:UIButtonTypeCustom]; | |
All_price.frame=CGRectMake(21.7, 231, 43, 43); | |
[All_price setImage:[UIImage imageNamed:@"all-transparent"] forState:UIControlStateNormal]; | |
[All_price setImage:[UIImage imageNamed:@"all-transparent"] forState:UIControlStateHighlighted]; | |
[All_price addTarget:self action:@selector(allBudget:) forControlEvents:UIControlEventTouchUpInside|UIControlEventTouchUpOutside]; | |
All_price.highlighted=YES; | |
image_for_allPrice=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"Circle-active-all"]]; | |
image_for_allPrice.frame=CGRectMake(21.7, 231, 43, 43); | |
image_for_allPrice.layer.zPosition=1; | |
All_price.layer.zPosition=5; | |
budget_price =[UIButton buttonWithType:UIButtonTypeCustom]; | |
budget_price.frame=CGRectMake(95.5, 231, 43, 43); | |
[budget_price setImage:[UIImage imageNamed:@"all-transparent"] forState:UIControlStateNormal]; | |
[budget_price setImage:[UIImage imageNamed:@"all-transparent"] forState:UIControlStateHighlighted]; | |
[budget_price addTarget:self action:@selector(budgetBudget:) forControlEvents:UIControlEventTouchUpInside|UIControlEventTouchUpOutside]; | |
image_for_budgetPrice=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"Circle-active-light"]]; | |
image_for_budgetPrice.frame=CGRectMake(95.5, 231, 43, 43); | |
image_for_budgetPrice.layer.zPosition=1; | |
budget_price.layer.zPosition=5; | |
regular_price =[UIButton buttonWithType:UIButtonTypeCustom]; | |
regular_price.frame=CGRectMake(177.5, 231, 43, 43); | |
[regular_price setImage:[UIImage imageNamed:@"all-transparent"] forState:UIControlStateNormal]; | |
[regular_price setImage:[UIImage imageNamed:@"all-transparent"] forState:UIControlStateHighlighted]; | |
image_for_refularPrice=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"Circle-active-regular"]]; | |
[regular_price addTarget:self action:@selector(regularBudget:) forControlEvents:UIControlEventTouchUpInside|UIControlEventTouchUpOutside]; | |
image_for_refularPrice.frame=CGRectMake(177.5, 231, 43, 43); | |
image_for_refularPrice.layer.zPosition=1; | |
regular_price.layer.zPosition=5; | |
splurge_price =[UIButton buttonWithType:UIButtonTypeCustom]; | |
splurge_price.frame=CGRectMake(255.5, 231, 43, 43); | |
[splurge_price setImage:[UIImage imageNamed:@"all-transparent"] forState:UIControlStateNormal]; | |
[splurge_price setImage:[UIImage imageNamed:@"all-transparent"] forState:UIControlStateHighlighted]; | |
image_for_splurgePrice=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"Circle-active-luxury"]]; | |
[splurge_price addTarget:self action:@selector(splurgeBudget:) forControlEvents:UIControlEventTouchUpInside|UIControlEventTouchUpOutside]; | |
image_for_splurgePrice.layer.zPosition=1; | |
image_for_splurgePrice.frame=CGRectMake(255.5, 231, 43, 43); | |
splurge_price.layer.zPosition=5; | |
/////////adding animation | |
image_for_allPrice.hidden=false; | |
image_for_budgetPrice.hidden=true; | |
image_for_refularPrice.hidden=true; | |
image_for_splurgePrice.hidden=true; | |
All_price.enabled=false; | |
regular_price.enabled=true; | |
budget_price.enabled=true; | |
splurge_price.enabled=true; | |
} | |
[self addSubview:ButtonSearch]; | |
[self addSubview:regular_price]; | |
[self addSubview:splurge_price]; | |
[self addSubview:All_price]; | |
[self addSubview:budget_price]; | |
[self addSubview:checkmark]; | |
[self addSubview:NetraSearch]; | |
[self addSubview:AllButton]; | |
[self addSubview:Package]; | |
[self addSubview:Flight]; | |
[self addSubview:Hotels]; | |
[self addSubview:labelForBudget]; | |
[self addSubview:backgrondPrice]; | |
[self addSubview:All_price_label]; | |
[self addSubview:budget_price_label]; | |
[self addSubview:regular_price_label]; | |
[self addSubview:splurge_price_label]; | |
[self addSubview:image_for_budgetPrice]; | |
[self addSubview:image_for_allPrice]; | |
[self addSubview:image_for_refularPrice]; | |
[self addSubview:image_for_splurgePrice]; | |
[self addSubview:continuesBackground]; | |
return self; | |
} | |
- (void)animateImageViewFromStartPosition:(CGPoint)aStartPosition toEndPosition:(CGPoint)aEndPosition; { | |
continuesBackground.frame.origin = aStartPosition; | |
[UIView animateWithDuration:5.0f | |
delay:0.0f | |
options:UIViewAnimationOptionCurveEaseInOut | |
animations:^(void){ | |
CGRect newFrame = continuesBackground.frame; | |
newFrame.origin = aEndPosition; | |
continuesBackground.frame = newFrame; | |
} | |
completion:^(BOOL finished){ | |
if(finished){ | |
[self animateImageViewFromStartPosition:aStartPosition toEndPosition:aEndPosition]; | |
} | |
}]; | |
} | |
-(void) test:(id)sender{ | |
location=NetraSearch.text; | |
if(location==NULL){ | |
location=@""; | |
} | |
NSLog(@"Mengirim%@",location); | |
[self.delegate searchBox:self location:location packageOption:deals_type_option priceOption:price_type_option]; | |
}; | |
- (void)dealloc { | |
[NetraSearchBox release]; | |
[ButtonSearch release]; | |
[super dealloc]; | |
} | |
-(void)layoutSubviews{ | |
self.backgroundColor=[UIColor colorWithRed:0.988 green:0.988 blue:0.988 alpha:1]; | |
self.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"searchbox_bg"]]; | |
} | |
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{ | |
UIImage *search_editing=[UIImage imageNamed:@"search_editing"]; | |
NetraSearch.background=search_editing; | |
return YES; | |
} | |
- (BOOL)textFieldShouldReturn:(UITextField *)textField { | |
[NetraSearch resignFirstResponder]; | |
return YES; | |
} | |
-(void)fetchSetting{ | |
NSURL *URL=[NSURL URLWithString:url_setting]; | |
NSURLRequest *request=[[NSURLRequest alloc] initWithURL:URL]; | |
AFJSONRequestOperation *operation=[[AFJSONRequestOperation alloc] initWithRequest:request]; | |
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { | |
//NSLog(@"response Object===%@",[responseObject objectForKey:@"location_ids"]); | |
data=[responseObject objectForKey:@"location_ids"]; | |
NSLog(@"data=%@",data); | |
//NSMutableArray *dictArray = [[NSMutableArray alloc] initWithObjects:data, nil]; | |
datasearch=[data allKeys]; | |
NSMutableArray *array1 = [[NSMutableArray alloc]init]; | |
NSMutableArray *array2 = [[NSMutableArray alloc]init]; | |
for (id key in data) { | |
//NSDictionary *sub=[data objectForKey:key]; | |
NSLog(@"key==--------------->%@",key); | |
[array1 addObject:key]; | |
[array2 addObject:[data objectForKey:key]]; | |
} | |
NSArray *myArray = [array1 copy]; | |
NSString *value = [data objectForKey: @"Phuket"]; | |
NSLog(@"myArray=========>%@",myArray); | |
//NSLog(@"data ke 0 adalah %@ dengan value=%@",[array1 objectAtIndex:0],[array2 objectAtIndex:0]); //NSLog(@"Array 2-->%@",array2); | |
} failure:^(AFHTTPRequestOperation *operation, NSError *error) { | |
}]; | |
[operation start]; | |
[operation release]; | |
} | |
////assing button for package | |
-(void) Allbutton:(id)sender{ | |
deals_type_option=@""; | |
[self performSelector:@selector(doHighlight:) withObject:sender afterDelay:0.0]; | |
} | |
- (void)doHighlight:(UIButton*)Allbutton { | |
Package.highlighted=NO; | |
Flight.highlighted=NO; | |
Hotels.highlighted=NO; | |
AllButton.highlighted=YES; | |
} | |
/////package | |
-(void) package:(id)sender{ | |
deals_type_option=@"packages"; | |
// NSLog(@"Button State %u",AllButton.state); | |
[self performSelector:@selector(doHighlight_package:) withObject:sender afterDelay:0.0]; | |
} | |
- (void)doHighlight_package:(UIButton*)package { | |
Package.highlighted=YES; | |
Flight.highlighted=NO; | |
Hotels.highlighted=NO; | |
AllButton.highlighted=NO; | |
} | |
////flights | |
-(void) flight:(id)sender{ | |
deals_type_option=@"flights"; | |
// NSLog(@"Button State %u",AllButton.state); | |
[self performSelector:@selector(doHighlight_flight:) withObject:sender afterDelay:0.0]; | |
} | |
- (void)doHighlight_flight:(UIButton*)flight { | |
Package.highlighted=NO; | |
Flight.highlighted=YES; | |
Hotels.highlighted=NO; | |
AllButton.highlighted=NO; | |
} | |
////flights | |
-(void) hotel:(id)sender{ | |
deals_type_option=@"hotels"; | |
// NSLog(@"Button State %u",AllButton.state); | |
[self performSelector:@selector(doHighlight_hotel:) withObject:sender afterDelay:0.0]; | |
} | |
- (void)doHighlight_hotel:(UIButton*)hotel { | |
Package.highlighted=NO; | |
Flight.highlighted=NO; | |
Hotels.highlighted=YES; | |
AllButton.highlighted=NO; | |
} | |
//////// | |
////////// | |
/////// | |
///////// | |
/////////// | |
//////choose budget | |
-(void) allBudget:(id)sender{ | |
[self performSelector:@selector(doHighlight_allBudget:) withObject:sender afterDelay:0.0]; | |
} | |
- (void)doHighlight_allBudget:(UIButton*)allBudget { | |
All_price.enabled=false; | |
regular_price.enabled=true; | |
budget_price.enabled=true; | |
splurge_price.enabled=true; | |
price_type_option=@""; | |
checkmark.frame=CGRectMake(38, 249, 11, 8); | |
All_price.highlighted=YES; | |
budget_price.highlighted=NO; | |
regular_price.highlighted=NO; | |
splurge_price.highlighted=NO; | |
image_for_allPrice.hidden=false; | |
image_for_budgetPrice.hidden=true; | |
image_for_refularPrice.hidden=true; | |
image_for_splurgePrice.hidden=true; | |
[UIView transitionWithView:image_for_allPrice duration:.1 options:UIViewAnimationCurveEaseOut animations:^{ | |
image_for_allPrice.frame=CGRectMake(17.7, 227, 53, 53); | |
} completion:^(BOOL finished) { | |
image_for_allPrice.frame=CGRectMake(21.7, 231, 43, 43); | |
}]; | |
} | |
-(void) budgetBudget:(id)sender{ | |
image_for_allPrice.hidden=TRUE; | |
// NSLog(@"Button State %u",AllButton.state); | |
NSLog(@"Button budgetBudget"); | |
[self performSelector:@selector(doHighlight_budgetBudget:) withObject:sender afterDelay:0.0]; | |
} | |
- (void)doHighlight_budgetBudget:(UIButton*)allBudget { | |
All_price.enabled=true; | |
regular_price.enabled=true; | |
budget_price.enabled=false; | |
splurge_price.enabled=true; | |
price_type_option=@"budget"; | |
checkmark.frame=CGRectMake(111.5, 249, 11, 8); | |
All_price.highlighted=NO; | |
budget_price.highlighted=YES; | |
regular_price.highlighted=NO; | |
splurge_price.highlighted=NO; | |
image_for_allPrice.hidden=true; | |
image_for_budgetPrice.hidden=false; | |
image_for_refularPrice.hidden=true; | |
image_for_splurgePrice.hidden=true; | |
[UIView transitionWithView:image_for_budgetPrice duration:.1 options:UIViewAnimationCurveEaseOut animations:^{ | |
image_for_budgetPrice.frame=CGRectMake(91.5, 227, 53, 53); | |
} completion:^(BOOL finished) { | |
image_for_budgetPrice.frame=CGRectMake(95.5, 231, 43, 43); | |
}]; | |
} | |
-(void) regularBudget:(id)sender{ | |
NSLog(@"Button regular"); | |
// NSLog(@"Button State %u",AllButton.state); | |
[self performSelector:@selector(doHighlight_regularBudget:) withObject:sender afterDelay:0.0]; | |
} | |
- (void)doHighlight_regularBudget:(UIButton*)allBudget { | |
All_price.enabled=true; | |
regular_price.enabled=false; | |
budget_price.enabled=true; | |
splurge_price.enabled=true; | |
price_type_option=@"regular"; | |
checkmark.frame=CGRectMake(193.5, 249, 11, 8); | |
All_price.highlighted=NO; | |
budget_price.highlighted=NO; | |
regular_price.highlighted=YES; | |
splurge_price.highlighted=NO; | |
image_for_allPrice.hidden=true; | |
image_for_budgetPrice.hidden=true; | |
image_for_refularPrice.hidden=false; | |
image_for_splurgePrice.hidden=true; | |
image_for_refularPrice.frame=CGRectMake(177.5, 231, 43, 43); | |
[UIView transitionWithView:image_for_refularPrice duration:.1 options:UIViewAnimationCurveEaseOut animations:^{ | |
image_for_refularPrice.frame=CGRectMake(173.5, 227, 53, 53); | |
} completion:^(BOOL finished) { | |
image_for_refularPrice.frame=CGRectMake(177.5, 231, 43, 43); | |
}]; | |
} | |
-(void) splurgeBudget:(id)sender{ | |
NSLog(@"Button splurge"); | |
// NSLog(@"Button State %u",AllButton.state); | |
[self performSelector:@selector(doHighlight_splurgeBudget:) withObject:sender afterDelay:0.0]; | |
} | |
- (void)doHighlight_splurgeBudget:(UIButton*)allBudget { | |
All_price.enabled=true; | |
regular_price.enabled=true; | |
budget_price.enabled=true; | |
splurge_price.enabled=false; | |
price_type_option=@"splurge"; | |
checkmark.frame=CGRectMake(271.5, 249, 11, 8); | |
All_price.highlighted=NO; | |
budget_price.highlighted=NO; | |
regular_price.highlighted=NO; | |
splurge_price.highlighted=YES; | |
image_for_allPrice.hidden=true; | |
image_for_budgetPrice.hidden=true; | |
image_for_refularPrice.hidden=true; | |
image_for_splurgePrice.hidden=false; | |
[UIView transitionWithView:image_for_refularPrice duration:.1 options:UIViewAnimationCurveEaseOut animations:^{ | |
image_for_splurgePrice.frame=CGRectMake(251.5, 227, 53, 53); | |
} completion:^(BOOL finished) { | |
image_for_splurgePrice.frame=CGRectMake(255.5, 231, 43, 43); | |
}]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment