Java Code Examples for android.webkit.WebView#getSettings()

The following examples show how to use android.webkit.WebView#getSettings() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From android-post-webview with The Unlicense 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mAddressView = (EditText) findViewById(R.id.addressView);
    mWebView = (WebView) findViewById(R.id.webView);

    WebSettings settings = mWebView.getSettings();
    settings.setJavaScriptEnabled(true);

    mWebView.setWebViewClient(new InterceptingWebViewClient(this, mWebView));
    mWebView.setWebChromeClient(new WebChromeClient());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        WebView.setWebContentsDebuggingEnabled(true);
    }

    loadOnEnter();
}
 
Example 2
Source File: ArticleActivity.java    From WanAndroid with Apache License 2.0 6 votes vote down vote up
@Override
protected void initData() {
    super.initData();
    mAgentWeb = AgentWeb.with(this)
            .setAgentWebParent(flContainer, new LinearLayout.LayoutParams(-1, -1))
            .useDefaultIndicator(getResources().getColor(R.color.colorPrimary))
            .setMainFrameErrorView(R.layout.error_view, -1)
            .setWebLayout(new WebLayout(this))
            .setOpenOtherPageWays(DefaultWebClient.OpenOtherPageWays.ASK)
            .createAgentWeb()
            .ready()
            .go(mAddress);

    //得到WebView
    WebView webView = mAgentWeb.getWebCreator().getWebView();
    WebSettings settings = webView.getSettings();
    setSettings(settings);

    //得到AgentWeb最底层的控件
    FrameLayout frameLayout = mAgentWeb.getWebCreator().getWebParentLayout();
    addBgChild(frameLayout);
}
 
Example 3
Source File: PNDVActivity.java    From PressureNet with GNU General Public License v3.0 6 votes vote down vote up
public void loadPNDV() {
	WebView pndvWebView = (WebView) findViewById(R.id.webViewPNDV);
	WebSettings webSettings = pndvWebView.getSettings();
	webSettings.setJavaScriptEnabled(true);
	webSettings.setBuiltInZoomControls(true);
	Intent intent = getIntent();
	double latitude = intent.getDoubleExtra("latitude",0.0);
	double longitude = intent.getDoubleExtra("longitude", 0.0);
	Calendar cal = Calendar.getInstance();
	long now = cal.getTimeInMillis();
	long dayInMillis = 1000*60*60*24;
	long twoDaysAgo = cal.getTimeInMillis() - (2 * dayInMillis);
	// gotta use tomorrow for UTC hack
	long tomorrow = now + dayInMillis;
	if(latitude!=0){
		pndvWebView.loadUrl(CbConfiguration.SERVER_URL_PRESSURENET + "?event=true&latitude=" + latitude + "&longitude=" + longitude + "&startTime=" + twoDaysAgo + "&endTime=" + tomorrow + "&zoomLevel=10");
	} else {
		pndvWebView.loadUrl(CbConfiguration.SERVER_URL_PRESSURENET);
	}
}
 
Example 4
Source File: InstagramDialog.java    From AndroidInstagram with Apache License 2.0 6 votes vote down vote up
private void setUpWebView() {
	mWebView = new WebView(getContext());
        
	mWebView.setVerticalScrollBarEnabled(false);
	mWebView.setHorizontalScrollBarEnabled(false);
	mWebView.setWebViewClient(new InstagramWebViewClient());
	mWebView.getSettings().setJavaScriptEnabled(true);
	mWebView.loadUrl(mAuthUrl);
	mWebView.setLayoutParams(FILL);
        
	WebSettings webSettings = mWebView.getSettings();
	
	webSettings.setSavePassword(false);
	webSettings.setSaveFormData(false);
	
	mContent.addView(mWebView);
}
 
Example 5
Source File: FullScreenWebViewDialog.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
private void buildSetting(WebView webView) {
        webView.clearCache(true);
        webView.clearHistory();
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        webSettings.setDefaultTextEncodingName("utf-8");// 避免中文乱码
        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
        webSettings.setJavaScriptEnabled(true);
        webSettings.setNeedInitialFocus(false);
//        webSettings.setDatabaseEnabled(true);
        webSettings.setDomStorageEnabled(true);
//        webSettings.setBlockNetworkLoads(true);
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);//1、提高渲染的优先级
//        webSettings.setBlockNetworkImage(true);//把图片加载放在最后来加载渲染
        webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
        webSettings.setSupportZoom(false);
    }
 
