From 29901b297cb4f33b333139eba77984a1426a4e4e Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Sun, 13 Nov 2011 20:04:59 +0300 Subject: [PATCH] [ios] Implemented SearchView programmatically for easier localization and faster usage --- iphone/Maps/Classes/SearchVC.h | 5 +- iphone/Maps/Classes/SearchVC.mm | 68 +++++- iphone/Maps/Maps.xcodeproj/project.pbxproj | 4 - iphone/Maps/Search.xib | 247 --------------------- 4 files changed, 59 insertions(+), 265 deletions(-) delete mode 100644 iphone/Maps/Search.xib diff --git a/iphone/Maps/Classes/SearchVC.h b/iphone/Maps/Classes/SearchVC.h index ab534aa620..b0c6827ff2 100644 --- a/iphone/Maps/Classes/SearchVC.h +++ b/iphone/Maps/Classes/SearchVC.h @@ -21,14 +21,13 @@ typedef Framework framework_t; framework_t * m_framework; LocationManager * m_locationManager; vector m_results; + UISearchBar * m_searchBar; + UITableView * m_table; // UILabel * m_warningView; /// Warning view shows only if this text is not nil // NSString * m_warningViewText; } -@property (nonatomic, retain) IBOutlet UISearchBar * m_searchBar; -@property (nonatomic, retain) IBOutlet UITableView * m_table; - - (id)initWithFramework:(framework_t *)framework andLocationManager:(LocationManager *)lm; @end diff --git a/iphone/Maps/Classes/SearchVC.mm b/iphone/Maps/Classes/SearchVC.mm index f083bdaa31..e1627dd2b7 100644 --- a/iphone/Maps/Classes/SearchVC.mm +++ b/iphone/Maps/Classes/SearchVC.mm @@ -58,6 +58,23 @@ static void OnSearchResultCallback(search::Result const & res, int queryId) ///////////////////////////////////////////////////////////////////// +@interface CustomView : UIView +@end +@implementation CustomView +- (void)layoutSubviews +{ + UISearchBar * searchBar = (UISearchBar *)[self.subviews objectAtIndex:0]; + [searchBar sizeToFit]; + UITableView * table = (UITableView *)[self.subviews objectAtIndex:1]; + CGRect rTable; + rTable.origin = CGPointMake(searchBar.frame.origin.x, searchBar.frame.origin.y + searchBar.frame.size.height); + rTable.size = self.bounds.size; + rTable.size.height -= searchBar.bounds.size.height; + table.frame = rTable; +} +@end + +//////////////////////////////////////////////////////////////////// /// Key to store settings #define SEARCH_MODE_SETTING "SearchMode" #define SEARCH_MODE_POPULARITY "ByPopularity" @@ -67,9 +84,6 @@ static void OnSearchResultCallback(search::Result const & res, int queryId) @implementation SearchVC -@synthesize m_searchBar; -@synthesize m_table; - // Controls visibility of information window with GPS location problems //- (void)showOrHideGPSWarningIfNeeded //{ @@ -149,7 +163,7 @@ static void OnSearchResultCallback(search::Result const & res, int queryId) - (id)initWithFramework:(framework_t *)framework andLocationManager:(LocationManager *)lm { - if ((self = [super initWithNibName:@"Search" bundle:nil])) + if ((self = [super initWithNibName:nil bundle:nil])) { m_framework = framework; m_locationManager = lm; @@ -157,6 +171,30 @@ static void OnSearchResultCallback(search::Result const & res, int queryId) return self; } +- (void)loadView +{ + // create user interface + CustomView * parentView = [[[CustomView alloc] init] autorelease]; + parentView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight; + + m_searchBar = [[UISearchBar alloc] init]; + m_searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth; + m_searchBar.delegate = self; + m_searchBar.placeholder = @"Search map"; + m_searchBar.showsCancelButton = YES; + m_searchBar.showsScopeBar = YES; + m_searchBar.scopeButtonTitles = [NSArray arrayWithObjects:@"By popularity", @"On the screen", @"Near me", nil]; + [parentView addSubview:m_searchBar]; + + m_table = [[UITableView alloc] init]; + m_table.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight; + m_table.delegate = self; + m_table.dataSource = self; + [parentView addSubview:m_table]; + + self.view = parentView; +} + - (void)clearResults { m_results.clear(); @@ -166,6 +204,8 @@ static void OnSearchResultCallback(search::Result const & res, int queryId) { // [m_warningViewText release]; g_searchVC = nil; + [m_searchBar release]; + [m_table release]; [self clearResults]; [super dealloc]; } @@ -179,8 +219,8 @@ static void OnSearchResultCallback(search::Result const & res, int queryId) { g_searchVC = nil; // to correctly free memory - self.m_searchBar = nil; - self.m_table = nil; + [m_searchBar release]; m_searchBar = nil; + [m_table release]; m_table = nil; m_results.clear(); [super viewDidUnload]; @@ -308,18 +348,23 @@ static void OnSearchResultCallback(search::Result const & res, int queryId) - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"MyTableViewCell"]; + UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"SearchVCTableViewCell"]; if (!cell) + { cell = [[[UITableViewCell alloc] - initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"MyTableViewCell"] + initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"SearchVCTableViewCell"] autorelease]; + } cell.accessoryView = nil; if (indexPath.row < m_results.size()) { search::Result const & r = m_results[indexPath.row]; cell.textLabel.text = [NSString stringWithUTF8String:r.GetString()]; - [self updateCellDistance:cell withIndex:indexPath.row]; + if (r.GetResultType() == search::Result::RESULT_FEATURE) + [self updateCellDistance:cell withIndex:indexPath.row]; + else + cell.detailTextLabel.text = nil; } else cell.textLabel.text = @"BUG"; @@ -393,8 +438,9 @@ static void OnSearchResultCallback(search::Result const & res, int queryId) for (NSUInteger i = 0; i < cells.count; ++i) { UITableViewCell * cell = (UITableViewCell *)[cells objectAtIndex:i]; - [self updateCellAngle:cell withIndex:[m_table indexPathForCell:cell].row - andAngle:((info.m_trueHeading < 0) ? info.m_magneticHeading : info.m_trueHeading)]; + NSInteger const index = [m_table indexPathForCell:cell].row; + if (m_results[index].GetResultType() == search::Result::RESULT_FEATURE) + [self updateCellAngle:cell withIndex:index andAngle:((info.m_trueHeading < 0) ? info.m_magneticHeading : info.m_trueHeading)]; } } //*********** End of Location manager callbacks ******************** diff --git a/iphone/Maps/Maps.xcodeproj/project.pbxproj b/iphone/Maps/Maps.xcodeproj/project.pbxproj index c71b0c858d..98841cb832 100644 --- a/iphone/Maps/Maps.xcodeproj/project.pbxproj +++ b/iphone/Maps/Maps.xcodeproj/project.pbxproj @@ -18,7 +18,6 @@ 46F26D1F10F626CB00ECCA39 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 46F26D1E10F626CB00ECCA39 /* QuartzCore.framework */; }; 490830551426B0900088EE84 /* downloader.png in Resources */ = {isa = PBXBuildFile; fileRef = 490830531426B0900088EE84 /* downloader.png */; }; 490830561426B0900088EE84 /* downloader@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 490830541426B0900088EE84 /* downloader@2x.png */; }; - 490830591426BD460088EE84 /* Search.xib in Resources */ = {isa = PBXBuildFile; fileRef = 490830581426BD460088EE84 /* Search.xib */; }; 4938BB1D1343652600E0815A /* dictionary.slf in Resources */ = {isa = PBXBuildFile; fileRef = 4938BB1C1343652600E0815A /* dictionary.slf */; }; 4945D21C1334187D0082387C /* settings.png in Resources */ = {isa = PBXBuildFile; fileRef = 4945D21A1334187D0082387C /* settings.png */; }; 4945D21D1334187D0082387C /* settings@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4945D21B1334187D0082387C /* settings@2x.png */; }; @@ -622,7 +621,6 @@ 46F8A2EB10EB63040045521A /* MapViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = MapViewController.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; 490830531426B0900088EE84 /* downloader.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = downloader.png; sourceTree = ""; }; 490830541426B0900088EE84 /* downloader@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "downloader@2x.png"; sourceTree = ""; }; - 490830581426BD460088EE84 /* Search.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = Search.xib; sourceTree = SOURCE_ROOT; }; 4938BB1C1343652600E0815A /* dictionary.slf */ = {isa = PBXFileReference; lastKnownFileType = file; name = dictionary.slf; path = ../../data/dictionary.slf; sourceTree = ""; }; 4945D21A1334187D0082387C /* settings.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = settings.png; sourceTree = ""; }; 4945D21B1334187D0082387C /* settings@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "settings@2x.png"; sourceTree = ""; }; @@ -1338,7 +1336,6 @@ FA5005611287BFCE002961F0 /* Icon@2x.png */, 28AD73870D9D96C1002E5188 /* MainWindow.xib */, 8D1107310486CEB800E47090 /* MapsWithMe-Info.plist */, - 490830581426BD460088EE84 /* Search.xib */, ); name = Resources; sourceTree = ""; @@ -2583,7 +2580,6 @@ FAF805311417E3510024E8C1 /* zw@2x.png in Resources */, 490830551426B0900088EE84 /* downloader.png in Resources */, 490830561426B0900088EE84 /* downloader@2x.png in Resources */, - 490830591426BD460088EE84 /* Search.xib in Resources */, FA459EB414327AF700B5BB3C /* WorldCoasts.mwm in Resources */, FA85F633145DDDC20090E1A0 /* packed_polygons.bin in Resources */, ); diff --git a/iphone/Maps/Search.xib b/iphone/Maps/Search.xib deleted file mode 100644 index 627b7855c4..0000000000 --- a/iphone/Maps/Search.xib +++ /dev/null @@ -1,247 +0,0 @@ - - - - 1024 - 11C74 - 1938 - 1138.23 - 567.00 - - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - 933 - - - IBUITableView - IBUIView - IBUISearchBar - IBProxyObject - - - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - - - PluginDependencyRecalculationVersion - - - - - IBFilesOwner - IBCocoaTouchFramework - - - IBFirstResponder - IBCocoaTouchFramework - - - - 274 - - - - 274 - {{0, 88}, {320, 372}} - - - _NS:418 - - 3 - MQA - - YES - NO - IBCocoaTouchFramework - YES - NO - 1 - 0 - YES - 44 - 22 - 22 - - - - 290 - {320, 88} - - - _NS:597 - 3 - IBCocoaTouchFramework - Search maps - YES - - 1 - IBCocoaTouchFramework - - - By popularity - On the screen - Near me - - YES - - - {{0, 20}, {320, 460}} - - - - - 3 - MQA - - 2 - - - NO - - IBCocoaTouchFramework - - - - - - - m_searchBar - - - - 13 - - - - view - - - - 14 - - - - m_table - - - - 16 - - - - delegate - - - - 12 - - - - delegate - - - - 17 - - - - dataSource - - - - 18 - - - - - - 0 - - - - - - 1 - - - - - - - - - -1 - - - File's Owner - - - -2 - - - - - 11 - - - - - 15 - - - - - - - SearchVC - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - UIResponder - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - - - - - - 18 - - - - - SearchVC - UIViewController - - UISearchBar - UITableView - - - - m_searchBar - UISearchBar - - - m_table - UITableView - - - - IBProjectSource - ./Classes/SearchVC.h - - - - - 0 - IBCocoaTouchFramework - - com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS - - - - com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3 - - - YES - 3 - 933 - -