Skip to content

Instantly share code, notes, and snippets.

@Sterling715
Created August 17, 2012 01:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Sterling715/3375151 to your computer and use it in GitHub Desktop.
Save Sterling715/3375151 to your computer and use it in GitHub Desktop.
Menu page
//
// HomeViewController.m
// FreeCare
//
// Created by Shashi on 08/10/11.
// Copyright __MyCompanyName__ 2011. All rights reserved.
//
#import "HomeViewController.h"
#import "ClinicListViewController.h"
@implementation HomeViewController
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
self.navigationController.navigationBarHidden =YES;
[super viewDidLoad];
[btnState setTitle:@" Select a State" forState:UIControlStateNormal];
[btnState setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
btnState.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
btnState.titleLabel.font=[UIFont fontWithName:@"Helvetica" size:22];
[btnCounty setTitle:@" Select a County" forState:UIControlStateNormal];
[btnCounty setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
btnCounty.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
btnCounty.titleLabel.font=[UIFont fontWithName:@"Helvetica" size:22];
[btnService setTitle:@" Select a Service" forState:UIControlStateNormal];
[btnService setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
btnService.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
btnService.titleLabel.font=[UIFont fontWithName:@"Helvetica" size:22];
btnState.enabled = YES;
btnCounty.enabled = NO;
btnService.enabled = NO;
btnSubmit.enabled = NO;
//strState = [[NSString alloc] init];
// strCounty = [[NSString alloc] init];
// strService = [[NSString alloc] init];
}
#pragma mark -
#pragma mark USER Function
-(IBAction) selectBtnClick:(id)sender
{
UIButton *btn = (UIButton *)sender;
pickerView.hidden = NO;
appDelegate.bannerView_.hidden = YES;
if (btn.tag == 10) {
lblPickerTitle.text = @"State";
[appDelegate getStates];
}
else if (btn.tag == 11) {
lblPickerTitle.text = @"County";
[appDelegate getCounty:strState];
}
else if (btn.tag == 12) {
lblPickerTitle.text = @"Service";
[appDelegate getServices:strState :strCounty];
}
[picker reloadComponent:0];
}
-(IBAction) doneBtnClick
{
pickerView.hidden = YES;
appDelegate.bannerView_.hidden = NO;
if ([lblPickerTitle.text isEqualToString:@"State"]) {
strState = [NSString stringWithFormat:@"%@",[appDelegate.arrResult objectAtIndex:[picker selectedRowInComponent:0]]];
[strState retain];
[btnState setTitle:[NSString stringWithFormat:@" %@",strState] forState:UIControlStateNormal];
btnCounty.enabled = YES;
}
else if ([lblPickerTitle.text isEqualToString:@"County"]) {
strCounty = [NSString stringWithFormat:@"%@",[appDelegate.arrResult objectAtIndex:[picker selectedRowInComponent:0]]];
[strCounty retain];
[btnCounty setTitle:[NSString stringWithFormat:@" %@",strCounty] forState:UIControlStateNormal];
btnService.enabled = YES;
}
else if ([lblPickerTitle.text isEqualToString:@"Service"]) {
strService = [NSString stringWithFormat:@"%@",[appDelegate.arrResult objectAtIndex:[picker selectedRowInComponent:0]]];
[strService retain];
[btnService setTitle:[NSString stringWithFormat:@" %@",strService] forState:UIControlStateNormal];
btnSubmit.enabled = YES;
}
}
-(IBAction) cancelBtnClick
{
//tbl.frame = CGRectMake(0, 44, 320, 310);
pickerView.hidden = YES;
appDelegate.bannerView_.hidden = NO;
}
-(IBAction) btnSubmitClick
{
[appDelegate getClinicDetial:strService :strState :strCounty];
ClinicListViewController *objClinicListViewController = [[ClinicListViewController alloc] initWithNibName:@"ClinicListViewController" bundle:nil];
[self.navigationController pushViewController:objClinicListViewController animated:YES];
[objClinicListViewController release];
}
#pragma mark -
#pragma mark ------------------- PickerView -------------------------
// returns the number of 'columns' to display.
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
// returns the # of rows in each component..
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return [appDelegate.arrResult count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [appDelegate.arrResult objectAtIndex:row];
}
#pragma mark -
#pragma mark Memory Management
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
//
// ClinicListViewController.m
// FreeCare
//
// Created by Shashi on 09/10/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "ClinicListViewController.h"
#import "ClinicDetialViewController.h"
@implementation ClinicListViewController
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
self.navigationController.navigationBarHidden = YES;
[super viewDidLoad];
}
- (void)viewWillAppear:(BOOL)animated
{
[tblClinic reloadData];
}
- (IBAction) backBtnClicked
{
[self.navigationController popViewControllerAnimated:YES];
}
#pragma mark -
#pragma mark -------------------------Table Data Source Methods ------------------------------------
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [appDelegate.arrResult count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *clinicCellIdentifier = @"clinicCellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:clinicCellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:clinicCellIdentifier] autorelease];
}
cell.textLabel.text = [[appDelegate.arrResult objectAtIndex:indexPath.row]valueForKey:@"name"];
cell.textLabel.font = [UIFont boldSystemFontOfSize:17];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ClinicDetialViewController *objClinicDetialViewController = [[ClinicDetialViewController alloc] initWithNibName:@"ClinicDetialViewController" bundle:nil];
objClinicDetialViewController.dictClinic = [appDelegate.arrResult objectAtIndex:indexPath.row];
[self.navigationController pushViewController:objClinicDetialViewController animated:YES];
[objClinicDetialViewController release];
}
#pragma mark -
#pragma mark Memory management
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
//
// ClinicDetialViewController.m
// FreeCare
//
// Created by Shashi on 09/10/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "ClinicDetialViewController.h"
#import "JSON.h"
@implementation ClinicDetialViewController
@synthesize dictClinic;
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
clinicLat = 0.0;
clinicLong = 0.0;
}
- (void) viewDidAppear:(BOOL)animated
{
activity.hidden =NO;
[activity startAnimating];
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
[self FillData];
}
#pragma mark -
#pragma mark Button Clicked
- (IBAction) btnCallClicked
{
UIButton *btn = (UIButton *)[self.view viewWithTag:7];
if (![btn.titleLabel.text isEqualToString:@"No Number"]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Phone call" message:@"Do you want to call ?" delegate:self cancelButtonTitle:@"Yes"otherButtonTitles:@"No",nil];
alert.tag = 4;
[alert show];
[alert release];
}
}
- (IBAction) btnDirection
{
if (clinicLat != 0.0 && clinicLong != 0) {
NSString* url = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f",
appDelegate.currentlat,appDelegate.currentlong,clinicLat,clinicLong];
//NSString* url = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr='%@'&daddr='%@'",
// strCurrAddress,[self.dictClinic valueForKey:@"address"]];
//
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];
}
}
- (IBAction) backBtnClicked
{
[self.navigationController popViewControllerAnimated:YES];
}
#pragma mark -
#pragma mark ---------------------- Alert view Methods -------------------------------
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (alertView.tag==4 && buttonIndex==0)
{
NSString *ph = [NSString stringWithFormat:@"%@", [self.dictClinic valueForKey:@"phone"]];
NSArray *arrPhone = [ph componentsSeparatedByString:@"x"];
ph = [NSString stringWithFormat:@"%@",[arrPhone objectAtIndex:0]];
NSString *phoneno= [ph stringByReplacingOccurrencesOfString: @"-" withString: @""];
phoneno = [phoneno stringByReplacingOccurrencesOfString: @" " withString: @""];
phoneno = [phoneno stringByReplacingOccurrencesOfString: @"(" withString: @""];
NSURL *phoneNumberURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",@"tel:",phoneno]];//@"tel:8005551234"
[[UIApplication sharedApplication] openURL:phoneNumberURL];
}
}
#pragma mark -
#pragma mark User Defined function
- (void) FillData
{
UILabel *lblName = (UILabel *)[self.view viewWithTag:5];
UILabel *lblAddress = (UILabel *)[self.view viewWithTag:6];
UIButton *btnPhone = (UIButton *)[self.view viewWithTag:7];
lblName.text = [self.dictClinic valueForKey:@"name"];
lblAddress.text = [self.dictClinic valueForKey:@"address"];
NSString *ph = [NSString stringWithFormat:@"%@", [self.dictClinic valueForKey:@"phone"]];
NSArray *arrPhone = [ph componentsSeparatedByString:@"x"];
if ([arrPhone count] > 0) {
[btnPhone setTitle:[NSString stringWithFormat:@" Call %@",[arrPhone objectAtIndex:0]] forState:UIControlStateNormal];
}
else {
[btnPhone setTitle:[NSString stringWithFormat:@"No Number"] forState:UIControlStateNormal];
}
[NSTimer scheduledTimerWithTimeInterval:0.2f target:self selector:@selector(getCurrentAddress) userInfo:nil repeats:NO];
}
- (void)getCurrentAddress
{
if (appDelegate.currentlat != 0 && appDelegate.currentlong != 0) {
NSURL *urlString;
urlString =[NSURL URLWithString:[NSString stringWithFormat:@"http://maps.google.com/maps/geo?output=json&oe=utf-8&ll=%f,%f&key=ABQIAAAA4vvsDmnbGNnY5FvM-aTqLRTI354re9uL7-WnWBj7IzV16L7D8xS1MEiiTfFAA5rKeOm6uAxEEviEPg",appDelegate.currentlat,appDelegate.currentlong]];
NSLog(@"\n\n-------------------------DM-Get City Name -Request-----------------------------\n%@\n\n",urlString);
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:urlString];
NSData *returnData = [ NSURLConnection sendSynchronousRequest: request returningResponse:nil error: nil ];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
//NSLog(@"\n\n------------------------TF-Get City Name -Response------------------------\n\n%@\n\n",returnString);
NSDictionary *dictAddress=[returnString JSONValue];// componentsSeparatedByString:@"address>"];
if ([[dictAddress allKeys] count] > 1) {
strCurrAddress = [NSString stringWithFormat:@"%@",
[[[dictAddress valueForKey:@"Placemark"] objectAtIndex:0] valueForKey:@"address"]];
[strCurrAddress retain];
NSLog(@"\n\n------------------------DM-city------------------------\n\n%@\n\n",strCurrAddress);
[self getDistance];
}
}
else {
activity.hidden =YES;
[activity stopAnimating];
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
}
}
- (void)getClinicLatLong
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *strLink = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?address='%@'&sensor=false",[self.dictClinic valueForKey:@"address"]];
strLink = [strLink stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURL *urlString =[NSURL URLWithString:strLink];
NSLog(@"\n\n-------------------------DM-Get Lat long Name -Request-----------------------------\n%@\n\n",urlString);
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:urlString];
NSData *returnData = [ NSURLConnection sendSynchronousRequest: request returningResponse:nil error: nil ];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSDictionary *dictAddress=[returnString JSONValue];// componentsSeparatedByString:@"address>"];
if ([[dictAddress valueForKey:@"status"] isEqualToString:@"OK"]) {
NSString *tempStr = [NSString stringWithFormat:@"%@",
[[[[[dictAddress valueForKey:@"results"] objectAtIndex:0] valueForKey:@"geometry"] valueForKey:@"location"] valueForKey:@"lat"]];
[tempStr retain];
clinicLat = [tempStr floatValue];
tempStr = [NSString stringWithFormat:@"%@",
[[[[[dictAddress valueForKey:@"results"] objectAtIndex:0] valueForKey:@"geometry"] valueForKey:@"location"] valueForKey:@"lng"]];
clinicLong = [tempStr floatValue];
}
NSLog(@"%f,%f",clinicLat,clinicLong);
[pool release];
}
- (void) getDistance
{
NSLog(@"%@",[NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/directions/json?origin=%@&destination=%@&sensor=false",strCurrAddress,[self.dictClinic valueForKey:@"address"]]);
NSString *str=[NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/directions/json?origin=%@&destination=%@&sensor=false",strCurrAddress,[self.dictClinic valueForKey:@"address"]];
str=[str stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
NSURL *urlString = [[NSURL alloc] initWithString:str];
//urlString =[NSURL URLWithString:[NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/directions/json?origin=%@&destination=%@&sensor=false",self.strHomeAddress,[[NSUserDefaults standardUserDefaults] valueForKey:@"WorkAddress"]]];
NSLog(@"\n\n-------------------------Get Distance Request-----------------------------\n%@\n\n",urlString);
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:urlString];
NSData *returnData = [ NSURLConnection sendSynchronousRequest: request returningResponse:nil error: nil ];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
//NSLog(@"\n\n------------------------TF-Get City Name -Response------------------------\n\n%@\n\n",returnString);
NSDictionary *dictDictance =[returnString JSONValue];
UILabel *lblDistance = (UILabel *)[self.view viewWithTag:8];
NSString *strdist;
if ([[dictDictance valueForKey:@"status"] isEqualToString:@"OK"]) {
strdist = [NSString stringWithFormat:@"%@",[[[[[[dictDictance valueForKey:@"routes"] objectAtIndex:0] valueForKey:@"legs"] objectAtIndex:0] valueForKey:@"distance"] valueForKey:@"text"]];
NSCharacterSet *charactersToRemove = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789."] invertedSet];
NSString *strDistance = [[strdist componentsSeparatedByCharactersInSet:charactersToRemove]
componentsJoinedByString:@""];
float mile = [strDistance floatValue] * 0.6214;
strdist = [NSString stringWithFormat:@"%.2f miles",mile];
}
else {
strdist = [NSString stringWithFormat:@""];
}
lblDistance.text = [NSString stringWithFormat:@"%@",strdist];
activity.hidden =YES;
[activity stopAnimating];
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
[self performSelectorInBackground:@selector(getClinicLatLong) withObject:nil];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment