Tuesday, 24 January 2012

urldemo 5

//For the hexa code to UIColor 
- (UIColor *) colorWithHexString: (NSString *) hex 

    NSString *cString = [[hex stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString]; 
   
    // String should be 6 or 8 characters 
    if ([cString length] < 6) return [UIColor grayColor]; 
   
    // strip 0X if it appears 
    if ([cString hasPrefix:@"0X"]) cString = [cString substringFromIndex:2]; 
   
    if ([cString length] != 6) return  [UIColor grayColor]; 
   
    // Separate into r, g, b substrings 
    NSRange range; 
    range.location = 0; 
    range.length = 2; 
    NSString *rString = [cString substringWithRange:range]; 
   
    range.location = 2; 
    NSString *gString = [cString substringWithRange:range]; 
   
    range.location = 4; 
    NSString *bString = [cString substringWithRange:range]; 
   
    // Scan values 
    unsigned int r, g, b; 
    [[NSScanner scannerWithString:rString] scanHexInt:&r]; 
    [[NSScanner scannerWithString:gString] scanHexInt:&g]; 
    [[NSScanner scannerWithString:bString] scanHexInt:&b]; 
   
    return [UIColor colorWithRed:((float) r / 255.0f) 
                           green:((float) g / 255.0f) 
                            blue:((float) b / 255.0f) 
                           alpha:1.0f]; 
}
how to use it
[self.view setBackgroundColor: [self colorWithHexString:@"Ff0000"]];


//For the slider to unlock example for slider
    altosdesign.com/iphonesdk/SlideToCancel.zip
    http://www.altosdesign.com/iphonesdk/SlideToCancel.zip

//For the pop to specific view in iPhone
[self.navigationController popToViewController: [self.navigationController.viewControllers objectAtIndex: 1] animated: YES];

//For the custom image slider

 UIImage *minImage = [UIImage imageNamed:@"grey_track.png"];
    UIImage *maxImage = [UIImage imageNamed:@"white_track.png"];
    UIImage *tumbImage= [UIImage imageNamed:@"metal_screw.png"];
   
    minImage=[minImage stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
    maxImage=[maxImage stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
   
    // Setup the FX slider
    [maxPriceSlider setMinimumTrackImage:minImage forState:UIControlStateNormal];
    [maxPriceSlider setMaximumTrackImage:maxImage forState:UIControlStateNormal];
    [maxPriceSlider setThumbImage:tumbImage forState:UIControlStateNormal];


//For the sectioned TableView
http://www.mobisoftinfotech.com/blog/iphone/iphone-uitableview-tutorial-grouped-table/
/*<?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
 <plist version="1.0">
 <dict>
 <key>Photo</key>
 <string>mobile.png</string>
 <key>Mobile Phones</key>
 <array>
 <string>GSM Phones</string>
 <string>Dual Sim Phones</string>
 <string>CDMA Phones</string>
 </array>
 <key>Smart Phones</key>
 <array>
 <string>IOS Phones</string>
 <string>Android OS Phones</string>
 <string>Blackberry Phones</string>
 <string>Symbian OS Phones</string>
 <string>Tablet Phones</string>
 <string>Windows OS Phones</string>
 <string>Bada OS Phones</string>
 </array>

 <key>Mobile Accessories</key>
 <array>
 <string>Screen Protectors</string>
 <string>Memory Card</string>
 <string>HeadPhones</string>
 <string>CaseMate</string>       
 <string>Bluetooth Devices</string>       
 </array>

 <key>Landline Phones</key>
 <array>
 <string>Landline Phones</string>
 </array>

 </dict>
 </plist>
 */

-(void)viewWillAppear:(BOOL)animated{
    self.navigationController.navigationBarHidden=NO;
        self.title=@"Sub Category";
    appDel=(AppDelegate *)[[UIApplication sharedApplication]delegate];
    NSLog(@"indexValue %@",indexValue);
    NSString *getPlist=[[NSBundle mainBundle] pathForResource:indexValue ofType:@"plist"];
    NSLog(@"%@",getPlist);
    plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:getPlist];
    NSLog(@"%@",plistDict);
   
   
    NSString *getPhoto=[plistDict valueForKey:@"Photo"];
    UIImageView *bgImgView=[[UIImageView alloc] initWithFrame:CGRectMake(subCatTableView.frame.origin.x, subCatTableView.frame.origin.y, subCatTableView.frame.size.width, subCatTableView.frame.size.height)];
    bgImgView.image=[UIImage imageNamed:getPhoto];
    bgImgView.alpha=0.5;
    subCatTableView.backgroundView=bgImgView;
    [plistDict removeObjectForKey:@"Photo"];
   
   
   
    sectionArray=[[NSMutableArray alloc] init];

    sectionArray =[[[plistDict allKeys]sortedArrayUsingSelector:@selector(compare:)] mutableCopy];
   
    NSLog(@"%@",sectionArray);
    subCatArray=[[NSMutableArray alloc] init];
   

   
}
#pragma mark Table Methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return [sectionArray count];
}

- (NSString *)tableView:(UITableView *)tableView
titleForHeaderInSection:(NSInteger)section
{
    return [sectionArray objectAtIndex:section];
}

- (NSInteger)tableView:(UITableView *)table
 numberOfRowsInSection:(NSInteger)section {
    NSArray *listData =[plistDict objectForKey:
                        [sectionArray objectAtIndex:section]];
    return [listData count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
   
    NSArray *listData =[plistDict objectForKey:
                        [sectionArray objectAtIndex:[indexPath section]]];
   
    UITableViewCell * cell = [tableView
                              dequeueReusableCellWithIdentifier: SimpleTableIdentifier];
   
    if(cell == nil) {
       
        cell = [[[UITableViewCell alloc]
                 initWithStyle:UITableViewCellStyleDefault
                 reuseIdentifier:SimpleTableIdentifier] autorelease];
         cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        /*cell = [[[UITableViewCell alloc]
         initWithStyle:UITableViewCellStyleSubtitle
         reuseIdentifier:SimpleTableIdentifier] autorelease];
         */
    }
    cell.selectionStyle=UITableViewCellSelectionStyleGray;
    NSUInteger row = [indexPath row];
    cell.textLabel.text = [listData objectAtIndex:row];
   
    return cell;
}

- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSArray *listData =[plistDict objectForKey:
                        [sectionArray objectAtIndex:[indexPath section]]];
    NSUInteger row = [indexPath row];
    NSString *rowValue = [listData objectAtIndex:row];
   
    NSString *message = [[NSString alloc] initWithFormat:rowValue];
    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle:@"You selected"
                          message:message delegate:nil
                          cancelButtonTitle:@"OK"
                          otherButtonTitles:nil];
    [alert show];
    [alert release];
    [message release];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
   
}

//For the view like the easy out and view like small to big
http://stackoverflow.com/questions/8175367/iphone-uiview-animation-resize-in-like-disappear-in-water-and-comes-back-floatin
CGRect originalFrame = scheduleView.frame;
   
    [UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationCurveEaseInOut animations:^{
        CGRect frame = scheduleView.frame;
        frame.origin = scheduleView.center;
        frame.size = CGSizeMake( 0, 0 );
        scheduleView.frame = frame;
    } completion:^(BOOL finished) {
        // Do something with the view
       
        [UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationCurveEaseInOut animations:^{
           scheduleView.frame = originalFrame;
        } completion:^(BOOL finished) {
            return;
        }];
       
        return;
    }];


//For the paypal library
https://www.x.com/developers/paypal/documentation-tools/sdk

