Java Code Examples for android.webkit.WebSettings#setAppCacheEnabled()

The following examples show how to use android.webkit.WebSettings#setAppCacheEnabled() . 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: TripDetailActivity.java    From Mobike with Apache License 2.0 7 votes vote down vote up
private void initWebView() {
    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    /*使webview能够加载图片*/
    webSettings.setBlockNetworkImage(false);
    webSettings.setAppCacheEnabled(true);
    mDialog=new SpotsDialog(this);
    mDialog.show();
    mWebView.loadUrl(mMessage.getClickUrl());
    //        mWebAppInterface = new WebAppInterface(this);
    //        mWebView.addJavascriptInterface(mWebAppInterface, "appInterface");
    mWebView.setWebViewClient(new MyWebChromeC());
    mWebView.setWebChromeClient(new WebChromeClient(){

    });

}
 
Example 2
Source File: JockeyJsWebView.java    From TLint with Apache License 2.0 6 votes vote down vote up
private void initWebView() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        setWebContentsDebuggingEnabled(BuildConfig.DEBUG);
    }
    WebSettings settings = getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setAllowFileAccess(true);
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    settings.setUseWideViewPort(true);
    settings.setSupportZoom(false);
    settings.setBuiltInZoomControls(false);
    settings.setSupportMultipleWindows(true);
    settings.setDefaultTextEncodingName("UTF-8");
    if (Build.VERSION.SDK_INT > 12) {
        settings.setJavaScriptCanOpenWindowsAutomatically(true);
    }
    settings.setAppCacheEnabled(true);
    settings.setLoadWithOverviewMode(true);
    settings.setDomStorageEnabled(true);
    settings.setCacheMode(NetWorkUtil.isNetworkConnected(getContext()) ? WebSettings.LOAD_DEFAULT
            : WebSettings.LOAD_CACHE_ELSE_NETWORK);
    settings.setCacheMode(2);
    if (Build.VERSION.SDK_INT > 11) {
        setLayerType(0, null);
    }
}
 
Example 3
Source File: BrowseActivity.java    From AndroidDownload with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    super.setTopBarTitle("详情页面");
    Intent getIntent = getIntent();
    btUrl=getIntent.getStringExtra("url");
    lt = new LoadToast(this);
    webView.setWebChromeClient(new MyWebChromeClient());
    WebSettings webSettings = webView.getSettings();
    webSettings.setAppCacheEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.supportMultipleWindows();
    webSettings.setAllowContentAccess(true);
    webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    webSettings.setUseWideViewPort(true);
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setSavePassword(true);
    webSettings.setSaveFormData(true);
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    webSettings.setLoadsImagesAutomatically(true);
    webSettings.setJavaScriptEnabled(false);
    webView.setWebViewClient(new WebViewClient());
    webView.loadUrl(btUrl);
    lt.setTranslationY(200).setBackgroundColor(getResources().getColor(R.color.colorMain)).setProgressColor(getResources().getColor(R.color.white));
    lt.show();
}
 
Example 4
Source File: MessageDetailActivity.java    From Mobike with Apache License 2.0 6 votes vote down vote up
private void initWebView() {
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        /*使webview能够加载图片*/
        webSettings.setBlockNetworkImage(false);
        webSettings.setAppCacheEnabled(true);
        mDialog=new SpotsDialog(this);
        mDialog.show();
        mWebView.loadUrl(mMessage.getClickUrl());
//        mWebAppInterface = new WebAppInterface(this);
//        mWebView.addJavascriptInterface(mWebAppInterface, "appInterface");
        mWebView.setWebViewClient(new MyWebChromeC());
        mWebView.setWebChromeClient(new WebChromeClient(){

        });

    }
 
Example 5
Source File: Tab2Fragment.java    From HelloActivityAndFragment with Apache License 2.0 5 votes vote down vote up
@SuppressLint("JavascriptInterface")
private void initWebView() {

    // Settings
    WebSettings settings = webView.getSettings();
    settings.setDefaultTextEncodingName("GBK");
    settings.setJavaScriptEnabled(true);
    settings.setDomStorageEnabled(true);
    settings.setGeolocationEnabled(true);
    // settings.setDisplayZoomControls(false);
    settings.setBuiltInZoomControls(true);
    settings.setUseWideViewPort(true);
    settings.setLoadWithOverviewMode(true);

    settings.setDatabaseEnabled(true);
    settings.setAppCacheEnabled(true);
    settings.setAppCachePath(this.getContext().getCacheDir().getAbsolutePath());
    settings.setDisplayZoomControls(false);


    webView.requestFocus();

    webView.setWebViewClient(new WebViewClient() {
    });

    webView.setWebChromeClient(new WebChromeClient() {

    });

}
 
