-
-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Timob 14761: Testing steps in JIRA #3
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
|
||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
|
||
import org.appcelerator.kroll.annotations.Kroll; | ||
|
@@ -17,6 +18,7 @@ | |
import org.appcelerator.titanium.TiApplication; | ||
import org.appcelerator.titanium.TiC; | ||
import org.appcelerator.titanium.proxy.TiViewProxy; | ||
import org.appcelerator.titanium.util.TiConvert; | ||
import org.appcelerator.titanium.view.TiUIView; | ||
|
||
import android.app.Activity; | ||
|
@@ -50,12 +52,10 @@ public class ViewProxy extends TiViewProxy | |
private static final int MSG_CHANGE_ZOOM = MSG_FIRST_ID + 509; | ||
private static final int MSG_SET_LOCATION = MSG_FIRST_ID + 510; | ||
|
||
private ArrayList<AnnotationProxy> preloadAnnotations; | ||
private ArrayList<RouteProxy> preloadRoutes; | ||
|
||
public ViewProxy() { | ||
super(); | ||
preloadAnnotations = new ArrayList<AnnotationProxy>(); | ||
preloadRoutes = new ArrayList<RouteProxy>(); | ||
} | ||
|
||
|
@@ -64,7 +64,6 @@ public TiUIView createView(Activity activity) { | |
} | ||
|
||
public void clearPreloadObjects() { | ||
preloadAnnotations.clear(); | ||
preloadRoutes.clear(); | ||
} | ||
|
||
|
@@ -152,49 +151,58 @@ public boolean handleMessage(Message msg) | |
} | ||
} | ||
} | ||
|
||
|
||
public ArrayList<AnnotationProxy> getPreloadAnnotations() { | ||
return preloadAnnotations; | ||
} | ||
|
||
@Kroll.method | ||
public void addAnnotation(AnnotationProxy annotation) { | ||
if (TiApplication.isUIThread()) { | ||
handleAddAnnotation(annotation); | ||
//Update the JS object | ||
Object annotations = getProperty(TiC.PROPERTY_ANNOTATIONS); | ||
if (annotations instanceof Object[]) { | ||
ArrayList<Object> annoList = new ArrayList<Object>(Arrays.asList((Object[])annotations)); | ||
annoList.add(annotation); | ||
setProperty(TiC.PROPERTY_ANNOTATIONS, annoList.toArray()); | ||
} else { | ||
TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_ADD_ANNOTATION), annotation); | ||
setProperty(TiC.PROPERTY_ANNOTATIONS, new Object[] {annotation}); | ||
} | ||
} | ||
|
||
private void handleAddAnnotation(AnnotationProxy annotation) { | ||
|
||
TiUIView view = peekView(); | ||
if (view instanceof TiUIMapView) { | ||
TiUIMapView mapView = (TiUIMapView) view; | ||
if (mapView.getMap() != null) { | ||
mapView.addAnnotation(annotation); | ||
|
||
if (TiApplication.isUIThread()) { | ||
handleAddAnnotation(annotation); | ||
} else { | ||
addPreloadAnnotation(annotation); | ||
TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_ADD_ANNOTATION), annotation); | ||
} | ||
} else { | ||
addPreloadAnnotation(annotation); | ||
} | ||
} | ||
|
||
private void addPreloadAnnotation(AnnotationProxy anno) { | ||
if (!preloadAnnotations.contains(anno)) { | ||
preloadAnnotations.add(anno); | ||
} | ||
private void handleAddAnnotation(AnnotationProxy annotation) { | ||
TiUIMapView mapView = (TiUIMapView) peekView(); | ||
if (mapView.getMap() != null) { | ||
mapView.addAnnotation(annotation); | ||
} | ||
} | ||
|
||
@Kroll.method | ||
public void addAnnotations(AnnotationProxy[] annotations) { | ||
if (TiApplication.isUIThread()) { | ||
handleAddAnnotations(annotations); | ||
public void addAnnotations(AnnotationProxy[] annos) { | ||
//Update the JS object | ||
Object annotations = getProperty(TiC.PROPERTY_ANNOTATIONS); | ||
if (annotations instanceof Object[]) { | ||
ArrayList<Object> annoList = new ArrayList<Object>(Arrays.asList((Object[])annotations)); | ||
for (int i = 0; i < annos.length; i++) { | ||
AnnotationProxy annotation = annos[i]; | ||
annoList.add(annotation); | ||
} | ||
setProperty(TiC.PROPERTY_ANNOTATIONS, annoList.toArray()); | ||
} else { | ||
TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_ADD_ANNOTATIONS), annotations); | ||
setProperty(TiC.PROPERTY_ANNOTATIONS, annos); | ||
} | ||
|
||
TiUIView view = peekView(); | ||
if (view instanceof TiUIMapView) { | ||
if (TiApplication.isUIThread()) { | ||
handleAddAnnotations(annos); | ||
} else { | ||
TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_ADD_ANNOTATIONS), annos); | ||
} | ||
} | ||
} | ||
|
||
|
@@ -209,6 +217,9 @@ private void handleAddAnnotations(Object[] annotations) { | |
|
||
@Kroll.method | ||
public void removeAllAnnotations() { | ||
//Update the JS object | ||
setProperty(TiC.PROPERTY_ANNOTATIONS, new Object[0]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not set it to null? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It makes sense to leave it as empty array. I.e: when you remove all elements of an Java array, the array becomes empty, not null. The JS splice method also returns an empty array when you remove all elements. |
||
|
||
if (TiApplication.isUIThread()) { | ||
handleRemoveAllAnnotations(); | ||
} else { | ||
|
@@ -247,53 +258,91 @@ public boolean isAnnotationValid(Object annotation) { | |
|
||
return true; | ||
} | ||
|
||
private void removeAnnotationByTitle(ArrayList<Object> annoList, String annoTitle) { | ||
for (int i = 0; i < annoList.size(); i++) { | ||
Object obj = annoList.get(i); | ||
if (obj instanceof AnnotationProxy) { | ||
AnnotationProxy annoProxy = (AnnotationProxy) obj; | ||
String title = TiConvert.toString(annoProxy.getProperty(TiC.PROPERTY_TITLE)); | ||
if (title != null && title.equals(annoTitle)) { | ||
annoList.remove(annoProxy); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
private void removeAnnoFromList(ArrayList<Object> annoList, Object annotation) { | ||
if (annotation instanceof AnnotationProxy) { | ||
annoList.remove(annotation); | ||
} else if (annotation instanceof String) { | ||
removeAnnotationByTitle(annoList, (String)annotation); | ||
} | ||
} | ||
|
||
@Kroll.method | ||
public void removeAnnotation(Object annotation) { | ||
if (!isAnnotationValid(annotation)) { | ||
if (!(annotation instanceof AnnotationProxy || annotation instanceof String)) { | ||
Log.e(TAG, "Unsupported argument type for removeAnnotation"); | ||
return; | ||
} | ||
|
||
if (TiApplication.isUIThread()) { | ||
handleRemoveAnnotation(annotation); | ||
} else { | ||
TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_REMOVE_ANNOTATION), annotation); | ||
//Update the JS object | ||
Object annotations = getProperty(TiC.PROPERTY_ANNOTATIONS); | ||
if (annotations instanceof Object[]) { | ||
ArrayList<Object> annoList = new ArrayList<Object>(Arrays.asList((Object[])annotations)); | ||
removeAnnoFromList(annoList, annotation); | ||
setProperty(TiC.PROPERTY_ANNOTATIONS, annoList.toArray()); | ||
} | ||
|
||
|
||
TiUIView view = peekView(); | ||
if (view instanceof TiUIMapView) { | ||
if (TiApplication.isUIThread()) { | ||
handleRemoveAnnotation(annotation); | ||
} else { | ||
TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_REMOVE_ANNOTATION), annotation); | ||
} | ||
} | ||
} | ||
|
||
@Kroll.method | ||
public void removeAnnotations(Object annotations) { | ||
if (TiApplication.isUIThread()) { | ||
handleRemoveAnnotations((Object[])annotations); | ||
} else { | ||
TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_REMOVE_ANNOTATIONS), annotations); | ||
public void removeAnnotations(Object annos) { | ||
//Update the JS object | ||
Object annotations = getProperty(TiC.PROPERTY_ANNOTATIONS); | ||
if (annotations instanceof Object[] && annos instanceof Object[]) { | ||
ArrayList<Object> annoList = new ArrayList<Object>(Arrays.asList((Object[])annotations)); | ||
Object[] annoArray = (Object[]) annos; | ||
for (int i = 0; i < annoArray.length; i++) { | ||
Object annotation = annoArray[i]; | ||
removeAnnoFromList(annoList, annotation); | ||
} | ||
setProperty(TiC.PROPERTY_ANNOTATIONS, annoList.toArray()); | ||
} | ||
|
||
TiUIView view = peekView(); | ||
if (view instanceof TiUIMapView) { | ||
if (TiApplication.isUIThread()) { | ||
handleRemoveAnnotations((Object[])annos); | ||
} else { | ||
TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_REMOVE_ANNOTATIONS), annos); | ||
} | ||
} | ||
} | ||
|
||
public void handleRemoveAnnotations(Object[] annotations) { | ||
for (int i = 0; i < annotations.length; i++) { | ||
removeAnnotation(annotations[i]); | ||
} | ||
} | ||
|
||
public void handleRemoveAnnotation(Object annotation) { | ||
TiUIView view = peekView(); | ||
if (view instanceof TiUIMapView) { | ||
TiUIMapView mapView = (TiUIMapView) view; | ||
if (mapView.getMap() != null) { | ||
mapView.removeAnnotation(annotation); | ||
} else { | ||
removePreloadAnnotation(annotation); | ||
Object annotation = annotations[i]; | ||
if (annotation instanceof AnnotationProxy || annotation instanceof String) { | ||
handleRemoveAnnotation(annotations[i]); | ||
} | ||
|
||
} else { | ||
removePreloadAnnotation(annotation); | ||
} | ||
} | ||
|
||
public void removePreloadAnnotation(Object annotation) { | ||
if (annotation instanceof AnnotationProxy && preloadAnnotations.contains(annotation)) { | ||
preloadAnnotations.remove(annotation); | ||
public void handleRemoveAnnotation(Object annotation) { | ||
TiUIMapView mapView = (TiUIMapView) peekView(); | ||
if (mapView.getMap() != null) { | ||
mapView.removeAnnotation(annotation); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about peekView() == null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check for that is in addAnnotation(). Basically if it gets to this method, peekView() should never be null.