Skip to content

Commit cbfc9c7

Browse files
VarunBaradfdocr
andauthored
Add methods to implement native copy-to-clipboard functionality. (#60)
* Add methods to implement native copy-to-clipboard functionality. * Supply context to AndroidWebViewBridge. Co-authored-by: Fernando Valverde <[email protected]>
1 parent ed12a62 commit cbfc9c7

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

app/src/main/java/to/dev/dev_android/util/AndroidWebViewBridge.kt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import android.content.ClipboardManager
55
import android.content.Context
66
import android.util.Log
77
import android.webkit.JavascriptInterface
8+
import android.widget.Toast
9+
import to.dev.dev_android.BuildConfig
810

911
/**
1012
* This class currently is empty because more methods would be added to it
1113
* when new bridge functionalities are added.
1214
*/
13-
class AndroidWebViewBridge(private val mContext: Context) {
14-
15+
class AndroidWebViewBridge(private val context: Context) {
1516
/**
1617
* Every method that has to be accessed from web-view needs to be marked with
1718
* `@JavascriptInterface`.
@@ -23,9 +24,14 @@ class AndroidWebViewBridge(private val mContext: Context) {
2324
}
2425

2526
@JavascriptInterface
26-
fun copyToClipboard(text: String) {
27-
val clipboard = mContext.getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager
28-
val clip = ClipData.newPlainText("clipboard", text)
29-
clipboard?.primaryClip = clip
27+
fun copyToClipboard(copyText: String) {
28+
val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager
29+
val clipData = ClipData.newPlainText("DEV Community", copyText)
30+
clipboard?.primaryClip = clipData
31+
}
32+
33+
@JavascriptInterface
34+
fun showToast(message: String) {
35+
Toast.makeText(context, message, Toast.LENGTH_LONG).show()
3036
}
3137
}

0 commit comments

Comments
 (0)