Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Tweak bookmark color + Cache bookmarked icon images.

  • Loading branch information...
commit e38ac379a132ded6718d37ab2346cc1562133576 1 parent 373e5ce
@mzheng authored
View
2  Libraries/aaronbrethorst-onebusaway-iphone-common-fa9a21b/Classes/View/OBAStopIconFactory.h
@@ -9,7 +9,7 @@
- (UIImage*) getIconForStop:(OBAStopV2*)stop;
- (UIImage*) getIconForStop:(OBAStopV2*)stop includeDirection:(BOOL)includeDirection;
-- (UIImage*) getBookmarkedIconForStop:(OBAStopV2*)stop;
+- (UIImage*) getIconForStop:(OBAStopV2*)stop includeDirection:(BOOL)includeDirection isBookmarked:(BOOL)isBookmarked;
- (UIImage*) getModeIconForRoute:(OBARouteV2*)route;
- (UIImage*) getModeIconForRoute:(OBARouteV2*)route selected:(BOOL)selected;
View
87 Libraries/aaronbrethorst-onebusaway-iphone-common-fa9a21b/Classes/View/OBAStopIconFactory.m
@@ -1,7 +1,7 @@
#import "OBAStopIconFactory.h"
#import "OBARouteV2.h"
-#define BOOKMARK_COLOR [UIColor colorWithRed:1.0 green:211.0/255.0 blue:94.0/255.0 alpha:1.0]
+#define BOOKMARK_COLOR [UIColor colorWithRed:1 green:243/255.0 blue:104/255.0 alpha:1.0]
@interface OBAStopIconFactory (Private)
@@ -11,6 +11,12 @@ - (NSString*) getRouteIconTypeForStop:(OBAStopV2*)stop;
- (NSString*) getRouteIconTypeForRouteTypes:(NSSet*)routeTypes;
- (NSString*) getRouteIconTypeForRoute:(OBARouteV2*)route;
+- (NSString*) keyForIcontTypeId:(NSString *)iconTypeId
+ directionId:(NSString *)directionId
+ isBookmarked:(BOOL) isBookmarked;
+
+- (UIImage *) getBookmarkedIconForImage:(UIImage *)image;
+
@end
@@ -30,13 +36,17 @@ - (UIImage*) getIconForStop:(OBAStopV2*)stop {
}
- (UIImage*) getIconForStop:(OBAStopV2*)stop includeDirection:(BOOL)includeDirection {
+ return [self getIconForStop:stop includeDirection:includeDirection isBookmarked:NO];
+}
+
+- (UIImage*) getIconForStop:(OBAStopV2*)stop includeDirection:(BOOL)includeDirection isBookmarked:(BOOL)isBookmarked {
NSString * routeIconType = [self getRouteIconTypeForStop:stop];
NSString * direction = @"";
if( includeDirection && stop.direction )
direction = stop.direction;
- NSString * key = [NSString stringWithFormat:@"%@StopIcon%@",routeIconType,direction];
+ NSString * key = [self keyForIcontTypeId:routeIconType directionId:direction isBookmarked:isBookmarked];
UIImage * image = _stopIcons[key];
@@ -46,38 +56,6 @@ - (UIImage*) getIconForStop:(OBAStopV2*)stop includeDirection:(BOOL)includeDirec
return image;
}
-- (UIImage *)bookmarkedIconForImage:(UIImage *)image {
- UIColor *color = BOOKMARK_COLOR;
- UIGraphicsBeginImageContextWithOptions(image.size, NO, image.scale);
-
- CGContextRef context = UIGraphicsGetCurrentContext();
- CGRect area = CGRectMake(0, 0, image.size.width, image.size.height);
-
- CGContextScaleCTM(context, 1, -1);
- CGContextTranslateCTM(context, 0, -area.size.height);
-
- CGContextSaveGState(context);
- CGContextClipToMask(context, area, image.CGImage);
-
- [color set];
- CGContextFillRect(context, area);
-
- CGContextRestoreGState(context);
-
- CGContextSetBlendMode(context, kCGBlendModeMultiply);
- CGContextDrawImage(context, area, image.CGImage);
- UIImage *colorizedImage = UIGraphicsGetImageFromCurrentImageContext();
-
- UIGraphicsEndImageContext();
-
- return colorizedImage;
-}
-
-- (UIImage *)getBookmarkedIconForStop:(OBAStopV2*)stop {
- UIImage *originalIcon = [self getIconForStop:stop];
- return [self bookmarkedIconForImage:originalIcon];
-}
-
- (UIImage*) getModeIconForRoute:(OBARouteV2*)route {
return [self getModeIconForRoute:route selected:NO];
}
@@ -117,16 +95,28 @@ - (void) loadIcons {
NSString * iconType = iconTypeIds[j];
for( int i=0; i<[directionIds count]; i++) {
NSString * directionId = directionIds[i];
- NSString * key = [NSString stringWithFormat:@"%@StopIcon%@",iconType,directionId];
+ NSString * key = [self keyForIcontTypeId:iconType directionId:directionId isBookmarked:NO];
NSString * imageName = [NSString stringWithFormat:@"%@.png",key];
UIImage * image = [UIImage imageNamed:imageName];
_stopIcons[key] = image;
+
+ NSString *bookmarkedKey = [self keyForIcontTypeId:iconType directionId:directionId isBookmarked:YES];
+ UIImage *bookmarkedImage = [self getBookmarkedIconForImage:image];
+ _stopIcons[bookmarkedKey] = bookmarkedImage;
}
}
_defaultStopIcon = _stopIcons[@"BusStopIcon"];
}
+- (NSString *)keyForIcontTypeId:(NSString *)iconTypeId

