Skip to content

Commit

Permalink
Merge pull request #3192 from pingwang2011/timob-11439-3_0_X
Browse files Browse the repository at this point in the history
Timob 11439 3 0 x: Android: Invalid events triggered
  • Loading branch information
hieupham007 committed Oct 12, 2012
2 parents 0f4a27e + df1a744 commit 9b519eb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 32 deletions.
40 changes: 35 additions & 5 deletions android/titanium/src/java/org/appcelerator/kroll/KrollProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* <a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.createView-method.html">Titanium.UI.createView </a>,
* the view object is a proxy itself.
*/
@Kroll.proxy(name = "KrollProxy", propertyAccessors = { KrollProxy.PROPERTY_HAS_JAVA_LISTENER, TiC.PROPERTY_BUBBLE_PARENT })
@Kroll.proxy(name = "KrollProxy", propertyAccessors = { KrollProxy.PROPERTY_HAS_JAVA_LISTENER })
public class KrollProxy implements Handler.Callback, KrollProxySupport
{
private static final String TAG = "KrollProxy";
Expand Down Expand Up @@ -79,6 +79,7 @@ public class KrollProxy implements Handler.Callback, KrollProxySupport
protected Handler runtimeHandler = null;

private KrollDict langConversionTable = null;
private boolean bubbleParent = true;

public static final String PROXY_ID_PREFIX = "proxy$";

Expand Down Expand Up @@ -108,7 +109,6 @@ public KrollProxy(String baseCreationUrl)
this.listenerIdGenerator = new AtomicInteger(0);
this.eventListeners = Collections.synchronizedMap(new HashMap<String, HashMap<Integer, KrollEventCallback>>());
this.langConversionTable = getLangConversionTable();
defaultValues.put(TiC.PROPERTY_BUBBLE_PARENT, true);
}

private void setupProxy(KrollObject object, Object[] creationArguments, TiUrl creationUrl)
Expand Down Expand Up @@ -604,6 +604,18 @@ protected void doSetProperty(String name, Object value)
getKrollObject().setProperty(name, value);
}

@Kroll.getProperty @Kroll.method
public boolean getBubbleParent()
{
return bubbleParent;
}

@Kroll.setProperty @Kroll.method
public void setBubbleParent(Object value)
{
bubbleParent = TiConvert.toBoolean(value);
}

/**
* Fires an event asynchronously via KrollRuntime thread, which can be intercepted on JS side.
* @param event the event to be fired.
Expand All @@ -617,7 +629,7 @@ public boolean fireEvent(String event, Object data)
message.getData().putString(PROPERTY_NAME, event);
message.sendToTarget();

return hasListeners(event);
return hierarchyHasListener(event);
}

/**
Expand All @@ -630,8 +642,7 @@ public boolean fireEvent(String event, Object data)
@Kroll.method(name = "_fireEventToParent")
public boolean fireEventToParent(String eventName, Object data)
{
Object bubbleParent = getProperty(TiC.PROPERTY_BUBBLE_PARENT);
if (bubbleParent != null && TiConvert.toBoolean(bubbleParent)) {
if (bubbleParent) {
KrollProxy parentProxy = getParentForBubbling();
if (parentProxy != null) {
return parentProxy.fireEvent(eventName, data);
Expand Down Expand Up @@ -713,6 +724,25 @@ public boolean hasListeners(String event)
return getKrollObject().hasListeners(event);
}

/**
* Returns true if any view in the hierarchy has the event listener.
*/
public boolean hierarchyHasListener(String event)
{
boolean hasListener = hasListeners(event);

// Checks whether the parent has the listener or not
if (!hasListener) {
KrollProxy parentProxy = getParentForBubbling();
if (parentProxy != null) {
boolean parentHasListener = parentProxy.hierarchyHasListener(event);
hasListener = hasListener || parentHasListener;
}
}

return hasListener;
}

public boolean shouldFireChange(Object oldValue, Object newValue)
{
if (!(oldValue == null && newValue == null)) {
Expand Down
5 changes: 0 additions & 5 deletions android/titanium/src/java/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -711,11 +711,6 @@ public class TiC
*/
public static final String PROPERTY_BUBBLES = "bubbles";

/**
* @module.api
*/
public static final String PROPERTY_BUBBLE_PARENT = "bubbleParent";

/**
* @module.api
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -867,28 +867,6 @@ public void eventListenerRemoved(String eventName, int count, KrollProxy proxy)
}
}

/**
* Return true if any view in the hierarchy has the event listener.
*/
public boolean hierarchyHasListener(String eventName)
{
boolean hasListener = hasListeners(eventName);

// Check whether the parent has the listener or not
if (!hasListener) {
TiViewProxy parent = getParent();
if (parent != null) {
boolean parentHasListener = parent.hierarchyHasListener(eventName);
hasListener = hasListener || parentHasListener;
if (hasListener) {
return hasListener;
}
}
}

return hasListener;
}

public void setClickable(boolean clickable)
{
TiUIView v = peekView();
Expand Down

0 comments on commit 9b519eb

Please sign in to comment.