diff options
author | Allan Wang <me@allanwang.ca> | 2017-07-06 15:03:29 -0700 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2017-07-06 15:03:29 -0700 |
commit | 6555a738c44d8734a8043e36711a6765c5c8d948 (patch) | |
tree | eb057d78a9b73b5885dd86c5ce366c6c95f78208 /core/src/main/kotlin | |
parent | f0731069057bb52614ba184389eb1432d9ba7e16 (diff) | |
download | kau-6555a738c44d8734a8043e36711a6765c5c8d948.tar.gz kau-6555a738c44d8734a8043e36711a6765c5c8d948.tar.bz2 kau-6555a738c44d8734a8043e36711a6765c5c8d948.zip |
Add copy to clipboard
Diffstat (limited to 'core/src/main/kotlin')
-rw-r--r-- | core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt index 21021e2..bc01919 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt @@ -2,6 +2,8 @@ package ca.allanwang.kau.utils import android.app.Activity import android.app.ActivityOptions +import android.content.ClipData +import android.content.ClipboardManager import android.content.Context import android.content.Intent import android.content.pm.PackageManager @@ -162,4 +164,10 @@ inline val Context.isNavBarOnBottom: Boolean return !canMove || dm.widthPixels < dm.heightPixels } -fun Context.hasPermission(permissions: String) = !buildIsMarshmallowAndUp || ContextCompat.checkSelfPermission(this, permissions) == PackageManager.PERMISSION_GRANTED
\ No newline at end of file +fun Context.hasPermission(permissions: String) = !buildIsMarshmallowAndUp || ContextCompat.checkSelfPermission(this, permissions) == PackageManager.PERMISSION_GRANTED + +fun Context.copyToClipboard(text: String, label: String = "Copied Text", showToast: Boolean = true) { + val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager + clipboard.primaryClip = ClipData.newPlainText(label, text) + if (showToast) toast(R.string.kau_text_copied) +}
\ No newline at end of file |