Example 6
Source File: WebViewActivity.java    From CircleFloatBar with Apache License 2.0 5 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
@Override
public void initWebView() {
    WebSettings settings = mWebView.getSettings();
    settings.setLoadWithOverviewMode(true);
    settings.setJavaScriptEnabled(true);
    settings.setAppCacheEnabled(true);
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    settings.setSupportZoom(true);

    mWebView.setWebChromeClient(new MyWebChrome());
    mWebView.setWebViewClient(new MyWebClient());
}
 
Example 7
Source File: ReadabilityActivity.java    From Ninja with Apache License 2.0 5 votes vote down vote up
private void initWebView() {
    webView.setAlwaysDrawnWithCacheEnabled(true);
    webView.setAnimationCacheEnabled(true);
    webView.setDrawingCacheBackgroundColor(0x00000000);
    webView.setDrawingCacheEnabled(true);
    webView.setWillNotCacheDrawing(false);
    webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);

    webView.setFocusable(true);
    webView.setFocusableInTouchMode(true);
    webView.setScrollbarFadingEnabled(true);
    webView.setHorizontalScrollBarEnabled(true);
    webView.setVerticalScrollBarEnabled(true);

    webView.setBackground(null);
    webView.getRootView().setBackground(null);
    int color = sp.getInt(getString(R.string.sp_readability_background), getResources().getColor(R.color.white));
    webView.setBackgroundColor(color);

    WebSettings webSettings = webView.getSettings();
    webSettings.setAppCacheEnabled(true);
    webSettings.setAppCachePath(getCacheDir().toString());
    webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
    webSettings.setDefaultTextEncodingName(BrowserUnit.URL_ENCODING);
    webSettings.setSupportZoom(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setDisplayZoomControls(false);
    webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setTextZoom(100);
    webSettings.setUseWideViewPort(true);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        webSettings.setLoadsImagesAutomatically(true);
    } else {
        webSettings.setLoadsImagesAutomatically(false);
    }
}
 
Example 8
Source File: WebViewActivity.java    From mattermost-android-classic with Apache License 2.0 5 votes vote down vote up
protected void initWebView(WebView view) {
    webView = view;
    setProgressBarVisibility(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        WebView.setWebContentsDebuggingEnabled(true);
    }

    WebSettings settings = view.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setDomStorageEnabled(true);
    settings.setUserAgentString(settings.getUserAgentString() + " Web-Atoms-Mobile-WebView");
    settings.setDatabaseEnabled(true);
    settings.setMediaPlaybackRequiresUserGesture(false);

    final File dir = this.getExternalCacheDir();
    settings.setAppCacheMaxSize(1024*1024*20);
    settings.setAppCachePath(dir.getAbsolutePath());
    settings.setAllowFileAccess(true);
    settings.setAppCacheEnabled(true);
    settings.setCacheMode(WebSettings.LOAD_DEFAULT);
    view.setDownloadListener(getDownloadListener());

    CookieManager cookies = CookieManager.getInstance();
    cookies.setAcceptCookie(true);

    setWebViewClient(view);
    setWebChromeClient(view);
}
 
