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-4260 add support for leftView and rightView for map annotation #105

Merged
merged 2 commits into from
Jun 6, 2011
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions android/modules/map/src/ti/modules/titanium/map/TiMapView.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2010 by Appcelerator, Inc. All Rights Reserved.
* Copyright (c) 2009-2011 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.
*/
Expand All @@ -20,7 +20,6 @@
import org.appcelerator.titanium.io.TiBaseFile;
import org.appcelerator.titanium.io.TiFileFactory;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.AsyncResult;
import org.appcelerator.titanium.util.Log;
import org.appcelerator.titanium.util.TiConfig;
import org.appcelerator.titanium.util.TiConvert;
Expand Down Expand Up @@ -225,6 +224,24 @@ protected TiOverlayItem createItem(int i) {
if (a.containsKey(TiC.PROPERTY_RIGHT_BUTTON)) {
item.setRightButton(proxy.getTiContext().resolveUrl(null, TiConvert.toString(a, TiC.PROPERTY_RIGHT_BUTTON)));
}
if (a.containsKey(TiC.PROPERTY_LEFT_VIEW)) {
Object leftView = a.get(TiC.PROPERTY_LEFT_VIEW);
if (leftView instanceof TiViewProxy) {
item.setLeftView((TiViewProxy)leftView);

} else {
Log.e(LCAT, "invalid type for leftView");
}
}
if (a.containsKey(TiC.PROPERTY_RIGHT_VIEW)) {
Object rightView = a.get(TiC.PROPERTY_RIGHT_VIEW);
if (rightView instanceof TiViewProxy) {
item.setRightView((TiViewProxy)rightView);

} else {
Log.e(LCAT, "invalid type for rightView");
}
}
} else {
Log.w(LCAT, "Skipping annotation: No coordinates #" + i);
}
Expand Down Expand Up @@ -337,7 +354,7 @@ public void onStop(Activity activity) {

setNativeView(view);

this.regionFit =true;
this.regionFit = true;
this.animate = false;

final TiViewProxy fproxy = proxy;
Expand Down Expand Up @@ -418,11 +435,9 @@ private void hideAnnotation() {
}

private void showAnnotation(int index, TiOverlayItem item) {
Log.e(LCAT, "B:" + view + ":" + itemView + ":" + item);
if (view != null && itemView != null && item != null) {
Log.e(LCAT, "B2");
itemView.setItem(index, item);
//Make sure the atonnation is always on top of the marker
//Make sure the annotation is always on top of the marker
int y = -1*item.getMarker(TiOverlayItem.ITEM_STATE_FOCUSED_MASK).getIntrinsicHeight();
MapView.LayoutParams params = new MapView.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT, item.getPoint(), 0, y, MapView.LayoutParams.BOTTOM_CENTER);
Expand Down Expand Up @@ -603,10 +618,8 @@ public void selectAnnotation(boolean select, String title, boolean animate)

public void doSelectAnnotation(boolean select, String title, boolean animate)
{
Log.e(LCAT, "A:" + title + ":" + view + ":" + annotations + ":" + overlay);
if (title != null && view != null && annotations != null && overlay != null) {
int index = ((ViewProxy)proxy).findAnnotation(title);
Log.e(LCAT, "A2:" + index);
if (index > -1) {
if (overlay != null) {
synchronized(overlay) {
Expand All @@ -626,7 +639,6 @@ public void doSelectAnnotation(boolean select, String title, boolean animate)
} else {
controller.setCenter(item.getPoint());
}
Log.e(LCAT, "A3:" + index + ":" + item);
showAnnotation(index, item);
} else {
hideAnnotation();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2010 by Appcelerator, Inc. All Rights Reserved.
* Copyright (c) 2009-2011 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.modules.titanium.map;

import org.appcelerator.titanium.proxy.TiViewProxy;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.OverlayItem;

public class TiOverlayItem extends OverlayItem
{
private String leftButtonPath;
private String rightButtonPath;
private TiViewProxy leftView;
private TiViewProxy rightView;
private AnnotationProxy proxy;

public TiOverlayItem(GeoPoint location, String title, String snippet, AnnotationProxy proxy) {
Expand All @@ -36,6 +40,24 @@ public String getRightButton() {
return rightButtonPath;
}

public void setLeftView(TiViewProxy leftView) {
this.leftView = leftView;
}

public TiViewProxy getLeftView()
{
return leftView;
}

public void setRightView(TiViewProxy rightView) {
this.rightView = rightView;
}

public TiViewProxy getRightView()
{
return rightView;
}

public AnnotationProxy getProxy() {
return proxy;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2010 by Appcelerator, Inc. All Rights Reserved.
* Copyright (c) 2009-2011 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.
*/
Expand All @@ -9,9 +9,11 @@
import java.lang.ref.WeakReference;

import org.appcelerator.titanium.TiContext;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.Log;
import org.appcelerator.titanium.util.TiFileHelper;
import org.appcelerator.titanium.util.TiUIHelper;
import org.appcelerator.titanium.view.TiCompositeLayout;

import android.content.Context;
import android.graphics.Color;
Expand All @@ -35,8 +37,8 @@ public interface OnOverlayClicked {
}

private RelativeLayout layout;
private ImageView leftImage;
private ImageView rightImage;
private TiCompositeLayout leftPane;
private TiCompositeLayout rightPane;
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be more efficient to use a generic "View" here, and assign the Image / custom View instead of having a wrapper layout?

private TextView title;
private TextView snippet;
private int lastIndex;
Expand All @@ -62,16 +64,16 @@ public TiOverlayItemView(Context context, TiContext tiContext)

RelativeLayout.LayoutParams params = null;

leftImage = new ImageView(context);
leftImage.setId(100);
leftImage.setTag("leftButton");
leftPane = new TiCompositeLayout(tiContext.getActivity());
leftPane.setId(100);
leftPane.setTag("leftPane");
params = createBaseParams();
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
if (Integer.parseInt(Build.VERSION.SDK) > 3) {
params.addRule(RelativeLayout.CENTER_VERTICAL);
}
params.setMargins(0, 0, 5, 0);
layout.addView(leftImage, params);
layout.addView(leftPane, params);

RelativeLayout textLayout = new RelativeLayout(getContext());
textLayout.setGravity(Gravity.NO_GRAVITY);
Expand Down Expand Up @@ -111,22 +113,22 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
params.addRule(RelativeLayout.ALIGN_TOP);
layout.addView(textLayout, params);

rightImage = new ImageView(context);
rightImage.setId(103);
rightImage.setTag("rightButton");
rightPane = new TiCompositeLayout(tiContext.getActivity());
rightPane.setId(103);
rightPane.setTag("rightPane");
params = createBaseParams();
if (Integer.parseInt(Build.VERSION.SDK) > 3) {
params.addRule(RelativeLayout.CENTER_VERTICAL);
}
params.addRule(RelativeLayout.RIGHT_OF, 101);
params.setMargins(5, 0, 0, 0);
layout.addView(rightImage, params);
layout.addView(rightPane, params);

FrameLayout.LayoutParams fparams = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
fparams.gravity = Gravity.NO_GRAVITY;
addView(layout, fparams);

hitTestList = new View[] { leftImage, title, snippet, rightImage };
hitTestList = new View[] { leftPane, title, snippet, rightPane };
}

private RelativeLayout.LayoutParams createBaseParams() {
Expand All @@ -139,37 +141,63 @@ public void setItem(int index, TiOverlayItem item)
Drawable d = null;

lastIndex = index;

if(item.getLeftButton() != null) {
try {
d = tfh.loadDrawable(weakTiContext.get(), item.getLeftButton(), false);
leftImage.setImageDrawable(d);
leftImage.setVisibility(VISIBLE);
} catch (Exception e) {
leftImage.setVisibility(GONE);
Log.e(LCAT, "Error loading left button - " + item.getLeftButton() + ": " + e.getMessage());

leftPane.removeAllViews();
rightPane.removeAllViews();

String leftButton = item.getLeftButton();
TiViewProxy leftView = item.getLeftView();
if((leftButton != null) || (leftView != null)) {
if (leftButton != null) {
try {
ImageView leftImage = new ImageView(getContext());
d = tfh.loadDrawable(weakTiContext.get(), leftButton, false);
leftImage.setImageDrawable(d);
leftPane.addView(leftImage);

} catch (Exception e) {
Log.e(LCAT, "Error loading left button - " + leftButton + ": " + e.getMessage());

}
} else if (leftView != null) {
leftPane.addView(leftView.getView(leftView.getTiContext().getActivity()).getNativeView());
}
leftPane.setVisibility(VISIBLE);

} else {
leftImage.setVisibility(GONE);
leftPane.setVisibility(GONE);
}
if(item.getRightButton() != null) {
try {
d = tfh.loadDrawable(weakTiContext.get(), item.getRightButton(), false);
rightImage.setImageDrawable(d);
rightImage.setVisibility(VISIBLE);
} catch (Exception e) {
rightImage.setVisibility(GONE);
Log.e(LCAT, "Error loading right button - " + item.getRightButton() + ": " + e.getMessage());

String rightButton = item.getRightButton();
TiViewProxy rightView = item.getRightView();
if((rightButton != null) || (rightView != null)) {
if (rightButton != null) {
try {
ImageView rightImage = new ImageView(getContext());
d = tfh.loadDrawable(weakTiContext.get(), rightButton, false);
rightImage.setImageDrawable(d);
rightPane.addView(rightImage);

} catch (Exception e) {
Log.e(LCAT, "Error loading right button - " + rightButton + ": " + e.getMessage());

}
} else if (rightView != null) {
rightPane.addView(rightView.peekView().getNativeView());
}
rightPane.setVisibility(VISIBLE);

} else {
rightImage.setVisibility(GONE);
rightPane.setVisibility(GONE);
}

if(item.getTitle() != null) {
title.setVisibility(VISIBLE);
title.setText(item.getTitle());
} else {
title.setVisibility(GONE);
}

if(item.getSnippet() != null) {
snippet.setVisibility(VISIBLE);
snippet.setText(item.getSnippet());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2010 by Appcelerator, Inc. All Rights Reserved.
* Copyright (c) 2009-2011 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.
*/
Expand All @@ -15,15 +15,13 @@
import org.appcelerator.titanium.TiContext;
import org.appcelerator.titanium.TiContext.OnLifecycleEvent;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.AsyncResult;
import org.appcelerator.titanium.util.Log;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.view.TiUIView;

import android.app.Activity;
import android.app.LocalActivityManager;
import android.content.Intent;
import android.os.Message;
import android.view.Window;

@Kroll.proxy(creatableInModule=MapModule.class)
Expand Down
4 changes: 3 additions & 1 deletion android/titanium/src/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2010 by Appcelerator, Inc. All Rights Reserved.
* Copyright (c) 2009-2011 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.
*/
Expand Down Expand Up @@ -194,6 +194,7 @@ public class TiC
public static final String PROPERTY_LEFT = "left";
public static final String PROPERTY_LEFT_BUTTON = "leftButton";
public static final String PROPERTY_LEFT_IMAGE = "leftImage";
public static final String PROPERTY_LEFT_VIEW = "leftView";
public static final String PROPERTY_LENGTH = "length";
public static final String PROPERTY_LEVEL = "level";
public static final String PROPERTY_LOCATION = "location";
Expand Down Expand Up @@ -239,6 +240,7 @@ public class TiC
public static final String PROPERTY_RIGHT = "right";
public static final String PROPERTY_RIGHT_BUTTON = "rightButton";
public static final String PROPERTY_RIGHT_IMAGE = "rightImage";
public static final String PROPERTY_RIGHT_VIEW = "rightView";
public static final String PROPERTY_ROTATE = "rotate";
public static final String PROPERTY_ROW_DATA = "rowData";
public static final String PROPERTY_ROW_HEIGHT = "rowHeight";
Expand Down