private int getPosY(boolean needCloseMenu) {
    if (needCloseMenu) {
      return screenHeight;
    }

    int destinationState;
    int minHalfY;
    if (menu.isExtended()) {
      destinationState = menu.getCurrentMenuState();
      minHalfY = viewHeight - (int) (viewHeight * menu.getHalfScreenMaxHeightKoef());
    } else {
      destinationState = MenuState.HEADER_ONLY;
      minHalfY = viewHeight;
    }

    int posY = 0;
    switch (destinationState) {
      case MenuState.HEADER_ONLY:
        posY = viewHeight - menuTitleHeight;
        break;
      case MenuState.HALF_SCREEN:
        posY = viewHeight - menuFullHeightMax;
        posY = Math.max(posY, minHalfY);
        break;
      case MenuState.FULL_SCREEN:
        posY = -menuTopShadowHeight - dpToPx(SHADOW_HEIGHT_TOP_DP);
        break;
      default:
        break;
    }
    return posY;
  }
  public static boolean showInstance(
      final MapContextMenu menu, final MainActivity mainActivity, final boolean centered) {
    try {

      if (menu.getLatLon() == null) {
        return false;
      }

      int slideInAnim = R.anim.slide_in_bottom;
      int slideOutAnim = R.anim.slide_out_bottom;

      if (menu.isExtended()) {
        slideInAnim = menu.getSlideInAnimation();
        slideOutAnim = menu.getSlideOutAnimation();
      }

      MapContextMenuFragment fragment = new MapContextMenuFragment();
      fragment.centered = centered;
      mainActivity
          .getSupportFragmentManager()
          .beginTransaction()
          .setCustomAnimations(slideInAnim, slideOutAnim, slideInAnim, slideOutAnim)
          .add(R.id.fragmentContainer, fragment, TAG)
          .addToBackStack(TAG)
          .commitAllowingStateLoss();

      return true;

    } catch (RuntimeException e) {
      return false;
    }
  }
 private void buildBottomView() {
   View bottomView = view.findViewById(R.id.context_menu_bottom_view);
   if (menu.isExtended()) {
     bottomView.setOnTouchListener(
         new View.OnTouchListener() {
           @Override
           public boolean onTouch(View v, MotionEvent event) {
             return true;
           }
         });
     menu.build(bottomView);
   }
 }
  public static void showInstance(final MapActivity mapActivity) {

    int slideInAnim = R.anim.slide_in_bottom;
    int slideOutAnim = R.anim.slide_out_bottom;

    MapContextMenu menu = mapActivity.getContextMenu();
    if (menu.isExtended()) {
      slideInAnim = menu.getSlideInAnimation();
      slideOutAnim = menu.getSlideOutAnimation();
    }

    MapContextMenuFragment fragment = new MapContextMenuFragment();
    mapActivity
        .getSupportFragmentManager()
        .beginTransaction()
        .setCustomAnimations(slideInAnim, slideOutAnim, slideInAnim, slideOutAnim)
        .add(R.id.fragmentContainer, fragment, TAG)
        .addToBackStack(TAG)
        .commit();
  }