Example 6
Source File: FullScreenWebViewDialog.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
private void buildSetting(WebView webView) {
        webView.clearCache(true);
        webView.clearHistory();
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        webSettings.setDefaultTextEncodingName("utf-8");// 避免中文乱码
        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
        webSettings.setJavaScriptEnabled(true);
        webSettings.setNeedInitialFocus(false);
//        webSettings.setDatabaseEnabled(true);
        webSettings.setDomStorageEnabled(true);
//        webSettings.setBlockNetworkLoads(true);
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);//1、提高渲染的优先级
//        webSettings.setBlockNetworkImage(true);//把图片加载放在最后来加载渲染
        webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
        webSettings.setSupportZoom(false);
    }
 
Example 7
Source File: JSWebViewActivity.java    From iBeebo with GNU General Public License v3.0 6 votes vote down vote up
public void initView() {
    mWebView = (WebView) findViewById(R.id.webview);

    mInjectJS = new InjectJS(mWebView);

    mWebView.setVerticalScrollBarEnabled(false);
    mWebView.setHorizontalScrollBarEnabled(false);
    mWebView.requestFocus();

    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setSaveFormData(true);
    webSettings.setSupportZoom(true);
    webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);

    progressBar = findViewById(R.id.show_request_progress_bar);

}
 
Example 8
Source File: MainActivity.java    From androidtestdebug with MIT License 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    
    final WebView wv = (WebView)findViewById(R.id.webview);
    // 启用JavaScript解释功能
    WebSettings setting = wv.getSettings();
    setting.setJavaScriptEnabled(true);
    
    // 扩展前台网页的JavaScript API
    wv.addJavascriptInterface(
    		new JavaScriptBridge(this), "android");
    
    // 设置点击“浏览”按钮的事件处理函数 - 显示网页
    Button btnBrowse = (Button)findViewById(R.id.btnBrowse);
    btnBrowse.setOnClickListener(new OnClickListener() {
    	public void onClick(View v) {
    		EditText txtUrl = (EditText)findViewById(R.id.txtUrl);
    		String url = txtUrl.getText().toString();
    		wv.loadUrl(url);
    	}
    });
}
 
Example 9
Source File: WebViewSignInActivity.java    From android-AutofillFramework with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.login_webview_activity);

    WebView webView = findViewById(R.id.webview);
    WebSettings webSettings = webView.getSettings();
    webView.setWebViewClient(new WebViewClient());
    webSettings.setJavaScriptEnabled(true);

    String url = getIntent().getStringExtra("url");
    if (url == null) {
        url = "file:///android_res/raw/sample_form.html";
    }
    if (DEBUG) Log.d(TAG, "Clearing WebView data");
    webView.clearHistory();
    webView.clearFormData();
    webView.clearCache(true);
    Log.i(TAG, "Loading URL " + url);
    webView.loadUrl(url);
}
 
Example 10
Source File: WebViewCache.java    From tysq-android with GNU General Public License v3.0 5 votes vote down vote up
public WebViewCache(Context context, String url, int size) {

        mWebViewList = new ArrayList<>(size);

        int width = ScreenAdapterUtils.getScreenWidth();
        int height = ScreenAdapterUtils.getAdHeight();

        for (int i = 0; i < DEFAULT_WEBVIEW_NUM; i++){
            WebView webView = new WebView(context);
            webView.loadUrl(url);

            ViewGroup.LayoutParams layoutParams = webView.getLayoutParams();

            if (layoutParams == null){
                layoutParams = new ViewGroup.LayoutParams(width, height);
            } else {
                layoutParams.width = width;
                layoutParams.height = height;
            }

            webView.setLayoutParams(layoutParams);
            webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);

            WebSettings settings = webView.getSettings();
            settings.setJavaScriptEnabled(true);
            webView.addJavascriptInterface(new TyJavaScriptInterface(context), "android");

            mWebViewList.add(webView);
        }
    }
 
Example 11
Source File: WebviewActivity.java    From AndroidProjects with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_webview);
    String url = getIntent().getStringExtra(EXTRA_URL);
    WebView webView = (WebView)findViewById(R.id.webview);
    webView.setWebViewClient(new WebViewClient());
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    setTitle(url);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    webView.loadUrl(url);
}
 
Example 12
Source File: WebViewPresenter.java    From gank with GNU General Public License v3.0 5 votes vote down vote up
public void setWebViewSettings(WebView webView, String url) {
    WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setLoadWithOverviewMode(true);
    settings.setAppCacheEnabled(true);
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    settings.setSupportZoom(true);
    webView.setWebChromeClient(new ChromeClient());
    webView.setWebViewClient(new GankClient());
    webView.loadUrl(url);
}
 
