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-10296]Use proxy if available in (de)select/remove #2683

Merged
merged 3 commits into from
Aug 7, 2012
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
44 changes: 25 additions & 19 deletions android/modules/map/src/java/ti/modules/titanium/map/TiMapView.java
Original file line number Diff line number Diff line change
Expand Up @@ -348,15 +348,17 @@ protected boolean onTap(int index)

public static class SelectedAnnotation
{
AnnotationProxy selectedAnnotation;
String title;
boolean animate;
boolean center;

public SelectedAnnotation(String title, boolean animate, boolean center)
public SelectedAnnotation(String title, AnnotationProxy selectedAnnotation, boolean animate, boolean center)
{
this.title = title;
this.animate = animate;
this.center = center;
this.selectedAnnotation = selectedAnnotation;
}
}

Expand Down Expand Up @@ -516,12 +518,14 @@ public boolean handleMessage(Message msg)
return true;

case MSG_SELECT_ANNOTATION :
Bundle args = msg.getData();
boolean select = args.getBoolean("select", false);
KrollDict args = (KrollDict) msg.obj;

boolean select = args.optBoolean("select", false);
String title = args.getString("title");
boolean animate = args.getBoolean("animate", false);
boolean center = args.getBoolean("center", true); // keep existing default behavior
doSelectAnnotation(select, title, animate, center);
boolean animate = args.optBoolean("animate", false);
boolean center = args.optBoolean("center", true); // keep existing default behavior
AnnotationProxy annotation = (AnnotationProxy)args.get("annotation");
doSelectAnnotation(select, title, annotation, animate, center);
return true;

case MSG_UPDATE_ANNOTATIONS :
Expand Down Expand Up @@ -836,7 +840,7 @@ public void doSetAnnotations(ArrayList<AnnotationProxy> annotations)
for(int i = 0; i < numSelectedAnnotations; i++) {
SelectedAnnotation annotation = selectedAnnotations.get(i);
Log.d(TAG, "Executing internal call to selectAnnotation:" + annotation.title, Log.DEBUG_MODE);
selectAnnotation(true, annotation.title, annotation.animate, annotation.center);
selectAnnotation(true, annotation.title, annotation.selectedAnnotation, annotation.animate, annotation.center);
}
}

Expand All @@ -845,27 +849,29 @@ public void doSetAnnotations(ArrayList<AnnotationProxy> annotations)
}
}

public void selectAnnotation(boolean select, String title, boolean animate, boolean center)
public void selectAnnotation(boolean select, String title, AnnotationProxy selectedAnnotation, boolean animate, boolean center)
{
if (title != null) {
Log.e(TAG, "Calling obtainMessage", Log.DEBUG_MODE);

Bundle args = new Bundle();
args.putBoolean("select", select);
args.putString("title", title);
args.putBoolean("animate", animate);
args.putBoolean("center", center);

Log.e(TAG, "calling obtainMessage", Log.DEBUG_MODE);

KrollDict args = new KrollDict();
args.put("select", new Boolean(select));
args.put("title", title);
args.put("animate", new Boolean(animate));
args.put("center", new Boolean(center));
if (selectedAnnotation != null) {
args.put("annotation", selectedAnnotation);
}
Message message = handler.obtainMessage(MSG_SELECT_ANNOTATION);
message.setData(args);
message.obj = args;
message.sendToTarget();
}
}

