package androidx.browser.customtabs;

import android.app.ActivityOptions;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.text.TextUtils;
import android.util.SparseArray;
import android.widget.RemoteViews;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.ArrayList;

/* JADX INFO: loaded from: classes.dex */
public final class q {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Intent f880a = new Intent("android.intent.action.VIEW");

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final b f881b = new b();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public int f882c = 0;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public boolean f883d = true;

    @Nullable
    private ArrayList<Bundle> mActionButtons;

    @Nullable
    private ActivityOptions mActivityOptions;

    @Nullable
    private SparseArray<Bundle> mColorSchemeParamBundles;

    @Nullable
    private Bundle mDefaultColorSchemeBundle;

    @Nullable
    private ArrayList<Bundle> mMenuItems;

    public q() {
    }

    private void setSessionParameters(@Nullable IBinder iBinder, @Nullable PendingIntent pendingIntent) {
        Bundle bundle = new Bundle();
        bundle.putBinder("android.support.customtabs.extra.SESSION", iBinder);
        if (pendingIntent != null) {
            bundle.putParcelable("android.support.customtabs.extra.SESSION_ID", pendingIntent);
        }
        this.f880a.putExtras(bundle);
    }

    public final void a(String str, PendingIntent pendingIntent) {
        if (this.mMenuItems == null) {
            this.mMenuItems = new ArrayList<>();
        }
        Bundle bundle = new Bundle();
        bundle.putString("android.support.customtabs.customaction.MENU_ITEM_TITLE", str);
        bundle.putParcelable("android.support.customtabs.customaction.PENDING_INTENT", pendingIntent);
        this.mMenuItems.add(bundle);
    }

    public final r b() {
        Intent intent = this.f880a;
        if (!intent.hasExtra("android.support.customtabs.extra.SESSION")) {
            setSessionParameters(null, null);
        }
        ArrayList<Bundle> arrayList = this.mMenuItems;
        if (arrayList != null) {
            intent.putParcelableArrayListExtra("android.support.customtabs.extra.MENU_ITEMS", arrayList);
        }
        ArrayList<Bundle> arrayList2 = this.mActionButtons;
        if (arrayList2 != null) {
            intent.putParcelableArrayListExtra("android.support.customtabs.extra.TOOLBAR_ITEMS", arrayList2);
        }
        intent.putExtra("android.support.customtabs.extra.EXTRA_ENABLE_INSTANT_APPS", this.f883d);
        intent.putExtras(this.f881b.a().a());
        Bundle bundle = this.mDefaultColorSchemeBundle;
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        if (this.mColorSchemeParamBundles != null) {
            Bundle bundle2 = new Bundle();
            bundle2.putSparseParcelableArray("androidx.browser.customtabs.extra.COLOR_SCHEME_PARAMS", this.mColorSchemeParamBundles);
            intent.putExtras(bundle2);
        }
        intent.putExtra("androidx.browser.customtabs.extra.SHARE_STATE", this.f882c);
        int i10 = Build.VERSION.SDK_INT;
        String defaultLocale = o.getDefaultLocale();
        if (!TextUtils.isEmpty(defaultLocale)) {
            Bundle bundleExtra = intent.hasExtra("com.android.browser.headers") ? intent.getBundleExtra("com.android.browser.headers") : new Bundle();
            if (!bundleExtra.containsKey("Accept-Language")) {
                bundleExtra.putString("Accept-Language", defaultLocale);
                intent.putExtra("com.android.browser.headers", bundleExtra);
            }
        }
        if (i10 >= 34) {
            if (this.mActivityOptions == null) {
                this.mActivityOptions = n.a();
            }
            p.a(this.mActivityOptions, false);
        }
        ActivityOptions activityOptions = this.mActivityOptions;
        return new r(intent, activityOptions != null ? activityOptions.toBundle() : null);
    }

    public final void c(c cVar) {
        this.mDefaultColorSchemeBundle = cVar.a();
    }

    public final void d(z zVar) {
        this.f880a.setPackage(zVar.f898d.getPackageName());
        setSessionParameters(zVar.f897c.asBinder(), zVar.getId());
    }

    public final void e(int i10) {
        if (i10 < 0 || i10 > 2) {
            throw new IllegalArgumentException("Invalid value for the shareState argument");
        }
        this.f882c = i10;
        Intent intent = this.f880a;
        if (i10 == 1) {
            intent.putExtra("android.support.customtabs.extra.SHARE_MENU_ITEM", true);
        } else if (i10 == 2) {
            intent.putExtra("android.support.customtabs.extra.SHARE_MENU_ITEM", false);
        } else {
            intent.removeExtra("android.support.customtabs.extra.SHARE_MENU_ITEM");
        }
    }

    public final void f(Context context, int i10, int i11) {
        this.mActivityOptions = ActivityOptions.makeCustomAnimation(context, i10, i11);
    }

    @NonNull
    public q setSecondaryToolbarSwipeUpGesture(@Nullable PendingIntent pendingIntent) {
        this.f880a.putExtra("androidx.browser.customtabs.extra.SECONDARY_TOOLBAR_SWIPE_UP_GESTURE", pendingIntent);
        return this;
    }

    @NonNull
    public q setSecondaryToolbarViews(@NonNull RemoteViews remoteViews, @Nullable int[] iArr, @Nullable PendingIntent pendingIntent) {
        Intent intent = this.f880a;
        intent.putExtra("android.support.customtabs.extra.EXTRA_REMOTEVIEWS", remoteViews);
        intent.putExtra("android.support.customtabs.extra.EXTRA_REMOTEVIEWS_VIEW_IDS", iArr);
        intent.putExtra("android.support.customtabs.extra.EXTRA_REMOTEVIEWS_PENDINGINTENT", pendingIntent);
        return this;
    }

    public q(@Nullable z zVar) {
        if (zVar != null) {
            d(zVar);
        }
    }
}
