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

The following examples show how to use android.webkit.WebSettings#setBuiltInZoomControls() . 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: VisualLinearActivity.java    From ans-android-sdk with GNU General Public License v3.0 6 votes vote down vote up
private void initWebView() {
    WebView webView = (WebView) findViewById(R.id.webView);
    webView.loadUrl("https://www.analysys.cn");
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    webSettings.setAllowContentAccess(true);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setUseWideViewPort(true);
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setSupportZoom(true);
    webSettings.setBuiltInZoomControls(true);
    webView.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view,
                                                String url) { //
            // 重写此方法表明点击网页里面的链接还是在当前的webview里跳转,不跳到浏览器那边
            view.loadUrl(url);
            return true;
        }
    });
}
 
Example 2
Source File: TestActivity.java    From ans-android-sdk with GNU General Public License v3.0 6 votes vote down vote up
private void initWebView() {
    WebView webView = (WebView) findViewById(R.id.test_activity_webView);
    webView.loadUrl("https://www.analysys.cn");
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    webSettings.setAllowContentAccess(true);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setUseWideViewPort(true);
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setSupportZoom(true);
    webSettings.setBuiltInZoomControls(true);
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view,
                                                String url) { //
            // 重写此方法表明点击网页里面的链接还是在当前的webview里跳转,不跳到浏览器那边
            view.loadUrl(url);
            return true;
        }
    });
}
 
