2021-06-27 20:44:35 +00:00
|
|
|
package androidx.browser.customtabs;
|
|
|
|
|
|
|
|
import android.app.PendingIntent;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.IBinder;
|
|
|
|
import android.util.SparseArray;
|
|
|
|
import android.widget.RemoteViews;
|
|
|
|
import androidx.annotation.AnimRes;
|
|
|
|
import androidx.annotation.ColorInt;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.annotation.RestrictTo;
|
|
|
|
import androidx.browser.customtabs.CustomTabColorSchemeParams;
|
|
|
|
import androidx.browser.customtabs.CustomTabsSession;
|
|
|
|
import androidx.core.app.ActivityOptionsCompat;
|
|
|
|
import androidx.core.app.BundleCompat;
|
|
|
|
import androidx.core.content.ContextCompat;
|
|
|
|
import c.d.b.a.a;
|
|
|
|
import java.lang.annotation.Retention;
|
|
|
|
import java.lang.annotation.RetentionPolicy;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
public final class CustomTabsIntent {
|
|
|
|
public static final int COLOR_SCHEME_DARK = 2;
|
|
|
|
public static final int COLOR_SCHEME_LIGHT = 1;
|
|
|
|
private static final int COLOR_SCHEME_MAX = 2;
|
|
|
|
public static final int COLOR_SCHEME_SYSTEM = 0;
|
|
|
|
public static final String EXTRA_ACTION_BUTTON_BUNDLE = "android.support.customtabs.extra.ACTION_BUTTON_BUNDLE";
|
|
|
|
public static final String EXTRA_CLOSE_BUTTON_ICON = "android.support.customtabs.extra.CLOSE_BUTTON_ICON";
|
|
|
|
public static final String EXTRA_COLOR_SCHEME = "androidx.browser.customtabs.extra.COLOR_SCHEME";
|
|
|
|
public static final String EXTRA_COLOR_SCHEME_PARAMS = "androidx.browser.customtabs.extra.COLOR_SCHEME_PARAMS";
|
|
|
|
@Deprecated
|
|
|
|
public static final String EXTRA_DEFAULT_SHARE_MENU_ITEM = "android.support.customtabs.extra.SHARE_MENU_ITEM";
|
|
|
|
public static final String EXTRA_ENABLE_INSTANT_APPS = "android.support.customtabs.extra.EXTRA_ENABLE_INSTANT_APPS";
|
|
|
|
public static final String EXTRA_ENABLE_URLBAR_HIDING = "android.support.customtabs.extra.ENABLE_URLBAR_HIDING";
|
|
|
|
public static final String EXTRA_EXIT_ANIMATION_BUNDLE = "android.support.customtabs.extra.EXIT_ANIMATION_BUNDLE";
|
|
|
|
public static final String EXTRA_MENU_ITEMS = "android.support.customtabs.extra.MENU_ITEMS";
|
|
|
|
public static final String EXTRA_NAVIGATION_BAR_COLOR = "androidx.browser.customtabs.extra.NAVIGATION_BAR_COLOR";
|
|
|
|
public static final String EXTRA_NAVIGATION_BAR_DIVIDER_COLOR = "androidx.browser.customtabs.extra.NAVIGATION_BAR_DIVIDER_COLOR";
|
|
|
|
public static final String EXTRA_REMOTEVIEWS = "android.support.customtabs.extra.EXTRA_REMOTEVIEWS";
|
|
|
|
public static final String EXTRA_REMOTEVIEWS_CLICKED_ID = "android.support.customtabs.extra.EXTRA_REMOTEVIEWS_CLICKED_ID";
|
|
|
|
public static final String EXTRA_REMOTEVIEWS_PENDINGINTENT = "android.support.customtabs.extra.EXTRA_REMOTEVIEWS_PENDINGINTENT";
|
|
|
|
public static final String EXTRA_REMOTEVIEWS_VIEW_IDS = "android.support.customtabs.extra.EXTRA_REMOTEVIEWS_VIEW_IDS";
|
|
|
|
public static final String EXTRA_SECONDARY_TOOLBAR_COLOR = "android.support.customtabs.extra.SECONDARY_TOOLBAR_COLOR";
|
|
|
|
public static final String EXTRA_SESSION = "android.support.customtabs.extra.SESSION";
|
|
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY})
|
|
|
|
public static final String EXTRA_SESSION_ID = "android.support.customtabs.extra.SESSION_ID";
|
|
|
|
public static final String EXTRA_SHARE_STATE = "androidx.browser.customtabs.extra.SHARE_STATE";
|
|
|
|
public static final String EXTRA_TINT_ACTION_BUTTON = "android.support.customtabs.extra.TINT_ACTION_BUTTON";
|
|
|
|
public static final String EXTRA_TITLE_VISIBILITY_STATE = "android.support.customtabs.extra.TITLE_VISIBILITY";
|
|
|
|
public static final String EXTRA_TOOLBAR_COLOR = "android.support.customtabs.extra.TOOLBAR_COLOR";
|
|
|
|
public static final String EXTRA_TOOLBAR_ITEMS = "android.support.customtabs.extra.TOOLBAR_ITEMS";
|
|
|
|
private static final String EXTRA_USER_OPT_OUT_FROM_CUSTOM_TABS = "android.support.customtabs.extra.user_opt_out";
|
|
|
|
public static final String KEY_DESCRIPTION = "android.support.customtabs.customaction.DESCRIPTION";
|
|
|
|
public static final String KEY_ICON = "android.support.customtabs.customaction.ICON";
|
|
|
|
public static final String KEY_ID = "android.support.customtabs.customaction.ID";
|
|
|
|
public static final String KEY_MENU_ITEM_TITLE = "android.support.customtabs.customaction.MENU_ITEM_TITLE";
|
|
|
|
public static final String KEY_PENDING_INTENT = "android.support.customtabs.customaction.PENDING_INTENT";
|
|
|
|
private static final int MAX_TOOLBAR_ITEMS = 5;
|
|
|
|
public static final int NO_TITLE = 0;
|
|
|
|
public static final int SHARE_STATE_DEFAULT = 0;
|
|
|
|
private static final int SHARE_STATE_MAX = 2;
|
|
|
|
public static final int SHARE_STATE_OFF = 2;
|
|
|
|
public static final int SHARE_STATE_ON = 1;
|
|
|
|
public static final int SHOW_PAGE_TITLE = 1;
|
|
|
|
public static final int TOOLBAR_ACTION_BUTTON_ID = 0;
|
|
|
|
@NonNull
|
|
|
|
public final Intent intent;
|
|
|
|
@Nullable
|
|
|
|
public final Bundle startAnimationBundle;
|
|
|
|
|
|
|
|
public static final class Builder {
|
|
|
|
@Nullable
|
|
|
|
private ArrayList<Bundle> mActionButtons;
|
|
|
|
@Nullable
|
|
|
|
private SparseArray<Bundle> mColorSchemeParamBundles;
|
|
|
|
private final CustomTabColorSchemeParams.Builder mDefaultColorSchemeBuilder = new CustomTabColorSchemeParams.Builder();
|
|
|
|
@Nullable
|
|
|
|
private Bundle mDefaultColorSchemeBundle;
|
|
|
|
private boolean mInstantAppsEnabled = true;
|
|
|
|
private final Intent mIntent = new Intent("android.intent.action.VIEW");
|
|
|
|
@Nullable
|
|
|
|
private ArrayList<Bundle> mMenuItems;
|
|
|
|
private int mShareState = 0;
|
|
|
|
@Nullable
|
|
|
|
private Bundle mStartAnimationBundle;
|
|
|
|
|
|
|
|
public Builder() {
|
|
|
|
}
|
|
|
|
|
|
|
|
public Builder(@Nullable CustomTabsSession customTabsSession) {
|
|
|
|
if (customTabsSession != null) {
|
|
|
|
setSession(customTabsSession);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setSessionParameters(@Nullable IBinder iBinder, @Nullable PendingIntent pendingIntent) {
|
|
|
|
Bundle bundle = new Bundle();
|
2021-08-09 22:50:52 +00:00
|
|
|
BundleCompat.putBinder(bundle, CustomTabsIntent.EXTRA_SESSION, iBinder);
|
2021-06-27 20:44:35 +00:00
|
|
|
if (pendingIntent != null) {
|
2021-08-09 22:50:52 +00:00
|
|
|
bundle.putParcelable(CustomTabsIntent.EXTRA_SESSION_ID, pendingIntent);
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
this.mIntent.putExtras(bundle);
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@Deprecated
|
|
|
|
public Builder addDefaultShareMenuItem() {
|
|
|
|
setShareState(1);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public Builder addMenuItem(@NonNull String str, @NonNull PendingIntent pendingIntent) {
|
|
|
|
if (this.mMenuItems == null) {
|
|
|
|
this.mMenuItems = new ArrayList<>();
|
|
|
|
}
|
|
|
|
Bundle bundle = new Bundle();
|
2021-08-09 22:50:52 +00:00
|
|
|
bundle.putString(CustomTabsIntent.KEY_MENU_ITEM_TITLE, str);
|
|
|
|
bundle.putParcelable(CustomTabsIntent.KEY_PENDING_INTENT, pendingIntent);
|
2021-06-27 20:44:35 +00:00
|
|
|
this.mMenuItems.add(bundle);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@Deprecated
|
|
|
|
public Builder addToolbarItem(int i, @NonNull Bitmap bitmap, @NonNull String str, @NonNull PendingIntent pendingIntent) throws IllegalStateException {
|
|
|
|
if (this.mActionButtons == null) {
|
|
|
|
this.mActionButtons = new ArrayList<>();
|
|
|
|
}
|
|
|
|
if (this.mActionButtons.size() < 5) {
|
|
|
|
Bundle bundle = new Bundle();
|
2021-08-09 22:50:52 +00:00
|
|
|
bundle.putInt(CustomTabsIntent.KEY_ID, i);
|
|
|
|
bundle.putParcelable(CustomTabsIntent.KEY_ICON, bitmap);
|
|
|
|
bundle.putString(CustomTabsIntent.KEY_DESCRIPTION, str);
|
|
|
|
bundle.putParcelable(CustomTabsIntent.KEY_PENDING_INTENT, pendingIntent);
|
2021-06-27 20:44:35 +00:00
|
|
|
this.mActionButtons.add(bundle);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
throw new IllegalStateException("Exceeded maximum toolbar item count of 5");
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public CustomTabsIntent build() {
|
2021-08-09 22:50:52 +00:00
|
|
|
if (!this.mIntent.hasExtra(CustomTabsIntent.EXTRA_SESSION)) {
|
2021-06-27 20:44:35 +00:00
|
|
|
setSessionParameters(null, null);
|
|
|
|
}
|
|
|
|
ArrayList<Bundle> arrayList = this.mMenuItems;
|
|
|
|
if (arrayList != null) {
|
2021-08-09 22:50:52 +00:00
|
|
|
this.mIntent.putParcelableArrayListExtra(CustomTabsIntent.EXTRA_MENU_ITEMS, arrayList);
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
ArrayList<Bundle> arrayList2 = this.mActionButtons;
|
|
|
|
if (arrayList2 != null) {
|
2021-08-09 22:50:52 +00:00
|
|
|
this.mIntent.putParcelableArrayListExtra(CustomTabsIntent.EXTRA_TOOLBAR_ITEMS, arrayList2);
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
2021-08-09 22:50:52 +00:00
|
|
|
this.mIntent.putExtra(CustomTabsIntent.EXTRA_ENABLE_INSTANT_APPS, this.mInstantAppsEnabled);
|
2021-06-27 20:44:35 +00:00
|
|
|
this.mIntent.putExtras(this.mDefaultColorSchemeBuilder.build().toBundle());
|
|
|
|
Bundle bundle = this.mDefaultColorSchemeBundle;
|
|
|
|
if (bundle != null) {
|
|
|
|
this.mIntent.putExtras(bundle);
|
|
|
|
}
|
|
|
|
if (this.mColorSchemeParamBundles != null) {
|
|
|
|
Bundle bundle2 = new Bundle();
|
2021-08-09 22:50:52 +00:00
|
|
|
bundle2.putSparseParcelableArray(CustomTabsIntent.EXTRA_COLOR_SCHEME_PARAMS, this.mColorSchemeParamBundles);
|
2021-06-27 20:44:35 +00:00
|
|
|
this.mIntent.putExtras(bundle2);
|
|
|
|
}
|
2021-08-09 22:50:52 +00:00
|
|
|
this.mIntent.putExtra(CustomTabsIntent.EXTRA_SHARE_STATE, this.mShareState);
|
2021-06-27 20:44:35 +00:00
|
|
|
return new CustomTabsIntent(this.mIntent, this.mStartAnimationBundle);
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@Deprecated
|
|
|
|
public Builder enableUrlBarHiding() {
|
2021-08-09 22:50:52 +00:00
|
|
|
this.mIntent.putExtra(CustomTabsIntent.EXTRA_ENABLE_URLBAR_HIDING, true);
|
2021-06-27 20:44:35 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public Builder setActionButton(@NonNull Bitmap bitmap, @NonNull String str, @NonNull PendingIntent pendingIntent) {
|
|
|
|
return setActionButton(bitmap, str, pendingIntent, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public Builder setActionButton(@NonNull Bitmap bitmap, @NonNull String str, @NonNull PendingIntent pendingIntent, boolean z2) {
|
|
|
|
Bundle bundle = new Bundle();
|
2021-08-09 22:50:52 +00:00
|
|
|
bundle.putInt(CustomTabsIntent.KEY_ID, 0);
|
|
|
|
bundle.putParcelable(CustomTabsIntent.KEY_ICON, bitmap);
|
|
|
|
bundle.putString(CustomTabsIntent.KEY_DESCRIPTION, str);
|
|
|
|
bundle.putParcelable(CustomTabsIntent.KEY_PENDING_INTENT, pendingIntent);
|
|
|
|
this.mIntent.putExtra(CustomTabsIntent.EXTRA_ACTION_BUTTON_BUNDLE, bundle);
|
|
|
|
this.mIntent.putExtra(CustomTabsIntent.EXTRA_TINT_ACTION_BUTTON, z2);
|
2021-06-27 20:44:35 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public Builder setCloseButtonIcon(@NonNull Bitmap bitmap) {
|
2021-08-09 22:50:52 +00:00
|
|
|
this.mIntent.putExtra(CustomTabsIntent.EXTRA_CLOSE_BUTTON_ICON, bitmap);
|
2021-06-27 20:44:35 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public Builder setColorScheme(int i) {
|
|
|
|
if (i < 0 || i > 2) {
|
|
|
|
throw new IllegalArgumentException("Invalid value for the colorScheme argument");
|
|
|
|
}
|
2021-08-09 22:50:52 +00:00
|
|
|
this.mIntent.putExtra(CustomTabsIntent.EXTRA_COLOR_SCHEME, i);
|
2021-06-27 20:44:35 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public Builder setColorSchemeParams(int i, @NonNull CustomTabColorSchemeParams customTabColorSchemeParams) {
|
|
|
|
if (i < 0 || i > 2 || i == 0) {
|
2021-08-31 07:21:49 +00:00
|
|
|
throw new IllegalArgumentException(a.l("Invalid colorScheme: ", i));
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
if (this.mColorSchemeParamBundles == null) {
|
|
|
|
this.mColorSchemeParamBundles = new SparseArray<>();
|
|
|
|
}
|
|
|
|
this.mColorSchemeParamBundles.put(i, customTabColorSchemeParams.toBundle());
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public Builder setDefaultColorSchemeParams(@NonNull CustomTabColorSchemeParams customTabColorSchemeParams) {
|
|
|
|
this.mDefaultColorSchemeBundle = customTabColorSchemeParams.toBundle();
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@Deprecated
|
|
|
|
public Builder setDefaultShareMenuItemEnabled(boolean z2) {
|
|
|
|
if (z2) {
|
|
|
|
setShareState(1);
|
|
|
|
} else {
|
|
|
|
setShareState(2);
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public Builder setExitAnimations(@NonNull Context context, @AnimRes int i, @AnimRes int i2) {
|
2021-08-09 22:50:52 +00:00
|
|
|
this.mIntent.putExtra(CustomTabsIntent.EXTRA_EXIT_ANIMATION_BUNDLE, ActivityOptionsCompat.makeCustomAnimation(context, i, i2).toBundle());
|
2021-06-27 20:44:35 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public Builder setInstantAppsEnabled(boolean z2) {
|
|
|
|
this.mInstantAppsEnabled = z2;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@Deprecated
|
|
|
|
public Builder setNavigationBarColor(@ColorInt int i) {
|
|
|
|
this.mDefaultColorSchemeBuilder.setNavigationBarColor(i);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@Deprecated
|
|
|
|
public Builder setNavigationBarDividerColor(@ColorInt int i) {
|
|
|
|
this.mDefaultColorSchemeBuilder.setNavigationBarDividerColor(i);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY})
|
|
|
|
public Builder setPendingSession(@NonNull CustomTabsSession.PendingSession pendingSession) {
|
|
|
|
setSessionParameters(null, pendingSession.getId());
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@Deprecated
|
|
|
|
public Builder setSecondaryToolbarColor(@ColorInt int i) {
|
|
|
|
this.mDefaultColorSchemeBuilder.setSecondaryToolbarColor(i);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public Builder setSecondaryToolbarViews(@NonNull RemoteViews remoteViews, @Nullable int[] iArr, @Nullable PendingIntent pendingIntent) {
|
2021-08-09 22:50:52 +00:00
|
|
|
this.mIntent.putExtra(CustomTabsIntent.EXTRA_REMOTEVIEWS, remoteViews);
|
|
|
|
this.mIntent.putExtra(CustomTabsIntent.EXTRA_REMOTEVIEWS_VIEW_IDS, iArr);
|
|
|
|
this.mIntent.putExtra(CustomTabsIntent.EXTRA_REMOTEVIEWS_PENDINGINTENT, pendingIntent);
|
2021-06-27 20:44:35 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public Builder setSession(@NonNull CustomTabsSession customTabsSession) {
|
|
|
|
this.mIntent.setPackage(customTabsSession.getComponentName().getPackageName());
|
|
|
|
setSessionParameters(customTabsSession.getBinder(), customTabsSession.getId());
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public Builder setShareState(int i) {
|
|
|
|
if (i < 0 || i > 2) {
|
|
|
|
throw new IllegalArgumentException("Invalid value for the shareState argument");
|
|
|
|
}
|
|
|
|
this.mShareState = i;
|
|
|
|
if (i == 1) {
|
2021-08-09 22:50:52 +00:00
|
|
|
this.mIntent.putExtra(CustomTabsIntent.EXTRA_DEFAULT_SHARE_MENU_ITEM, true);
|
2021-06-27 20:44:35 +00:00
|
|
|
} else if (i == 2) {
|
2021-08-09 22:50:52 +00:00
|
|
|
this.mIntent.putExtra(CustomTabsIntent.EXTRA_DEFAULT_SHARE_MENU_ITEM, false);
|
2021-06-27 20:44:35 +00:00
|
|
|
} else {
|
2021-08-09 22:50:52 +00:00
|
|
|
this.mIntent.removeExtra(CustomTabsIntent.EXTRA_DEFAULT_SHARE_MENU_ITEM);
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public Builder setShowTitle(boolean z2) {
|
2021-08-09 22:50:52 +00:00
|
|
|
this.mIntent.putExtra(CustomTabsIntent.EXTRA_TITLE_VISIBILITY_STATE, z2 ? 1 : 0);
|
2021-06-27 20:44:35 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public Builder setStartAnimations(@NonNull Context context, @AnimRes int i, @AnimRes int i2) {
|
|
|
|
this.mStartAnimationBundle = ActivityOptionsCompat.makeCustomAnimation(context, i, i2).toBundle();
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@Deprecated
|
|
|
|
public Builder setToolbarColor(@ColorInt int i) {
|
|
|
|
this.mDefaultColorSchemeBuilder.setToolbarColor(i);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public Builder setUrlBarHidingEnabled(boolean z2) {
|
2021-08-09 22:50:52 +00:00
|
|
|
this.mIntent.putExtra(CustomTabsIntent.EXTRA_ENABLE_URLBAR_HIDING, z2);
|
2021-06-27 20:44:35 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Retention(RetentionPolicy.SOURCE)
|
|
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY})
|
|
|
|
public @interface ColorScheme {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Retention(RetentionPolicy.SOURCE)
|
|
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY})
|
|
|
|
public @interface ShareState {
|
|
|
|
}
|
|
|
|
|
|
|
|
public CustomTabsIntent(@NonNull Intent intent, @Nullable Bundle bundle) {
|
|
|
|
this.intent = intent;
|
|
|
|
this.startAnimationBundle = bundle;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public static CustomTabColorSchemeParams getColorSchemeParams(@NonNull Intent intent, int i) {
|
|
|
|
Bundle bundle;
|
|
|
|
if (i < 0 || i > 2 || i == 0) {
|
2021-08-31 07:21:49 +00:00
|
|
|
throw new IllegalArgumentException(a.l("Invalid colorScheme: ", i));
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
Bundle extras = intent.getExtras();
|
|
|
|
if (extras == null) {
|
|
|
|
return CustomTabColorSchemeParams.fromBundle(null);
|
|
|
|
}
|
|
|
|
CustomTabColorSchemeParams fromBundle = CustomTabColorSchemeParams.fromBundle(extras);
|
2021-08-09 22:50:52 +00:00
|
|
|
SparseArray sparseParcelableArray = extras.getSparseParcelableArray(EXTRA_COLOR_SCHEME_PARAMS);
|
2021-06-27 20:44:35 +00:00
|
|
|
return (sparseParcelableArray == null || (bundle = (Bundle) sparseParcelableArray.get(i)) == null) ? fromBundle : CustomTabColorSchemeParams.fromBundle(bundle).withDefaults(fromBundle);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getMaxToolbarItems() {
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public static Intent setAlwaysUseBrowserUI(@Nullable Intent intent) {
|
|
|
|
if (intent == null) {
|
|
|
|
intent = new Intent("android.intent.action.VIEW");
|
|
|
|
}
|
|
|
|
intent.addFlags(268435456);
|
2021-08-09 22:50:52 +00:00
|
|
|
intent.putExtra(EXTRA_USER_OPT_OUT_FROM_CUSTOM_TABS, true);
|
2021-06-27 20:44:35 +00:00
|
|
|
return intent;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean shouldAlwaysUseBrowserUI(@NonNull Intent intent) {
|
2021-08-09 22:50:52 +00:00
|
|
|
return intent.getBooleanExtra(EXTRA_USER_OPT_OUT_FROM_CUSTOM_TABS, false) && (intent.getFlags() & 268435456) != 0;
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void launchUrl(@NonNull Context context, @NonNull Uri uri) {
|
|
|
|
this.intent.setData(uri);
|
|
|
|
ContextCompat.startActivity(context, this.intent, this.startAnimationBundle);
|
|
|
|
}
|
|
|
|
}
|