本文整理汇总了Java中android.view.Display.getRealMetrics方法的典型用法代码示例。如果您正苦于以下问题:Java Display.getRealMetrics方法的具体用法?Java Display.getRealMetrics怎么用?Java Display.getRealMetrics使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.Display
的用法示例。
在下文中一共展示了Display.getRealMetrics方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateLayoutParams
import android.view.Display; //导入方法依赖的package包/类
@SuppressWarnings("SuspiciousNameCombination")
private void updateLayoutParams() {
ViewGroup.LayoutParams params = videoView.getLayoutParams();
Context context = videoView.getContext();
WindowManager windowManager = (WindowManager) context.getSystemService(
Context.WINDOW_SERVICE);
if (windowManager == null) {
return;
}
Display display = windowManager.getDefaultDisplay();
DisplayMetrics realMetrics = new DisplayMetrics();
display.getRealMetrics(realMetrics);
params.width = realMetrics.widthPixels;
params.height = realMetrics.heightPixels;
videoView.setLayoutParams(params);
}
示例2: getTrueScreenWidth
import android.view.Display; //导入方法依赖的package包/类
public static int getTrueScreenWidth(Context context) {
int dpi = 0;
Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
DisplayMetrics dm = new DisplayMetrics();
if (Build.VERSION.SDK_INT >= 17) {
display.getRealMetrics(dm);
dpi = dm.widthPixels;
} else {
try {
Class c = Class.forName("android.view.Display");
Method method = c.getMethod("getRealMetrics", DisplayMetrics.class);
method.invoke(display, dm);
dpi = dm.widthPixels;
} catch (Exception e) {
e.printStackTrace();
}
}
return dpi;
}
示例3: hasSoftKeys
import android.view.Display; //导入方法依赖的package包/类
/**
* 判断底部navigator是否已经显示
*
* @param windowManager
* @return
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static boolean hasSoftKeys(WindowManager windowManager) {
try {
Display d = windowManager.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;
return (realWidth - displayWidth) > 0 || (realHeight - displayHeight) > 0;
} catch (Exception e) {
LoggerManager.e("hasSoftKeys:" + e.getMessage());
return false;
}
}
示例4: 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;
}
示例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: getNaviHeight
import android.view.Display; //导入方法依赖的package包/类
private static int getNaviHeight(Activity activity) {
if (activity == null) {
return 0;
}
Display display = activity.getWindowManager().getDefaultDisplay();
int contentHeight = activity.getResources().getDisplayMetrics().heightPixels;
int realHeight = 0;
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
final DisplayMetrics metrics = new DisplayMetrics();
display.getRealMetrics(metrics);
realHeight = metrics.heightPixels;
} else {
try {
Method mGetRawH = Display.class.getMethod("getRawHeight");
realHeight = (Integer) mGetRawH.invoke(display);
} catch (Exception e) {
e.printStackTrace();
}
}
return realHeight - contentHeight;
}
示例7: 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;
}
示例8: getRealScreenWidth
import android.view.Display; //导入方法依赖的package包/类
/**
* 获取屏幕宽度,不包括右侧导航栏
*
* @param activity
* @return
*/
public static int getRealScreenWidth(Activity activity) {
WindowManager windowManager = activity.getWindowManager();
Display display = windowManager.getDefaultDisplay();
DisplayMetrics displayMetrics = new DisplayMetrics();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
display.getRealMetrics(displayMetrics);
} else {
display.getMetrics(displayMetrics);
}
return displayMetrics.widthPixels;
}
示例9: screenShotPrepare
import android.view.Display; //导入方法依赖的package包/类
/**
* 初始化截屏相关设置
* MediaProjectionManager -> MediaProjection -> VirtualDisplay
* */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected void screenShotPrepare() {
initLooper();
// mediaProjection = MainApp.mediaProjection;
// SysUtils.hideStatusBar(this);
if(mediaProjection==null) {
log.d("screenShotPrepare mediaProjection null ");
return;
}
log.d("screenShotPrepare");
Display display = ((WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
metrics = new DisplayMetrics();
display.getRealMetrics(metrics);
Point point = new Point();
display.getRealSize(point);
width = point.x;
height = point.y;
//将屏幕画面放入ImageReader关联的Surface中
imageReader = ImageReader.newInstance(width, height, PixelFormat.RGBA_8888, 1);
log.d("screenShotPrepare2 "+imageReader);
// imageReader.setOnImageAvailableListener(new ImageReader.OnImageAvailableListener() {
// @Override
// public void onImageAvailable(ImageReader reader) {
// log.d("onImageAvailable ");
// }
// },null);
virtualDisplay = mediaProjection.createVirtualDisplay("ScreenShotDemo",
width, height, metrics.densityDpi,
DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,
imageReader.getSurface(),
null, null/*Handler*/);
}
示例10: initDisplayMetrics
import android.view.Display; //导入方法依赖的package包/类
public static void initDisplayMetrics(Context context) {
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
DisplayMetricsHolder.setWindowDisplayMetrics(displayMetrics);
DisplayMetrics screenDisplayMetrics = new DisplayMetrics();
screenDisplayMetrics.setTo(displayMetrics);
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Assertions.assertNotNull(
wm,
"WindowManager is null!");
Display display = wm.getDefaultDisplay();
// Get the real display metrics if we are using API level 17 or higher.
// The real metrics include system decor elements (e.g. soft menu bar).
//
// See: http://developer.android.com/reference/android/view/Display.html#getRealMetrics(android.util.DisplayMetrics)
if (Build.VERSION.SDK_INT >= 17) {
display.getRealMetrics(screenDisplayMetrics);
} else {
// For 14 <= API level <= 16, we need to invoke getRawHeight and getRawWidth to get the real dimensions.
// Since react-native only supports API level 16+ we don't have to worry about other cases.
//
// Reflection exceptions are rethrown at runtime.
//
// See: http://stackoverflow.com/questions/14341041/how-to-get-real-screen-height-and-width/23861333#23861333
try {
Method mGetRawH = Display.class.getMethod("getRawHeight");
Method mGetRawW = Display.class.getMethod("getRawWidth");
screenDisplayMetrics.widthPixels = (Integer) mGetRawW.invoke(display);
screenDisplayMetrics.heightPixels = (Integer) mGetRawH.invoke(display);
} catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
throw new RuntimeException("Error getting real dimensions for API level < 17", e);
}
}
DisplayMetricsHolder.setScreenDisplayMetrics(screenDisplayMetrics);
}
示例11: 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;
}
示例12: getRealScreenHeight
import android.view.Display; //导入方法依赖的package包/类
/**
* 获取屏幕高度,包括底部导航栏
*
* @param activity
* @return
*/
public static int getRealScreenHeight(Activity activity) {
WindowManager windowManager = activity.getWindowManager();
Display display = windowManager.getDefaultDisplay();
DisplayMetrics displayMetrics = new DisplayMetrics();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
display.getRealMetrics(displayMetrics);
} else {
display.getMetrics(displayMetrics);
}
return displayMetrics.heightPixels;
}
示例13: getRealResolution
import android.view.Display; //导入方法依赖的package包/类
/**
* Gets real resolution via the new getRealMetrics API.
* */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private static Pair<Integer,Integer> getRealResolution(Context ctx) {
WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
DisplayMetrics metrics = new DisplayMetrics();
display.getRealMetrics(metrics);
return new Pair<Integer, Integer>(metrics.widthPixels, metrics.heightPixels);
}
示例14: getScreenWidth
import android.view.Display; //导入方法依赖的package包/类
/**
* Finds and returns the TRUE width of the screen
* @return
*/
public static int getScreenWidth(Activity activity) {
if (activity != null) {
Display display = activity.getWindowManager().getDefaultDisplay();
DisplayMetrics metrics = new DisplayMetrics();
Point size = new Point();
int width, height;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && activity.isInMultiWindowMode()) {
display.getMetrics(metrics);
} else {
display.getRealMetrics(metrics);
}
width = metrics.widthPixels;
height = metrics.heightPixels;
} else {
display.getSize(size);
width = size.x;
height = size.y;
}
return Math.max(width, height);
}
return 0;
}
示例15: 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