-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1628 from Adyen/feature/custom-tabs-styling
Support changing the custom tabs toolbar and navigation colors
- Loading branch information
Showing
9 changed files
with
114 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
ui-core/src/main/java/com/adyen/checkout/ui/core/internal/util/CustomTabsLauncher.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) 2024 Adyen N.V. | ||
* | ||
* This file is open source and available under the MIT license. See the LICENSE file for more info. | ||
* | ||
* Created by josephj on 6/5/2024. | ||
*/ | ||
|
||
package com.adyen.checkout.ui.core.internal.util | ||
|
||
import android.content.ActivityNotFoundException | ||
import android.content.Context | ||
import android.net.Uri | ||
import androidx.annotation.AttrRes | ||
import androidx.annotation.RestrictTo | ||
import androidx.browser.customtabs.CustomTabColorSchemeParams | ||
import androidx.browser.customtabs.CustomTabsIntent | ||
import com.adyen.checkout.ui.core.R | ||
|
||
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) | ||
object CustomTabsLauncher { | ||
fun launchCustomTab(context: Context, uri: Uri): Boolean { | ||
@Suppress("SwallowedException") | ||
return try { | ||
CustomTabsIntent.Builder() | ||
.setShowTitle(true) | ||
.setDefaultColorSchemeParams(getDefaultColorSchemeParams(context)) | ||
.build() | ||
.launchUrl(context, uri) | ||
true | ||
} catch (e: ActivityNotFoundException) { | ||
false | ||
} | ||
} | ||
|
||
private fun getDefaultColorSchemeParams(context: Context): CustomTabColorSchemeParams { | ||
val toolbarColor = context.getColorOrNull(R.attr.adyenCustomTabsToolbarColor) | ||
val secondaryToolbarColor = context.getColorOrNull(R.attr.adyenCustomTabsSecondaryToolbarColor) | ||
val navigationBarColor = context.getColorOrNull(R.attr.adyenCustomTabsNavigationBarColor) | ||
val navigationBarDividerColor = context.getColorOrNull(R.attr.adyenCustomTabsNavigationBarDividerColor) | ||
|
||
return CustomTabColorSchemeParams.Builder().apply { | ||
toolbarColor?.let { setToolbarColor(it) } | ||
secondaryToolbarColor?.let { setSecondaryToolbarColor(it) } | ||
navigationBarColor?.let { setNavigationBarColor(it) } | ||
navigationBarDividerColor?.let { setNavigationBarDividerColor(it) } | ||
}.build() | ||
} | ||
|
||
private fun Context.getColorOrNull(@AttrRes attribute: Int): Int? { | ||
val typedArray = obtainStyledAttributes(R.style.AdyenCheckout_CustomTabs, intArrayOf(attribute)) | ||
val color = typedArray.getColor(0, -1).takeIf { it != -1 } | ||
typedArray.recycle() | ||
return color | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 0 additions & 32 deletions
32
ui-core/src/main/java/com/adyen/checkout/ui/core/internal/util/ThemeUtil.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters