1 |
/**
|
2 |
* ZANavi, Zoff Android Navigation system.
|
3 |
* Copyright (C) 2015 Zoff <zoff@zoff.cc>
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* version 2 as published by the Free Software Foundation.
|
8 |
*
|
9 |
* This program is distributed in the hope that it will be useful,
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
* GNU General Public License for more details.
|
13 |
*
|
14 |
* You should have received a copy of the GNU General Public License
|
15 |
* along with this program; if not, write to the
|
16 |
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
17 |
* Boston, MA 02110-1301, USA.
|
18 |
*/
|
19 |
|
20 |
package com.zoffcc.applications.zanavi;
|
21 |
|
22 |
import android.content.Context;
|
23 |
import android.graphics.Canvas;
|
24 |
import android.graphics.Color;
|
25 |
import android.graphics.Paint;
|
26 |
import android.graphics.Paint.Style;
|
27 |
import android.text.Editable;
|
28 |
import android.text.TextWatcher;
|
29 |
import android.util.AttributeSet;
|
30 |
import android.widget.AutoCompleteTextView;
|
31 |
|
32 |
public class ZANaviAutoCompleteTextViewSearchLocation extends AutoCompleteTextView
|
33 |
{
|
34 |
|
35 |
public ZANaviAutoCompleteTextViewSearchLocation(Context context)
|
36 |
{
|
37 |
super(context);
|
38 |
|
39 |
this.addTextChangedListener(new TextWatcher()
|
40 |
{
|
41 |
@Override
|
42 |
public void onTextChanged(CharSequence s, int start, int before, int count)
|
43 |
{
|
44 |
|
45 |
}
|
46 |
|
47 |
@Override
|
48 |
public void afterTextChanged(Editable arg0)
|
49 |
{
|
50 |
}
|
51 |
|
52 |
@Override
|
53 |
public void beforeTextChanged(CharSequence s, int start, int count, int after)
|
54 |
{
|
55 |
}
|
56 |
});
|
57 |
|
58 |
}
|
59 |
|
60 |
public ZANaviAutoCompleteTextViewSearchLocation(Context context, AttributeSet attrs)
|
61 |
{
|
62 |
super(context, attrs);
|
63 |
|
64 |
this.addTextChangedListener(new TextWatcher()
|
65 |
{
|
66 |
@Override
|
67 |
public void onTextChanged(CharSequence s, int start, int before, int count)
|
68 |
{
|
69 |
|
70 |
}
|
71 |
|
72 |
@Override
|
73 |
public void afterTextChanged(Editable arg0)
|
74 |
{
|
75 |
}
|
76 |
|
77 |
@Override
|
78 |
public void beforeTextChanged(CharSequence s, int start, int count, int after)
|
79 |
{
|
80 |
}
|
81 |
});
|
82 |
|
83 |
}
|
84 |
|
85 |
public ZANaviAutoCompleteTextViewSearchLocation(Context context, AttributeSet attrs, int defStyle)
|
86 |
{
|
87 |
super(context, attrs, defStyle);
|
88 |
|
89 |
this.addTextChangedListener(new TextWatcher()
|
90 |
{
|
91 |
@Override
|
92 |
public void onTextChanged(CharSequence s, int start, int before, int count)
|
93 |
{
|
94 |
|
95 |
}
|
96 |
|
97 |
@Override
|
98 |
public void afterTextChanged(Editable arg0)
|
99 |
{
|
100 |
}
|
101 |
|
102 |
@Override
|
103 |
public void beforeTextChanged(CharSequence s, int start, int count, int after)
|
104 |
{
|
105 |
}
|
106 |
});
|
107 |
|
108 |
}
|
109 |
|
110 |
private Paint paint = new Paint();
|
111 |
// private int xx = 0;
|
112 |
// private float textHeight = 0;
|
113 |
// private float textOffset = 0;
|
114 |
private float mt = 0;
|
115 |
private int start_x = 0;
|
116 |
private String this_text = "";
|
117 |
private String text1 = "";
|
118 |
private String text2 = "";
|
119 |
private float space = 10;
|
120 |
private int split_at = -1;
|
121 |
|
122 |
private int color_street = 0xaa00ff00;
|
123 |
private int color_town = 0xaa0000ff;
|
124 |
|
125 |
private int line_thickness_in_dp = 5;
|
126 |
|
127 |
protected void onDraw(Canvas c)
|
128 |
{
|
129 |
super.onDraw(c);
|
130 |
|
131 |
try
|
132 |
{
|
133 |
if (Navit.use_index_search)
|
134 |
{
|
135 |
this_text = this.getText().toString();
|
136 |
paint.setTextSize(this.getTextSize());
|
137 |
// textHeight = paint.descent() - paint.ascent();
|
138 |
// textOffset = (textHeight / 2) - paint.descent();
|
139 |
|
140 |
split_at = this_text.lastIndexOf(" ");
|
141 |
|
142 |
if ((this_text.length() > 1) && (split_at != -1) && (split_at != 0) && (split_at < (this_text.length() - 1)))
|
143 |
{
|
144 |
space = paint.measureText(" ");
|
145 |
text1 = this_text.substring(0, split_at);
|
146 |
text2 = this_text.substring(split_at);
|
147 |
|
148 |
start_x = this.getPaddingLeft();
|
149 |
mt = paint.measureText(text1);
|
150 |
paint.setColor(color_street);
|
151 |
paint.setStrokeWidth(NavitGraphics.dp_to_px(line_thickness_in_dp));
|
152 |
paint.setStyle(Style.STROKE);
|
153 |
c.drawLine(start_x, NavitGraphics.dp_to_px(line_thickness_in_dp), start_x + mt, NavitGraphics.dp_to_px(line_thickness_in_dp), paint);
|
154 |
|
155 |
start_x = (int) (this.getPaddingLeft() + mt + space);
|
156 |
mt = paint.measureText(text2);
|
157 |
paint.setColor(color_town);
|
158 |
c.drawLine(start_x, NavitGraphics.dp_to_px(line_thickness_in_dp), start_x + mt - space, NavitGraphics.dp_to_px(line_thickness_in_dp), paint);
|
159 |
}
|
160 |
else
|
161 |
{
|
162 |
start_x = this.getPaddingLeft();
|
163 |
mt = paint.measureText(this_text);
|
164 |
|
165 |
paint.setColor(color_street);
|
166 |
paint.setStrokeWidth(NavitGraphics.dp_to_px(line_thickness_in_dp));
|
167 |
paint.setStyle(Style.STROKE);
|
168 |
c.drawLine(start_x, NavitGraphics.dp_to_px(line_thickness_in_dp), start_x + mt, NavitGraphics.dp_to_px(line_thickness_in_dp), paint);
|
169 |
}
|
170 |
}
|
171 |
}
|
172 |
catch (Exception e)
|
173 |
{
|
174 |
}
|
175 |
}
|
176 |
}
|