Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SearchBar.mm « Classes « Maps « iphone - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dc348f35d45d6253a0fbd29753c4b970fb6a5776 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#import "Framework.h"
#import "SearchBar.h"
#import "UIColor+MapsMeColor.h"
#import "UIFont+MapsMeFonts.h"

#import "3party/Alohalytics/src/alohalytics_objc.h"

@interface SearchBar ()

@property (nonatomic) UITextField * textField;
@property (nonatomic) UIButton * cancelButton;
@property (nonatomic) UIButton * clearButton;
@property (nonatomic) UIImageView * spotImageView;
@property (nonatomic) UIActivityIndicatorView * activity;
@property (nonatomic) SolidTouchView * fieldBackgroundView;

@end

extern NSString * const kAlohalyticsTapEventKey;

@implementation SearchBar

- (id)initWithFrame:(CGRect)frame
{
  self = [super initWithFrame:frame];

  [self addSubview:self.fieldBackgroundView];
  self.fieldBackgroundView.maxY = self.height - 12;
  self.fieldBackgroundView.minX = 8;

  [self.fieldBackgroundView addSubview:self.spotImageView];
  self.spotImageView.center = CGPointMake(14, self.fieldBackgroundView.height / 2 - 1);
  [self.fieldBackgroundView addSubview:self.activity];
  self.activity.center = CGPointMake(self.spotImageView.center.x, self.spotImageView.center.y + INTEGRAL(0.5));

  [self.fieldBackgroundView addSubview:self.clearButton];
  self.clearButton.midY = self.fieldBackgroundView.height / 2;
  self.clearButton.midX = self.fieldBackgroundView.width - 14;

  self.cancelButton.midY = self.height / 2 - 5;
  self.cancelButton.maxX = self.width - 8;
  [self addSubview:self.cancelButton];

  [self addSubview:self.textField];
  self.textField.midY = self.height / 2 - 3;
  self.textField.minX = 36.;

  self.textField.tintColor = [UIColor blackHintText];

  return self;
}

- (void)setSearching:(BOOL)searching
{
  if (searching)
  {
    [self.activity startAnimating];
    self.spotImageView.alpha = 0;
  }
  else
  {
    [self.activity stopAnimating];
    self.spotImageView.alpha = 1;
  }
}

- (void)cancelButtonPressed:(id)sender
{
  [Alohalytics logEvent:kAlohalyticsTapEventKey withValue:@"searchCancel"];
  [self.delegate searchBarDidPressCancelButton:self];
}

- (void)clearButtonPressed
{
  [self.delegate searchBarDidPressClearButton:self];
}

- (UIButton *)cancelButton
{
  if (!_cancelButton)
  {
    _cancelButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 52, 44)];
    _cancelButton.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:15];
    _cancelButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin;
    [_cancelButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_cancelButton setTitleColor:[UIColor colorWithWhite:1 alpha:0.5] forState:UIControlStateHighlighted];
    NSString * title = L(@"cancel");
    CGFloat const titleWidth = [title sizeWithDrawSize:CGSizeMake(80, 25) font:_cancelButton.titleLabel.font].width + 2;
    _cancelButton.width = MAX(titleWidth, _cancelButton.width);
    [_cancelButton setTitle:title forState:UIControlStateNormal];
    [_cancelButton addTarget:self action:@selector(cancelButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
  }
  return _cancelButton;
}

- (UIButton *)clearButton
{
 if (!_clearButton)
  {
    _clearButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
    _clearButton.contentMode = UIViewContentModeCenter;
    _clearButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
    [_clearButton setImage:[UIImage imageNamed:@"SearchBarClearButton"] forState:UIControlStateNormal];
    [_clearButton addTarget:self action:@selector(clearButtonPressed) forControlEvents:UIControlEventTouchUpInside];
  }
  return _clearButton;
}

- (SolidTouchView *)fieldBackgroundView
{
  if (!_fieldBackgroundView)
  {
    _fieldBackgroundView = [[SolidTouchView alloc] initWithFrame:CGRectMake(0, 0, 0, 27)];
    _fieldBackgroundView.backgroundColor = [UIColor whiteColor];
    _fieldBackgroundView.userInteractionEnabled = YES;
    _fieldBackgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    _fieldBackgroundView.layer.cornerRadius = 4.;
  }
  return _fieldBackgroundView;
}

- (UITextField *)textField
{
  if (!_textField)
  {
    _textField = [[UITextField alloc] initWithFrame:CGRectMake(1, 0, self.width, 22)];
    _textField.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    _textField.font = [UIFont regular16];
    _textField.textColor = [UIColor blackPrimaryText];
    _textField.placeholder = L(@"search");
    _textField.returnKeyType = UIReturnKeySearch;
    _textField.autocorrectionType = UITextAutocorrectionTypeNo;
    _textField.enablesReturnKeyAutomatically = YES;
  }
  return _textField;
}

- (UIImageView *)spotImageView
{
  if (!_spotImageView)
  {
    _spotImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ic_search"]];
    _spotImageView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin;
  }
  return _spotImageView;
}

- (UIActivityIndicatorView *)activity
{
  if (!_activity)
  {
    _activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    _activity.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin;
  }
  return _activity;
}

@end