Example 9
Source File: HuPuWebView.java    From SprintNBA with Apache License 2.0 5 votes vote down vote up
private void init() {
    WebSettings settings = getSettings();
    settings.setBuiltInZoomControls(false);
    settings.setSupportZoom(false);
    settings.setJavaScriptEnabled(true);
    settings.setAllowFileAccess(true);
    settings.setSupportMultipleWindows(false);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setDomStorageEnabled(true);
    settings.setCacheMode(WebSettings.LOAD_DEFAULT);
    settings.setUseWideViewPort(true);
    if (Build.VERSION.SDK_INT > 6) {
        settings.setAppCacheEnabled(true);
        settings.setLoadWithOverviewMode(true);
    }
    String path = getContext().getFilesDir().getPath();
    settings.setGeolocationEnabled(true);
    settings.setGeolocationDatabasePath(path);
    settings.setDomStorageEnabled(true);
    this.basicUA = settings.getUserAgentString() + " kanqiu/7.05.6303/7059";
    setBackgroundColor(0);
    initWebViewClient();
    setWebChromeClient(new HuPuChromeClient());
    try {
        if (SettingPrefUtils.isLogin()) {
            CookieManager cookieManager = CookieManager.getInstance();
            cookieManager.setCookie("http://bbs.mobileapi.hupu.com", "u=" + SettingPrefUtils.getCookies());
            cookieManager.setCookie("http://bbs.mobileapi.hupu.com", "_gamesu=" + URLEncoder.encode(SettingPrefUtils.getToken(), "utf-8"));
            cookieManager.setCookie("http://bbs.mobileapi.hupu.com", "_inKanqiuApp=1");
            cookieManager.setCookie("http://bbs.mobileapi.hupu.com", "_kanqiu=1");
            CookieSyncManager.getInstance().sync();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 10
Source File: MainActivity.java    From webTube with GNU General Public License v3.0 5 votes vote down vote up
public void setUpWebview() {
    // To save login info
    CookieHelper.acceptCookies(webView, true);

    // Some settings
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setJavaScriptCanOpenWindowsAutomatically(false);
    webSettings.setAllowFileAccess(false);

    webSettings.setDatabaseEnabled(true);

    String cachePath = mApplicationContext
            .getDir("cache", Context.MODE_PRIVATE).getPath();
    webSettings.setAppCachePath(cachePath);
    webSettings.setAllowFileAccess(true);
    webSettings.setAppCacheEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);

    webView.setHorizontalScrollBarEnabled(false);

    webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);

    webView.setBackgroundColor(Color.WHITE);
    webView.setScrollbarFadingEnabled(true);
    webView.setNetworkAvailable(true);
}
 
Example 11
Source File: Html5Activity.java    From ClassSchedule with Apache License 2.0 5 votes vote down vote up
/**
 * HTML5数据存储
 */
private void saveData(WebSettings mWebSettings) {
    //有时候网页需要自己保存一些关键数据,Android WebView 需要自己设置
    mWebSettings.setDomStorageEnabled(true);
    mWebSettings.setDatabaseEnabled(true);
    mWebSettings.setAppCacheEnabled(true);
    String appCachePath = getApplicationContext().getCacheDir().getAbsolutePath();
    mWebSettings.setAppCachePath(appCachePath);
}
 
Example 12
Source File: WebViewActivity.java    From ByWebView with Apache License 2.0 4 votes vote down vote up
@SuppressLint({"SetJavaScriptEnabled", "AddJavascriptInterface"})
    private void initWebView() {
        WebSettings ws = webView.getSettings();
        // 保存表单数据
        ws.setSaveFormData(true);
        // 是否应该支持使用其屏幕缩放控件和手势缩放
        ws.setSupportZoom(true);
        ws.setBuiltInZoomControls(true);
        ws.setDisplayZoomControls(false);
        // 启动应用缓存
        ws.setAppCacheEnabled(true);
        // 设置缓存模式
        ws.setCacheMode(WebSettings.LOAD_DEFAULT);
        // setDefaultZoom  api19被弃用
        // 网页内容的宽度自适应屏幕
        ws.setLoadWithOverviewMode(true);
        ws.setUseWideViewPort(true);
        // 网页缩放至100,一般的网页达到屏幕宽度效果,个别除外
//        webView.setInitialScale(100);
        // 关掉下滑弧形阴影
//        webView.setOverScrollMode(WebView.OVER_SCROLL_NEVER);
        // 告诉WebView启用JavaScript执行。默认的是false。
        ws.setJavaScriptEnabled(true);
        //  页面加载好以后,再放开图片
        ws.setBlockNetworkImage(false);
        // 使用localStorage则必须打开
        ws.setDomStorageEnabled(true);
        // 排版适应屏幕
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        } else {
            ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
        }
        // WebView是否新窗口打开(加了后可能打不开网页)
//        ws.setSupportMultipleWindows(true);

        // webview从5.0开始默认不允许混合模式,https中不能加载http资源,需要设置开启。
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            ws.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
        }
        /** 设置字体默认缩放大小(改变网页字体大小,setTextSize  api14被弃用)*/
        ws.setTextZoom(100);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            webView.setScrollBarSize(WebTools.dp2px(this, 3));
        }

        mWebChromeClient = new MyWebChromeClient(this);
        webView.setWebChromeClient(mWebChromeClient);
        // 与js交互
        webView.addJavascriptInterface(new MyJavascriptInterface(this), "injectedObject");
        webView.setWebViewClient(new MyWebViewClient(this));
        webView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                return handleLongImage();
            }
        });

    }
 