//For the multiselection of row
- (void)viewDidLoad {
    [super viewDidLoad];
    self.arForTable=[NSArray arrayWithObjects:@"Object-One",@"Object-Two",@"Object-Three",@"Object-Four",@"Object-Five", nil];
    self.arForIPs=[NSMutableArray array];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [self.arForTable count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    if([self.arForIPs containsObject:indexPath]){
        [cell setAccessoryType:UITableViewCellAccessoryCheckmark];
    } else {
        [cell setAccessoryType:UITableViewCellAccessoryNone];
    }
    cell.textLabel.text=[self.arForTable objectAtIndex:indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if([self.arForIPs containsObject:indexPath]){
        [self.arForIPs removeObject:indexPath];
    } else {
        [self.arForIPs addObject:indexPath];
    }
    [tableView reloadData];
}




//For the different source code
http://projectswithlove.com/projects/

http://osx.hyperjeff.net/Reference/CocoaArticles?cat=52


//For the MPMediaItemArtwork
https://github.com/erica/MPMediaItem-Properties

//For the different demos
http://www.vellios.com/downloads/

//Soap parsing Demos
http://www.devx.com/wireless/Article/43209
http://iphonebyradix.blogspot.com/2011/04/working-with-webservices.html
http://www.icodeblog.com/2008/11/03/iphone-programming-tutorial-intro-to-soap-web-services/

//To generate the random charter unto limit
 NSString *chars = @"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    NSMutableString *randomString = [NSMutableString stringWithCapacity: string_length];
    for (int i=0; i<string_length; i++)
    {
        [randomString appendFormat:@"%C", [chars characterAtIndex: arc4random()%[chars length]]];
    }


//For the writing to the xml file
NSString *fromNumber;
    NSString *toNumber;
    NSString *msg;
   
   
    NSString *tempString = @"<?xml version=""1.0"" encoding=""UTF-8""?>";
    NSString *strXmlNode = [[NSString alloc] initWithFormat:@"%@<TwilioResponse><SMSMessage><Sid>AP38503af035184c6a8b9cb9b7c70fb2b4</Sid><DateCreated>Wed, 18 Aug 2010 20:01:40 +0000</DateCreated><DateUpdated>Wed, 18 Aug 2010 20:01:40 +0000</DateUpdated><DateSent/><AccountSid>AC696f8df0c9ca45cfb59b073ad5e3ee02</AccountSid>\n""<To>+919904523387</To>\n"
        "<From>+%@</From>\n"
        "<Body>%@</Body>\n"
        "<Status>queued</Status>\n"
        "<Direction>outbound-api</Direction>\n"
        "<ApiVersion>2010-04-01</ApiVersion>\n"
        "<Price/>\n"
        "<Uri>/2010-04-01/Accounts/AP38503af035184c6a8b9cb9b7c70fb2b4/SMS/Messages/AC696f8df0c9ca45cfb59b073ad5e3ee02</Uri>\n"
        "</SMSMessage>\n"
        "</TwilioResponse>",fromNumber,toNumber,msg];
   
/*    NSData *data = [[NSString stringWithString:strXmlNode] dataUsingEncoding:NSUTF8StringEncoding];
   
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
   
    NSString *documentsDirectory = [paths objectAtIndex:0];
   
    NSString *dataFilePath = [[documentsDirectory stringByAppendingPathComponent:@"Message.xml"] retain];
   
    [data writeToFile: dataFilePath atomically:YES]; */




Tuesday, 13 December 2011

UrlDemo 5

URLDemo5
//For the CiFaceDetection

http://maniacdev.com/2011/11/tutorial-easy-face-detection-with-core-image-in-ios-5/

//For the different example
http://iphonecode.weebly.com/second-page.html

//For the paint app reference
http://itunes.apple.com/us/app/xpaint/id388881325?mt=8
http://itunes.apple.com/us/app/doodle-touch/id398904512?mt=8

//For the Enape and MKStoreManager of the app
http://www.sixtemia.com/journal/2009/08/12/using-store-kit-framework/

//For the different snippet of the iphone
http://borkware.com/quickies/everything-by-date
http://jidh.weebly.com/iphone-development.html

//For the UUID in iphone
  CFUUIDRef cfuuid = CFUUIDCreate (kCFAllocatorDefault);
    NSString *uuid = (NSString *)CFUUIDCreateString (kCFAllocatorDefault, cfuuid);
    CFRelease (cfuuid);
    NSLog(@"%@",uuid);
//For the paint demo
http://code.google.com/p/paintboardiphone/downloads/list
http://pastebin.com/9dKPHt6R

http://www.iphonedevsdk.com/forum/iphone-sdk-development/13064-how-draw-transparent-stroke-anyway-delete-some-part-uiimage-cg.html

//For the checking of network
-(BOOL)checkNetworkConnection{
    NSString *connectingString=[[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://google.com"]];
    if ([connectingString length]==0) {
        NSLog(@"not connected");
        UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Error" message:@"Network is not available " delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
        [alert release];
        netWork=YES;
    }
    else {
        netWork=NO;
    }
   
    [connectingString release];
    return netWork;
}
// For the sorting of array into alphabetic order
wordArray = [[wordArray sortedArrayUsingSelector:
                       @selector(compare:)] mutableCopy];
//For the pdf demos
http://pspdfkit.com/

//For the line drawing and erasing
write it between the touch moved

UITouch *touch = [touches anyObject];   
    CGPoint currentPoint = [touch locationInView:self.colorView];
      //currentPoint.y -= 20;
        if (appDelegate.iphoneIpad==1) {
            drawPencil.frame=CGRectMake(currentPoint.x+5,currentPoint.y-30,drawPencil.frame.size.width,drawPencil.frame.size.height);       
           
        }
        else{
            drawPencil.frame=CGRectMake(currentPoint.x+10,currentPoint.y-80,drawPencil.frame.size.width,drawPencil.frame.size.height);       
           
        }
       
        if (eraseDrawImg==NO) {
                //For Drawing of line....
           
                //drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
                UIGraphicsBeginImageContext(self.colorView.frame.size);
                [drawImage.image drawInRect:CGRectMake(0, 0, drawImage.frame.size.width, drawImage.frame.size.height)];
                CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
                CGContextSetLineWidth(UIGraphicsGetCurrentContext(), eraseSize);
                
                    CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(),color);
               
                CGContextBeginPath(UIGraphicsGetCurrentContext());
                CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
                CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
                CGContextStrokePath(UIGraphicsGetCurrentContext());
                drawImage.image=UIGraphicsGetImageFromCurrentImageContext();
                          
                UIGraphicsEndImageContext();  
                
            } 
            else{
                //For Erasing of Drawn line....

                UIGraphicsBeginImageContext(self.colorView.frame.size);
                [drawImage.image drawInRect:CGRectMake(0, 0, drawImage.frame.size.width, drawImage.frame.size.height)];
                CGContextSetLineCap(UIGraphicsGetCurrentContext(),kCGImageAlphaNone); //kCGImageAlphaPremultipliedLast);
                CGContextSetLineWidth(UIGraphicsGetCurrentContext(), eraseSize);
                CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1, 0, 0, 10);
                CGContextAddArc(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y, eraseSize, 0.0, 2*M_PI, 0);//, 50, 50, 50, 0.0, 2*M_PI, 0);
                CGContextClip(UIGraphicsGetCurrentContext());
                CGContextClearRect(UIGraphicsGetCurrentContext(),self.colorView.frame);

                CGContextBeginPath(UIGraphicsGetCurrentContext());
                CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
                CGContextClearRect(UIGraphicsGetCurrentContext(), CGRectMake(lastPoint.x, lastPoint.y, eraseSize,eraseSize));
                
                CGContextStrokePath(UIGraphicsGetCurrentContext());
                drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
                UIGraphicsEndImageContext();
            }           
           // NSLog(@"%d",imageTag);
         NSLog(@"%@",lineArray);
        lastPoint = currentPoint;
   
        mouseMoved++;
   
    if (mouseMoved == 10) {
        mouseMoved = 0;
        }
    }

//For the Bluring to imageview

-(UIImage*)imageWithBlurAroundPoint:(CGPoint)point {
    CGRect             bnds = CGRectZero;
    UIImage*           copy = nil;
    CGContextRef       ctxt = nil;
    CGImageRef         imag = rgbImg.image.CGImage;
    CGRect             rect = CGRectZero;
    CGAffineTransform  tran = CGAffineTransformIdentity;
    int                indx = 0;
   
    rect.size.width  = CGImageGetWidth(imag);
    rect.size.height = CGImageGetHeight(imag);
   
    bnds = rect;
   
    UIGraphicsBeginImageContext(bnds.size);
    ctxt = UIGraphicsGetCurrentContext();
   
    // Cut out a sample out the image
    CGRect fillRect = CGRectMake(point.x - 10, point.y - 10, 20, 20);
    CGImageRef sampleImageRef = CGImageCreateWithImageInRect(rgbImg.image.CGImage, fillRect);
   
    // Flip the image right side up & draw
    CGContextSaveGState(ctxt);
   
    CGContextScaleCTM(ctxt, 1.0, -1.0);
    CGContextTranslateCTM(ctxt, 0.0, -rect.size.height);
    CGContextConcatCTM(ctxt, tran);
   
    CGContextDrawImage(UIGraphicsGetCurrentContext(), rect, imag);
   
    // Restore the context so that the coordinate system is restored
    CGContextRestoreGState(ctxt);
   
    // Cut out a sample image and redraw it over the source rect
    // several times, shifting the opacity and the positioning slightly
    // to produce a blurred effect
    for (indx = 0; indx < 5; indx++) {
        CGRect myRect = CGRectOffset(fillRect, 0.5 * indx, 0.5 * indx);
        CGContextSetAlpha(ctxt, 0.2 * indx);
        CGContextScaleCTM(ctxt, 1.0, -1.0);
        CGContextDrawImage(ctxt, myRect, sampleImageRef);
    }
   
    copy = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
   
    return copy;

}
//For the soap parsing demo
http://www.icodeblog.com/2008/11/03/iphone-programming-tutorial-intro-to-soap-web-services/

//For the page curl effect from left to right & vice versa
https://github.com/jemmons/PageCurl


 //For the glow of the line
    /*float glowWidth = 10.0;
     float colorValues[] = { 0, 0, 1, 1.0 };
     CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
     CGColorRef glowColor = CGColorCreate( colorSpace, colorValues );
     CGContextSetShadowWithColor( c, CGSizeMake( 0.0, 0.0 ), glowWidth, glowColor );*/

//touch and erase in uiimageview in iphone
http://www.iphonedevsdk.com/forum/iphone-sdk-development/13064-how-draw-transparent-stroke-anyway-delete-some-part-uiimage-cg.html




Friday, 18 November 2011

iphone snippet

//For the Invert of any object in iphone
UIGraphicsBeginImageContext(rgbImg.image.size);
    CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeCopy);
    UIImage * image=rgbImg.image;
    [image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
    CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeDifference);
    CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(),[UIColor whiteColor].CGColor);
    CGContextFillRect(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, image.size.width, image.size.height));
    rgbImg.image= UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();


