android.support.customtabs.CustomTabsServiceConnection Java Examples

The following examples show how to use android.support.customtabs.CustomTabsServiceConnection. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CustomTabs.java    From ForceDoze with GNU General Public License v3.0 6 votes vote down vote up
private Warmer warm(){
    mCustomTabServiceConnection =
            new CustomTabsServiceConnection() {
                @Override
                public void onCustomTabsServiceConnected(ComponentName componentName,
                                                         CustomTabsClient customTabsClient) {
                    mCustomTabsClient = customTabsClient;
                    mCustomTabsClient.warmup(0);
                    mCustomTabsSession = mCustomTabsClient.newSession(null);
                }

                @Override
                public void onServiceDisconnected(ComponentName name) {
                    mCustomTabsClient = null;
                }
            };

    packageNameToUse = ChromePackageHelper.getPackageNameToUse(context);

    if (packageNameToUse != null){
        CustomTabsClient.bindCustomTabsService(context, packageNameToUse,
                mCustomTabServiceConnection);
    }
    return this;
}
 
Example #2
Source File: CustomTabsControllerTest.java    From Auth0.Android with MIT License 5 votes vote down vote up
@Test
public void shouldUnbind() throws Exception {
    bindService(true);
    connectBoundService();

    controller.unbindService();
    verify(context).unbindService(serviceConnectionCaptor.capture());
    final CustomTabsServiceConnection connection = serviceConnectionCaptor.getValue();
    CustomTabsServiceConnection controllerConnection = controller;
    assertThat(connection, is(equalTo(controllerConnection)));
}
 
Example #3
Source File: CustomTabsControllerTest.java    From Auth0.Android with MIT License 5 votes vote down vote up
private void connectBoundService() throws Exception {
    CustomTabsSession session = mock(CustomTabsSession.class);
    ComponentName componentName = new ComponentName(DEFAULT_BROWSER_PACKAGE, DEFAULT_BROWSER_PACKAGE + ".CustomTabsService");
    //This depends on an implementation detail but is the only way to test it because of methods visibility
    PowerMockito.when(session, "getComponentName").thenReturn(componentName);

    when(customTabsClient.newSession(Matchers.<CustomTabsCallback>eq(null))).thenReturn(session);
    CustomTabsServiceConnection conn = serviceConnectionCaptor.getValue();
    conn.onCustomTabsServiceConnected(componentName, customTabsClient);
    verify(customTabsClient).newSession(Matchers.<CustomTabsCallback>eq(null));
    verify(customTabsClient).warmup(eq(0L));
}
 
Example #4
Source File: CustomTabsHelper.java    From rides-android-sdk with MIT License 5 votes vote down vote up
/**
 * Opens the URL on a Custom Tab if possible. Otherwise fallsback to opening it on a WebView.
 *
 * @param context The host context.
 * @param customTabsIntent a CustomTabsIntent to be used if Custom Tabs is available.
 * @param uri the Uri to be opened.
 * @param fallback a CustomTabFallback to be used if Custom Tabs is not available.
 */
public void openCustomTab(
        final Context context,
        final CustomTabsIntent customTabsIntent,
        final Uri uri,
        CustomTabFallback fallback) {
    final String packageName = getPackageNameToUse(context);

    if (packageName != null) {
        connection = new CustomTabsServiceConnection() {
            @Override
            public void onCustomTabsServiceConnected(ComponentName componentName, CustomTabsClient client) {
                client.warmup(0L); // This prevents backgrounding after redirection

                customTabsIntent.intent.setPackage(packageName);
                customTabsIntent.intent.setData(uri);
                customTabsIntent.launchUrl(context, uri);
            }

            @Override
            public void onServiceDisconnected(ComponentName name) {
            }
        };
        CustomTabsClient.bindCustomTabsService(context, packageName, connection);
    } else if (fallback != null) {
        fallback.openUri(context, uri);
    } else {
        Log.e(UberSdk.UBER_SDK_LOG_TAG, "Use of openCustomTab without Customtab support or a fallback set");
    }
}