Search in sources :

Example 26 with WebChromeClient

use of android.webkit.WebChromeClient in project JsBridge by lzyzsd.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    webView = (BridgeWebView) findViewById(R.id.webView);
    button = (Button) findViewById(R.id.button);
    button.setOnClickListener(this);
    webView.setDefaultHandler(new DefaultHandler());
    webView.setWebChromeClient(new WebChromeClient() {

        @SuppressWarnings("unused")
        public void openFileChooser(ValueCallback<Uri> uploadMsg, String AcceptType, String capture) {
            this.openFileChooser(uploadMsg);
        }

        @SuppressWarnings("unused")
        public void openFileChooser(ValueCallback<Uri> uploadMsg, String AcceptType) {
            this.openFileChooser(uploadMsg);
        }

        public void openFileChooser(ValueCallback<Uri> uploadMsg) {
            mUploadMessage = uploadMsg;
            pickFile();
        }
    });
    webView.loadUrl("file:///android_asset/demo.html");
    webView.registerHandler("submitFromWeb", new BridgeHandler() {

        @Override
        public void handler(String data, CallBackFunction function) {
            Log.i(TAG, "handler = submitFromWeb, data from web = " + data);
            function.onCallBack("submitFromWeb exe, response data 中文 from Java");
        }
    });
    User user = new User();
    Location location = new Location();
    location.address = "SDU";
    user.location = location;
    user.name = "大头鬼";
    webView.callHandler("functionInJs", new Gson().toJson(user), new CallBackFunction() {

        @Override
        public void onCallBack(String data) {
        }
    });
    webView.send("hello");
}
Also used : BridgeHandler(com.github.lzyzsd.jsbridge.BridgeHandler) WebChromeClient(android.webkit.WebChromeClient) Gson(com.google.gson.Gson) CallBackFunction(com.github.lzyzsd.jsbridge.CallBackFunction) Uri(android.net.Uri) DefaultHandler(com.github.lzyzsd.jsbridge.DefaultHandler)

Example 27 with WebChromeClient

use of android.webkit.WebChromeClient in project android by owncloud.

the class PrivacyPolicyActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_privacy_policy);
    setupToolbar();
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    setTitle(getText(R.string.actionbar_privacy_policy));
    // Display the progress in a progress bar, like the browser app does.
    final ProgressBar mProgressBar = (ProgressBar) findViewById(R.id.syncProgressBar);
    DisplayUtils.colorPreLollipopHorizontalProgressBar(mProgressBar);
    WebView webview = (WebView) findViewById(R.id.privacyPolicyWebview);
    webview.getSettings().setJavaScriptEnabled(true);
    //Enable zoom but hide display zoom controls
    webview.getSettings().setBuiltInZoomControls(true);
    webview.getSettings().setDisplayZoomControls(false);
    webview.setWebChromeClient(new WebChromeClient() {

        public void onProgressChanged(WebView view, int progress) {
            //Set the web page loading progress
            mProgressBar.setProgress(progress);
            if (progress == 100) {
                mProgressBar.setVisibility(View.GONE);
            }
        }
    });
    webview.setWebViewClient(new WebViewClient() {

        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            Snackbar snackbar = Snackbar.make(findViewById(android.R.id.content), getString(R.string.privacy_policy_error) + description, Snackbar.LENGTH_LONG);
            snackbar.show();
        }
    });
    String urlPrivacyPolicy = getResources().getString(R.string.url_privacy_policy);
    webview.loadUrl(urlPrivacyPolicy);
}
Also used : WebChromeClient(android.webkit.WebChromeClient) WebView(android.webkit.WebView) ProgressBar(android.widget.ProgressBar) WebViewClient(android.webkit.WebViewClient) Snackbar(android.support.design.widget.Snackbar)

Example 28 with WebChromeClient

use of android.webkit.WebChromeClient in project 9GAG by Mixiaoxiao.

