jimu-decompiled/sources/androidx/appcompat/app/WindowDecorActionBar.java
2025-05-13 19:24:51 +02:00

724 lines
25 KiB
Java

package androidx.appcompat.app;
import android.R;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.util.TypedValue;
import android.view.ContextThemeWrapper;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import androidx.appcompat.R$attr;
import androidx.appcompat.R$id;
import androidx.appcompat.R$styleable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.view.ActionBarPolicy;
import androidx.appcompat.view.ActionMode;
import androidx.appcompat.view.SupportMenuInflater;
import androidx.appcompat.view.ViewPropertyAnimatorCompatSet;
import androidx.appcompat.view.menu.MenuBuilder;
import androidx.appcompat.widget.ActionBarContainer;
import androidx.appcompat.widget.ActionBarContextView;
import androidx.appcompat.widget.ActionBarOverlayLayout;
import androidx.appcompat.widget.DecorToolbar;
import androidx.appcompat.widget.ScrollingTabContainerView;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.ViewCompat;
import androidx.core.view.ViewPropertyAnimatorCompat;
import androidx.core.view.ViewPropertyAnimatorListener;
import androidx.core.view.ViewPropertyAnimatorListenerAdapter;
import androidx.core.view.ViewPropertyAnimatorUpdateListener;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
/* loaded from: classes.dex */
public class WindowDecorActionBar extends ActionBar implements ActionBarOverlayLayout.ActionBarVisibilityCallback {
private static final Interpolator B = new AccelerateInterpolator();
private static final Interpolator C = new DecelerateInterpolator();
final ViewPropertyAnimatorUpdateListener A;
Context a;
private Context b;
ActionBarOverlayLayout c;
ActionBarContainer d;
DecorToolbar e;
ActionBarContextView f;
View g;
ScrollingTabContainerView h;
private boolean i;
ActionModeImpl j;
ActionMode k;
ActionMode.Callback l;
private boolean m;
private ArrayList<ActionBar.OnMenuVisibilityListener> n;
private boolean o;
private int p;
boolean q;
boolean r;
boolean s;
private boolean t;
private boolean u;
ViewPropertyAnimatorCompatSet v;
private boolean w;
boolean x;
final ViewPropertyAnimatorListener y;
final ViewPropertyAnimatorListener z;
public class ActionModeImpl extends ActionMode implements MenuBuilder.Callback {
private final Context c;
private final MenuBuilder d;
private ActionMode.Callback e;
private WeakReference<View> f;
public ActionModeImpl(Context context, ActionMode.Callback callback) {
this.c = context;
this.e = callback;
MenuBuilder menuBuilder = new MenuBuilder(context);
menuBuilder.c(1);
this.d = menuBuilder;
this.d.a(this);
}
@Override // androidx.appcompat.view.ActionMode
public void a() {
WindowDecorActionBar windowDecorActionBar = WindowDecorActionBar.this;
if (windowDecorActionBar.j != this) {
return;
}
if (WindowDecorActionBar.a(windowDecorActionBar.r, windowDecorActionBar.s, false)) {
this.e.a(this);
} else {
WindowDecorActionBar windowDecorActionBar2 = WindowDecorActionBar.this;
windowDecorActionBar2.k = this;
windowDecorActionBar2.l = this.e;
}
this.e = null;
WindowDecorActionBar.this.e(false);
WindowDecorActionBar.this.f.a();
WindowDecorActionBar.this.e.l().sendAccessibilityEvent(32);
WindowDecorActionBar windowDecorActionBar3 = WindowDecorActionBar.this;
windowDecorActionBar3.c.setHideOnContentScrollEnabled(windowDecorActionBar3.x);
WindowDecorActionBar.this.j = null;
}
@Override // androidx.appcompat.view.ActionMode
public void b(CharSequence charSequence) {
WindowDecorActionBar.this.f.setTitle(charSequence);
}
@Override // androidx.appcompat.view.ActionMode
public Menu c() {
return this.d;
}
@Override // androidx.appcompat.view.ActionMode
public MenuInflater d() {
return new SupportMenuInflater(this.c);
}
@Override // androidx.appcompat.view.ActionMode
public CharSequence e() {
return WindowDecorActionBar.this.f.getSubtitle();
}
@Override // androidx.appcompat.view.ActionMode
public CharSequence g() {
return WindowDecorActionBar.this.f.getTitle();
}
@Override // androidx.appcompat.view.ActionMode
public void i() {
if (WindowDecorActionBar.this.j != this) {
return;
}
this.d.s();
try {
this.e.b(this, this.d);
} finally {
this.d.r();
}
}
@Override // androidx.appcompat.view.ActionMode
public boolean j() {
return WindowDecorActionBar.this.f.b();
}
public boolean k() {
this.d.s();
try {
return this.e.a(this, this.d);
} finally {
this.d.r();
}
}
@Override // androidx.appcompat.view.ActionMode
public void b(int i) {
b(WindowDecorActionBar.this.a.getResources().getString(i));
}
@Override // androidx.appcompat.view.ActionMode
public View b() {
WeakReference<View> weakReference = this.f;
if (weakReference != null) {
return weakReference.get();
}
return null;
}
@Override // androidx.appcompat.view.ActionMode
public void a(View view) {
WindowDecorActionBar.this.f.setCustomView(view);
this.f = new WeakReference<>(view);
}
@Override // androidx.appcompat.view.ActionMode
public void a(CharSequence charSequence) {
WindowDecorActionBar.this.f.setSubtitle(charSequence);
}
@Override // androidx.appcompat.view.ActionMode
public void a(int i) {
a((CharSequence) WindowDecorActionBar.this.a.getResources().getString(i));
}
@Override // androidx.appcompat.view.ActionMode
public void a(boolean z) {
super.a(z);
WindowDecorActionBar.this.f.setTitleOptional(z);
}
@Override // androidx.appcompat.view.menu.MenuBuilder.Callback
public boolean a(MenuBuilder menuBuilder, MenuItem menuItem) {
ActionMode.Callback callback = this.e;
if (callback != null) {
return callback.a(this, menuItem);
}
return false;
}
@Override // androidx.appcompat.view.menu.MenuBuilder.Callback
public void a(MenuBuilder menuBuilder) {
if (this.e == null) {
return;
}
i();
WindowDecorActionBar.this.f.d();
}
}
public WindowDecorActionBar(Activity activity, boolean z) {
new ArrayList();
this.n = new ArrayList<>();
this.p = 0;
this.q = true;
this.u = true;
this.y = new ViewPropertyAnimatorListenerAdapter() { // from class: androidx.appcompat.app.WindowDecorActionBar.1
@Override // androidx.core.view.ViewPropertyAnimatorListener
public void b(View view) {
View view2;
WindowDecorActionBar windowDecorActionBar = WindowDecorActionBar.this;
if (windowDecorActionBar.q && (view2 = windowDecorActionBar.g) != null) {
view2.setTranslationY(0.0f);
WindowDecorActionBar.this.d.setTranslationY(0.0f);
}
WindowDecorActionBar.this.d.setVisibility(8);
WindowDecorActionBar.this.d.setTransitioning(false);
WindowDecorActionBar windowDecorActionBar2 = WindowDecorActionBar.this;
windowDecorActionBar2.v = null;
windowDecorActionBar2.l();
ActionBarOverlayLayout actionBarOverlayLayout = WindowDecorActionBar.this.c;
if (actionBarOverlayLayout != null) {
ViewCompat.B(actionBarOverlayLayout);
}
}
};
this.z = new ViewPropertyAnimatorListenerAdapter() { // from class: androidx.appcompat.app.WindowDecorActionBar.2
@Override // androidx.core.view.ViewPropertyAnimatorListener
public void b(View view) {
WindowDecorActionBar windowDecorActionBar = WindowDecorActionBar.this;
windowDecorActionBar.v = null;
windowDecorActionBar.d.requestLayout();
}
};
this.A = new ViewPropertyAnimatorUpdateListener() { // from class: androidx.appcompat.app.WindowDecorActionBar.3
@Override // androidx.core.view.ViewPropertyAnimatorUpdateListener
public void a(View view) {
((View) WindowDecorActionBar.this.d.getParent()).invalidate();
}
};
View decorView = activity.getWindow().getDecorView();
b(decorView);
if (z) {
return;
}
this.g = decorView.findViewById(R.id.content);
}
/* JADX WARN: Multi-variable type inference failed */
private DecorToolbar a(View view) {
if (view instanceof DecorToolbar) {
return (DecorToolbar) view;
}
if (view instanceof Toolbar) {
return ((Toolbar) view).getWrapper();
}
StringBuilder sb = new StringBuilder();
sb.append("Can't make a decor toolbar out of ");
sb.append(view != 0 ? view.getClass().getSimpleName() : "null");
throw new IllegalStateException(sb.toString());
}
static boolean a(boolean z, boolean z2, boolean z3) {
if (z3) {
return true;
}
return (z || z2) ? false : true;
}
private void b(View view) {
this.c = (ActionBarOverlayLayout) view.findViewById(R$id.decor_content_parent);
ActionBarOverlayLayout actionBarOverlayLayout = this.c;
if (actionBarOverlayLayout != null) {
actionBarOverlayLayout.setActionBarVisibilityCallback(this);
}
this.e = a(view.findViewById(R$id.action_bar));
this.f = (ActionBarContextView) view.findViewById(R$id.action_context_bar);
this.d = (ActionBarContainer) view.findViewById(R$id.action_bar_container);
DecorToolbar decorToolbar = this.e;
if (decorToolbar == null || this.f == null || this.d == null) {
throw new IllegalStateException(WindowDecorActionBar.class.getSimpleName() + " can only be used with a compatible window decor layout");
}
this.a = decorToolbar.b();
boolean z = (this.e.m() & 4) != 0;
if (z) {
this.i = true;
}
ActionBarPolicy a = ActionBarPolicy.a(this.a);
j(a.a() || z);
k(a.f());
TypedArray obtainStyledAttributes = this.a.obtainStyledAttributes(null, R$styleable.ActionBar, R$attr.actionBarStyle, 0);
if (obtainStyledAttributes.getBoolean(R$styleable.ActionBar_hideOnContentScroll, false)) {
i(true);
}
int dimensionPixelSize = obtainStyledAttributes.getDimensionPixelSize(R$styleable.ActionBar_elevation, 0);
if (dimensionPixelSize != 0) {
a(dimensionPixelSize);
}
obtainStyledAttributes.recycle();
}
private void k(boolean z) {
this.o = z;
if (this.o) {
this.d.setTabContainer(null);
this.e.a(this.h);
} else {
this.e.a((ScrollingTabContainerView) null);
this.d.setTabContainer(this.h);
}
boolean z2 = m() == 2;
ScrollingTabContainerView scrollingTabContainerView = this.h;
if (scrollingTabContainerView != null) {
if (z2) {
scrollingTabContainerView.setVisibility(0);
ActionBarOverlayLayout actionBarOverlayLayout = this.c;
if (actionBarOverlayLayout != null) {
ViewCompat.B(actionBarOverlayLayout);
}
} else {
scrollingTabContainerView.setVisibility(8);
}
}
this.e.b(!this.o && z2);
this.c.setHasNonEmbeddedTabs(!this.o && z2);
}
private void n() {
if (this.t) {
this.t = false;
ActionBarOverlayLayout actionBarOverlayLayout = this.c;
if (actionBarOverlayLayout != null) {
actionBarOverlayLayout.setShowingForActionMode(false);
}
l(false);
}
}
private boolean o() {
return ViewCompat.x(this.d);
}
private void p() {
if (this.t) {
return;
}
this.t = true;
ActionBarOverlayLayout actionBarOverlayLayout = this.c;
if (actionBarOverlayLayout != null) {
actionBarOverlayLayout.setShowingForActionMode(true);
}
l(false);
}
@Override // androidx.appcompat.widget.ActionBarOverlayLayout.ActionBarVisibilityCallback
public void b() {
}
@Override // androidx.appcompat.widget.ActionBarOverlayLayout.ActionBarVisibilityCallback
public void c() {
if (this.s) {
return;
}
this.s = true;
l(true);
}
@Override // androidx.appcompat.app.ActionBar
public void d(boolean z) {
ViewPropertyAnimatorCompatSet viewPropertyAnimatorCompatSet;
this.w = z;
if (z || (viewPropertyAnimatorCompatSet = this.v) == null) {
return;
}
viewPropertyAnimatorCompatSet.a();
}
public void e(boolean z) {
ViewPropertyAnimatorCompat a;
ViewPropertyAnimatorCompat a2;
if (z) {
p();
} else {
n();
}
if (!o()) {
if (z) {
this.e.c(4);
this.f.setVisibility(0);
return;
} else {
this.e.c(0);
this.f.setVisibility(8);
return;
}
}
if (z) {
a2 = this.e.a(4, 100L);
a = this.f.a(0, 200L);
} else {
a = this.e.a(0, 200L);
a2 = this.f.a(8, 100L);
}
ViewPropertyAnimatorCompatSet viewPropertyAnimatorCompatSet = new ViewPropertyAnimatorCompatSet();
viewPropertyAnimatorCompatSet.a(a2, a);
viewPropertyAnimatorCompatSet.c();
}
public void f(boolean z) {
View view;
ViewPropertyAnimatorCompatSet viewPropertyAnimatorCompatSet = this.v;
if (viewPropertyAnimatorCompatSet != null) {
viewPropertyAnimatorCompatSet.a();
}
if (this.p != 0 || (!this.w && !z)) {
this.y.b(null);
return;
}
this.d.setAlpha(1.0f);
this.d.setTransitioning(true);
ViewPropertyAnimatorCompatSet viewPropertyAnimatorCompatSet2 = new ViewPropertyAnimatorCompatSet();
float f = -this.d.getHeight();
if (z) {
this.d.getLocationInWindow(new int[]{0, 0});
f -= r5[1];
}
ViewPropertyAnimatorCompat a = ViewCompat.a(this.d);
a.b(f);
a.a(this.A);
viewPropertyAnimatorCompatSet2.a(a);
if (this.q && (view = this.g) != null) {
ViewPropertyAnimatorCompat a2 = ViewCompat.a(view);
a2.b(f);
viewPropertyAnimatorCompatSet2.a(a2);
}
viewPropertyAnimatorCompatSet2.a(B);
viewPropertyAnimatorCompatSet2.a(250L);
viewPropertyAnimatorCompatSet2.a(this.y);
this.v = viewPropertyAnimatorCompatSet2;
viewPropertyAnimatorCompatSet2.c();
}
@Override // androidx.appcompat.app.ActionBar
public int g() {
return this.e.m();
}
public void h(boolean z) {
a(z ? 4 : 0, 4);
}
public void i(boolean z) {
if (z && !this.c.i()) {
throw new IllegalStateException("Action bar must be in overlay mode (Window.FEATURE_OVERLAY_ACTION_BAR) to enable hide on content scroll");
}
this.x = z;
this.c.setHideOnContentScrollEnabled(z);
}
public void j(boolean z) {
this.e.a(z);
}
void l() {
ActionMode.Callback callback = this.l;
if (callback != null) {
callback.a(this.k);
this.k = null;
this.l = null;
}
}
public int m() {
return this.e.k();
}
public void g(boolean z) {
View view;
View view2;
ViewPropertyAnimatorCompatSet viewPropertyAnimatorCompatSet = this.v;
if (viewPropertyAnimatorCompatSet != null) {
viewPropertyAnimatorCompatSet.a();
}
this.d.setVisibility(0);
if (this.p == 0 && (this.w || z)) {
this.d.setTranslationY(0.0f);
float f = -this.d.getHeight();
if (z) {
this.d.getLocationInWindow(new int[]{0, 0});
f -= r5[1];
}
this.d.setTranslationY(f);
ViewPropertyAnimatorCompatSet viewPropertyAnimatorCompatSet2 = new ViewPropertyAnimatorCompatSet();
ViewPropertyAnimatorCompat a = ViewCompat.a(this.d);
a.b(0.0f);
a.a(this.A);
viewPropertyAnimatorCompatSet2.a(a);
if (this.q && (view2 = this.g) != null) {
view2.setTranslationY(f);
ViewPropertyAnimatorCompat a2 = ViewCompat.a(this.g);
a2.b(0.0f);
viewPropertyAnimatorCompatSet2.a(a2);
}
viewPropertyAnimatorCompatSet2.a(C);
viewPropertyAnimatorCompatSet2.a(250L);
viewPropertyAnimatorCompatSet2.a(this.z);
this.v = viewPropertyAnimatorCompatSet2;
viewPropertyAnimatorCompatSet2.c();
} else {
this.d.setAlpha(1.0f);
this.d.setTranslationY(0.0f);
if (this.q && (view = this.g) != null) {
view.setTranslationY(0.0f);
}
this.z.b(null);
}
ActionBarOverlayLayout actionBarOverlayLayout = this.c;
if (actionBarOverlayLayout != null) {
ViewCompat.B(actionBarOverlayLayout);
}
}
@Override // androidx.appcompat.app.ActionBar
public Context h() {
if (this.b == null) {
TypedValue typedValue = new TypedValue();
this.a.getTheme().resolveAttribute(R$attr.actionBarWidgetTheme, typedValue, true);
int i = typedValue.resourceId;
if (i != 0) {
this.b = new ContextThemeWrapper(this.a, i);
} else {
this.b = this.a;
}
}
return this.b;
}
@Override // androidx.appcompat.app.ActionBar
public void c(boolean z) {
if (this.i) {
return;
}
h(z);
}
@Override // androidx.appcompat.widget.ActionBarOverlayLayout.ActionBarVisibilityCallback
public void d() {
ViewPropertyAnimatorCompatSet viewPropertyAnimatorCompatSet = this.v;
if (viewPropertyAnimatorCompatSet != null) {
viewPropertyAnimatorCompatSet.a();
this.v = null;
}
}
private void l(boolean z) {
if (a(this.r, this.s, this.t)) {
if (this.u) {
return;
}
this.u = true;
g(z);
return;
}
if (this.u) {
this.u = false;
f(z);
}
}
public void a(float f) {
ViewCompat.b(this.d, f);
}
@Override // androidx.appcompat.app.ActionBar
public void a(Configuration configuration) {
k(ActionBarPolicy.a(this.a).f());
}
@Override // androidx.appcompat.widget.ActionBarOverlayLayout.ActionBarVisibilityCallback
public void a(int i) {
this.p = i;
}
@Override // androidx.appcompat.app.ActionBar
public void a(CharSequence charSequence) {
this.e.setWindowTitle(charSequence);
}
public void a(int i, int i2) {
int m = this.e.m();
if ((i2 & 4) != 0) {
this.i = true;
}
this.e.a((i & i2) | ((~i2) & m));
}
public WindowDecorActionBar(Dialog dialog) {
new ArrayList();
this.n = new ArrayList<>();
this.p = 0;
this.q = true;
this.u = true;
this.y = new ViewPropertyAnimatorListenerAdapter() { // from class: androidx.appcompat.app.WindowDecorActionBar.1
@Override // androidx.core.view.ViewPropertyAnimatorListener
public void b(View view) {
View view2;
WindowDecorActionBar windowDecorActionBar = WindowDecorActionBar.this;
if (windowDecorActionBar.q && (view2 = windowDecorActionBar.g) != null) {
view2.setTranslationY(0.0f);
WindowDecorActionBar.this.d.setTranslationY(0.0f);
}
WindowDecorActionBar.this.d.setVisibility(8);
WindowDecorActionBar.this.d.setTransitioning(false);
WindowDecorActionBar windowDecorActionBar2 = WindowDecorActionBar.this;
windowDecorActionBar2.v = null;
windowDecorActionBar2.l();
ActionBarOverlayLayout actionBarOverlayLayout = WindowDecorActionBar.this.c;
if (actionBarOverlayLayout != null) {
ViewCompat.B(actionBarOverlayLayout);
}
}
};
this.z = new ViewPropertyAnimatorListenerAdapter() { // from class: androidx.appcompat.app.WindowDecorActionBar.2
@Override // androidx.core.view.ViewPropertyAnimatorListener
public void b(View view) {
WindowDecorActionBar windowDecorActionBar = WindowDecorActionBar.this;
windowDecorActionBar.v = null;
windowDecorActionBar.d.requestLayout();
}
};
this.A = new ViewPropertyAnimatorUpdateListener() { // from class: androidx.appcompat.app.WindowDecorActionBar.3
@Override // androidx.core.view.ViewPropertyAnimatorUpdateListener
public void a(View view) {
((View) WindowDecorActionBar.this.d.getParent()).invalidate();
}
};
b(dialog.getWindow().getDecorView());
}
@Override // androidx.appcompat.app.ActionBar
public ActionMode a(ActionMode.Callback callback) {
ActionModeImpl actionModeImpl = this.j;
if (actionModeImpl != null) {
actionModeImpl.a();
}
this.c.setHideOnContentScrollEnabled(false);
this.f.c();
ActionModeImpl actionModeImpl2 = new ActionModeImpl(this.f.getContext(), callback);
if (!actionModeImpl2.k()) {
return null;
}
this.j = actionModeImpl2;
actionModeImpl2.i();
this.f.a(actionModeImpl2);
e(true);
this.f.sendAccessibilityEvent(32);
return actionModeImpl2;
}
@Override // androidx.appcompat.app.ActionBar
public void b(boolean z) {
if (z == this.m) {
return;
}
this.m = z;
int size = this.n.size();
for (int i = 0; i < size; i++) {
this.n.get(i).a(z);
}
}
@Override // androidx.appcompat.app.ActionBar
public boolean f() {
DecorToolbar decorToolbar = this.e;
if (decorToolbar == null || !decorToolbar.i()) {
return false;
}
this.e.collapseActionView();
return true;
}
@Override // androidx.appcompat.widget.ActionBarOverlayLayout.ActionBarVisibilityCallback
public void a(boolean z) {
this.q = z;
}
@Override // androidx.appcompat.widget.ActionBarOverlayLayout.ActionBarVisibilityCallback
public void a() {
if (this.s) {
this.s = false;
l(true);
}
}
@Override // androidx.appcompat.app.ActionBar
public boolean a(int i, KeyEvent keyEvent) {
Menu c;
ActionModeImpl actionModeImpl = this.j;
if (actionModeImpl == null || (c = actionModeImpl.c()) == null) {
return false;
}
c.setQwertyMode(KeyCharacterMap.load(keyEvent != null ? keyEvent.getDeviceId() : -1).getKeyboardType() != 1);
return c.performShortcut(i, keyEvent, 0);
}
}