hide the clipboard content only at Delete, not whole toolbar

This commit is contained in:
tibbi 2022-01-25 10:07:23 +01:00
parent 1a12aa67b1
commit 1f2b2b33c9
4 changed files with 92 additions and 58 deletions

View File

@ -41,7 +41,7 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
val keyboardHolder = layoutInflater.inflate(R.layout.keyboard_view_keyboard, null) val keyboardHolder = layoutInflater.inflate(R.layout.keyboard_view_keyboard, null)
keyboardView = keyboardHolder.keyboard_view as MyKeyboardView keyboardView = keyboardHolder.keyboard_view as MyKeyboardView
keyboardView!!.setKeyboard(keyboard!!) keyboardView!!.setKeyboard(keyboard!!)
keyboardView!!.setClipboardHolder(keyboardHolder.clipboard_holder) keyboardView!!.setToolbarHolder(keyboardHolder.toolbar_holder)
keyboardView!!.mOnKeyboardActionListener = this keyboardView!!.mOnKeyboardActionListener = this
return keyboardHolder!! return keyboardHolder!!
} }

View File

@ -139,7 +139,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
private var mKeyBackground: Drawable? = null private var mKeyBackground: Drawable? = null
private val mDistances = IntArray(MAX_NEARBY_KEYS) private val mDistances = IntArray(MAX_NEARBY_KEYS)
private var mClipboardHolder: View? = null private var mToolbarHolder: View? = null
// For multi-tap // For multi-tap
private var mLastTapTime = 0L private var mLastTapTime = 0L
@ -263,6 +263,21 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
} }
background.applyColorFilter(newBgColor.darkenColor(2)) background.applyColorFilter(newBgColor.darkenColor(2))
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)
mToolbarHolder?.apply {
background = ColorDrawable(mBackgroundColor.darkenColor())
clipboard_value.apply {
background = rippleBg
setTextColor(mTextColor)
setLinkTextColor(mTextColor)
}
clipboard_delete.applyColorFilter(mTextColor)
}
} }
} }
@ -290,9 +305,9 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
mAbortKey = true // Until the next ACTION_DOWN mAbortKey = true // Until the next ACTION_DOWN
} }
/** Sets the top row above the keyboard containing the clipboard value **/ /** Sets the top row above the keyboard containing a couple buttons and the clipboard **/
fun setClipboardHolder(clipboardHolder: View) { fun setToolbarHolder(toolbarHolder: View) {
mClipboardHolder = clipboardHolder mToolbarHolder = toolbarHolder
} }
/** /**
@ -504,37 +519,29 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
} }
private fun handleClipboard() { private fun handleClipboard() {
if (context.config.showClipboard && mClipboardHolder != null && mPopupParent.id != R.id.mini_keyboard_view) { if (context.config.showClipboard && mToolbarHolder != null && mPopupParent.id != R.id.mini_keyboard_view) {
val clipboardContent = (context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager).primaryClip?.getItemAt(0)?.text val clipboardContent = (context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager).primaryClip?.getItemAt(0)?.text
if (clipboardContent?.trim()?.isNotEmpty() == true) { if (clipboardContent?.trim()?.isNotEmpty() == true) {
val rippleBg = resources.getDrawable(R.drawable.clipboard_background, context.theme) as RippleDrawable mToolbarHolder?.apply {
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 { clipboard_value.apply {
text = clipboardContent text = clipboardContent
background = rippleBg
setTextColor(mTextColor)
setLinkTextColor(mTextColor)
setOnClickListener { setOnClickListener {
mOnKeyboardActionListener!!.onText(clipboardContent.toString()) mOnKeyboardActionListener!!.onText(clipboardContent.toString())
} }
} }
clipboard_delete.applyColorFilter(mTextColor)
clipboard_delete.setOnLongClickListener { context.toast(R.string.clear_clipboard_data); true; } clipboard_delete.setOnLongClickListener { context.toast(R.string.clear_clipboard_data); true; }
clipboard_delete.setOnClickListener { clipboard_delete.setOnClickListener {
clearClipboardContent() clearClipboardContent()
toggleClipboardVisibility(false)
} }
toggleClipboardVisibility(true)
} }
} else { } else {
mClipboardHolder?.beGone() mToolbarHolder?.clipboard_holder?.beGone()
} }
} else { } else {
mClipboardHolder?.beGone() mToolbarHolder?.clipboard_holder?.beGone()
} }
} }
@ -546,14 +553,28 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
val clip = ClipData.newPlainText("", "") val clip = ClipData.newPlainText("", "")
clipboardManager.setPrimaryClip(clip) clipboardManager.setPrimaryClip(clip)
} }
}
mClipboardHolder?.animate()!! private fun toggleClipboardVisibility(show: Boolean) {
.yBy(mClipboardHolder!!.height.toFloat()) val newAlpha = if (show) {
1f
} else {
0f
}
mToolbarHolder?.clipboard_holder!!.animate()!!
.alpha(newAlpha)
.setInterpolator(AccelerateInterpolator()) .setInterpolator(AccelerateInterpolator())
.setDuration(200) .setDuration(150)
.withStartAction {
if (show) {
mToolbarHolder?.clipboard_holder?.beVisible()
}
}
.withEndAction { .withEndAction {
mClipboardHolder?.beGone() if (!show) {
mClipboardHolder?.y = mClipboardHolder!!.y - mClipboardHolder!!.height mToolbarHolder?.clipboard_holder?.beGone()
}
}.start() }.start()
} }

View File

@ -7,11 +7,21 @@
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:orientation="vertical"> android:orientation="vertical">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/toolbar_holder"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
android:gravity="center_vertical">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/clipboard_holder" android:id="@+id/clipboard_holder"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/clipboard_height" android:layout_height="match_parent"
android:gravity="center_vertical"> android:gravity="center_vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView <TextView
android:id="@+id/clipboard_value" android:id="@+id/clipboard_value"
@ -19,9 +29,11 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_margin" android:layout_marginStart="@dimen/activity_margin"
android:layout_marginEnd="@dimen/medium_margin" android:layout_marginEnd="@dimen/medium_margin"
android:layout_toStartOf="@+id/clipboard_delete"
android:autoLink="none" android:autoLink="none"
android:background="@drawable/clipboard_background" android:background="@drawable/clipboard_background"
android:ellipsize="end" android:ellipsize="end"
android:gravity="center"
android:lines="1" android:lines="1"
android:paddingStart="@dimen/activity_margin" android:paddingStart="@dimen/activity_margin"
android:paddingTop="@dimen/smaller_margin" android:paddingTop="@dimen/smaller_margin"
@ -48,6 +60,7 @@
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<com.simplemobiletools.keyboard.views.MyKeyboardView <com.simplemobiletools.keyboard.views.MyKeyboardView
android:id="@+id/keyboard_view" android:id="@+id/keyboard_view"

View File

@ -2,7 +2,7 @@
<dimen name="popup_max_move_distance">60dp</dimen> <dimen name="popup_max_move_distance">60dp</dimen>
<dimen name="top_small_number_margin_width">12dp</dimen> <dimen name="top_small_number_margin_width">12dp</dimen>
<dimen name="top_small_number_margin_height">18dp</dimen> <dimen name="top_small_number_margin_height">18dp</dimen>
<dimen name="clipboard_height">50dp</dimen> <dimen name="toolbar_height">50dp</dimen>
<dimen name="key_height">60dp</dimen> <dimen name="key_height">60dp</dimen>
<dimen name="vertical_correction">-10dp</dimen> <dimen name="vertical_correction">-10dp</dimen>