Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions app/src/main/java/com/glowled/app/core/LedController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ object LedController {
main.postDelayed({ if (NotificationStore.remove(key)) onNotificationsChanged(false) }, 60_000)
}

private var pendingDropletColor: Int? = null
private var pendingDropletUntil = 0L

fun onNotificationsChanged(newPost: Boolean) = main.post {
if (newPost) {
suppressed = false
Expand All @@ -152,12 +155,24 @@ object LedController {
if (NotificationStore.isEmpty()) {
cancelPulse()
disarmMotion()
pendingDropletColor = null
} else if (newPost && !isInteractive() && prefs.aodOnNew) {
startAod(pulse = false)
}
updateOverlay()
if (newPost && prefs.droplet && isInteractive() && !aodVisible) {
NotificationStore.apps().firstOrNull()?.let { OverlayHost.droplet(it.color) }
val app = NotificationStore.apps().firstOrNull()
if (app != null) {
DebugLog.add("Droplet triggered for ${app.pkg}")
OverlayHost.droplet(app.color)
// If overlay wasn't ready (e.g. app in foreground), retry shortly when it appears.
pendingDropletColor = app.color
pendingDropletUntil = SystemClock.uptimeMillis() + 6000
} else {
DebugLog.add("Droplet skipped: no app")
}
} else if (newPost) {
DebugLog.add("Droplet skipped: droplet=${prefs.droplet} interactive=${isInteractive()} aod=$aodVisible")
}
}

Expand Down Expand Up @@ -549,11 +564,26 @@ object LedController {
fun updateOverlay() {
if (!initialized) return
val launching = SystemClock.uptimeMillis() < ourWakeUntil
val canShow = prefs.enabled && !aodVisible && !launching && !appInForeground && isInteractive() &&
(prefs.style.isEdge || CutoutGeometry.isPortrait(app))
val portrait = prefs.style.isEdge || CutoutGeometry.isPortrait(app)
val canShow = prefs.enabled && !aodVisible && !launching && !appInForeground && isInteractive() && portrait
val notifRing = prefs.overlayEnabled && !NotificationStore.isEmpty() && (!prefs.overlayLockOnly || isLocked())
overlayMeter = if (canShow) computeMeter(notifRing) else null
if (canShow && (notifRing || overlayMeter != null || prefs.batteryIndicator)) OverlayHost.show(app) else OverlayHost.hide()
val show = canShow && (notifRing || overlayMeter != null || prefs.batteryIndicator)
if (!show && isInteractive() && !isLocked() && !NotificationStore.isEmpty()) {
DebugLog.add("Overlay off: can=$canShow enabled=${prefs.enabled} aod=$aodVisible fg=$appInForeground portrait=$portrait oE=${prefs.overlayEnabled} lockOnly=${prefs.overlayLockOnly} meter=${overlayMeter != null} batt=${prefs.batteryIndicator}")
}
if (show) {
OverlayHost.show(app)
val pending = pendingDropletColor
if (pending != null && SystemClock.uptimeMillis() <= pendingDropletUntil) {
pendingDropletColor = null
main.postDelayed({ OverlayHost.droplet(pending) }, 150)
} else if (pending != null) {
pendingDropletColor = null
}
} else {
OverlayHost.hide()
}
}

// ---- charging ring and transfer ring (both views) ----------------------------------------------
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/com/glowled/app/core/Prefs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ class Prefs(context: Context) {
val showContent get() = bool("show_content", true)
/** Liquid droplet from the camera when a notification arrives. */
val droplet get() = bool("droplet", true)
/** Droplet size (radius) in dp for the camera droplet animation. */
val dropletSizeDp get() = int("droplet_size", 10).coerceIn(4, 28)
/** App icon size in dp in the notification icon row (screen-on / AOD). */
val appIconDp get() = int("app_icon_size", 36).coerceIn(24, 72)
/** Reply / Mark as read buttons on the message peek. */
val peekActions get() = bool("peek_actions", true)
/** Always-on icons as monochrome glyphs (One UI AOD style) instead of full-colour app icons. */
Expand All @@ -79,6 +83,13 @@ class Prefs(context: Context) {
// Screen-on overlay
val overlayEnabled get() = bool("overlay_enabled", true)
val overlayLockOnly get() = bool("overlay_lock_only", false)
/** Tap the ring on the unlocked screen to expand app icons and read messages. */
val onTapMessages get() = bool("overlay_tap_messages", true)
// Screen-on tap response zone (collapsed ring). Offsets/sizes in dp; 0 width/height = automatic.
val tapZoneOffsetXDp get() = int("tap_zone_dx", 0).coerceIn(-300, 300)
val tapZoneOffsetYDp get() = int("tap_zone_dy", 0).coerceIn(-300, 500)
val tapZoneWidthDp get() = int("tap_zone_w", 0).coerceIn(0, 500)
val tapZoneHeightDp get() = int("tap_zone_h", 0).coerceIn(0, 800)

// Charging and download rings (screen on, also over the lock screen)
/**
Expand Down
54 changes: 44 additions & 10 deletions app/src/main/java/com/glowled/app/service/OverlayHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import com.glowled.app.view.LedView
* Screen-on indicator window. Over apps it is a "display over other apps" window, which apps that
* guard against overlays (banking, payments) can hide; the accessibility overlay is only used on
* the lock screen, or when there is no overlay permission.
* The window is sized tightly around the camera so the compositor has almost nothing to blend.
* The passive window is sized tightly around the camera; the interactive message view uses its own window.
*/
object OverlayHost {

Expand All @@ -27,15 +27,26 @@ object OverlayHost {
private var usingA11y = false
private val listener: () -> Unit = { refresh() }

private fun shouldUseInteractive(): Boolean = ScreenOnOverlay.shouldBeInteractive()

fun show(context: Context) {
if (shouldUseInteractive()) {
hidePassive()
if (ScreenOnOverlay.isShowing()) ScreenOnOverlay.refresh() else ScreenOnOverlay.show(context)
if (ScreenOnOverlay.isShowing()) return
com.glowled.app.core.DebugLog.add("Screen-on interactive unavailable, using passive")
// Interactive failed to show; fall back to passive so the ring still appears.
} else {
if (ScreenOnOverlay.isShowing()) ScreenOnOverlay.hide()
}
val a11y = LedAccessibilityService.instance?.takeIf {
!Settings.canDrawOverlays(context) || LedController.isLocked()
}
if (view != null && usingA11y == (a11y != null)) {
refresh()
return
}
hide()
hidePassive()
val ctx: Context
val type: Int
if (a11y != null) {
Expand Down Expand Up @@ -71,6 +82,7 @@ object OverlayHost {
val m = LedController.overlayMeter
v.setMeter(m?.fraction, m?.color ?: 0, m?.icon ?: MeterIcon.NONE, m?.indeterminate ?: false)
v.setBattery(LedController.batteryPercent())
v.dropletRadiusDp = prefs.dropletSizeDp.toFloat()
val flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE or
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN or
Expand Down Expand Up @@ -109,7 +121,19 @@ object OverlayHost {

/** Re-applies settings, colours and the gauge; repositions the window if geometry or style changed. */
fun refresh() {
val v = view ?: return
if (shouldUseInteractive()) {
hidePassive()
if (ScreenOnOverlay.isShowing()) ScreenOnOverlay.refresh() else ScreenOnOverlay.show(LedController.app)
if (ScreenOnOverlay.isShowing()) return
// fell back to passive below if interactive couldn't be shown
} else if (ScreenOnOverlay.isShowing()) {
ScreenOnOverlay.hide()
}
val v = view ?: run {
// No passive view yet (e.g. after interactive fallback) - let show() create it.
runCatching { LedController.app }.getOrNull()?.let { show(it) }
return
}
val manager = wm ?: return
val type = (v.layoutParams as? WindowManager.LayoutParams)?.type ?: return
val old = v.layoutParams as? WindowManager.LayoutParams ?: return
Expand All @@ -125,22 +149,32 @@ object OverlayHost {

/** New notification while the screen is on: a drop stretches out of the camera and springs back. */
fun droplet(color: Int) {
val v = view ?: return
if (ScreenOnOverlay.isShowing()) {
ScreenOnOverlay.droplet(color)
return
}
val v = view ?: run {
com.glowled.app.core.DebugLog.add("Droplet skipped: no overlay")
return
}
com.glowled.app.core.DebugLog.add("Droplet on passive ring")
// Post: the window may have just been added and not laid out yet.
v.post { v.playDropletBelow(color, DROP_DP * v.resources.displayMetrics.density, retract = true) }
}

private const val DROP_DP = 26f

fun hide() {
private fun hidePassive() {
val v = view ?: return
LedController.removeListener(listener)
try { LedController.removeListener(listener) } catch (_: Exception) {}
v.visibility = View.GONE
try {
wm?.removeViewImmediate(v)
} catch (_: Exception) {
}
try { wm?.removeViewImmediate(v) } catch (_: Exception) {}
view = null
wm = null
}

fun hide() {
hidePassive()
if (ScreenOnOverlay.isShowing()) ScreenOnOverlay.hide()
}
}
Loading
Loading