338 lines
12 KiB
Java
338 lines
12 KiB
Java
package androidx.appcompat.widget;
|
|
|
|
import android.content.Context;
|
|
import android.graphics.drawable.Drawable;
|
|
import android.text.TextUtils;
|
|
import android.util.AttributeSet;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.view.accessibility.AccessibilityEvent;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.TextView;
|
|
import androidx.appcompat.R$attr;
|
|
import androidx.appcompat.R$id;
|
|
import androidx.appcompat.R$layout;
|
|
import androidx.appcompat.R$styleable;
|
|
import androidx.appcompat.view.ActionMode;
|
|
import androidx.appcompat.view.menu.MenuBuilder;
|
|
import androidx.core.view.ViewCompat;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class ActionBarContextView extends AbsActionBarView {
|
|
private CharSequence i;
|
|
private CharSequence j;
|
|
private View k;
|
|
private View l;
|
|
private LinearLayout m;
|
|
private TextView n;
|
|
private TextView o;
|
|
private int p;
|
|
private int q;
|
|
private boolean r;
|
|
private int s;
|
|
|
|
public ActionBarContextView(Context context) {
|
|
this(context, null);
|
|
}
|
|
|
|
private void e() {
|
|
if (this.m == null) {
|
|
LayoutInflater.from(getContext()).inflate(R$layout.abc_action_bar_title_item, this);
|
|
this.m = (LinearLayout) getChildAt(getChildCount() - 1);
|
|
this.n = (TextView) this.m.findViewById(R$id.action_bar_title);
|
|
this.o = (TextView) this.m.findViewById(R$id.action_bar_subtitle);
|
|
if (this.p != 0) {
|
|
this.n.setTextAppearance(getContext(), this.p);
|
|
}
|
|
if (this.q != 0) {
|
|
this.o.setTextAppearance(getContext(), this.q);
|
|
}
|
|
}
|
|
this.n.setText(this.i);
|
|
this.o.setText(this.j);
|
|
boolean z = !TextUtils.isEmpty(this.i);
|
|
boolean z2 = !TextUtils.isEmpty(this.j);
|
|
int i = 0;
|
|
this.o.setVisibility(z2 ? 0 : 8);
|
|
LinearLayout linearLayout = this.m;
|
|
if (!z && !z2) {
|
|
i = 8;
|
|
}
|
|
linearLayout.setVisibility(i);
|
|
if (this.m.getParent() == null) {
|
|
addView(this.m);
|
|
}
|
|
}
|
|
|
|
public boolean b() {
|
|
return this.r;
|
|
}
|
|
|
|
public void c() {
|
|
removeAllViews();
|
|
this.l = null;
|
|
this.c = null;
|
|
}
|
|
|
|
public boolean d() {
|
|
ActionMenuPresenter actionMenuPresenter = this.d;
|
|
if (actionMenuPresenter != null) {
|
|
return actionMenuPresenter.i();
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override // android.view.ViewGroup
|
|
protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
|
|
return new ViewGroup.MarginLayoutParams(-1, -2);
|
|
}
|
|
|
|
@Override // android.view.ViewGroup
|
|
public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attributeSet) {
|
|
return new ViewGroup.MarginLayoutParams(getContext(), attributeSet);
|
|
}
|
|
|
|
@Override // androidx.appcompat.widget.AbsActionBarView
|
|
public /* bridge */ /* synthetic */ int getAnimatedVisibility() {
|
|
return super.getAnimatedVisibility();
|
|
}
|
|
|
|
@Override // androidx.appcompat.widget.AbsActionBarView
|
|
public /* bridge */ /* synthetic */ int getContentHeight() {
|
|
return super.getContentHeight();
|
|
}
|
|
|
|
public CharSequence getSubtitle() {
|
|
return this.j;
|
|
}
|
|
|
|
public CharSequence getTitle() {
|
|
return this.i;
|
|
}
|
|
|
|
@Override // android.view.ViewGroup, android.view.View
|
|
public void onDetachedFromWindow() {
|
|
super.onDetachedFromWindow();
|
|
ActionMenuPresenter actionMenuPresenter = this.d;
|
|
if (actionMenuPresenter != null) {
|
|
actionMenuPresenter.e();
|
|
this.d.f();
|
|
}
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public void onInitializeAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
|
|
if (accessibilityEvent.getEventType() != 32) {
|
|
super.onInitializeAccessibilityEvent(accessibilityEvent);
|
|
return;
|
|
}
|
|
accessibilityEvent.setSource(this);
|
|
accessibilityEvent.setClassName(ActionBarContextView.class.getName());
|
|
accessibilityEvent.setPackageName(getContext().getPackageName());
|
|
accessibilityEvent.setContentDescription(this.i);
|
|
}
|
|
|
|
@Override // android.view.ViewGroup, android.view.View
|
|
protected void onLayout(boolean z, int i, int i2, int i3, int i4) {
|
|
int i5;
|
|
boolean a = ViewUtils.a(this);
|
|
int paddingRight = a ? (i3 - i) - getPaddingRight() : getPaddingLeft();
|
|
int paddingTop = getPaddingTop();
|
|
int paddingTop2 = ((i4 - i2) - getPaddingTop()) - getPaddingBottom();
|
|
View view = this.k;
|
|
if (view == null || view.getVisibility() == 8) {
|
|
i5 = paddingRight;
|
|
} else {
|
|
ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) this.k.getLayoutParams();
|
|
int i6 = a ? marginLayoutParams.rightMargin : marginLayoutParams.leftMargin;
|
|
int i7 = a ? marginLayoutParams.leftMargin : marginLayoutParams.rightMargin;
|
|
int a2 = AbsActionBarView.a(paddingRight, i6, a);
|
|
i5 = AbsActionBarView.a(a2 + a(this.k, a2, paddingTop, paddingTop2, a), i7, a);
|
|
}
|
|
LinearLayout linearLayout = this.m;
|
|
if (linearLayout != null && this.l == null && linearLayout.getVisibility() != 8) {
|
|
i5 += a(this.m, i5, paddingTop, paddingTop2, a);
|
|
}
|
|
int i8 = i5;
|
|
View view2 = this.l;
|
|
if (view2 != null) {
|
|
a(view2, i8, paddingTop, paddingTop2, a);
|
|
}
|
|
int paddingLeft = a ? getPaddingLeft() : (i3 - i) - getPaddingRight();
|
|
ActionMenuView actionMenuView = this.c;
|
|
if (actionMenuView != null) {
|
|
a(actionMenuView, paddingLeft, paddingTop, paddingTop2, !a);
|
|
}
|
|
}
|
|
|
|
@Override // android.view.View
|
|
protected void onMeasure(int i, int i2) {
|
|
if (View.MeasureSpec.getMode(i) != 1073741824) {
|
|
throw new IllegalStateException(ActionBarContextView.class.getSimpleName() + " can only be used with android:layout_width=\"match_parent\" (or fill_parent)");
|
|
}
|
|
if (View.MeasureSpec.getMode(i2) == 0) {
|
|
throw new IllegalStateException(ActionBarContextView.class.getSimpleName() + " can only be used with android:layout_height=\"wrap_content\"");
|
|
}
|
|
int size = View.MeasureSpec.getSize(i);
|
|
int i3 = this.e;
|
|
if (i3 <= 0) {
|
|
i3 = View.MeasureSpec.getSize(i2);
|
|
}
|
|
int paddingTop = getPaddingTop() + getPaddingBottom();
|
|
int paddingLeft = (size - getPaddingLeft()) - getPaddingRight();
|
|
int i4 = i3 - paddingTop;
|
|
int makeMeasureSpec = View.MeasureSpec.makeMeasureSpec(i4, Integer.MIN_VALUE);
|
|
View view = this.k;
|
|
if (view != null) {
|
|
int a = a(view, paddingLeft, makeMeasureSpec, 0);
|
|
ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) this.k.getLayoutParams();
|
|
paddingLeft = a - (marginLayoutParams.leftMargin + marginLayoutParams.rightMargin);
|
|
}
|
|
ActionMenuView actionMenuView = this.c;
|
|
if (actionMenuView != null && actionMenuView.getParent() == this) {
|
|
paddingLeft = a(this.c, paddingLeft, makeMeasureSpec, 0);
|
|
}
|
|
LinearLayout linearLayout = this.m;
|
|
if (linearLayout != null && this.l == null) {
|
|
if (this.r) {
|
|
this.m.measure(View.MeasureSpec.makeMeasureSpec(0, 0), makeMeasureSpec);
|
|
int measuredWidth = this.m.getMeasuredWidth();
|
|
boolean z = measuredWidth <= paddingLeft;
|
|
if (z) {
|
|
paddingLeft -= measuredWidth;
|
|
}
|
|
this.m.setVisibility(z ? 0 : 8);
|
|
} else {
|
|
paddingLeft = a(linearLayout, paddingLeft, makeMeasureSpec, 0);
|
|
}
|
|
}
|
|
View view2 = this.l;
|
|
if (view2 != null) {
|
|
ViewGroup.LayoutParams layoutParams = view2.getLayoutParams();
|
|
int i5 = layoutParams.width != -2 ? 1073741824 : Integer.MIN_VALUE;
|
|
int i6 = layoutParams.width;
|
|
if (i6 >= 0) {
|
|
paddingLeft = Math.min(i6, paddingLeft);
|
|
}
|
|
int i7 = layoutParams.height == -2 ? Integer.MIN_VALUE : 1073741824;
|
|
int i8 = layoutParams.height;
|
|
if (i8 >= 0) {
|
|
i4 = Math.min(i8, i4);
|
|
}
|
|
this.l.measure(View.MeasureSpec.makeMeasureSpec(paddingLeft, i5), View.MeasureSpec.makeMeasureSpec(i4, i7));
|
|
}
|
|
if (this.e > 0) {
|
|
setMeasuredDimension(size, i3);
|
|
return;
|
|
}
|
|
int childCount = getChildCount();
|
|
int i9 = 0;
|
|
for (int i10 = 0; i10 < childCount; i10++) {
|
|
int measuredHeight = getChildAt(i10).getMeasuredHeight() + paddingTop;
|
|
if (measuredHeight > i9) {
|
|
i9 = measuredHeight;
|
|
}
|
|
}
|
|
setMeasuredDimension(size, i9);
|
|
}
|
|
|
|
@Override // androidx.appcompat.widget.AbsActionBarView
|
|
public void setContentHeight(int i) {
|
|
this.e = i;
|
|
}
|
|
|
|
public void setCustomView(View view) {
|
|
LinearLayout linearLayout;
|
|
View view2 = this.l;
|
|
if (view2 != null) {
|
|
removeView(view2);
|
|
}
|
|
this.l = view;
|
|
if (view != null && (linearLayout = this.m) != null) {
|
|
removeView(linearLayout);
|
|
this.m = null;
|
|
}
|
|
if (view != null) {
|
|
addView(view);
|
|
}
|
|
requestLayout();
|
|
}
|
|
|
|
public void setSubtitle(CharSequence charSequence) {
|
|
this.j = charSequence;
|
|
e();
|
|
}
|
|
|
|
public void setTitle(CharSequence charSequence) {
|
|
this.i = charSequence;
|
|
e();
|
|
}
|
|
|
|
public void setTitleOptional(boolean z) {
|
|
if (z != this.r) {
|
|
requestLayout();
|
|
}
|
|
this.r = z;
|
|
}
|
|
|
|
@Override // androidx.appcompat.widget.AbsActionBarView, android.view.View
|
|
public /* bridge */ /* synthetic */ void setVisibility(int i) {
|
|
super.setVisibility(i);
|
|
}
|
|
|
|
@Override // android.view.ViewGroup
|
|
public boolean shouldDelayChildPressedState() {
|
|
return false;
|
|
}
|
|
|
|
public ActionBarContextView(Context context, AttributeSet attributeSet) {
|
|
this(context, attributeSet, R$attr.actionModeStyle);
|
|
}
|
|
|
|
public void a(final ActionMode actionMode) {
|
|
View view = this.k;
|
|
if (view == null) {
|
|
this.k = LayoutInflater.from(getContext()).inflate(this.s, (ViewGroup) this, false);
|
|
addView(this.k);
|
|
} else if (view.getParent() == null) {
|
|
addView(this.k);
|
|
}
|
|
this.k.findViewById(R$id.action_mode_close_button).setOnClickListener(new View.OnClickListener(this) { // from class: androidx.appcompat.widget.ActionBarContextView.1
|
|
@Override // android.view.View.OnClickListener
|
|
public void onClick(View view2) {
|
|
actionMode.a();
|
|
}
|
|
});
|
|
MenuBuilder menuBuilder = (MenuBuilder) actionMode.c();
|
|
ActionMenuPresenter actionMenuPresenter = this.d;
|
|
if (actionMenuPresenter != null) {
|
|
actionMenuPresenter.c();
|
|
}
|
|
this.d = new ActionMenuPresenter(getContext());
|
|
this.d.c(true);
|
|
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(-2, -1);
|
|
menuBuilder.a(this.d, this.b);
|
|
this.c = (ActionMenuView) this.d.b(this);
|
|
ViewCompat.a(this.c, (Drawable) null);
|
|
addView(this.c, layoutParams);
|
|
}
|
|
|
|
public ActionBarContextView(Context context, AttributeSet attributeSet, int i) {
|
|
super(context, attributeSet, i);
|
|
TintTypedArray a = TintTypedArray.a(context, attributeSet, R$styleable.ActionMode, i, 0);
|
|
ViewCompat.a(this, a.b(R$styleable.ActionMode_background));
|
|
this.p = a.g(R$styleable.ActionMode_titleTextStyle, 0);
|
|
this.q = a.g(R$styleable.ActionMode_subtitleTextStyle, 0);
|
|
this.e = a.f(R$styleable.ActionMode_height, 0);
|
|
this.s = a.g(R$styleable.ActionMode_closeItemLayout, R$layout.abc_action_mode_close_item_material);
|
|
a.a();
|
|
}
|
|
|
|
public void a() {
|
|
if (this.k == null) {
|
|
c();
|
|
}
|
|
}
|
|
}
|