Beispiel #1
0
  private void setPopupOffset(
      ListPopupWindow popup, int screenRotation, Rect appRect, Rect padding) {
    int[] anchorLocation = new int[2];
    popup.getAnchorView().getLocationInWindow(anchorLocation);
    int anchorHeight = popup.getAnchorView().getHeight();

    // If we have a hardware menu button, locate the app menu closer to the estimated
    // hardware menu button location.
    if (mIsByPermanentButton) {
      int horizontalOffset = -anchorLocation[0];
      switch (screenRotation) {
        case Surface.ROTATION_0:
        case Surface.ROTATION_180:
          horizontalOffset += (appRect.width() - mPopup.getWidth()) / 2;
          break;
        case Surface.ROTATION_90:
          horizontalOffset += appRect.width() - mPopup.getWidth();
          break;
        case Surface.ROTATION_270:
          break;
        default:
          assert false;
          break;
      }
      popup.setHorizontalOffset(horizontalOffset);
      // The menu is displayed above the anchored view, so shift the menu up by the bottom
      // padding of the background.
      popup.setVerticalOffset(-padding.bottom);
    } else {
      // The menu is displayed over and below the anchored view, so shift the menu up by the
      // height of the anchor view.
      popup.setVerticalOffset(-mNegativeSoftwareVerticalOffset - anchorHeight);
    }
  }