當前位置: 首頁>>代碼示例>>Java>>正文


Java Display.getRealMetrics方法代碼示例

本文整理匯總了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);
}
 
開發者ID:dev-labs-bg,項目名稱:fullscreen-video-view,代碼行數:17,代碼來源:OrientationDelegate.java

示例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;
}
 
開發者ID:thelinuxgeekcommunity,項目名稱:nightmode,代碼行數:21,代碼來源:Utility.java

示例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;
    }

}
 
開發者ID:AriesHoo,項目名稱:FastLib,代碼行數:26,代碼來源:NavigationBarUtil.java

示例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;
}
 
開發者ID:jeasinlee,項目名稱:AndroidBasicLibs,代碼行數:22,代碼來源:DensityUtil.java

示例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;
}
 
開發者ID:youth5201314,項目名稱:XFrame,代碼行數:26,代碼來源:XDensityUtils.java

示例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;
}
 
開發者ID:kyleduo,項目名稱:BlurPopupWindow,代碼行數:22,代碼來源:BlurPopupWindow.java

示例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;
}
 
開發者ID:A-Miracle,項目名稱:QiangHongBao,代碼行數:26,代碼來源:ViewUtils.java

示例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;
}
 
開發者ID:zhudongya123,項目名稱:WechatChatroomHelper,代碼行數:18,代碼來源:UIUtil.java

示例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*/);
    }
 
開發者ID:yippeesoft,項目名稱:NotifyTools,代碼行數:38,代碼來源:JumpService.java

示例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);
}
 
開發者ID:qq565999484,項目名稱:RNLearn_Project1,代碼行數:37,代碼來源:DisplayMetricsHolder.java

示例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;
}
 
開發者ID:z-chu,項目名稱:FriendBook,代碼行數:33,代碼來源:DisplayUtil.java

示例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;
}
 
開發者ID:zhudongya123,項目名稱:WechatChatroomHelper,代碼行數:18,代碼來源:UIUtil.java

示例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);
}
 
開發者ID:coding-dream,項目名稱:TPlayer,代碼行數:12,代碼來源:ScreenResolution.java

示例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;
}
 
開發者ID:SebastianRask,項目名稱:Pocket-Plays-for-Twitch,代碼行數:32,代碼來源:StreamFragment.java

示例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


注:本文中的android.view.Display.getRealMetrics方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。