Search in sources :

Example 1 with CustomTabsServiceConnection

use of androidx.browser.customtabs.CustomTabsServiceConnection 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 CustomTabsServiceConnection

use of androidx.browser.customtabs.CustomTabsServiceConnection 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 CustomTabsServiceConnection

use of androidx.browser.customtabs.CustomTabsServiceConnection 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 CustomTabsServiceConnection

use of androidx.browser.customtabs.CustomTabsServiceConnection 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 CustomTabsServiceConnection

use of androidx.browser.customtabs.CustomTabsServiceConnection in project MaxLock by Maxr1998.

the class SettingsActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    Util.setTheme(this);
    super.onCreate(savedInstanceState);
    if (MLPreferences.getPreferences(this).getInt(FirstStartActivity.FIRST_START_LAST_VERSION_KEY, 0) != FirstStartActivity.FIRST_START_LATEST_VERSION) {
        startActivity(new Intent(this, FirstStartActivity.class));
    }
    settingsViewModel = ViewModelProviders.of(this).get(SettingsViewModel.class);
    devicePolicyManager = (DevicePolicyManager) getSystemService(DEVICE_POLICY_SERVICE);
    deviceAdmin = new ComponentName(this, UninstallProtectionReceiver.class);
    setContentView(R.layout.activity_settings);
    contentView = findViewById(R.id.content_view_settings);
    toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    secondFragmentContainer = findViewById(R.id.second_fragment_container);
    Fragment settingsFragment = getSupportFragmentManager().findFragmentByTag(TAG_PREFERENCE_FRAGMENT);
    if (settingsFragment == null || !UNLOCKED) {
        // Main fragment doesn't exist, app just opened
        // → Show lockscreen
        UNLOCKED = false;
        if (!MLPreferences.getPreferences(this).getString(Common.LOCKING_TYPE, "").isEmpty()) {
            contentView.addView(lockscreen = new LockView(this, null), ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            lockscreen.forceFocus();
            // → Hide Action bar
            toolbar.setTranslationY(-getResources().getDimensionPixelSize(R.dimen.toolbar_height));
        } else
            UNLOCKED = true;
        // → Create and display settings
        settingsFragment = getIntent().getAction() != null && getIntent().getAction().equals(BuildConfig.APPLICATION_ID + ".VIEW_APPS") ? new AppListFragment() : MaxLockPreferenceFragment.Screen.MAIN.getScreen();
        getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, settingsFragment, TAG_PREFERENCE_FRAGMENT).commit();
    }
    ctConnection = new CustomTabsServiceConnection() {

        @Override
        public void onCustomTabsServiceConnected(ComponentName componentName, CustomTabsClient customTabsClient) {
            customTabsClient.warmup(0);
            ctSession = customTabsClient.newSession(new CustomTabsCallback());
            if (ctSession == null)
                return;
            Bundle maxr1998Website = new Bundle();
            maxr1998Website.putParcelable(CustomTabsService.KEY_URL, Common.MAXR1998_URI);
            Bundle technoSparksProfile = new Bundle();
            technoSparksProfile.putParcelable(CustomTabsService.KEY_URL, Common.TECHNO_SPARKS_URI);
            ctSession.mayLaunchUrl(Common.WEBSITE_URI, null, Arrays.asList(maxr1998Website, technoSparksProfile));
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
        }
    };
    String cctPackageName = CustomTabsClient.getPackageName(this, Arrays.asList("com.android.chrome", "com.chrome.beta", "com.chrome.dev", "org.mozilla.firefox", "org.mozilla.firefox_beta"));
    if (cctPackageName != null) {
        CustomTabsClient.bindCustomTabsService(this, cctPackageName, ctConnection);
    } else
        ctConnection = null;
}
Also used : CustomTabsClient(androidx.browser.customtabs.CustomTabsClient) Bundle(android.os.Bundle) Intent(android.content.Intent) CustomTabsIntent(androidx.browser.customtabs.CustomTabsIntent) MaxLockPreferenceFragment(de.Maxr1998.xposed.maxlock.ui.settings.MaxLockPreferenceFragment) Fragment(androidx.fragment.app.Fragment) AppListFragment(de.Maxr1998.xposed.maxlock.ui.settings.applist.AppListFragment) CustomTabsCallback(androidx.browser.customtabs.CustomTabsCallback) FirstStartActivity(de.Maxr1998.xposed.maxlock.ui.firstStart.FirstStartActivity) AppListFragment(de.Maxr1998.xposed.maxlock.ui.settings.applist.AppListFragment) LockView(de.Maxr1998.xposed.maxlock.ui.lockscreen.LockView) ComponentName(android.content.ComponentName) CustomTabsServiceConnection(androidx.browser.customtabs.CustomTabsServiceConnection)

Aggregations

CustomTabsServiceConnection (androidx.browser.customtabs.CustomTabsServiceConnection)15 ComponentName (android.content.ComponentName)13 CustomTabsClient (androidx.browser.customtabs.CustomTabsClient)13 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 CustomTabsCallback (androidx.browser.customtabs.CustomTabsCallback)2 CustomTabsIntent (androidx.browser.customtabs.CustomTabsIntent)2 Test (org.junit.Test)2 Uri (android.net.Uri)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)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