From 6555a738c44d8734a8043e36711a6765c5c8d948 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Thu, 6 Jul 2017 15:03:29 -0700 Subject: Add copy to clipboard --- .../src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt | 10 +++++++++- core/src/main/res/values/strings_commons.xml | 14 ++++++++------ 2 files changed, 17 insertions(+), 7 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 diff --git a/core/src/main/res/values/strings_commons.xml b/core/src/main/res/values/strings_commons.xml index 0ca785d..fba49fe 100644 --- a/core/src/main/res/values/strings_commons.xml +++ b/core/src/main/res/values/strings_commons.xml @@ -4,6 +4,8 @@ Most resources are verbatim and x represents a formatted item --> + About App + About %s Add Account AMOLED Back @@ -33,6 +35,7 @@ Most resources are verbatim and x represents a formatted item Maybe Menu No + No Results Found None @android:string/ok 1 day @@ -40,18 +43,17 @@ Most resources are verbatim and x represents a formatted item Play Store Rate Report A Bug + Search Send Feedback + Send via Settings + Share Thank You Uh Oh + Warning %d days %d hours %d minutes - Warning Yes - Search - No Results Found - About App - Send via - About %s + Text copied to clipboard. -- cgit v1.2.3