@SuppressWarnings("deprecation")
  public boolean isDisplayedOnViewport(View view) {
    int coordinates[] = {-1, -1};
    int width = 0, height = 0;

    view.getLocationOnScreen(coordinates);
    if (coordinates[0] + view.getWidth() < 0) return false;
    if (coordinates[1] + view.getHeight() < 0) return false;

    if (width == 0 || height == 0) {
      if (instrumentation.getInstrumentation().getContext() == null) return false;
      Display display =
          ((WindowManager) instrumentation.getInstrumentation().getContext().getSystemService(Context.WINDOW_SERVICE))
              .getDefaultDisplay();
      try {
        android.graphics.Point screenSize = new android.graphics.Point();
        display.getSize(screenSize);
        width = screenSize.x;
        height = screenSize.y;
      } catch (NoSuchMethodError e) {
        width = display.getWidth();
        height = display.getHeight();
      }
    }

    if (coordinates[0] > width) return false;
    if (coordinates[1] > height) return false;

    return true;
  }
@deprecated Please use new implemented extension mechanism
@see <a href="https://github.com/selendroid/selendroid-extension">extension mechanism Docu</a>
selendroid-server/src/main/java/io/selendroid/server/model/internal/execute_native/IsElementDisplayedInViewport.java