Features
- Single prayer focus showing only the next upcoming prayer
- Large, readable time display
- Live countdown updated every minute
- Minimal design for quick glances
- Tap to open the main app
Widget appearance
The widget displays a centered card with:- Label: “Next Prayer” in small text
- Prayer name: Large, bold text (e.g., “Dhuhr”)
- Prayer time: Extra large time display (e.g., “1:30 PM”)
- Countdown badge: Colored badge showing time remaining (e.g., “in 2h 30m”)
The Next Prayer widget is designed to be smaller than the Prayer Times widget, making it ideal for users with limited home screen space.
Adding the widget
Live countdown
The countdown timer shows time remaining until the next prayer and updates approximately every minute.Countdown format
The display format changes based on time remaining:- More than 1 hour: “in 3h 15m”
- 30-60 minutes: “in 45m 30s”
- Less than 30 minutes: “in 12m 42s”
- Less than 1 minute: “in 30s”
Implementation
The countdown uses the sharedWidgetUpdateScheduler:
Countdown badge
The countdown is displayed in a rounded badge with:- Background: Dimmed primary color (
R.color.widget_primary_dim) - Text: Primary accent color
- Border radius: 8dp for rounded appearance
- Padding: Comfortable spacing for readability
Implementation details
Widget class
The Next Prayer widget extendsGlanceAppWidget:
Widget state
The widget manages three states:Update mechanism
The widget uses two update mechanisms:Periodic data refresh
NextPrayerWorker fetches updated prayer data:
Minute-by-minute countdown
TheWidgetTickReceiver updates both Next Prayer and Prayer Times widgets:
Widget UI composition
The success state composable creates a centered layout:Styling
The widget uses a hierarchy of font sizes:- “Next Prayer” label: 11sp, medium weight, secondary color
- Prayer name: 20sp, bold, primary accent color
- Prayer time: 28sp, bold, primary text color
- Countdown: 12sp, bold, in colored badge
Theme colors
Android manifest registration
The widget is declared inAndroidManifest.xml:
Interaction
The entire widget is clickable and opensMainActivity:
- Full prayer schedule
- Prayer tracking
- Qibla direction
- Other app features
Edge cases handled
After Isha prayer
When Isha (the last prayer) has passed, the widget displays tomorrow’s Fajr prayer as the “next” prayer.Invalid data
If prayer times haven’t been calculated:- Widget shows “Tap to setup” message
- Clicking opens the app for initial configuration
- After setup, widget updates automatically
Midnight transition
The widget automatically updates when the day changes:- Worker recalculates prayer times
- Next prayer switches from last Isha to next Fajr
- Countdown resets for the new day
Battery efficiency
The widget is optimized for battery life:- Inexact repeating alarms: Uses
setInexactRepeating()which allows the system to batch updates - Efficient workers: Periodic updates only when widget is active
- No continuous processes: Only scheduled updates, no always-running services
- Shared scheduler: Both countdown widgets share the same
WidgetUpdateScheduler
Countdown updates may be slightly delayed by the system to save battery. This is normal Android behavior and typically results in updates within a few seconds of each minute.
Troubleshooting
Widget shows “Tap to setup”
This appears when prayer times aren’t available. Solution:- Open the Nimaz app
- Grant location permission
- Wait for prayer times to calculate
- Widget will update automatically
Countdown not updating
The countdown may stop updating if the scheduler is killed. Solution:- Check battery optimization settings
- Ensure Nimaz is not restricted
- Remove and re-add the widget
- Restart your device if needed
Shows wrong prayer
This can happen if prayer times are outdated. Solution:- Open the app to trigger recalculation
- Check your location is correct
- Verify time zone settings
- Wait for the next periodic update
Time format issues
The widget respects your app’s time format setting. Solution:- Open Nimaz app
- Go to Settings
- Change time format (12-hour/24-hour)
- Widget will update on next refresh
Comparison with Prayer Times widget
| Feature | Next Prayer | Prayer Times |
|---|---|---|
| Size | Small | Medium-Large |
| Prayers shown | 1 (next) | 5 (all) |
| Countdown | Yes | Yes |
| Location | No | Yes |
| Hijri date | No | Yes |
| Best for | Quick glance | Full schedule |
- Have limited home screen space
- Only need to know the upcoming prayer
- Prefer a minimal, focused design
- Want to see the full daily schedule
- Need location and Hijri date information
- Have more home screen space available
Related widgets
- Prayer times widget - Complete daily prayer schedule
- Prayer tracker widget - Track completed prayers
- Hijri date widget - Islamic calendar display