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

The following examples show how to use android.webkit.WebSettings#setDefaultZoom() . 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: TopSlidWebView.java    From MyBlogDemo with Apache License 2.0 6 votes vote down vote up
private void initSize(WebSettings settings) {
    int   screenDensity   = getResources().getDisplayMetrics(). densityDpi ;
    WebSettings.ZoomDensity   zoomDensity   = WebSettings.ZoomDensity. MEDIUM ;
    switch (screenDensity){
        case   DisplayMetrics.DENSITY_LOW :
            zoomDensity = WebSettings.ZoomDensity.CLOSE;
            break ;
        case   DisplayMetrics.DENSITY_MEDIUM :
            zoomDensity = WebSettings.ZoomDensity.MEDIUM;
            break ;
        case   DisplayMetrics.DENSITY_HIGH :
            zoomDensity = WebSettings.ZoomDensity.FAR;
            break ;
    }
    settings.setDefaultZoom(zoomDensity) ;
}
 
Example 2
Source File: WebSettingsCompatEclairMr1.java    From Android_Skin_2.0 with Apache License 2.0 6 votes vote down vote up
public static void setDefaultZoom(WebSettings settings, ZoomDensityCompat zoom) {
	switch (zoom) {
	case FAR: {
		settings.setDefaultZoom(ZoomDensity.FAR);
		break;
	}
	case MEDIUM: {
		settings.setDefaultZoom(ZoomDensity.MEDIUM);
		break;
	}
	case CLOSE: {
		settings.setDefaultZoom(ZoomDensity.CLOSE);
		break;
	}
	default: {
		break;
	}
	}
}
 
Example 3
Source File: WebViewActivity.java    From movienow with GNU General Public License v3.0 5 votes vote down vote up
private void initWebSettings() {
    WebSettings webSettings = webViewT.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setSupportZoom(true);
    webSettings.setDisplayZoomControls(false);
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    webSettings.setAllowFileAccess(true);
    webSettings.setDefaultTextEncodingName("UTF-8");
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setUseWideViewPort(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setAppCacheMaxSize(1024 * 1024 * 8);
    String appCachePath = getApplicationContext().getCacheDir().getAbsolutePath();
    webSettings.setAppCachePath(appCachePath);
    webSettings.setAllowFileAccess(true);
    webSettings.setAppCacheEnabled(true);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
    }
    webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int mDensity = metrics.densityDpi;
    if (mDensity == 240) {
        webSettings.setDefaultZoom(WebSettings.ZoomDensity.FAR);
    } else if (mDensity == 160) {
        webSettings.setDefaultZoom(WebSettings.ZoomDensity.MEDIUM);
    } else if (mDensity == 120) {
        webSettings.setDefaultZoom(WebSettings.ZoomDensity.CLOSE);
    } else if (mDensity == DisplayMetrics.DENSITY_XHIGH) {
        webSettings.setDefaultZoom(WebSettings.ZoomDensity.FAR);
    } else if (mDensity == DisplayMetrics.DENSITY_TV) {
        webSettings.setDefaultZoom(WebSettings.ZoomDensity.FAR);
    } else {
        webSettings.setDefaultZoom(WebSettings.ZoomDensity.MEDIUM);
    }
}
 
Example 4
Source File: WebViewActivity.java    From pre-dem-android with MIT License 5 votes vote down vote up
private void init() {
        mWebView.setWebViewClient(webViewClient);
//        mWebView.setWebChromeClient(chromeClient);
        WebSettings settings = mWebView.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
        settings.setDefaultZoom(WebSettings.ZoomDensity.FAR);

        settings.setSupportZoom(true);
        settings.setBuiltInZoomControls(true);
        settings.setAppCacheEnabled(false);
        settings.setSavePassword(false);

        mWebView.loadUrl(mUrl);
    }
 
Example 5
Source File: WebViewUtils.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@SuppressLint("SetJavaScriptEnabled")
public static void loadUrlAdaptiveScreen(Context mContext, WebView webview,
                                         String url, boolean javaScriptEnabled) {
    WebSettings webSettings = webview.getSettings();
    webSettings.setJavaScriptEnabled(javaScriptEnabled);
    // 自适应屏幕
    // 第一种:
    // WebSetting settings = webView.getSettings();
    // settings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
    // 把所有内容放在webview等宽的一列中。(可能会出现页面中链接失效)
    // 第二种:
    // settings.setUseWideViewPort(true);
    // settings.setLoadWithOverviewMode(true);
    // 第三种:
    DisplayMetrics metrics = new DisplayMetrics();
    ((Activity) mContext).getWindowManager().getDefaultDisplay()
            .getMetrics(metrics);
    int mDensity = metrics.densityDpi;
    if (mDensity <= 120) {
        webSettings.setDefaultZoom(ZoomDensity.CLOSE);
    } else if (mDensity > 120 && mDensity < 240) {
        webSettings.setDefaultZoom(ZoomDensity.MEDIUM);
    } else if (mDensity >= 240) {
        webSettings.setDefaultZoom(ZoomDensity.FAR);
    }

    webview.setWebViewClient(new WebViewClient());
    webview.loadUrl(url);

}
 
