Skip to content

Commit baff2df

Browse files
committed
Add option to hide status text on lockscreen
1 parent f36be26 commit baff2df

File tree

4 files changed

+42
-21
lines changed

4 files changed

+42
-21
lines changed

faceunlock/src/main/java/ax/nd/faceunlock/pref/PrefKeys.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ object PrefKeys {
66
const val EARLY_UNLOCK_HOOK = "early_unlock_hook"
77
const val REQUIRE_PIN_ON_BOOT = "require_pin_on_boot"
88
const val BYPASS_KEYGUARD = "bypass_keyguard"
9+
const val SHOW_STATUS_TEXT = "show_status_text"
910
}

faceunlock/src/main/java/ax/nd/faceunlock/pref/Prefs.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ class Prefs(context: Context) {
1313
val earlyUnlockHook = flowPrefs.getBoolean(PrefKeys.EARLY_UNLOCK_HOOK, false)
1414
val requirePinOnBoot = flowPrefs.getBoolean(PrefKeys.REQUIRE_PIN_ON_BOOT, false)
1515
val bypassKeyguard = flowPrefs.getBoolean(PrefKeys.BYPASS_KEYGUARD, true)
16+
val showStatusText = flowPrefs.getBoolean(PrefKeys.SHOW_STATUS_TEXT, true)
1617
}

faceunlock/src/main/java/ax/nd/faceunlock/service/LockscreenFaceAuthService.kt

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ class LockscreenFaceAuthService : AccessibilityService(), FaceAuthServiceCallbac
6262
private lateinit var serviceScope: CoroutineScope
6363
private lateinit var prefs: Prefs
6464

65+
private var showStatusText = true
66+
6567
override fun onCreate() {
6668
super.onCreate()
6769

@@ -89,6 +91,12 @@ class LockscreenFaceAuthService : AccessibilityService(), FaceAuthServiceCallbac
8991
} else {
9092
reconfigureUnlockHook()
9193
}
94+
95+
serviceScope.launch {
96+
prefs.showStatusText.asFlow().collect { showStatusText ->
97+
this@LockscreenFaceAuthService.showStatusText = showStatusText
98+
}
99+
}
92100
}
93101

94102
private fun setupRequirePinOnBootReceiver() {
@@ -198,9 +206,11 @@ class LockscreenFaceAuthService : AccessibilityService(), FaceAuthServiceCallbac
198206
if(Util.isFaceUnlockEnrolled(this)) {
199207
active = true
200208
// If animation is currently playing, we need to fire it's end listener
201-
textViewAnimator?.cancel()
202-
textView?.text = "Looking for face..."
203-
windowManager?.addView(textView, params)
209+
if(showStatusText) {
210+
textViewAnimator?.cancel()
211+
textView?.text = "Looking for face..."
212+
windowManager?.addView(textView, params)
213+
}
204214
startTime = System.currentTimeMillis()
205215
controller?.start()
206216
}
@@ -210,27 +220,31 @@ class LockscreenFaceAuthService : AccessibilityService(), FaceAuthServiceCallbac
210220
private fun hide(delay: Int = 0) {
211221
if(active) {
212222
active = false
213-
if(delay > 0) {
214-
// Delayed hide is animated
215-
textViewAnimator = textView?.animate()
216-
?.alpha(0f)
217-
?.setListener(object : Animator.AnimatorListener {
218-
override fun onAnimationStart(p0: Animator?) {}
219-
override fun onAnimationEnd(p0: Animator?) = onTextViewAnimationEnd()
220-
override fun onAnimationCancel(p0: Animator?) {}
221-
override fun onAnimationRepeat(p0: Animator?) {}
222-
})
223-
?.setStartDelay(delay.toLong())
224-
?.setDuration(300)
225-
textViewAnimator?.start()
226-
} else {
227-
removeTextViewFromWindowManager()
223+
if(showStatusText) {
224+
if (delay > 0) {
225+
// Delayed hide is animated
226+
textViewAnimator = textView?.animate()
227+
?.alpha(0f)
228+
?.setListener(object : Animator.AnimatorListener {
229+
override fun onAnimationStart(p0: Animator?) {}
230+
override fun onAnimationEnd(p0: Animator?) = onTextViewAnimationEnd()
231+
override fun onAnimationCancel(p0: Animator?) {}
232+
override fun onAnimationRepeat(p0: Animator?) {}
233+
})
234+
?.setStartDelay(delay.toLong())
235+
?.setDuration(300)
236+
textViewAnimator?.start()
237+
} else {
238+
removeTextViewFromWindowManager()
239+
}
228240
}
229241
controller?.stop()
230242
} else {
231-
if(delay == 0) {
232-
// If hide animation is running, skip it
233-
textViewAnimator?.cancel()
243+
if(showStatusText) {
244+
if (delay == 0) {
245+
// If hide animation is running, skip it
246+
textViewAnimator?.cancel()
247+
}
234248
}
235249
}
236250
}

faceunlock/src/main/res/xml/root_preferences.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,9 @@
2727
android:entryValues="@array/unlock_animation_values"
2828
android:key="unlock_animation"
2929
android:title="Lockscreen dismiss animation" />
30+
<SwitchPreference
31+
android:defaultValue="true"
32+
android:key="show_status_text"
33+
android:summary="Show face unlock status on lockscreen"
34+
android:title="Show status text" />
3035
</PreferenceScreen>

0 commit comments

Comments
 (0)