content: package androidx.appcompat.widget;
  
  import android.content.Context;
  import android.view.Menu;
  import android.view.MenuInflater;
  import android.view.MenuItem;
  import android.view.View;
  import android.widget.ListView;
  import android.widget.PopupWindow;
  import androidx.appcompat.R;
  import androidx.appcompat.view.SupportMenuInflater;
  import androidx.appcompat.view.menu.MenuBuilder;
  import androidx.appcompat.view.menu.MenuPopupHelper;
  import androidx.appcompat.view.menu.ShowableListMenu;
  
  public class PopupMenu {
      private final View mAnchor;
      private final Context mContext;
      private View.OnTouchListener mDragListener;
      private final MenuBuilder mMenu;
      OnMenuItemClickListener mMenuItemClickListener;
      OnDismissListener mOnDismissListener;
      final MenuPopupHelper mPopup;
  
      public interface OnDismissListener {
          void onDismiss(PopupMenu popupMenu);
      }
  
      public interface OnMenuItemClickListener {
          boolean onMenuItemClick(MenuItem menuItem);
      }
  
      public PopupMenu(Context context, View anchor) {
          this(context, anchor, 0);
      }
  
      public PopupMenu(Context context, View anchor, int gravity) {
          this(context, anchor, gravity, R.attr.popupMenuStyle, 0);
      }
  
      public PopupMenu(Context context, View anchor, int gravity, int popupStyleAttr, int popupStyleRes) {
          this.mContext = context;
          this.mAnchor = anchor;
          MenuBuilder menuBuilder = new MenuBuilder(context);
          this.mMenu = menuBuilder;
          menuBuilder.setCallback(new MenuBuilder.Callback() {
              public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {
                  if (PopupMenu.this.mMenuItemClickListener != null) {
                      return PopupMenu.this.mMenuItemClickListener.onMenuItemClick(item);
                  }
                  return false;
              }
  
              public void onMenuModeChange(MenuBuilder menu) {
              }
          });
          MenuPopupHelper menuPopupHelper = new MenuPopupHelper(context, menuBuilder, anchor, false, popupStyleAttr, popupStyleRes);
          this.mPopup = menuPopupHelper;
          menuPopupHelper.setGravity(gravity);
          menuPopupHelper.setOnDismissListener(new PopupWindow.OnDismissListener() {
              public void onDismiss() {
                  if (PopupMenu.this.mOnDismissListener != null) {
                      PopupMenu.this.mOnDismissListener.onDismiss(PopupMenu.this);
                  }
              }
          });
      }
  
      public void dismiss() {
          this.mPopup.dismiss();
      }
  
      public View.OnTouchListener getDragToOpenListener() {
          if (this.mDragListener == null) {
              this.mDragListener = new ForwardingListener(this.mAnchor) {
                  public ShowableListMenu getPopup() {
                      return PopupMenu.this.mPopup.getPopup();
                  }
  
                  /* access modifiers changed from: protected */
                  public boolean onForwardingStarted() {
                      PopupMenu.this.show();
                      return true;
                  }
  
                  /* access modifiers changed from: protected */
                  public boolean onForwardingStopped() {
                      PopupMenu.this.dismiss();
                      return true;
                  }
              };
          }
          return this.mDragListener;
      }
  
      public int getGravity() {
          return this.mPopup.getGravity();
      }
  
      public Menu getMenu() {
          return this.mMenu;
      }
  
      public MenuInflater getMenuInflater() {
          return new SupportMenuInflater(this.mContext);
      }
  
      /* access modifiers changed from: package-private */
      public ListView getMenuListView() {
          if (!this.mPopup.isShowing()) {
              return null;
          }
          return this.mPopup.getListView();
      }
  
      public void inflate(int menuRes) {
          getMenuInflater().inflate(menuRes, this.mMenu);
      }
  
      public void setForceShowIcon(boolean forceShowIcon) {
          this.mPopup.setForceShowIcon(forceShowIcon);
      }
  
      public void setGravity(int gravity) {
          this.mPopup.setGravity(gravity);
      }
  
      public void setOnDismissListener(OnDismissListener listener) {
          this.mOnDismissListener = listener;
      }
  
      public void setOnMenuItemClickListener(OnMenuItemClickListener listener) {
          this.mMenuItemClickListener = listener;
      }
  
      public void show() {
          this.mPopup.show();
      }
  }
  