[iOS] copy function for coordinates

This commit is contained in:
Kirill Zhdanovich 2013-06-27 16:47:26 +03:00 committed by Alex Zolotarev
parent 366c57ac6a
commit 6ede1f2797
4 changed files with 109 additions and 44 deletions

View file

@ -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;

View file

@ -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

View file

@ -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;

View file

@ -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;