Example usage for android.webkit WebChromeClient WebChromeClient

List of usage examples for android.webkit WebChromeClient WebChromeClient

Introduction

In this page you can find the example usage for android.webkit WebChromeClient WebChromeClient.

Prototype

WebChromeClient

Source Link

Usage

From source file:com.prasanna.android.stacknetwork.FullscreenTextActivity.java

@SuppressLint("SetJavaScriptEnabled")
@Override//from   w ww.  ja v a 2  s .  c  o m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.code_full_screen);

    getActionBar().hide();

    CharSequence text = getIntent().getCharSequenceExtra(StringConstants.TEXT);

    WebView webView = (WebView) findViewById(R.id.fullScreenText);
    webView.setWebChromeClient(new WebChromeClient());
    webView.setWebViewClient(new WebViewClient());
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadDataWithBaseURL(BASE_URL,
            CODE_HTML_PREFIX + MarkdownFormatter.escapeHtml(text) + CODE_HTML_SUFFIX,
            HttpContentTypes.TEXT_HTML, HTTP.UTF_8, null);
}

From source file:cn.zy.ef.fragment.WebViewFragment.java

/**
 * Called to instantiate the view. Creates and returns the WebView.
 *///from www  .ja va  2s  .co m
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (mWebView != null) {
        mWebView.destroy();
    }
    mWebView = new WebView(getActivity());
    mWebView.setWebChromeClient(new WebChromeClient());
    //mWebView.addJavascriptInterface(new InJavaScriptLocalObj(), "androidphone");
    configureWebView(mWebView.getSettings());
    mIsWebViewAvailable = true;
    return mWebView;
}

From source file:com.prasanna.android.stacknetwork.utils.MarkdownFormatter.java

public static void loadText(final WebView webView, final String text) {
    webView.setWebChromeClient(new WebChromeClient());
    webView.setWebViewClient(new WebViewClient());
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadDataWithBaseURL(BASE_URL,
            CODE_HTML_PREFIX + MarkdownFormatter.escapeHtml(text) + CODE_HTML_SUFFIX,
            HttpContentTypes.TEXT_HTML, HTTP.UTF_8, null);
}

From source file:com.wordpress.jftreading.BaseFragmentWebView.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    fragmentView = inflater.inflate(R.layout.webview_fragment, container, false);
    browser = (WebView) fragmentView.findViewById(R.id.webkit);
    browser.getSettings().setJavaScriptEnabled(true);
    browser.setWebViewClient(new WebViewClient() {
        @Override//w  ww. jav a 2s .c o m
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (!networkIsUp() && !offlinePage) {
                view.loadUrl(getErrorPage());
                return true;
            }
            if (url.startsWith("http:") || url.startsWith("https:") || url.startsWith("file:")) {
                return false;
            }
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            startActivity(intent);
            return true;
        }
    });
    browser.setWebChromeClient(new WebChromeClient() {
        @Override
        public boolean onJsConfirm(WebView view, String url, String message, JsResult result) {
            return super.onJsConfirm(view, url, message, result);
        }
    });
    browser.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                WebView webView = (WebView) v;

                switch (keyCode) {
                case KeyEvent.KEYCODE_BACK:
                    if (webView.canGoBack()) {
                        webView.goBack();
                        return true;
                    }
                    break;
                }
            }
            return false;
        }
    });
    browser.setDownloadListener(new DownloadListener() {

        @Override
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype,
                long contentLength) {
            Uri uri = Uri.parse(url);
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            startActivity(intent);
        }
    });
    browser.addJavascriptInterface(new MyJavascriptInterface(), "Android");
    browser.loadUrl(linkSelector());
    return fragmentView;
}

From source file:android.kostalms.fragment.WebViewFragment.java

