@Override public void onActivityCreated(Bundle saved) { super.onActivityCreated(saved); view = (WebView) getView().findViewById(R.id.Viewport); // enable JavaScript for cool things to happen! view.getSettings().setJavaScriptEnabled(true); // ----- SWIPE PAGE view.setOnTouchListener( new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (state == ViewStateEnum.books) swipePage(v, event, 0); WebView view = (WebView) v; return view.onTouchEvent(event); } }); // ----- NOTE & LINK view.setOnLongClickListener( new OnLongClickListener() { @Override public boolean onLongClick(View v) { Message msg = new Message(); msg.setTarget( new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); String url = msg.getData().getString(getString(R.string.url)); if (url != null) navigator.setNote(url, index); } }); view.requestFocusNodeHref(msg); return false; } }); view.setWebViewClient( new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { try { navigator.setBookPage(url, index); } catch (Exception e) { errorMessage(getString(R.string.error_LoadPage)); } return true; } }); loadPage(viewedPage); }
@SuppressLint("SetJavaScriptEnabled") private void setup() { mScale = mActivity.getResources().getDisplayMetrics().density; mWebView.setOnLongClickListener(this); mWebView.setOnTouchListener(this); final WebSettings settings = mWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); mSelectionController = new TextSelectionController(this); mWebView.addJavascriptInterface(mSelectionController, TextSelectionController.INTERFACE_NAME); createSelectionLayer(mActivity); }
private void webViewInitialization(final Activity activity) { webView = (WebView) findViewById(R.id.webview); webView.setWebChromeClient( new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { activity.setProgress(progress * 1000); if (progress == 100 && progressDialog.isShowing()) progressDialog.dismiss(); } @Override public boolean onConsoleMessage(ConsoleMessage consoleMessage) { String message = format( "Javascript Log. Message: {0}, lineNumber: {1}, sourceId, {2}", consoleMessage.message(), consoleMessage.lineNumber(), consoleMessage.sourceId()); if (consoleMessage.messageLevel() == ERROR) { logError(message); reportException(message); } else { logDebug(message); } return true; } }); webView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH); webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAllowUniversalAccessFromFileURLs(true); webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); webView.addJavascriptInterface(formController, "formContext"); webView.addJavascriptInterface(navigationController, "navigationContext"); webView.addJavascriptInterface( new VillageController( context.allEligibleCouples(), context.listCache(), context.villagesCache()), "villageContext"); webView.addJavascriptInterface( new InternationalizationContext(getResources()), "internationalizationContext"); webView.addJavascriptInterface(context.anmLocationController(), ANM_LOCATION_CONTROLLER); webView.setOnLongClickListener( new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { return true; } }); }