the class MxxBrowserActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    // setmProgressBarIndeterminateVisibility(false);
    getActionBar().setDisplayShowHomeEnabled(false);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    //		MxxSystemBarTintUtil.setSystemBarTintColor(this);
    setContentView(R.layout.mxx_common_activity_browser);
    initPadding();
    //		mActionBar = getActionBar();
    //		mActionBar.setTitle("");
    //		mActionBar.setDisplayHomeAsUpEnabled(true);
    setActionBarTitle("");
    View.OnClickListener toolbar_listener = new OnClickListener() {

        @Override
        public void onClick(View v) {
            switch(v.getId()) {
                case R.id.mxx_common_activity_browser_toolbar_btn_back:
                    if (webView.canGoBack()) {
                        webView.goBack();
                    }
                    break;
                case R.id.mxx_common_activity_browser_toolbar_btn_forward:
                    if (webView.canGoForward()) {
                        webView.goForward();
                    }
                    break;
                case R.id.mxx_common_activity_browser_toolbar_btn_refresh:
                    webView.reload();
                    break;
                default:
                    break;
            }
        }
    };
    webView = (WebView) this.findViewById(R.id.mxx_common_activity_browser_webview);
    mProgressBar = (ProgressBar) findViewById(R.id.mxx_common_activity_browser_progressbar);
    mBtnBack = (ImageButton) this.findViewById(R.id.mxx_common_activity_browser_toolbar_btn_back);
    mBtnForward = (ImageButton) this.findViewById(R.id.mxx_common_activity_browser_toolbar_btn_forward);
    mBtnRefresh = (ImageButton) this.findViewById(R.id.mxx_common_activity_browser_toolbar_btn_refresh);
    mBtnBack.setEnabled(false);
    mBtnForward.setEnabled(false);
    //		mBtnMenu = (ImageButton) this
    //				.findViewById(R.id.mxx_common_activity_browser_toolbar_btn_menu);
    //		mBtnClose = (ImageButton) this
    //				.findViewById(R.id.mxx_common_activity_browser_toolbar_btn_close);
    mBtnBack.setOnClickListener(toolbar_listener);
    mBtnForward.setOnClickListener(toolbar_listener);
    //		mBtnMenu.setOnClickListener(toolbar_listener);
    //		mBtnClose.setOnClickListener(toolbar_listener);
    mBtnRefresh.setOnClickListener(toolbar_listener);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setSupportMultipleWindows(true);
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setSupportZoom(true);
    // webView.getSettings().setUseWideViewPort(true);
    // webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setDefaultZoom(ZoomDensity.MEDIUM);
    webView.getSettings().setCacheMode(WebSettings.LOAD_NORMAL);
    webView.setClipToPadding(false);
    // webView.setFitsSystemWindows(true);
    webView.setDownloadListener(new DownloadListener() {

        @Override
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
            try {
                //					mActionBar.setTitle("下载");
                setActionBarTitle("download");
                Uri uri = Uri.parse(url);
                Intent it = new Intent(Intent.ACTION_VIEW, uri);
                startActivity(Intent.createChooser(it, "下载"));
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                MxxToastUtil.showToast(MxxBrowserActivity.this, "没有应用可执行此操作");
            }
        }
    });
    // webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET);
    webView.setWebViewClient(new WebViewClient() {

        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }

        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            // mUrlTitle.setText("鍔犺浇涓?..");
            //				mActionBar.setTitle("loading...");
            setActionBarTitle("loading...");
            mProgressBar.setVisibility(View.VISIBLE);
        //				 mPage_title.setVisibility(View.INVISIBLE);
        }

        public void onPageFinished(WebView view, String url) {
            mProgressBar.setVisibility(View.INVISIBLE);
            mBtnBack.setEnabled(view.canGoBack());
            mBtnForward.setEnabled(view.canGoForward());
        //				 mActionBar.setTitle(url);
        // mUrlTitle.setText(url);
        }
    });
    webView.setWebChromeClient(new WebChromeClient() {

        public void onProgressChanged(WebView view, int newProgress) {
            // mmProgressBar.setProgress(newProgress);
            // 璁剧疆杩涘害鐨勯暱搴︼紝0 <= progress <= 10000.
            //				setProgress(newProgress * 100);
            mProgressBar.setProgress(newProgress);
        }

        public void onReceivedIcon(WebView view, Bitmap icon) {
        // mFavor_icon.setImageBitmap(icon);
        //				mActionBar.setLogo(new BitmapDrawable(getResources(),icon));
        }

        public void onReceivedTitle(WebView view, String title) {
            // mUrlTitle.setText(title);
            //				mActionBar.setTitle(title);
            setActionBarTitle(title);
        }
    });
    Intent intent = getIntent();
    if (intent.hasExtra(extra_string_name)) {
        String urlString = intent.getStringExtra(extra_string_name);
        // webView.loadDataWithBaseURL(null, htmlString, "text/html",
        // "utf-8", null);
        webView.loadUrl(urlString);
    } else {
        // UiUtils.showToast(this, "锟斤拷莶锟斤拷锟饺笔?);
        finish();
    }
}
Also used : OnClickListener(android.view.View.OnClickListener) Intent(android.content.Intent) SpannableString(android.text.SpannableString) View(android.view.View) WebView(android.webkit.WebView) Uri(android.net.Uri) Bitmap(android.graphics.Bitmap) DownloadListener(android.webkit.DownloadListener) WebChromeClient(android.webkit.WebChromeClient) OnClickListener(android.view.View.OnClickListener) WebView(android.webkit.WebView) WebViewClient(android.webkit.WebViewClient)