@SuppressLint("SetJavaScriptEnabled")
@Override/*from ww  w. ja  v  a  2  s  .co m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // xml   .
    final View v = inflater.inflate(R.layout.webview, container, false);

    // viewContentProgress has a
    final ProgressBar viewContentProgress = (ProgressBar) v.findViewById(R.id.progress);

    // viewContentWebView has a
    viewContentWebView = (WebView) v.findViewById(R.id.webview);
    viewContentWebView.getSettings().setJavaScriptEnabled(true);
    viewContentWebView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return super.shouldOverrideUrlLoading(view, url);
        }
    });

    // WebChromeClient    .
    viewContentWebView.setWebChromeClient(new WebChromeClient() {

        //    
        @Override
        public void onProgressChanged(WebView view, int newProgress) {

            // viewContentProgress set
            viewContentProgress.setProgress(newProgress);

            // 100   .    .
            viewContentProgress.setVisibility(newProgress == 100 ? View.GONE : View.VISIBLE);

            //      url   ?
            //     .
            if (newProgress == 100 && resetHistory) {
                viewContentWebView.clearHistory();
                resetHistory = false;
            }
        }
    });
    return v;
}

From source file:org.geometerplus.android.fbreader.network.auth.WebAuthorisationScreen.java

@Override
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    requestWindowFeature(Window.FEATURE_PROGRESS);
    SQLiteCookieDatabase.init(this);
    CookieSyncManager.createInstance(getApplicationContext());
    CookieManager.getInstance().removeAllCookie();
    final Intent intent = getIntent();
    final Uri data = intent.getData();
    if (data == null || data.getHost() == null) {
        finish();/*from w w  w  .  ja v a2  s.  c om*/
        return;
    }
    final String completeUrl = intent.getStringExtra(COMPLETE_URL_KEY);

    OrientationUtil.setOrientation(this, intent);
    final WebView view = new WebView(this);
    view.getSettings().setJavaScriptEnabled(true);

    view.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int progress) {
            setProgress(progress * 100);
        }
    });
    view.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            setTitle(url);
            if (url != null && url.startsWith(completeUrl)) {
                final HashMap<String, String> cookies = new HashMap<String, String>();
                final String cookieString = CookieManager.getInstance().getCookie(url);
                if (cookieString != null) {
                    // cookieString is a string like NAME=VALUE [; NAME=VALUE]
                    for (String pair : cookieString.split(";")) {
                        final String[] parts = pair.split("=", 2);
                        if (parts.length != 2) {
                            continue;
                        }
                        cookies.put(parts[0].trim(), parts[1].trim());
                    }
                }
                storeCookies(data.getHost(), cookies);
                WebAuthorisationScreen.this.setResult(RESULT_OK);
                finish();
            }
        }

        public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
            if (android.os.Build.VERSION.SDK_INT == android.os.Build.VERSION_CODES.ECLAIR_MR1) {
                // hack for auth problem in android 2.1
                handler.proceed();
            } else {
                super.onReceivedSslError(view, handler, error);
            }
        }
    });
    setContentView(view);
    view.loadUrl(intent.getDataString());
}

From source file:org.quizreader.android.PageReadActivity.java

/** Called when the activity is first created. */
@SuppressLint("SetJavaScriptEnabled")
@Override// ww w. j a v  a  2  s  .  co m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.page_read);
    // immediately pop up loading dialog
    dialog = new ProgressDialog(this);
    dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    dialog.setMessage("loading page");
    dialog.show();
    // set up webview
    WebView webview = (WebView) findViewById(R.id.webView);
    webview.setWebViewClient(new QRWebViewClient());
    webview.setWebChromeClient(new WebChromeClient() {
        public boolean onConsoleMessage(ConsoleMessage cm) {
            Log.d("QuizReader", cm.message() + ", line " + cm.lineNumber() + " " + cm.sourceId());
            return true;
        }
    });
    WebSettings webSettings = webview.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webview.addJavascriptInterface(new QuizReaderInterface(), "qr");
    try {
        random = new Random();
        wordDao = new WordDao(this);
        qzzFile = new QzzFile(title.getFilepath(), this);
        URL htmlURL = qzzFile.getHTML(title.getId(), title.getSection());
        if (htmlURL == null) { // beyond the last section
            setResult(RESULT_END_TITLE);
            finish();
        }
        String externalForm = htmlURL.toExternalForm();
        webview.loadUrl(externalForm + "?paragraph=" + title.getParagraph());
    } catch (Exception ex) {
        webview.loadData(ex.toString(), "text/plain", null);
    }
}

