本文整理汇总了Java中android.view.Display.getMetrics方法的典型用法代码示例。如果您正苦于以下问题:Java Display.getMetrics方法的具体用法?Java Display.getMetrics怎么用?Java Display.getMetrics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.Display
的用法示例。
在下文中一共展示了Display.getMetrics方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getResolution
import android.view.Display; //导入方法依赖的package包/类
/**
* Returns the non-scaled pixel resolution of the current default display being used by the
* WindowManager in the specified context.
* @param context context to use to retrieve the current WindowManager
* @return a string in the format "WxH", or the empty string "" if resolution cannot be determined
*/
static String getResolution(final Context context) {
// user reported NPE in this method; that means either getSystemService or getDefaultDisplay
// were returning null, even though the documentation doesn't say they should do so; so now
// we catch Throwable and return empty string if that happens
String resolution = "";
try {
final WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
final Display display = wm.getDefaultDisplay();
final DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);
resolution = metrics.widthPixels + "x" + metrics.heightPixels;
}
catch (Throwable t) {
if (Countly.sharedInstance().isLoggingEnabled()) {
Log.i(Countly.TAG, "Device resolution cannot be determined");
}
}
return resolution;
}
示例2: navigationBarExist2
import android.view.Display; //导入方法依赖的package包/类
/**
* 此方法在模拟器还是在真机都是完全正确
* @param activity
* @return
*/
public static boolean navigationBarExist2(Activity activity) {
WindowManager windowManager = activity.getWindowManager();
Display d = windowManager.getDefaultDisplay();
DisplayMetrics realDisplayMetrics = new DisplayMetrics();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
d.getRealMetrics(realDisplayMetrics);
}
int realHeight = realDisplayMetrics.heightPixels;
int realWidth = realDisplayMetrics.widthPixels;
DisplayMetrics displayMetrics = new DisplayMetrics();
d.getMetrics(displayMetrics);
int displayHeight = displayMetrics.heightPixels;
int displayWidth = displayMetrics.widthPixels;
return (realWidth - displayWidth) > 0 || (realHeight - displayHeight) > 0;
}
示例3: getScreenRealH
import android.view.Display; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static int getScreenRealH(Context context) {
int h;
WindowManager winMgr = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = winMgr.getDefaultDisplay();
DisplayMetrics dm = new DisplayMetrics();
if (Build.VERSION.SDK_INT >= 17) {
display.getRealMetrics(dm);
h = dm.heightPixels;
} else {
try {
Method method = Class.forName("android.view.Display").getMethod("getRealMetrics", DisplayMetrics.class);
method.invoke(display, dm);
h = dm.heightPixels;
} catch (Exception e) {
display.getMetrics(dm);
h = dm.heightPixels;
}
}
return h;
}
示例4: SeeScoreView
import android.view.Display; //导入方法依赖的package包/类
/**
* construct the SeeScore scrollable View
* @param context (usually the MainActivity)
* @param am the asset manager for font handling
* @param zn the zoom notification which is called on (pinch) zoom change
* @param tn the tap notification which is called on a tap in the view with info about what was tapped
* if tn == null then taps will not be intercepted and pinch-zoom is enabled
* NB tn disables pinch-zoom
*/
public SeeScoreView(Activity context, AssetManager am, ZoomNotification zn, TapNotification tn) {
super(context);
setOrientation(VERTICAL);
this.assetManager = am;
this.magnification = 1.0F;
this.zoomNotify = zn;
this.tapNotify = tn;
DisplayMetrics displayMetrics = new android.util.DisplayMetrics();
Display display = context.getWindowManager().getDefaultDisplay();
display.getMetrics(displayMetrics);
displayDPI = displayMetrics.densityDpi;
android.graphics.Point screenSize = new android.graphics.Point();
display.getSize(screenSize);
screenHeight = screenSize.y;
}
示例5: getScreenRealHeight
import android.view.Display; //导入方法依赖的package包/类
/**
* 获取屏幕真正的高度
* @return
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static int getScreenRealHeight() {
int h;
WindowManager winMgr = (WindowManager) XFrame.getSystemService(Context.WINDOW_SERVICE);
Display display = winMgr.getDefaultDisplay();
DisplayMetrics dm = new DisplayMetrics();
if (Build.VERSION.SDK_INT >= 17) {
display.getRealMetrics(dm);
h = dm.heightPixels;
} else {
try {
Method method = Class.forName("android.view.Display").getMethod("getRealMetrics", DisplayMetrics.class);
method.invoke(display, dm);
h = dm.heightPixels;
} catch (Exception e) {
display.getMetrics(dm);
h = dm.heightPixels;
}
}
return h;
}
示例6: onItemClickListener
import android.view.Display; //导入方法依赖的package包/类
@Override
public void onItemClickListener(View view, int position) {
if (this.isFinishing()) return;
mPopDialog = new PopDialog(this, R.style.PopDeleteDialogStyle);
mPopDialog.setPopItemClickListener(this);
int[] location = new int[2];
currentPosition = position;
view.getLocationOnScreen(location);// x为0,y根据点击位置不同而不同
DisplayMetrics dm = new DisplayMetrics();
WindowManager wm = getWindowManager();
if (wm == null) return;
Display display = wm.getDefaultDisplay();
if (display == null) return;
display.getMetrics(dm);
if (mPopDialog == null) return;
Window window = mPopDialog.getWindow();
if (window == null) return;
WindowManager.LayoutParams params = window.getAttributes();
if (params == null) return;
params.gravity = Gravity.BOTTOM;
params.y = dm.heightPixels - location[1];
window.setAttributes(params);
mPopDialog.setCanceledOnTouchOutside(true);
mPopDialog.setOnCancelListener(dialog -> Toast.makeText(this, "cancel", Toast.LENGTH_SHORT).show());
mPopDialog.show();
}
示例7: getScreenSize
import android.view.Display; //导入方法依赖的package包/类
public void getScreenSize() {
WindowManager windowManager = (WindowManager)this.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics dm = new DisplayMetrics();
Display display = windowManager.getDefaultDisplay();
display.getMetrics(dm);
DIMEN_RATE = dm.density / 1.0F;
DIMEN_DPI = dm.densityDpi;
SCREEN_WIDTH = dm.widthPixels;
SCREEN_HEIGHT = dm.heightPixels;
if(SCREEN_WIDTH > SCREEN_HEIGHT) {
int t = SCREEN_HEIGHT;
SCREEN_HEIGHT = SCREEN_WIDTH;
SCREEN_WIDTH = t;
}
}
示例8: getScreenHeight
import android.view.Display; //导入方法依赖的package包/类
public static int getScreenHeight(Context c) {
WindowManager mWindowManager = (WindowManager)c.getSystemService(Context.WINDOW_SERVICE);
Display mDisplay = mWindowManager.getDefaultDisplay();
DisplayMetrics mMetrics = new DisplayMetrics();
mDisplay.getMetrics(mMetrics);
return mMetrics.heightPixels;
}
示例9: getScreenSize
import android.view.Display; //导入方法依赖的package包/类
public void getScreenSize() {
WindowManager windowManager = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics dm = new DisplayMetrics();
Display display = windowManager.getDefaultDisplay();
display.getMetrics(dm);
DIMEN_RATE = dm.density / 1.0F;
DIMEN_DPI = dm.densityDpi;
SCREEN_WIDTH = dm.widthPixels;
SCREEN_HEIGHT = dm.heightPixels;
if (SCREEN_WIDTH > SCREEN_HEIGHT) {
int t = SCREEN_HEIGHT;
SCREEN_HEIGHT = SCREEN_WIDTH;
SCREEN_WIDTH = t;
}
}
示例10: getScreenDimensions
import android.view.Display; //导入方法依赖的package包/类
public static Point getScreenDimensions(Context context) {
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
DisplayMetrics dm = new DisplayMetrics();
display.getMetrics(dm);
Point point = new Point();
point.set(dm.widthPixels, dm.heightPixels);
return point;
}
示例11: hasImmersive
import android.view.Display; //导入方法依赖的package包/类
@SuppressLint ("NewApi")
private boolean hasImmersive() {
if (!cached) {
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
hasImmersive = false;
cached = true;
return false;
}
Display d = ((WindowManager) reactContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
DisplayMetrics realDisplayMetrics = new DisplayMetrics();
d.getRealMetrics(realDisplayMetrics);
int realHeight = realDisplayMetrics.heightPixels;
int realWidth = realDisplayMetrics.widthPixels;
DisplayMetrics displayMetrics = new DisplayMetrics();
d.getMetrics(displayMetrics);
int displayHeight = displayMetrics.heightPixels;
int displayWidth = displayMetrics.widthPixels;
hasImmersive = (realWidth > displayWidth) || (realHeight > displayHeight);
cached = true;
}
return hasImmersive;
}
开发者ID:lequanghuylc,项目名称:react-native-detect-navbar-android,代码行数:30,代码来源:RNDetectNavbarAndroidModule.java
示例12: getDisplayMetrics
import android.view.Display; //导入方法依赖的package包/类
private DisplayMetrics getDisplayMetrics() {
DisplayMetrics metrics = new DisplayMetrics();
WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
display.getMetrics(metrics);
return metrics;
}
示例13: getScreenDimensions
import android.view.Display; //导入方法依赖的package包/类
public static Point getScreenDimensions(Context context) {
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
DisplayMetrics dm = new DisplayMetrics();
display.getMetrics(dm);
Point point = new Point();
point.set(dm.widthPixels, dm.heightPixels);
return point;
}
示例14: px2dp
import android.view.Display; //导入方法依赖的package包/类
public static int px2dp(Context context, int px) {
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
DisplayMetrics displaymetrics = new DisplayMetrics();
display.getMetrics(displaymetrics);
return (int) (px / displaymetrics.density + 0.5f);
}
示例15: hasVirtualNavigationBar
import android.view.Display; //导入方法依赖的package包/类
/**
* 判断手机是否含有虚拟按键 99%
*
* @return
*/
public static boolean hasVirtualNavigationBar(Context context) {
boolean hasSoftwareKeys = true;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
Display d = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
DisplayMetrics realDisplayMetrics = new DisplayMetrics();
d.getRealMetrics(realDisplayMetrics);
int realHeight = realDisplayMetrics.heightPixels;
int realWidth = realDisplayMetrics.widthPixels;
DisplayMetrics displayMetrics = new DisplayMetrics();
d.getMetrics(displayMetrics);
int displayHeight = displayMetrics.heightPixels;
int displayWidth = displayMetrics.widthPixels;
hasSoftwareKeys = (realWidth - displayWidth) > 0 || (realHeight - displayHeight) > 0;
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
boolean hasMenuKey = ViewConfiguration.get(context).hasPermanentMenuKey();
boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
hasSoftwareKeys = !hasMenuKey && !hasBackKey;
}
return hasSoftwareKeys;
}