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

The following examples show how to use android.webkit.WebSettings#setCacheMode() . 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: WebActivity.java    From Android-Plugin-Framework with MIT License 6 votes vote down vote up
private void setUpWebViewSetting() {
	WebSettings webSettings = web.getSettings();

	webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);// 根据cache-control决定是否从网络上取数据
	webSettings.setSupportZoom(true);
	webSettings.setBuiltInZoomControls(true);// 显示放大缩小
	webSettings.setJavaScriptEnabled(true);
	// webSettings.setPluginsEnabled(true);
	webSettings.setPluginState(WebSettings.PluginState.ON);
	webSettings.setUserAgentString(webSettings.getUserAgentString());
	webSettings.setDomStorageEnabled(true);
	webSettings.setAppCacheEnabled(true);
	webSettings.setAppCachePath(getCacheDir().getPath());
	webSettings.setUseWideViewPort(true);// 影响默认满屏和双击缩放
	webSettings.setLoadWithOverviewMode(true);// 影响默认满屏和手势缩放

}
 
Example 2
Source File: LoveVideoView.java    From Gank.io with GNU General Public License v3.0 6 votes vote down vote up
void init() {
  setWebViewClient(new LoveClient());
  WebSettings webSettings = getSettings();
  webSettings.setJavaScriptEnabled(true);
  webSettings.setAllowFileAccess(true);
  webSettings.setDatabaseEnabled(true);
  webSettings.setDomStorageEnabled(true);
  webSettings.setSaveFormData(false);
  webSettings.setAppCacheEnabled(true);
  webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
  webSettings.setLoadWithOverviewMode(false);
  webSettings.setUseWideViewPort(true);

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    if (BuildConfig.DEBUG) {
      WebView.setWebContentsDebuggingEnabled(true);
    }
  }
}
 
Example 3
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 4
Source File: WebActivity.java    From Musicoco with Apache License 2.0 6 votes vote down vote up
private void initWebView() {
        WebSettings webSettings = webView.getSettings();
//        webSettings.setJavaScriptEnabled(true);

        webSettings.setUseWideViewPort(true); //将图片调整到适合webview的大小
        webSettings.setLoadWithOverviewMode(true); // 缩放至屏幕的大小

        webSettings.setSupportZoom(true); //支持缩放,默认为true。是下面那个的前提。
        webSettings.setBuiltInZoomControls(true); //设置内置的缩放控件。若为false,则该WebView不可缩放
        webSettings.setDisplayZoomControls(false); //隐藏原生的缩放控件

        webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); //关闭webview中缓存
        webSettings.setAllowFileAccess(true); //设置可以访问文件
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true); //支持通过JS打开新窗口
        webSettings.setLoadsImagesAutomatically(true); //支持自动加载图片
        webSettings.setDefaultTextEncodingName("utf-8");//设置编码格式

    }
 
Example 5
Source File: WebViewHelper.java    From AndroidReview with GNU General Public License v3.0 6 votes vote down vote up
public static void initWebViewSettings(WebView webView) {
    WebSettings settings = webView.getSettings();
    //这个单位是SP
    settings.setDefaultFontSize(15);

    settings.setJavaScriptEnabled(true);  //支持js

    settings.setUseWideViewPort(false);  //将图片调整到适合webview的大小

    settings.setSupportZoom(true);  //支持缩放

    settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);//无论是否有网络,只要本地有缓存,都使用缓存。本地没有缓存时才从网络上获取。 这里的WebView主要是用来加载图片和解析Html文本

    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); //支持内容重新布局

    webView.setWebViewClient(new WebViewClient(){
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            //使超链接失效
            return true;
        }
    });

}
 
Example 6
Source File: JSAutoLogin.java    From iBeebo with GNU General Public License v3.0 6 votes vote down vote up
public JSAutoLogin(Context context, AccountBean ab) {

        this.mContext = context;
        this.mAccountBean = ab;

        this.mWebView = new WebView(mContext);
        mWeiboWebViewClient = new WeiboWebViewClient();
        mWebView.setWebViewClient(mWeiboWebViewClient);

        mInjectJS = new InjectJS(mWebView);

        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setBuiltInZoomControls(true);
        webSettings.setSaveFormData(true);
        webSettings.setSupportZoom(true);
        webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    }
 
Example 7
Source File: JSAutoLogin.java    From iBeebo with GNU General Public License v3.0 6 votes vote down vote up
public JSAutoLogin(Context context, AccountBean ab) {

        this.mContext = context;
        this.mAccountBean = ab;

        this.mWebView = new WebView(mContext);
        mWeiboWebViewClient = new WeiboWebViewClient();
        mWebView.setWebViewClient(mWeiboWebViewClient);

        mInjectJS = new InjectJS(mWebView);

        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setBuiltInZoomControls(true);
        webSettings.setSaveFormData(true);
        webSettings.setSupportZoom(true);
        webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    }
 