//For the Black & White of the image
UIImage *originalImage = rgbImg.image; // this image we get from UIImagePickerController
    CGColorSpaceRef colorSapce = CGColorSpaceCreateDeviceGray();
    CGContextRef context = CGBitmapContextCreate(nil, originalImage.size.width, originalImage.size.height, 8, originalImage.size.width, colorSapce, kCGImageAlphaNone);
    CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
    CGContextSetShouldAntialias(context, NO);
    CGContextDrawImage(context, CGRectMake(0, 0, originalImage.size.width, originalImage.size.height), [originalImage CGImage]);
    CGImageRef bwImage = CGBitmapContextCreateImage(context);
    CGContextRelease(context);
    CGColorSpaceRelease(colorSapce);
    rgbImg.image = [UIImage imageWithCGImage:bwImage]; // This is result B/W image.
    CGImageRelease(bwImage);


//For the mirrored image orientation
if (mirrorOn==NO) {
       rgbImg.image = [UIImage imageWithCGImage:rgbImg.image.CGImage scale:rgbImg.image.scale orientation:UIImageOrientationUpMirrored];
       mirrorOn=YES;

    }
   else if (mirrorOn==YES) {
       mirrorOn=NO;
       rgbImg.image = [UIImage imageWithCGImage:rgbImg.image.CGImage scale:rgbImg.image.scale orientation:UIImageOrientationUp];

    }


