Last modified: 2012-02-24 02:52:37 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T33484, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 31484 - Android app doesn't allow text selection for cut-n-paste
Android app doesn't allow text selection for cut-n-paste
Status: RESOLVED FIXED
Product: Wikipedia App
Classification: Unclassified
Generic (Other open bugs)
1.0.0 (Android)
All All
: Low normal
: ---
Assigned To: Anis Kadri
:
Depends on:
Blocks: 31447
  Show dependency treegraph
 
Reported: 2011-10-07 02:49 UTC by Brion Vibber
Modified: 2012-02-24 02:52 UTC (History)
7 users (show)

See Also:
Web browser: ---
Mobile Platform: Android
Assignee Huggle Beta Tester: ---


Attachments

Description Brion Vibber 2011-10-07 02:49:30 UTC
Cut-n-paste from articles seems like something we'd want to support. :)


Nexus 1, Android 2.3.6
Comment 1 herman wong 2011-10-14 21:29:08 UTC
We need to access the following native API: http://developer.android.com/reference/android/webkit/WebView.html#emulateShiftHeld()

Would suggest writing a PhoneGap plugin to allow us to access this API.
Comment 2 Tomasz Finc 2011-10-14 21:42:00 UTC
Is there anything else that could do that? That function is marked as 'Do not rely on this functionality; it will be deprecated in the future.'
Comment 3 herman wong 2011-10-16 14:14:39 UTC
Perhaps creating a plugin to emulate this functionality may to do the trick for us.

http://devemat-androidprogramming.blogspot.com/2011/06/selecting-text-with-webview.html
Comment 5 Brion Vibber 2011-10-24 23:48:45 UTC
This menu item doesn't appear to do anything on my Nexus 1, Android 2.3.6. No highlight or selection markers appear; tapping or dragging around after selecting the option does nothing; using the roller ball after selecting the option does nothing.
Comment 6 Tomasz Finc 2011-10-24 23:51:22 UTC
Same goes for me. I'm not seeing any changes within the UI after a key press hold.
Comment 7 Patrick Reilly 2011-10-25 00:17:45 UTC
Can we use the following approach: http://stackoverflow.com/questions/1111844/selecting-text-in-a-webview
Comment 8 Brion Vibber 2011-10-25 00:26:25 UTC
Ok, my first result was from Eclipse seeing the new *web asset files* but not the new *plugin files*. :P

After forcing it to refresh, it now builds the actual selection plugin.

But, it's... not very stable:

[17:25] <brion> it intermittently mostly-works or crashes
[17:25] <brion> when it mostly-works, it first shows a tiny mouse cursor in the center of my screen (i shit you not)
[17:25] <brion> then i can select some stuff and copy it
[17:25] <brion> when it crashes, it just crashes as soon as i select the menu item.
Comment 9 Anis Kadri 2011-10-25 01:09:01 UTC
It's crashing for me too intermittently. I will look into it tomorrow.
Comment 10 Anis Kadri 2011-10-25 01:26:48 UTC
Actually I looked into it nao. Try with this: 

https://github.com/nitobi/Wikipedia/commit/856043fd84e1bfa41812703cf24753d299ff7cd0

and let me know how it goes
Comment 11 Brion Vibber 2011-10-25 17:34:34 UTC
Ok, that version doesn't seem to crash anymore on my Nexus 1. :)

