-
-
Notifications
You must be signed in to change notification settings - Fork 129
/
Copy pathCircleProxy.java
263 lines (223 loc) · 7.81 KB
/
CircleProxy.java
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2013-present by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
package ti.map;
import android.app.Activity;
import android.graphics.Color;
import android.os.Message;
import android.view.ViewGroup;
import com.google.android.gms.maps.model.Circle;
import com.google.android.gms.maps.model.CircleOptions;
import com.google.android.gms.maps.model.LatLng;
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.kroll.common.AsyncResult;
import org.appcelerator.kroll.common.TiMessenger;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.TiDimension;
import org.appcelerator.titanium.util.TiConvert;
import ti.map.Shape.IShape;
@Kroll.
proxy(name = "Circle", creatableInModule = MapModule.class,
propertyAccessors = { MapModule.PROPERTY_CENTER, MapModule.PROPERTY_RADIUS, MapModule.PROPERTY_STROKE_WIDTH,
MapModule.PROPERTY_STROKE_COLOR, MapModule.PROPERTY_FILL_COLOR, MapModule.PROPERTY_ZINDEX,
TiC.PROPERTY_VISIBLE, TiC.PROPERTY_OPACITY, TiC.PROPERTY_TOUCH_ENABLED })
public class CircleProxy extends KrollProxy implements IShape
{
private CircleOptions options;
private Circle circle;
private boolean clickable;
private static final int MSG_FIRST_ID = KrollProxy.MSG_LAST_ID + 1;
private static final int MSG_SET_CENTER = MSG_FIRST_ID + 500;
private static final int MSG_SET_RADIUS = MSG_FIRST_ID + 501;
private static final int MSG_SET_STROKE_WIDTH = MSG_FIRST_ID + 502;
private static final int MSG_SET_STROKE_COLOR = MSG_FIRST_ID + 503;
private static final int MSG_SET_FILL_COLOR = MSG_FIRST_ID + 504;
private static final int MSG_SET_ZINDEX = MSG_FIRST_ID + 505;
private static final int MSG_SET_VISIBLE = MSG_FIRST_ID + 506;
private static final int MSG_SET_OPACITY = MSG_FIRST_ID + 507;
private static final int MSG_SET_TOUCH_ENABLED = MSG_FIRST_ID + 508;
public CircleProxy()
{
super();
clickable = true;
}
private int toPx(Object size)
{
ViewGroup rootViewGroup =
(ViewGroup) TiApplication.getAppCurrentActivity().getWindow().getDecorView().findViewById(
android.R.id.content);
return TiConvert.toTiDimension(size, TiDimension.COMPLEX_UNIT_AUTO).getAsPixels(rootViewGroup);
}
private int alphaColor(int color)
{
if (hasProperty(TiC.PROPERTY_OPACITY)) {
color = Color.argb(Math.round(TiConvert.toFloat(getProperty(TiC.PROPERTY_OPACITY)) * 255), Color.red(color),
Color.green(color), Color.blue(color));
}
return color;
}
@Override
public boolean handleMessage(Message msg)
{
AsyncResult result = null;
switch (msg.what) {
case MSG_SET_CENTER: {
result = (AsyncResult) msg.obj;
LatLng location = TiMapUtils.parseLocation(result.getArg());
circle.setCenter(location);
result.setResult(null);
return true;
}
case MSG_SET_RADIUS: {
result = (AsyncResult) msg.obj;
circle.setRadius((Double) result.getArg());
result.setResult(null);
return true;
}
case MSG_SET_STROKE_WIDTH: {
result = (AsyncResult) msg.obj;
circle.setStrokeWidth((Integer) result.getArg());
result.setResult(null);
return true;
}
case MSG_SET_STROKE_COLOR: {
result = (AsyncResult) msg.obj;
circle.setStrokeColor(alphaColor((Integer) result.getArg()));
result.setResult(null);
return true;
}
case MSG_SET_FILL_COLOR: {
result = (AsyncResult) msg.obj;
circle.setFillColor(alphaColor((Integer) result.getArg()));
result.setResult(null);
return true;
}
case MSG_SET_ZINDEX: {
result = (AsyncResult) msg.obj;
circle.setZIndex((Float) result.getArg());
result.setResult(null);
return true;
}
case MSG_SET_VISIBLE: {
result = (AsyncResult) msg.obj;
circle.setVisible((Boolean) result.getArg());
result.setResult(null);
return true;
}
case MSG_SET_OPACITY: {
result = (AsyncResult) msg.obj;
circle.setFillColor(alphaColor(circle.getFillColor()));
circle.setStrokeColor(alphaColor(circle.getStrokeColor()));
result.setResult(null);
return true;
}
case MSG_SET_TOUCH_ENABLED: {
result = (AsyncResult) msg.obj;
clickable = TiConvert.toBoolean(result.getArg(), true);
result.setResult(null);
return true;
}
default: {
return super.handleMessage(msg);
}
}
}
public void processOptions()
{
options = new CircleOptions();
Activity currentActivity = TiApplication.getAppCurrentActivity();
if (hasProperty(MapModule.PROPERTY_CENTER)) {
options.center(TiMapUtils.parseLocation(getProperty(MapModule.PROPERTY_CENTER)));
}
if (hasProperty(MapModule.PROPERTY_RADIUS)) {
options.radius(TiConvert.toDouble(getProperty(MapModule.PROPERTY_RADIUS)));
}
if (hasProperty(MapModule.PROPERTY_STROKE_WIDTH)) {
options.strokeWidth(toPx(getProperty(MapModule.PROPERTY_STROKE_WIDTH)));
}
if (hasProperty(MapModule.PROPERTY_STROKE_COLOR)) {
options.strokeColor(
alphaColor(TiConvert.toColor((String) getProperty(MapModule.PROPERTY_STROKE_COLOR), currentActivity)));
}
if (hasProperty(MapModule.PROPERTY_FILL_COLOR)) {
options.fillColor(
alphaColor(TiConvert.toColor((String) getProperty(MapModule.PROPERTY_FILL_COLOR), currentActivity)));
}
if (hasProperty(MapModule.PROPERTY_ZINDEX)) {
options.zIndex(TiConvert.toFloat(getProperty(MapModule.PROPERTY_ZINDEX)));
}
if (hasProperty(TiC.PROPERTY_VISIBLE)) {
options.visible(TiConvert.toBoolean(getProperty(TiC.PROPERTY_VISIBLE)));
}
if (hasProperty(TiC.PROPERTY_TOUCH_ENABLED)) {
clickable = TiConvert.toBoolean(getProperty(TiC.PROPERTY_TOUCH_ENABLED));
}
}
@Override
public void onPropertyChanged(String name, Object value)
{
super.onPropertyChanged(name, value);
Activity currentActivity = TiApplication.getAppCurrentActivity();
if (circle == null) {
return;
}
else if (name.equals(MapModule.PROPERTY_CENTER)) {
TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_SET_CENTER), value);
}
else if (name.equals(MapModule.PROPERTY_RADIUS)) {
TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_SET_RADIUS),
TiConvert.toDouble(value));
}
else if (name.equals(MapModule.PROPERTY_STROKE_WIDTH)) {
TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_SET_STROKE_WIDTH), toPx(value));
}
else if (name.equals(MapModule.PROPERTY_STROKE_COLOR)) {
TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_SET_STROKE_COLOR),
TiConvert.toColor((String) value, currentActivity));
}
else if (name.equals(MapModule.PROPERTY_FILL_COLOR)) {
TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_SET_FILL_COLOR),
TiConvert.toColor((String) value, currentActivity));
}
else if (name.equals(MapModule.PROPERTY_ZINDEX)) {
TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_SET_ZINDEX),
TiConvert.toFloat(value));
}
else if (name.equals(TiC.PROPERTY_VISIBLE)) {
TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_SET_VISIBLE),
TiConvert.toBoolean(value));
}
else if (name.equals(TiC.PROPERTY_OPACITY)) {
TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_SET_OPACITY));
}
else if (name.equals(TiC.PROPERTY_TOUCH_ENABLED)) {
TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_SET_TOUCH_ENABLED),
TiConvert.toBoolean(value));
}
}
public CircleOptions getOptions()
{
return options;
}
public void setCircle(Circle c)
{
circle = c;
}
public Circle getCircle()
{
return circle;
}
public boolean getClickable()
{
return clickable;
}
public String getApiName()
{
return "Ti.Map.Circle";
}
}