Skip to content
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

Merged
merged 2 commits into from
Sep 4, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file modified android/dist/ti.map-android-2.1.2.zip
Binary file not shown.
1 change: 1 addition & 0 deletions android/documentation/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
v2.1.2 Clicking on an annotation should center it in map view [TIMOB-13778].
Fixed a bug where removing an annotation using its title crashed the app [TIMOB-14502].
Updated Google Play Services SDK.
Fixed a bug where add/remove annotations didn't modify map's 'annotations' property correctly [TIMOB-14761].

v2.1.1 Added isGooglePlayServicesAvailable [TIMOB-14075].
Added the userLocationButton property [TIMOB-13003].
Expand Down
9 changes: 0 additions & 9 deletions android/src/ti/map/TiUIMapView.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,6 @@ protected Fragment createFragment()
return SupportMapFragment.newInstance();
}

protected void processPreloadAnnotations()
{
ArrayList<AnnotationProxy> annotations = ((ViewProxy) proxy).getPreloadAnnotations();
for (int i = 0; i < annotations.size(); i++) {
addAnnotation(annotations.get(i));
}
}

protected void processPreloadRoutes()
{
ArrayList<RouteProxy> routes = ((ViewProxy) proxy).getPreloadRoutes();
Expand All @@ -76,7 +68,6 @@ protected void onViewCreated()
{
map = acquireMap();
processMapProperties(proxy.getProperties());
processPreloadAnnotations();
processPreloadRoutes();
map.setOnMarkerClickListener(this);
map.setOnMapClickListener(this);
Expand Down
167 changes: 108 additions & 59 deletions android/src/ti/map/ViewProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@


import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;

import org.appcelerator.kroll.annotations.Kroll;
Expand All @@ -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;
Expand Down Expand Up @@ -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>();
}

Expand All @@ -64,7 +64,6 @@ public TiUIView createView(Activity activity) {
}

public void clearPreloadObjects() {
preloadAnnotations.clear();
preloadRoutes.clear();
}

Expand Down Expand Up @@ -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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about peekView() == null?

Copy link
Contributor Author

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.

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);
}
}
}

Expand All @@ -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]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not set it to null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 {
Expand Down Expand Up @@ -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);
}
}

Expand Down