Example 3
Source File: MainFragment.java    From chromium-webview-samples with Apache License 2.0 6 votes vote down vote up
/**
 * Convenience method to set some generic defaults for a
 * given WebView
 *
 * @param webView
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setUpWebViewDefaults(WebView webView) {
    WebSettings settings = webView.getSettings();

    // Enable Javascript
    settings.setJavaScriptEnabled(true);

    // Use WideViewport and Zoom out if there is no viewport defined
    settings.setUseWideViewPort(true);
    settings.setLoadWithOverviewMode(true);

    // Enable pinch to zoom without the zoom buttons
    settings.setBuiltInZoomControls(true);

    if(Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
        // Hide the zoom controls for HONEYCOMB+
        settings.setDisplayZoomControls(false);
    }

    // Enable remote debugging via chrome://inspect
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        WebView.setWebContentsDebuggingEnabled(true);
    }
}
 
Example 4
Source File: HelpActivity.java    From PressureNet with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.help);

	ActionBar bar = getActionBar();
	int actionBarTitleId = getResources().getSystem().getIdentifier(
			"action_bar_title", "id", "android");

	TextView actionBarTextView = (TextView) findViewById(actionBarTitleId);
	actionBarTextView.setTextColor(Color.WHITE);

	ImageView view = (ImageView) findViewById(android.R.id.home);
	view.setPadding(8, 0, 0, 0);

	webHelp = (WebView) findViewById(R.id.webViewHelp);
	WebView pndvWebView = (WebView) findViewById(R.id.webViewHelp);
	WebSettings webSettings = pndvWebView.getSettings();
	webSettings.setJavaScriptEnabled(true);
	webSettings.setBuiltInZoomControls(true);
	webHelp.loadUrl("http://www.cumulonimbus.ca/pressurenet-help/");

}
 
Example 5
Source File: WebViewFragment.java    From Xndroid with GNU General Public License v3.0 6 votes vote down vote up
private void setWebView()
{

    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);//如果访问的页面中要与Javascript交互,则webview必须设置支持Javascript
    webSettings.setUseWideViewPort(true); //将图片调整到适合webview的大小
    webSettings.setLoadWithOverviewMode(true); // 缩放至屏幕的大小
    webSettings.setSupportZoom(true); //支持缩放,默认为true。是下面那个的前提。
    webSettings.setBuiltInZoomControls(true); //设置内置的缩放控件。若为false,则该WebView不可缩放
    webSettings.setDisplayZoomControls(false); //隐藏原生的缩放控件
    webSettings.setAllowFileAccess(true); //设置可以访问文件
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true); //支持通过JS打开新窗口
    webSettings.setLoadsImagesAutomatically(true); //支持自动加载图片
    webSettings.setDefaultTextEncodingName("utf-8");//设置编码格式
    webSettings.setDomStorageEnabled(true);
    mWebView.setWebViewClient(new WebViewClient());
}
 
Example 6
Source File: WebViewActivity.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);
    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 7
Source File: APIFragment.java    From XFrame with Apache License 2.0 6 votes vote down vote up
@Override
public void initView() {
    webView = (WebView) getView().findViewById(R.id.webview);
    webView.loadUrl("https://github.com/youth5201314/XFrame/wiki");
    WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setUseWideViewPort(true);
    settings.setBuiltInZoomControls(true);
    settings.setDisplayZoomControls(false);
    settings.setUseWideViewPort(true);
    settings.setLoadWithOverviewMode(true);
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    });
}
 
Example 8
Source File: WebViewActivity.java    From AndroidSamples with Apache License 2.0 6 votes vote down vote up
private void initWeb() {
    WebSettings webSettings = mWebView.getSettings();

    // 启用js
    webSettings.setJavaScriptEnabled(true);
    // 禁止缩放
    webSettings.setBuiltInZoomControls(false);
    webSettings.setSupportZoom(false);
    //不显示webview缩放按钮
    webSettings.setDisplayZoomControls(false);

    // WebView 背景透明效果
    // webview.setBackgroundColor(Color.TRANSPARENT);
    mWebView.addJavascriptInterface(new JsInteration(), "app");
    mWebView.loadUrl("file:///android_asset/html/webtest.html");
}
 
Example 9
Source File: PKDialog.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
private void d()
{
    n.setVerticalScrollBarEnabled(false);
    n.setHorizontalScrollBarEnabled(false);
    n.setWebViewClient(new e(this, null));
    n.setWebChromeClient(mChromeClient);
    n.clearFormData();
    WebSettings websettings = n.getSettings();
    websettings.setSavePassword(false);
    websettings.setSaveFormData(false);
    websettings.setCacheMode(-1);
    websettings.setNeedInitialFocus(false);
    websettings.setBuiltInZoomControls(true);
    websettings.setSupportZoom(true);
    websettings.setRenderPriority(android.webkit.WebSettings.RenderPriority.HIGH);
    websettings.setJavaScriptEnabled(true);
    if (o != null && o.get() != null)
    {
        websettings.setDatabaseEnabled(true);
        websettings.setDatabasePath(((Context)o.get()).getApplicationContext().getDir("databases", 0).getPath());
    }
    websettings.setDomStorageEnabled(true);
    jsBridge.a(new f(this, null), "sdk_js_if");
    n.clearView();
    n.loadUrl(i);
    n.getSettings().setSavePassword(false);
}
 
Example 10
Source File: HTML5WebView.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
private void init(Context context) {
	mContext = context;		
	Activity a = (Activity) mContext;
	
	mLayout = new FrameLayout(context);
	
	mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(a).inflate(R.layout.custom_screen, null);
	mContentView = (FrameLayout) mBrowserFrameLayout.findViewById(R.id.main_content);
	mCustomViewContainer = (FrameLayout) mBrowserFrameLayout.findViewById(R.id.fullscreen_custom_content);
	
	mLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS);

	mWebChromeClient = new MyWebChromeClient();
    setWebChromeClient(mWebChromeClient);
    
    setWebViewClient(new MyWebViewClient());
       
    // Configure the webview
    WebSettings s = getSettings();
    s.setBuiltInZoomControls(true);
    s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    s.setUseWideViewPort(true);
    s.setLoadWithOverviewMode(true);
    s.setSavePassword(true);
    s.setSaveFormData(true);
    s.setJavaScriptEnabled(true);
    
    // enable navigator.geolocation 
    s.setGeolocationEnabled(true);
    s.setGeolocationDatabasePath("/data/data/org.itri.html5webview/databases/");
    
    // enable Web Storage: localStorage, sessionStorage
    s.setDomStorageEnabled(true);
    
    mContentView.addView(this);
}
 
Example 11
Source File: MainActivity.java    From chromium-webview-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Convenience method to set some generic defaults for a
 * given WebView
 *
 * @param webView
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setUpWebViewDefaults(WebView webView) {
    WebSettings settings = webView.getSettings();

    // Enable Javascript
    settings.setJavaScriptEnabled(true);

    // Use WideViewport and Zoom out if there is no viewport defined
    settings.setUseWideViewPort(true);
    settings.setLoadWithOverviewMode(true);

    // Enable pinch to zoom without the zoom buttons
    settings.setBuiltInZoomControls(true);

    // Allow use of Local Storage
    settings.setDomStorageEnabled(true);

    if(Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
        // Hide the zoom controls for HONEYCOMB+
        settings.setDisplayZoomControls(false);
    }

    // Enable remote debugging via chrome://inspect
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        WebView.setWebContentsDebuggingEnabled(true);
    }

    webView.setWebViewClient(new WebViewClient());
}
 
Example 12
Source File: PrettifyWebView.java    From mvvm-template with GNU General Public License v3.0 5 votes vote down vote up
public void setSource(@NonNull String source, boolean wrap) {
    if (!InputHelper.isEmpty(source)) {
        WebSettings settings = getSettings();
        settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING);
        setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
        settings.setSupportZoom(!wrap);
        settings.setBuiltInZoomControls(!wrap);
        if (!wrap) settings.setDisplayZoomControls(false);
        String page = PrettifyHelper.generateContent(source, AppHelper.isNightMode(getResources()), wrap);
        loadCode(page);
    }
}
 
Example 13
Source File: CodeWebView.java    From OpenHub with GNU General Public License v3.0 5 votes vote down vote up
public void setDiffFileSource(@NonNull String source, boolean wrap) {
    if (StringUtils.isBlank(source)) return;
    WebSettings settings = getSettings();
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING);
    setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    settings.setSupportZoom(true);
    settings.setBuiltInZoomControls(true);
    settings.setDisplayZoomControls(false);
    String page = HtmlHelper.generateDiffHtml(source, AppUtils.isNightMode(),
            getCodeBackgroundColor(), wrap);
    loadPage(page);
}
 
Example 14
Source File: WebViewActivity.java    From YCAudioPlayer with Apache License 2.0 4 votes vote down vote up
@SuppressLint("JavascriptInterface")
private void initWebView() {
    WebSettings ws = mWebView.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
    mWebView.setInitialScale(1);
    // 告诉WebView启用JavaScript执行。默认的是false。
    ws.setJavaScriptEnabled(true);
    //如果启用了JavaScript,要做好安全措施,防止远程执行漏洞
    removeJavascriptInterfaces(mWebView);
    //  页面加载好以后,再放开图片
    ws.setBlockNetworkImage(false);
    // 使用localStorage则必须打开
    ws.setDomStorageEnabled(true);
    //自动加载图片
    ws.setLoadsImagesAutomatically(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);
    //在js中调用本地java方法
    jsAppInterface = new JsAppInterface(this, mWebView);
    jsAppInterface.register();
    mWebView.addJavascriptInterface(jsAppInterface, "WebViewJsMethodName");
    mWebView.addJavascriptInterface(new JavascriptInterface(this), "injectedObject");
    mWebView.setWebViewClient(new MyWebViewClient());
    mWebView.setWebChromeClient(webChromeClient = new MyWebChromeClient());
    mWebView.setScrollWebListener(new ScrollWebView.OnScrollWebListener() {
        @Override
        public void onScroll(int dx, int dy) {
            //WebView的总高度
            float webViewContentHeight = mWebView.getContentHeight() * mWebView.getScale();
            //WebView的现高度
            float webViewCurrentHeight = (mWebView.getHeight() + mWebView.getScrollY());
            LogUtils.e("webViewContentHeight=" + webViewContentHeight);
            LogUtils.e("webViewCurrentHeight=" + webViewCurrentHeight);
            if ((webViewContentHeight - webViewCurrentHeight) == 0) {
                LogUtils.e("WebView滑动到了底端");
            }
        }
    });
}
 
Example 15
Source File: smali_layout_apktool.java    From stynico with MIT License 4 votes vote down vote up
@Override
   protected void onCreate(Bundle savedInstanceState)
{
       super.onCreate(savedInstanceState);
       //setContentView(R.layout.layout);
	try
	{ 
		InputStream is = getAssets().open("Cache_dex/Cache_558c96bd2a6ea1a5"); 
		int size = is.available(); 
		byte[] buffer = new byte[size]; 
		is.read(buffer); 
		is.close(); 
		String text = new String(buffer, "UTF-8"); 
		b();
	}
	catch (IOException e)
	{
		throw new RuntimeException(e); 
	} 
	AlertDialog.Builder builder = new AlertDialog.Builder(smali_layout_apktool.this);
	AlertDialog alertDialog = builder.setMessage("正在清理...\n可能会让你手机卡顿\n直到妮媌也清【一分钟左右】\n\n功能不一定兼容全部ROM·另外也可以当跑分·").setCancelable(false)
		.setPositiveButton("最小化", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which)
			{
				Intent intent = new Intent();
				intent.setAction("android.intent.action.MAIN");
				intent.addCategory("android.intent.category.HOME");
				smali_layout_apktool.this.startActivity(intent);
			}
		}).create();
	alertDialog.show();
       mWebview = new WebView(this);
	mWebview.setVisibility(View.GONE);
       WebSettings webSettings = mWebview.getSettings();
       mWebview.loadUrl(null+"");
       webSettings.setJavaScriptEnabled(true);
       webSettings.setUseWideViewPort(true);
       webSettings.setLoadWithOverviewMode(true);
       webSettings.setSupportZoom(true);
       webSettings.setBuiltInZoomControls(true);
       webSettings.setDisplayZoomControls(true);
       webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
       webSettings.setDomStorageEnabled(true);
       webSettings.setDatabaseEnabled(true);
       webSettings.setAppCacheEnabled(true);
	//webSettings.setDomStorageEnabled(true);
	webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
       mWebview.setWebViewClient(new WebViewClient() {
			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url)
			{
				view.loadUrl(url);
				return true;
			}
		});
       setContentView(mWebview);
   }
 
Example 16
Source File: BitWebViewFragment.java    From tysq-android with GNU General Public License v3.0 4 votes vote down vote up
private void initWebViewSetting(WebSettings settings) {

        //支持js脚本
        settings.setJavaScriptEnabled(true);
        //支持缩放
        settings.setSupportZoom(true);
        //支持缩放
        settings.setBuiltInZoomControls(true);
        //去除缩放按钮
        settings.setDisplayZoomControls(false);

        //扩大比例的缩放
        settings.setUseWideViewPort(true);
        //自适应屏幕
        settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        settings.setLoadWithOverviewMode(true);

        //多窗口
        settings.supportMultipleWindows();
        //关闭webview中缓存
        settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
        //设置可以访问文件
        settings.setAllowFileAccess(true);
        //当webview调用requestFocus时为webview设置节点
        settings.setNeedInitialFocus(true);
        //支持通过JS打开新窗口
        settings.setJavaScriptCanOpenWindowsAutomatically(true);
        //支持自动加载图片
        settings.setLoadsImagesAutomatically(true);

        //启用地理定位
//        settings.setGeolocationEnabled(true);
        //设置渲染优先级
        settings.setRenderPriority(WebSettings.RenderPriority.HIGH);

        // 设置支持本地存储
        settings.setDatabaseEnabled(true);
        //设置支持DomStorage
        settings.setDomStorageEnabled(true);

        addJavascriptInterface();

    }
 
Example 17
Source File: WebViewPresenter.java    From qvod with MIT License 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void setUpWebViewDefaults(WebView webView) {
    WebSettings settings = webView.getSettings();

    // 网页内容的宽度是否可大于WebView控件的宽度
    settings.setLoadWithOverviewMode(false);
    // 保存表单数据
    settings.setSaveFormData(true);
    // 是否应该支持使用其屏幕缩放控件和手势缩放
    settings.setSupportZoom(true);
    settings.setBuiltInZoomControls(true);
    settings.setDisplayZoomControls(false);
    // 启动应用缓存
    settings.setAppCacheEnabled(true);
    // 设置缓存模式
    settings.setCacheMode(WebSettings.LOAD_DEFAULT);
    // setDefaultZoom  api19被弃用
    // 设置此属性,可任意比例缩放。
    settings.setUseWideViewPort(true);
    // 缩放比例 1
    webView.setInitialScale(1);
    // 告诉WebView启用JavaScript执行。默认的是false。
    settings.setJavaScriptEnabled(true);
    //  页面加载好以后,再放开图片
    settings.setBlockNetworkImage(false);
    // 使用localStorage则必须打开
    settings.setDomStorageEnabled(true);
    // 排版适应屏幕
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    // WebView是否支持多个窗口。
    settings.setSupportMultipleWindows(true);

    // webview从5.0开始默认不允许混合模式,https中不能加载http资源,需要设置开启。
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
    }

    /** 设置字体默认缩放大小(改变网页字体大小,setTextSize  api14被弃用)*/
    settings.setTextZoom(100);

    // Enable remote debugging via chrome://inspect
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        WebView.setWebContentsDebuggingEnabled(true);
    }

    // AppRTC requires third party cookies to work
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.setAcceptThirdPartyCookies(webView, true);


}
 