public void doSelectAnnotation(boolean select, String title, boolean animate, boolean center)
public void doSelectAnnotation(boolean select, String title, AnnotationProxy annotation, boolean animate, boolean center)
{
if (title != null && view != null && annotations != null && overlay != null) {
int index = ((ViewProxy)proxy).findAnnotation(title);
int index = ((ViewProxy)proxy).findAnnotation(title, annotation);
if (index > -1) {
if (overlay != null) {
synchronized(overlay) {
Expand Down
44 changes: 30 additions & 14 deletions android/modules/map/src/java/ti/modules/titanium/map/ViewProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.kroll.common.Log;
import org.appcelerator.kroll.common.TiConfig;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiBaseActivity;
import org.appcelerator.titanium.TiC;
Expand Down Expand Up @@ -286,12 +287,22 @@ public void addAnnotations(Object annotations)
}
}

protected int findAnnotation(String title)
protected int findAnnotation(String title, AnnotationProxy annotation)
{
int existsIndex = -1;
// Check for existence
int len = annotations.size();
for (int i = 0; i < len; i++) {

if (annotation != null) {
for (int i = 0; i < len && existsIndex == -1; i++) {
if (annotation == annotations.get(i)) {
existsIndex = i;
break;
}
}
}

for (int i = 0; i < len && existsIndex == -1; i++) {
AnnotationProxy a = annotations.get(i);
String t = (String) a.getProperty(TiC.PROPERTY_TITLE);

Expand All @@ -310,16 +321,17 @@ protected int findAnnotation(String title)
public void removeAnnotation(Object arg)
{
String title = null;

AnnotationProxy annotation = null;
if (arg != null) {
if (arg instanceof AnnotationProxy) {
title = TiConvert.toString(((AnnotationProxy) arg).getProperty("title"));
annotation = (AnnotationProxy)arg;
title = TiConvert.toString(annotation.getProperty(TiC.PROPERTY_TITLE));
} else {
title = TiConvert.toString(arg);
}

if (title != null) {
int existsIndex = findAnnotation(title);
int existsIndex = findAnnotation(title, annotation);
if (existsIndex > -1) {
annotations.get(existsIndex).setViewProxy(null);
annotations.remove(existsIndex);
Expand All @@ -335,6 +347,7 @@ public void removeAnnotation(Object arg)
@Kroll.method
public void selectAnnotation(Object[] args)
{
AnnotationProxy selAnnotation = null;
String title = null;
boolean animate = false;
boolean center = true; // keep existing default behavior
Expand All @@ -345,7 +358,8 @@ public void selectAnnotation(Object[] args)

Object selectedAnnotation = params.get(TiC.PROPERTY_ANNOTATION);
if (selectedAnnotation instanceof AnnotationProxy) {
title = TiConvert.toString(((AnnotationProxy) selectedAnnotation).getProperty(TiC.PROPERTY_TITLE));
selAnnotation = (AnnotationProxy)selectedAnnotation;
title = TiConvert.toString(selAnnotation.getProperty(TiC.PROPERTY_TITLE));
} else {
title = TiConvert.toString(params, TiC.PROPERTY_TITLE);
}
Expand All @@ -362,7 +376,8 @@ public void selectAnnotation(Object[] args)

} else {
if (args[0] instanceof AnnotationProxy) {
title = TiConvert.toString(((AnnotationProxy) args[0]).getProperty(TiC.PROPERTY_TITLE));
selAnnotation = (AnnotationProxy) args[0];
title = TiConvert.toString(selAnnotation.getProperty(TiC.PROPERTY_TITLE));

} else if (args[0] instanceof String) {
title = TiConvert.toString(args[0]);
Expand All @@ -376,11 +391,11 @@ public void selectAnnotation(Object[] args)

if (title != null) {
if (mapView == null) {
Log.e(TAG, "Calling selectedAnnotations.add", Log.DEBUG_MODE);
selectedAnnotations.add(new TiMapView.SelectedAnnotation(title, animate, center));
Log.i(TAG, "calling selectedAnnotations.add", Log.DEBUG_MODE);
selectedAnnotations.add(new TiMapView.SelectedAnnotation(title, selAnnotation, animate, center));
} else {
Log.e(TAG, "Calling selectedAnnotations.add2", Log.DEBUG_MODE);
mapView.selectAnnotation(true, title, animate, center);
Log.i(TAG, "calling selectedAnnotations.add2", Log.DEBUG_MODE);
mapView.selectAnnotation(true, title, selAnnotation, animate, center);
}
}
}
Expand All @@ -389,10 +404,11 @@ public void selectAnnotation(Object[] args)
public void deselectAnnotation(Object[] args)
{
String title = null;

AnnotationProxy selectedAnnotation = null;
if (args.length > 0) {
if (args[0] instanceof AnnotationProxy) {
title = TiConvert.toString(((AnnotationProxy) args[0]).getProperty("title"));
selectedAnnotation = (AnnotationProxy) args[0];
title = TiConvert.toString(selectedAnnotation.getProperty("title"));
} else if (args[0] instanceof String) {
title = TiConvert.toString(args[0]);
}
Expand All @@ -412,7 +428,7 @@ public void deselectAnnotation(Object[] args)
}
}
} else {
mapView.selectAnnotation(false, title, animate, false);
mapView.selectAnnotation(false, title, selectedAnnotation, animate, false);
}
}
}
Expand Down