Friday, September 28, 2012

Android - R cannot be resolved to a variable

Project Properties -> Google Apis (make sure it is checked).  After each checkout / update from git, this is unchecked for my environment (for whatever reason.)
Project -> Clean
Project -> Build

Friday, September 14, 2012

Can't interact with bottom screen iOS Retina 4 inch


If you cannot interact with the bottom portion of the new iPhone simulator, be sure you are setting the frame of the main window.  If you configured the window with the nib, it defaults to 480 screen size, thus any UI objects located beyond the 480 screen size cannot be interacted with.  To solve, in your launched app delegate:



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
    [window setFrame:CGRectMake(0, 0, [[UIScreen mainScreen]bounds].size.width, [[UIScreen mainScreen]bounds].size.height)];

Monday, September 10, 2012

Bash Redirection Cheat Sheet

http://www.catonmat.net/download/bash-redirections-cheat-sheet.pdf

UIGestureRecognizer being handled differently on iOS6 vs iOS5

Noticed that UIGestureRecognizer would still fire off in iOS5 after a UIButton was selected.

On iOS6, the UIGestureRecognizer would not fire off if the UIButton was selected.

Friday, September 7, 2012

UIProgressBar download file

Helpful example of creating your own progress bar download.  Utilizes connection:(NSURLConnection *) delegate methods:


http://www.developers-life.com/progress-bar-download-file-on-iphone.html

Critical components:
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [self.receivedData appendData:data];
    
    NSInteger receivedLen = [data length];
    bytesReceived = (bytesReceived + receivedLen);
    
    if(expectedBytes != NSURLResponseUnknownLength) {
        self.progress = ((bytesReceived/(float)expectedBytes)*100)/100;
        percentComplete = self.progress*100;
    }
    
    [delegate downloadBarUpdated:self];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    [self.delegate downloadBar:self didFailWithError:error];
    [connection release];
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    expectedBytes = [response expectedContentLength];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    [self.delegate downloadBar:self didFinishWithData:self.receivedData suggestedFilename:localFilename];
    [connection release];
}

Thursday, September 6, 2012

Fitting all map annotations for display iOS

If you support iOS4+, use the method of creating a MKMapRect to display

MKMapRect zoomRect = MKMapRectNull;
if ([mView.annotations count] == 0) return;
NSInteger count=0;
for (id <MKAnnotation> annotation in mapView.annotations){
if( [annotation isKindOfClass:[MapViewAnnotation class]] && annotation.coordinate.latitude != 0 && annotation.coordinate.longitude != 0 ){
MKMapPoint annotationPoint = MKMapPointForCoordinate(annotation.coordinate);
MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0, 0);
if (MKMapRectIsNull(zoomRect)) {
zoomRect = pointRect;
}
else {
zoomRect = MKMapRectUnion(zoomRect, pointRect);
}
count++;
}
}
MKCoordinateRegion region = MKCoordinateRegionForMapRect(zoomRect);
[mapView setRegion:region];




If you need to support iOS3, loop through the annotations to find the top left and bottom most right annotation to figure out largest region to display:


CLLocationCoordinate2D topLeftCoord; 
    topLeftCoord.latitude = -90; 
    topLeftCoord.longitude = 180; 
    CLLocationCoordinate2D bottomRightCoord; 
    bottomRightCoord.latitude = 90; 
    bottomRightCoord.longitude = -180; 
NSInteger i=0;
    for(MapViewAnnotation *annotation in mView.annotations) { 
if(
  ([annotation isKindOfClass:[MapViewAnnotation class]] || [annotation isKindOfClass:[MKPointAnnotation class]] == includeKml) 
  && (![annotation isKindOfClass:[MKUserLocation class]])
  ){
topLeftCoord.longitude = fmin(topLeftCoord.longitude, annotation.coordinate.longitude); 
topLeftCoord.latitude = fmax(topLeftCoord.latitude, annotation.coordinate.latitude); 
bottomRightCoord.longitude = fmax(bottomRightCoord.longitude, annotation.coordinate.longitude); 
bottomRightCoord.latitude = fmin(bottomRightCoord.latitude, annotation.coordinate.latitude); 
i++;
}
    } 
    MKCoordinateRegion region; 
    region.center.latitude = topLeftCoord.latitude - (topLeftCoord.latitude - bottomRightCoord.latitude) * 0.5; 
    region.center.longitude = topLeftCoord.longitude + (bottomRightCoord.longitude - topLeftCoord.longitude) * 0.5;      
    region.span.latitudeDelta = fabs(topLeftCoord.latitude - bottomRightCoord.latitude) * 1.1; 
    // Add a little extra space on the sides 
    region.span.longitudeDelta = fabs(bottomRightCoord.longitude - topLeftCoord.longitude) * 1.1; 
    // Add a little extra space on the sides 
    region = [mView regionThatFits:region]; 
    [mView setRegion:region animated:YES]; 


Convert pixel length to latitude longitude difference iOS


//  1.  Get difference from center of map to top middle of map (200 pixel difference).
//  2.  Convert this pixel difference into difference of latitude
//  3.  Reset the mapView center point with the new offset
//Grab the pixel difference from the center of the mapview

CGPoint centerOfMap = CGPointMake(mapView.frame.size.width/2, mapView.frame.size.height/2);
CGPoint topMidOfMap = CGPointMake(centerOfMap.x, centerOfMap.y-200); //Step 1
//Now get difference of longitude and latitude
CLLocationCoordinate2D centerOfMapCoord = [mapView convertPoint:centerOfMap toCoordinateFromView:mapView];   //Step 2
CLLocationCoordinate2D topMidOfMapCoord = [mapView convertPoint:topMidOfMap toCoordinateFromView:mapView]; //Step 2
CGFloat latitudeDiff = topMidOfMapCoord.latitude - centerOfMapCoord.latitude; //Step 2
coord.latitude -= latitudeDiff;
[mapView setCenterCoordinate:coord zoomLevel:default_zoom animated:NO]; //Step 3

Wednesday, September 5, 2012

Converting screen size (pixels) to Longitude Latitude

http://stackoverflow.com/questions/11019965/convert-screen-size-pixels-to-latitude-longitude

git changed files in log

git log --name-only

Tuesday, September 4, 2012

iPhone 5 Resolution Hack crash

Modifying the plist file directly:

open /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone Simulator.app/Contents/Resources/Devices/iPhone (Retina).deviceinfo/Info.plist

May cause XCode to crash, most likely due to permission issues.  Copy the Info.plist file into a temporary directory first.  Modify the copied Info.plist file with XCode, then copy back into the directory using sudo.

Original article:
http://www.ijailbreak.com/how-to/run-apps-640-x-1136-iphone-5-resolution-hack/


iOS Auto resizing subviews

I have the parent view: self.view and a subview: UIImageView *pinView.

I would like pinView resize when self.view becomes resized.  To accomplish this:

[pinView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];


Early attempts that did NOT work:
[self.view setAutoresizesSubviews:YES];
[self.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];

You will need to apply the autoresize mask to the subview you want resized.