Example 13
Source File: Browse9PForumActivity.java    From v9porn with MIT License 4 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_browse9_porn);
    ButterKnife.bind(this);
    historyIdStack = new Stack<>();
    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setAppCacheEnabled(true);
    webSettings.setAppCachePath(AppCacheUtils.getRxCacheDir(context).getAbsolutePath());
    mWebView.setWebChromeClient(
            new InjectedChromeClient("HostApp", HostJsScope.class)
    );
    mWebView.setBackgroundColor(0);
    mWebView.setBackgroundResource(0);
    mWebView.setVisibility(View.INVISIBLE);
    mWebView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.contains("tid=")) {
                int starIndex = url.indexOf("tid=");
                String tidStr = StringUtils.subString(url, starIndex + 4, starIndex + 10);
                if (!TextUtils.isEmpty(tidStr) && TextUtils.isDigitsOnly(tidStr)) {
                    Long id = Long.parseLong(tidStr);
                    presenter.loadContent(id);
                    historyIdStack.push(id);
                } else {
                    Logger.t(TAG).d(tidStr);
                    showMessage("暂不支持直接打开此链接", TastyToast.INFO);
                }
            }
            return true;
        }
    });
    AppUtils.setColorSchemeColors(context, swipeLayout);
    f9PronItem = (F9PronItem) getIntent().getSerializableExtra(Keys.KEY_INTENT_BROWSE_FORUM_9PORN_ITEM);
    presenter.loadContent(f9PronItem.getTid());
    historyIdStack.push(f9PronItem.getTid());
    imageList = new ArrayList<>();
    boolean needShowTip = presenter.isNeedShowTipFirstViewForum9Content();
    if (needShowTip) {
        showTipDialog();
    }

    fabFunction.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showOpenNewForum();
        }
    });
}
 
Example 14
Source File: WebView.java    From unity-ads-android with Apache License 2.0 4 votes vote down vote up
public WebView(Context context) {
	super(context);
	WebSettings settings = getSettings();

	if(Build.VERSION.SDK_INT >= 16) {
		settings.setAllowFileAccessFromFileURLs(true);
		settings.setAllowUniversalAccessFromFileURLs(true);
	}

	if (Build.VERSION.SDK_INT >= 19) {
		try {
			_evaluateJavascript = android.webkit.WebView.class.getMethod("evaluateJavascript", String.class, ValueCallback.class);
		} catch(NoSuchMethodException e) {
			DeviceLog.exception("Method evaluateJavascript not found", e);
			_evaluateJavascript = null;
		}
	}

	settings.setAppCacheEnabled(false);
	settings.setBlockNetworkImage(false);
	settings.setBlockNetworkLoads(false);
	settings.setBuiltInZoomControls(false);
	settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
	settings.setDatabaseEnabled(false);

	if(Build.VERSION.SDK_INT >= 11) {
		settings.setDisplayZoomControls(false);
	}

	settings.setDomStorageEnabled(false);

	if(Build.VERSION.SDK_INT >= 11) {
		settings.setEnableSmoothTransition(false);
	}

	settings.setGeolocationEnabled(false);
	settings.setJavaScriptCanOpenWindowsAutomatically(false);
	settings.setJavaScriptEnabled(true);
	settings.setLightTouchEnabled(false);
	settings.setLoadWithOverviewMode(false);
	settings.setLoadsImagesAutomatically(true);

	if(Build.VERSION.SDK_INT >= 17) {
		settings.setMediaPlaybackRequiresUserGesture(false);
	}

	if(Build.VERSION.SDK_INT >= 21) {
		settings.setMixedContentMode(WebSettings.MIXED_CONTENT_NEVER_ALLOW);
	}

	settings.setNeedInitialFocus(true);
	settings.setPluginState(WebSettings.PluginState.OFF);
	settings.setRenderPriority(WebSettings.RenderPriority.NORMAL);
	settings.setSaveFormData(false);
	settings.setSavePassword(false);
	settings.setSupportMultipleWindows(false);
	settings.setSupportZoom(false);
	settings.setUseWideViewPort(true);

	setHorizontalScrollBarEnabled(false);
	setVerticalScrollBarEnabled(false);
	setInitialScale(0);
	setBackgroundColor(Color.TRANSPARENT);
	ViewUtilities.setBackground(this, new ColorDrawable(Color.TRANSPARENT));
	setBackgroundResource(0);

	addJavascriptInterface(new WebViewBridgeInterface(), "webviewbridge");
}
 
