add a button for clearing clipboard data
This commit is contained in:
parent
1da8153a5f
commit
34e498cac6
2 changed files with 80 additions and 31 deletions
|
@ -1,6 +1,7 @@
|
|||
package com.simplemobiletools.keyboard.views
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.graphics.*
|
||||
|
@ -16,9 +17,11 @@ import android.util.TypedValue
|
|||
import android.view.*
|
||||
import android.view.accessibility.AccessibilityEvent
|
||||
import android.view.accessibility.AccessibilityManager
|
||||
import android.view.animation.AccelerateInterpolator
|
||||
import android.widget.PopupWindow
|
||||
import android.widget.TextView
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.isPiePlus
|
||||
import com.simplemobiletools.keyboard.R
|
||||
import com.simplemobiletools.keyboard.extensions.config
|
||||
import com.simplemobiletools.keyboard.helpers.*
|
||||
|
@ -406,32 +409,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
|||
|
||||
canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR)
|
||||
|
||||
if (context.config.showClipboard && mClipboardHolder != null && mPopupParent.id != R.id.mini_keyboard_view) {
|
||||
val clipboardContent = (context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager).primaryClip?.getItemAt(0)?.text
|
||||
if (clipboardContent?.trim()?.isNotEmpty() == true) {
|
||||
val rippleBg = resources.getDrawable(R.drawable.clipboard_background, context.theme) as RippleDrawable
|
||||
val layerDrawable = rippleBg.findDrawableByLayerId(R.id.clipboard_background_holder) as LayerDrawable
|
||||
layerDrawable.findDrawableByLayerId(R.id.clipboard_background_shape).applyColorFilter(mBackgroundColor)
|
||||
|
||||
mClipboardHolder?.apply {
|
||||
background = ColorDrawable(mBackgroundColor.darkenColor())
|
||||
beVisible()
|
||||
clipboard_value.apply {
|
||||
text = clipboardContent
|
||||
background = rippleBg
|
||||
setTextColor(mTextColor)
|
||||
setOnClickListener {
|
||||
mOnKeyboardActionListener!!.onText(clipboardContent.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
mClipboardHolder?.beGone()
|
||||
}
|
||||
} else {
|
||||
mClipboardHolder?.beGone()
|
||||
}
|
||||
|
||||
handleClipboard()
|
||||
val keyCount = keys.size
|
||||
for (i in 0 until keyCount) {
|
||||
val key = keys[i]
|
||||
|
@ -525,6 +503,59 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
|||
mDirtyRect.setEmpty()
|
||||
}
|
||||
|
||||
private fun handleClipboard() {
|
||||
if (context.config.showClipboard && mClipboardHolder != null && mPopupParent.id != R.id.mini_keyboard_view) {
|
||||
val clipboardContent = (context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager).primaryClip?.getItemAt(0)?.text
|
||||
if (clipboardContent?.trim()?.isNotEmpty() == true) {
|
||||
val rippleBg = resources.getDrawable(R.drawable.clipboard_background, context.theme) as RippleDrawable
|
||||
val layerDrawable = rippleBg.findDrawableByLayerId(R.id.clipboard_background_holder) as LayerDrawable
|
||||
layerDrawable.findDrawableByLayerId(R.id.clipboard_background_shape).applyColorFilter(mBackgroundColor)
|
||||
|
||||
mClipboardHolder?.apply {
|
||||
background = ColorDrawable(mBackgroundColor.darkenColor())
|
||||
beVisible()
|
||||
clipboard_value.apply {
|
||||
text = clipboardContent
|
||||
background = rippleBg
|
||||
setTextColor(mTextColor)
|
||||
setOnClickListener {
|
||||
mOnKeyboardActionListener!!.onText(clipboardContent.toString())
|
||||
}
|
||||
}
|
||||
|
||||
clipboard_delete.applyColorFilter(mTextColor)
|
||||
clipboard_delete.setOnLongClickListener { context.toast(R.string.clear_clipboard_data); true; }
|
||||
clipboard_delete.setOnClickListener {
|
||||
clearClipboardContent()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
mClipboardHolder?.beGone()
|
||||
}
|
||||
} else {
|
||||
mClipboardHolder?.beGone()
|
||||
}
|
||||
}
|
||||
|
||||
private fun clearClipboardContent() {
|
||||
val clipboardManager = (context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager)
|
||||
if (isPiePlus()) {
|
||||
clipboardManager.clearPrimaryClip()
|
||||
} else {
|
||||
val clip = ClipData.newPlainText("", "")
|
||||
clipboardManager.setPrimaryClip(clip)
|
||||
}
|
||||
|
||||
mClipboardHolder?.animate()!!
|
||||
.yBy(mClipboardHolder!!.height.toFloat())
|
||||
.setInterpolator(AccelerateInterpolator())
|
||||
.setDuration(200)
|
||||
.withEndAction {
|
||||
mClipboardHolder?.beGone()
|
||||
mClipboardHolder?.y = mClipboardHolder!!.y - mClipboardHolder!!.height
|
||||
}.start()
|
||||
}
|
||||
|
||||
private fun getKeyIndices(x: Int, y: Int, allKeys: IntArray?): Int {
|
||||
val keys = mKeys
|
||||
var primaryIndex = NOT_A_KEY
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/keyboard_holder"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -6,18 +7,18 @@
|
|||
android:layout_alignParentBottom="true"
|
||||
android:orientation="vertical">
|
||||
|
||||
<RelativeLayout
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/clipboard_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/clipboard_height"
|
||||
android:gravity="center"
|
||||
android:paddingStart="@dimen/big_margin"
|
||||
android:paddingEnd="@dimen/big_margin">
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/clipboard_value"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/activity_margin"
|
||||
android:layout_marginEnd="@dimen/medium_margin"
|
||||
android:background="@drawable/clipboard_background"
|
||||
android:ellipsize="end"
|
||||
android:lines="1"
|
||||
|
@ -26,9 +27,26 @@
|
|||
android:paddingEnd="@dimen/activity_margin"
|
||||
android:paddingBottom="@dimen/smaller_margin"
|
||||
android:textSize="@dimen/label_text_size"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/clipboard_delete"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="Clipboard content" />
|
||||
|
||||
</RelativeLayout>
|
||||
<ImageView
|
||||
android:id="@+id/clipboard_delete"
|
||||
android:layout_width="@dimen/list_avatar_size"
|
||||
android:layout_height="@dimen/list_avatar_size"
|
||||
android:layout_marginEnd="@dimen/medium_margin"
|
||||
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||
android:contentDescription="@string/clear_clipboard_data"
|
||||
android:padding="@dimen/medium_margin"
|
||||
android:src="@drawable/ic_delete_vector"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<com.simplemobiletools.keyboard.views.MyKeyboardView
|
||||
android:id="@+id/keyboard_view"
|
||||
|
|
Loading…
Reference in a new issue