Android设备的显示信息

package com.keyisoftware.utils;

import android.app.Activity;
import android.util.DisplayMetrics;

/***
 * 实现获取设备的显示信息<br/>
 * 主要包括设备的分辨率,dpi,缩放率等;全部继承自DisplayMetrics
 * 
 * @author [email protected]
 * @version 1.0.0
 * 
 */
public class DeviceDisplayInfo {

	private int screenWidth;
	private int screenHeight;
	private int densityDpi;
	private float scale;
	private float fontScale;
	private float xdpi;
	private float ydpi;

	public DeviceDisplayInfo(Activity activity) {

		DisplayMetrics displayMetrics = new DisplayMetrics();
		activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
		screenWidth = displayMetrics.widthPixels;
		screenHeight = displayMetrics.heightPixels;
		densityDpi = displayMetrics.densityDpi;
		scale = displayMetrics.density;
		fontScale = displayMetrics.scaledDensity;
		xdpi = displayMetrics.xdpi;
		ydpi = displayMetrics.ydpi;

	}

	/**
	 * 获取屏幕宽度,单位为px
	 * 
	 * @return
	 */
	public int getScreenWidth() {
		return screenWidth;
	}

	public void setScreenWidth(int screenWidth) {
		this.screenWidth = screenWidth;
	}

	/**
	 * 获取屏幕高度,单位为px
	 * 
	 * @return
	 */
	public int getScreenHeight() {
		return screenHeight;
	}

	public void setScreenHeight(int screenHeight) {
		this.screenHeight = screenHeight;
	}

	/**
	 * 获取屏幕密度,单位为dpi
	 * 
	 * @return
	 */
	public int getDensityDpi() {
		return densityDpi;
	}

	public void setDensityDpi(int densityDpi) {
		this.densityDpi = densityDpi;
	}

	/**
	 * 获取缩放系数,值为 densityDpi/160
	 * 
	 * @return
	 */
	public float getScale() {
		return scale;
	}

	public void setScale(float scale) {
		this.scale = scale;
	}

	/**
	 * 获取文字缩放系数,同scale
	 * 
	 * @return
	 */
	public float getFontScale() {
		return fontScale;
	}

	public void setFontScale(float fontScale) {
		this.fontScale = fontScale;
	}

	public float getXdpi() {
		return xdpi;
	}

	public void setXdpi(float xdpi) {
		this.xdpi = xdpi;
	}

	public float getYdpi() {
		return ydpi;
	}

	public void setYdpi(float ydpi) {
		this.ydpi = ydpi;
	}
}


你可能感兴趣的:(android,显示,设备)