Example 15
Source File: MainActivity.java    From styT with Apache License 2.0 4 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
private void initWebSettings() {

    WebSettings settings = sMm.getSettings();
    settings.setUserAgentString("" + SPUtils.get(MainActivity.this, "if_7", ""));//UA
    //支持获取手势焦点
    sMm.requestFocusFromTouch();
    //支持JS
    settings.setJavaScriptEnabled((Boolean) SPUtils.get(MainActivity.this, "if_1", true));
    //支持插件

    // settings.setPluginState(WebSettings.PluginState.ON);
    //设置适应屏幕
    settings.setUseWideViewPort(true);
    settings.setLoadWithOverviewMode(true);
    //支持缩放
    settings.setSupportZoom((Boolean) SPUtils.get(MainActivity.this, "if_3", false)); // 支持缩放
    //隐藏原生的缩放控件
    settings.setDisplayZoomControls(false);
    //支持内容重新布局
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    settings.supportMultipleWindows();
    settings.setSupportMultipleWindows(false);
    //设置缓存模式
    settings.setGeolocationEnabled((Boolean) SPUtils.get(MainActivity.this, "if_2", true));//允许地理位置可用
    settings.setDomStorageEnabled(true);
    settings.setDatabaseEnabled((Boolean) SPUtils.get(MainActivity.this, "if_4", true));
    settings.setCacheMode(WebSettings.LOAD_DEFAULT);
    settings.setAppCacheEnabled(true);
    settings.setAppCachePath(sMm.getContext().getCacheDir().getAbsolutePath());
    //settings.setRenderPriority(WebSettings.RenderPriority.HIGH);  //提高渲染的优先级
    //设置可访问文件
    settings.setAllowFileAccess(true);
    //当webview调用requestFocus时为webview设置节点
    settings.setNeedInitialFocus(true);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
    }

    settings.setLoadsImagesAutomatically(false);

    // settings.setNeedInitialFocus(true);
    //设置编码格式
    //settings.setDefaultTextEncodingName("UTF-8");

}
 
Example 16
Source File: WebViewActivity.java    From CloudReader with Apache License 2.0 4 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
    private void initWebView() {
        WebSettings ws = webView.getSettings();
        // 网页内容的宽度适配
        ws.setLoadWithOverviewMode(true);
        ws.setUseWideViewPort(true);
        // 保存表单数据
        ws.setSaveFormData(true);
        // 是否应该支持使用其屏幕缩放控件和手势缩放
        ws.setSupportZoom(true);
        ws.setBuiltInZoomControls(true);
        ws.setDisplayZoomControls(false);
        // 启动应用缓存
        ws.setAppCacheEnabled(true);
        // 设置缓存模式
        ws.setCacheMode(WebSettings.LOAD_DEFAULT);
        // 告诉WebView启用JavaScript执行。默认的是false。
        ws.setJavaScriptEnabled(true);
        //  页面加载好以后,再放开图片
        ws.setBlockNetworkImage(false);
        // 使用localStorage则必须打开
        ws.setDomStorageEnabled(true);
        // 排版适应屏幕
        ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        // WebView是否新窗口打开(加了后可能打不开网页)
//        ws.setSupportMultipleWindows(true);

        // webview从5.0开始默认不允许混合模式,https中不能加载http资源,需要设置开启。
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            ws.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
        }
        /** 设置字体默认缩放大小(改变网页字体大小,setTextSize  api14被弃用)*/
        ws.setTextZoom(100);

        mWebChromeClient = new MyWebChromeClient(this);
        webView.setWebChromeClient(mWebChromeClient);
        // 与js交互
        webView.addJavascriptInterface(new ImageClickInterface(this), "injectedObject");
        webView.setWebViewClient(new MyWebViewClient(this));
        webView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                return handleLongImage();
            }
        });
    }
 