typo. should be keyForIconTypeId:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ directionId:(NSString *)directionId
+ isBookmarked:(BOOL) isBookmarked
+{
+ NSString *imageName = [NSString stringWithFormat:@"%@StopIcon%@",iconTypeId,directionId];
+ return isBookmarked ? [NSString stringWithFormat:@"Bookmarked%@", imageName] : imageName;
+}
+
- (NSString*) getRouteIconTypeForStop:(OBAStopV2*)stop {
NSMutableSet * routeTypes = [NSMutableSet set];
for( OBARouteV2 * route in stop.routes ) {
@@ -162,4 +152,31 @@ - (NSString*) getRouteIconTypeForRoute:(OBARouteV2*)route {
}
}
+- (UIImage *)getBookmarkedIconForImage:(UIImage *)image {
+ UIColor *color = BOOKMARK_COLOR;
+ UIGraphicsBeginImageContextWithOptions(image.size, NO, image.scale);
+
+ CGContextRef context = UIGraphicsGetCurrentContext();
+ CGRect area = CGRectMake(0, 0, image.size.width, image.size.height);
+
+ CGContextScaleCTM(context, 1, -1);
+ CGContextTranslateCTM(context, 0, -area.size.height);
+
+ CGContextSaveGState(context);
+ CGContextClipToMask(context, area, image.CGImage);
+
+ [color set];
+ CGContextFillRect(context, area);
+
+ CGContextRestoreGState(context);
+
+ CGContextSetBlendMode(context, kCGBlendModeMultiply);
+ CGContextDrawImage(context, area, image.CGImage);
+ UIImage *colorizedImage = UIGraphicsGetImageFromCurrentImageContext();
+
+ UIGraphicsEndImageContext();
+
+ return colorizedImage;
+}
+
@end
View
8 view_controllers/OBASearchResultsMapViewController.m
@@ -599,12 +599,8 @@ - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnot
}
OBAStopIconFactory * stopIconFactory = self.appDelegate.stopIconFactory;
- if ([self isStopBookmarked:stop]) {
- view.image = [stopIconFactory getBookmarkedIconForStop:stop];
- }
- else {
- view.image = [stopIconFactory getIconForStop:stop];
- }
+ BOOL isBookmarked = [self isStopBookmarked:stop];
+ view.image = [stopIconFactory getIconForStop:stop includeDirection:YES isBookmarked:isBookmarked];
return view;
}
else if ([annotation isKindOfClass:[OBAPlacemark class]]) {
Please sign in to comment.
Something went wrong with that request. Please try again.