code: public static Rect getFrame(Activity a) {
          Rect frame = new Rect();
          a.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
          return frame;
      }
docs: Get the {@link View#getWindowVisibleDisplayFrame(Rect) visible area} of the Activity's
  Window. The height of screen decorations above the Window can be found in {@link Rect#top}.