From source file:yet.another.hackernews.reader.ViewFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    menuBrowser = (WebView) getSherlockActivity().findViewById(R.id.view_webview);

    final ProgressBar progressBar = (ProgressBar) getSherlockActivity().findViewById(R.id.view_progress);

    webviewSettings();//from  ww  w.j a v a2 s  .c  om

    menuBrowser.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int progress) {
            // Hide dialog on finished
            if (progress >= 100) {
                progressBar.setVisibility(View.GONE);
            } else {
                progressBar.setProgress(progress);
            }

        }
    });

    menuBrowser.setWebViewClient(new WebViewClient() {
        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {

            progressBar.setVisibility(View.GONE);

            Toast.makeText(getActivity().getApplicationContext(), R.string.error, Toast.LENGTH_SHORT).show();
        }
    });

    final Bundle recieveArgs = this.getSherlockActivity().getIntent().getExtras();

    if (recieveArgs != null) {
        try {
            news = new News(new JSONObject(recieveArgs.getString("NewsObject")));
        } catch (JSONException e) {
        }

        update(progressBar);
    }
}

From source file:com.paulshantanu.bputapp.PdfViewerAcitvity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pdf_notice);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setSubtitle("View Notice");

    String link = getIntent().getExtras().getString("link");
    Log.i("debug", "pdfintent: " + link);

    url = URLDecoder.getDecodedUrl(link);

    progressBar = ButteryProgressBar.getInstance(PdfViewerAcitvity.this);
    progressBar.setVisibility(View.VISIBLE);

    webView = (WebView) findViewById(R.id.notice_view);
    webView.setVisibility(View.INVISIBLE);
    WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { //required for running javascript on android 4.1 or later
        settings.setAllowFileAccessFromFileURLs(true);
        settings.setAllowUniversalAccessFromFileURLs(true);
    }//  w ww.  j a v a 2 s . co m
    settings.setBuiltInZoomControls(true);
    webView.setWebChromeClient(new WebChromeClient());

    new DownloadTask(PdfViewerAcitvity.this).execute(url);
}

From source file:com.clutch.ClutchView.java

@SuppressLint("SetJavaScriptEnabled")
private void clutchInit() {
    loading = new ProgressDialog(this.getContext());
    loading.hide();//  w  ww . ja v  a 2 s . co  m

    this.setWebChromeClient(new WebChromeClient() {
        // TODO: Clutch Debug Toolbar
        @Override
        public boolean onJsPrompt(WebView view, String url, String message, String defaultValue,
                JsPromptResult result) {
            if (!"methodCalled".equals(defaultValue)) {
                return false;
            }
            JSONObject jsonMessage = null;
            String methodName = null;
            String callbackId = null;
            JSONObject params = null;
            try {
                jsonMessage = new JSONObject(message);
                methodName = jsonMessage.getString("method");
                callbackId = jsonMessage.getString("callbackNum");
                params = jsonMessage.getJSONObject("args");
            } catch (JSONException e) {
                Log.e(TAG, "Could not decode JSON: " + message);
                result.cancel();
                return true;
            }
            if (methodName.equals("clutch.loading.begin")) {
                String loadingMessage = params.optString("text");
                if (loadingMessage == null) {
                    loadingMessage = "Loading...";
                } else if ("null".equals(loadingMessage)) {
                    loadingMessage = "Loading...";
                }
                loading.setMessage(loadingMessage);
                loading.show();
            } else if (methodName.equals("clutch.loading.end")) {
                loading.hide();
            }
            ClutchCallback callback = null;
            if (!"0".equals(callbackId)) {
                callback = new ClutchCallback(ClutchView.this, callbackId);
            }
            dispatcher.methodCalled(methodName, params, callback);
            result.cancel();
            return true;
        }
    });

    ClutchSync.addClutchView(this);
    WebSettings settings = this.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setSupportZoom(true);
    settings.setAppCacheEnabled(false);
}