166 lines
4.6 KiB
Java
166 lines
4.6 KiB
Java
package androidx.appcompat.view.menu;
|
|
|
|
import android.content.Context;
|
|
import android.graphics.Point;
|
|
import android.graphics.Rect;
|
|
import android.os.Build;
|
|
import android.view.Display;
|
|
import android.view.View;
|
|
import android.view.WindowManager;
|
|
import android.widget.PopupWindow;
|
|
import androidx.appcompat.R$dimen;
|
|
import androidx.appcompat.view.menu.MenuPresenter;
|
|
import androidx.core.view.GravityCompat;
|
|
import androidx.core.view.ViewCompat;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class MenuPopupHelper implements MenuHelper {
|
|
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;
|
|
private boolean h;
|
|
private MenuPresenter.Callback i;
|
|
private MenuPopup j;
|
|
private PopupWindow.OnDismissListener k;
|
|
private final PopupWindow.OnDismissListener l;
|
|
|
|
public MenuPopupHelper(Context context, MenuBuilder menuBuilder, View view, boolean z, int i) {
|
|
this(context, menuBuilder, view, z, i, 0);
|
|
}
|
|
|
|
private MenuPopup g() {
|
|
Display defaultDisplay = ((WindowManager) this.a.getSystemService("window")).getDefaultDisplay();
|
|
Point point = new Point();
|
|
if (Build.VERSION.SDK_INT >= 17) {
|
|
defaultDisplay.getRealSize(point);
|
|
} else {
|
|
defaultDisplay.getSize(point);
|
|
}
|
|
MenuPopup cascadingMenuPopup = Math.min(point.x, point.y) >= this.a.getResources().getDimensionPixelSize(R$dimen.abc_cascading_menus_min_smallest_width) ? new CascadingMenuPopup(this.a, this.f, this.d, this.e, this.c) : new StandardMenuPopup(this.a, this.b, this.f, this.d, this.e, this.c);
|
|
cascadingMenuPopup.a(this.b);
|
|
cascadingMenuPopup.a(this.l);
|
|
cascadingMenuPopup.a(this.f);
|
|
cascadingMenuPopup.a(this.i);
|
|
cascadingMenuPopup.b(this.h);
|
|
cascadingMenuPopup.a(this.g);
|
|
return cascadingMenuPopup;
|
|
}
|
|
|
|
public void a(PopupWindow.OnDismissListener onDismissListener) {
|
|
this.k = onDismissListener;
|
|
}
|
|
|
|
public MenuPopup b() {
|
|
if (this.j == null) {
|
|
this.j = g();
|
|
}
|
|
return this.j;
|
|
}
|
|
|
|
public boolean c() {
|
|
MenuPopup menuPopup = this.j;
|
|
return menuPopup != null && menuPopup.c();
|
|
}
|
|
|
|
protected void d() {
|
|
this.j = null;
|
|
PopupWindow.OnDismissListener onDismissListener = this.k;
|
|
if (onDismissListener != null) {
|
|
onDismissListener.onDismiss();
|
|
}
|
|
}
|
|
|
|
public void e() {
|
|
if (!f()) {
|
|
throw new IllegalStateException("MenuPopupHelper cannot be used without an anchor");
|
|
}
|
|
}
|
|
|
|
public boolean f() {
|
|
if (c()) {
|
|
return true;
|
|
}
|
|
if (this.f == null) {
|
|
return false;
|
|
}
|
|
a(0, 0, false, false);
|
|
return true;
|
|
}
|
|
|
|
public MenuPopupHelper(Context context, MenuBuilder menuBuilder, View view, boolean z, int i, int i2) {
|
|
this.g = 8388611;
|
|
this.l = new PopupWindow.OnDismissListener() { // from class: androidx.appcompat.view.menu.MenuPopupHelper.1
|
|
@Override // android.widget.PopupWindow.OnDismissListener
|
|
public void onDismiss() {
|
|
MenuPopupHelper.this.d();
|
|
}
|
|
};
|
|
this.a = context;
|
|
this.b = menuBuilder;
|
|
this.f = view;
|
|
this.c = z;
|
|
this.d = i;
|
|
this.e = i2;
|
|
}
|
|
|
|
public void a(View view) {
|
|
this.f = view;
|
|
}
|
|
|
|
public void a(boolean z) {
|
|
this.h = z;
|
|
MenuPopup menuPopup = this.j;
|
|
if (menuPopup != null) {
|
|
menuPopup.b(z);
|
|
}
|
|
}
|
|
|
|
public void a(int i) {
|
|
this.g = i;
|
|
}
|
|
|
|
public boolean a(int i, int i2) {
|
|
if (c()) {
|
|
return true;
|
|
}
|
|
if (this.f == null) {
|
|
return false;
|
|
}
|
|
a(i, i2, true, true);
|
|
return true;
|
|
}
|
|
|
|
private void a(int i, int i2, boolean z, boolean z2) {
|
|
MenuPopup b = b();
|
|
b.c(z2);
|
|
if (z) {
|
|
if ((GravityCompat.a(this.g, ViewCompat.k(this.f)) & 7) == 5) {
|
|
i -= this.f.getWidth();
|
|
}
|
|
b.b(i);
|
|
b.c(i2);
|
|
int i3 = (int) ((this.a.getResources().getDisplayMetrics().density * 48.0f) / 2.0f);
|
|
b.a(new Rect(i - i3, i2 - i3, i + i3, i2 + i3));
|
|
}
|
|
b.a();
|
|
}
|
|
|
|
public void a() {
|
|
if (c()) {
|
|
this.j.dismiss();
|
|
}
|
|
}
|
|
|
|
public void a(MenuPresenter.Callback callback) {
|
|
this.i = callback;
|
|
MenuPopup menuPopup = this.j;
|
|
if (menuPopup != null) {
|
|
menuPopup.a(callback);
|
|
}
|
|
}
|
|
}
|