Java Code Examples for android.view.Display#getRealSize()

The following examples show how to use android.view.Display#getRealSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScreenUtils.java    From NewbieGuide with Apache License 2.0 6 votes vote down vote up
/**
 * 虚拟操作拦(home等)是否显示
 */
public static boolean isNavigationBarShow(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        Display display = activity.getWindowManager().getDefaultDisplay();
        Point size = new Point();
        Point realSize = new Point();
        display.getSize(size);
        display.getRealSize(realSize);
        return realSize.y != size.y;
    } else {
        boolean menu = ViewConfiguration.get(activity).hasPermanentMenuKey();
        boolean back = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
        if (menu || back) {
            return false;
        } else {
            return true;
        }
    }
}
 
Example 2
Source File: jl.java    From letv with Apache License 2.0 6 votes vote down vote up
@SuppressLint({"NewApi"})
public static Point b() {
    Display defaultDisplay = ((WindowManager) hn.a().c().getSystemService("window")).getDefaultDisplay();
    Point point = new Point();
    if (VERSION.SDK_INT >= 17) {
        defaultDisplay.getRealSize(point);
    } else if (VERSION.SDK_INT >= 14) {
        try {
            Method method = Display.class.getMethod("getRawHeight", new Class[0]);
            point.x = ((Integer) Display.class.getMethod("getRawWidth", new Class[0]).invoke(defaultDisplay, new Object[0])).intValue();
            point.y = ((Integer) method.invoke(defaultDisplay, new Object[0])).intValue();
        } catch (Throwable th) {
            defaultDisplay.getSize(point);
        }
    } else if (VERSION.SDK_INT >= 13) {
        defaultDisplay.getSize(point);
    } else {
        point.x = defaultDisplay.getWidth();
        point.y = defaultDisplay.getHeight();
    }
    return point;
}
 
Example 3
Source File: MainActivity.java    From OpenCvFaceDetect with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mSurfaceView = findViewById(R.id.surface_view);
    mSurfaceView.getHolder().addCallback(this);

    int permission = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA);
    if (permission != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, PERMISSION_CAMERA_REQUEST_CODE);
    } else {
        isCheckPermissionOk = true;
    }


    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getRealSize(size);
    mSurfaceViewWidth = size.x;
    mSurfaceViewHeight = size.y;
    Log.e(TAG, "onCreate: " + size.x + "--" + size.y);
}
 
Example 4
Source File: BarUtils.java    From Android-utils with Apache License 2.0 6 votes vote down vote up
/**
 * Return whether the navigation bar visible.
 *
 * @return {@code true}: yes<br>{@code false}: no
 */
public static boolean isSupportNavBar() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        WindowManager wm = (WindowManager) UtilsApp.getApp().getSystemService(Context.WINDOW_SERVICE);
        if (wm == null) return false;
        Display display = wm.getDefaultDisplay();
        Point size = new Point();
        Point realSize = new Point();
        display.getSize(size);
        display.getRealSize(realSize);
        return realSize.y != size.y || realSize.x != size.x;
    }
    boolean menu = ViewConfiguration.get(UtilsApp.getApp()).hasPermanentMenuKey();
    boolean back = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
    return !menu && !back;
}
 
Example 5
Source File: MainActivity.java    From CSCI4669-Fall15-Android with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
   // get the default Display object representing the screen
   Display display = ((WindowManager) 
      getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
   Point screenSize = new Point(); // used to store screen size
   display.getRealSize(screenSize); // store size in screenSize
   
   // display the app's menu only in portrait orientation
   if (screenSize.x < screenSize.y) // x is width, y is height
   {
      getMenuInflater().inflate(R.menu.main, menu); // inflate the menu      
      return true;
   }
   else
      return false;
}
 
Example 6
Source File: NavigationUtil.java    From UIWidget with Apache License 2.0 6 votes vote down vote up
/**
     * 手机具有底部导航栏时,底部导航栏是否可见
     */
    private static boolean isNavigationBarVisible(Activity activity) {
//        View decorView = activity.getWindow().getDecorView();
//        return (decorView.getSystemUiVisibility() & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 2;

        boolean show = false;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            Display display = activity.getWindow().getWindowManager().getDefaultDisplay();
            Point point = new Point();
            display.getRealSize(point);
            View decorView = activity.getWindow().getDecorView();
            Configuration conf = activity.getResources().getConfiguration();
            if (Configuration.ORIENTATION_LANDSCAPE == conf.orientation) {
                View contentView = decorView.findViewById(android.R.id.content);
                if (contentView != null) {
                    show = (point.x != contentView.getWidth());
                }
            } else {
                Rect rect = new Rect();
                decorView.getWindowVisibleDisplayFrame(rect);
                show = (rect.bottom != point.y);
            }
        }
        return show;
    }
 
