CustomTabsIntent.java revision 2c1994fe5a72dc1a6c320034f86598a168ce4527
108889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal/*
208889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal * Copyright (C) 2015 The Android Open Source Project
308889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal *
408889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal * Licensed under the Apache License, Version 2.0 (the "License");
508889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal * you may not use this file except in compliance with the License.
608889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal * You may obtain a copy of the License at
708889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal *
808889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal *      http://www.apache.org/licenses/LICENSE-2.0
908889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal *
1008889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal * Unless required by applicable law or agreed to in writing, software
1108889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal * distributed under the License is distributed on an "AS IS" BASIS,
1208889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1308889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal * See the License for the specific language governing permissions and
1408889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal * limitations under the License.
1508889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal */
1608889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal
1708889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysalpackage android.support.customtabs;
1808889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal
1908889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysalimport android.app.Activity;
2008889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysalimport android.app.PendingIntent;
2197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lizeimport android.content.Context;
2208889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysalimport android.content.Intent;
2308889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysalimport android.graphics.Bitmap;
2408889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysalimport android.graphics.Color;
2508889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysalimport android.net.Uri;
2608889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysalimport android.os.Bundle;
2797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lizeimport android.support.annotation.AnimRes;
28e063d4d36883c9f7ca100036b9344b665ab6fd1eYusuf Ozuysalimport android.support.annotation.ColorInt;
29c5c0045de7c8848144a570665e0d3c950816f314Yusuf Ozuysalimport android.support.annotation.NonNull;
3097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lizeimport android.support.annotation.Nullable;
311b7158bbc0d0ba4569881f547d12f52e405e125eIan Lakeimport android.support.v4.app.ActivityCompat;
321b7158bbc0d0ba4569881f547d12f52e405e125eIan Lakeimport android.support.v4.app.ActivityOptionsCompat;
33c5c0045de7c8848144a570665e0d3c950816f314Yusuf Ozuysalimport android.support.v4.app.BundleCompat;
34f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysalimport android.view.View;
35f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysalimport android.widget.RemoteViews;
3608889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal
3797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lizeimport java.util.ArrayList;
3808889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal
3908889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal/**
4097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * Class holding the {@link Intent} and start bundle for a Custom Tabs Activity.
4197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize *
4297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * <p>
4397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * <strong>Note:</strong> The constants below are public for the browser implementation's benefit.
4497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * You are strongly encouraged to use {@link CustomTabsIntent.Builder}.</p>
4508889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal */
4697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lizepublic final class CustomTabsIntent {
4708889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal
4808889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal    /**
4908889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal     * Extra used to match the session. This has to be included in the intent to open in
5008889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal     * a custom tab. This is the same IBinder that gets passed to ICustomTabsService#newSession.
5108889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal     * Null if there is no need to match any service side sessions with the intent.
5208889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal     */
5308889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal    public static final String EXTRA_SESSION = "android.support.customtabs.extra.SESSION";
5408889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal
5508889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal    /**
5608889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal     * Extra that changes the background color for the toolbar. colorRes is an int that specifies a
5708889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal     * {@link Color}, not a resource id.
5808889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal     */
5908889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal    public static final String EXTRA_TOOLBAR_COLOR =
6008889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal            "android.support.customtabs.extra.TOOLBAR_COLOR";
6108889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal
6208889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal    /**
639440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal     * Boolean extra that enables the url bar to hide as the user scrolls down the page
649440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal     */
659440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal    public static final String EXTRA_ENABLE_URLBAR_HIDING =
669440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal            "android.support.customtabs.extra.ENABLE_URLBAR_HIDING";
679440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal
689440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal    /**
6997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize     * Extra bitmap that specifies the icon of the back button on the toolbar. If the client chooses
7097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize     * not to customize it, a default close button will be used.
7197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize     */
7297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize    public static final String EXTRA_CLOSE_BUTTON_ICON =
7397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize            "android.support.customtabs.extra.CLOSE_BUTTON_ICON";
7497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize
7597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize    /**
7697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize     * Extra (int) that specifies state for showing the page title. Default is {@link #NO_TITLE}.
7797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize     */
7897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize    public static final String EXTRA_TITLE_VISIBILITY_STATE =
7997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize            "android.support.customtabs.extra.TITLE_VISIBILITY";
8097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize
8197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize    /**
8297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize     * Don't show any title. Shows only the domain.
8397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize     */
8497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize    public static final int NO_TITLE = 0;
8597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize
8697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize    /**
8797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize     * Shows the page title and the domain.
8897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize     */
8997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize    public static final int SHOW_PAGE_TITLE = 1;
9097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize
9197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize    /**
928a1ccd14081000d6501622de72a16da67c33030cYusuf Ozuysal     * Bundle used for adding a custom action button to the custom tab toolbar. The client should
938a1ccd14081000d6501622de72a16da67c33030cYusuf Ozuysal     * provide a description, an icon {@link Bitmap} and a {@link PendingIntent} for the button.
948a1ccd14081000d6501622de72a16da67c33030cYusuf Ozuysal     * All three keys must be present.
9508889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal     */
9608889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal    public static final String EXTRA_ACTION_BUTTON_BUNDLE =
9708889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal            "android.support.customtabs.extra.ACTION_BUTTON_BUNDLE";
9808889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal
9908889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal    /**
10031d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal     * List<Bundle> used for adding items to the top and bottom toolbars. The client should
101179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal     * provide an ID, a description, an icon {@link Bitmap} for each item. They may also provide a
102179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal     * {@link PendingIntent} if the item is a button.
103179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal     */
10431d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal    public static final String EXTRA_TOOLBAR_ITEMS =
10531d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal            "android.support.customtabs.extra.TOOLBAR_ITEMS";
106179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal
107179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal    /**
10831d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal     * Extra that changes the background color for the secondary toolbar. The value should be an
10964694064caedb59afda4ef69b04feaee12c0a33fYusuf Ozuysal     * int that specifies a {@link Color}, not a resource id.
11064694064caedb59afda4ef69b04feaee12c0a33fYusuf Ozuysal     */
11131d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal    public static final String EXTRA_SECONDARY_TOOLBAR_COLOR =
11231d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal            "android.support.customtabs.extra.SECONDARY_TOOLBAR_COLOR";
11364694064caedb59afda4ef69b04feaee12c0a33fYusuf Ozuysal
11464694064caedb59afda4ef69b04feaee12c0a33fYusuf Ozuysal    /**
11508889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal     * Key that specifies the {@link Bitmap} to be used as the image source for the action button.
1168a1ccd14081000d6501622de72a16da67c33030cYusuf Ozuysal     *  The icon should't be more than 24dp in height (No padding needed. The button itself will be
1178a1ccd14081000d6501622de72a16da67c33030cYusuf Ozuysal     *  48dp in height) and have a width/height ratio of less than 2.
11808889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal     */
11908889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal    public static final String KEY_ICON = "android.support.customtabs.customaction.ICON";
12008889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal
12108889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal    /**
1228a1ccd14081000d6501622de72a16da67c33030cYusuf Ozuysal     * Key that specifies the content description for the custom action button.
1238a1ccd14081000d6501622de72a16da67c33030cYusuf Ozuysal     */
1248a1ccd14081000d6501622de72a16da67c33030cYusuf Ozuysal    public static final String KEY_DESCRIPTION =
1258a1ccd14081000d6501622de72a16da67c33030cYusuf Ozuysal            "android.support.customtabs.customaction.DESCRIPTION";
1268a1ccd14081000d6501622de72a16da67c33030cYusuf Ozuysal
1278a1ccd14081000d6501622de72a16da67c33030cYusuf Ozuysal    /**
12808889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal     * Key that specifies the PendingIntent to launch when the action button or menu item was
12908889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal     * clicked. The custom tab will be calling {@link PendingIntent#send()} on clicks after adding
13008889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal     * the url as data. The client app can call {@link Intent#getDataString()} to get the url.
13108889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal     */
13208889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal    public static final String KEY_PENDING_INTENT =
13308889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal            "android.support.customtabs.customaction.PENDING_INTENT";
13408889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal
13508889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal    /**
1369440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal     * Extra boolean that specifies whether the custom action button should be tinted. Default is
1379440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal     * false and the action button will not be tinted.
1389440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal     */
1399440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal    public static final String EXTRA_TINT_ACTION_BUTTON =
1409440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal            "android.support.customtabs.extra.TINT_ACTION_BUTTON";
1419440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal
1429440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal    /**
14308889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal     * Use an {@code ArrayList<Bundle>} for specifying menu related params. There should be a
14408889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal     * separate {@link Bundle} for each custom menu item.
14508889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal     */
14608889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal    public static final String EXTRA_MENU_ITEMS = "android.support.customtabs.extra.MENU_ITEMS";
14708889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal
14808889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal    /**
14908889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal     * Key for specifying the title of a menu item.
15008889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal     */
15108889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal    public static final String KEY_MENU_ITEM_TITLE =
15208889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal            "android.support.customtabs.customaction.MENU_ITEM_TITLE";
15308889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal
15408889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal    /**
1551b7158bbc0d0ba4569881f547d12f52e405e125eIan Lake     * Bundle constructed out of {@link ActivityOptionsCompat} that will be running when the
15608889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal     * {@link Activity} that holds the custom tab gets finished. A similar ActivityOptions
15708889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal     * for creation should be constructed and given to the startActivity() call that
15808889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal     * launches the custom tab.
15908889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal     */
16008889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal    public static final String EXTRA_EXIT_ANIMATION_BUNDLE =
16108889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal            "android.support.customtabs.extra.EXIT_ANIMATION_BUNDLE";
16208889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal
16308889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal    /**
1648b26db5521378d84391e4ac4c932ca39d1ac83e1Yusuf Ozuysal     * Boolean extra that specifies whether a default share button will be shown in the menu.
1658b26db5521378d84391e4ac4c932ca39d1ac83e1Yusuf Ozuysal     */
1668b26db5521378d84391e4ac4c932ca39d1ac83e1Yusuf Ozuysal    public static final String EXTRA_DEFAULT_SHARE_MENU_ITEM =
1678b26db5521378d84391e4ac4c932ca39d1ac83e1Yusuf Ozuysal            "android.support.customtabs.extra.SHARE_MENU_ITEM";
1688b26db5521378d84391e4ac4c932ca39d1ac83e1Yusuf Ozuysal
1698b26db5521378d84391e4ac4c932ca39d1ac83e1Yusuf Ozuysal    /**
170f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal     * Extra that specifies the {@link RemoteViews} showing on the secondary toolbar. If this extra
171f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal     * is set, the other secondary toolbar configurations will be overriden. The height of the
172f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal     * {@link RemoteViews} should not exceed 56dp.
173f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal     * @see CustomTabsIntent.Builder#setSecondaryToolbarViews(RemoteViews, int[], PendingIntent).
174f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal     */
175f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal    public static final String EXTRA_REMOTEVIEWS =
176f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal            "android.support.customtabs.extra.EXTRA_REMOTEVIEWS";
177f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal
178f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal    /**
179f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal     * Extra that specifies an array of {@link View} ids. When these {@link View}s are clicked, a
180f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal     * {@link PendingIntent} will be sent, carrying the current url of the custom tab as data.
181f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal     * <p>
182f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal     * Note that Custom Tabs will override the default onClick behavior of the listed {@link View}s.
183f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal     * If you do not care about the current url, you can safely ignore this extra and use
184f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal     * {@link RemoteViews#setOnClickPendingIntent(int, PendingIntent)} instead.
185f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal     * @see CustomTabsIntent.Builder#setSecondaryToolbarViews(RemoteViews, int[], PendingIntent).
186f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal     */
187f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal    public static final String EXTRA_REMOTEVIEWS_VIEW_IDS =
188f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal            "android.support.customtabs.extra.EXTRA_REMOTEVIEWS_VIEW_IDS";
189f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal
190f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal    /**
191f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal     * Extra that specifies the {@link PendingIntent} to be sent when the user clicks on the
192d0f2cc4ee9ac45be16119a04433d4dd3ddf9e576Yusuf Ozuysal     * {@link View}s that is listed by {@link #EXTRA_REMOTEVIEWS_VIEW_IDS}.
193f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal     * <p>
194f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal     * Note when this {@link PendingIntent} is triggered, it will have the current url as data
195f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal     * field, also the id of the clicked {@link View}, specified by
196f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal     * {@link #EXTRA_REMOTEVIEWS_CLICKED_ID}.
197f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal     * @see CustomTabsIntent.Builder#setSecondaryToolbarViews(RemoteViews, int[], PendingIntent).
198f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal     */
199f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal    public static final String EXTRA_REMOTEVIEWS_PENDINGINTENT =
200f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal            "android.support.customtabs.extra.EXTRA_REMOTEVIEWS_PENDINGINTENT";
201f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal
202f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal    /**
203f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal     * Extra that specifies which {@link View} has been clicked. This extra will be put to the
204f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal     * {@link PendingIntent} sent from Custom Tabs when a view in the {@link RemoteViews} is clicked
205f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal     * @see CustomTabsIntent.Builder#setSecondaryToolbarViews(RemoteViews, int[], PendingIntent).
206f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal     */
207f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal    public static final String EXTRA_REMOTEVIEWS_CLICKED_ID =
208f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal            "android.support.customtabs.extra.EXTRA_REMOTEVIEWS_CLICKED_ID";
209f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal
2102c1994fe5a72dc1a6c320034f86598a168ce4527Ian Wen    /**
2112c1994fe5a72dc1a6c320034f86598a168ce4527Ian Wen     * Extra that specifies whether Instant Apps is enabled.
2122c1994fe5a72dc1a6c320034f86598a168ce4527Ian Wen     */
2132c1994fe5a72dc1a6c320034f86598a168ce4527Ian Wen    public static final String EXTRA_ENABLE_INSTANT_APPS =
2142c1994fe5a72dc1a6c320034f86598a168ce4527Ian Wen            "android.support.customtabs.extra.EXTRA_ENABLE_INSTANT_APPS";
215f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal
216f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal    /**
217179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal     * Key that specifies the unique ID for an action button. To make a button to show on the
218179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal     * toolbar, use {@link #TOOLBAR_ACTION_BUTTON_ID} as its ID.
219179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal     */
220179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal    public static final String KEY_ID = "android.support.customtabs.customaction.ID";
221179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal
222179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal    /**
223179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal     * The ID allocated to the custom action button that is shown on the toolbar.
224179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal     */
225179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal    public static final int TOOLBAR_ACTION_BUTTON_ID = 0;
226179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal
227179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal    /**
22831d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal     * The maximum allowed number of toolbar items.
229179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal     */
23031d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal    private static final int MAX_TOOLBAR_ITEMS = 5;
231179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal
232179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal    /**
23397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize     * An {@link Intent} used to start the Custom Tabs Activity.
23497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize     */
23597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize    @NonNull public final Intent intent;
23697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize
23797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize    /**
23897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize     * A {@link Bundle} containing the start animation for the Custom Tabs Activity.
23908889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal     */
24097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize    @Nullable public final Bundle startAnimationBundle;
24197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize
24297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize    /**
24397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize     * Convenience method to launch a Custom Tabs Activity.
24497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize     * @param context The source Activity.
24597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize     * @param url The URL to load in the Custom Tab.
24697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize     */
24797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize    public void launchUrl(Activity context, Uri url) {
24897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        intent.setData(url);
2491b7158bbc0d0ba4569881f547d12f52e405e125eIan Lake        ActivityCompat.startActivity(context, intent, startAnimationBundle);
25097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize    }
25197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize
25297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize    private CustomTabsIntent(Intent intent, Bundle startAnimationBundle) {
25397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        this.intent = intent;
25497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        this.startAnimationBundle = startAnimationBundle;
25508889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal    }
25608889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal
25708889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal    /**
25897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize     * Builder class for {@link CustomTabsIntent} objects.
25997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize     */
26097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize    public static final class Builder {
26197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        private final Intent mIntent = new Intent(Intent.ACTION_VIEW);
26297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        private ArrayList<Bundle> mMenuItems = null;
26397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        private Bundle mStartAnimationBundle = null;
264179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal        private ArrayList<Bundle> mActionButtons = null;
2652c1994fe5a72dc1a6c320034f86598a168ce4527Ian Wen        private boolean mInstantAppsEnabled = true;
26697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize
26797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        /**
26897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         * Creates a {@link CustomTabsIntent.Builder} object associated with no
26997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         * {@link CustomTabsSession}.
27097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         */
27197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        public Builder() {
27297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize            this(null);
27397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        }
27497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize
27597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        /**
27697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         * Creates a {@link CustomTabsIntent.Builder} object associated with a given
27797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         * {@link CustomTabsSession}.
27897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         *
27997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         * Guarantees that the {@link Intent} will be sent to the same component as the one the
28097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         * session is associated with.
28197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         *
28297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         * @param session The session to associate this Builder with.
28397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         */
28497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        public Builder(@Nullable CustomTabsSession session) {
28597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize            if (session != null) mIntent.setPackage(session.getComponentName().getPackageName());
28697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize            Bundle bundle = new Bundle();
287c5c0045de7c8848144a570665e0d3c950816f314Yusuf Ozuysal            BundleCompat.putBinder(
288c5c0045de7c8848144a570665e0d3c950816f314Yusuf Ozuysal                    bundle, EXTRA_SESSION, session == null ? null : session.getBinder());
28997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize            mIntent.putExtras(bundle);
29097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        }
29197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize
29297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        /**
29397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         * Sets the toolbar color.
29497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         *
29597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         * @param color {@link Color}
29697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         */
29797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        public Builder setToolbarColor(@ColorInt int color) {
29897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize            mIntent.putExtra(EXTRA_TOOLBAR_COLOR, color);
29997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize            return this;
30097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        }
30197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize
30297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        /**
3039440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal         * Enables the url bar to hide as the user scrolls down on the page.
3049440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal         */
3059440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal        public Builder enableUrlBarHiding() {
3069440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal            mIntent.putExtra(EXTRA_ENABLE_URLBAR_HIDING, true);
3079440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal            return this;
3089440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal        }
3099440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal
3109440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal        /**
31197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         * Sets the Close button icon for the custom tab.
31297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         *
31397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         * @param icon The icon {@link Bitmap}
31497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         */
31597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        public Builder setCloseButtonIcon(@NonNull Bitmap icon) {
31697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize            mIntent.putExtra(EXTRA_CLOSE_BUTTON_ICON, icon);
31797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize            return this;
31897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        }
31997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize
32097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        /**
32197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         * Sets whether the title should be shown in the custom tab.
32297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         *
32397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         * @param showTitle Whether the title should be shown.
32497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         */
32597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        public Builder setShowTitle(boolean showTitle) {
32697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize            mIntent.putExtra(EXTRA_TITLE_VISIBILITY_STATE,
32797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize                    showTitle ? SHOW_PAGE_TITLE : NO_TITLE);
32897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize            return this;
32997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        }
33097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize
33197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        /**
33297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         * Adds a menu item.
33397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         *
33497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         * @param label Menu label.
33597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         * @param pendingIntent Pending intent delivered when the menu item is clicked.
33697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         */
33797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        public Builder addMenuItem(@NonNull String label, @NonNull PendingIntent pendingIntent) {
33897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize            if (mMenuItems == null) mMenuItems = new ArrayList<>();
33997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize            Bundle bundle = new Bundle();
34097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize            bundle.putString(KEY_MENU_ITEM_TITLE, label);
34197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize            bundle.putParcelable(KEY_PENDING_INTENT, pendingIntent);
34297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize            mMenuItems.add(bundle);
34397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize            return this;
34497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        }
34597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize
34697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        /**
3478b26db5521378d84391e4ac4c932ca39d1ac83e1Yusuf Ozuysal         * Adds a default share item to the menu.
3488b26db5521378d84391e4ac4c932ca39d1ac83e1Yusuf Ozuysal         */
3498b26db5521378d84391e4ac4c932ca39d1ac83e1Yusuf Ozuysal        public Builder addDefaultShareMenuItem() {
3508b26db5521378d84391e4ac4c932ca39d1ac83e1Yusuf Ozuysal            mIntent.putExtra(EXTRA_DEFAULT_SHARE_MENU_ITEM, true);
3518b26db5521378d84391e4ac4c932ca39d1ac83e1Yusuf Ozuysal            return this;
3528b26db5521378d84391e4ac4c932ca39d1ac83e1Yusuf Ozuysal        }
3538b26db5521378d84391e4ac4c932ca39d1ac83e1Yusuf Ozuysal
3548b26db5521378d84391e4ac4c932ca39d1ac83e1Yusuf Ozuysal        /**
355f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal         * Sets the action button that is displayed in the Toolbar.
356179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal         * <p>
357179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal         * This is equivalent to calling
35831d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal         * {@link CustomTabsIntent.Builder#addToolbarItem(int, Bitmap, String, PendingIntent)}
359179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal         * with {@link #TOOLBAR_ACTION_BUTTON_ID} as id.
36097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         *
36197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         * @param icon The icon.
3628a1ccd14081000d6501622de72a16da67c33030cYusuf Ozuysal         * @param description The description for the button. To be used for accessibility.
36397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         * @param pendingIntent pending intent delivered when the button is clicked.
3649440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal         * @param shouldTint Whether the action button should be tinted.
365179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal         *
36631d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal         * @see CustomTabsIntent.Builder#addToolbarItem(int, Bitmap, String, PendingIntent)
36797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         */
3689440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal        public Builder setActionButton(@NonNull Bitmap icon, @NonNull String description,
3699440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal                @NonNull PendingIntent pendingIntent, boolean shouldTint) {
37097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize            Bundle bundle = new Bundle();
371179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal            bundle.putInt(KEY_ID, TOOLBAR_ACTION_BUTTON_ID);
37297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize            bundle.putParcelable(KEY_ICON, icon);
3738a1ccd14081000d6501622de72a16da67c33030cYusuf Ozuysal            bundle.putString(KEY_DESCRIPTION, description);
37497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize            bundle.putParcelable(KEY_PENDING_INTENT, pendingIntent);
37597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize            mIntent.putExtra(EXTRA_ACTION_BUTTON_BUNDLE, bundle);
3769440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal            mIntent.putExtra(EXTRA_TINT_ACTION_BUTTON, shouldTint);
37797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize            return this;
37897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        }
37997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize
38097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        /**
381179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal         * Sets the action button that is displayed in the Toolbar with default tinting behavior.
382179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal         *
383179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal         * @see {@link CustomTabsIntent.Builder#setActionButton(
3849440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal         * Bitmap, String, PendingIntent, boolean)}
3859440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal         */
3869440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal        public Builder setActionButton(@NonNull Bitmap icon, @NonNull String description,
3879440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal                @NonNull PendingIntent pendingIntent) {
3889440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal            return setActionButton(icon, description, pendingIntent, false);
3899440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal        }
3909440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal
3919440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal        /**
392179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal         * Adds an action button to the custom tab. Multiple buttons can be added via this method.
393179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal         * If the given id equals {@link #TOOLBAR_ACTION_BUTTON_ID}, the button will be placed on
394179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal         * the toolbar; if the bitmap is too wide, it will be put to the bottom bar instead. If
39531d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal         * the id is not {@link #TOOLBAR_ACTION_BUTTON_ID}, it will be directly put on secondary
39631d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal         * toolbar. The maximum number of allowed toolbar items in a single intent is
39731d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal         * {@link CustomTabsIntent#getMaxToolbarItems()}. Throws an
39831d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal         * {@link IllegalStateException} when that number is exceeded per intent.
399179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal         *
400179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal         * @param id The unique id of the action button. This should be non-negative.
401179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal         * @param icon The icon.
402179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal         * @param description The description for the button. To be used for accessibility.
403179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal         * @param pendingIntent The pending intent delivered when the button is clicked.
404179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal         *
40551c7c534e9fd93942aee5edce244f2e2a6e57f34Yusuf Ozuysal         * @see CustomTabsIntent#getMaxToolbarItems()
406f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal         * @deprecated Use
407f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal         * CustomTabsIntent.Builder#setSecondaryToolbarViews(RemoteViews, int[], PendingIntent).
408179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal         */
409f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal        @Deprecated
41031d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal        public Builder addToolbarItem(int id, @NonNull Bitmap icon, @NonNull String description,
411179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal                PendingIntent pendingIntent) throws IllegalStateException {
412179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal            if (mActionButtons == null) {
413179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal                mActionButtons = new ArrayList<>();
414179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal            }
41531d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal            if (mActionButtons.size() >= MAX_TOOLBAR_ITEMS) {
416179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal                throw new IllegalStateException(
41731d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal                        "Exceeded maximum toolbar item count of " + MAX_TOOLBAR_ITEMS);
418179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal            }
419179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal            Bundle bundle = new Bundle();
420179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal            bundle.putInt(KEY_ID, id);
421179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal            bundle.putParcelable(KEY_ICON, icon);
422179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal            bundle.putString(KEY_DESCRIPTION, description);
423179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal            bundle.putParcelable(KEY_PENDING_INTENT, pendingIntent);
424179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal            mActionButtons.add(bundle);
425179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal            return this;
426179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal        }
427179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal
428179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal        /**
42931d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal         * Sets the color of the secondary toolbar.
43031d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal         * @param color The color for the secondary toolbar.
43164694064caedb59afda4ef69b04feaee12c0a33fYusuf Ozuysal         */
43231d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal        public Builder setSecondaryToolbarColor(@ColorInt int color) {
43331d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal            mIntent.putExtra(EXTRA_SECONDARY_TOOLBAR_COLOR, color);
43464694064caedb59afda4ef69b04feaee12c0a33fYusuf Ozuysal            return this;
43564694064caedb59afda4ef69b04feaee12c0a33fYusuf Ozuysal        }
43664694064caedb59afda4ef69b04feaee12c0a33fYusuf Ozuysal
43764694064caedb59afda4ef69b04feaee12c0a33fYusuf Ozuysal        /**
438f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal         * Sets the remote views displayed in the secondary toolbar in a custom tab.
439f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal         *
440f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal         * @param remoteViews   The {@link RemoteViews} that will be shown on the secondary toolbar.
441f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal         * @param clickableIDs  The IDs of clickable views. The onClick event of these views will be
442f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal         *                      handled by custom tabs.
443f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal         * @param pendingIntent The {@link PendingIntent} that will be sent when the user clicks on
444f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal         *                      one of the {@link View}s in clickableIDs. When the
445f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal         *                      {@link PendingIntent} is sent, it will have the current URL as its
446f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal         *                      intent data.
44751c7c534e9fd93942aee5edce244f2e2a6e57f34Yusuf Ozuysal         * @see CustomTabsIntent#EXTRA_REMOTEVIEWS
44851c7c534e9fd93942aee5edce244f2e2a6e57f34Yusuf Ozuysal         * @see CustomTabsIntent#EXTRA_REMOTEVIEWS_VIEW_IDS
44951c7c534e9fd93942aee5edce244f2e2a6e57f34Yusuf Ozuysal         * @see CustomTabsIntent#EXTRA_REMOTEVIEWS_PENDINGINTENT
45051c7c534e9fd93942aee5edce244f2e2a6e57f34Yusuf Ozuysal         * @see CustomTabsIntent#EXTRA_REMOTEVIEWS_CLICKED_ID
451f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal         */
452f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal        public Builder setSecondaryToolbarViews(@NonNull RemoteViews remoteViews,
453f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal                @Nullable int[] clickableIDs, @Nullable PendingIntent pendingIntent) {
454f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal            mIntent.putExtra(EXTRA_REMOTEVIEWS, remoteViews);
455f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal            mIntent.putExtra(EXTRA_REMOTEVIEWS_VIEW_IDS, clickableIDs);
456f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal            mIntent.putExtra(EXTRA_REMOTEVIEWS_PENDINGINTENT, pendingIntent);
457f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal            return this;
458f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal        }
459f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal
460f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal        /**
4612c1994fe5a72dc1a6c320034f86598a168ce4527Ian Wen         * Sets whether Instant Apps is enabled for this Custom Tab.
4622c1994fe5a72dc1a6c320034f86598a168ce4527Ian Wen
4632c1994fe5a72dc1a6c320034f86598a168ce4527Ian Wen         * @param enabled Whether Instant Apps should be enabled.
4642c1994fe5a72dc1a6c320034f86598a168ce4527Ian Wen         */
4652c1994fe5a72dc1a6c320034f86598a168ce4527Ian Wen        public Builder setInstantAppsEnabled(boolean enabled) {
4662c1994fe5a72dc1a6c320034f86598a168ce4527Ian Wen            mInstantAppsEnabled = enabled;
4672c1994fe5a72dc1a6c320034f86598a168ce4527Ian Wen            return this;
4682c1994fe5a72dc1a6c320034f86598a168ce4527Ian Wen        }
4692c1994fe5a72dc1a6c320034f86598a168ce4527Ian Wen
4702c1994fe5a72dc1a6c320034f86598a168ce4527Ian Wen        /**
471f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal         * Sets the start animations.
47297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         *
47397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         * @param context Application context.
47497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         * @param enterResId Resource ID of the "enter" animation for the browser.
47597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         * @param exitResId Resource ID of the "exit" animation for the application.
47697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         */
47797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        public Builder setStartAnimations(
47897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize                @NonNull Context context, @AnimRes int enterResId, @AnimRes int exitResId) {
4791b7158bbc0d0ba4569881f547d12f52e405e125eIan Lake            mStartAnimationBundle = ActivityOptionsCompat.makeCustomAnimation(
4801b7158bbc0d0ba4569881f547d12f52e405e125eIan Lake                    context, enterResId, exitResId).toBundle();
48197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize            return this;
48297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        }
48397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize
48497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        /**
485f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal         * Sets the exit animations.
48697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         *
48797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         * @param context Application context.
48897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         * @param enterResId Resource ID of the "enter" animation for the application.
48997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         * @param exitResId Resource ID of the "exit" animation for the browser.
49097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         */
49197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        public Builder setExitAnimations(
49297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize                @NonNull Context context, @AnimRes int enterResId, @AnimRes int exitResId) {
4931b7158bbc0d0ba4569881f547d12f52e405e125eIan Lake            Bundle bundle = ActivityOptionsCompat.makeCustomAnimation(
4941b7158bbc0d0ba4569881f547d12f52e405e125eIan Lake                    context, enterResId, exitResId).toBundle();
49597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize            mIntent.putExtra(EXTRA_EXIT_ANIMATION_BUNDLE, bundle);
49697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize            return this;
49797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        }
49897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize
49997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        /**
50097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         * Combines all the options that have been set and returns a new {@link CustomTabsIntent}
50197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         * object.
50297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize         */
50397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        public CustomTabsIntent build() {
50497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize            if (mMenuItems != null) {
50597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize                mIntent.putParcelableArrayListExtra(CustomTabsIntent.EXTRA_MENU_ITEMS, mMenuItems);
50697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize            }
507179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal            if (mActionButtons != null) {
50831d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal                mIntent.putParcelableArrayListExtra(EXTRA_TOOLBAR_ITEMS, mActionButtons);
509179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal            }
5102c1994fe5a72dc1a6c320034f86598a168ce4527Ian Wen            mIntent.putExtra(EXTRA_ENABLE_INSTANT_APPS, mInstantAppsEnabled);
51197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize            return new CustomTabsIntent(mIntent, mStartAnimationBundle);
51297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        }
51308889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal    }
514179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal
515179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal    /**
51631d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal     * @return The maximum number of allowed toolbar items for
51731d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal     * {@link CustomTabsIntent.Builder#addToolbarItem(int, Bitmap, String, PendingIntent)} and
51831d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal     * {@link CustomTabsIntent#EXTRA_TOOLBAR_ITEMS}.
519179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal     */
52031d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal    public static int getMaxToolbarItems() {
52131d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal        return MAX_TOOLBAR_ITEMS;
522179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal    }
52308889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal}
524