add a settings item at the top bar too

This commit is contained in:
tibbi 2022-01-25 11:25:27 +01:00
parent 1f2b2b33c9
commit 97d9a28e9e
2 changed files with 84 additions and 45 deletions

View File

@ -1,9 +1,12 @@
package com.simplemobiletools.keyboard.views
import android.animation.AnimatorSet
import android.animation.ObjectAnimator
import android.annotation.SuppressLint
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.graphics.*
import android.graphics.Paint.Align
import android.graphics.drawable.ColorDrawable
@ -20,9 +23,12 @@ import android.view.accessibility.AccessibilityManager
import android.view.animation.AccelerateInterpolator
import android.widget.PopupWindow
import android.widget.TextView
import androidx.core.animation.doOnEnd
import androidx.core.animation.doOnStart
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.isPiePlus
import com.simplemobiletools.keyboard.R
import com.simplemobiletools.keyboard.activities.SettingsActivity
import com.simplemobiletools.keyboard.extensions.config
import com.simplemobiletools.keyboard.helpers.*
import com.simplemobiletools.keyboard.helpers.MyKeyboard.Companion.KEYCODE_DELETE
@ -276,7 +282,8 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
setLinkTextColor(mTextColor)
}
clipboard_delete.applyColorFilter(mTextColor)
settings_cog.applyColorFilter(mTextColor)
clipboard_clear.applyColorFilter(mTextColor)
}
}
}
@ -308,6 +315,16 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
/** Sets the top row above the keyboard containing a couple buttons and the clipboard **/
fun setToolbarHolder(toolbarHolder: View) {
mToolbarHolder = toolbarHolder
mToolbarHolder!!.apply {
settings_cog.setOnLongClickListener { context.toast(R.string.settings); true; }
settings_cog.setOnClickListener {
Intent(context, SettingsActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(this)
}
}
}
}
/**
@ -530,18 +547,27 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
}
}
clipboard_delete.setOnLongClickListener { context.toast(R.string.clear_clipboard_data); true; }
clipboard_delete.setOnClickListener {
clipboard_clear.setOnLongClickListener { context.toast(R.string.clear_clipboard_data); true; }
clipboard_clear.setOnClickListener {
clearClipboardContent()
toggleClipboardVisibility(false)
}
toggleClipboardVisibility(true)
}
} else {
mToolbarHolder?.clipboard_holder?.beGone()
hideClipboardViews()
}
} else {
mToolbarHolder?.clipboard_holder?.beGone()
hideClipboardViews()
}
}
private fun hideClipboardViews() {
mToolbarHolder?.apply {
clipboard_value_holder?.beGone()
clipboard_value_holder?.alpha = 0f
clipboard_clear?.beGone()
clipboard_clear?.alpha = 0f
}
}
@ -556,26 +582,33 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
}
private fun toggleClipboardVisibility(show: Boolean) {
val newAlpha = if (show) {
1f
} else {
0f
}
if ((show && mToolbarHolder?.clipboard_value_holder!!.alpha == 0f) || (!show && mToolbarHolder?.clipboard_value_holder!!.alpha == 1f)) {
val newAlpha = if (show) 1f else 0f
val animations = ArrayList<ObjectAnimator>()
val clipboardValueAnimation = ObjectAnimator.ofFloat(mToolbarHolder!!.clipboard_value_holder!!, "alpha", newAlpha)
animations.add(clipboardValueAnimation)
mToolbarHolder?.clipboard_holder!!.animate()!!
.alpha(newAlpha)
.setInterpolator(AccelerateInterpolator())
.setDuration(150)
.withStartAction {
val clipboardClearAnimation = ObjectAnimator.ofFloat(mToolbarHolder!!.clipboard_clear!!, "alpha", newAlpha)
animations.add(clipboardClearAnimation)
val animSet = AnimatorSet()
animSet.playTogether(*animations.toTypedArray())
animSet.duration = 150
animSet.interpolator = AccelerateInterpolator()
animSet.doOnStart {
if (show) {
mToolbarHolder?.clipboard_holder?.beVisible()
mToolbarHolder?.clipboard_value_holder?.beVisible()
mToolbarHolder?.clipboard_clear?.beVisible()
}
}
.withEndAction {
animSet.doOnEnd {
if (!show) {
mToolbarHolder?.clipboard_holder?.beGone()
mToolbarHolder?.clipboard_value_holder?.beGone()
mToolbarHolder?.clipboard_clear?.beGone()
}
}
animSet.start()
}
}.start()
}
private fun getKeyIndices(x: Int, y: Int, allKeys: IntArray?): Int {

View File

@ -13,23 +13,33 @@
android:layout_height="@dimen/toolbar_height"
android:gravity="center_vertical">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/clipboard_holder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
<ImageView
android:id="@+id/settings_cog"
android:layout_width="@dimen/list_avatar_size"
android:layout_height="@dimen/list_avatar_size"
android:layout_marginStart="@dimen/medium_margin"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/settings"
android:padding="@dimen/medium_margin"
android:src="@drawable/ic_settings_cog_vector"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<RelativeLayout
android:id="@+id/clipboard_value_holder"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/clipboard_clear"
app:layout_constraintStart_toEndOf="@+id/settings_cog"
app:layout_constraintTop_toTopOf="parent">
<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:layout_toStartOf="@+id/clipboard_delete"
android:layout_centerInParent="true"
android:autoLink="none"
android:background="@drawable/clipboard_background"
android:ellipsize="end"
@ -40,14 +50,11 @@
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:id="@+id/clipboard_clear"
android:layout_width="@dimen/list_avatar_size"
android:layout_height="@dimen/list_avatar_size"
android:layout_marginEnd="@dimen/medium_margin"
@ -60,7 +67,6 @@
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<com.simplemobiletools.keyboard.views.MyKeyboardView
android:id="@+id/keyboard_view"