Example 8
Source File: WebActivity.java    From MD with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_web);
    ButterKnife.inject(this);

    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            finish();
        }
    });
    String url = getIntent().getStringExtra("url");
    WebSettings webSettings = webView.getSettings();
    webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
    webView.loadUrl(url);
    webView.setOnKeyListener(new View.OnKeyListener() { // webview can
        // go back
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack()) {
                webView.goBack();
                return true;
            }
            return false;
        }
    });
}
 
Example 9
Source File: WebActivity.java    From JustDraw with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTitle(R.string.title_web);
    setContentView(R.layout.activity_web);

    mWebView = (WebView)findViewById(R.id.webview);
    mTvMsg = (TextView) findViewById(R.id.tv_msg);

    WebSettings webSettings = mWebView.getSettings();
    // 开启Javascript脚本
    webSettings.setJavaScriptEnabled(true);
    webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);

    WebViewClient wc = new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            mTvMsg.setText(
                    String.format(
                            getResources().getString(R.string.format_time),
                            System.currentTimeMillis() - time + ""));
        }
    };
    mWebView.setWebViewClient(wc);

    int count = getIntent().getIntExtra("count", 1000);
    html = FileUtil.getFromAssets(this, "just/index.html");
    html = html.replace("$count$", count + "");
    draw(null);
}
 
Example 10
Source File: CodeWebView.java    From OpenHub with GNU General Public License v3.0 5 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
private void init(AttributeSet attrs) {
    if (attrs != null) {
        TypedArray tp = getContext().obtainStyledAttributes(attrs, R.styleable.CodeWebView);
        try {
            backgroundColor = tp.getColor(R.styleable.CodeWebView_webview_background,
                    ViewUtils.getWindowBackground(getContext()));
            setBackgroundColor(backgroundColor);
        } finally {
            tp.recycle();
        }
    }

    setWebChromeClient(new ChromeClient());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        setWebViewClient(new WebClientN());
    } else {
        setWebViewClient(new WebClient());
    }
    WebSettings settings = getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setAppCachePath(getContext().getCacheDir().getPath());
    settings.setAppCacheEnabled(true);
    settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    settings.setDefaultTextEncodingName("utf-8");
    boolean isLoadImageEnable = PrefUtils.isLoadImageEnable();
    settings.setLoadsImagesAutomatically(isLoadImageEnable);
    settings.setBlockNetworkImage(!isLoadImageEnable);
    setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            WebView.HitTestResult result = getHitTestResult();
            if (hitLinkResult(result) && !StringUtils.isBlank(result.getExtra())) {
                AppUtils.copyToClipboard(getContext(), result.getExtra());
                return true;
            }
            return false;
        }
    });
}
 
Example 11
Source File: BaseWebView.java    From dcs-sdk-java with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
private void init(Context context) {
    this.setVerticalScrollBarEnabled(false);
    this.setHorizontalScrollBarEnabled(false);
    if (Build.VERSION.SDK_INT < 19) {
        removeJavascriptInterface("searchBoxJavaBridge_");
    }

    WebSettings localWebSettings = this.getSettings();
    try {
        // 禁用file协议,http://www.tuicool.com/articles/Q36ZfuF, 防止Android WebView File域攻击
        localWebSettings.setAllowFileAccess(false);
        localWebSettings.setSupportZoom(false);
        localWebSettings.setBuiltInZoomControls(false);
        localWebSettings.setUseWideViewPort(true);
        localWebSettings.setDomStorageEnabled(true);
        localWebSettings.setLoadWithOverviewMode(true);
        localWebSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
        localWebSettings.setPluginState(PluginState.ON);
        // 启用数据库
        localWebSettings.setDatabaseEnabled(true);
        // 设置定位的数据库路径
        String dir = context.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
        localWebSettings.setGeolocationDatabasePath(dir);
        localWebSettings.setGeolocationEnabled(true);
        localWebSettings.setJavaScriptEnabled(true);
        localWebSettings.setSavePassword(false);
        String agent = localWebSettings.getUserAgentString();

        localWebSettings.setUserAgentString(agent);
        // setCookie(context, ".baidu.com", bdussCookie);

    } catch (Exception e1) {
        e1.printStackTrace();
    }
    this.setWebViewClient(new BridgeWebViewClient());
}
 
Example 12
Source File: FragmentWebView.java    From rss with GNU General Public License v3.0 5 votes vote down vote up
@Override
public
View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
    WebView view = (WebView) super.onCreateView(inflater, container, savedInstanceState);

    // Configure the WebView.
    WebSettings settings = view.getSettings();
    settings.setBuiltInZoomControls(true);
    settings.setDisplayZoomControls(false);
    settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);

    return view;
}
 