//For the uiimage+extra classes for the brightness and contrast

https://github.com/coryleach/UIImageAdjust

//For the uiimage sepia and more

https://github.com/Nyx0uf/NYXImagesUtilities/tree/master/Categories

//For the paint in iphone

http://www.bogotobogo.com/XcodeSDK-Chapter11.html

//Dropdown in iphone
http://kshitizghimire.com.np/dropdown-in-iphoneipad/

//Lazy loading of tableview in iphone

http://kshitizghimire.com.np/lazy-loading-custom-uitableviewcell/

//TwitPic

http://www.techotopia.com/index.php/An_Example_iPhone_iOS_5_TWTweetComposeViewController_Twitter_Application

//For Image Cropping

- (UIImage*)imageByCropping:(UIImage *)imageToCrop toRect:(CGRect)rect
{
    CGImageRef imageRef = CGImageCreateWithImageInRect([imageToCrop CGImage], rect);
    UIImage *cropped = [UIImage imageWithCGImage:imageRef];
    CGImageRelease(imageRef);   
   
    return cropped;
}


//For imageview animation like crossDissolve

#import <QuartzCore/QuartzCore.h>
...
imageView.image = [UIImage imageNamed:(i % 2) ? @"3.jpg" : @"4.jpg"];

CATransition *transition = [CATransition animation];
transition.duration = 1.0f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;

[imageView.layer addAnimation:transition forKey:nil];

//For memory warning issues
http://akosma.com/2009/01/28/10-iphone-memory-management-tips/

//Cook book Example
http://code.google.com/p/iphone-sdk-programming-book-code-samples/downloads/list

