CustomTabsCallback
public class CustomTabsCallback
A callback class for custom tabs client to get messages regarding events in their custom tabs. In the implementation, all callbacks are sent to the UI thread for the client.
Summary
Constants |
|
|---|---|
static final int |
The activity is being displayed as a bottom-sheet at its initial height. |
static final int |
The activity is being displayed as a bottom-sheet at its maximized height. |
static final int |
The activity is being displayed over the whole window. |
static final int |
The activity is being displayed as a side-sheet at its initial width. |
static final int |
The activity is being displayed as a side-sheet at its maximized width. |
static final int |
The activity's layout state is unknown. |
static final int |
Sent when loading was aborted by a user action before it finishes like clicking on a link or refreshing the page. |
static final int |
Sent when the tab couldn't finish loading due to a failure. |
static final int |
Sent when the tab has finished loading a page. |
static final int |
Sent when the tab has started loading a page. |
static final int |
TAB_HIDDEN = 6Sent when the tab becomes hidden. |
static final int |
TAB_SHOWN = 5Sent when the tab becomes visible. |
Public constructors |
|---|
Public methods |
|
|---|---|
void |
extraCallback(@NonNull String callbackName, @Nullable Bundle args)Unsupported callbacks that may be provided by the implementation. |
@Nullable Bundle |
extraCallbackWithResult(The same as |
void |
onActivityLayout(Called when the Partial Custom Tab's layout has changed. |
void |
onActivityResized(Called when the tab is resized. |
void |
onMessageChannelReady(@Nullable Bundle extras)Called when |
void |
onMinimized(@NonNull Bundle extras)Called when the Custom Tab is minimized by the user such that it covers a small part of the screen. |
void |
onNavigationEvent(int navigationEvent, @Nullable Bundle extras)To be called when a navigation event happens. |
void |
onPostMessage(@NonNull String message, @Nullable Bundle extras)Called when a tab controlled by this |
void |
onRelationshipValidationResult(Called when a relationship validation result is available. |
void |
onUnminimized(@NonNull Bundle extras)Called when the Custom Tab is unminimized by the user such that it returns back to its original state. |
void |
onWarmupCompleted(@NonNull Bundle extras)Called when the browser process finished warming up initiated by warmup. |
Constants
ACTIVITY_LAYOUT_STATE_BOTTOM_SHEET
public static final int ACTIVITY_LAYOUT_STATE_BOTTOM_SHEET = 1
The activity is being displayed as a bottom-sheet at its initial height.
ACTIVITY_LAYOUT_STATE_BOTTOM_SHEET_MAXIMIZED
public static final int ACTIVITY_LAYOUT_STATE_BOTTOM_SHEET_MAXIMIZED = 2
The activity is being displayed as a bottom-sheet at its maximized height.
ACTIVITY_LAYOUT_STATE_FULL_SCREEN
public static final int ACTIVITY_LAYOUT_STATE_FULL_SCREEN = 5
The activity is being displayed over the whole window. This will be the case when a Partial Custom Tab bottom sheet or side sheet cannot be displayed due to minimum width restrictions (see EXTRA_INITIAL_ACTIVITY_WIDTH_PX) or browser limitations.
ACTIVITY_LAYOUT_STATE_SIDE_SHEET
public static final int ACTIVITY_LAYOUT_STATE_SIDE_SHEET = 3
The activity is being displayed as a side-sheet at its initial width.
ACTIVITY_LAYOUT_STATE_SIDE_SHEET_MAXIMIZED
public static final int ACTIVITY_LAYOUT_STATE_SIDE_SHEET_MAXIMIZED = 4
The activity is being displayed as a side-sheet at its maximized width.
ACTIVITY_LAYOUT_STATE_UNKNOWN
public static final int ACTIVITY_LAYOUT_STATE_UNKNOWN = 0
The activity's layout state is unknown. This value communicates an error state, the fact that the state cannot be determined, or that the browser implementation does not provide support for this feature.
NAVIGATION_ABORTED
public static final int NAVIGATION_ABORTED = 4
Sent when loading was aborted by a user action before it finishes like clicking on a link or refreshing the page.
NAVIGATION_FAILED
public static final int NAVIGATION_FAILED = 3
Sent when the tab couldn't finish loading due to a failure.
NAVIGATION_FINISHED
public static final int NAVIGATION_FINISHED = 2
Sent when the tab has finished loading a page.
NAVIGATION_STARTED
public static final int NAVIGATION_STARTED = 1
Sent when the tab has started loading a page.
Public constructors
Public methods
extraCallback
public void extraCallback(@NonNull String callbackName, @Nullable Bundle args)
Unsupported callbacks that may be provided by the implementation.
Note:Clients should never rely on this callback to be called and/or to have a defined behavior, as it is entirely implementation-defined and not supported.
This can be used by implementations to add extra callbacks, for testing or experimental purposes.
extraCallbackWithResult
public @Nullable Bundle extraCallbackWithResult(
@NonNull String callbackName,
@Nullable Bundle args
)
The same as extraCallback, except that this method allows the custom tabs provider to return a result. A return value of null will be used to signify that the client does not know how to handle the callback. As optional best practices, KEY_SUCCESS could be use to identify that callback was *successfully* handled. For example, when returning a message with result:
Bundle result = new Bundle();
result.putString("message", message);
if (success)
result.putBoolean(CustomTabsService#KEY_SUCCESS, true);
return result; Bundle result = extraCallbackWithResult(callbackName, args);
if (result.getBoolean(CustomTabsService#KEY_SUCCESS)) {
// callback was successfully handled
}onActivityLayout
public void onActivityLayout(
@Dimension(unit = 1) int left,
@Dimension(unit = 1) int top,
@Dimension(unit = 1) int right,
@Dimension(unit = 1) int bottom,
int state,
@NonNull Bundle extras
)
Called when the Partial Custom Tab's layout has changed. This callback is not applicable to Custom Tabs that are not launched with EXTRA_INITIAL_ACTIVITY_WIDTH_PX or EXTRA_INITIAL_ACTIVITY_HEIGHT_PX set to their intent.
| Parameters | |
|---|---|
@Dimension(unit = 1) int left |
The new left coordinate of the Partial Custom Tab's window in pixels. |
@Dimension(unit = 1) int top |
The new top coordinate of the Partial Custom Tab's window in pixels. |
@Dimension(unit = 1) int right |
The new right coordinate of the Partial Custom Tab's window in pixels. |
@Dimension(unit = 1) int bottom |
The new bottom coordinate of the Partial Custom Tab's window in pixels. |
int state |
The type of Partial Custom Tab that is currently displayed on the screen. |
@NonNull Bundle extras |
Reserved for future use. |
onActivityResized
public void onActivityResized(
@Dimension(unit = 1) int height,
@Dimension(unit = 1) int width,
@NonNull Bundle extras
)
Called when the tab is resized.
onMessageChannelReady
public void onMessageChannelReady(@Nullable Bundle extras)
Called when CustomTabsSession has requested a postMessage channel through requestPostMessageChannel and the channel is ready for sending and receiving messages on both ends.
onMinimized
public void onMinimized(@NonNull Bundle extras)
Called when the Custom Tab is minimized by the user such that it covers a small part of the screen.
onNavigationEvent
public void onNavigationEvent(int navigationEvent, @Nullable Bundle extras)
To be called when a navigation event happens.
onPostMessage
public void onPostMessage(@NonNull String message, @Nullable Bundle extras)
Called when a tab controlled by this CustomTabsSession has sent a postMessage. If postMessage() is called from a single thread, then the messages will be posted in the same order. When received on the client side, it is the client's responsibility to preserve the ordering further.
onRelationshipValidationResult
public void onRelationshipValidationResult(
@CustomTabsService.Relation int relation,
@NonNull Uri requestedOrigin,
boolean result,
@Nullable Bundle extras
)
Called when a relationship validation result is available.
| Parameters | |
|---|---|
@CustomTabsService.Relation int relation |
Relation for which the result is available. Value previously passed to |
@NonNull Uri requestedOrigin |
Origin requested. Value previously passed to |
boolean result |
Whether the relation was validated. |
@Nullable Bundle extras |
Reserved for future use. |
onUnminimized
public void onUnminimized(@NonNull Bundle extras)
Called when the Custom Tab is unminimized by the user such that it returns back to its original state.