Search code examples
androidcrosswalk-runtime

Cross Walk XWalkView the super class Views methods are not being called. For e.g. onScrollChanged


We trying to handle the scrolling event of Cross Walk XWalkView version 12.41.296.9-x86 but the scrolling is not being called.

    public class CustomXWalkView extends XWalkView{

    public CustomXWalkView(Context arg0, Activity arg1) {
        super(arg0, arg1);
    }

    public CustomXWalkView (Context context, AttributeSet attrs)  {
        super(context, attrs);
    }



    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        super.onScrollChanged(l, t, oldl, oldt);
        Log.d("I'm scrolling", "do");
    }
}

How do i get onScrollChanged event is XWalkView.


Solution

  • Below custom web view solved my problem. Hope it helps

    package com.example.crosswalkexample;
    
    import org.chromium.content.browser.ContentViewCore;
    import org.xwalk.core.XWalkView;
    import org.xwalk.core.internal.XWalkViewBridge;
    
    import android.app.Activity;
    import android.content.Context;
    import android.content.res.Configuration;
    import android.graphics.Canvas;
    import android.util.AttributeSet;
    import android.util.Log;
    import android.view.KeyEvent;
    import android.view.MotionEvent;
    import android.view.View;
    
    public class CustomCrossWalkView extends XWalkView implements ContentViewCore.InternalAccessDelegate {
    
    
        private XWalkViewBridge mWalkViewBridge;
        private ContentViewCore mContentViewCore;
    
        public CustomCrossWalkView(Context context, Activity arg1) {
            super(context, arg1);
            init();
        }
    
        public CustomCrossWalkView(Context context, AttributeSet attrs) {
            super(context, attrs);
            init();
        }
    
        private void init(){
            if(this.getChildCount() > 0){
                mWalkViewBridge = (XWalkViewBridge) this.getChildAt(0);
            }else{
                throw new Error("XWalkWebView Bridge not found");
            }
            mContentViewCore = mWalkViewBridge.getXWalkContentForTest();
            mContentViewCore.setContainerViewInternals(this);
        }
    
        @Override
        public boolean super_awakenScrollBars(int arg0, boolean arg1) {
            // TODO Auto-generated method stub
            return false;
        }
    
        @Override
        public boolean super_dispatchKeyEvent(KeyEvent arg0) {
            // TODO Auto-generated method stub
            return false;
        }
    
        @Override
        public boolean super_dispatchKeyEventPreIme(KeyEvent arg0) {
            // TODO Auto-generated method stub
            return false;
        }
    
        @Override
        public void super_onConfigurationChanged(Configuration arg0) {
            // TODO Auto-generated method stub
    
        }
    
        @Override
        public boolean super_onGenericMotionEvent(MotionEvent arg0) {
            // TODO Auto-generated method stub
            return false;
        }
    
        @Override
        public boolean super_onKeyUp(int arg0, KeyEvent arg1) {
            // TODO Auto-generated method stub
            return false;
        }
    
    
        @Override
        public boolean awakenScrollBars() {
            // TODO Auto-generated method stub
            return super.awakenScrollBars();
        }
    
        @Override
        public boolean drawChild(Canvas canvas, View child, long drawingTime) {
            // TODO Auto-generated method stub
            return super.drawChild(canvas, child, drawingTime);
        }
    
        @Override
        public void onScrollChanged(int l, int t, int oldl, int oldt) {
            // TODO Auto-generated method stub
            Log.d("onScrollChanged", "Scorlling");
            super.onScrollChanged(l, t, oldl, oldt);
        }
    
        @Override
        public boolean dispatchTouchEvent(MotionEvent ev) {
            // TODO Auto-generated method stub
            return super.dispatchTouchEvent(ev);
        }
    
    
    }