//Send sms from the iphone ipad
- (void)sendSMS
{
    if ([MFMessageComposeViewController canSendText])
    {
        MFMessageComposeViewController *messageView = [[MFMessageComposeViewController alloc] init];
        messageView.messageComposeDelegate = self;
       
         [self presentModalViewController:messageView animated:YES];
        [messageView release];
    }
    else {
        [appDel showAlert:@"Oops" message:@"You can't send message"];
    }
   
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
  //  SMS.hidden = NO;
    switch (result)
    {
        case MessageComposeResultCancelled:
           // SMS.text = @"Result: canceled";
            NSLog(@"Result: canceled");
            break;
        case MessageComposeResultSent:
         //   SMS.text = @"Result: sent";
            NSLog(@"Result: sent");
            break;
        case MessageComposeResultFailed:
          //  SMS.text = @"Result: failed";
            NSLog(@"Result: failed");
            break;
        default:
         //   SMS.text = @"Result: not sent";
            NSLog(@"Result: not sent");
            break;
    }
   
    [self dismissModalViewControllerAnimated:YES];
   
}

//Send mail from the iphone ipad
-(IBAction)sendEmail
{
   
    //disappear=YES;
    if([MFMailComposeViewController canSendMail] == false) {
        UIAlertView *view = [[UIAlertView alloc] initWithTitle:@"Error" message:@"The device cannot currently send email." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [view show];
        [view release];
        return;
    }
    else{
        Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
        if (mailClass != nil)
        {
            // We must always check whether the current device is configured for sending emails
            if ([mailClass canSendMail])
            {
                [self displayComposerSheet];
            }
            else
            {
                [self launchMailAppOnDevice];
            }
        }
        else
        {
            [self launchMailAppOnDevice];
        }
    }
   
}
-(void)displayComposerSheet
{
   
    MFMailComposeViewController *mailView = [[MFMailComposeViewController alloc] init];
    mailView.mailComposeDelegate = self;
    //SharedManager *sm = [SharedManager sharedInstance];
    [mailView setSubject:@"Hello from "];//[sm.text substringToIndex:20]];
   
    [mailView setMessageBody:@"You can know more from this url!" isHTML:YES];
   
    NSData *attachmentData = UIImageJPEGRepresentation(getImg, 1.0);
    UIImage *image=getImg;
    [mailView addAttachmentData:attachmentData mimeType:@"image/png" fileName:[NSString stringWithFormat:@"%@",image]];
     [self presentModalViewController:mailView animated:YES];
    [mailView release];
   
}


#pragma mark -
#pragma mark Workaround

// Launches the Mail application on the device.
-(void)launchMailAppOnDevice
{    
    MFMailComposeViewController *mailView = [[MFMailComposeViewController alloc] init];
    mailView.mailComposeDelegate = self;
    [mailView setSubject:@"Hello from  "];    
    [mailView setMessageBody:@"You can know more from this url!" isHTML:YES];
   
    NSData *attachmentData = UIImageJPEGRepresentation(getImg, 1.0);
    UIImage *image=getImg;
    [mailView addAttachmentData:attachmentData mimeType:@"image/png" fileName:[NSString stringWithFormat:@"%@",image]];
    [self presentModalViewController:mailView animated:YES];
    [mailView release];
   
   
   
}
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
    // Dismiss Mail View
    [self dismissModalViewControllerAnimated:YES];
   
    switch (result)
    {
        case MFMailComposeResultCancelled:
            NSLog(@"Mail send canceled");
            self.navigationController.navigationBar.hidden =YES;
            break;
        case MFMailComposeResultSent:
            [appDel showAlert:@"Mail sent successfully." message:@"Success"];
            NSLog(@"Mail send successfully");
            break;
        case MFMailComposeResultSaved:
            [appDel showAlert:@"Mail saved to drafts successfully." message:@"Mail saved"];
            NSLog(@"Mail Saved");
            break;
        case MFMailComposeResultFailed:
            [appDel showAlert:[NSString stringWithFormat:@"Error:%@.", [error localizedDescription]] message:@"Failed to send mail"];
            NSLog(@"Mail send error : %@",[error localizedDescription]);
            break;
        default:
            break;
    }
}

// For SCListner class
https://github.com/stephencelis/sc_listener
//For mic Detection program
http://mobileorchard.com/tutorial-detecting-when-a-user-blows-into-the-mic/


//For the drawing the rectangle lines on the any object
- (void)drawRect  {
    UIGraphicsBeginImageContext(self.view.frame.size);
   
    CGContextRef currentContext = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(currentContext, 3.0); //or whatever width you want
    CGContextSetRGBStrokeColor(currentContext, 0.0, 0.0, 0.0, 1.0);
   
    CGRect myRect = CGContextGetClipBoundingBox(currentContext);
    //printf("rect = %f,%f,%f,%f\n", myRect.origin.x, myRect.origin.y, myRect.size.width, myRect.size.height);
   
    CGContextStrokeRect(currentContext, myRect);
    UIImage *backgroundImage = (UIImage *)UIGraphicsGetImageFromCurrentImageContext();
    UIImageView *myImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    [myImageView setImage:backgroundImage];
    [self.view addSubview:myImageView];
    [backgroundImage release];
   
    UIGraphicsEndImageContext();
}