Example 17
Source File: ArticleDetailActivity.java    From Awesome-WanAndroid with Apache License 2.0 4 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void initEventAndData() {
    mAgentWeb = AgentWeb.with(this)
            .setAgentWebParent(mWebContent, new LinearLayout.LayoutParams(-1, -1))
            .useDefaultIndicator()
            .setMainFrameErrorView(R.layout.webview_error_view, -1)
            .createAgentWeb()
            .ready()
            .go(articleLink);

    WebView mWebView = mAgentWeb.getWebCreator().getWebView();
    WebSettings mSettings = mWebView.getSettings();
    if (mPresenter.getNoImageState()) {
        mSettings.setBlockNetworkImage(true);
    } else {
        mSettings.setBlockNetworkImage(false);
    }
    if (mPresenter.getAutoCacheState()) {
        mSettings.setAppCacheEnabled(true);
        mSettings.setDomStorageEnabled(true);
        mSettings.setDatabaseEnabled(true);
        if (CommonUtils.isNetworkConnected()) {
            mSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
        } else {
            mSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
        }
    } else {
        mSettings.setAppCacheEnabled(false);
        mSettings.setDomStorageEnabled(false);
        mSettings.setDatabaseEnabled(false);
        mSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    }

    mSettings.setJavaScriptEnabled(true);
    mSettings.setSupportZoom(true);
    mSettings.setBuiltInZoomControls(true);
    //不显示缩放按钮
    mSettings.setDisplayZoomControls(false);
    //设置自适应屏幕,两者合用
    //将图片调整到适合WebView的大小
    mSettings.setUseWideViewPort(true);
    //缩放至屏幕的大小
    mSettings.setLoadWithOverviewMode(true);
    //自适应屏幕
    mSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
}
 
Example 18
Source File: SystemWebViewEngine.java    From lona with GNU General Public License v3.0 4 votes vote down vote up
@SuppressLint({"NewApi", "SetJavaScriptEnabled"})
@SuppressWarnings("deprecation")
private void initWebViewSettings() {
    webView.setInitialScale(0);
    webView.setVerticalScrollBarEnabled(false);
    // Enable JavaScript
    final WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);

    String manufacturer = android.os.Build.MANUFACTURER;
    LOG.d(TAG, "CordovaWebView is running on device made by: " + manufacturer);

    //We don't save any form data in the application
    settings.setSaveFormData(false);
    settings.setSavePassword(false);

    // Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist
    // while we do this
    settings.setAllowUniversalAccessFromFileURLs(true);
    settings.setMediaPlaybackRequiresUserGesture(false);

    // Enable database
    // We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16
    String databasePath = webView.getContext().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setDatabaseEnabled(true);
    settings.setDatabasePath(databasePath);


    //Determine whether we're in debug or release mode, and turn on Debugging!
    ApplicationInfo appInfo = webView.getContext().getApplicationContext().getApplicationInfo();
    if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
        enableRemoteDebugging();
    }

    settings.setGeolocationDatabasePath(databasePath);

    // Enable DOM storage
    settings.setDomStorageEnabled(true);

    // Enable built-in geolocation
    settings.setGeolocationEnabled(true);

    // Enable AppCache
    // Fix for CB-2282
    settings.setAppCacheMaxSize(5 * 1048576);
    settings.setAppCachePath(databasePath);
    settings.setAppCacheEnabled(true);

    // Fix for CB-1405
    // Google issue 4641
    String defaultUserAgent = settings.getUserAgentString();

    // Fix for CB-3360
    String overrideUserAgent = preferences.getString("OverrideUserAgent", null);
    if (overrideUserAgent != null) {
        settings.setUserAgentString(overrideUserAgent);
    } else {
        String appendUserAgent = preferences.getString("AppendUserAgent", null);
        if (appendUserAgent != null) {
            settings.setUserAgentString(defaultUserAgent + " " + appendUserAgent);
        }
    }
    // End CB-3360

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                settings.getUserAgentString();
            }
        };
        webView.getContext().registerReceiver(this.receiver, intentFilter);
    }
    // end CB-1405
}
 