Example 7
Source File: ViewUtil.java    From timecat with Apache License 2.0 5 votes vote down vote up
public static boolean isNavigationBarShow(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        Display display = activity.getWindowManager().getDefaultDisplay();
        Point size = new Point();
        Point realSize = new Point();
        display.getSize(size);
        display.getRealSize(realSize);
        return realSize.y != size.y;
    } else {
        boolean menu = ViewConfiguration.get(activity).hasPermanentMenuKey();
        boolean back = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
        return !(menu || back);
    }
}
 
Example 8
Source File: DeviceInfoHelper.java    From appium-uiautomator2-server with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the real size of the default display
 *
 * @return The display size in 'WxH' format
 */
public String getRealDisplaySize() {
    Display display = UiAutomatorBridge.getInstance().getDefaultDisplay();
    android.graphics.Point p = new android.graphics.Point();
    display.getRealSize(p);
    return String.format("%sx%s", p.x, p.y);
}
 
Example 9
Source File: LauncherAppState.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
static DynamicGrid createDynamicGrid(Context context, DynamicGrid dynamicGrid) {
    // Determine the dynamic grid properties
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    Point realSize = new Point();
    display.getRealSize(realSize);
    DisplayMetrics dm = new DisplayMetrics();
    display.getMetrics(dm);

    if (dynamicGrid == null) {
        Point smallestSize = new Point();
        Point largestSize = new Point();
        display.getCurrentSizeRange(smallestSize, largestSize);

        dynamicGrid = new DynamicGrid(context,
                context.getResources(),
                Math.min(smallestSize.x, smallestSize.y),
                Math.min(largestSize.x, largestSize.y),
                realSize.x, realSize.y,
                dm.widthPixels, dm.heightPixels);
    }

    // Update the icon size
    DeviceProfile grid = dynamicGrid.getDeviceProfile();
    grid.updateFromConfiguration(context, context.getResources(),
            realSize.x, realSize.y,
            dm.widthPixels, dm.heightPixels);
    return dynamicGrid;
}
 
Example 10
Source File: ScreenUtils.java    From Moment with GNU General Public License v3.0 5 votes vote down vote up
public static int getHeight(Context context) {
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Point size = new Point();
    Display display = manager.getDefaultDisplay();
    display.getRealSize(size);
    return size.y;
}
 
Example 11
Source File: InitActivity.java    From HJMirror with MIT License 5 votes vote down vote up
private boolean isNavigationBarShow() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        Display display = getWindowManager().getDefaultDisplay();
        Point size = new Point();
        Point realSize = new Point();
        display.getSize(size);
        display.getRealSize(realSize);
        return realSize.y != size.y;
    } else {
        boolean menu = ViewConfiguration.get(this).hasPermanentMenuKey();
        boolean back = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
        return !(menu || back);
    }
}
 
Example 12
Source File: ScreenUtils.java    From Moment with GNU General Public License v3.0 5 votes vote down vote up
public static int getWidth(Context context) {
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Point size = new Point();
    Display display = manager.getDefaultDisplay();
    display.getRealSize(size);

    return size.x;
}
 
Example 13
Source File: ScreenUtils.java    From Interessant with Apache License 2.0 5 votes vote down vote up
public static int getWidth(Context context) {
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Point size = new Point();
    Display display = manager.getDefaultDisplay();
    display.getRealSize(size);
    return size.x;
}
 
Example 14
Source File: DragState.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * @param display The Display that the window being dragged is on.
 */
void register(Display display) {
    display.getRealSize(mDisplaySize);
    if (DEBUG_DRAG) Slog.d(TAG_WM, "registering drag input channel");
    if (mInputInterceptor != null) {
        Slog.e(TAG_WM, "Duplicate register of drag input channel");
    } else {
        mInputInterceptor = new InputInterceptor(display);
        mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
    }
}
 
Example 15
Source File: BarConfig.java    From a with GNU General Public License v3.0 5 votes vote down vote up
public boolean checkDeviceHasNavigationBar(Activity activity) {
    Display display = activity.getWindowManager().getDefaultDisplay();
    Point size = new Point();
    Point realSize = new Point();
    display.getSize(size);
    display.getRealSize(realSize);
    return realSize.y != size.y;
}
 
Example 16
Source File: UiDevice.java    From za-Farmer with MIT License 5 votes vote down vote up
/**
 * Returns the display size in dp (device-independent pixel)
 *
 * The returned display size is adjusted per screen rotation. Also this will return the actual
 * size of the screen, rather than adjusted per system decorations (like status bar).
 *
 * @return a Point containing the display size in dp
 */
