//
//  CustomCell.m
//  VisIVOMobile
//
//  Created by Fabio Roberto Vitello on 09/03/12.
//  Copyright (c) 2012 nothing. All rights reserved.
//

#import "CustomCellView.h"

@implementation CustomCellView
@synthesize primaryLabel,secondaryLabel,myImageView,myImageViewEnd;

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier type:(int)t
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        type=t;
        
        primaryLabel = [[UILabel alloc]init];
        primaryLabel.textAlignment = UITextAlignmentLeft;
        primaryLabel.backgroundColor=[UIColor clearColor];


        secondaryLabel = [[UILabel alloc]init];
        secondaryLabel.textAlignment = UITextAlignmentLeft;
        secondaryLabel.backgroundColor=[UIColor clearColor];


        myImageView = [[UIImageView alloc]init];
        myImageViewEnd = [[UIImageView alloc]init];
        
        textField =[[UITextField alloc]init];


        if(type==0)
        {
            
        // Initialization code
        primaryLabel.font = [UIFont systemFontOfSize:24];
        secondaryLabel.font = [UIFont systemFontOfSize:14];
        
        }  
        
        if (type == 1) {
            // Initialization code
            primaryLabel.font = [UIFont systemFontOfSize:18];
            secondaryLabel.font = [UIFont systemFontOfSize:12];

        }
        
        if (type == 2) {
            // Initialization code
            primaryLabel.font = [UIFont boldSystemFontOfSize:16];
            
            secondaryLabel.font = [UIFont systemFontOfSize:16];
            
        }
        
        if (type == 3)
        {
            
            textField.textAlignment=UITextAlignmentLeft;
            textField.clearButtonMode = UITextFieldViewModeWhileEditing;
            textField.returnKeyType=UIReturnKeyDone;
            textField.adjustsFontSizeToFitWidth=YES;
            textField.autocorrectionType=UITextAutocorrectionTypeNo;
            textField.autocapitalizationType= UITextAutocapitalizationTypeNone;
            
            
            textField.delegate=self;
            
            
            
            
            
        }
        if (type == 4)
        {
            
            primaryLabel.font = [UIFont systemFontOfSize:20];
            
            
            
            
        }
        [self.contentView addSubview:primaryLabel];
        [self.contentView addSubview:secondaryLabel];
        [self.contentView addSubview:myImageView];
        [self.contentView addSubview:myImageViewEnd];
        [self.contentView addSubview:textField];

        
    }
    return self;
    
}


- (void)layoutSubviews {
    [super layoutSubviews];
    CGRect contentRect = self.contentView.bounds;
    CGFloat boundsX = contentRect.origin.x;
    CGRect frame;
    
    if (type==0) {
        frame= CGRectMake(boundsX+10 ,10, 64, 64);
        myImageView.frame = frame;
        
        frame= CGRectMake(boundsX+100 ,15, 200, 45);
        primaryLabel.frame = frame;
        
        frame= CGRectMake(boundsX+100 ,65, 200, 15);
        secondaryLabel.frame = frame;
        
        frame= CGRectMake(boundsX+250 ,30, 30, 30);
        myImageViewEnd.frame = frame;
        
    }   
    
    if (type==1) {
       
        frame= CGRectMake(boundsX+10 ,10, 32, 32);
        myImageView.frame = frame;
        
        frame= CGRectMake(boundsX+45 ,-5, 200, 45);
        primaryLabel.frame = frame;
        
        frame= CGRectMake(boundsX+60 ,25, 200, 15);
        secondaryLabel.frame = frame;
        secondaryLabel.backgroundColor=[UIColor clearColor];
        
        frame= CGRectMake(boundsX+280 ,10, 30, 30);
        myImageViewEnd.frame = frame;

    }
    
    if (type == 2) {
        frame= CGRectMake(boundsX+5 ,0, 150, 45);
        primaryLabel.frame = frame;
        
        frame= CGRectMake(boundsX+160 ,0, 150, 45);
        secondaryLabel.frame = frame;
        
        frame= CGRectMake(boundsX+250 ,7, 30, 30);
        myImageViewEnd.frame = frame;

    }
    
    if (type == 3) {
    
        frame= CGRectMake(boundsX+5 ,0, 150, 45);
        primaryLabel.frame = frame;
        
        frame= CGRectMake(boundsX+100 ,10, 200, 35);
        textField.frame = frame;
        
    }

    if (type == 4)
    {
        frame= CGRectMake(boundsX+10 ,10, 64, 64);
        myImageView.frame = frame;
        
        frame= CGRectMake(boundsX+100 ,10, 200, 45);
        primaryLabel.frame = frame;
        
        frame= CGRectMake(boundsX+250 ,30, 30, 30);
        myImageViewEnd.frame = frame;

    }
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField {
    
    [textField resignFirstResponder];
    return YES;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    //[super setSelected:selected animated:animated];
}

@end