Example 6
Source File: EditAreaView.java    From 920-text-editor-v2 with Apache License 2.0 4 votes vote down vote up
public EditAreaView(Context context, AttributeSet attrs) {
        super(context, attrs);

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

        setLongClickable(false);
        setOnLongClickListener(new OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                return true;
            }
        });

        WebSettings ws = getSettings();
        ws.setDefaultZoom(WebSettings.ZoomDensity.FAR);
        ws.setAllowContentAccess(true);
        ws.setAllowFileAccess(true);
        ws.setBuiltInZoomControls(false);
        ws.setDefaultTextEncodingName("utf-8");
        ws.setDisplayZoomControls(false);
        ws.setSupportZoom(false);
        ws.setLoadWithOverviewMode(false);

        ws.setJavaScriptEnabled(true);
        ws.setAppCacheEnabled(false);
        ws.setDomStorageEnabled(true);
        ws.setAppCacheMaxSize(1024*1024*80);
        ws.setAppCachePath(context.getCacheDir().getPath());
//        ws.setAllowFileAccess(true);
        ws.setCacheMode(WebSettings.LOAD_DEFAULT);

        addJavascriptInterface(new JavascriptApi(), "AndroidEditor");

        setWebViewClient(new EditorViewClient());
        setWebChromeClient(new EditorViewChromeClient());

        pref = Pref.getInstance(getContext());
        ThemeList.Theme theme = pref.getThemeInfo();
        boolean isDark = false;
        if (theme != null) {
            isDark = theme.isDark;
        }

        String html = null;

        try {
            InputStream is = getContext().getAssets().open("editor.html");
            html = IOUtils.readFile(is, "utf-8");
            is.close();
        } catch (Exception e) {
            L.e(e);
            UIUtils.toast(getContext(), R.string.editor_create_unknown_exception);
            return;
        }

        if (!isDark)
            html = html.replaceAll("<\\!\\-\\-\\{DARK\\-START\\}\\-\\->[\\w\\W]+?<\\!\\-\\-\\{DARK\\-END\\}\\-\\->", "");

        loadDataWithBaseURL("file:///android_asset/", html, "text/html", "utf-8", "file:///android_asset/");
        //fix dark theme background spark
        setBackgroundColor(Color.TRANSPARENT);

        pref.registerOnSharedPreferenceChangeListener(this);
        onSharedPreferenceChanged(null, Pref.KEY_FONT_SIZE);
        onSharedPreferenceChanged(null, Pref.KEY_CURSOR_WIDTH);
        onSharedPreferenceChanged(null, Pref.KEY_SHOW_LINE_NUMBER);
        onSharedPreferenceChanged(null, Pref.KEY_WORD_WRAP);
        onSharedPreferenceChanged(null, Pref.KEY_SHOW_WHITESPACE);
        onSharedPreferenceChanged(null, Pref.KEY_TAB_SIZE);
        onSharedPreferenceChanged(null, Pref.KEY_AUTO_INDENT);
        onSharedPreferenceChanged(null, Pref.KEY_AUTO_CAPITALIZE);
        onSharedPreferenceChanged(null, Pref.KEY_INSERT_SPACE_FOR_TAB);
        onSharedPreferenceChanged(null, Pref.KEY_THEME);
        onSharedPreferenceChanged(null, Pref.KEY_TOUCH_TO_ADJUST_TEXT_SIZE);
        enableHighlight(pref.isHighlight());
        setReadOnly(pref.isReadOnly());
    }
 
Example 7
Source File: CompatibilityImpl.java    From Overchan-Android with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.ECLAIR_MR1)
public static void setDefaultZoomFAR(WebSettings settings) {
    settings.setDefaultZoom(WebSettings.ZoomDensity.FAR);
}
 
Example 8
Source File: CompatibilityImpl.java    From Overchan-Android with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.ECLAIR_MR1)
public static void setDefaultZoomCLOSE(WebSettings settings) {
    settings.setDefaultZoom(WebSettings.ZoomDensity.CLOSE);
}
 
Example 9
Source File: CompatibilityImpl.java    From Overchan-Android with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.ECLAIR_MR1)
public static void setDefaultZoomMEDIUM(WebSettings settings) {
    settings.setDefaultZoom(WebSettings.ZoomDensity.MEDIUM);
}