public Point getDisplaySizeDp() {
    Tracer.trace();
    Display display = getAutomatorBridge().getDefaultDisplay();
    Point p = new Point();
    display.getRealSize(p);
    DisplayMetrics metrics = new DisplayMetrics();
    display.getRealMetrics(metrics);
    float dpx = p.x / metrics.density;
    float dpy = p.y / metrics.density;
    p.x = Math.round(dpx);
    p.y = Math.round(dpy);
    return p;
}
 
Example 17
Source File: ScaleTypeTransform.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Determines whether the current device is a natural portrait-oriented device
 *
 * <p>
 * Using the current app's window to determine whether the device is a natural
 * portrait-oriented device doesn't work in all scenarios, one example of this is multi-window
 * mode.
 * Taking a natural portrait-oriented device in multi-window mode, rotating it 90 degrees (so
 * that it's in landscape), with the app open, and its window's width being smaller than its
 * height. Using the app's width and height would determine that the device isn't
 * naturally portrait-oriented, where in fact it is, which is why it is important to use the
 * size of the device instead.
 * </p>
 *
 * @param context         Current context. Can be an {@link android.app.Application} context
 *                        or an {@link android.app.Activity} context.
 * @param rotationDegrees The device's rotation in degrees from its natural orientation.
 * @return Whether the device is naturally portrait-oriented.
 */
private static boolean isNaturalPortrait(@NonNull final Context context,
        final int rotationDegrees) {
    final WindowManager windowManager = (WindowManager) context.getSystemService(
            Context.WINDOW_SERVICE);
    if (windowManager == null) {
        return true;
    }

    final Display display = windowManager.getDefaultDisplay();
    final Point deviceSize = new Point();
    display.getRealSize(deviceSize);

    final int width = deviceSize.x;
    final int height = deviceSize.y;
    return ((rotationDegrees == 0 || rotationDegrees == 180) && width < height) || (
            (rotationDegrees == 90 || rotationDegrees == 270) && width >= height);
}
 
Example 18
Source File: BitmapUtil.java    From JsDroidCmd with Mozilla Public License 2.0 4 votes vote down vote up
public static Bitmap takeScreenshot(int rotation, int screenWidth,
		int screenHeight) {
	Display display = DisplayManagerGlobal.getInstance().getRealDisplay(
			Display.DEFAULT_DISPLAY);
	Point displaySize = new Point();
	display.getRealSize(displaySize);
	final int displayWidth = screenWidth;
	final int displayHeight = screenHeight;
	final float screenshotWidth;
	final float screenshotHeight;
	switch (rotation) {
	case UiAutomation.ROTATION_FREEZE_0: {
		screenshotWidth = displayWidth;
		screenshotHeight = displayHeight;
	}
		break;
	case UiAutomation.ROTATION_FREEZE_90: {
		screenshotWidth = displayHeight;
		screenshotHeight = displayWidth;
	}
		break;
	case UiAutomation.ROTATION_FREEZE_180: {
		screenshotWidth = displayWidth;
		screenshotHeight = displayHeight;
	}
		break;
	case UiAutomation.ROTATION_FREEZE_270: {
		screenshotWidth = displayHeight;
		screenshotHeight = displayWidth;
	}
		break;
	default: {
		return null;
	}
	}

	Bitmap screenShot = null;
	try {
		screenShot = SurfaceControl.screenshot((int) screenshotWidth,
				(int) screenshotHeight);
		if (screenShot == null) {
			return null;
		}
	} catch (Exception re) {
		return null;
	}
	if (rotation != UiAutomation.ROTATION_FREEZE_0) {
		Bitmap unrotatedScreenShot = Bitmap.createBitmap(displayWidth,
				displayHeight, Bitmap.Config.ARGB_8888);
		Canvas canvas = new Canvas(unrotatedScreenShot);
		canvas.translate(unrotatedScreenShot.getWidth() / 2,
				unrotatedScreenShot.getHeight() / 2);
		canvas.rotate(getDegreesForRotation(rotation));
		canvas.translate(-screenshotWidth / 2, -screenshotHeight / 2);
		canvas.drawBitmap(screenShot, 0, 0, null);
		canvas.setBitmap(null);
		screenShot.recycle();
		screenShot = unrotatedScreenShot;
	}
	// Optimization
	screenShot.setHasAlpha(false);
	return screenShot;
}
 
Example 19
Source File: Util.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@TargetApi(17)
private static void getDisplaySizeV17(Display display, Point outSize) {
  display.getRealSize(outSize);
}
 
Example 20
Source File: Util.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
@TargetApi(17)
private static void getDisplaySizeV17(Display display, Point outSize) {
  display.getRealSize(outSize);
}