File tree Expand file tree Collapse file tree 2 files changed +57
-1
lines changed
src/main/java/org/buffer/android/utils Expand file tree Collapse file tree 2 files changed +57
-1
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,8 @@ android {
22
22
23
23
dependencies {
24
24
implementation ' androidx.appcompat:appcompat:1.0.2'
25
- implementation " org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version "
25
+ implementation ' androidx.browser:browser:1.0.0'
26
+ implementation " org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version "
26
27
}
27
28
28
29
publish {
Original file line number Diff line number Diff line change
1
+ package org.buffer.android.utils
2
+
3
+ import android.content.ActivityNotFoundException
4
+ import android.content.Context
5
+ import android.content.Intent
6
+ import android.graphics.BitmapFactory
7
+ import android.net.Uri
8
+ import android.util.Log
9
+ import androidx.annotation.ColorRes
10
+ import androidx.annotation.DrawableRes
11
+ import androidx.browser.customtabs.CustomTabsIntent
12
+ import androidx.core.content.ContextCompat
13
+
14
+ object CustomTabUtil {
15
+
16
+ fun open (
17
+ context : Context ,
18
+ uri : Uri ,
19
+ @ColorRes color : Int ,
20
+ @DrawableRes backArrow : Int
21
+ ) {
22
+ val intent = buildIntent(context, uri, color, backArrow)
23
+ try {
24
+ context.startActivity(intent)
25
+ } catch (error: ActivityNotFoundException ) {
26
+ Log .e(
27
+ CustomTabUtil ::class .java.name,
28
+ " There was a problem start the browser intent"
29
+ )
30
+ }
31
+
32
+ }
33
+
34
+ private fun buildIntent (
35
+ context : Context ,
36
+ uri : Uri ,
37
+ @ColorRes color : Int ,
38
+ @DrawableRes backArrow : Int
39
+ ): Intent {
40
+ val customTabsIntent = CustomTabsIntent .Builder ()
41
+ .setToolbarColor(ContextCompat .getColor(context, color))
42
+ .setShowTitle(true )
43
+ .setCloseButtonIcon(
44
+ BitmapFactory .decodeResource(
45
+ context.resources,
46
+ backArrow
47
+ )
48
+ )
49
+ .addDefaultShareMenuItem()
50
+ .build()
51
+ return customTabsIntent.intent.apply {
52
+ data = uri
53
+ }
54
+ }
55
+ }
You can’t perform that action at this time.
0 commit comments