Example 13
Source File: WebSettingsCompat.java    From Android_Skin_2.0 with Apache License 2.0 5 votes vote down vote up
private WebSettingsCompat(int apiVersion, WebView view) {
	super();
	if (apiVersion >= Build.VERSION_CODES.JELLY_BEAN) {
		impl = new JellyBeanWebSettingsCompatImpl();
	} else if (apiVersion >= Build.VERSION_CODES.HONEYCOMB) {
		impl = new HoneyCombWebSettingsCompatImpl();
	} else if (apiVersion >= Build.VERSION_CODES.FROYO) {
		impl = new FroyoWebSettingsCompatImpl();
	} else if (apiVersion >= Build.VERSION_CODES.ECLAIR_MR1) {
		impl = new EclairMr1WebSettingsCompatImpl();
	} else {
		impl = new EarlyWebSettingsCompatImpl();
	}
	settings = view.getSettings();
}
 
Example 14
Source File: WebFragment.java    From Android_framework with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void initView() {
    webView = (WebView) mViewContainer;
    webView.setWebViewClient(webViewClient);
    webView.setWebChromeClient(chromeClient);

    WebSettings settings = webView.getSettings();
    //设置网页大小自适应
    settings.setUseWideViewPort(true);
    settings.setLoadWithOverviewMode(true);
    //支持js
    settings.setJavaScriptEnabled(true);
}
 
Example 15
Source File: WebViewPageActivity.java    From phphub-android with Apache License 2.0 5 votes vote down vote up
private String getUserAgent() {
    if (Build.VERSION.SDK_INT < 19) {
        WebView webView = new WebView(this);
        WebSettings settings = webView.getSettings();
        return settings.getUserAgentString();
    }

    // api >= 19
    return WebSettings.getDefaultUserAgent(this);
}
 
Example 16
Source File: ViewUtils.java    From Qiitanium with MIT License 4 votes vote down vote up
public static void setupWebView(WebView webview) {
  webview.setVerticalScrollbarOverlay(true);
  WebSettings settings = webview.getSettings();
  settings.setLoadWithOverviewMode(true);
  settings.setUseWideViewPort(true);
}
 
Example 17
Source File: AssistActivity.java    From letv with Apache License 2.0 4 votes vote down vote up
@SuppressLint({"SetJavaScriptEnabled"})
private void setWebViewAttributes(WebView wv) {
    WebSettings webSettings = wv.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setBlockNetworkImage(true);
}
 
Example 18
Source File: Html5Activity.java    From ClassSchedule with Apache License 2.0 4 votes vote down vote up
@SuppressLint("JavascriptInterface")
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_web);

    mSmoothProgress = findViewById(R.id.smooth_progress);

    Bundle bundle = getIntent().getBundleExtra("bundle");
    mUrl = bundle.getString("url");
    mTitle = bundle.getString("title", "");
    mJavaScriptInterface = bundle.getSerializable("javascript");

    initBackToolbar(TextUtils.isEmpty(mTitle) ? "加载中" : mTitle);

    Log.d("Url:", mUrl);
    Log.d("mTitle:", mTitle);


    mLayout = (LinearLayout) findViewById(R.id.web_layout);


    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    mWebView = new WebView(getApplicationContext());
    mWebView.setLayoutParams(params);
    mLayout.addView(mWebView);

    WebSettings mWebSettings = mWebView.getSettings();
    mWebSettings.setSupportZoom(true);
    mWebSettings.setLoadWithOverviewMode(true);
    mWebSettings.setUseWideViewPort(true);
    mWebSettings.setDefaultTextEncodingName("utf-8");
    mWebSettings.setLoadsImagesAutomatically(true);

    //调用JS方法.安卓版本大于17,加上注解 @JavascriptInterface
    mWebSettings.setJavaScriptEnabled(true);

    if (mJavaScriptInterface != null) {
        mWebView.addJavascriptInterface(mJavaScriptInterface, "android");
    }

    mWebView.setDownloadListener(new DownloadListener() {
        @Override
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
            downloadByBrowser(url);
        }
    });

    saveData(mWebSettings);

    newWin(mWebSettings);

    mWebView.setWebChromeClient(webChromeClient);


    mWebView.setWebViewClient(webViewClient);
    mWebView.loadUrl(mUrl);
}
 
