CustomTabsIntent.java revision f75fe23543be03eba16f915724caf3a15e036a7f
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 192f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal * {@link View}s that is listed by {@link #EXTRA_REMOTEVIEWS_CLICKED_ID}. 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 210f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal 211f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal /** 212179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal * Key that specifies the unique ID for an action button. To make a button to show on the 213179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal * toolbar, use {@link #TOOLBAR_ACTION_BUTTON_ID} as its ID. 214179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal */ 215179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal public static final String KEY_ID = "android.support.customtabs.customaction.ID"; 216179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal 217179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal /** 218179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal * The ID allocated to the custom action button that is shown on the toolbar. 219179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal */ 220179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal public static final int TOOLBAR_ACTION_BUTTON_ID = 0; 221179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal 222179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal /** 22331d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal * The maximum allowed number of toolbar items. 224179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal */ 22531d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal private static final int MAX_TOOLBAR_ITEMS = 5; 226179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal 227179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal /** 22897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * An {@link Intent} used to start the Custom Tabs Activity. 22997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize */ 23097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize @NonNull public final Intent intent; 23197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 23297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize /** 23397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * A {@link Bundle} containing the start animation for the Custom Tabs Activity. 23408889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal */ 23597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize @Nullable public final Bundle startAnimationBundle; 23697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 23797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize /** 23897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * Convenience method to launch a Custom Tabs Activity. 23997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * @param context The source Activity. 24097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * @param url The URL to load in the Custom Tab. 24197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize */ 24297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize public void launchUrl(Activity context, Uri url) { 24397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize intent.setData(url); 2441b7158bbc0d0ba4569881f547d12f52e405e125eIan Lake ActivityCompat.startActivity(context, intent, startAnimationBundle); 24597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize } 24697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 24797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize private CustomTabsIntent(Intent intent, Bundle startAnimationBundle) { 24897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize this.intent = intent; 24997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize this.startAnimationBundle = startAnimationBundle; 25008889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal } 25108889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal 25208889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal /** 25397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * Builder class for {@link CustomTabsIntent} objects. 25497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize */ 25597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize public static final class Builder { 25697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize private final Intent mIntent = new Intent(Intent.ACTION_VIEW); 25797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize private ArrayList<Bundle> mMenuItems = null; 25897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize private Bundle mStartAnimationBundle = null; 259179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal private ArrayList<Bundle> mActionButtons = null; 26097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 26197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize /** 26297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * Creates a {@link CustomTabsIntent.Builder} object associated with no 26397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * {@link CustomTabsSession}. 26497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize */ 26597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize public Builder() { 26697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize this(null); 26797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize } 26897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 26997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize /** 27097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * Creates a {@link CustomTabsIntent.Builder} object associated with a given 27197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * {@link CustomTabsSession}. 27297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * 27397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * Guarantees that the {@link Intent} will be sent to the same component as the one the 27497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * session is associated with. 27597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * 27697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * @param session The session to associate this Builder with. 27797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize */ 27897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize public Builder(@Nullable CustomTabsSession session) { 27997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize if (session != null) mIntent.setPackage(session.getComponentName().getPackageName()); 28097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize Bundle bundle = new Bundle(); 281c5c0045de7c8848144a570665e0d3c950816f314Yusuf Ozuysal BundleCompat.putBinder( 282c5c0045de7c8848144a570665e0d3c950816f314Yusuf Ozuysal bundle, EXTRA_SESSION, session == null ? null : session.getBinder()); 28397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize mIntent.putExtras(bundle); 28497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize } 28597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 28697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize /** 28797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * Sets the toolbar color. 28897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * 28997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * @param color {@link Color} 29097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize */ 29197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize public Builder setToolbarColor(@ColorInt int color) { 29297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize mIntent.putExtra(EXTRA_TOOLBAR_COLOR, color); 29397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize return this; 29497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize } 29597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 29697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize /** 2979440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal * Enables the url bar to hide as the user scrolls down on the page. 2989440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal */ 2999440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal public Builder enableUrlBarHiding() { 3009440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal mIntent.putExtra(EXTRA_ENABLE_URLBAR_HIDING, true); 3019440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal return this; 3029440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal } 3039440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal 3049440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal /** 30597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * Sets the Close button icon for the custom tab. 30697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * 30797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * @param icon The icon {@link Bitmap} 30897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize */ 30997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize public Builder setCloseButtonIcon(@NonNull Bitmap icon) { 31097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize mIntent.putExtra(EXTRA_CLOSE_BUTTON_ICON, icon); 31197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize return this; 31297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize } 31397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 31497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize /** 31597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * Sets whether the title should be shown in the custom tab. 31697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * 31797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * @param showTitle Whether the title should be shown. 31897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize */ 31997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize public Builder setShowTitle(boolean showTitle) { 32097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize mIntent.putExtra(EXTRA_TITLE_VISIBILITY_STATE, 32197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize showTitle ? SHOW_PAGE_TITLE : NO_TITLE); 32297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize return this; 32397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize } 32497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 32597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize /** 32697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * Adds a menu item. 32797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * 32897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * @param label Menu label. 32997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * @param pendingIntent Pending intent delivered when the menu item is clicked. 33097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize */ 33197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize public Builder addMenuItem(@NonNull String label, @NonNull PendingIntent pendingIntent) { 33297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize if (mMenuItems == null) mMenuItems = new ArrayList<>(); 33397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize Bundle bundle = new Bundle(); 33497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize bundle.putString(KEY_MENU_ITEM_TITLE, label); 33597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize bundle.putParcelable(KEY_PENDING_INTENT, pendingIntent); 33697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize mMenuItems.add(bundle); 33797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize return this; 33897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize } 33997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 34097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize /** 3418b26db5521378d84391e4ac4c932ca39d1ac83e1Yusuf Ozuysal * Adds a default share item to the menu. 3428b26db5521378d84391e4ac4c932ca39d1ac83e1Yusuf Ozuysal */ 3438b26db5521378d84391e4ac4c932ca39d1ac83e1Yusuf Ozuysal public Builder addDefaultShareMenuItem() { 3448b26db5521378d84391e4ac4c932ca39d1ac83e1Yusuf Ozuysal mIntent.putExtra(EXTRA_DEFAULT_SHARE_MENU_ITEM, true); 3458b26db5521378d84391e4ac4c932ca39d1ac83e1Yusuf Ozuysal return this; 3468b26db5521378d84391e4ac4c932ca39d1ac83e1Yusuf Ozuysal } 3478b26db5521378d84391e4ac4c932ca39d1ac83e1Yusuf Ozuysal 3488b26db5521378d84391e4ac4c932ca39d1ac83e1Yusuf Ozuysal /** 349f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal * Sets the action button that is displayed in the Toolbar. 350179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal * <p> 351179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal * This is equivalent to calling 35231d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal * {@link CustomTabsIntent.Builder#addToolbarItem(int, Bitmap, String, PendingIntent)} 353179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal * with {@link #TOOLBAR_ACTION_BUTTON_ID} as id. 35497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * 35597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * @param icon The icon. 3568a1ccd14081000d6501622de72a16da67c33030cYusuf Ozuysal * @param description The description for the button. To be used for accessibility. 35797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * @param pendingIntent pending intent delivered when the button is clicked. 3589440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal * @param shouldTint Whether the action button should be tinted. 359179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal * 36031d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal * @see CustomTabsIntent.Builder#addToolbarItem(int, Bitmap, String, PendingIntent) 36197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize */ 3629440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal public Builder setActionButton(@NonNull Bitmap icon, @NonNull String description, 3639440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal @NonNull PendingIntent pendingIntent, boolean shouldTint) { 36497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize Bundle bundle = new Bundle(); 365179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal bundle.putInt(KEY_ID, TOOLBAR_ACTION_BUTTON_ID); 36697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize bundle.putParcelable(KEY_ICON, icon); 3678a1ccd14081000d6501622de72a16da67c33030cYusuf Ozuysal bundle.putString(KEY_DESCRIPTION, description); 36897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize bundle.putParcelable(KEY_PENDING_INTENT, pendingIntent); 36997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize mIntent.putExtra(EXTRA_ACTION_BUTTON_BUNDLE, bundle); 3709440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal mIntent.putExtra(EXTRA_TINT_ACTION_BUTTON, shouldTint); 37197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize return this; 37297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize } 37397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 37497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize /** 375179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal * Sets the action button that is displayed in the Toolbar with default tinting behavior. 376179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal * 377179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal * @see {@link CustomTabsIntent.Builder#setActionButton( 3789440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal * Bitmap, String, PendingIntent, boolean)} 3799440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal */ 3809440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal public Builder setActionButton(@NonNull Bitmap icon, @NonNull String description, 3819440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal @NonNull PendingIntent pendingIntent) { 3829440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal return setActionButton(icon, description, pendingIntent, false); 3839440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal } 3849440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal 3859440f0b000fc2740382eb4ae5f1afec58c245c2cYusuf Ozuysal /** 386179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal * Adds an action button to the custom tab. Multiple buttons can be added via this method. 387179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal * If the given id equals {@link #TOOLBAR_ACTION_BUTTON_ID}, the button will be placed on 388179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal * the toolbar; if the bitmap is too wide, it will be put to the bottom bar instead. If 38931d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal * the id is not {@link #TOOLBAR_ACTION_BUTTON_ID}, it will be directly put on secondary 39031d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal * toolbar. The maximum number of allowed toolbar items in a single intent is 39131d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal * {@link CustomTabsIntent#getMaxToolbarItems()}. Throws an 39231d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal * {@link IllegalStateException} when that number is exceeded per intent. 393179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal * 394179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal * @param id The unique id of the action button. This should be non-negative. 395179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal * @param icon The icon. 396179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal * @param description The description for the button. To be used for accessibility. 397179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal * @param pendingIntent The pending intent delivered when the button is clicked. 398179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal * 39931d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal * @see CustomTabsIntent#getMaxToolbarItems(). 400f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal * @deprecated Use 401f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal * CustomTabsIntent.Builder#setSecondaryToolbarViews(RemoteViews, int[], PendingIntent). 402179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal */ 403f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal @Deprecated 40431d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal public Builder addToolbarItem(int id, @NonNull Bitmap icon, @NonNull String description, 405179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal PendingIntent pendingIntent) throws IllegalStateException { 406179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal if (mActionButtons == null) { 407179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal mActionButtons = new ArrayList<>(); 408179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal } 40931d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal if (mActionButtons.size() >= MAX_TOOLBAR_ITEMS) { 410179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal throw new IllegalStateException( 41131d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal "Exceeded maximum toolbar item count of " + MAX_TOOLBAR_ITEMS); 412179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal } 413179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal Bundle bundle = new Bundle(); 414179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal bundle.putInt(KEY_ID, id); 415179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal bundle.putParcelable(KEY_ICON, icon); 416179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal bundle.putString(KEY_DESCRIPTION, description); 417179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal bundle.putParcelable(KEY_PENDING_INTENT, pendingIntent); 418179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal mActionButtons.add(bundle); 419179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal return this; 420179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal } 421179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal 422179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal /** 42331d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal * Sets the color of the secondary toolbar. 42431d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal * @param color The color for the secondary toolbar. 425f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal * @deprecated Use 426f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal * CustomTabsIntent.Builder#setSecondaryToolbarViews(RemoteViews, int[], PendingIntent). 42764694064caedb59afda4ef69b04feaee12c0a33fYusuf Ozuysal */ 428f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal @Deprecated 42931d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal public Builder setSecondaryToolbarColor(@ColorInt int color) { 43031d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal mIntent.putExtra(EXTRA_SECONDARY_TOOLBAR_COLOR, color); 43164694064caedb59afda4ef69b04feaee12c0a33fYusuf Ozuysal return this; 43264694064caedb59afda4ef69b04feaee12c0a33fYusuf Ozuysal } 43364694064caedb59afda4ef69b04feaee12c0a33fYusuf Ozuysal 43464694064caedb59afda4ef69b04feaee12c0a33fYusuf Ozuysal /** 435f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal * Sets the remote views displayed in the secondary toolbar in a custom tab. 436f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal * 437f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal * @param remoteViews The {@link RemoteViews} that will be shown on the secondary toolbar. 438f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal * @param clickableIDs The IDs of clickable views. The onClick event of these views will be 439f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal * handled by custom tabs. 440f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal * @param pendingIntent The {@link PendingIntent} that will be sent when the user clicks on 441f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal * one of the {@link View}s in clickableIDs. When the 442f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal * {@link PendingIntent} is sent, it will have the current URL as its 443f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal * intent data. 444f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal * @see CustomTabsIntent#EXTRA_REMOTEVIEWS. 445f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal * @see CustomTabsIntent#EXTRA_REMOTEVIEWS_VIEW_IDS. 446f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal * @see CustomTabsIntent#EXTRA_REMOTEVIEWS_PENDINGINTENT. 447f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal * @see CustomTabsIntent#EXTRA_REMOTEVIEWS_CLICKED_ID. 448f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal */ 449f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal public Builder setSecondaryToolbarViews(@NonNull RemoteViews remoteViews, 450f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal @Nullable int[] clickableIDs, @Nullable PendingIntent pendingIntent) { 451f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal mIntent.putExtra(EXTRA_REMOTEVIEWS, remoteViews); 452f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal mIntent.putExtra(EXTRA_REMOTEVIEWS_VIEW_IDS, clickableIDs); 453f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal mIntent.putExtra(EXTRA_REMOTEVIEWS_PENDINGINTENT, pendingIntent); 454f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal return this; 455f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal } 456f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal 457f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal /** 458f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal * Sets the start animations. 45997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * 46097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * @param context Application context. 46197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * @param enterResId Resource ID of the "enter" animation for the browser. 46297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * @param exitResId Resource ID of the "exit" animation for the application. 46397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize */ 46497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize public Builder setStartAnimations( 46597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize @NonNull Context context, @AnimRes int enterResId, @AnimRes int exitResId) { 4661b7158bbc0d0ba4569881f547d12f52e405e125eIan Lake mStartAnimationBundle = ActivityOptionsCompat.makeCustomAnimation( 4671b7158bbc0d0ba4569881f547d12f52e405e125eIan Lake context, enterResId, exitResId).toBundle(); 46897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize return this; 46997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize } 47097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 47197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize /** 472f75fe23543be03eba16f915724caf3a15e036a7fYusuf Ozuysal * Sets the exit animations. 47397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * 47497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * @param context Application context. 47597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * @param enterResId Resource ID of the "enter" animation for the application. 47697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * @param exitResId Resource ID of the "exit" animation for the browser. 47797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize */ 47897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize public Builder setExitAnimations( 47997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize @NonNull Context context, @AnimRes int enterResId, @AnimRes int exitResId) { 4801b7158bbc0d0ba4569881f547d12f52e405e125eIan Lake Bundle bundle = ActivityOptionsCompat.makeCustomAnimation( 4811b7158bbc0d0ba4569881f547d12f52e405e125eIan Lake context, enterResId, exitResId).toBundle(); 48297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize mIntent.putExtra(EXTRA_EXIT_ANIMATION_BUNDLE, bundle); 48397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize return this; 48497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize } 48597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 48697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize /** 48797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * Combines all the options that have been set and returns a new {@link CustomTabsIntent} 48897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * object. 48997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize */ 49097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize public CustomTabsIntent build() { 49197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize if (mMenuItems != null) { 49297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize mIntent.putParcelableArrayListExtra(CustomTabsIntent.EXTRA_MENU_ITEMS, mMenuItems); 49397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize } 494179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal if (mActionButtons != null) { 49531d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal mIntent.putParcelableArrayListExtra(EXTRA_TOOLBAR_ITEMS, mActionButtons); 496179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal } 49797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize return new CustomTabsIntent(mIntent, mStartAnimationBundle); 49897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize } 49908889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal } 500179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal 501179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal /** 50231d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal * @return The maximum number of allowed toolbar items for 50331d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal * {@link CustomTabsIntent.Builder#addToolbarItem(int, Bitmap, String, PendingIntent)} and 50431d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal * {@link CustomTabsIntent#EXTRA_TOOLBAR_ITEMS}. 505179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal */ 50631d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal public static int getMaxToolbarItems() { 50731d3693ce923831667ce9e3c83d1bdd3f66742d8Yusuf Ozuysal return MAX_TOOLBAR_ITEMS; 508179ab306d366df2ac610dd8c72bf19a5a8887970Yusuf Ozuysal } 50908889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal} 510