//For the Border of the imageview in iphone

 [imageView.layer setBorderColor: [[UIColor redColor] CGColor]];
    [imageView.layer setBorderWidth: 2.0];

//Different Example for ios
http://projectswithlove.com/projects/

Wednesday, 5 October 2011

//For wifi driver for mac 10.6

http://www.insanelymac.com/forum/index.php?showtopic=218189


http://www.insanelymac.com/forum/index.php?act=Search&CODE=show&searchid=90d2112282c961971f33961e5ff7a55d&search_in=posts&result_type=topics&highlite=%2Blenovo

http://www.insanelymac.com/forum/index.php?showtopic=51725
Usage: unzip, open a Terminal window and type 'sudo ./bcm43xx_enabler.sh'. Reboot 

For Getting particular named images from the project

//For Getting particular named images from the project

NSMutableArray *any=[[NSMutableArray alloc] init];
    NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];
    NSArray *dirContents = [[NSFileManager defaultManager] directoryContentsAtPath:bundleRoot];
    for (NSString *tString in dirContents) {
        if ([tString hasPrefix:@"Fire Type1"] && [tString hasSuffix:@".png"]) {
           
            [any addObject:tString];
           
        }
    }
    NSLog(@"%@",any);

Accessing specific folder files in iphone app

Accessing specific folder files
1. add folder with the second radio button
2. it is located at anyname.app/yourfolder


NSString *bundleRoot1 = [[NSBundle mainBundle] resourcePath];
    bundleRoot1=[bundleRoot1 stringByAppendingString:@"/Images"];
    NSArray *dirContents1 = [[NSFileManager defaultManager] directoryContentsAtPath:bundleRoot1];
    NSLog(@"dirContents1 %@",dirContents1);
   
    [self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:[dirContents1 objectAtIndex:0]]]];

Tuesday, 4 October 2011

twit Image on twitter with Share kit





 //


#import "TwitImageAppDelegate.h"
@interface TwitterMain : UIViewController<UIActionSheetDelegate> {

   
    TwitImageAppDelegate *appDel;
    IBOutlet UIButton *doneBtn;
    IBOutlet UITextField *userNameTxt;
    IBOutlet UITextField *passTxt;
    IBOutlet UIImageView *imageView;
}
-(IBAction)doneBtnPress;



//////////
#import "TwitterMain.h"
#import "SHKItem.h"
#import "SHKActionSheet.h"
#import "SHKSharer.h"
#import "SHKCustomShareMenu.h"
#import "Global.h"


BOOL checkImg;
@implementation TwitterMain

@synthesize controller,popover;




- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void)viewWillAppear:(BOOL)animated
{
    checkImg=NO;
    appDel=(TwitImageAppDelegate *)[[UIApplication sharedApplication]delegate];
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
}
-(IBAction)doneBtnPress{
   
    if (checkImg==NO) {
        [Global showAlert:@"! Opps" message:@"First Select the Image To Upload"];
    }
    else{
        appDel.username=userNameTxt.text;
        appDel.password=passTxt.text;
        SHKItem *item = [SHKItem image:imageView.image title:@"Selected Image"];
        //    SHKSharer *sharers;
        SHKActionSheet *as = [[SHKActionSheet alloc] initWithTitle:SHKLocalizedString(@"Share")
                                                          delegate:self
                                                 cancelButtonTitle:nil
                                            destructiveButtonTitle:nil
                                                 otherButtonTitles:nil];
        as.item = [[[SHKItem alloc] init] autorelease];
        as.item.shareType = SHKShareTypeImage;
       
        as.sharers = [NSMutableArray arrayWithCapacity:0];
        id class;
        class = NSClassFromString(@"SHKTwitter");
        [as addButtonWithTitle: [class sharerTitle]];
        [as.sharers addObject:@"SHKTwitter"];
        [NSClassFromString([as.sharers objectAtIndex:0]) performSelector:@selector(shareItem:) withObject:item];
    }
    //SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
     //[actionSheet showFromToolbar:self.navigationController.toolbar];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
   
    [textField resignFirstResponder];   
   
    return YES;
}
-(IBAction)camera{
    //UIImagePickerController *controller;
    if (appDel.iphoneIpad==1) {
       
       
       
#if TARGET_IPHONE_SIMULATOR
       
        [Global showAlert:@"Camera is not available." message:@"Not Successfull"];
       
#elif TARGET_OS_IPHONE   
        if ([UIImagePickerController isSourceTypeAvailable:
             UIImagePickerControllerSourceTypeCamera])
        {
            controller = [[UIImagePickerController alloc] init]; 
            controller.sourceType = UIImagePickerControllerSourceTypeCamera; 
            controller.delegate = self; 
            //picker.allowsEditing = YES; 
            [self presentModalViewController:controller animated:YES];
            [controller release];
        }
        else {
            [Global showAlert:@"Camera is not available." message:@"Not Successfull"];
        }
       
#endif   
    }
    else if(appDel.iphoneIpad==2){
       
       
        controller = [[UIImagePickerController alloc] init];
        self.popover = [[UIPopoverController alloc] initWithContentViewController:controller];
        NSLog(@"The value of the bool is %@\n", (self.popover.popoverVisible ? @"YES" : @"NO"));
        //[self dismissPopoverAnimated:YES];
        if (self.popover.popoverVisible == YES) {
           
            [self.popover dismissPopoverAnimated:YES];
            [Global showAlert:@"FIRST CLOSE THE." message:@"PHOTO GALLARY"];
        }
       
        else {
           
            if ([UIImagePickerController isSourceTypeAvailable:
                 UIImagePickerControllerSourceTypeCamera])
            {
                controller.sourceType=UIImagePickerControllerSourceTypeCamera;
                [controller setDelegate:self];
               
                [self.popover setDelegate:self];
                [self.popover presentPopoverFromRect:CGRectMake(0.0, 0.0, 1200.0,1200.0)
                                              inView:self.view
                            permittedArrowDirections:UIPopoverArrowDirectionAny
                                            animated:YES];
                //[self.popover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];
            }
            else {
                [Global showAlert:@"Camera is not available." message:@"Not Successfull"];
            }
           
           
        }
    }
   
}

-(IBAction)addPhoto {

    if (appDel.iphoneIpad==1) {
        controller = [[UIImagePickerController alloc] init];
        //[controller setMediaTypes:[NSArray arrayWithObject:kUTTypeImage]];
        [controller setDelegate:self];
        [self presentModalViewController:controller animated:YES];
       
    }
    else if(appDel.iphoneIpad==2){
        controller = [[UIImagePickerController alloc] init];
        self.popover = [[UIPopoverController alloc] initWithContentViewController:controller];
       
        if ( self.popover.popoverVisible == YES) {
           
            [self.popover dismissPopoverAnimated:YES];
            [Global showAlert:@"FIRST CLOSE THE." message:@"PHOTO GALLARY"];
        }
        else {
           
            controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            [controller setDelegate:self];
            [popover setPopoverContentSize:CGSizeMake(700.0f,300.0f)];
           
            //self.popover= [[UIPopoverController alloc] initWithContentViewController:controller];
            [self.popover setDelegate:self];
           
            [self.popover presentPopoverFromRect:CGRectMake(0.0, 0.0, 800.0, 400.0)
                                          inView:self.view
                        permittedArrowDirections:UIPopoverArrowDirectionAny
                                        animated:YES];   
        }
       
    }
   
}

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    [[picker parentViewController] dismissModalViewControllerAnimated:YES];
    [picker release];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    //    savePhotoBtn.enabled=YES;
    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    ///heroImgView.image=image;
    checkImg=YES;
   
    imageView.image=image;
   
    if (appDel.iphoneIpad==2) {
        [self.popover dismissPopoverAnimated:YES];
    }
    [self dismissModalViewControllerAnimated:YES];
   
   
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    UIAlertView *alert;
   
    // Unable to save the image 
    if (error){
       
        alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                           message:@"Unable to save image to Photo Album."
                                          delegate:self cancelButtonTitle:@"Ok"
                                 otherButtonTitles:nil];
    }
    else{ // All is well
        alert = [[UIAlertView alloc] initWithTitle:@"Success"
                                           message:@"Image saved to Photo Album."
                                          delegate:self cancelButtonTitle:@"Ok"
                                 otherButtonTitles:nil];
        [alert show];
        [alert release];
       
       
    }
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    // Relinquish ownership any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
   
    // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
    // For example: self.myOutlet = nil;
}

- (void)dealloc
{
    [super dealloc];
}

@end