Manage package name from Magikeyboard #1010

This commit is contained in:
J-Jamet
2022-04-05 15:28:15 +02:00
parent 131eb78407
commit 553098f9be
9 changed files with 130 additions and 108 deletions

View File

@@ -8,6 +8,7 @@ KeePassDX(3.4.0)
* Fix small bugs #1282
* Better search implementation #175 #1254
* Setting to change keyboard during a search #1243
* Manage package name from Magikeyboard #1010
KeePassDX(3.3.3)
* Fix shared otpauth link if database not open #1274

View File

@@ -172,9 +172,6 @@
<data android:scheme="otpauth" android:host="hotp" />
</intent-filter>
</activity>
<activity
android:name="com.kunzisoft.keepass.activities.MagikeyboardLauncherActivity"
android:theme="@style/Theme.Transparent" />
<activity
android:name="com.kunzisoft.keepass.settings.MagikeyboardSettingsActivity"
android:label="@string/keyboard_setting_label"

View File

@@ -20,8 +20,10 @@
package com.kunzisoft.keepass.activities
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.widget.Toast
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.activities.helpers.EntrySelectionHelper
@@ -50,40 +52,52 @@ class EntrySelectionLauncherActivity : DatabaseModeActivity() {
override fun onDatabaseRetrieved(database: Database?) {
super.onDatabaseRetrieved(database)
var sharedWebDomain: String? = null
var otpString: String? = null
when (intent?.action) {
Intent.ACTION_SEND -> {
if ("text/plain" == intent.type) {
// Retrieve web domain or OTP
intent.getStringExtra(Intent.EXTRA_TEXT)?.let { extra ->
if (OtpEntryFields.isOTPUri(extra))
otpString = extra
else
sharedWebDomain = Uri.parse(extra).host
val keySelectionBundle = intent.getBundleExtra(KEY_SELECTION_BUNDLE)
if (keySelectionBundle != null) {
// To manage package name
var searchInfo = SearchInfo()
keySelectionBundle.getParcelable<SearchInfo>(KEY_SEARCH_INFO)?.let { mSearchInfo ->
searchInfo = mSearchInfo
}
launch(database, searchInfo)
} else {
// To manage share
var sharedWebDomain: String? = null
var otpString: String? = null
when (intent?.action) {
Intent.ACTION_SEND -> {
if ("text/plain" == intent.type) {
// Retrieve web domain or OTP
intent.getStringExtra(Intent.EXTRA_TEXT)?.let { extra ->
if (OtpEntryFields.isOTPUri(extra))
otpString = extra
else
sharedWebDomain = Uri.parse(extra).host
}
}
}
}
Intent.ACTION_VIEW -> {
// Retrieve OTP
intent.dataString?.let { extra ->
if (OtpEntryFields.isOTPUri(extra))
otpString = extra
Intent.ACTION_VIEW -> {
// Retrieve OTP
intent.dataString?.let { extra ->
if (OtpEntryFields.isOTPUri(extra))
otpString = extra
}
}
else -> {}
}
else -> {}
}
// Build domain search param
val searchInfo = SearchInfo().apply {
this.webDomain = sharedWebDomain
this.otpString = otpString
}
// Build domain search param
val searchInfo = SearchInfo().apply {
this.webDomain = sharedWebDomain
this.otpString = otpString
}
SearchInfo.getConcreteWebDomain(this, searchInfo.webDomain) { concreteWebDomain ->
searchInfo.webDomain = concreteWebDomain
launch(database, searchInfo)
SearchInfo.getConcreteWebDomain(this, searchInfo.webDomain) { concreteWebDomain ->
searchInfo.webDomain = concreteWebDomain
launch(database, searchInfo)
}
}
}
@@ -176,9 +190,44 @@ class EntrySelectionLauncherActivity : DatabaseModeActivity() {
}
}
)
} else {
SearchHelper.checkAutoSearchInfo(this,
database,
null,
{ _, _ ->
// Not called
// if items found directly returns before calling this activity
},
{ openedDatabase ->
// Select if not found
GroupActivity.launchForKeyboardSelectionResult(this, openedDatabase)
},
{
// Pass extra to get entry
FileDatabaseSelectActivity.launchForKeyboardSelectionResult(this)
}
)
}
finish()
}
companion object {
private const val KEY_SELECTION_BUNDLE = "KEY_SELECTION_BUNDLE"
private const val KEY_SEARCH_INFO = "KEY_SEARCH_INFO"
fun launch(context: Context,
searchInfo: SearchInfo? = null) {
val intent = Intent(context, EntrySelectionLauncherActivity::class.java).apply {
putExtra(KEY_SELECTION_BUNDLE, Bundle().apply {
putParcelable(KEY_SEARCH_INFO, searchInfo)
})
}
// New task needed because don't launch from an Activity context
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
context.startActivity(intent)
}
}
}
fun populateKeyboardAndMoveAppToBackground(activity: Activity,

View File

@@ -1,59 +0,0 @@
/*
* Copyright 2020 Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePassDX.
*
* KeePassDX 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.
*
* KeePassDX 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 KeePassDX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.activities
import com.kunzisoft.keepass.activities.legacy.DatabaseModeActivity
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.search.SearchHelper
/**
* Activity to select entry in database and populate it in Magikeyboard
*/
class MagikeyboardLauncherActivity : DatabaseModeActivity() {
override fun applyCustomStyle(): Boolean {
return false
}
override fun finishActivityIfReloadRequested(): Boolean {
return true
}
override fun onDatabaseRetrieved(database: Database?) {
super.onDatabaseRetrieved(database)
SearchHelper.checkAutoSearchInfo(this,
database,
null,
{ _, _ ->
// Not called
// if items found directly returns before calling this activity
},
{ openedDatabase ->
// Select if not found
GroupActivity.launchForKeyboardSelectionResult(this, openedDatabase)
},
{
// Pass extra to get entry
FileDatabaseSelectActivity.launchForKeyboardSelectionResult(this)
}
)
finish()
}
}

View File

@@ -18,6 +18,8 @@ package com.kunzisoft.keepass.magikeyboard;
import static com.kunzisoft.keepass.magikeyboard.MagikeyboardService.KEY_BACK_KEYBOARD;
import static com.kunzisoft.keepass.magikeyboard.MagikeyboardService.KEY_CHANGE_KEYBOARD;
import static com.kunzisoft.keepass.magikeyboard.MagikeyboardService.KEY_ENTRY;
import static com.kunzisoft.keepass.magikeyboard.MagikeyboardService.KEY_ENTRY_ALT;
import static com.kunzisoft.keepass.magikeyboard.MagikeyboardService.KEY_OTP;
import static com.kunzisoft.keepass.magikeyboard.MagikeyboardService.KEY_OTP_ALT;
@@ -1049,6 +1051,9 @@ public class KeyboardView extends View implements View.OnClickListener {
if (popupKey.codes[0] == KEY_BACK_KEYBOARD) {
mKeyboardActionListener.onKey(KEY_CHANGE_KEYBOARD, popupKey.codes);
return true;
} else if (popupKey.codes[0] == KEY_ENTRY) {
mKeyboardActionListener.onKey(KEY_ENTRY_ALT, popupKey.codes);
return true;
} else if (popupKey.codes[0] == KEY_OTP) {
mKeyboardActionListener.onKey(KEY_OTP_ALT, popupKey.codes);
return true;

View File

@@ -33,12 +33,13 @@ import android.widget.FrameLayout
import android.widget.PopupWindow
import android.widget.TextView
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.activities.MagikeyboardLauncherActivity
import com.kunzisoft.keepass.activities.EntrySelectionLauncherActivity
import com.kunzisoft.keepass.adapters.FieldsAdapter
import com.kunzisoft.keepass.database.action.DatabaseTaskProvider
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.element.Field
import com.kunzisoft.keepass.model.EntryInfo
import com.kunzisoft.keepass.model.SearchInfo
import com.kunzisoft.keepass.otp.OtpEntryFields.OTP_TOKEN_FIELD
import com.kunzisoft.keepass.services.KeyboardEntryNotificationService
import com.kunzisoft.keepass.settings.PreferencesUtil
@@ -51,12 +52,15 @@ class MagikeyboardService : InputMethodService(), KeyboardView.OnKeyboardActionL
private var keyboardView: KeyboardView? = null
private var entryText: TextView? = null
private var packageText: TextView? = null
private var keyboard: Keyboard? = null
private var keyboardEntry: Keyboard? = null
private var popupCustomKeys: PopupWindow? = null
private var fieldsAdapter: FieldsAdapter? = null
private var playSoundDuringCLick: Boolean = false
private var mFormPackageName: String? = null
private var lockReceiver: LockReceiver? = null
override fun onCreate() {
@@ -83,6 +87,7 @@ class MagikeyboardService : InputMethodService(), KeyboardView.OnKeyboardActionL
val rootKeyboardView = layoutInflater.inflate(R.layout.keyboard_container, null)
entryText = rootKeyboardView.findViewById(R.id.magikeyboard_entry_text)
packageText = rootKeyboardView.findViewById(R.id.magikeyboard_package_text)
keyboardView = rootKeyboardView.findViewById(R.id.magikeyboard_view)
if (keyboardView != null) {
@@ -170,6 +175,13 @@ class MagikeyboardService : InputMethodService(), KeyboardView.OnKeyboardActionL
override fun onStartInputView(info: EditorInfo, restarting: Boolean) {
super.onStartInputView(info, restarting)
mFormPackageName = info.packageName
if (!mFormPackageName.isNullOrEmpty()) {
packageText?.text = mFormPackageName
packageText?.visibility = View.VISIBLE
} else {
packageText?.visibility = View.GONE
}
assignKeyboardView()
}
@@ -228,16 +240,17 @@ class MagikeyboardService : InputMethodService(), KeyboardView.OnKeyboardActionL
(getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager?)
?.showInputMethodPicker()
}
KEY_UNLOCK -> {
}
KEY_ENTRY -> {
// Stop current service and reinit entry
stopService(Intent(this, KeyboardEntryNotificationService::class.java))
removeEntryInfo()
val intent = Intent(this, MagikeyboardLauncherActivity::class.java)
// New task needed because don't launch from an Activity context
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
startActivity(intent)
actionKeyEntry()
}
KEY_ENTRY_ALT -> {
var searchInfo: SearchInfo? = null
if (mFormPackageName != null) {
searchInfo = SearchInfo().apply {
applicationId = mFormPackageName
}
}
actionKeyEntry(searchInfo)
}
KEY_LOCK -> {
removeEntryInfo()
@@ -303,6 +316,13 @@ class MagikeyboardService : InputMethodService(), KeyboardView.OnKeyboardActionL
}
}
private fun actionKeyEntry(searchInfo: SearchInfo? = null) {
// Stop current service and reinit entry
stopService(Intent(this, KeyboardEntryNotificationService::class.java))
removeEntryInfo()
EntrySelectionLauncherActivity.launch(this, searchInfo)
}
private fun actionTabAutomatically() {
if (PreferencesUtil.isAutoGoActionEnable(this))
currentInputConnection.sendKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_TAB))
@@ -359,15 +379,15 @@ class MagikeyboardService : InputMethodService(), KeyboardView.OnKeyboardActionL
const val KEY_BACK_KEYBOARD = 600
const val KEY_CHANGE_KEYBOARD = 601
private const val KEY_UNLOCK = 610
private const val KEY_LOCK = 611
private const val KEY_ENTRY = 620
private const val KEY_USERNAME = 500
private const val KEY_PASSWORD = 510
const val KEY_LOCK = 611
const val KEY_ENTRY = 620
const val KEY_ENTRY_ALT = 621
const val KEY_USERNAME = 500
const val KEY_PASSWORD = 510
const val KEY_OTP = 515
const val KEY_OTP_ALT = 516
private const val KEY_URL = 520
private const val KEY_FIELDS = 530
const val KEY_URL = 520
const val KEY_FIELDS = 530
// TODO Retrieve entry info from id and service when database is open
private var entryInfoKey: EntryInfo? = null

View File

@@ -32,6 +32,13 @@
android:background="@color/grey_blue_deep"
android:gravity="center"
android:textColor="@color/white"/>
<TextView
android:id="@+id/magikeyboard_package_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/grey_blue_deep"
android:gravity="center"
android:textColor="@color/reply_blue"/>
<com.kunzisoft.keepass.magikeyboard.KeyboardView
android:id="@+id/magikeyboard_view"
style="@style/KeepassDXStyle.Keyboard"

View File

@@ -7,3 +7,4 @@
* Fix small bugs #1282
* Better search implementation #175 #1254
* Setting to change keyboard during a search #1243
* Manage package name from Magikeyboard #1010

View File

@@ -7,3 +7,4 @@
* Correction de petits bugs #1282
* Meilleure implémentation de la recherche #175 #1254
* Paramètre pour changer de clavier lors d'une recherche #1243
* Gestion du nom de package du Magiclavier #1010