mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-12-06 00:32:32 -08:00
Add keyboard Timeout
This commit is contained in:
1 parent
6cb97de793
commit
e8d0d03ad9
6 files changed
+66
-37
No files matched your search
+46
-25
@@ -7,20 +7,24 @@ import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
import android.os.IBinder;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v7.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.kunzisoft.keepass.R;
|
||||
import com.kunzisoft.keepass.magikeyboard.receiver.LockBroadcastReceiver;
|
||||
import com.kunzisoft.keepass.magikeyboard.receiver.NotificationDeleteBroadcastReceiver;
|
||||
import com.kunzisoft.keepass.timeout.TimeoutHelper;
|
||||
|
||||
import static android.content.ContentValues.TAG;
|
||||
import static com.kunzisoft.keepass.magikeyboard.receiver.LockBroadcastReceiver.LOCK_ACTION;
|
||||
|
||||
public class KeyboardEntryNotificationService extends Service {
|
||||
|
||||
private static final String TAG = KeyboardEntryNotificationService.class.getName();
|
||||
|
||||
private static final String CHANNEL_ID_KEYBOARD = "com.kunzisoft.keyboard.notification.entry.channel";
|
||||
private static final String CHANNEL_NAME_KEYBOARD = "Magikeyboard notification";
|
||||
|
||||
@@ -100,30 +104,40 @@ public class KeyboardEntryNotificationService extends Service {
|
||||
|
||||
notificationManager.cancel(notificationId);
|
||||
notificationManager.notify(notificationId, builder.build());
|
||||
}
|
||||
|
||||
// TODO Get timeout
|
||||
/*
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
notificationTimeoutMilliSecs = prefs.getInt(getString(R.string.entry_timeout_key), 100000);
|
||||
*/
|
||||
|
||||
/*
|
||||
stopTask(cleanNotificationTimer);
|
||||
cleanNotificationTimer = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(notificationTimeoutMilliSecs);
|
||||
} catch (InterruptedException e) {
|
||||
cleanNotificationTimer = null;
|
||||
return;
|
||||
}
|
||||
notificationManager.cancel(notificationId);
|
||||
// Timeout
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
String keyboardTimeout = prefs.getString(getString(R.string.keyboard_entry_timeout_key),
|
||||
getString(R.string.timeout_default));
|
||||
try {
|
||||
notificationTimeoutMilliSecs = Long.parseLong(keyboardTimeout);
|
||||
} catch (NumberFormatException e) {
|
||||
notificationTimeoutMilliSecs = TimeoutHelper.DEFAULT_TIMEOUT;
|
||||
}
|
||||
});
|
||||
cleanNotificationTimer.start();
|
||||
*/
|
||||
|
||||
if (notificationTimeoutMilliSecs != TimeoutHelper.TIMEOUT_NEVER) {
|
||||
stopTask(cleanNotificationTimer);
|
||||
cleanNotificationTimer = new Thread(() -> {
|
||||
int maxPos = 100;
|
||||
long posDurationMills = notificationTimeoutMilliSecs / maxPos;
|
||||
for (int pos = maxPos; pos > 0; --pos) {
|
||||
builder.setProgress(maxPos, pos, false);
|
||||
notificationManager.notify(notificationId, builder.build());
|
||||
try {
|
||||
Thread.sleep(posDurationMills);
|
||||
} catch (InterruptedException e) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
try {
|
||||
pendingDeleteIntent.send();
|
||||
} catch (PendingIntent.CanceledException e) {
|
||||
Log.e(TAG, e.getLocalizedMessage());
|
||||
}
|
||||
});
|
||||
cleanNotificationTimer.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void stopTask(Thread task) {
|
||||
@@ -131,12 +145,19 @@ public class KeyboardEntryNotificationService extends Service {
|
||||
task.interrupt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
private void destroyKeyboardNotification() {
|
||||
stopTask(cleanNotificationTimer);
|
||||
cleanNotificationTimer = null;
|
||||
unregisterReceiver(lockBroadcastReceiver);
|
||||
pendingDeleteIntent.cancel();
|
||||
|
||||
notificationManager.cancel(notificationId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
|
||||
destroyKeyboardNotification();
|
||||
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@@ -143,8 +143,10 @@ public class MagikIME extends InputMethodService
|
||||
if (keyboard_entry != null)
|
||||
keyboardView.setKeyboard(keyboard_entry);
|
||||
} else {
|
||||
if (keyboard != null)
|
||||
if (keyboard != null) {
|
||||
dismissCustomKeys();
|
||||
keyboardView.setKeyboard(keyboard);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -192,7 +194,6 @@ public class MagikIME extends InputMethodService
|
||||
if (imeManager != null)
|
||||
imeManager.showInputMethodPicker();
|
||||
}
|
||||
// TODO Add a long press to choose the keyboard
|
||||
break;
|
||||
case KEY_CHANGE_KEYBOARD:
|
||||
InputMethodManager imeManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
|
||||
@@ -203,6 +204,7 @@ public class MagikIME extends InputMethodService
|
||||
// TODO Unlock key
|
||||
break;
|
||||
case KEY_ENTRY:
|
||||
deleteEntryKey(this);
|
||||
Intent intent = new Intent(this, EntryRetrieverActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(intent);
|
||||
@@ -285,8 +287,8 @@ public class MagikIME extends InputMethodService
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
unregisterReceiver(lockBroadcastReceiver);
|
||||
dismissCustomKeys();
|
||||
unregisterReceiver(lockBroadcastReceiver);
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
||||
@@ -31,8 +31,9 @@ public class TimeoutHelper {
|
||||
|
||||
private static final String TAG = "TimeoutHelper";
|
||||
|
||||
private static final long DEFAULT_TIMEOUT = 5 * 60 * 1000; // 5 minutes
|
||||
|
||||
public static final long DEFAULT_TIMEOUT = 5 * 60 * 1000; // 5 minutes
|
||||
public static final long TIMEOUT_NEVER = -1; // Infinite
|
||||
|
||||
public static void recordTime(Activity act) {
|
||||
// Record timeout time in case timeout service is killed
|
||||
long time = System.currentTimeMillis();
|
||||
@@ -56,9 +57,9 @@ public class TimeoutHelper {
|
||||
long cur_time = System.currentTimeMillis();
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(act);
|
||||
long timeout_start = prefs.getLong(act.getString(R.string.timeout_key), -1);
|
||||
long timeout_start = prefs.getLong(act.getString(R.string.timeout_key), TIMEOUT_NEVER);
|
||||
// The timeout never started
|
||||
if (timeout_start == -1) {
|
||||
if (timeout_start == TIMEOUT_NEVER) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -71,7 +72,7 @@ public class TimeoutHelper {
|
||||
}
|
||||
|
||||
// We are set to never timeout
|
||||
if (timeout == -1) {
|
||||
if (timeout == TIMEOUT_NEVER) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -144,7 +144,7 @@
|
||||
<bool name="allow_no_password_default" translatable="false">true</bool>
|
||||
<bool name="enable_read_only_default" translatable="false">false</bool>
|
||||
|
||||
<string name="app_timeout_default" translatable="false">300000</string>
|
||||
<string name="timeout_default" translatable="false">300000</string>
|
||||
<string name="clipboard_timeout_default" translatable="false">60000</string>
|
||||
|
||||
<string-array name="timeout_values">
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
android:entries="@array/timeout_options"
|
||||
android:entryValues="@array/timeout_values"
|
||||
android:dialogTitle="@string/app_timeout"
|
||||
android:defaultValue="@string/app_timeout_default"/>
|
||||
android:defaultValue="@string/timeout_default"/>
|
||||
<SwitchPreference
|
||||
android:key="@string/lock_database_screen_off_key"
|
||||
android:title="@string/lock_database_screen_off_title"
|
||||
|
||||
@@ -20,11 +20,14 @@
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<PreferenceCategory
|
||||
android:title="@string/keyboard_entry_category">
|
||||
<Preference
|
||||
<ListPreference
|
||||
android:key="@string/keyboard_entry_timeout_key"
|
||||
android:title="@string/keyboard_entry_timeout_title"
|
||||
android:summary="@string/keyboard_entry_timeout_summary"
|
||||
android:enabled="false"/>
|
||||
android:entries="@array/timeout_options"
|
||||
android:entryValues="@array/timeout_values"
|
||||
android:dialogTitle="@string/keyboard_entry_timeout_title"
|
||||
android:defaultValue="@string/timeout_default"/>
|
||||
<SwitchPreference
|
||||
android:key="@string/keyboard_notification_entry_key"
|
||||
android:title="@string/keyboard_notification_entry_title"
|
||||
@@ -37,6 +40,7 @@
|
||||
android:dependency="@string/keyboard_notification_entry_key"
|
||||
android:defaultValue="@bool/keyboard_notification_entry_clear_close_default"/>
|
||||
</PreferenceCategory>
|
||||
<!--
|
||||
<PreferenceCategory
|
||||
android:title="@string/keyboard_appearance_category">
|
||||
<Preference
|
||||
@@ -45,6 +49,7 @@
|
||||
android:summary="dark"
|
||||
android:enabled="false"/>
|
||||
</PreferenceCategory>
|
||||
-->
|
||||
<PreferenceCategory
|
||||
android:title="@string/keyboard_keys_category">
|
||||
<SwitchPreference
|
||||
|
||||
Reference in new issue
Block a user