Example 19
Source File: NewsDetailActivity.java    From LiuAGeAndroid with MIT License 4 votes vote down vote up
/**
     * 准备UI
     */
    private void prepareUI() {
        mTopBar = findViewById(R.id.v_cell_news_detail_top_bar);
        mContentView = (ViewGroup) findViewById(R.id.activity_news_detail);
        mProgressBar = (ProgressBar) findViewById(R.id.pb_news_detail_progressbar);
        mScrollView = (ScrollView) findViewById(R.id.bsv_news_detail_scrollview);
        mContentWebView = (WebView) findViewById(R.id.wv_news_detail_webview);
        mShareQQButton = findViewById(R.id.ll_article_content_share_qq);
        mShareWxButton = findViewById(R.id.ll_article_content_share_weixin);
        mSharePyqButton = findViewById(R.id.ll_article_content_share_pyq);
        mBackButton = (ImageButton) findViewById(R.id.ib_news_detail_bottom_bar_back);
        mEditButton = (ImageButton) findViewById(R.id.ib_news_detail_bottom_bar_edit);
        mFontButton = (ImageButton) findViewById(R.id.ib_news_detail_bottom_bar_font);
        mCollectionButton = (ImageButton) findViewById(R.id.ib_news_detail_bottom_bar_collection);
        mShareButton = (ImageButton) findViewById(R.id.ib_news_detail_bottom_bar_share);
        mLinkLayout = (LinearLayout) findViewById(R.id.ll_news_detail_links);
        mLinkRecyclerView = (RecyclerView) findViewById(R.id.rv_news_detail_links_recyclerview);
        mCommentLayout = (LinearLayout) findViewById(R.id.ll_news_detail_comment);
        mCommentRecyclerView = (RecyclerView) findViewById(R.id.rv_news_detail_comment_recyclerview);
        mMoreCommentButton = (Button) findViewById(R.id.btn_news_detail_comment_more);
        mAdImageView = (SimpleDraweeView) findViewById(R.id.iv_news_detail_ad_image);
        mAdTextView = (TextView) findViewById(R.id.tv_news_detail_ad_text);

        // 如果未能修改掉状态栏的颜色,就修改状态栏的背景颜色
        if (!isStatusChanged) {
            mTopBar.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
            mTopBar.setAlpha(1);
        }

        // 新闻正文
        WebSettings webSettings = mContentWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        // 开启硬件加速后,webView内容太大会crash 还在寻求最终解决办法
//        mContentWebView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        mContentWebView.addJavascriptInterface(new ArticleJavascriptInterface(), "ARTICLE");
        mContentWebView.setWebChromeClient(new WebChromeClient() {
        });
        mContentWebView.setWebViewClient(new WebViewClient() {

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                // 隐藏加载进度条
                mProgressBar.setVisibility(View.INVISIBLE);
                // 网页加载完成才去加载其他UI
                setupDetailData();
                // 加载网页缓存图片
                getImageFromDownloaderOrDiskByImageUrlArray();
                // 页面滑动到顶部
                mScrollView.fullScroll(ScrollView.FOCUS_UP);
            }

        });

        // 底部工具条按钮点击事件
        mBackButton.setOnClickListener(this);
        mEditButton.setOnClickListener(this);
        mFontButton.setOnClickListener(this);
        mCollectionButton.setOnClickListener(this);
        mShareButton.setOnClickListener(this);
        mShareQQButton.setOnClickListener(this);
        mShareWxButton.setOnClickListener(this);
        mSharePyqButton.setOnClickListener(this);
        mAdImageView.setOnClickListener(this);

        // 更多评论
        mMoreCommentButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 跳转到评论列表
                CommentListActivity.start(mContext, classid, id, commentBeanList, "news");
            }
        });

    }
 
Example 20
Source File: SendScreen.java    From smartcoins-wallet with MIT License 4 votes vote down vote up
private void loadWebView(WebView webView, int size, String encryptText) {
    String htmlShareAccountName = "<html><head><style>body,html {margin:0; padding:0; text-align:center;}</style><meta name=viewport content=width=" + size + ",user-scalable=no/></head><body><canvas width=" + size + " height=" + size + " data-jdenticon-hash=" + encryptText + "></canvas><script src=https://cdn.jsdelivr.net/jdenticon/1.3.2/jdenticon.min.js async></script></body></html>";
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webView.loadData(htmlShareAccountName, "text/html", "UTF-8");
}