Here's a test branch that also triggers text selection mode after a tap-and-hold in the web view; it doesn't _quite_ feel natural (it's still doing the weird-ass mouse cursor thing) but on my phone it's closer to the expected behavior.

https://github.com/brion/Wikipedia/tree/hold-to-select
Comment 12 Brion Vibber 2011-10-25 20:21:29 UTC
So the ultimate confusion with all this is that as far as we can tell, long touch to activate text selection mode *is baked in to the WebView* and should already work, without us doing anything at all special.

I've checked out the Android 2.3.6r1 source and packaged it up for Eclipse (per <http://android.opensourceror.org/2010/01/18/android-source/>) so I could step through the code and see what's going on.

(Note: I had to remove a directory tree containing 'mock' interfaces so the real code would show up in Eclipse when debugging.)

WebView.performLongClick() gets called when I've been holding on the screen for half a second or so.

This function does some checks (all of which pass), including a call to super.performLongClick() which should call any standard event handlers or context menu popups that are attached. This doesn't actually trigger anything, so we keep on executing.

It then starts the text selection by calling its own WebView.setUpSelect() function (the same function that emulateLeftShiftClick() calls) and if I understand then attempts to adjust the selection to match the word you were clicking on.

Finally, it calls notifySelectDialogDismissed() and returns false to continue on to other things.


So it *really looks like* it's setting up text selection.... but it doesn't appear to actually happen. What the heck? A minimal test case might be nice here.
Comment 13 Brion Vibber 2011-10-25 20:54:09 UTC
Here's a minimal test case to confirm whether text selection works:
https://github.com/brion/WebViewTest

This is a stub Eclipse Android project with a WebView tossed in. Only added code is to load up http://en.m.wikipedia.org/ into the view.

Text selection works when I tap and hold for about a half second on a portion of the text in the web view; tested on my Nexus 1 running 2.3.6, built with Android 4.0 SDK.


So at a minimal level, we know text selection *should be able to work* in a WebView, with no special magic performed by the calling application.
Comment 14 Brion Vibber 2011-10-25 21:08:37 UTC
Ok if I call setWebChromeClient() on the WebView, it breaks! Copied a bunch of stuff out of the phonegap DroidGap class, and that was the only one to cause this effect.

        // from DroidGap:
        //
        //this.appView.setWebChromeClient(new GapClient(DroidGap.this));
        //this.setWebViewClient(this.appView, new GapViewClient(this));
        //
        // Including this line kills selection mode activation.
        webby.setWebChromeClient(new WebChromeClient());

The WebChromeClient gets called during WebView.performLongClick():

        if (mNativeClass != 0 && nativeWordSelection(x, y)) {
            nativeSetExtendSelection();
            WebChromeClient client = getWebChromeClient();
            if (client != null) client.onSelectionStart(this);
            return true;
        }

perhaps we're swapping it from a handler that performs the cut-n-paste logic to one that's ignoring it?
Comment 15 Brion Vibber 2011-10-25 21:12:39 UTC
in WebChromeClient:

    /**
     * Tell the client that the selection has been initiated.
     * @hide
     */
    public void onSelectionStart(WebView view) {
        // By default we cancel the selection again, thus disabling
        // text selection unless the chrome client supports it.
        view.notifySelectDialogDismissed();
    }


Haha! Another magic hidden public method that's not in the documentation. THANKS, ANDROID.
Comment 16 Brion Vibber 2011-10-25 22:36:46 UTC
Here's a branch of callback-android (the new home for phonegap-android) which builds with current Android SDK and lets select-copy work in the WebView:

https://github.com/brion/callback-android/tree/select-tweak
Comment 17 herman wong 2011-10-25 22:51:40 UTC
You'll need to merge the select-tweak into https://github.com/hermwong/phonegap-android since we have some custom changes for the menu plugin that have not been pulled into the main callback-android repo.
Comment 18 Brion Vibber 2011-10-25 23:08:32 UTC
Are those the Honeycomb changes that cause the app to crash on Honeycomb? Not sure we want that... :)
Comment 19 Joe Bowser 2011-11-02 21:44:16 UTC
Upgraded PhoneGap by merging the menu code with the selection tweak code.  These two commits have the upgrading of the JAR.

https://github.com/nitobi/Wikipedia/commit/b615af6b9f3a90c2a804da8abed482b2b272817a
https://github.com/nitobi/Wikipedia/commit/2c0f9294996672fa055984c360a46b0dba262b75
Comment 20 Brion Vibber 2011-11-02 21:55:25 UTC
The app no longer builds, as the .classpath still refers to phonegap-1.1.0.jar which no longer exists.

Fix in pull request: https://github.com/nitobi/Wikipedia/pull/52

With this it seems to work reasonably nice on my Nexus 1 / Android 2.3.6 -- tap-and-hold on text selects a word or a few, more as I expect. Yay!
Comment 21 Brion Vibber 2011-11-02 22:06:58 UTC
this has been merged, all is well :D
Comment 22 Amir E. Aharoni 2012-02-02 16:57:57 UTC
I am not able to tap and hold on my Sony Xperia Neo.
Comment 23 Amir E. Aharoni 2012-02-02 17:12:06 UTC
Sorry, found how to do it.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links