Skip to content

Commit

Permalink
Merge pull request #2853 from krowley/timob-10584
Browse files Browse the repository at this point in the history
[TIMOB-10584] Android: WebView click event is not being fired
  • Loading branch information
pingwang2011 committed Sep 1, 2012
2 parents 244d317 + f359952 commit f7c44d2
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,28 @@ public void destroy()
@Override
public boolean onTouchEvent(MotionEvent ev)
{

boolean handled = false;

// In Android WebView, all the click events are directly sent to WebKit. As a result, OnClickListener() is
// never called. Therefore, we have to manually call performClick() when a click event is detected.
//
// In native Android and in the Ti world, it's possible to to have a touchEvent click on a link in a webview and
// also to be detected as a click on the webview. So we cannot let handling of the event one way block
// the handling the other way -- it must be passed to both in all cases for everything to work correctly.
//
if (ev.getAction() == MotionEvent.ACTION_UP) {
Rect r = new Rect(0, 0, getWidth(), getHeight());
if (r.contains((int) ev.getX(), (int) ev.getY())) {
handled = proxy.fireEvent(TiC.EVENT_CLICK, dictFromEvent(ev));
}
}

if (handled) {
return true;
}

// If performClick() can not handle the event, we pass it to WebKit.
return super.onTouchEvent(ev);

// Don't return here -- must call super.onTouchEvent()

boolean superHandled = super.onTouchEvent(ev);

return (superHandled || handled);
}

@SuppressWarnings("deprecation")
Expand Down

0 comments on commit f7c44d2

Please sign in to comment.