diff options
author | Kirill Zhdanovich <kzhdanovich@gmail.com> | 2013-06-27 17:47:26 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:57:21 +0300 |
commit | 6ede1f2797b71e7d692151b884c527231b78b9ff (patch) | |
tree | 0d8f4dabd02f83dfadb77a3be4f094aced937165 /iphone | |
parent | 366c57ac6a0c8ac48e22c8831b641a4afb3a979e (diff) |
[iOS] copy function for coordinates
Diffstat (limited to 'iphone')
-rw-r--r-- | iphone/Maps/Bookmarks/PlacePageVC.h | 2 | ||||
-rw-r--r-- | iphone/Maps/Bookmarks/PlacePageVC.mm | 70 | ||||
-rw-r--r-- | iphone/Maps/Classes/PlacePreviewViewController.h | 2 | ||||
-rw-r--r-- | iphone/Maps/Classes/PlacePreviewViewController.mm | 79 |
4 files changed, 109 insertions, 44 deletions
diff --git a/iphone/Maps/Bookmarks/PlacePageVC.h b/iphone/Maps/Bookmarks/PlacePageVC.h index 2417807c90..7ffeb9d1c9 100644 --- a/iphone/Maps/Bookmarks/PlacePageVC.h +++ b/iphone/Maps/Bookmarks/PlacePageVC.h @@ -7,7 +7,7 @@ namespace search { struct AddressInfo; } namespace url_scheme { struct ApiPoint; } -@interface PlacePageVC : UITableViewController <UITextFieldDelegate, UIActionSheetDelegate, MFMailComposeViewControllerDelegate, MFMessageComposeViewControllerDelegate, UIPickerViewDelegate, UITextViewDelegate> +@interface PlacePageVC : UITableViewController <UITextFieldDelegate, UIActionSheetDelegate, MFMailComposeViewControllerDelegate, MFMessageComposeViewControllerDelegate, UIPickerViewDelegate, UITextViewDelegate, UIGestureRecognizerDelegate> - (id) initWithInfo:(search::AddressInfo const &)info point:(CGPoint)point; - (id) initWithApiPoint:(url_scheme::ApiPoint const &)apiPoint; diff --git a/iphone/Maps/Bookmarks/PlacePageVC.mm b/iphone/Maps/Bookmarks/PlacePageVC.mm index 39bea35f9b..ea7cc5869c 100644 --- a/iphone/Maps/Bookmarks/PlacePageVC.mm +++ b/iphone/Maps/Bookmarks/PlacePageVC.mm @@ -78,6 +78,7 @@ CGFloat const pMargin = 10; #define DESCRIPTIONHEIGHT 140 #define TWOBUTTONSHEIGHT 44 #define CELLHEIGHT 44 +#define COORDINATECOLOR 51.0/255.0 static NSString * const g_colors [] = { @@ -744,26 +745,17 @@ typedef enum {Editing, Saved} Mode; cell = [tableView dequeueReusableCellWithIdentifier:@"CoordinatesCELL"]; if (!cell) { - cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"CoordinatesCELL"] autorelease]; - cell.textLabel.text = @"Temporary Name"; - [cell layoutSubviews]; - UITextField * f = [[UITextField alloc] initWithFrame:cell.contentView.frame]; - f.tag = COORDINATE_TAG; - f.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - f.returnKeyType = UIReturnKeyDone; - f.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; - f.font = [UIFont fontWithName:@"Helvetica" size:26]; - f.textAlignment = UITextAlignmentCenter; - f.userInteractionEnabled = NO; - f.delegate = self; - [cell.contentView addSubview:f]; - [f release]; - cell.textLabel.text = @""; - [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; + cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CoordinatesCELL"] autorelease]; + cell.textLabel.textAlignment = UITextAlignmentCenter; + cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:26]; + cell.textLabel.textColor = [UIColor colorWithRed:COORDINATECOLOR green:COORDINATECOLOR blue:COORDINATECOLOR alpha:1.0]; + UILongPressGestureRecognizer * longTouch = [[[UILongPressGestureRecognizer alloc] + initWithTarget:self action:@selector(handleLongPress:)] autorelease]; + longTouch.minimumPressDuration = 1.0; + longTouch.delegate = self; + [cell addGestureRecognizer:longTouch]; } - UITextField * f = (UITextField *)[cell viewWithTag:COORDINATE_TAG]; - f.text = [NSString stringWithFormat:@"%f %f", MercatorBounds::YToLat(self.pinGlobalPosition.y), - MercatorBounds::XToLon(self.pinGlobalPosition.x)]; + cell.textLabel.text = [self coordinatesToString]; } return cell; } @@ -793,4 +785,44 @@ typedef enum {Editing, Saved} Mode; if (textView.tag == TEXTVIEW_TAG) self.pinNotes = textView.text; } + +-(void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer +{ + if (gestureRecognizer.state == UIGestureRecognizerStateBegan) + { + CGPoint p = [gestureRecognizer locationInView:self.tableView]; + NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:p]; + if (indexPath != nil) + { + [self becomeFirstResponder]; + UIMenuController * menu = [UIMenuController sharedMenuController]; + [menu setTargetRect:[self.tableView rectForRowAtIndexPath:indexPath] inView:self.tableView]; + [menu setMenuVisible:YES animated:YES]; + } + } +} + +- (BOOL)canPerformAction:(SEL)action withSender:(id)sender +{ + if (action == @selector(copy:)) + return YES; + return NO; +} + +- (BOOL)canBecomeFirstResponder +{ + return YES; +} + +- (void)copy:(id)sender +{ + [UIPasteboard generalPasteboard].string = [self coordinatesToString]; +} + +-(NSString *)coordinatesToString +{ + NSLocale * decimalPointLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease]; + return [[[NSString alloc] initWithFormat:@"%@" locale:decimalPointLocale, [NSString stringWithFormat:@"%f %f", MercatorBounds::YToLat(self.pinGlobalPosition.y), MercatorBounds::XToLon(self.pinGlobalPosition.x)]] autorelease]; +} + @end diff --git a/iphone/Maps/Classes/PlacePreviewViewController.h b/iphone/Maps/Classes/PlacePreviewViewController.h index d3de4d0654..eaa0a8807a 100644 --- a/iphone/Maps/Classes/PlacePreviewViewController.h +++ b/iphone/Maps/Classes/PlacePreviewViewController.h @@ -14,7 +14,7 @@ namespace url_scheme { struct ApiPoint; } typedef enum {APIPOINT, POI, MYPOSITION} Type; -@interface PlacePreviewViewController : UITableViewController <UIActionSheetDelegate> +@interface PlacePreviewViewController : UITableViewController <UIActionSheetDelegate, UIGestureRecognizerDelegate> -(id)initWith:(search::AddressInfo const &)info point:(CGPoint)point; -(id)initWithApiPoint:(url_scheme::ApiPoint const &)apiPoint; -(id)initWithPoint:(CGPoint)point; diff --git a/iphone/Maps/Classes/PlacePreviewViewController.mm b/iphone/Maps/Classes/PlacePreviewViewController.mm index e021a73ad7..e485d4f4f8 100644 --- a/iphone/Maps/Classes/PlacePreviewViewController.mm +++ b/iphone/Maps/Classes/PlacePreviewViewController.mm @@ -21,6 +21,7 @@ #define BALLOON_PROPOSAL_ALERT_VIEW 11 #define TWOBUTTONSHEIGHT 44 #define COORDINATE_TAG 333 +#define COORDINATECOLOR 51.0/255.0 @interface PlacePreviewViewController() { @@ -116,28 +117,17 @@ cell = [tableView dequeueReusableCellWithIdentifier:@"CoordinatesCELL"]; if (!cell) { - cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"CoordinatesCELL"] autorelease]; - cell.textLabel.text = @"Temporary Name"; - [cell layoutSubviews]; - UITextField * f = [[UITextField alloc] initWithFrame:cell.contentView.frame]; - f.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - f.returnKeyType = UIReturnKeyDone; - f.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; - f.textColor = cell.textLabel.textColor; - f.font = [UIFont fontWithName:@"Helvetica" size:26]; - f.textAlignment = UITextAlignmentCenter; - f.userInteractionEnabled = NO; - f.tag = COORDINATE_TAG; - [cell.contentView addSubview:f]; - [f release]; - cell.textLabel.text = @""; - [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; + cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CoordinatesCELL"] autorelease]; + cell.textLabel.textAlignment = UITextAlignmentCenter; + cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:26]; + cell.textLabel.textColor = [UIColor colorWithRed:COORDINATECOLOR green:COORDINATECOLOR blue:COORDINATECOLOR alpha:1.0]; + UILongPressGestureRecognizer * longTouch = [[[UILongPressGestureRecognizer alloc] + initWithTarget:self action:@selector(handleLongPress:)] autorelease]; + longTouch.minimumPressDuration = 1.0; + longTouch.delegate = self; + [cell addGestureRecognizer:longTouch]; } - UITextField * f = (UITextField *)[cell viewWithTag:COORDINATE_TAG]; - if (m_previewType == APIPOINT) - f.text = [NSString stringWithFormat:@"%f %f", m_apiPoint.m_lat, m_apiPoint.m_lon]; - else - f.text = [NSString stringWithFormat:@"%f %f", MercatorBounds::YToLat(m_point.y), MercatorBounds::XToLon(m_point.x)]; + cell.textLabel.text = [self coordinatesToString]; } } else @@ -147,8 +137,6 @@ cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ApiReturnCell"] autorelease]; cell.textLabel.text = NSLocalizedString(@"more_info", nil); } - if (indexPath.section != 2) - [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; return cell; } @@ -156,6 +144,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { + [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; if (m_previewType == APIPOINT && indexPath.section == 2) { [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; @@ -315,6 +304,50 @@ [self.tableView reloadData]; } +-(void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer +{ + if (gestureRecognizer.state == UIGestureRecognizerStateBegan) + { + CGPoint p = [gestureRecognizer locationInView:self.tableView]; + NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:p]; + if (indexPath != nil) + { + [self becomeFirstResponder]; + UIMenuController * menu = [UIMenuController sharedMenuController]; + [menu setTargetRect:[self.tableView rectForRowAtIndexPath:indexPath] inView:self.tableView]; + [menu setMenuVisible:YES animated:YES]; + } + } +} + +- (BOOL)canPerformAction:(SEL)action withSender:(id)sender +{ + if (action == @selector(copy:)) + return YES; + return NO; +} + +- (BOOL)canBecomeFirstResponder +{ + return YES; +} + +- (void)copy:(id)sender +{ + [UIPasteboard generalPasteboard].string = [self coordinatesToString]; +} + +-(NSString *)coordinatesToString +{ + NSString * result = nil; + if (m_previewType == APIPOINT) + result = [NSString stringWithFormat:@"%f %f", m_apiPoint.m_lat, m_apiPoint.m_lon]; + else + result = [NSString stringWithFormat:@"%f %f", MercatorBounds::YToLat(m_point.y), MercatorBounds::XToLon(m_point.x)]; + NSLocale * decimalPointLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]; + return [[[NSString alloc] initWithFormat:@"%@" locale:decimalPointLocale,result] autorelease]; +} + -(void)dealloc { self.placeAndCompass = nil; |