Search in sources :

Example 1 with DocumentWebView

use of com.instructure.speedgrader.views.DocumentWebView in project instructure-android by instructure.

the class SubmissionWebViewFragment method initWebView.

public void initWebView(View rootView) {
    webView = (DocumentWebView) rootView.findViewById(R.id.documentWebView);
    webView.setVerticalScrollBarEnabled(true);
    webView.setHorizontalScrollBarEnabled(true);
    webView.requestFocusFromTouch();
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setUseWideViewPort(true);
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setBuiltInZoomControls(true);
    webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    webView.addJavascriptInterface(new JsObject(webView, loadingView), "CallToAnAndroidFunction");
    webView.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.contains("?login_success=1")) {
                view.loadUrl(currentSubmission.getPreviewUrl());
                return true;
            } else if (url.contains("score_updated=1")) {
                getSubmissionAndUpdateRubric();
            } else {
                view.loadUrl(url);
            }
            return false;
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            if (!isAdded()) {
                return;
            }
            if (!((App) getActivity().getApplication()).showStudentNames()) {
                view.loadUrl("javascript:" + "var css = document.createElement('style');" + "css.type = 'text/css';" + "css.innerHTML = '.quiz-header h2{ visibility: hidden !important; }';" + "document.getElementById('content').appendChild(css);");
            }
        }
    });
}
Also used : App(com.instructure.speedgrader.util.App) WebView(android.webkit.WebView) DocumentWebView(com.instructure.speedgrader.views.DocumentWebView) WebViewClient(android.webkit.WebViewClient)

Aggregations

WebView (android.webkit.WebView)1 WebViewClient (android.webkit.WebViewClient)1 App (com.instructure.speedgrader.util.App)1 DocumentWebView (com.instructure.speedgrader.views.DocumentWebView)1