gt:         if (showMenuRunnable != null) {
context: /*
   * This is the source code of Telegram for Android v. 3.x.x.
   * It is licensed under GNU GPL v. 2 or later.
   * You should have received a copy of the license in this archive (see LICENSE).
   *
   * Copyright Nikolai Kudashov, 2013-2016.
   */
  
  package org.telegram.ui.ActionBar;
  
  import android.content.Context;
  import android.graphics.Rect;
  import android.os.Build;
  import android.text.Editable;
  import android.text.TextWatcher;
  import android.util.TypedValue;
  import android.view.ActionMode;
  import android.view.ContextMenu;
  import android.view.Gravity;
  import android.view.KeyEvent;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.MotionEvent;
  import android.view.View;
  import android.view.WindowManager;
  import android.view.inputmethod.EditorInfo;
  import android.widget.EditText;
  import android.widget.FrameLayout;
  import android.widget.ImageView;
  import android.widget.LinearLayout;
  import android.widget.TextView;
  
  import org.telegram.messenger.AndroidUtilities;
  import org.telegram.messenger.LocaleController;
  import org.telegram.messenger.R;
  import org.telegram.messenger.AnimationCompat.ViewProxy;
  import org.telegram.ui.Components.FrameLayoutFixed;
  import org.telegram.ui.Components.LayoutHelper;
  
  import java.lang.reflect.Field;
  
  public class ActionBarMenuItem extends FrameLayoutFixed {
  
      public static class ActionBarMenuItemSearchListener {
          public void onSearchExpand() {
          }
  
          public boolean canCollapseSearch() {
              return true;
          }
  
          public void onSearchCollapse() {
  
          }
  
          public void onTextChanged(EditText editText) {
          }
  
          public void onSearchPressed(EditText editText) {
          }
      }
  
      public interface ActionBarMenuItemDelegate {
          void onItemClick(int id);
      }
  
      private ActionBarPopupWindow.ActionBarPopupWindowLayout popupLayout;
      private ActionBarMenu parentMenu;
      private ActionBarPopupWindow popupWindow;
      private EditText searchField;
      private ImageView clearButton;
      protected ImageView iconView;
      private FrameLayout searchContainer;
      private boolean isSearchField = false;
      private ActionBarMenuItemSearchListener listener;
      private Rect rect;
      private int[] location;
      private View selectedMenuView;
      private Runnable showMenuRunnable;
      private boolean showFromBottom;
      private int menuHeight = AndroidUtilities.dp(16);
      private int subMenuOpenSide = 0;
      private ActionBarMenuItemDelegate delegate;
      private boolean allowCloseAnimation = true;
      protected boolean overrideMenuClick;
      private boolean processedPopupClick;
  
      public ActionBarMenuItem(Context context, ActionBarMenu menu, int background) {
          super(context);
          setBackgroundResource(background);
          parentMenu = menu;
  
          iconView = new ImageView(context);
          iconView.setScaleType(ImageView.ScaleType.CENTER);
          addView(iconView);
          LayoutParams layoutParams = (LayoutParams) iconView.getLayoutParams();
          layoutParams.width = LayoutHelper.MATCH_PARENT;
          layoutParams.height = LayoutHelper.MATCH_PARENT;
          iconView.setLayoutParams(layoutParams);
      }
  
      @Override
      public boolean onTouchEvent(MotionEvent event) {
          if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
              if (hasSubMenu() && (popupWindow == null || popupWindow != null && !popupWindow.isShowing())) {
                  showMenuRunnable = new Runnable() {
                      @Override
                      public void run() {
                          if (getParent() != null) {
                              getParent().requestDisallowInterceptTouchEvent(true);
                          }
                          toggleSubMenu();
                      }
                  };
                  AndroidUtilities.runOnUIThread(showMenuRunnable, 200);
              }
          } else if (event.getActionMasked() == MotionEvent.ACTION_MOVE) {
              if (hasSubMenu() && (popupWindow == null || popupWindow != null && !popupWindow.isShowing())) {
                  if (event.getY() > getHeight()) {
                      if (getParent() != null) {
                          getParent().requestDisallowInterceptTouchEvent(true);
                      }
                      toggleSubMenu();
                      return true;
                  }
              } else if (popupWindow != null && popupWindow.isShowing()) {
                  getLocationOnScreen(location);
                  float x = event.getX() + location[0];
                  float y = event.getY() + location[1];
                  popupLayout.getLocationOnScreen(location);
                  x -= location[0];
                  y -= location[1];
                  selectedMenuView = null;
                  for (int a = 0; a < popupLayout.getItemsCount(); a++) {
                      View child = popupLayout.getItemAt(a);
                      child.getHitRect(rect);
                      if ((Integer) child.getTag() < 100) {
                          if (!rect.contains((int) x, (int) y)) {
                              child.setPressed(false);
                              child.setSelected(false);
                              if (Build.VERSION.SDK_INT == 21) {
                                  child.getBackground().setVisible(false, false);
                              }
                          } else {
                              child.setPressed(true);
                              child.setSelected(true);
                              if (Build.VERSION.SDK_INT >= 21) {
                                  if (Build.VERSION.SDK_INT == 21) {
                                      child.getBackground().setVisible(true, false);
                                  }
                                  child.drawableHotspotChanged(x, y - child.getTop());
                              }
                              selectedMenuView = child;
                          }
                      }
                  }
              }
          } else if (popupWindow != null && popupWindow.isShowing() && event.getActionMasked() == MotionEvent.ACTION_UP) {
              if (selectedMenuView != null) {
                  selectedMenuView.setSelected(false);
                  if (parentMenu != null) {
                      parentMenu.onItemClick((Integer) selectedMenuView.getTag());
                  } else if (delegate != null) {
                      delegate.onItemClick((Integer) selectedMenuView.getTag());
                  }
                  popupWindow.dismiss(allowCloseAnimation);
              } else {
                  popupWindow.dismiss();
              }
          } else {
              if (selectedMenuView != null) {
                  selectedMenuView.setSelected(false);
                  selectedMenuView = null;
              }
          }
          return super.onTouchEvent(event);
      }
  
      public void setDelegate(ActionBarMenuItemDelegate delegate) {
          this.delegate = delegate;
      }
  
      public void setShowFromBottom(boolean value) {
          showFromBottom = value;
          if (popupLayout != null) {
              popupLayout.setShowedFromBotton(showFromBottom);
          }
      }
  
      public void setSubMenuOpenSide(int side) {
          subMenuOpenSide = side;
      }
  
      public TextView addSubItem(int id, String text, int icon) {
          if (popupLayout == null) {
              rect = new Rect();
              location = new int[2];
              popupLayout = new ActionBarPopupWindow.ActionBarPopupWindowLayout(getContext());
              popupLayout.setOnTouchListener(new OnTouchListener() {
                  @Override
                  public boolean onTouch(View v, MotionEvent event) {
                      if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
                          if (popupWindow != null && popupWindow.isShowing()) {
                              v.getHitRect(rect);
                              if (!rect.contains((int) event.getX(), (int) event.getY())) {
                                  popupWindow.dismiss();
                              }
                          }
                      }
                      return false;
                  }
              });
              popupLayout.setDispatchKeyEventListener(new ActionBarPopupWindow.OnDispatchKeyEventListener() {
                  @Override
                  public void onDispatchKeyEvent(KeyEvent keyEvent) {
                      if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_BACK && keyEvent.getRepeatCount() == 0 && popupWindow != null && popupWindow.isShowing()) {
                          popupWindow.dismiss();
                      }
                  }
              });
          }
          TextView textView = new TextView(getContext());
          textView.setTextColor(0xff212121);
          textView.setBackgroundResource(R.drawable.list_selector);
          if (!LocaleController.isRTL) {
              textView.setGravity(Gravity.CENTER_VERTICAL);
          } else {
              textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);
          }
          textView.setPadding(AndroidUtilities.dp(16), 0, AndroidUtilities.dp(16), 0);
          textView.setTextSize(18);
          textView.setMinWidth(AndroidUtilities.dp(196));
          textView.setTag(id);
          textView.setText(text);
          if (icon != 0) {
              textView.setCompoundDrawablePadding(AndroidUtilities.dp(12));
              if (!LocaleController.isRTL) {
                  textView.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(icon), null, null, null);
              } else {
                  textView.setCompoundDrawablesWithIntrinsicBounds(null, null, getResources().getDrawable(icon), null);
              }
          }
          popupLayout.setShowedFromBotton(showFromBottom);
          popupLayout.addView(textView);
          LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) textView.getLayoutParams();
          if (LocaleController.isRTL) {
              layoutParams.gravity = Gravity.RIGHT;
          }
          layoutParams.width = LayoutHelper.MATCH_PARENT;
          layoutParams.height = AndroidUtilities.dp(48);
          textView.setLayoutParams(layoutParams);
          textView.setOnClickListener(new OnClickListener() {
              @Override
              public void onClick(View view) {
                  if (popupWindow != null && popupWindow.isShowing()) {
                      if (processedPopupClick) {
                          return;
                      }
                      processedPopupClick = true;
                      popupWindow.dismiss(allowCloseAnimation);
                  }
                  if (parentMenu != null) {
                      parentMenu.onItemClick((Integer) view.getTag());
                  } else if (delegate != null) {
                      delegate.onItemClick((Integer) view.getTag());
                  }
              }
          });
          menuHeight += layoutParams.height;
          return textView;
      }
  
      public boolean hasSubMenu() {
          return popupLayout != null;
      }
  
      public void toggleSubMenu() {
          if (popupLayout == null) {
              return;
          }
  