~/projects-hub/projects/rest-your-eyes
Rest Your Eyes icon
Active
Last updated:

Rest Your Eyes

Native Android application designed to prevent eye strain caused by prolonged mobile device usage.

MobileHealthAndroid
KotlinJetpack ComposeForeground ServicesBroadcast ReceiversJetpack DataStoreHabit AnalyticsMVVM

The Problem

Eye strain from prolonged, continuous mobile screen use, with no built-in way to track real screen-on time or receive proactive rest reminders — and Android 14+'s stricter background service restrictions make naive polling solutions unreliable.

The Solution

A native Android app that enforces the 20-20-20 rule by tracking real screen-on time via a Foreground Service and BroadcastReceivers (ACTION_SCREEN_ON/OFF), pausing automatically when the device is locked to avoid battery drain. It overlays a gentle SYSTEM_ALERT_WINDOW reminder with customizable alerts, declares the Android 14+ health foreground service type, and incorporates visual break adherence analytics with a 7-day rolling window and 180-day historical retention.

Key Learnings

  • Building an app capable of tracking real device usage (screen on/off time).
  • Visual Break Adherence Architecture & 180-Day Retention: Engineered StatsRepository backed by Jetpack DataStore featuring a dynamic 7-day rolling window to prevent artificial Monday morning resets and an atomic barrier against duplicate event logging.
  • Using Foreground Services and Broadcast Receivers in Android for background monitoring.
  • Implementing system-level overlay notifications (SYSTEM_ALERT_WINDOW) to proactively interact with the user.

Background Architecture & Screen Time Tracking

Rest Your Eyes enforces the 20-20-20 optical rule (rest eyes for 20 seconds every 20 minutes of continuous screen use) via a high-efficiency native Android background service:

  • Foreground Service & BroadcastReceivers: Real-time state tracking listening to ACTION_SCREEN_ON and ACTION_SCREEN_OFF events to aggregate only genuine active screen-on time.
  • Proactive Overlays (SYSTEM_ALERT_WINDOW): Renders a gentle, translucent Jetpack Compose overlay prompting eye relaxation without forcibly crashing active tasks.
  • Visual Adherence Analytics & Habit Tracking: Real-time tracking powered by StatsRepository over Jetpack DataStore calculating completed vs. skipped breaks across a rolling 7-day window and 180-day historical trend with empathetic microcopy.

Battery & Resource Optimization

  • Zero Battery Drain when Locked: The timer automatically pauses when the device is locked or asleep, avoiding CPU WakeLocks and preserving battery longevity.
  • Android 14+ Compliance (FOREGROUND_SERVICE_HEALTH): The Foreground Service explicitly declares the health service type, satisfying Android 14+’s stricter background process restrictions and preventing the OS from killing the monitor during active sessions.

This page is a high-level summary. The GitHub repository is the source of truth for each tool's current features. GitHub ↗

Back to Hub