Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android WebView Video after closing fullscreen view, webview auto scrolls

I am using WebView to display a webpage having text as well as video content.

It loads & display video correctly as expected.

But when I go to full screen view of video ( I implemeted full screen video view as given here ) and then come back to WebView, WebView autoscroll in some amount.

How can I fix that?

Please suggest some idea/link.

like image 617
Randheer Avatar asked Dec 26 '16 13:12

Randheer


1 Answers

I am using a compatible ScrollChangedListener already. So I've decided to scroll the view back in this listener during a period after onHideCustomView.

webview:

public interface OnScrollChangedListener {
    void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY);
}

    public void SafeScrollTo(int x, int y) {
        OnScrollChangedListener mScrollChanged = mOnScrollChangeListener;
        mOnScrollChangeListener =null;
        scrollTo(x, y);
        mOnScrollChangeListener =mScrollChanged;
    }

    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        super.onScrollChanged(l, t, oldl, oldt);
        if(mOnScrollChangeListener !=null)
            mOnScrollChangeListener.onScrollChange(this,l,t,oldl,oldt);
    }

    public void setOnScrollChangedListener(OnScrollChangedListener onSrollChangedListener) {
        mOnScrollChangeListener =onSrollChangedListener;
    }

    OnScrollChangedListener mOnScrollChangeListener;

Activity:

mWebview.setOnScrollChangedListener((v, x, y, oldx, oldy) -> {
                ArticleWebView webview = (ArticleWebView) v;
                if(CustomViewHideTime>0 && System.currentTimeMillis()-CustomViewHideTime<350){
                    webview.SafeScrollTo(oldx, oldy);
                    return;
                }});

WebChromeClient:

        @Override
        public void onHideCustomView() {
            CustomViewHideTime = System.currentTimeMillis();
            //todo delay and set CustomViewHideTime to 0
        }

This can work just fine.

like image 97
KnIfER Avatar answered Nov 15 '22 20:11

KnIfER