MenuPopupHelper.java 6.23 KB
package android.support.v7.view.menu;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Point;
import android.graphics.Rect;
import android.os.Build.VERSION;
import android.support.annotation.AttrRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RestrictTo;
import android.support.annotation.StyleRes;
import android.support.v4.view.GravityCompat;
import android.support.v4.view.ViewCompat;
import android.support.v7.appcompat.R.attr;
import android.support.v7.appcompat.R.dimen;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import android.widget.PopupWindow.OnDismissListener;
import fw;
import fy;

@RestrictTo({android.support.annotation.RestrictTo.Scope.LIBRARY_GROUP})
public class MenuPopupHelper
{
  private final Context a;
  private final MenuBuilder b;
  private final boolean c;
  private final int d;
  private final int e;
  private View f;
  private int g = 8388611;
  private boolean h;
  private MenuPresenter.Callback i;
  private fw j;
  private PopupWindow.OnDismissListener k;
  private final PopupWindow.OnDismissListener l = new PopupWindow.OnDismissListener()
  {
    public final void onDismiss()
    {
      MenuPopupHelper.this.onDismiss();
    }
  };
  
  public MenuPopupHelper(@NonNull Context paramContext, @NonNull MenuBuilder paramMenuBuilder)
  {
    this(paramContext, paramMenuBuilder, null, false, R.attr.popupMenuStyle, 0);
  }
  
  public MenuPopupHelper(@NonNull Context paramContext, @NonNull MenuBuilder paramMenuBuilder, @NonNull View paramView)
  {
    this(paramContext, paramMenuBuilder, paramView, false, R.attr.popupMenuStyle, 0);
  }
  
  public MenuPopupHelper(@NonNull Context paramContext, @NonNull MenuBuilder paramMenuBuilder, @NonNull View paramView, boolean paramBoolean, @AttrRes int paramInt)
  {
    this(paramContext, paramMenuBuilder, paramView, paramBoolean, paramInt, 0);
  }
  
  public MenuPopupHelper(@NonNull Context paramContext, @NonNull MenuBuilder paramMenuBuilder, @NonNull View paramView, boolean paramBoolean, @AttrRes int paramInt1, @StyleRes int paramInt2)
  {
    this.a = paramContext;
    this.b = paramMenuBuilder;
    this.f = paramView;
    this.c = paramBoolean;
    this.d = paramInt1;
    this.e = paramInt2;
  }
  
  private void a(int paramInt1, int paramInt2, boolean paramBoolean1, boolean paramBoolean2)
  {
    fw localfw = getPopup();
    localfw.b(paramBoolean2);
    if (paramBoolean1)
    {
      int m = paramInt1;
      if ((GravityCompat.getAbsoluteGravity(this.g, ViewCompat.getLayoutDirection(this.f)) & 0x7) == 5) {
        m = paramInt1 - this.f.getWidth();
      }
      localfw.b(m);
      localfw.c(paramInt2);
      paramInt1 = (int)(this.a.getResources().getDisplayMetrics().density * 48.0F / 2.0F);
      localfw.e = new Rect(m - paramInt1, paramInt2 - paramInt1, m + paramInt1, paramInt1 + paramInt2);
    }
    localfw.show();
  }
  
  public void dismiss()
  {
    if (isShowing()) {
      this.j.dismiss();
    }
  }
  
  public int getGravity()
  {
    return this.g;
  }
  
  @NonNull
  public fw getPopup()
  {
    Point localPoint;
    int m;
    if (this.j == null)
    {
      localObject = ((WindowManager)this.a.getSystemService("window")).getDefaultDisplay();
      localPoint = new Point();
      if (Build.VERSION.SDK_INT < 17) {
        break label165;
      }
      ((Display)localObject).getRealSize(localPoint);
      if (Math.min(localPoint.x, localPoint.y) < this.a.getResources().getDimensionPixelSize(R.dimen.abc_cascading_menus_min_smallest_width)) {
        break label196;
      }
      m = 1;
      label75:
      if (m == 0) {
        break label201;
      }
    }
    label165:
    label196:
    label201:
    for (Object localObject = new CascadingMenuPopup(this.a, this.f, this.d, this.e, this.c);; localObject = new fy(this.a, this.b, this.f, this.d, this.e, this.c))
    {
      ((fw)localObject).a(this.b);
      ((fw)localObject).a(this.l);
      ((fw)localObject).a(this.f);
      ((fw)localObject).setCallback(this.i);
      ((fw)localObject).a(this.h);
      ((fw)localObject).a(this.g);
      this.j = ((fw)localObject);
      return this.j;
      if (Build.VERSION.SDK_INT >= 13)
      {
        ((Display)localObject).getSize(localPoint);
        break;
      }
      localPoint.set(((Display)localObject).getWidth(), ((Display)localObject).getHeight());
      break;
      m = 0;
      break label75;
    }
  }
  
  public boolean isShowing()
  {
    return (this.j != null) && (this.j.isShowing());
  }
  
  protected void onDismiss()
  {
    this.j = null;
    if (this.k != null) {
      this.k.onDismiss();
    }
  }
  
  public void setAnchorView(@NonNull View paramView)
  {
    this.f = paramView;
  }
  
  public void setForceShowIcon(boolean paramBoolean)
  {
    this.h = paramBoolean;
    if (this.j != null) {
      this.j.a(paramBoolean);
    }
  }
  
  public void setGravity(int paramInt)
  {
    this.g = paramInt;
  }
  
  public void setOnDismissListener(@Nullable PopupWindow.OnDismissListener paramOnDismissListener)
  {
    this.k = paramOnDismissListener;
  }
  
  public void setPresenterCallback(@Nullable MenuPresenter.Callback paramCallback)
  {
    this.i = paramCallback;
    if (this.j != null) {
      this.j.setCallback(paramCallback);
    }
  }
  
  public void show()
  {
    if (!tryShow()) {
      throw new IllegalStateException("MenuPopupHelper cannot be used without an anchor");
    }
  }
  
  public void show(int paramInt1, int paramInt2)
  {
    if (!tryShow(paramInt1, paramInt2)) {
      throw new IllegalStateException("MenuPopupHelper cannot be used without an anchor");
    }
  }
  
  public boolean tryShow()
  {
    if (isShowing()) {
      return true;
    }
    if (this.f == null) {
      return false;
    }
    a(0, 0, false, false);
    return true;
  }
  
  public boolean tryShow(int paramInt1, int paramInt2)
  {
    if (isShowing()) {
      return true;
    }
    if (this.f == null) {
      return false;
    }
    a(paramInt1, paramInt2, true, true);
    return true;
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/android/support/v7/view/menu/MenuPopupHelper.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */