Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
Get latest updates to support lib
Browse files Browse the repository at this point in the history
-Add an extra in Custom Tabs Intent to enable Instant Apps
-Add methods to opt out from launching custom tabs

Review-Url: https://codereview.chromium.org/2237143003
  • Loading branch information
yusufo authored and Commit bot committed Aug 12, 2016
1 parent 2d896e8 commit c51efbd
Showing 1 changed file with 48 additions and 4 deletions.
52 changes: 48 additions & 4 deletions customtabs/src/android/support/customtabs/CustomTabsIntent.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ public final class CustomTabsIntent {
* Indicates that the user explicitly opted out of Custom Tabs in the calling application.
* <p>
* If an application provides a mechanism for users to opt out of Custom Tabs, this extra should
* be provided to ensure the browser does not attempt to trigger any Custom Tab-like experiences
* as a result of the VIEW intent.
* be provided with {@link Intent#FLAG_ACTIVITY_NEW_TASK} to ensure the browser does not attempt
* to trigger any Custom Tab-like experiences as a result of the VIEW intent.
* <p>
* If this extra is present, all Custom Tabs customizations will be ignored.
* If this extra is present with {@link Intent#FLAG_ACTIVITY_NEW_TASK}, all Custom Tabs
* customizations will be ignored.
*/
public static final String EXTRA_USER_OPT_OUT_FROM_CUSTOM_TABS =
private static final String EXTRA_USER_OPT_OUT_FROM_CUSTOM_TABS =
"android.support.customtabs.extra.user_opt_out";

/**
Expand Down Expand Up @@ -219,6 +220,11 @@ public final class CustomTabsIntent {
public static final String EXTRA_REMOTEVIEWS_CLICKED_ID =
"android.support.customtabs.extra.EXTRA_REMOTEVIEWS_CLICKED_ID";

/**
* Extra that specifies whether Instant Apps is enabled.
*/
public static final String EXTRA_ENABLE_INSTANT_APPS =
"android.support.customtabs.extra.EXTRA_ENABLE_INSTANT_APPS";

/**
* Key that specifies the unique ID for an action button. To make a button to show on the
Expand Down Expand Up @@ -269,6 +275,7 @@ public static final class Builder {
private ArrayList<Bundle> mMenuItems = null;
private Bundle mStartAnimationBundle = null;
private ArrayList<Bundle> mActionButtons = null;
private boolean mInstantAppsEnabled = true;

/**
* Creates a {@link CustomTabsIntent.Builder} object associated with no
Expand Down Expand Up @@ -463,6 +470,16 @@ public Builder setSecondaryToolbarViews(@NonNull RemoteViews remoteViews,
return this;
}

/**
* Sets whether Instant Apps is enabled for this Custom Tab.
* @param enabled Whether Instant Apps should be enabled.
*/
public Builder setInstantAppsEnabled(boolean enabled) {
mInstantAppsEnabled = enabled;
return this;
}

/**
* Sets the start animations.
*
Expand Down Expand Up @@ -503,6 +520,7 @@ public CustomTabsIntent build() {
if (mActionButtons != null) {
mIntent.putParcelableArrayListExtra(EXTRA_TOOLBAR_ITEMS, mActionButtons);
}
mIntent.putExtra(EXTRA_ENABLE_INSTANT_APPS, mInstantAppsEnabled);
return new CustomTabsIntent(mIntent, mStartAnimationBundle);
}
}
Expand All @@ -515,4 +533,30 @@ public CustomTabsIntent build() {
public static int getMaxToolbarItems() {
return MAX_TOOLBAR_ITEMS;
}

/**
* Adds the necessary flags and extras to signal any browser supporting custom tabs to use the
* browser UI at all times and avoid showing custom tab like UI. Calling this with an intent
* will override any custom tabs related customizations.
* @param intent The intent to modify for always showing browser UI.
* @return The same intent with the necessary flags and extras added.
*/
public static Intent setAlwaysUseBrowserUI(Intent intent) {
if (intent == null) intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(EXTRA_USER_OPT_OUT_FROM_CUSTOM_TABS, true);
return intent;
}

/**
* Whether a browser receiving the given intent should always use browser UI and avoid using any
* custom tabs UI.
*
* @param intent The intent to check for the required flags and extras.
* @return Whether the browser UI should be used exclusively.
*/
public static boolean shouldAlwaysUseBrowserUI(Intent intent) {
return intent.getBooleanExtra(EXTRA_USER_OPT_OUT_FROM_CUSTOM_TABS, false)
&& (intent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) != 0;
}
}

0 comments on commit c51efbd

Please sign in to comment.