Example 19
Source File: BaseWebViewLoadActivity.java    From YiZhi with Apache License 2.0 4 votes vote down vote up
/**
 * 初始化WebSetting
 *
 * @param settings WebSetting
 */
protected void initWebSetting(WebSettings settings) {
    // 缩放至屏幕的大小
    settings.setLoadWithOverviewMode(true);
    // 保存表单数据
    settings.setSaveFormData(true);
    // 是否应该支持使用其屏幕缩放控件和手势缩放
    settings.setSupportZoom(true);
    //        //是否支持手势缩放控制
    //        settings.setBuiltInZoomControls(true);
    //        是否隐藏原生的缩放控件
    //        settings.setDisplayZoomControls(false);
    // 启动应用缓存
    settings.setAppCacheEnabled(true);
    // 排版适应屏幕,只显示一列
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    //        settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    //  页面加载好以后,再放开图片
    settings.setBlockNetworkImage(false);
    // 使用localStorage则必须打开
    settings.setDomStorageEnabled(true);
    settings.setDatabaseEnabled(true);
    // WebView启用JavaScript执行。默认的是false。
    settings.setJavaScriptEnabled(true); // 设置支持javascript脚本
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    if (NetworkConnectionUtils.isConnected(mContext)) {
        settings.setCacheMode(WebSettings.LOAD_DEFAULT);
    } else {
        settings.setCacheMode(WebSettings.LOAD_CACHE_ONLY);
    }

    //        settings.setBlockNetworkImage(false);
    //        settings.setAppCacheEnabled(true);
    //        settings.setDomStorageEnabled(true);
    //        settings.setDatabaseEnabled(true);
    //        if (NetworkConnectionUtils.isConnected(mContext)) {
    //            settings.setCacheMode(WebSettings.LOAD_DEFAULT);
    //        } else {
    //            settings.setCacheMode(WebSettings.LOAD_CACHE_ONLY);
    //        }
    //        settings.setJavaScriptEnabled(true);
    //        settings.setLoadWithOverviewMode(true);
    //        settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    //        settings.setSupportZoom(true);
}
 
Example 20
Source File: WebPlayerView.java    From unity-ads-android with Apache License 2.0 4 votes vote down vote up
public WebPlayerView(Context context, String viewId, JSONObject webSettings, JSONObject webPlayerSettings) {
	super(context);

	this.viewId = viewId;

	WebSettings settings = getSettings();

	if(Build.VERSION.SDK_INT >= 16) {
		settings.setAllowFileAccessFromFileURLs(false);
		settings.setAllowUniversalAccessFromFileURLs(false);
	}
	if (Build.VERSION.SDK_INT >= 19) {
		try {
			_evaluateJavascript = WebView.class.getMethod("evaluateJavascript", String.class, ValueCallback.class);
		} catch(NoSuchMethodException e) {
			DeviceLog.exception("Method evaluateJavascript not found", e);
			_evaluateJavascript = null;
		}
	}

	settings.setAppCacheEnabled(false);
	settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
	settings.setDatabaseEnabled(false);

	settings.setDomStorageEnabled(false);
	settings.setGeolocationEnabled(false);
	settings.setJavaScriptEnabled(true);
	settings.setLoadsImagesAutomatically(true);

	settings.setPluginState(WebSettings.PluginState.OFF);
	settings.setRenderPriority(WebSettings.RenderPriority.NORMAL);
	settings.setSaveFormData(false);
	settings.setSavePassword(false);

	setHorizontalScrollBarEnabled(false);
	setVerticalScrollBarEnabled(false);
	setInitialScale(0);
	setBackgroundColor(Color.TRANSPARENT);
	ViewUtilities.setBackground(this, new ColorDrawable(Color.TRANSPARENT));
	setBackgroundResource(0);

	setSettings(webSettings, webPlayerSettings);

	setWebViewClient(new WebPlayerClient());
	setWebChromeClient(new WebPlayerChromeClient());
	setDownloadListener(new WebPlayerDownloadListener());

	addJavascriptInterface(new WebPlayerBridgeInterface(viewId), "webplayerbridge");

	WebPlayerViewCache.getInstance().addWebPlayer(viewId, this);

	this.subscribeOnLayoutChange();
}