package androidx.appcompat.widget; import android.R; import android.content.ComponentName; import android.content.Context; import android.content.pm.PackageItemInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.res.Resources; import android.content.res.TypedArray; import android.database.DataSetObserver; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.os.AsyncTask; import android.text.TextUtils; import android.util.AttributeSet; import android.util.Base64; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.view.accessibility.AccessibilityNodeInfo; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.PopupWindow; import android.widget.TextView; import androidx.core.view.ViewCompat; import androidx.core.view.accessibility.AccessibilityNodeInfoCompat; import com.huawei.hms.support.api.entity.common.CommonConstant; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import o.AZJ; import o.C0683McA; import o.C15846jAy; import o.SYO; import o.hbU; import o.nHL; import o.ykw; /* loaded from: classes.dex */ public class ActivityChooserView extends ViewGroup { private static int r = 0; private static byte s = 6; private static int y = 1; final Drawable a; int b; final View c; final IeS d; final FrameLayout e; boolean f; final DataSetObserver g; final FrameLayout h; int i; final ImageView j; private final ImageView k; private boolean l; private final RVV m; hbU n; /* renamed from: o, reason: collision with root package name */ PopupWindow.OnDismissListener f6374o; private C15846jAy p; private final int q; private final ViewTreeObserver.OnGlobalLayoutListener t; private void u(String str, Object[] objArr) { byte[] decode = Base64.decode(str, 0); byte[] bArr = new byte[decode.length]; for (int i = 0; i < decode.length; i++) { bArr[i] = (byte) (decode[(decode.length - i) - 1] ^ s); } objArr[0] = new String(bArr, StandardCharsets.UTF_8); } public ActivityChooserView(Context context) { this(context, null); } public ActivityChooserView(Context context, AttributeSet attributeSet) { this(context, attributeSet, 0); } public ActivityChooserView(Context context, AttributeSet attributeSet, int i) { super(context, attributeSet, i); this.g = new DataSetObserver(this) { // from class: androidx.appcompat.widget.ActivityChooserView.4 final ActivityChooserView c; { this.c = this; } @Override // android.database.DataSetObserver public final void onChanged() { super.onChanged(); this.c.d.notifyDataSetChanged(); } @Override // android.database.DataSetObserver public final void onInvalidated() { super.onInvalidated(); this.c.d.notifyDataSetInvalidated(); } }; this.t = new ViewTreeObserver.OnGlobalLayoutListener(this) { // from class: androidx.appcompat.widget.ActivityChooserView.5 final ActivityChooserView e; { this.e = this; } @Override // android.view.ViewTreeObserver.OnGlobalLayoutListener public final void onGlobalLayout() { if (this.e.d().j()) { if (!this.e.isShown()) { this.e.d().b(); return; } this.e.d().h(); if (this.e.n != null) { this.e.n.b(true); } } } }; this.i = 4; TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, SYO.ZqN.ActivityChooserView, i, 0); ViewCompat.sm_(this, context, SYO.ZqN.ActivityChooserView, attributeSet, obtainStyledAttributes, i, 0); this.i = obtainStyledAttributes.getInt(SYO.ZqN.ActivityChooserView_initialActivityCount, 4); Drawable drawable = obtainStyledAttributes.getDrawable(SYO.ZqN.ActivityChooserView_expandActivityOverflowButtonDrawable); obtainStyledAttributes.recycle(); LayoutInflater.from(getContext()).inflate(SYO.ojQ.abc_activity_chooser_view, (ViewGroup) this, true); RVV rvv = new RVV(this); this.m = rvv; View findViewById = findViewById(SYO.saX.activity_chooser_view_content); this.c = findViewById; this.a = findViewById.getBackground(); FrameLayout frameLayout = (FrameLayout) findViewById(SYO.saX.default_activity_button); this.e = frameLayout; frameLayout.setOnClickListener(rvv); frameLayout.setOnLongClickListener(rvv); this.j = (ImageView) frameLayout.findViewById(SYO.saX.image); FrameLayout frameLayout2 = (FrameLayout) findViewById(SYO.saX.expand_activities_button); frameLayout2.setOnClickListener(rvv); frameLayout2.setAccessibilityDelegate(new View.AccessibilityDelegate(this) { // from class: androidx.appcompat.widget.ActivityChooserView.2 final ActivityChooserView a; { this.a = this; } @Override // android.view.View.AccessibilityDelegate public final void onInitializeAccessibilityNodeInfo(View view, AccessibilityNodeInfo accessibilityNodeInfo) { super.onInitializeAccessibilityNodeInfo(view, accessibilityNodeInfo); AccessibilityNodeInfoCompat.tU_(accessibilityNodeInfo).b(true); } }); frameLayout2.setOnTouchListener(new nHL(this, frameLayout2) { // from class: androidx.appcompat.widget.ActivityChooserView.1 final ActivityChooserView e; { this.e = this; } @Override // o.nHL public final AZJ e() { return this.e.d(); } @Override // o.nHL public final boolean c() { this.e.a(); return true; } @Override // o.nHL public final boolean a() { this.e.e(); return true; } }); this.h = frameLayout2; ImageView imageView = (ImageView) frameLayout2.findViewById(SYO.saX.image); this.k = imageView; imageView.setImageDrawable(drawable); IeS ieS = new IeS(this); this.d = ieS; ieS.registerDataSetObserver(new DataSetObserver(this) { // from class: androidx.appcompat.widget.ActivityChooserView.3 final ActivityChooserView e; { this.e = this; } @Override // android.database.DataSetObserver public final void onChanged() { super.onChanged(); ActivityChooserView activityChooserView = this.e; if (activityChooserView.d.getCount() > 0) { activityChooserView.h.setEnabled(true); } else { activityChooserView.h.setEnabled(false); } int d = activityChooserView.d.b.d(); int g = activityChooserView.d.b.g(); if (d == 1 || (d > 1 && g > 0)) { activityChooserView.e.setVisibility(0); ResolveInfo fu_ = activityChooserView.d.b.fu_(); PackageManager packageManager = activityChooserView.getContext().getPackageManager(); activityChooserView.j.setImageDrawable(fu_.loadIcon(packageManager)); if (activityChooserView.b != 0) { activityChooserView.e.setContentDescription(activityChooserView.getContext().getString(activityChooserView.b, fu_.loadLabel(packageManager))); } } else { activityChooserView.e.setVisibility(8); } if (activityChooserView.e.getVisibility() == 0) { activityChooserView.c.setBackgroundDrawable(activityChooserView.a); } else { activityChooserView.c.setBackgroundDrawable(null); } } }); Resources resources = context.getResources(); this.q = Math.max(resources.getDisplayMetrics().widthPixels / 2, resources.getDimensionPixelSize(SYO.Sts.abc_config_prefDialogWidth)); } public void setActivityChooserModel(ykw ykwVar) { IeS ieS = this.d; ykw ykwVar2 = ieS.i.d.b; if (ykwVar2 != null && ieS.i.isShown()) { ykwVar2.unregisterObserver(ieS.i.g); } ieS.b = ykwVar; if (ykwVar != null && ieS.i.isShown()) { ykwVar.registerObserver(ieS.i.g); } ieS.notifyDataSetChanged(); if (d().j()) { e(); a(); } } public void setExpandActivityOverflowButtonDrawable(Drawable drawable) { this.k.setImageDrawable(drawable); } public void setExpandActivityOverflowButtonContentDescription(int i) { int i2 = 2 % 2; int i3 = y + 83; r = i3 % 128; if (i3 % 2 != 0) { getContext().getString(i).startsWith(",*,)"); Object obj = null; obj.hashCode(); throw null; } String string = getContext().getString(i); if (string.startsWith(",*,)")) { int i4 = y + 79; r = i4 % 128; int i5 = i4 % 2; Object[] objArr = new Object[1]; u(string.substring(4), objArr); string = ((String) objArr[0]).intern(); int i6 = r + 17; y = i6 % 128; int i7 = i6 % 2; } this.k.setContentDescription(string); } @Override // android.view.ViewGroup, android.view.View protected void onAttachedToWindow() { super.onAttachedToWindow(); ykw ykwVar = this.d.b; if (ykwVar != null) { ykwVar.registerObserver(this.g); } this.l = true; } @Override // android.view.ViewGroup, android.view.View protected void onDetachedFromWindow() { super.onDetachedFromWindow(); ykw ykwVar = this.d.b; if (ykwVar != null) { ykwVar.unregisterObserver(this.g); } ViewTreeObserver viewTreeObserver = getViewTreeObserver(); if (viewTreeObserver.isAlive()) { viewTreeObserver.removeGlobalOnLayoutListener(this.t); } if (d().j()) { e(); } this.l = false; } @Override // android.view.View protected void onMeasure(int i, int i2) { View view = this.c; if (this.e.getVisibility() != 0) { i2 = View.MeasureSpec.makeMeasureSpec(View.MeasureSpec.getSize(i2), 1073741824); } measureChild(view, i, i2); setMeasuredDimension(view.getMeasuredWidth(), view.getMeasuredHeight()); } @Override // android.view.ViewGroup, android.view.View protected void onLayout(boolean z, int i, int i2, int i3, int i4) { this.c.layout(0, 0, i3 - i, i4 - i2); if (d().j()) { return; } e(); } final C15846jAy d() { if (this.p == null) { C15846jAy c15846jAy = new C15846jAy(getContext()); this.p = c15846jAy; c15846jAy.iu_(this.d); this.p.e(this); this.p.c(true); this.p.iy_(this.m); this.p.ix_(this.m); } return this.p; } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes.dex */ public class RVV implements AdapterView.OnItemClickListener, View.OnClickListener, View.OnLongClickListener, PopupWindow.OnDismissListener { final ActivityChooserView e; RVV(ActivityChooserView activityChooserView) { this.e = activityChooserView; } @Override // android.widget.AdapterView.OnItemClickListener public final void onItemClick(AdapterView adapterView, View view, int i, long j) { float f; int itemViewType = ((IeS) adapterView.getAdapter()).getItemViewType(i); if (itemViewType != 0) { if (itemViewType == 1) { this.e.d(Integer.MAX_VALUE); return; } throw new IllegalArgumentException(); } this.e.e(); if (!this.e.f) { boolean z = this.e.d.e; this.e.d.b.fr_(); return; } if (i > 0) { ykw ykwVar = this.e.d.b; synchronized (ykwVar.f) { ykwVar.c(); ykw.HBt hBt = ykwVar.a.get(i); ykw.HBt hBt2 = ykwVar.a.get(0); if (hBt2 != null) { float f2 = hBt2.e; float f3 = hBt.e; f = 5.0f; } else { f = 1.0f; } if (ykwVar.h.add(new ykw.LWm(new ComponentName((String) PackageItemInfo.class.getField(CommonConstant.ReqAccessTokenParam.PACKAGE_NAME).get(hBt.a.activityInfo), (String) PackageItemInfo.class.getField("name").get(hBt.a.activityInfo)), System.currentTimeMillis(), f))) { ykwVar.j = true; ykwVar.e(); if (ykwVar.g) { if (ykwVar.j) { ykwVar.j = false; if (!TextUtils.isEmpty(ykwVar.i)) { new ykw.Sts(ykwVar).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new ArrayList(ykwVar.h), ykwVar.i); } } ykw.IeS ieS = ykwVar.d; ykwVar.notifyChanged(); } else { throw new IllegalStateException("No preceding call to #readHistoricalData"); } } } } } @Override // android.view.View.OnClickListener public final void onClick(View view) { if (view == this.e.e) { this.e.e(); this.e.d.b.ft_(this.e.d.b.fu_()); this.e.d.b.fr_(); return; } if (view == this.e.h) { this.e.f = false; ActivityChooserView activityChooserView = this.e; activityChooserView.d(activityChooserView.i); return; } throw new IllegalArgumentException(); } @Override // android.view.View.OnLongClickListener public final boolean onLongClick(View view) { if (view == this.e.e) { if (this.e.d.getCount() > 0) { this.e.f = true; ActivityChooserView activityChooserView = this.e; activityChooserView.d(activityChooserView.i); } return true; } throw new IllegalArgumentException(); } @Override // android.widget.PopupWindow.OnDismissListener public final void onDismiss() { if (this.e.f6374o != null) { this.e.f6374o.onDismiss(); } if (this.e.n != null) { this.e.n.b(false); } } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes.dex */ public class IeS extends BaseAdapter { int a = 4; ykw b; boolean c; boolean d; boolean e; final ActivityChooserView i; @Override // android.widget.Adapter public final long getItemId(int i) { return i; } @Override // android.widget.BaseAdapter, android.widget.Adapter public final int getViewTypeCount() { return 3; } IeS(ActivityChooserView activityChooserView) { this.i = activityChooserView; } @Override // android.widget.BaseAdapter, android.widget.Adapter public final int getItemViewType(int i) { return (this.c && i == getCount() - 1) ? 1 : 0; } @Override // android.widget.Adapter public final int getCount() { int d = this.b.d(); if (!this.e && this.b.fu_() != null) { d--; } int min = Math.min(d, this.a); return this.c ? min + 1 : min; } @Override // android.widget.Adapter public final Object getItem(int i) { int itemViewType = getItemViewType(i); if (itemViewType != 0) { if (itemViewType == 1) { return null; } throw new IllegalArgumentException(); } if (!this.e && this.b.fu_() != null) { i++; } return this.b.fs_(i); } @Override // android.widget.Adapter public final View getView(int i, View view, ViewGroup viewGroup) { int itemViewType = getItemViewType(i); if (itemViewType != 0) { if (itemViewType == 1) { if (view != null && view.getId() == 1) { return view; } View inflate = LayoutInflater.from(this.i.getContext()).inflate(SYO.ojQ.abc_activity_chooser_view_list_item, viewGroup, false); inflate.setId(1); ((TextView) inflate.findViewById(SYO.saX.title)).setText(this.i.getContext().getString(SYO.tOB.abc_activity_chooser_view_see_all)); return inflate; } throw new IllegalArgumentException(); } if (view == null || view.getId() != SYO.saX.list_item) { view = LayoutInflater.from(this.i.getContext()).inflate(SYO.ojQ.abc_activity_chooser_view_list_item, viewGroup, false); } PackageManager packageManager = this.i.getContext().getPackageManager(); ImageView imageView = (ImageView) view.findViewById(SYO.saX.icon); ResolveInfo resolveInfo = (ResolveInfo) getItem(i); imageView.setImageDrawable(resolveInfo.loadIcon(packageManager)); ((TextView) view.findViewById(SYO.saX.title)).setText(resolveInfo.loadLabel(packageManager)); if (this.e && i == 0 && this.d) { view.setActivated(true); } else { view.setActivated(false); } return view; } public final int a() { int i = this.a; this.a = Integer.MAX_VALUE; int makeMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, 0); int makeMeasureSpec2 = View.MeasureSpec.makeMeasureSpec(0, 0); int count = getCount(); int i2 = 0; View view = null; for (int i3 = 0; i3 < count; i3++) { view = getView(i3, view, null); view.measure(makeMeasureSpec, makeMeasureSpec2); i2 = Math.max(i2, view.getMeasuredWidth()); } this.a = i; return i2; } } /* loaded from: classes.dex */ public static class InnerLayout extends LinearLayout { private static final int[] d = {R.attr.background}; public InnerLayout(Context context, AttributeSet attributeSet) { super(context, attributeSet); C0683McA c0683McA = new C0683McA(context, context.obtainStyledAttributes(attributeSet, d)); setBackgroundDrawable(c0683McA.jL_(0)); c0683McA.d.recycle(); } } public final boolean e() { if (!d().j()) { return true; } d().b(); ViewTreeObserver viewTreeObserver = getViewTreeObserver(); if (!viewTreeObserver.isAlive()) { return true; } viewTreeObserver.removeGlobalOnLayoutListener(this.t); return true; } public final boolean a() { if (d().j() || !this.l) { return false; } this.f = false; d(this.i); return true; } /* JADX WARN: Type inference failed for: r0v15 */ /* JADX WARN: Type inference failed for: r0v6 */ /* JADX WARN: Type inference failed for: r0v7, types: [int, boolean] */ final void d(int i) { if (this.d.b == null) { throw new IllegalStateException("No data model. Did you call #setDataModel?"); } getViewTreeObserver().addOnGlobalLayoutListener(this.t); ?? r0 = this.e.getVisibility() == 0 ? 1 : 0; int d = this.d.b.d(); if (i != Integer.MAX_VALUE && d > i + r0) { IeS ieS = this.d; if (!ieS.c) { ieS.c = true; ieS.notifyDataSetChanged(); } IeS ieS2 = this.d; int i2 = i - 1; if (ieS2.a != i2) { ieS2.a = i2; ieS2.notifyDataSetChanged(); } } else { IeS ieS3 = this.d; if (ieS3.c) { ieS3.c = false; ieS3.notifyDataSetChanged(); } IeS ieS4 = this.d; if (ieS4.a != i) { ieS4.a = i; ieS4.notifyDataSetChanged(); } } C15846jAy d2 = d(); if (d2.j()) { return; } if (this.f || r0 == 0) { IeS ieS5 = this.d; if (!ieS5.e || ieS5.d != r0) { ieS5.e = true; ieS5.d = r0; ieS5.notifyDataSetChanged(); } } else { IeS ieS6 = this.d; if (ieS6.e || ieS6.d) { ieS6.e = false; ieS6.d = false; ieS6.notifyDataSetChanged(); } } d2.a(Math.min(this.d.a(), this.q)); d2.h(); hbU hbu = this.n; if (hbu != null) { hbu.b(true); } d2.it_().setContentDescription(getContext().getString(SYO.tOB.abc_activitychooserview_choose_application)); d2.it_().setSelector(new ColorDrawable(0)); } public void setProvider(hbU hbu) { this.n = hbu; } public void setOnDismissListener(PopupWindow.OnDismissListener onDismissListener) { this.f6374o = onDismissListener; } public void setInitialActivityCount(int i) { this.i = i; } public void setDefaultActionButtonContentDescription(int i) { this.b = i; } }