The Element of the Day widget displays a different chemical element each day on the home screen. It cycles through all 118 elements in the periodic table based on the day of the year.
- Daily Element: Shows a different element each day (Day 1 = Hydrogen, Day 2 = Helium, etc.)
- Element Information: Displays:
- Element symbol (large, prominent)
- Element name (localized)
- Atomic number
- Scrollable description
- Interactive: Clicking the widget opens the app and navigates directly to the element's detail page
- Adaptive Design:
- Matches app theme with rounded corners
- Supports Material You design on Android 12+ with system accent colors
- Supports light/dark themes
ElementOfTheDayWidget.kt: Widget provider classlayout/element_of_the_day_widget.xml: Widget layout for Android <12layout-v31/element_of_the_day_widget.xml: Widget layout for Android 12+ with Material Youxml/element_of_the_day_widget_info.xml: Widget configuration
AndroidManifest.xml: Added widget receiver declarationMainActivity.kt: Added handler for widget intent to open specific elementstrings.xml: Added widget-related string resources
- Update Period: 24 hours (86400000 milliseconds)
- Minimum Size: 250dp x 180dp
- Target Size: 4 cells wide x 3 cells high
- Resize Mode: Both horizontal and vertical
The widget uses the day of year (1-365/366) to select an element:
val dayOfYear = Calendar.getInstance().get(Calendar.DAY_OF_YEAR)
val index = (dayOfYear - 1) % 118 // Cycles through all 118 elements
val elementKey = ELEMENT_KEYS[index]- Long-press on the home screen
- Select "Widgets"
- Find "Element of the Day" widget
- Drag and drop onto home screen
- The widget will automatically show today's element
- Click the widget to view detailed information about the element in the app
- Element data is loaded from localized JSON files using
ElementDataLoader - Widget updates are handled by the Android system based on the update period
- Coroutines are used for asynchronous data loading to avoid blocking the UI
- PendingIntent is properly configured for Android 12+ with immutable flag