Example 29 with WebChromeClient

use of android.webkit.WebChromeClient in project robotium by RobotiumTech.

the class WebUtils method prepareForStartOfJavascriptExecution.

/**
	 * Prepares for start of JavaScript execution
	 * 
	 * @return the JavaScript as a String
	 */
private String prepareForStartOfJavascriptExecution(List<WebView> webViews) {
    webElementCreator.prepareForStart();
    WebChromeClient currentWebChromeClient = getCurrentWebChromeClient();
    if (currentWebChromeClient != null && !currentWebChromeClient.getClass().isAssignableFrom(RobotiumWebClient.class)) {
        originalWebChromeClient = currentWebChromeClient;
    }
    robotiumWebCLient.enableJavascriptAndSetRobotiumWebClient(webViews, originalWebChromeClient);
    return getJavaScriptAsString();
}
Also used : WebChromeClient(android.webkit.WebChromeClient)

Example 30 with WebChromeClient

use of android.webkit.WebChromeClient in project robolectric by robolectric.

the class ShadowWebViewTest method shouldRecordWebChromeClient.

@Test
public void shouldRecordWebChromeClient() {
    WebChromeClient webChromeClient = new WebChromeClient();
    assertThat(shadowWebView.getWebChromeClient()).isNull();
    webView.setWebChromeClient(webChromeClient);
    assertThat(shadowWebView.getWebChromeClient()).isSameAs(webChromeClient);
}
Also used : WebChromeClient(android.webkit.WebChromeClient) Test(org.junit.Test)

Aggregations

WebChromeClient (android.webkit.WebChromeClient)39 WebView (android.webkit.WebView)32 WebViewClient (android.webkit.WebViewClient)29 WebSettings (android.webkit.WebSettings)13 View (android.view.View)12 Bitmap (android.graphics.Bitmap)9 SuppressLint (android.annotation.SuppressLint)6 JsResult (android.webkit.JsResult)6 WebResourceRequest (android.webkit.WebResourceRequest)6 Intent (android.content.Intent)5 LinearLayout (android.widget.LinearLayout)5 Uri (android.net.Uri)4 KeyEvent (android.view.KeyEvent)4 JsPromptResult (android.webkit.JsPromptResult)4 WebResourceError (android.webkit.WebResourceError)4 WebResourceResponse (android.webkit.WebResourceResponse)3 InjectView (butterknife.InjectView)3 IOException (java.io.IOException)3 SharedPreferences (android.content.SharedPreferences)2 Bundle (android.os.Bundle)2