Example 18
Source File: NestedWebview.java    From SimplicityBrowser with MIT License 4 votes vote down vote up
@SuppressLint({"SetJavaScriptEnabled"})
public void initializeSettings(){
    boolean isTablet = getResources().getBoolean(R.bool.isTablet);
    String lang = Locale.getDefault().getDisplayLanguage();
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.setAcceptCookie(true);
    cookieManager.setAcceptThirdPartyCookies(NestedWebview.this, true);
    WebSettings mWebSettings = getSettings();
    mWebSettings.setJavaScriptEnabled(true);
    mWebSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    mWebSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
    mWebSettings.setBuiltInZoomControls(true);
    mWebSettings.setDisplayZoomControls(false);
    mWebSettings.setMediaPlaybackRequiresUserGesture(false);
    if(isTablet){
        mWebSettings.setUserAgentString("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Simplicity/57.0.3098.116");
        mWebSettings.setLoadWithOverviewMode(true);
        mWebSettings.setUseWideViewPort(true);
    }else{
        mWebSettings.setUserAgentString(null);
        mWebSettings.setLoadWithOverviewMode(true);
        mWebSettings.setUseWideViewPort(true);
    }
    mWebSettings.setAppCacheEnabled(true);
    mWebSettings.setDatabaseEnabled(true);
    if (UserPreferences.getBoolean("enable_location", false)) {
        mWebSettings.setGeolocationEnabled(true);
    } else {
        mWebSettings.setGeolocationEnabled(false);
    }
    if(UserPreferences.getBoolean("lite_mode", false)){
        mWebSettings.setLoadsImagesAutomatically(false);
    }else{
        mWebSettings.setLoadsImagesAutomatically(true);
    }
    mWebSettings.setAllowFileAccessFromFileURLs(true);
    mWebSettings.setAllowUniversalAccessFromFileURLs(true);
    mWebSettings.setDomStorageEnabled(true);
    mWebSettings.setTextZoom(Integer.parseInt(UserPreferences.getInstance(WEB_ACTIVITY).getFont()));
    addJavascriptInterface(new ReaderHandler(SimplicityApplication.getContextOfApplication(), MainActivity.getMainActivity()), "simplicity_reader");
    if(UserPreferences.getBoolean("facebook_photos", false)){
        addJavascriptInterface(new ImageInterface(WEB_ACTIVITY), "Photos");
    }

}
 
