fy.java 7.72 KB
import android.content.Context;
import android.content.res.Resources;
import android.os.Parcelable;
import android.support.v7.appcompat.R.dimen;
import android.support.v7.appcompat.R.layout;
import android.support.v7.view.menu.MenuAdapter;
import android.support.v7.view.menu.MenuBuilder;
import android.support.v7.view.menu.MenuPopupHelper;
import android.support.v7.view.menu.MenuPresenter;
import android.support.v7.view.menu.MenuPresenter.Callback;
import android.support.v7.view.menu.SubMenuBuilder;
import android.support.v7.widget.MenuPopupWindow;
import android.util.DisplayMetrics;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnKeyListener;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.FrameLayout;
import android.widget.ListView;
import android.widget.PopupWindow.OnDismissListener;
import android.widget.TextView;

public final class fy
  extends fw
  implements MenuPresenter, View.OnKeyListener, AdapterView.OnItemClickListener, PopupWindow.OnDismissListener
{
  final MenuPopupWindow a;
  View b;
  private final Context c;
  private final MenuBuilder d;
  private final MenuAdapter f;
  private final boolean g;
  private final int h;
  private final int i;
  private final int j;
  private final ViewTreeObserver.OnGlobalLayoutListener k = new ViewTreeObserver.OnGlobalLayoutListener()
  {
    public final void onGlobalLayout()
    {
      if ((fy.this.isShowing()) && (!fy.this.a.isModal()))
      {
        View localView = fy.this.b;
        if ((localView == null) || (!localView.isShown())) {
          fy.this.dismiss();
        }
      }
      else
      {
        return;
      }
      fy.this.a.show();
    }
  };
  private PopupWindow.OnDismissListener l;
  private View m;
  private MenuPresenter.Callback n;
  private ViewTreeObserver o;
  private boolean p;
  private boolean q;
  private int r;
  private int s = 0;
  private boolean t;
  
  public fy(Context paramContext, MenuBuilder paramMenuBuilder, View paramView, int paramInt1, int paramInt2, boolean paramBoolean)
  {
    this.c = paramContext;
    this.d = paramMenuBuilder;
    this.g = paramBoolean;
    this.f = new MenuAdapter(paramMenuBuilder, LayoutInflater.from(paramContext), this.g);
    this.i = paramInt1;
    this.j = paramInt2;
    Resources localResources = paramContext.getResources();
    this.h = Math.max(localResources.getDisplayMetrics().widthPixels / 2, localResources.getDimensionPixelSize(R.dimen.abc_config_prefDialogWidth));
    this.m = paramView;
    this.a = new MenuPopupWindow(this.c, null, this.i, this.j);
    paramMenuBuilder.addMenuPresenter(this, paramContext);
  }
  
  public final void a(int paramInt)
  {
    this.s = paramInt;
  }
  
  public final void a(MenuBuilder paramMenuBuilder) {}
  
  public final void a(View paramView)
  {
    this.m = paramView;
  }
  
  public final void a(PopupWindow.OnDismissListener paramOnDismissListener)
  {
    this.l = paramOnDismissListener;
  }
  
  public final void a(boolean paramBoolean)
  {
    this.f.setForceShowIcon(paramBoolean);
  }
  
  public final void b(int paramInt)
  {
    this.a.setHorizontalOffset(paramInt);
  }
  
  public final void b(boolean paramBoolean)
  {
    this.t = paramBoolean;
  }
  
  public final void c(int paramInt)
  {
    this.a.setVerticalOffset(paramInt);
  }
  
  public final void dismiss()
  {
    if (isShowing()) {
      this.a.dismiss();
    }
  }
  
  public final boolean flagActionItems()
  {
    return false;
  }
  
  public final ListView getListView()
  {
    return this.a.getListView();
  }
  
  public final boolean isShowing()
  {
    return (!this.p) && (this.a.isShowing());
  }
  
  public final void onCloseMenu(MenuBuilder paramMenuBuilder, boolean paramBoolean)
  {
    if (paramMenuBuilder != this.d) {}
    do
    {
      return;
      dismiss();
    } while (this.n == null);
    this.n.onCloseMenu(paramMenuBuilder, paramBoolean);
  }
  
  public final void onDismiss()
  {
    this.p = true;
    this.d.close();
    if (this.o != null)
    {
      if (!this.o.isAlive()) {
        this.o = this.b.getViewTreeObserver();
      }
      this.o.removeGlobalOnLayoutListener(this.k);
      this.o = null;
    }
    if (this.l != null) {
      this.l.onDismiss();
    }
  }
  
  public final boolean onKey(View paramView, int paramInt, KeyEvent paramKeyEvent)
  {
    if ((paramKeyEvent.getAction() == 1) && (paramInt == 82))
    {
      dismiss();
      return true;
    }
    return false;
  }
  
  public final void onRestoreInstanceState(Parcelable paramParcelable) {}
  
  public final Parcelable onSaveInstanceState()
  {
    return null;
  }
  
  public final boolean onSubMenuSelected(SubMenuBuilder paramSubMenuBuilder)
  {
    if (paramSubMenuBuilder.hasVisibleItems())
    {
      MenuPopupHelper localMenuPopupHelper = new MenuPopupHelper(this.c, paramSubMenuBuilder, this.b, this.g, this.i, this.j);
      localMenuPopupHelper.setPresenterCallback(this.n);
      localMenuPopupHelper.setForceShowIcon(fw.b(paramSubMenuBuilder));
      localMenuPopupHelper.setOnDismissListener(this.l);
      this.l = null;
      this.d.close(false);
      if (localMenuPopupHelper.tryShow(this.a.getHorizontalOffset(), this.a.getVerticalOffset()))
      {
        if (this.n != null) {
          this.n.onOpenSubMenu(paramSubMenuBuilder);
        }
        return true;
      }
    }
    return false;
  }
  
  public final void setCallback(MenuPresenter.Callback paramCallback)
  {
    this.n = paramCallback;
  }
  
  public final void show()
  {
    int i2 = 1;
    int i1;
    if (isShowing()) {
      i1 = i2;
    }
    while (i1 == 0)
    {
      throw new IllegalStateException("StandardMenuPopup cannot be used without an anchor");
      if ((this.p) || (this.m == null))
      {
        i1 = 0;
      }
      else
      {
        this.b = this.m;
        this.a.setOnDismissListener(this);
        this.a.setOnItemClickListener(this);
        this.a.setModal(true);
        Object localObject = this.b;
        if (this.o == null) {}
        for (i1 = 1;; i1 = 0)
        {
          this.o = ((View)localObject).getViewTreeObserver();
          if (i1 != 0) {
            this.o.addOnGlobalLayoutListener(this.k);
          }
          this.a.setAnchorView((View)localObject);
          this.a.setDropDownGravity(this.s);
          if (!this.q)
          {
            this.r = a(this.f, null, this.c, this.h);
            this.q = true;
          }
          this.a.setContentWidth(this.r);
          this.a.setInputMethodMode(2);
          this.a.setEpicenterBounds(this.e);
          this.a.show();
          localObject = this.a.getListView();
          ((ListView)localObject).setOnKeyListener(this);
          if ((this.t) && (this.d.getHeaderTitle() != null))
          {
            FrameLayout localFrameLayout = (FrameLayout)LayoutInflater.from(this.c).inflate(R.layout.abc_popup_menu_header_item_layout, (ViewGroup)localObject, false);
            TextView localTextView = (TextView)localFrameLayout.findViewById(16908310);
            if (localTextView != null) {
              localTextView.setText(this.d.getHeaderTitle());
            }
            localFrameLayout.setEnabled(false);
            ((ListView)localObject).addHeaderView(localFrameLayout, null, false);
          }
          this.a.setAdapter(this.f);
          this.a.show();
          i1 = i2;
          break;
        }
      }
    }
  }
  
  public final void updateMenuView(boolean paramBoolean)
  {
    this.q = false;
    if (this.f != null) {
      this.f.notifyDataSetChanged();
    }
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/fy.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */