androidurlhandlerlong-presscrosswalk

How to get the URL on long press using Crosswalk?


I noticed that when long-pressing a link inside of a XWalkView results just in nothing. I want to handle a long press on links such as you can see in Chrome (when you long press a blue link). I don't need to know from you how to create a dialog, I want to know how to intercept the long press event.

(Note that this is android-related)

I don't care of using JavaScript for that, but it must work.

I tried using a onLongClickListener but I can't get the URL from it.

Here is the current code:

//...
private static Handler handler = new Handler();
private static Runnable longPressRunnable = new Runnable() {
    @Override
    public void run() {
        Logging.logd("Long press detected");
    }
};
//...
public static final View.OnTouchListener
        mainOnTouchListener = new View.OnTouchListener() {
    //...
    @Override
    public boolean onTouch(View view, MotionEvent motionEvent) {
        switch(motionEvent.getAction()) {
            case MotionEvent.ACTION_DOWN:
                handler.postDelayed(longPressRunnable, 1200);
                //...
                break;
            case MotionEvent.ACTION_UP:
                handler.removeCallbacks(longPressRunnable);
                //...
                break;
            case MotionEvent.ACTION_MOVE:
                //...
                handler.removeCallbacks(longPressRunnable);
                break;
            default: break;
        }
    return false;
}

Note that XWalkView does not support HitTestResult, so avoid telling me to use that as answer.


Solution

  • Actually it is not possible to do this only using a touch listener. I would have to handle it with javascript/jQuery or find another way around. I marked this as solved because I will get on my own way and this is not getting attention at all.

    Update:

    Crosswalk added it finally. You can find out how to do that here: https://github.com/xdevs23/Cornowser/blob/master/app/src/main/java/io/xdevs23/cornowser/browser/browser/xwalk/CrunchyWalkView.java#L109

    Code snippet (excerpt from link above):

            // Thanks to chuan.liu (XWALK-7233) for the awesome example
            setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    XWalkHitTestResult result = ((CrunchyWalkView) v).getHitTestResult();
                    XWalkHitTestResult.type resultType = result.getType();
                    if(result.getExtra() == null) return false;
                    switch (resultType) {
                        case IMAGE_TYPE:
                            onLongPress(result.getExtra(), result.getExtra(), true);
                            break;
                        case PHONE_TYPE:
                            break;
                        default:
                            onLongPress(result.getExtra(), result.getExtra(), false);
                            break;
                    }
                    return true;
                }
            });