Improve recognition to reset app timeout #562

This commit is contained in:
J-Jamet committed 2020-07-10 17:46:14 +02:00
1 parent fe902648ad
commit 9f99b67563
10 files changed
+36 -5

No files matched your search

+1
View File
@@ -3,6 +3,7 @@ KeePassDX(2.8)
* Fix searching in recycle bin
* Settings to back to the previous keyboard during database credentials and after form filling
* Improve action tasks
* Improve recognition to reset app timeout
* Fix minor issues
KeePassDX(2.7)
@@ -130,6 +130,9 @@ class EntryActivity : LockingActivity() {
lockAndExit()
}
// Focus view to reinitialize timeout
resetAppTimeoutWhenViewFocusedOrChanged(coordinatorLayout)
// Init the clipboard helper
clipboardHelper = ClipboardHelper(this)
firstLaunchOfActivity = true
@@ -121,7 +121,7 @@ class EntryEditActivity : LockingActivity(),
}
// Focus view to reinitialize timeout
resetAppTimeoutWhenViewFocusedOrChanged(entryEditContentsView)
resetAppTimeoutWhenViewFocusedOrChanged(coordinatorLayout)
stopService(Intent(this, ClipboardEntryNotificationService::class.java))
stopService(Intent(this, KeyboardEntryNotificationService::class.java))
@@ -32,6 +32,7 @@ import android.util.Log
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.annotation.RequiresApi
@@ -90,6 +91,7 @@ class GroupActivity : LockingActivity(),
SortDialogFragment.SortSelectionListener {
// Views
private var rootContainerView: ViewGroup? = null
private var coordinatorLayout: CoordinatorLayout? = null
private var lockView: View? = null
private var toolbar: Toolbar? = null
@@ -130,6 +132,7 @@ class GroupActivity : LockingActivity(),
setContentView(layoutInflater.inflate(R.layout.activity_group, null))
// Initialize views
rootContainerView = findViewById(R.id.activity_group_container_view)
coordinatorLayout = findViewById(R.id.group_coordinator)
iconView = findViewById(R.id.group_icon)
numberChildrenView = findViewById(R.id.group_numbers)
@@ -153,7 +156,7 @@ class GroupActivity : LockingActivity(),
taTextColor.recycle()
// Focus view to reinitialize timeout
resetAppTimeoutWhenViewFocusedOrChanged(addNodeButtonView)
resetAppTimeoutWhenViewFocusedOrChanged(rootContainerView)
// Retrieve elements after an orientation change
if (savedInstanceState != null) {
@@ -19,9 +19,10 @@
*/
package com.kunzisoft.keepass.activities.lock
import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import com.kunzisoft.keepass.activities.helpers.ReadOnlyHelper
@@ -152,11 +153,21 @@ abstract class LockingActivity : SpecialModeActivity() {
/**
* To reset the app timeout when a view is focused or changed
*/
@SuppressLint("ClickableViewAccessibility")
protected fun resetAppTimeoutWhenViewFocusedOrChanged(vararg views: View?) {
views.forEach {
it?.setOnTouchListener { _, event ->
when (event.action) {
MotionEvent.ACTION_DOWN -> {
// Log.d(TAG, "View touched, try to reset app timeout")
TimeoutHelper.checkTimeAndLockIfTimeoutOrResetTimeout(this)
}
}
false
}
it?.setOnFocusChangeListener { _, hasFocus ->
if (hasFocus) {
Log.d(TAG, "View focused, reset app timeout")
// Log.d(TAG, "View focused, try to reset app timeout")
TimeoutHelper.checkTimeAndLockIfTimeoutOrResetTimeout(this)
}
}
@@ -92,6 +92,9 @@ open class SettingsActivity
lockAndExit()
}
// Focus view to reinitialize timeout
resetAppTimeoutWhenViewFocusedOrChanged(coordinatorLayout)
if (savedInstanceState == null) {
supportFragmentManager.beginTransaction()
.add(R.id.fragment_container, retrieveMainFragment())
@@ -38,6 +38,7 @@ object TimeoutHelper {
private const val TAG = "TimeoutHelper"
private var lastAppTimeoutRecord: Long? = null
var temporarilyDisableTimeout = false
private set
@@ -141,7 +142,13 @@ object TimeoutHelper {
*/
fun checkTimeAndLockIfTimeoutOrResetTimeout(context: Context, action: (() -> Unit)? = null) {
if (checkTimeAndLockIfTimeout(context)) {
recordTime(context)
// To prevent spam registration, record after at least 2 seconds
if (lastAppTimeoutRecord == null
|| lastAppTimeoutRecord!! + 2000 <= System.currentTimeMillis()) {
Log.d(TAG, "Record app timeout")
recordTime(context)
lastAppTimeoutRecord = System.currentTimeMillis()
}
action?.invoke()
}
}
@@ -21,6 +21,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_group_container_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
@@ -2,5 +2,6 @@
* Fix searching in recycle bin
* Settings to back to the previous keyboard during database credentials and after form filling
* Improving action tasks
* Improve recognition to reset app timeout
* Fix minor issues
@@ -2,4 +2,5 @@
* Correction de la recherche dans la corbeille
* Paramètres pour revenir automatiquement au clavier précédent durant l'identification de la base et après le remplissage de formulaire
* Amélioration des tâches d'action
* Amélioration de la reconnaissance pour le temps écoulé
* Correction de problèmes mineurs