List of usage examples for android.view Display getRealMetrics
public void getRealMetrics(DisplayMetrics outMetrics)
From source file:com.skytree.epubtest.BookViewActivity.java
@SuppressLint("NewApi") public int getRawHeight() { int width = 0, height = 0; final DisplayMetrics metrics = new DisplayMetrics(); Display display = getWindowManager().getDefaultDisplay(); Method mGetRawH = null, mGetRawW = null; try {/*from w w w.j a va 2 s. c o m*/ // For JellyBeans and onward if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) { display.getRealMetrics(metrics); width = metrics.widthPixels; height = metrics.heightPixels; } else { mGetRawH = Display.class.getMethod("getRawHeight"); mGetRawW = Display.class.getMethod("getRawWidth"); try { width = (Integer) mGetRawW.invoke(display); height = (Integer) mGetRawH.invoke(display); } catch (IllegalArgumentException e) { e.printStackTrace(); return 0; } catch (IllegalAccessException e) { e.printStackTrace(); return 0; } catch (InvocationTargetException e) { e.printStackTrace(); return 0; } } return height; } catch (NoSuchMethodException e3) { e3.printStackTrace(); return 0; } }
From source file:com.skytree.epubtest.BookViewActivity.java
@SuppressLint("NewApi") public int getRawWidth() { int width = 0, height = 0; final DisplayMetrics metrics = new DisplayMetrics(); Display display = getWindowManager().getDefaultDisplay(); Method mGetRawH = null, mGetRawW = null; try {// ww w. j a va 2 s .c o m // For JellyBeans and onward if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) { display.getRealMetrics(metrics); width = metrics.widthPixels; height = metrics.heightPixels; } else { mGetRawH = Display.class.getMethod("getRawHeight"); mGetRawW = Display.class.getMethod("getRawWidth"); try { width = (Integer) mGetRawW.invoke(display); height = (Integer) mGetRawH.invoke(display); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); return 0; } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); return 0; } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); return 0; } } return width; } catch (NoSuchMethodException e3) { e3.printStackTrace(); return 0; } }