Example 13
Source File: HelpActivity.java    From CatVision-io-SDK-Android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_help);
	Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
	setSupportActionBar(toolbar);

	try {
		getSupportActionBar().setDisplayHomeAsUpEnabled(true);
		getSupportActionBar().setDisplayShowHomeEnabled(true);
	} catch (NullPointerException e) {
		e.printStackTrace();
	}

	// Web view
	WebView webView = (WebView)findViewById(R.id.mainWebView);
	WebSettings webSettings = webView.getSettings();
	webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
	// other
	webSettings.setJavaScriptEnabled(true);
	webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
	webSettings.setAllowFileAccessFromFileURLs(true);
	webSettings.setAllowUniversalAccessFromFileURLs(true);
	// important!
	webView.setWebViewClient(new WebViewClient());
	webView.loadUrl("file:///android_asset/help/index.html");
}
 
Example 14
Source File: WebViewActivity.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private void initWebView() {
    mWebView.setWebViewClient(new WebViewClient());
    mWebView.setWebChromeClient(new WebChromeClient());
    WebSettings settings = mWebView.getSettings();
    settings.setSavePassword(true);
    settings.setSaveFormData(true);
    settings.setJavaScriptEnabled(true);
    settings.setSupportZoom(false);
    settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    settings.setDomStorageEnabled(true);
    settings.setSupportMultipleWindows(false);


    mWebView.loadUrl("http://developer.android.com");
}
 
Example 15
Source File: WebViewActivity.java    From NetEasyNews with GNU General Public License v3.0 4 votes vote down vote up
private void initWebView() {
    mProgressBar.setVisibility(View.VISIBLE);
    WebSettings ws = webView.getSettings();
    // 网页内容的宽度是否可大于WebView控件的宽度
    ws.setLoadWithOverviewMode(false);
    // 保存表单数据
    ws.setSaveFormData(true);
    // 是否应该支持使用其屏幕缩放控件和手势缩放
    ws.setSupportZoom(true);
    ws.setBuiltInZoomControls(true);
    ws.setDisplayZoomControls(false);
    // 启动应用缓存
    ws.setAppCacheEnabled(true);
    // 设置缓存模式
    ws.setCacheMode(WebSettings.LOAD_DEFAULT);
    // setDefaultZoom  api19被弃用
    // 设置此属性,可任意比例缩放。
    ws.setUseWideViewPort(true);
    // 缩放比例 1
    webView.setInitialScale(1);
    // 告诉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));
}
 
Example 16
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 17
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 18
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 19
Source File: OAuthActivity.java    From iBeebo with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.oauth_activity_layout);

    this.mIsAuthPro = getIntent().getBooleanExtra(Ext.KEY_IS_HACK, false);
    this.mAccountBean = getIntent().getParcelableExtra(Ext.KEY_ACCOUNT);

    Toolbar mToolbar = ViewUtility.findViewById(this, R.id.oauthToolbar);

    setSupportActionBar(mToolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mToolbar.setNavigationOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
        }
    });

    getSupportActionBar().setTitle(mIsAuthPro ? R.string.oauth_senior_title : R.string.oauth_normal_title);

    mWebView = (WebView) findViewById(R.id.webView);
    mInjectJS = new InjectJS(mWebView);

    mWebView.setWebViewClient(new WeiboWebViewClient());

    mCircleProgressBar = (CircleProgressBar) findViewById(R.id.oauthProgress);

    WebSettings settings = mWebView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setSaveFormData(true);
    settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    settings.setRenderPriority(WebSettings.RenderPriority.HIGH);

    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();

    refresh();
}
 
Example 20
Source File: WebViewActivity.java    From DeviceConnect-Android with MIT License 4 votes vote down vote up
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_web_view);

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    Intent intent = getIntent();
    if (intent == null) {
        finish();
        return;
    }

    String url = intent.getStringExtra(EXTRA_URL);
    if (url == null) {
        finish();
        return;
    }

    String title = intent.getStringExtra(EXTRA_TITLE);
    if (title != null) {
        setTitle(title);
    }

    boolean ssl = intent.getBooleanExtra(EXTRA_SSL, false);
    mSSL = ssl ? SSL_ON : SSL_OFF;

    mWebView = (WebView) findViewById(R.id.activity_web_view);
    if (mWebView != null) {
        mWebView.setWebViewClient(mWebViewClient);
        mWebView.setWebChromeClient(mChromeClient);
        mWebView.setVerticalScrollBarEnabled(false);
        mWebView.setHorizontalScrollBarEnabled(false);
        mWebView.addJavascriptInterface(new JavaScriptInterface(), "Android");

        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setUseWideViewPort(true);
        webSettings.setLoadWithOverviewMode(true);
        webSettings.setDomStorageEnabled(true);
        webSettings.setDatabaseEnabled(true);
        webSettings.setAllowFileAccess(true);
        webSettings.setAppCacheEnabled(false);
        webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);

        // Android 4.0以上では、chromeからデバッグするための機能が存在する
        // ここでは、DEBUGビルドの場合のみ使えるように設定している。
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            if (DEBUG) {
                if (0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)) {
                    WebView.setWebContentsDebuggingEnabled(true);
                }
            }
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            webSettings.setAllowFileAccessFromFileURLs(true);
            webSettings.setAllowUniversalAccessFromFileURLs(true);
        }

        loadUrl(mWebView, url);
    }
}