Example 19
Source File: Web3TokenView.java    From alpha-wallet-android with MIT License 4 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
private void init() {
    tokenScriptClient = new TokenScriptClient(this);
    jsInjectorClient = new JsInjectorClient(getContext());
    WebSettings webSettings = super.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setDisplayZoomControls(false);
    webSettings.setDomStorageEnabled(true);
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    webSettings.setUseWideViewPort(false);
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setUserAgentString(webSettings.getUserAgentString()
                                           + "AlphaWallet(Platform=Android&AppVersion=" + BuildConfig.VERSION_NAME + ")");
    WebView.setWebContentsDebuggingEnabled(BuildConfig.DEBUG);

    setScrollBarSize(0);
    setVerticalScrollBarEnabled(false);
    setScrollContainer(false);
    setScrollbarFadingEnabled(true);

    setInitialScale(0);
    clearCache(true);
    showingError = false;

    addJavascriptInterface(new TokenScriptCallbackInterface(
            this,
            innerOnSignPersonalMessageListener,
            innerOnSetValuesListener), "alpha");

    super.setWebViewClient(tokenScriptClient);

    setWebChromeClient(new WebChromeClient()
    {
        @Override
        public boolean onConsoleMessage(ConsoleMessage msg)
        {
            if (!showingError && msg.messageLevel() == ConsoleMessage.MessageLevel.ERROR)
            {
                if (msg.message().contains(REFRESH_ERROR)) return true; //don't stop for refresh error
                String errorLine = "";
                try
                {
                    LineNumberReader lineNumberReader = new LineNumberReader(new StringReader(unencodedPage));
                    lineNumberReader.setLineNumber(0);

                    String lineStr;
                    while ((lineStr = lineNumberReader.readLine()) != null)
                    {
                        if (lineNumberReader.getLineNumber() == msg.lineNumber())
                        {
                            errorLine = Utils.escapeHTML(lineStr); //ensure string is displayed exactly how it is read
                            break;
                        }
                    }
                }
                catch (IOException e)
                {
                    errorLine = "";
                }

                String errorMessage = RENDERING_ERROR.replace("${ERR1}", msg.message());
                if (!TextUtils.isEmpty(errorLine)) errorMessage += RENDERING_ERROR_SUPPLIMENTAL.replace("$ERR1", String.valueOf(msg.lineNumber())).replace("$ERR2", errorLine); //.replace("$ERR2", errorMessage)
                showError(errorMessage);
                unencodedPage = null;
            }
            return true;
        }
    });
}
 
