Search in sources :

Example 1 with CustomTabsClient

use of androidx.browser.customtabs.CustomTabsClient in project SpaceLaunchNow-Android by ItsCalebJones.

the class CustomTabActivityHelper method bindCustomTabsService.

/**
 * Binds the Activity to the Custom Tabs Service
 *
 * @param activity the activity to be binded to the service
 */
public void bindCustomTabsService(Activity activity) {
    Timber.v("Binding CustomTabService");
    if (mClient != null)
        return;
    String packageName = CustomTabHelper.getPackageNameToUse(activity);
    if (packageName == null)
        return;
    mConnection = new CustomTabsServiceConnection() {

        @Override
        public void onCustomTabsServiceConnected(ComponentName name, CustomTabsClient client) {
            mClient = client;
            mClient.warmup(0L);
            if (mConnectionCallback != null)
                mConnectionCallback.onCustomTabsConnected();
            // Initialize a session as soon as possible.
            Timber.v("Initializing CustomTabsService");
            getSession();
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            Timber.v("Disconnecting CustomTabsService");
            mClient = null;
            if (mConnectionCallback != null)
                mConnectionCallback.onCustomTabsDisconnected();
        }
    };
    CustomTabsClient.bindCustomTabsService(activity, packageName, mConnection);
}
Also used : CustomTabsClient(androidx.browser.customtabs.CustomTabsClient) ComponentName(android.content.ComponentName) CustomTabsServiceConnection(androidx.browser.customtabs.CustomTabsServiceConnection)

Example 2 with CustomTabsClient

use of androidx.browser.customtabs.CustomTabsClient in project SpaceLaunchNow-Android by ItsCalebJones.

the class CustomTabActivityHelper method bindCustomTabsService.

/**
 * Binds the Activity to the Custom Tabs Service
 *
 * @param activity the activity to be binded to the service
 */
public void bindCustomTabsService(Activity activity) {
    Timber.v("Binding CustomTabService");
    if (mClient != null)
        return;
    String packageName = CustomTabHelper.getPackageNameToUse(activity);
    if (packageName == null)
        return;
    mConnection = new CustomTabsServiceConnection() {

        @Override
        public void onCustomTabsServiceConnected(ComponentName name, CustomTabsClient client) {
            mClient = client;
            mClient.warmup(0L);
            if (mConnectionCallback != null)
                mConnectionCallback.onCustomTabsConnected();
            // Initialize a session as soon as possible.
            Timber.v("Initializing CustomTabsService");
            getSession();
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            Timber.v("Disconnecting CustomTabsService");
            mClient = null;
            if (mConnectionCallback != null)
                mConnectionCallback.onCustomTabsDisconnected();
        }
    };
    CustomTabsClient.bindCustomTabsService(activity, packageName, mConnection);
}
Also used : CustomTabsClient(androidx.browser.customtabs.CustomTabsClient) ComponentName(android.content.ComponentName) CustomTabsServiceConnection(androidx.browser.customtabs.CustomTabsServiceConnection)

Example 3 with CustomTabsClient

use of androidx.browser.customtabs.CustomTabsClient in project router-companion-android by rm3l.

the class CustomTabActivityHelper method bindCustomTabsService.

/**
 * Binds the Activity to the Custom Tabs Service
 *
 * @param activity the activity to be binded to the service
 */
public void bindCustomTabsService(Activity activity) {
    if (mClient != null) {
        return;
    }
    String packageName = CustomTabsHelper.getPackageNameToUse(activity);
    if (packageName == null) {
        return;
    }
    mConnection = new CustomTabsServiceConnection() {

        @Override
        public void onCustomTabsServiceConnected(ComponentName name, CustomTabsClient client) {
            mClient = client;
            mClient.warmup(0L);
            if (mConnectionCallback != null) {
                mConnectionCallback.onCustomTabsConnected();
            }
            // Initialize a session as soon as possible.
            getSession();
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            mClient = null;
            if (mConnectionCallback != null) {
                mConnectionCallback.onCustomTabsDisconnected();
            }
        }
    };
    CustomTabsClient.bindCustomTabsService(activity, packageName, mConnection);
}
Also used : CustomTabsClient(androidx.browser.customtabs.CustomTabsClient) ComponentName(android.content.ComponentName) CustomTabsServiceConnection(androidx.browser.customtabs.CustomTabsServiceConnection)

Example 4 with CustomTabsClient

use of androidx.browser.customtabs.CustomTabsClient in project android-browser-helper by GoogleChrome.

the class MainActivity method onStart.

@Override
protected void onStart() {
    super.onStart();
    mConnection = new CustomTabsServiceConnection() {

        @Override
        public void onCustomTabsServiceConnected(@NonNull ComponentName name, @NonNull CustomTabsClient client) {
            mSession = client.newSession(null);
            client.warmup(0);
            mExtraButton.setEnabled(true);
        }

        @Override
        public void onServiceDisconnected(ComponentName componentName) {
        }
    };
    String packageName = CustomTabsClient.getPackageName(MainActivity.this, null);
    if (packageName == null) {
        Toast.makeText(this, "Can't find a Custom Tabs provider.", Toast.LENGTH_SHORT).show();
        return;
    }
    CustomTabsClient.bindCustomTabsService(this, packageName, mConnection);
}
Also used : CustomTabsClient(androidx.browser.customtabs.CustomTabsClient) ComponentName(android.content.ComponentName) CustomTabsServiceConnection(androidx.browser.customtabs.CustomTabsServiceConnection)

Example 5 with CustomTabsClient

use of androidx.browser.customtabs.CustomTabsClient in project Anki-Android by ankidroid.

the class CustomTabActivityHelperTest method invalidClientMeansFallbackIsCalled.

@Test
public void invalidClientMeansFallbackIsCalled() {
    CustomTabsClient badClient = getClientThrowingSecurityException();
    CustomTabActivityHelper customTabActivityHelper = getValidTabHandler();
    customTabActivityHelper.onServiceConnected(badClient);
    CustomTabActivityHelper.CustomTabFallback fallback = mock(CustomTabActivityHelper.CustomTabFallback.class);
    Activity activity = mock(Activity.class);
    PackageManager packageManager = mock(PackageManager.class);
    when(activity.getPackageManager()).thenReturn(packageManager);
    when(packageManager.queryIntentActivities(any(), anyInt())).thenReturn(Collections.emptyList());
    CustomTabActivityHelper.openCustomTab(activity, null, null, fallback);
    verify(fallback, times(1)).openUri(any(), any());
}
Also used : CustomTabsClient(androidx.browser.customtabs.CustomTabsClient) PackageManager(android.content.pm.PackageManager) Activity(android.app.Activity) Test(org.junit.Test)

Aggregations

CustomTabsClient (androidx.browser.customtabs.CustomTabsClient)21 ComponentName (android.content.ComponentName)13 CustomTabsServiceConnection (androidx.browser.customtabs.CustomTabsServiceConnection)13 Test (org.junit.Test)4 NonNull (androidx.annotation.NonNull)3 Activity (android.app.Activity)2 Intent (android.content.Intent)2 PackageManager (android.content.pm.PackageManager)2 Bundle (android.os.Bundle)2 CheckResult (androidx.annotation.CheckResult)2 CustomTabsCallback (androidx.browser.customtabs.CustomTabsCallback)2 CustomTabsIntent (androidx.browser.customtabs.CustomTabsIntent)2 Uri (android.net.Uri)1 Nullable (androidx.annotation.Nullable)1 CustomTabsSession (androidx.browser.customtabs.CustomTabsSession)1 Fragment (androidx.fragment.app.Fragment)1 FirstStartActivity (de.Maxr1998.xposed.maxlock.ui.firstStart.FirstStartActivity)1 LockView (de.Maxr1998.xposed.maxlock.ui.lockscreen.LockView)1 MaxLockPreferenceFragment (de.Maxr1998.xposed.maxlock.ui.settings.MaxLockPreferenceFragment)1 AppListFragment (de.Maxr1998.xposed.maxlock.ui.settings.applist.AppListFragment)1