-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(android-sdk): support copy text for WebView (#219)
- Loading branch information
Showing
4 changed files
with
38 additions
and
4 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
27 changes: 27 additions & 0 deletions
27
android-sdk/android/src/main/kotlin/io/logto/sdk/android/auth/logto/LogtoWebViewPolyfill.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,27 @@ | ||
package io.logto.sdk.android.auth.logto | ||
|
||
import android.app.Activity | ||
import android.content.ClipData | ||
import android.content.ClipboardManager | ||
import android.content.Context | ||
import android.webkit.JavascriptInterface | ||
|
||
class LogtoWebViewPolyfill(private val hostActivity: Activity) { | ||
companion object { | ||
const val NAME = "Polyfill" | ||
} | ||
|
||
fun getInjectScript() = """ | ||
window.addEventListener("load", () => { | ||
window.navigator.clipboard = { | ||
writeText: (text) => window.$NAME.writeText(text), | ||
}; | ||
}); | ||
""".trimIndent() | ||
|
||
@JavascriptInterface | ||
fun writeText(text: String) { | ||
val clipboard = hostActivity.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager | ||
clipboard.setPrimaryClip(ClipData.newPlainText(text, text)) | ||
} | ||
} |
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