Search in sources :

Example 1 with CustomTabColorSchemeParams

use of androidx.browser.customtabs.CustomTabColorSchemeParams in project Tusky by Vavassor.

the class LinkHelper method openLinkInCustomTab.

/**
 * tries to open a link in a custom tab
 * falls back to browser if not possible
 *
 * @param uri the uri to open
 * @param context context
 */
public static void openLinkInCustomTab(Uri uri, Context context) {
    int toolbarColor = ThemeUtils.getColor(context, R.attr.colorSurface);
    int navigationbarColor = ThemeUtils.getColor(context, android.R.attr.navigationBarColor);
    int navigationbarDividerColor = ThemeUtils.getColor(context, R.attr.dividerColor);
    CustomTabColorSchemeParams colorSchemeParams = new CustomTabColorSchemeParams.Builder().setToolbarColor(toolbarColor).setNavigationBarColor(navigationbarColor).setNavigationBarDividerColor(navigationbarDividerColor).build();
    CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder().setDefaultColorSchemeParams(colorSchemeParams).setShowTitle(true).build();
    try {
        customTabsIntent.launchUrl(context, uri);
    } catch (ActivityNotFoundException e) {
        Log.w("LinkHelper", "Activity was not found for intent " + customTabsIntent);
        openLinkInBrowser(uri, context);
    }
}
Also used : CustomTabsIntent(androidx.browser.customtabs.CustomTabsIntent) ActivityNotFoundException(android.content.ActivityNotFoundException) CustomTabColorSchemeParams(androidx.browser.customtabs.CustomTabColorSchemeParams) SpannableStringBuilder(android.text.SpannableStringBuilder)

Aggregations

ActivityNotFoundException (android.content.ActivityNotFoundException)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 CustomTabColorSchemeParams (androidx.browser.customtabs.CustomTabColorSchemeParams)1 CustomTabsIntent (androidx.browser.customtabs.CustomTabsIntent)1