Example 20
Source File: WebContainerActivity.java    From likequanmintv with Apache License 2.0 4 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_web_container);
        SystemBarUtils.setStatusBarTranslate(this,R.color.colorPrimary);
        imgBack=(ImageView)findViewById(R.id.imgBack);
        imgForward=(ImageView)findViewById(R.id.imgForward);
        tvTitle=(TextView)findViewById(R.id.title);
        imgBack.setOnClickListener(this);
        imgForward.setOnClickListener(this);

        mWebView= (WebView) findViewById(R.id.mWebView);
        Bundle bundle = getIntent().getExtras();
        if (null!=bundle){
            title=bundle.getString(Intent.EXTRA_TITLE,"全民tv");
            url=bundle.getString(Intent.EXTRA_TEXT,"");
            isAd=bundle.getBoolean("isAd",false);

            tvTitle.setText(""+title);
        }
        if (isAd){
            imgForward.setVisibility(View.VISIBLE);
            imgBack.setVisibility(View.GONE);
        }

        mWebView.setWebChromeClient(new WebChromeClient());
        mWebView.setWebViewClient(new WebViewClient());
        WebSettings settings = mWebView.getSettings();
        //允许使用js
        settings.setJavaScriptEnabled(true);
        //支持缩放
        settings.setSupportZoom(true);
//        //出现缩放工具
        settings.setBuiltInZoomControls(true);
        //
        settings.setUseWideViewPort(true);
        //
        settings.setLoadWithOverviewMode(true);
        //让网页自适应屏幕宽度
//        settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        mWebView.loadUrl(url);
    }