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.ActivityOptions; 2108889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysalimport android.app.PendingIntent; 2297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lizeimport android.content.Context; 2308889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysalimport android.content.Intent; 2408889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysalimport android.graphics.Bitmap; 2508889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysalimport android.graphics.Color; 2608889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysalimport android.net.Uri; 2708889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysalimport android.os.Bundle; 2897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lizeimport android.support.annotation.AnimRes; 29e063d4d36883c9f7ca100036b9344b665ab6fd1eYusuf Ozuysalimport android.support.annotation.ColorInt; 30c5c0045de7c8848144a570665e0d3c950816f314Yusuf Ozuysalimport android.support.annotation.NonNull; 3197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lizeimport android.support.annotation.Nullable; 32c5c0045de7c8848144a570665e0d3c950816f314Yusuf Ozuysalimport android.support.v4.app.BundleCompat; 3308889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal 3497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lizeimport java.util.ArrayList; 3508889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal 3608889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal/** 3797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * Class holding the {@link Intent} and start bundle for a Custom Tabs Activity. 3897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * 3997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * <p> 4097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * <strong>Note:</strong> The constants below are public for the browser implementation's benefit. 4197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * You are strongly encouraged to use {@link CustomTabsIntent.Builder}.</p> 4208889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal */ 4397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lizepublic final class CustomTabsIntent { 4408889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal 4508889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal /** 4608889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal * Extra used to match the session. This has to be included in the intent to open in 4708889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal * a custom tab. This is the same IBinder that gets passed to ICustomTabsService#newSession. 4808889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal * Null if there is no need to match any service side sessions with the intent. 4908889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal */ 5008889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal public static final String EXTRA_SESSION = "android.support.customtabs.extra.SESSION"; 5108889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal 5208889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal /** 5308889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal * Extra that changes the background color for the toolbar. colorRes is an int that specifies a 5408889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal * {@link Color}, not a resource id. 5508889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal */ 5608889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal public static final String EXTRA_TOOLBAR_COLOR = 5708889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal "android.support.customtabs.extra.TOOLBAR_COLOR"; 5808889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal 5908889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal /** 6097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * Extra bitmap that specifies the icon of the back button on the toolbar. If the client chooses 6197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * not to customize it, a default close button will be used. 6297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize */ 6397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize public static final String EXTRA_CLOSE_BUTTON_ICON = 6497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize "android.support.customtabs.extra.CLOSE_BUTTON_ICON"; 6597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 6697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize /** 6797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * Extra (int) that specifies state for showing the page title. Default is {@link #NO_TITLE}. 6897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize */ 6997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize public static final String EXTRA_TITLE_VISIBILITY_STATE = 7097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize "android.support.customtabs.extra.TITLE_VISIBILITY"; 7197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 7297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize /** 7397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * Don't show any title. Shows only the domain. 7497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize */ 7597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize public static final int NO_TITLE = 0; 7697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 7797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize /** 7897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * Shows the page title and the domain. 7997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize */ 8097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize public static final int SHOW_PAGE_TITLE = 1; 8197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 8297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize /** 838a1ccd14081000d6501622de72a16da67c33030cYusuf Ozuysal * Bundle used for adding a custom action button to the custom tab toolbar. The client should 848a1ccd14081000d6501622de72a16da67c33030cYusuf Ozuysal * provide a description, an icon {@link Bitmap} and a {@link PendingIntent} for the button. 858a1ccd14081000d6501622de72a16da67c33030cYusuf Ozuysal * All three keys must be present. 8608889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal */ 8708889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal public static final String EXTRA_ACTION_BUTTON_BUNDLE = 8808889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal "android.support.customtabs.extra.ACTION_BUTTON_BUNDLE"; 8908889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal 9008889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal /** 9108889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal * Key that specifies the {@link Bitmap} to be used as the image source for the action button. 928a1ccd14081000d6501622de72a16da67c33030cYusuf Ozuysal * The icon should't be more than 24dp in height (No padding needed. The button itself will be 938a1ccd14081000d6501622de72a16da67c33030cYusuf Ozuysal * 48dp in height) and have a width/height ratio of less than 2. 9408889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal */ 9508889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal public static final String KEY_ICON = "android.support.customtabs.customaction.ICON"; 9608889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal 9708889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal /** 988a1ccd14081000d6501622de72a16da67c33030cYusuf Ozuysal * Key that specifies the content description for the custom action button. 998a1ccd14081000d6501622de72a16da67c33030cYusuf Ozuysal */ 1008a1ccd14081000d6501622de72a16da67c33030cYusuf Ozuysal public static final String KEY_DESCRIPTION = 1018a1ccd14081000d6501622de72a16da67c33030cYusuf Ozuysal "android.support.customtabs.customaction.DESCRIPTION"; 1028a1ccd14081000d6501622de72a16da67c33030cYusuf Ozuysal 1038a1ccd14081000d6501622de72a16da67c33030cYusuf Ozuysal /** 10408889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal * Key that specifies the PendingIntent to launch when the action button or menu item was 10508889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal * clicked. The custom tab will be calling {@link PendingIntent#send()} on clicks after adding 10608889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal * the url as data. The client app can call {@link Intent#getDataString()} to get the url. 10708889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal */ 10808889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal public static final String KEY_PENDING_INTENT = 10908889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal "android.support.customtabs.customaction.PENDING_INTENT"; 11008889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal 11108889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal /** 11208889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal * Use an {@code ArrayList<Bundle>} for specifying menu related params. There should be a 11308889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal * separate {@link Bundle} for each custom menu item. 11408889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal */ 11508889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal public static final String EXTRA_MENU_ITEMS = "android.support.customtabs.extra.MENU_ITEMS"; 11608889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal 11708889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal /** 11808889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal * Key for specifying the title of a menu item. 11908889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal */ 12008889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal public static final String KEY_MENU_ITEM_TITLE = 12108889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal "android.support.customtabs.customaction.MENU_ITEM_TITLE"; 12208889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal 12308889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal /** 12408889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal * Bundle constructed out of {@link ActivityOptions} that will be running when the 12508889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal * {@link Activity} that holds the custom tab gets finished. A similar ActivityOptions 12608889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal * for creation should be constructed and given to the startActivity() call that 12708889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal * launches the custom tab. 12808889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal */ 12908889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal public static final String EXTRA_EXIT_ANIMATION_BUNDLE = 13008889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal "android.support.customtabs.extra.EXIT_ANIMATION_BUNDLE"; 13108889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal 13208889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal /** 13397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * An {@link Intent} used to start the Custom Tabs Activity. 13497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize */ 13597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize @NonNull public final Intent intent; 13697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 13797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize /** 13897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * A {@link Bundle} containing the start animation for the Custom Tabs Activity. 13908889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal */ 14097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize @Nullable public final Bundle startAnimationBundle; 14197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 14297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize /** 14397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * Convenience method to launch a Custom Tabs Activity. 14497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * @param context The source Activity. 14597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * @param url The URL to load in the Custom Tab. 14697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize */ 14797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize public void launchUrl(Activity context, Uri url) { 14897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize intent.setData(url); 14997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize if (startAnimationBundle != null){ 15097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize context.startActivity(intent, startAnimationBundle); 15197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize } else { 15297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize context.startActivity(intent); 15397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize } 15497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize } 15597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 15697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize private CustomTabsIntent(Intent intent, Bundle startAnimationBundle) { 15797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize this.intent = intent; 15897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize this.startAnimationBundle = startAnimationBundle; 15908889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal } 16008889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal 16108889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal /** 16297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * Builder class for {@link CustomTabsIntent} objects. 16397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize */ 16497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize public static final class Builder { 16597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize private final Intent mIntent = new Intent(Intent.ACTION_VIEW); 16697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize private ArrayList<Bundle> mMenuItems = null; 16797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize private Bundle mStartAnimationBundle = null; 16897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 16997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize /** 17097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * Creates a {@link CustomTabsIntent.Builder} object associated with no 17197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * {@link CustomTabsSession}. 17297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize */ 17397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize public Builder() { 17497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize this(null); 17597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize } 17697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 17797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize /** 17897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * Creates a {@link CustomTabsIntent.Builder} object associated with a given 17997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * {@link CustomTabsSession}. 18097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * 18197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * Guarantees that the {@link Intent} will be sent to the same component as the one the 18297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * session is associated with. 18397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * 18497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * @param session The session to associate this Builder with. 18597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize */ 18697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize public Builder(@Nullable CustomTabsSession session) { 18797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize if (session != null) mIntent.setPackage(session.getComponentName().getPackageName()); 18897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize Bundle bundle = new Bundle(); 189c5c0045de7c8848144a570665e0d3c950816f314Yusuf Ozuysal BundleCompat.putBinder( 190c5c0045de7c8848144a570665e0d3c950816f314Yusuf Ozuysal bundle, EXTRA_SESSION, session == null ? null : session.getBinder()); 19197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize mIntent.putExtras(bundle); 19297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize } 19397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 19497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize /** 19597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * Sets the toolbar color. 19697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * 19797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * @param color {@link Color} 19897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize */ 19997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize public Builder setToolbarColor(@ColorInt int color) { 20097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize mIntent.putExtra(EXTRA_TOOLBAR_COLOR, color); 20197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize return this; 20297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize } 20397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 20497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize /** 20597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * Sets the Close button icon for the custom tab. 20697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * 20797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * @param icon The icon {@link Bitmap} 20897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize */ 20997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize public Builder setCloseButtonIcon(@NonNull Bitmap icon) { 21097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize mIntent.putExtra(EXTRA_CLOSE_BUTTON_ICON, icon); 21197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize return this; 21297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize } 21397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 21497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize /** 21597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * Sets whether the title should be shown in the custom tab. 21697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * 21797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * @param showTitle Whether the title should be shown. 21897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize */ 21997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize public Builder setShowTitle(boolean showTitle) { 22097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize mIntent.putExtra(EXTRA_TITLE_VISIBILITY_STATE, 22197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize showTitle ? SHOW_PAGE_TITLE : NO_TITLE); 22297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize return this; 22397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize } 22497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 22597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize /** 22697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * Adds a menu item. 22797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * 22897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * @param label Menu label. 22997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * @param pendingIntent Pending intent delivered when the menu item is clicked. 23097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize */ 23197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize public Builder addMenuItem(@NonNull String label, @NonNull PendingIntent pendingIntent) { 23297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize if (mMenuItems == null) mMenuItems = new ArrayList<>(); 23397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize Bundle bundle = new Bundle(); 23497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize bundle.putString(KEY_MENU_ITEM_TITLE, label); 23597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize bundle.putParcelable(KEY_PENDING_INTENT, pendingIntent); 23697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize mMenuItems.add(bundle); 23797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize return this; 23897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize } 23997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 24097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize /** 24197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * Set the action button. 24297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * 24397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * @param icon The icon. 2448a1ccd14081000d6501622de72a16da67c33030cYusuf Ozuysal * @param description The description for the button. To be used for accessibility. 24597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * @param pendingIntent pending intent delivered when the button is clicked. 24697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize */ 2478a1ccd14081000d6501622de72a16da67c33030cYusuf Ozuysal public Builder setActionButton(@NonNull Bitmap icon, 2488a1ccd14081000d6501622de72a16da67c33030cYusuf Ozuysal @NonNull String description, @NonNull PendingIntent pendingIntent) { 24997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize Bundle bundle = new Bundle(); 25097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize bundle.putParcelable(KEY_ICON, icon); 2518a1ccd14081000d6501622de72a16da67c33030cYusuf Ozuysal bundle.putString(KEY_DESCRIPTION, description); 25297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize bundle.putParcelable(KEY_PENDING_INTENT, pendingIntent); 25397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize mIntent.putExtra(EXTRA_ACTION_BUTTON_BUNDLE, bundle); 25497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize return this; 25597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize } 25697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 25797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize /** 25897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * Sets the start animations, 25997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * 26097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * @param context Application context. 26197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * @param enterResId Resource ID of the "enter" animation for the browser. 26297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * @param exitResId Resource ID of the "exit" animation for the application. 26397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize */ 26497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize public Builder setStartAnimations( 26597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize @NonNull Context context, @AnimRes int enterResId, @AnimRes int exitResId) { 26697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize mStartAnimationBundle = 26797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize ActivityOptions.makeCustomAnimation(context, enterResId, exitResId).toBundle(); 26897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize return this; 26997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize } 27097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 27197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize /** 27297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * Sets the exit animations, 27397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * 27497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * @param context Application context. 27597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * @param enterResId Resource ID of the "enter" animation for the application. 27697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * @param exitResId Resource ID of the "exit" animation for the browser. 27797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize */ 27897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize public Builder setExitAnimations( 27997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize @NonNull Context context, @AnimRes int enterResId, @AnimRes int exitResId) { 28097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize Bundle bundle = 28197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize ActivityOptions.makeCustomAnimation(context, enterResId, exitResId).toBundle(); 28297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize mIntent.putExtra(EXTRA_EXIT_ANIMATION_BUNDLE, bundle); 28397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize return this; 28497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize } 28597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 28697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize /** 28797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * Combines all the options that have been set and returns a new {@link CustomTabsIntent} 28897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * object. 28997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize */ 29097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize public CustomTabsIntent build() { 29197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize if (mMenuItems != null) { 29297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize mIntent.putParcelableArrayListExtra(CustomTabsIntent.EXTRA_MENU_ITEMS, mMenuItems); 29397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize } 29497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize return new CustomTabsIntent(mIntent, mStartAnimationBundle); 29597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize } 29608889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal } 29708889acbc842c73b64f94a761910154d9d42ee4cYusuf Ozuysal} 298