Note that there are some explanatory texts on larger screens.

plurals
  1. POConverting View's touch location to WebView's HTML screen location
    primarykey
    data
    text
    <p>I have a <code>WebView</code> that is displaying a local HTML page within the assets folder. The <code>WebView</code> is part of larger layout in an <code>Activity</code>. I'm trying to allow users to drag text from an <code>EditText</code> widget to an Input Element within the <code>WebView</code>. Everything works good except for converting the screen coordinates received by the drag listener to the screen coordinates used by <code>document.elementFromPoint</code>. They don't match up. It'll keep dropping text into input boxes which are further down then the users finger. Any help would be appreciated. Warning: my javascript knowledge is pretty pathetic.</p> <p>Basic flow:</p> <ol> <li>WebView's onDrag event catches the ACTION_DROP event.</li> <li>The event's x, y location is passed to a Javascript function</li> <li>The Javascript function finds element based on points and updates the value</li> </ol> <p>In my Activity:</p> <pre class="lang-java prettyprint-override"><code>private class OnWebViewDragListener implements OnDragListener { public boolean onDrag(View v, DragEvent event) { switch (event.getAction()) { case DragEvent.ACTION_DROP: String dropText = event.getClipData().getItemAt(0).getText().toString(); mJavaScript._dropText(mWebView, dropText, event.getX(), event.getY()); return true; default: break; } return false; } } </code></pre> <p>Javascript wrapper:</p> <pre class="lang-java prettyprint-override"><code>public void _dropText(WebView wv, String text, float x, float y) { wv.loadUrl("javascript:dropText('" + text + "', " + x + ", " + y + ")"); } </code></pre> <p>Javascript function:</p> <pre class="lang-js prettyprint-override"><code>&lt;script type="text/javascript"&gt; function dropText(text, x, y) { var elem = document.elementFromPoint(x, y); if (elem.tagName == "INPUT") { elem.value = text; } } &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload