Java Code Examples for android.webkit.webview#setInitialScale()

The following examples show how to use android.webkit.webview#setInitialScale() . 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: AdViewUtils.java    From prebid-mobile-android with Apache License 2.0 7 votes vote down vote up
static void setWebViewScale(WebView webView, float webViewHeight, int webViewContentHeight) {
    //case: regulate scale because WebView.getSettings().setLoadWithOverviewMode() does not work
    int scale = (int) (webViewHeight / webViewContentHeight * 100 + 1);

    LogUtil.d("fixZoomIn WB Height:" + webViewHeight + " getContentHeight:" + webViewContentHeight + " scale:" + scale );
    webView.setInitialScale(scale);
}
 
Example 2
Source File: PadViewActivity.java    From padland with Apache License 2.0 6 votes vote down vote up
/**
 * Enables the required settings and features for the webview
 *
 * @param webView
 */
private void _makeWebSettings(WebView webView) {
    webView.setInitialScale(1);
    WebSettings webSettings = webView.getSettings();
    // Enable Javascript
    webSettings.setJavaScriptEnabled(true);
    // remove a weird white line on the right size
    webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);

    webSettings.setUseWideViewPort(true);
    webSettings.setSupportZoom(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setDisplayZoomControls(false);
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setDomStorageEnabled(true); // Required for some NodeJS based code
}
 
Example 3
Source File: WebViewActivity.java    From YCAudioPlayer with Apache License 2.0 5 votes vote down vote up
@Override
public void onScaleChanged(WebView view, float oldScale, float newScale) {
    super.onScaleChanged(view, oldScale, newScale);
    if (newScale - oldScale > 7) {
        //异常放大,缩回去。
        view.setInitialScale((int) (oldScale / newScale * 100));
    }
}
 
Example 4
Source File: VenvyWebView.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setZoomScale(float scale) {
    if (mAgentWeb != null && mAgentWeb.getWebCreator() != null) {
        WebView webView = mAgentWeb.getWebCreator().getWebView();
        if (webView == null) {
            return;
        }
        webView.setInitialScale((int) (scale * 100));
    }
}
 
Example 5
Source File: MyWebViewClient.java    From MaoWanAndoidClient with Apache License 2.0 5 votes vote down vote up
@Override
public void onScaleChanged(WebView view, float oldScale, float newScale) {
    super.onScaleChanged(view, oldScale, newScale);
    if (newScale - oldScale > 7) {
        view.setInitialScale((int) (oldScale / newScale * 100)); //异常放大,缩回去。
    }
}
 
Example 6
Source File: DefaultWebClient.java    From AgentWeb with Apache License 2.0 5 votes vote down vote up
@Override
public void onScaleChanged(WebView view, float oldScale, float newScale) {
	LogUtils.i(TAG, "onScaleChanged:" + oldScale + "   n:" + newScale);
	if (newScale - oldScale > CONSTANTS_ABNORMAL_BIG) {
		view.setInitialScale((int) (oldScale / newScale * 100));
	}
}
 
Example 7
Source File: MyWebViewClient.java    From BaseProject with Apache License 2.0 5 votes vote down vote up
@Override
public void onScaleChanged(WebView view, float oldScale, float newScale) {
    super.onScaleChanged(view, oldScale, newScale);
    if (newScale - oldScale > 7) {
        view.setInitialScale((int) (oldScale / newScale * 100)); //异常放大,缩回去。
    }
}
 
Example 8
Source File: ByWebViewClient.java    From ByWebView with Apache License 2.0 5 votes vote down vote up
@Override
public void onScaleChanged(WebView view, float oldScale, float newScale) {
    super.onScaleChanged(view, oldScale, newScale);
    if (newScale - oldScale > 7) {
        view.setInitialScale((int) (oldScale / newScale * 100)); //异常放大,缩回去。
    }
}
 
Example 9
Source File: MyWebViewClient.java    From ByWebView with Apache License 2.0 5 votes vote down vote up
@Override
public void onScaleChanged(WebView view, float oldScale, float newScale) {
    super.onScaleChanged(view, oldScale, newScale);
    if (newScale - oldScale > 7) {
        view.setInitialScale((int) (oldScale / newScale * 100)); //异常放大,缩回去。
    }
}
 
Example 10
Source File: MyWebViewClient.java    From CloudReader with Apache License 2.0 5 votes vote down vote up
@Override
public void onScaleChanged(WebView view, float oldScale, float newScale) {
    super.onScaleChanged(view, oldScale, newScale);
    if (newScale - oldScale > 7) {
        view.setInitialScale((int) (oldScale / newScale * 100)); //异常放大,缩回去。
    }
}
 
Example 11
Source File: MyWebViewClient.java    From NetEasyNews with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onScaleChanged(WebView view, float oldScale, float newScale) {
    super.onScaleChanged(view, oldScale, newScale);
    if (newScale - oldScale > 7) {
        view.setInitialScale((int) (oldScale / newScale * 100)); //异常放大,缩回去。
    }
}
 
Example 12
Source File: LoginActivity.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
private void c()
{
    WebView webview = (WebView)findViewById(0x7f0a003b);
    WebSettings websettings = webview.getSettings();
    websettings.setUseWideViewPort(true);
    websettings.setLoadWithOverviewMode(true);
    webview.setLayerType(1, null);
    webview.setBackgroundColor(0);
    webview.setInitialScale((100 * getResources().getDisplayMetrics().densityDpi) / 480);
    webview.loadUrl("file:///android_asset/startup.gif");
    (new Handler()).postDelayed(new b(this), 4800L);
    C.setEnabled(false);
    r.setEnabled(false);
    s.setEnabled(false);
}
 
Example 13
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);


}