Add entry title in Magikeyboard

This commit is contained in:
J-Jamet
2019-08-12 14:05:23 +02:00
parent 23f2e5decc
commit dcf654cf0a
3 changed files with 72 additions and 36 deletions

View File

@@ -34,11 +34,11 @@ import android.view.inputmethod.EditorInfo
import android.view.inputmethod.InputMethodManager
import android.widget.FrameLayout
import android.widget.PopupWindow
import android.widget.TextView
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.magikeyboard.adapter.FieldsAdapter
import com.kunzisoft.keepass.magikeyboard.receiver.LockBroadcastReceiver
import com.kunzisoft.keepass.magikeyboard.receiver.LockBroadcastReceiver.Companion.LOCK_ACTION
import com.kunzisoft.keepass.magikeyboard.view.MagikeyboardView
import com.kunzisoft.keepass.model.EntryInfo
import com.kunzisoft.keepass.model.Field
import com.kunzisoft.keepass.settings.PreferencesUtil
@@ -46,6 +46,7 @@ import com.kunzisoft.keepass.settings.PreferencesUtil
class MagikIME : InputMethodService(), KeyboardView.OnKeyboardActionListener {
private var keyboardView: KeyboardView? = null
private var entryText: TextView? = null
private var keyboard: Keyboard? = null
private var keyboardEntry: Keyboard? = null
private var popupCustomKeys: PopupWindow? = null
@@ -68,7 +69,10 @@ class MagikIME : InputMethodService(), KeyboardView.OnKeyboardActionListener {
}
override fun onCreateInputView(): View {
keyboardView = layoutInflater.inflate(R.layout.keyboard_view, null) as MagikeyboardView
val rootKeyboardView = layoutInflater.inflate(R.layout.keyboard_container, null)
entryText = rootKeyboardView.findViewById(R.id.magikeyboard_entry_text)
keyboardView = rootKeyboardView.findViewById(R.id.magikeyboard_view)
if (keyboardView != null) {
keyboard = Keyboard(this, R.xml.keyboard_password)
@@ -104,7 +108,7 @@ class MagikIME : InputMethodService(), KeyboardView.OnKeyboardActionListener {
val closeView = popupFieldsView.findViewById<View>(R.id.keyboard_popup_close)
closeView.setOnClickListener { popupCustomKeys?.dismiss() }
return keyboardView!!
return rootKeyboardView
}
return super.onCreateInputView()
@@ -113,10 +117,13 @@ class MagikIME : InputMethodService(), KeyboardView.OnKeyboardActionListener {
private fun assignKeyboardView() {
if (keyboardView != null) {
if (entryInfoKey != null) {
if (keyboardEntry != null)
if (keyboardEntry != null) {
populateEntryInfoInView()
keyboardView?.keyboard = keyboardEntry
}
} else {
if (keyboard != null) {
hideEntryInfo()
dismissCustomKeys()
keyboardView?.keyboard = keyboard
}
@@ -128,6 +135,19 @@ class MagikIME : InputMethodService(), KeyboardView.OnKeyboardActionListener {
}
}
private fun populateEntryInfoInView() {
entryText?.visibility = View.VISIBLE
if (entryInfoKey?.title?.isNotEmpty() == true) {
entryText?.text = entryInfoKey?.title
} else {
hideEntryInfo()
}
}
private fun hideEntryInfo() {
entryText?.visibility = View.GONE
}
override fun onStartInputView(info: EditorInfo, restarting: Boolean) {
super.onStartInputView(info, restarting)
assignKeyboardView()

View File

@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2018 Jeremy Jamet / Kunzisoft.
This file is part of KeePass DX.
KeePass DX is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
KeePass DX is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
-->
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_alignParentBottom="true"
android:paddingTop="4dp"
android:paddingBottom="8dp"
android:background="@color/keyboard_background"
android:orientation="vertical">
<TextView
android:id="@+id/magikeyboard_entry_text"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/magikeyboard_view"
android:background="@color/keyboard_background"
android:gravity="center"
android:textColor="@color/white"/>
<com.kunzisoft.keepass.magikeyboard.view.MagikeyboardView
android:id="@+id/magikeyboard_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:paddingTop="4dp"
app:layout_constraintBottom_toBottomOf="parent"
android:background="@color/keyboard_background"
android:keyBackground="@drawable/key_background"
android:keyTextColor="@color/white"
android:popupLayout="@layout/keyboard_popup_fields" />
</android.support.constraint.ConstraintLayout>

View File

@@ -1,32 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2018 Jeremy Jamet / Kunzisoft.
This file is part of KeePass DX.
KeePass DX is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
KeePass DX is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
-->
<com.kunzisoft.keepass.magikeyboard.view.MagikeyboardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/keyboard"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:background="@color/keyboard_background"
android:keyBackground="@drawable/key_background"
android:keyTextColor="#ffff"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:popupLayout="@layout/keyboard_popup_fields"
/>