android.webkit.WebSettings.ZoomDensity Java Examples

The following examples show how to use android.webkit.WebSettings.ZoomDensity. 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: 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 #2
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 #3
Source File: TutorialView.java    From GestureTutorial with Apache License 2.0 5 votes vote down vote up
private void init() {
	this.setBackgroundColor(Color.TRANSPARENT); // Background color
	this.setInitialScale(1); // Make whole image viewable.
	this.getSettings().setUseWideViewPort(true);
	this.getSettings().setDefaultZoom(ZoomDensity.FAR);
	this.getSettings().setLoadWithOverviewMode(true);

}
 
Example #4
Source File: SocialAuthDialog.java    From socialauth-android with MIT License 4 votes vote down vote up
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
	super.onPageStarted(view, url, favicon);

	Log.d("SocialAuth-WebView", "onPageStart:" + url);

	// To set zoom density of runkeeper dialog for various densities
	if (url.startsWith("https://runkeeper.com/apps/authorize") & count < 1) {
		if (Util.UI_DENSITY == 120 && Util.UI_SIZE == 4 || Util.UI_DENSITY == 160 && Util.UI_SIZE == 3
				|| Util.UI_DENSITY == 240) {
			mWebView.getSettings().setDefaultZoom(ZoomDensity.FAR);
			count = 1;
		} else {
			if (Util.UI_DENSITY == 160 && Util.UI_SIZE == 10)
				mWebView.getSettings().setDefaultZoom(ZoomDensity.CLOSE);

			count = 1;
		}
	}

	// To set zoom density of linkedin dialog for ldpi and mdpi
	if (mProviderName.toString().equalsIgnoreCase("linkedin")) {
		if (Util.UI_DENSITY == 120 || Util.UI_DENSITY == 240)
			mWebView.getSettings().setDefaultZoom(ZoomDensity.FAR);
		else if (Util.UI_DENSITY == 160) {
			if (Util.UI_SIZE == 3)
				mWebView.getSettings().setDefaultZoom(ZoomDensity.FAR);
			else
				mWebView.getSettings().setDefaultZoom(ZoomDensity.CLOSE);
		} else if (Util.UI_DENSITY == 213)
			mWebView.getSettings().setDefaultZoom(ZoomDensity.CLOSE);

	}

	// To set zoom density of yammer dialog
	if (mProviderName.toString().equalsIgnoreCase("yammer")) {
		if (Util.UI_DENSITY == 160) {
			if (Util.UI_SIZE == 10)
				mWebView.getSettings().setDefaultZoom(ZoomDensity.MEDIUM);
		} else
			mWebView.getSettings().setDefaultZoom(ZoomDensity.FAR);
	}

	// To set zoom density of googleplus/google/salesforce/instagram
	// dialog
	if (mProviderName.toString().equalsIgnoreCase("google")
			|| mProviderName.toString().equalsIgnoreCase("googleplus")
			|| mProviderName.toString().equalsIgnoreCase("salesforce")
			|| mProviderName.toString().equalsIgnoreCase("instagram")) {
		if (Util.UI_DENSITY == 160 && Util.UI_SIZE == 3 || Util.UI_DENSITY == 120 && Util.UI_SIZE == 4
				|| Util.UI_DENSITY == 240)
			mWebView.getSettings().setDefaultZoom(ZoomDensity.FAR);
		else if (Util.UI_DENSITY == 213)
			mWebView.getSettings().setDefaultZoom(ZoomDensity.CLOSE);
	}

	mSpinner.show();

	// For Linkedin, MySpace, Runkeeper - Calls onPageStart to
	// authorize.
	if (url.startsWith(mProviderName.getCallBackUri())) {
		if (url.startsWith(mProviderName.getCancelUri())) {
			mListener.onCancel();
		} else {
			final Map<String, String> params = Util.parseUrl(url);
			Runnable runnable = new Runnable() {
				@Override
				public void run() {
					try {
						AuthProvider auth = mSocialAuthManager.connect(params);

						// Don't save token for yahoo, yammer,
						// salesforce
						if (!mProviderName.toString().equalsIgnoreCase("yammer")
								|| !mProviderName.toString().equalsIgnoreCase("salesforce"))
							writeToken(auth);

						handler.post(new Runnable() {
							@Override
							public void run() {

								if (mSpinner != null && mSpinner.isShowing())
									mSpinner.dismiss();

								Bundle bundle = new Bundle();
								bundle.putString(SocialAuthAdapter.PROVIDER, mProviderName.toString());
								mListener.onComplete(bundle);
							}
						});
					} catch (Exception e) {
						e.printStackTrace();
						mListener.onError(new SocialAuthError("Could not connect using SocialAuth", e));
					}
				}
			};
			new Thread(runnable).start();
		}
		SocialAuthDialog.this.dismiss();
	}
}