8

I was able to get the selected text using the following method:

webview.evaluateJavascript("(function(){return window.getSelection().toString()})()",
    new ValueCallback<String>()
    {
        @Override
        public void onReceiveValue(String value)
        {
            selected = value;
            Log.v(TAG, "SELECTION:" + value);
        }
    }
);

And I detect the first selection using when the motion event detected by the onTouchEvent is ACTION_UP.

webview.setOnTouchListener(new View.OnTouchListener() {
    public boolean onTouch(View v, MotionEvent event) {
        int action = event.getAction();
        if(event.getAction() == MotionEvent.ACTION_UP)
        {
           //webview started selection a word
        }
    }
});

My problem is to be able to detect when the selection changes using the handlers. Unfortunately ACTION_MOVE and ACTION_DOWN are not getting called while changing the selection using the default selection handlers.

Kindly note that when I use the ActionMode CallBack function, the default selection stops working.

Sufian
  • 6,405
  • 16
  • 66
  • 120
coder
  • 5,200
  • 3
  • 20
  • 45

1 Answers1

1

Instead of trying to mange the touches try letting the system do it for you:

How to get the selected text of webview in ActionMode override

@Override
public void onReceiveValue(String value)
{
    Log.v(TAG, "SELECTION:" + value);
}

with possibly.... selection change ? :)

Community
  • 1
  • 1