Pen calculator: the whole brief
The brief from which an AI builds an injection pen calculator, in full and ready to copy. What I publish and what not, what the app does and does not do, and how it differs from the app on my phone.
Warning. The app from this brief is only a calculator: it works only with the numbers the user enters. Counting clicks is not part of the pen’s instructions. A doctor or pharmacist has to confirm the pen values and every conversion before use. The app is not a medical device. This article is not a guide to adjusting the amount of a medicine; treatment decisions are made by a doctor. Software that converts a medicine amount and is given to other people can fall under the rules for medical devices. That is why I do not publish the app or the APK. Anyone who builds the app from this brief does so at their own risk and only for themselves.
What I publish and what I do not
I publish the brief. It is below in full. I do not give the app, the APK or the code to anyone; why is in part six. An app I give to others is a product I am responsible for, and it can fall under the rules for medical devices. From the brief, everyone builds for themselves, on their own and at their own risk.
What applies to the brief:
- The medicine, the active substance, the pen and the maker are not named anywhere, not even in the brief.
- The brief contains no values of any real pen. The user enters the strength, the volume, the number of clicks and the in-use period, and a doctor or pharmacist has to confirm them. All numbers in the examples and tests are made up.
- Neither the text nor the brief says what amount anyone should set.
How the brief came about
The app on my phone was not built from this brief. It was built in October, step by step in a conversation with the AI, as parts 1 to 6 describe. I wrote this brief afterwards, with the help of AI, from the finished app. It has no name of a medicine or pen, no values of a real pen, and the examples in it are made up.
I checked by a build that an app really comes out of it. An AI (Claude Code) got only the Slovak brief and built the app in one run. How it went, what was checked and what was not, is in part thirteen.
Honest note: the English brief below has not been tested by a build. The build used the Slovak brief, which is in the Slovak version of this article. The English brief has the same features, limits, made-up values and definition of done, but the interface defaults to English, Slovak is the second language, and folders, commands and code identifiers are in English.
What the app does
Five tabs and Settings:
- Calculator: from the pen values the user enters, it converts an amount in mg into a volume in ml and a number of clicks. When the amount does not land on a whole click, it shows the two nearest options and picks neither. A “How it is calculated” button shows the calculation with the numbers filled in.
- Pens: several open pens at once, an active pen, the pen’s status (open, used up, discarded) and the prescribed amount, which the user enters as their doctor set it.
- Home: what is left in the active pen, a drawing of the pen with a scale and a plunger, and the nearest dates.
- History: logged administrations with the date, an optional injection site and a note. An entry can be edited and deleted, and a deletion can be undone.
- Schedule: the next administration by the interval the user entered, when the pen will no longer hold the full prescribed amount, the end of the in-use period after opening and by when to buy a new pen.
- Settings: the notice, reminders (administration, end of the in-use period, buying, also after a phone restart), export of a backup and of the log, restore from a backup and deleting everything.
The texts are in English and Slovak, following the phone’s language.
What the app does not do
- It recommends, changes and suggests nothing: not the amount, not the interval, not the way of administration. The app has no “your dose”, only the prescribed amount the user enters.
- It has no database of medicines or pens and no prefilled values. For a new pen the value fields are empty.
- It never rounds a partial click on its own, not even “to the safer side”.
- It does not preselect the injection site. It only marks where the last one was.
- Input checks only say that the entered values should be checked. They block nothing and give no advice.
- It has no internet permission, no accounts, no analytics and no cloud backup. Data leaves the phone only through an export the user makes.
- It is not meant for an app store. It is installed from your own computer.
How the brief differs from the app on my phone
The features are the same as in version 0.5 from part five. Some things are deliberately different in the brief:
- No pen presets. The app on my phone has a choice of pen type with prefilled values, a default interval and, for one pen type, a name tied to the strength. The brief has none of that: the pen values are required and empty for a new pen, and the interval is optional with no default. The prefilled amount comes from a pen with the same entered values, not from a pen of the same type.
- A longer notice in three places, including the Calculator tab. On my phone it is shorter.
- Lessons that came later. Checks return an error code and the texts are in the translation file; on my phone the Slovak sentences are right in the code. The app is bilingual. An error in the pen form is shown at the field. The data is also excluded from device-to-device transfer. Before a restore from backup, a copy of the current data is saved, and a restore accepts only a complete backup file. The install command never uninstalls the app.
- End of the in-use period instead of “expiry after opening”, so it is not confused with the expiry date on the package.
- Two things left out: the calendar in the history, which I never built, and the test notification button, which I removed in version 0.4.
What you need
- A Mac with Android Studio installed: the Android SDK, the emulator and at least one virtual device (created in Android Studio’s Device Manager).
- Claude Code in the terminal.
The brief is written for a Mac and Android. For an iPhone it would be different code.
How to use the brief
- Copy the whole block below.
- In part 0, check the line with the project folder. By default it is
~/projects/pen-calculator. It is the only place that needs changing. - Paste the brief into Claude Code as one message.
The AI then works on its own and asks nothing. Claude Code may still ask for permission to run commands (Gradle, adb, the emulator, downloads). Without an answer the build stops.
The brief forbids the AI to use a physical phone. It checks the app only on the emulator. A person installs it on a phone themselves.
There is no app code or APK to download here.
The brief
Once more before you copy. The app is only a calculator working with the numbers the user enters. Counting clicks is not part of the pen’s instructions. A doctor or pharmacist has to confirm the pen values and every conversion. The app is not a medical device. This article is not a guide to adjusting the amount of a medicine; treatment decisions are made by a doctor. Software that converts a medicine amount and is given to other people can fall under the rules for medical devices, which is why I do not publish the app or the APK. Anyone who builds it from this brief does so at their own risk and only for themselves.
# Task for the AI: "Pen calculator" app for Android
## 0. Project folder (FILL IN YOURS HERE)
>>> PROJECT FOLDER: ~/projects/pen-calculator <<<
This is the only line to check before you start. If you want the project elsewhere, change only the path on it.
All paths below are relative to this folder. If it does not exist, create it. If it exists and is not empty,
delete nothing in it and work only in the subfolders code/ and notes/.
## 1. Goal
At the end there is a native Android app "Pen calculator" that builds with a single command, passes its tests and
runs on the emulator. From the values of a multi-dose injection pen that the user enters, it converts an amount
in mg into a volume in ml and a number of clicks, keeps a log of administrations, shows and draws what is left
in the pen, builds a schedule from the interval the user entered, and reminds the user of the next administration,
of the end of the pen's in-use period and of buying a new pen.
## 2. Context
- One person uses the app on their own Android phone. The pen contains a medicine prescribed by their doctor.
The user knows the prescribed amount, the interval and the pen values from the doctor, from the pen and from
the package leaflet, and enters them into the app themselves. The app is only a calculator: it does basic
arithmetic and suggests nothing.
- They install it from their own computer over adb, not from an app store. There are no accounts, no server and
no sync.
- The person giving this task is not an Android developer. Everything a human has to do is one command
of start.sh, and messages are understandable for them.
- The computer is a Mac with Android Studio installed (Android SDK, emulator, at least one virtual device).
Find out everything else yourself (part 5).
- Work on your own from start to finish and do not ask questions. Where this task says nothing, decide sensibly
and write the decision with its reason into the build log (part 8). The only exception is "When to stop"
in part 8.
- All numbers in this task (pen strength, volumes, clicks, days) are made up to test the calculation. They do not
match any real pen or medicine, and the app must not have them prefilled.
## 3. What the app does
One activity, Jetpack Compose, Material 3. Bottom navigation with five tabs: Home, Convert, Pens, History,
Schedule. Settings open from a gear icon in the top bar; in Settings the top bar has a back arrow and the bottom
navigation is hidden. The system Back button closes an open form, dialog or Settings without saving.
Notice (the same text in three places: on first launch, in Settings and on the Convert tab)
- Title "Before you start", text (strings.xml, notice_text):
"Pen calculator is only a calculator: from the values you enter it converts an amount into volume and number
of clicks. It suggests nothing and does not change the amount, interval or way of administration; your doctor
decides that.
Counting clicks is not part of the pen's instructions for use. Have your doctor or pharmacist confirm the pen
values and every conversion before you use them.
The app is not a medical device and does not replace a professional."
- On first launch it is a dialog that cannot be closed by tapping outside or with system Back, only with the button
"I understand". Until the user confirms it, the app shows nothing else. The confirmation is saved
(noticeAccepted).
- In Settings the full text is on a card at the top, on Convert the full text is below the result. On Home there is
one short sentence at the bottom: "Only a calculator. Your doctor or pharmacist confirms the pen values and the
conversion."
Pens
- List of pens, open pens first, then used up and discarded. Pen card: colored circle, name, "Left X ml = Y mg",
a line about the technical reserve (if there is anything to show), "Opened DD.MM.YYYY, use for N more days"
(once over, in red "in-use period is over"), a label "used up" or "discarded" for pens that are not open.
The active pen has a highlighted border; tapping an open pen makes it active.
- Pen menu (three dots on the card): Edit; Open a new pen with the same values (copy with a new id, opened now,
becomes active); Mark as used up; Mark as discarded (for a pen that is not open: Return to open pens); Delete.
Delete opens a confirmation dialog "Delete <name>?" saying that all administration records of this pen are deleted
too and that an empty pen is better marked as used up; buttons Delete and Keep.
- The + button bottom right opens the new pen form. An empty list shows one sentence on how to add the first pen.
- Pen form (new and edit, scrollable):
- Name (an empty name is saved as "Pen").
- Pen values, all required and **empty for a new pen**, no default values and no picking from a list:
pen strength (mg of active substance in one marked dose of the pen), volume of one marked dose (ml), number of
clicks per marked dose (whole number), usable volume of the whole pen (ml), how many days the pen may be used
after opening (whole number). Below them the helper text "Copy them from the pen and the package leaflet.
Have your doctor or pharmacist confirm them."
- Waste per administration (ml, default 0, for example priming the needle) and technical reserve (ml, optional,
text "your estimate of what is left in the pen beyond the usable volume; the app cannot check it").
- Opened: date and time (now by default), picked from a calendar and then a clock.
- Prescribed amount (mg), optional, text "You enter it as your doctor prescribed; the app only converts it."
- When editing an existing pen and the strength changes: a red sentence that click conversion and the amount
left in mg will use the new strength, and that strength is the substance in the whole marked dose, not the
amount per administration.
- Below the values, live input checks from part 4 (notices), if any apply.
- Section "Schedule and reminders": interval between administrations in days (optional, text "as your doctor
prescribed"), reminder time (default 09:00, time picker, 24 h), switch Remind me of administration by interval
(can be switched on only when an interval is entered), switch Remind me of the end of the in-use period and
the field "how many days before" (default 3), switch Remind me to buy a new pen and the field "how many days
before" (default 7, text "counted from the earlier of the two dates: the pen runs out or its in-use period
ends"). Switching on any reminder on Android 13 and newer asks for the notification permission if the app
does not have it.
- Pen color: 12 colors to choose from in circles and a slider "custom hue" (HSV, saturation 0.6, value 0.7) with
a preview.
- Cancel and Save. An input error is shown right at the field and the pen is not saved.
- The first saved pen becomes active. If the active pen is no longer open (used up, discarded, deleted), the first
open pen becomes active, otherwise none.
Convert
- At the top the pen choice: chips of the open pens and a chip "Enter manually". The active pen is selected by
default; when the active pen changes, the selection returns to it.
- Fields: pen strength, volume of one marked dose, clicks per marked dose (prefilled from the selected pen, empty
when entering manually) and the requested amount in mg with the text "The amount your doctor prescribed."
The requested amount is prefilled by the rule defaultUg from part 4 and the text says so ("Prefilled from the
pen's prescribed amount." or "Prefilled from the last administration.").
- If the values on screen differ from the saved pen, a red sentence: "The values differ from the saved pen.
The conversion and the record use the values on this screen."
- Result:
- nothing filled in: "Fill in the pen strength, dose volume, number of clicks and the requested amount.";
- error: the error text in red;
- exact: a large card "6 clicks" and below "= 0.18 ml = 3 mg";
- partial click: a red sentence "The amount does not come out as a whole click. The app does not round on its
own, choose one of the options:" and two cards side by side (lower and higher option: clicks, ml, mg).
Neither is selected in advance; only a tap marks one, and below them a large card with the chosen option
appears. Changing any field clears the choice.
- Below the result the notices (input checks) in red.
- A button "How it is calculated" expands the calculation with the numbers filled in: concentration = strength /
dose volume, volume per click = dose volume / clicks per dose, clicks = requested mg × clicks per dose /
strength, and the sentence "Numbers shown are rounded to thousandths, the number of clicks is exact."
- If a saved pen is selected and the result is exact or chosen: a button "Record administration" (opens the record
dialog) and a button "Save as prescribed amount for this pen" (saves the mg of the chosen option into the pen,
bar "Saved as prescribed amount for <name>.").
- Below that the full notice text.
Administration record dialog (from Convert, from Home, and for editing from History)
- Title "Record administration" or "Edit record".
- If an earlier administration exists (from any pen): a card "Last administration" with date and time,
"N d M h ago", amount in mg, pen name (or "deleted pen") and the injection site in bold ("Site not recorded"
if missing).
- Pen name and in large type "6 clicks = 0.18 ml = 3 mg" (without clicks for an administration from the reserve).
- When: date and time (now by default), picked as date and then time.
- Injection site (optional): chips abdomen left, abdomen right, thigh left, thigh right, upper arm left,
upper arm right. **None is selected in advance.** The site of the last administration is marked "(last time)".
A second tap clears the choice.
- Note (optional).
- If the administration (volume + waste) does not fit into what is left in the pen: a sentence "According to the
volume entered, X ml is left in the pen, this administration needs Y ml.", a switch "Administration from the pen's
technical reserve", if a reserve estimate is entered also a sentence on how much of it is left by the estimate
(in red if the administration is larger), and in small type "The app does not know how much reserve is really
in the pen; it only records the amount entered, clicks are not counted." Without the switch on, the Confirm
button is disabled.
- Cancel and Confirm. After saving a bar "Administration recorded."
Home
- Without an open pen: the sentence "You have no open pen yet." and a button "Add pen" (opens the new pen form on
the Pens tab).
- Otherwise: if several pens are open, chips to switch the active pen (with a colored dot); pen name; pen drawing;
"Left X ml = Y mg"; the reserve line if there is anything to show; if a prescribed amount is entered,
"Enough for N more administrations of 3 mg."
- Three info cards: "Next administration by interval" (date, time and "in 2 d 3 h", or "Record the first
administration from this pen.", or "No interval entered."), "Use until" (date and "in N days" or "over")
and "Buy a new pen by" (date). A card uses the error color when the next administration or the buy date is in
the past and when the days left in the in-use period are equal to or fewer than the "days before" setting.
- Large button: if the pen has a default amount and it comes out as a whole click, "Record administration 3 mg"
opens the record dialog; otherwise "Convert and record" switches to Convert.
- Relative time on screen ("in 2 d 3 h") refreshes every 30 seconds.
Pen drawing (own Canvas, about 88 dp high, full width)
- The pen from the side: button on the left, dial with grooves, body in the pen color, a window with a scale
(a tick every 0.1 ml, every fifth longer, at most 60 ticks), liquid in the window (a lighter pen color) and
a plunger that moves towards the tip by the share of what is left in the usable volume, tip on the right.
A change of the amount left is animated (about 900 ms).
- Description for screen readers: "Pen, X of Y ml left".
History
- Chips "All pens" and each pen (filter). List of administrations, newest on top, with month headings
("November 2026").
- Row: the pen's colored dot, date and time, "<pen>: 3 mg, 6 clicks, 0.18 ml" (for an administration from the
reserve "from reserve" instead of clicks), site and note in small type. A trash icon on the right.
- Tapping a row opens the record dialog for editing (time, site, note, reserve flag; the amount does not change).
If the edit cannot be saved, a bar says why.
- The trash icon deletes the record at once and shows a bar "Record deleted." with an "Undo" button that brings it
back (longer bar duration, no confirmation dialog).
- Empty list: "No administrations recorded yet."
Schedule
- A card for each open pen: colored dot and name, then events sorted by date: Last administration; Next
administration by interval; Pen will no longer hold the full prescribed amount; End of in-use period after
opening; Buy a new pen by. Date in bold, for future ones "in N d M h", past dates (except the last
administration) in red.
- Below the events depending on the situation: "Enter the prescribed amount in the pen, otherwise it cannot be
estimated when the pen runs out.", or "At 3 mg enough for N administrations, interval 5 days."; "The next
administration appears after the first record."; "No interval entered, the next administration is not
calculated."
- Without an open pen: "No open pen."
Settings
- Card "Notice" with the full text.
- Reminders: whether notifications are allowed ("Notifications are allowed." or "Notifications are off, reminders
will not show."), a button Allow notifications (Android 13+, when not allowed), a button Notification settings
(the app's system notification settings), the list of scheduled reminders (date, time, title) or a sentence on
where to switch them on (Pens, pen menu, Edit, Schedule and reminders). A sentence "Some phones restrict
background alarms of apps. If reminders are late, set the app's battery usage to Unrestricted." and a button
Battery optimization (Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS, no extra permission).
- Backup: a sentence "Data stays only on this phone, with no account, no internet and no cloud backup. Make your
backup with export."; Export backup (JSON, suggested name pen-calculator-YYYY-MM-DD.json); Export records (CSV,
pen-calculator-records-YYYY-MM-DD.csv); Restore from backup (OpenDocument, the app shows "The backup has N pens
and M records. Current data will be replaced." and after confirmation replaces everything; before that it saves
the current data to the internal file before-import.json; an unreadable or invalid file changes nothing and the
app shows a clear error). Export and import through the system dialog (Storage Access Framework), no storage
permissions.
- Data: a button "Delete all data" in the error color, a confirmation dialog ("All pens and records will be
deleted. Without a backup this cannot be undone."), buttons Delete and Keep. The notice stays confirmed.
- At the bottom "Version 1.0" (versionName).
Reminders (notifications)
- For each open pen with the matching switch on, only times in the future:
- administration: at the time of the next administration; title "Administration: <pen>", text with the
conversion of the prescribed amount ("3 mg = 6 clicks = 0.18 ml"), for a partial click only "Prescribed
amount 3 mg", without a prescribed amount "By your interval it is time for the next administration.";
- end of in-use period: N days before the end, at the reminder time; "End of in-use period: <pen>",
"The pen may be used until DD.MM.YYYY.";
- buying: on the "buy by" day, at the reminder time; "Buy a new pen", "<pen> lasts until DD.MM.YYYY."
- Tapping the notification opens the app. One channel "Reminders" with high importance.
- After every data change all of the app's alarms are cancelled and scheduled again (the app keeps the codes of
scheduled alarms in SharedPreferences so it can cancel them). After a phone restart and after an app update,
a receiver for BOOT_COMPLETED and MY_PACKAGE_REPLACED schedules them again.
- Exact alarms: AlarmManager.setExactAndAllowWhileIdle; if the app may not schedule exact alarms
(canScheduleExactAlarms returns false), it uses setAndAllowWhileIdle. Without the notification permission no
notification is shown and the app does not crash.
Look
- The theme's primary color follows the active pen's color (without a pen the first palette color). Light and dark
scheme by system setting, no dynamic colors. Choose text color on colored backgrounds (white or black) and the
primary color against the background so the contrast is at least 4.5 : 1 (WCAG AA); if it is not, move the
color towards black (light scheme) or white (dark scheme) until it is.
- Palette of 12 colors (ARGB): FF5E35B1, FF00897B, FF1E88E5, FFD81B60, FFF4511E, FF6D4C41, FF43A047, FF546E7A,
FF8E24AA, FF00ACC1, FF9E9D24, FFFFB300.
- App icon: a simple vector adaptive icon in neutral colors, an equals sign (=) or a simple calculator. No pen,
needle, drop, medicine or logo. Small notification icon: a single-color vector (a bell).
- Tab icons only from the core set (material-icons-core): Home, Edit, List, DateRange, Notifications, Settings.
Language: all texts in res/values/strings.xml in English (source) and in res/values-sk/strings.xml in Slovak,
no hardcoded text in code. Number-dependent forms (1 click, 2 clicks; in Slovak 1 klik, 2 kliky, 5 klikov) via
<plurals>. The app follows the system language and has android:localeConfig (en, sk). App name: "Pen calculator"
(en), "Kalkulačka pera" (sk). Decimal point or comma, date and time according to language, 24-hour time.
## 4. Data and calculations
Units and rounding
- The amount of substance is calculated in whole micrograms (ug), volume in whole microlitres (ul), as Long.
Decimals exist only on screen. The number of clicks is always a whole number and is exact.
- Input: accept both a decimal point and a comma, ignore spaces, at most 3 decimals (mg and ml). More decimals is
an input error, not silent rounding. Text to thousandths: "3.5" and "3,5" are 3500; "abc", empty text and
"1.2345" are not a number.
- Display: mg without trailing zeros, at most 3 decimals (3000 is "3", 3500 is "3.5", 667 is "0.667"); ml at least
2 and at most 3 decimals (180 is "0.18", 2700 is "2.70", 233 is "0.233").
- Integer division rounded to the nearest whole number (half up): (2 × numerator + denominator) /
(2 × denominator).
Conversion (formula from the values the user entered)
- The pen has strength S (ug of substance in one marked dose), marked dose volume V (ul) and K clicks per marked
dose.
- For a requested amount M (ug): clicks = M × K / S.
- If the division has no remainder: result Exact(option).
- If not and the whole part is 0: error "less than one click" (with the amount of one click in mg).
- Otherwise: Between(lower, higher), the whole part and the whole part + 1. **Never chosen automatically.**
- Option for n clicks: ul = round(n × V / K), ug = round(n × S / K).
- Concentration in thousandths of mg/ml = round(S × 1000 / V); volume of one click in ul = round(V / K).
- The pen check returns an error code if S, V or K is not greater than 0; a requested amount of 0 or less is an
error.
- Notices (input checks, they block nothing and are not advice), as a list of codes: requested amount is larger
than one marked dose of the pen ("Check the values entered."); clicks per dose outside 5 to 200 ("unusual,
check it on the pen"); dose volume above 3 ml; usable pen volume smaller than one marked dose.
Supply and technical reserve
- Used from a pen = sum of (record ul + pen waste) over all records of the pen. Left = usable volume − used,
at least 0. Left in mg = round(ul × S / V).
- How many more times amount M can be given: one administration needs the ul for M rounded up
(M × V + S − 1) / S plus waste; count = left / that (integer).
- Record check: if (ul + waste) > what is left in the pen (without the record being edited, when editing), it
returns an error with both numbers; a record marked as from the reserve always passes. A missing pen is an error.
- Taken from the reserve = used − usable volume, at least 0. If the user entered a reserve estimate (> 0), left of
it = estimate − taken, at least 0; otherwise null. The app claims nothing about the reserve, it only subtracts the
recorded administrations.
- Reserve sentence for Home and Pens (built by the UI from strings.xml): taken and left (if there is an estimate),
only taken (no estimate), only the estimate (nothing taken yet), or nothing.
Schedule (all dates via java.time in the phone's time zone, days added by calendar, not as 24 hours)
- Last administration = the latest record of the pen.
- Next administration = day of the last administration + interval days, at the reminder time. Without a record or
without an interval null.
- How many administrations of the prescribed amount are left (from the supply); without a prescribed amount null.
- Pen will no longer hold the full prescribed amount = next administration + (administrations left × interval)
days; if anything is missing, null.
- End of in-use period = opened + in-use days (at the time of opening).
- Runs out = the earlier of "no longer holds the full prescribed amount" and "end of in-use period".
- Buy by = runs out − days before for buying.
- Alarms: a pure function list(state, now, zone) returns a list of (code, time, kind: ADMINISTRATION, END, BUY,
pen id) only for open pens, switched-on reminders and times in the future. End: (end of in-use period − days
before) at the reminder time; buy: the "buy by" day at the reminder time. Alarm code: (hashCode of pen id and
0x0FFFFFFF) × 4 + 0, 1 or 2. The notification text is built by the Android part from strings.xml.
Prefilled amount (defaultUg) and last administration
- Default amount for a pen: the pen's prescribed amount; if there is none, the amount of the last administration
from this pen; if none either, from the last administration from another pen with the same strength, dose
volume and clicks; otherwise null. The app suggests nothing by this, it only returns what the user entered
earlier.
- Last administration before a given record: the latest other record with an earlier time, from any pen.
Data model (kotlinx.serialization), file state.json in the app's internal storage (filesDir)
- State(version = 1, pens, records, activePenId: String?, noticeAccepted = false)
- Pen(id: String (UUID), name, strengthUg, doseUl, clicksPerDose, volumeUl, wasteUl = 0, reserveUl = 0 (0 = not
entered), openedMs, inUseDays: Int, color: Long (ARGB), status: PenStatus = OPEN, prescribedUg: Long? = null,
intervalDays: Int? = null, reminderTimeMin: Int = 540, remindAdministration = false, remindEnd = false,
endDaysBefore = 3, remindBuy = false, buyDaysBefore = 7)
- PenStatus = OPEN, USED_UP, DISCARDED
- Record(id: String (UUID), penId, timeMs, ug, clicks, ul, site: InjectionSite? = null, note = "",
fromReserve = false)
- InjectionSite = ABDOMEN_L, ABDOMEN_R, THIGH_L, THIGH_R, ARM_L, ARM_R (labels only in strings.xml)
- Pen values (strengthUg, doseUl, clicksPerDose, volumeUl, inUseDays) have no default value, neither in the model
nor in the form. Every field added in a future version must have a default value and JSON is read with
ignoreUnknownKeys, so a newer app version can read an older file.
Logic and checks
- All logic lives in pure functions in the package model with no Android dependency: number parsing and
formatting, conversion, checks and notices, supply and reserve, schedule, alarm list, default amount, last
administration, the pen form check (from the field texts it returns either a Pen or a list of field and error
code pairs), JSON and CSV export and import.
- **Checks return an error code (enum or sealed class with numbers), never text.** The text for a code belongs in
strings.xml and the UI builds it. Tests compare codes and numbers, not texts.
- CSV for spreadsheets: semicolon separator, header date;time;pen;mg;clicks;ml;site;note;from_reserve, records
oldest first, date DD.MM.YYYY, time HH:mm, decimals according to language; a field containing a semicolon, quote
or line break in quotes, quotes doubled. The function takes the zone, the decimal separator and the site labels
as parameters so it can be tested.
- Import requires the fields version, pens and records in the JSON (otherwise any JSON object would look like an
empty backup thanks to default values and wipe everything) and rejects a higher version than the app knows.
The result is Ok(state) or Error(reason: UNREADABLE, INVALID, NEWER_VERSION).
- Storage (data/Storage.kt) works with java.io.File, not with Context, so it can be tested on the JVM. Writes go to
a .tmp file which is then renamed. An unreadable file is never overwritten: it is moved aside as
state-corrupted-<time>.json and the app starts empty (with the notice not yet confirmed). Time can be injected
for the test.
- One ViewModel holds the state as an immutable object in a StateFlow. Every change: a new State, the active pen
fixed up, saved (off the main thread, in the order changes were made) and alarms scheduled again.
Tests (JUnit 4 on the JVM, app/src/test/), made-up values only
- Test pen A: strength 8 mg, marked dose volume 0.48 ml, 16 clicks per dose, usable volume 2.88 ml, waste 0,
in-use period 21 days, interval 5 days, reminder time 09:00, buy 4 days before, end 3 days before.
Test pen B: strength 9 mg, dose volume 0.70 ml, 21 clicks. These numbers are made up and match no pen.
- Conversion (pen A): 3 mg = 6 clicks, 180 ul, 3000 ug; 3.5 mg = 7 clicks, 210 ul; 8 mg = 16 clicks, 480 ul;
3.2 mg = Between(6 clicks 180 ul 3000 ug, 7 clicks 210 ul 3500 ug); 0.3 mg = error less than one click
(one click 500 ug); 0 mg = error; a pen with 0 clicks, 0 mg or 0 ml = pen check error;
concentration 16667 (16.667 mg/ml), volume per click 30 ul.
- Conversion (pen B): 3 mg = exactly 7 clicks, ul = 233 (rounded), ug = 3000; volume per click 33 ul.
- Notices: 3 mg on pen A none; 9 mg on pen A "more than a marked dose"; a pen with 3 clicks per dose "unusual
number of clicks"; dose volume 3.5 ml "large dose volume"; usable volume 0.24 ml "smaller than a dose".
- Numbers: "3.5" and "3,5" = 3500, " 0.48 " = 480, "abc", "" and "1.2345" = null; format 3000 "3", 3500 "3.5",
667 "0.667", 180 "0.18", 2700 "2.70", 233 "0.233"; with a decimal comma "0,18".
- Supply (pen A): after one administration of 3 mg, 2700 ul = 45000 ug is left and 15 more administrations of
3 mg; six administrations of 8 mg empty the pen (left 0), a further administration of 1 mg (2 clicks, 60 ul) is
stopped by the check with the numbers 0 and 60, marked as from the reserve it passes; when editing one of the six,
the edited record is not counted.
- Reserve (pen A, six administrations of 8 mg + 60 ul from the reserve): taken 60; without an estimate "left" is
null; with an estimate of 0.10 ml, 40 ul (667 ug) is left; with waste 10 ul per administration and no
administration from the reserve, taken 60.
- Schedule (zone Europe/Bratislava, pen A opened 2026-03-02 08:00, prescribed 3 mg, one administration of 3 mg on
2026-03-02 10:00): next administration 2026-03-07 09:00, 15 administrations left, no longer holds the full amount
2026-05-21 09:00, end of in-use period 2026-03-23 08:00, runs out 2026-03-23 08:00, buy by 2026-03-19 08:00.
Without a record: next administration null, buy by 2026-03-19 08:00. Without an interval: next administration
null. With prescribed 8 mg and an in-use period of 90 days: 5 administrations left, no longer holds the full
amount 2026-04-01 09:00 (across the switch to summer time, hence 09:00 local time), which is also "runs out",
buy by 2026-03-28 09:00.
- Alarms (the same pen, all three switches on, now 2026-03-03 12:00): administration 2026-03-07 09:00, end
2026-03-20 09:00, buy 2026-03-19 09:00, codes distinct; a used-up pen none; "now" after a time drops that alarm.
- Default amount: the prescribed amount wins; otherwise the last administration from the same pen; a new pen with
the same values and no records gets the amount of pen A's last administration; a pen with other values and no
records null. Last administration before a record includes other pens and when editing ignores the edited record.
- Pen form check: empty strength, 0 clicks, "1.5" clicks and "abc" as volume return codes at the right fields;
an empty interval is fine (null).
- Storage and transfer: JSON round trip (including a note with accents, quotes and a line break), an unknown field
is ignored, import {"name": "x"} is INVALID, import with version 2 is NEWER_VERSION, unreadable text UNREADABLE,
a corrupted state.json is moved aside (in a temporary folder) and an empty State is loaded; CSV header and
escaping (a pen named "Pen; test", a note with a quote), zone UTC.
- At least 30 tests in total.
## 5. Technology and versions
- Kotlin, Jetpack Compose, Material 3, one activity, enableEdgeToEdge() and Scaffold so nothing sits under the
system bars. Navigation through state (tab, Settings open, form open), no navigation library.
- Allowed libraries: AndroidX core (including NotificationCompat), activity-compose, lifecycle (viewmodel-compose,
runtime-compose), Compose BOM (ui, material3, material-icons-core), kotlinx-serialization-json, JUnit 4.
Nothing else.
- applicationId and namespace eu.papuh.pero, versionCode 1, versionName 1.0, minSdk 26, compileSdk and targetSdk the
highest that is installed on the machine and supported by the chosen Android Gradle Plugin (AGP) version.
- Do not guess versions from memory. First find out what is on the machine: the SDK in ANDROID_HOME, otherwise
~/Library/Android/sdk (folders platforms, build-tools, platform-tools, emulator; for each platform its
source.properties, because a platform can have a minor version too, for example 37.0); JDKs in JAVA_HOME, in
Android Studio (/Applications/Android Studio.app/Contents/jbr/Contents/Home) and in
~/Library/Java/JavaVirtualMachines, with java -version for each; downloaded Gradle versions in
~/.gradle/wrapper/dists. Then check official sources (developer.android.com, gradle.org, kotlinlang.org, Google
Maven, Maven Central) for the current stable versions of AGP, Gradle, Kotlin, the Compose BOM, AndroidX libraries
and kotlinx-serialization and their compatibility tables. Read the newest version from maven-metadata.xml and
sort by version number (sort -V), not by order in the file; skip alpha, beta, rc and dev. Put all versions in one
place: gradle/libs.versions.toml.
- For every AndroidX library, including those the Compose BOM brings in (ui-android, foundation-android,
animation-android, material3-android), look at aar-metadata.properties in its AAR: minCompileSdk, the minor
compileSdk version (if listed) and minAndroidGradlePluginVersion. Checking one library is not enough.
- What wins when tables do not overlap: AGP requirements (minimum Gradle, maximum API, JDK) are mandatory; Kotlin's
table (which Gradle and AGP versions Kotlin is tested with) means "tested up to", not a ban. Pick a Gradle that
satisfies both if one exists; if not, AGP wins and you log the deviation. Newer AGP versions have Kotlin support
built in and the separate plugin org.jetbrains.kotlin.android is not combined with them; check in its
documentation how the Kotlin version is chosen for your AGP.
- compileSdk is the highest platform installed on the machine. **Do not download a platform, not even a higher minor
version.** If a library wants a higher platform than the machine has, pick an older version of it (for Compose
an older BOM) whose metadata fits, and log it. Gradle may download on its own only the build-tools the chosen AGP
requires. Otherwise do not change the SDK.
- Gradle wrapper: if an unpacked Gradle is on the machine, generate the wrapper with it (even if it is older than
the target version, the wrapper can point to a newer one); otherwise download the official distribution from
services.gradle.org (curl -L) into a temporary folder and run gradle wrapper from it. Generate the wrapper before
the build files with AGP. Install nothing globally.
- Right after the Gradle skeleton (before writing screens) run a build that checks library metadata (for example
:app:checkDebugAarMetadata) so a version mismatch shows up at once.
## 6. Privacy and permissions
- The manifest has no INTERNET permission. If a library adds it through manifest merging, remove it
(tools:node="remove").
- The app may have only these permissions, each with a comment in the manifest on why it is needed:
- POST_NOTIFICATIONS (Android 13+: showing reminders, the app asks for it when a reminder is switched on);
- RECEIVE_BOOT_COMPLETED (scheduling alarms again after a phone restart);
- SCHEDULE_EXACT_ALARM with android:maxSdkVersion="32" (exact alarms on Android 12);
- USE_EXACT_ALARM (exact alarms from Android 13 without a further user request).
Besides them the APK will contain the permission eu.papuh.pero.DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION, which
AndroidX core adds; it is the app's own permission with signature level, opens nothing and is not removed.
- Because of USE_EXACT_ALARM the app is **not meant for an app store**: Google Play accepts it only for alarm clocks
and calendars, and converting an amount of medicine would be assessed there as a medical device. It is installed
only over adb.
- android:allowBackup="false" and android:dataExtractionRules with a file that excludes everything from cloud
backup and from device-to-device transfer; for older Android versions also android:fullBackupContent="false".
- The alarm receiver is exported="false"; the boot receiver is exported="true" only with the filter BOOT_COMPLETED
and MY_PACKAGE_REPLACED and checks the action.
- No accounts, analytics, crash reporting, ads, WebView or outgoing links. Data leaves the phone only through an
export the user makes.
- Signing: the computer's debug key, no own keystore. A build from another computer will not install over the old
one, and uninstalling deletes the data (see start.sh install).
## 7. Output
code/
start.sh the single entry point for a human
README.md short: what it is, start.sh commands, chosen versions, permissions and why
.gitignore build/, .gradle/, .kotlin/, local.properties, *.apk, *.jks, *.keystore
settings.gradle.kts, build.gradle.kts, gradle.properties, gradle/libs.versions.toml
gradlew, gradlew.bat, gradle/wrapper/
app/build.gradle.kts
app/src/main/AndroidManifest.xml
app/src/main/java/eu/papuh/pero/ MainActivity.kt, AppViewModel.kt, model/, data/, reminders/, ui/
app/src/main/res/ values/, values-sk/, xml/, mipmap-anydpi-v26/, drawable/
app/src/test/java/eu/papuh/pero/
notes/
build-log.md
screenshots/ emulator screenshots from the check
start.sh (zsh, set -euo pipefail, executable, no absolute paths containing the user name):
- ./start.sh or ./start.sh test: unit tests on the JVM, always really run (:app:testDebugUnitTest --rerun, not
from cache), then from the XML results it prints "Tests: total N, failed N, skipped N."
- ./start.sh apk: builds the debug APK, prints its path and size and the list of permissions in the APK (aapt2 dump
permissions from the newest build-tools). Fails if android.permission.INTERNET or a permission not on the list
in part 6 is among them.
- ./start.sh install: builds, installs over adb (install -r, data is kept) and launches the app. If no device is
connected, it says what to do (connect a phone with USB debugging or start the emulator). If there are several,
it uses ANDROID_SERIAL, otherwise it lists them and exits. **It never uninstalls the app** (that would delete all
records); if installation fails because of a different signature, it says to export a backup in the app first,
and exits.
- The script finds the JDK itself (order: JAVA_HOME, the JDK in Android Studio, ~/Library/Java/JavaVirtualMachines;
it takes the first whose version is in the range the chosen Gradle runs on according to its table) and the SDK
(ANDROID_HOME, otherwise ~/Library/Android/sdk), creates local.properties if missing and prints once at the start
which Java and SDK it uses (if one command calls another, it does not print it twice). It prints paths with ~
instead of the home folder.
- zsh traps to watch for: with set -e the command (( x += 0 )) returns status 1 and the script exits, so write
x=$(( x + y )); zsh does not handle nested ${...} with escaped quotes inside (( )), read numbers from XML with
grep -o and tr; a variable holding a command with arguments is not split into words in zsh, use an array
(adb=( "$sdk/platform-tools/adb" -s "$serial" ) and "${adb[@]}" shell ...); write a glob that may match nothing
with (N). After writing it, check zsh -n start.sh.
Code, identifiers and comments in English, UI texts only from strings.xml.
## 8. Way of working and build log
1. Before each bigger step, say in one sentence what you are about to do.
2. Create notes/build-log.md right at the start and update it after every step, not only at the end. Each entry:
time (HH:MM), what was done, the exact command, the result (passed or failed), for a failure a short excerpt of
the message (at most 10 lines) and what fixed it. At the end a table of chosen versions with the reason, the
number of tests, the APK size, the permission list, what was checked on the emulator and what was not, and
a section "Ideas for later".
3. The log is truthful: do not write that something passed unless you saw it pass, and do not leave out errors
or dead ends. It is the material for a video about the build.
4. No path containing the user name in the log, code, README or screenshots: write the home folder as ~.
When the log describes a check from part 10, **describe the searched string in words, do not quote it
literally**, otherwise the check finds it in the log itself.
5. Order: inspect the machine and versions, wrapper, Gradle skeleton and library metadata check, the model package
with tests, ./start.sh test, storage and ViewModel, screens, reminders, ./start.sh apk, check on the emulator.
6. When the build fails because of a version, change one thing at a time and log it. After three failed attempts
with the newest combination, go back to a combination the compatibility tables list explicitly.
7. Check on the emulator:
- $ANDROID_HOME/emulator/emulator -list-avds lists the devices. If no emulator is running, start the first device
**detached from your command**, so the tool does not wait for it to end: nohup, output to a file in a temporary
folder outside the project and & (in zsh &!). With its window if the environment allows it; if not,
-no-window, and log it. Then wait with one command containing a loop until adb shell getprop
sys.boot_completed returns 1 (at most 5 minutes).
- Use only the emulator, never a physical phone, even if one is connected (set ANDROID_SERIAL to the emulator).
- Set the app language to English: adb shell cmd locale set-app-locales eu.papuh.pero --locales en.
Grant the notification permission beforehand: adb shell pm grant eu.papuh.pero
android.permission.POST_NOTIFICATIONS.
- ./start.sh install and drive the app over adb: uiautomator dump to find elements, input tap, input text
(plain ASCII only, space as %s). So elements can be found regardless of language, put
Modifier.semantics { testTagsAsResourceId = true } on the root of the UI and give important elements a testTag
(for example notice_confirm, tab_home, tab_convert, tab_pens, tab_history, tab_schedule, settings, add_pen,
field_strength, field_dose_volume, field_clicks, field_pen_volume, field_in_use_days, field_prescribed,
field_interval, switch_administration_reminder, save_pen, field_amount, option_lower, option_higher, result,
record, confirm_record, amount_left). Before pressing system Back, check that the keyboard is hidden
(adb shell dumpsys input_method | grep mInputShown); keyevent 111 may not hide it, and Back then closes only
the keyboard.
- Steps: confirm the notice (screenshot 01-notice). Pens, +: check in uiautomator dump that the pen value fields
are empty (screenshot 02-new-pen-empty). Fill in pen A from part 4 (name Test pen, strength 8, dose volume
0.48, clicks 16, pen volume 2.88, 21 days, prescribed 3, interval 5), switch on the administration reminder,
save. Convert: enter 3.2 and check that two options appear (6 and 7 clicks) and neither is selected
(screenshot 03-partial-click); then enter 3 (screenshot 04-convert: 6 clicks = 0.18 ml = 3 mg). Record
administration, Confirm. Home (screenshot 05-home: left 2.70 ml = 45 mg), Schedule (screenshot 06-schedule:
next administration in 5 days at 09:00), History (screenshot 07-history), Settings (screenshot 08-settings).
- Screenshots: adb exec-out screencap -p > notes/screenshots/<name>.png. Check the data with
adb shell run-as eu.papuh.pero cat files/state.json (a record with ug 3000, clicks 6, ul 180) and the alarm with
adb shell dumpsys alarm, looking for eu.papuh.pero in its output.
- Leave the emulator running at the end and write in the log how to stop it.
8. When to stop: if the Android SDK is missing or there is no virtual device, do not improvise. Write into the log
what is missing and what the human has to do (for example open Device Manager in Android Studio and create
a device), and finish with a message containing the same text.
## 9. What not to do (and why)
- The app gives no advice. It suggests, changes or proposes no amount, interval or way of administration: no
"your dose", no "dosing", no step-up plan, no suggested interval, no preselected injection site and no judgement
of whether an amount is right. The app's vocabulary: "prescribed amount (entered by the user as the doctor
prescribed)", "administration record", "conversion". Checks are input checks and only say "check the values
entered". Reason: the app knows nothing about the person's health or treatment; the doctor decides the amount and
the interval.
- No database of medicines or pens, no prefilled pens, strengths, volumes, clicks, intervals or in-use periods, no
names of medicines, active substances, pens or manufacturers (not in examples, tests, variable names or comments
either). Reason: values differ between pens, and a wrongly chosen default value is converted silently without
anything on screen showing it. Whatever the app calculates with must have been typed by the user.
- Never round a partial click on your own, not even "to the safer side". Reason: an error in the calculation has
a health consequence; the person who sees both options decides.
- No internet, accounts, analytics, ads or cloud. Reason: administration records are health data and stay only
on the phone.
- No Room, Hilt, KSP, kapt, WorkManager, navigation or chart library. Reason: every extra dependency is one more
version that can clash; the pen is a few shapes on a Canvas and only AlarmManager gives an exact reminder time.
- Do not edit a test to make it pass and do not change the meaning of a calculation to match a test. When a test
fails, first find out whether the error is in the code or in the test's expected value, fix what is actually
wrong and write in the log why.
- Install nothing globally (no Homebrew, no changes to ~/.zshrc) and do not change system, Android Studio or SDK
settings beyond the build-tools Gradle downloads during the build.
- Do not use a physical phone and do not delete data of other apps. The human installs the app on the phone with
./start.sh install.
- Do not create a git repository, do not commit and do not publish anything: no app store, no APK upload, no
sharing. The human decides that.
- Add no features beyond this task. Write ideas into the log under "Ideas for later".
## 10. Definition of done
Done means everything below holds at once in the folder code/ and the log contains the output of every command:
1. ./start.sh test ends with BUILD SUCCESSFUL and prints at least 30 tests, 0 failed, 0 skipped.
2. ./start.sh apk prints the path to app-debug.apk and a permission list that contains only the permissions from
part 6 and not android.permission.INTERNET.
3. On the emulator the app installs and starts via ./start.sh install and the steps from part 8, point 7, all pass:
notice confirmed, a new pen has empty value fields, 3.2 mg shows two options with none chosen, 3 mg shows
6 clicks = 0.18 ml = 3 mg, run-as ... cat files/state.json shows a record with ug 3000, clicks 6, ul 180, Home
shows 2.70 ml = 45 mg left, Schedule shows the next administration in 5 days at 09:00, dumpsys alarm shows the
app's alarm and the screenshots are in notes/screenshots/.
4. grep -rniE "odporúč|odporuc|tvoja dávka|tvoju dávku|dávkovan|recommend|your dose|dosing|dosage" app/src/main
finds nothing.
5. grep -rn "/Users/" . ../notes --exclude=local.properties --exclude-dir=build --exclude-dir=.gradle
--exclude-dir=.kotlin finds nothing.
6. grep -n "applicationId" app/build.gradle.kts shows eu.papuh.pero.
7. notes/build-log.md has all steps, versions, permissions and the summary.
At the end write a short message: what is done, chosen versions, number of tests, permissions in the APK, what
failed or was not checked, and how to get the app onto the phone (Developer options, USB debugging,
./start.sh install; before installing from another computer, export a backup first).
What each part does
| Part | What it does | What happens without it |
|---|---|---|
| 0 Folder | the only place you change; everything else is relative to it | the AI picks a place itself, often where nobody looks |
| 1 Goal | one sentence about what must be true at the end | the AI does not know when to stop, and keeps adding |
| 2 Context | who it is for, which computer, work without questions, the numbers are made up | the AI proposes accounts or “fills in” the values of a real pen from memory |
| 3 What the app does | five tabs, Settings, the log dialog, reminders, the notice in three places | an app that is “similar” but different; the notice shown once and easy to dismiss |
| 4 Data and calculations | whole micrograms and microlitres, the formula, two options for a partial click, the schedule, the data model, tests with made-up numbers | decimal errors, silent rounding of clicks, data a new version cannot read |
| 5 Technology and versions | the stack, find versions on the machine and in official sources, what wins when the tables disagree, do not download a platform | the AI writes versions from memory that may no longer hold, and the first build fails |
| 6 Privacy and permissions | no internet and no cloud backup, an exact list of permissions with reasons | data leaves the phone; a new permission appears and nobody notices |
| 7 Output | folder structure, start.sh commands, zsh traps |
every project starts differently; the script fails on small things |
| 8 Way of working and log | order of steps, an honest log, a step-by-step check on the emulator, when to stop | you do not know what happened and why; “it works” without proof |
| 9 What not to do | limits with reasons: the app gives no advice, no preset pens, a partial click is never rounded, never change a test to get green | the AI “helps” with a list of pens or a recommended interval and the app starts giving advice |
| 10 Definition of done | commands you can run and what they must print | “done” only means the AI stopped writing |
Three things worth noticing:
- Empty fields are a feature, not laziness. The app does not know which pen anyone has. Every number it calculates with is typed in by the user, and a doctor or pharmacist has to confirm it. The definition of done checks this on the emulator.
- A partial click is a question for a person. When the amount does not land on a whole click, the app shows two options and picks neither. There is a test for it, and part 9 says why.
- Lessons from the previous build are in the brief. With the weight log the AI ran into a library that wanted a newer platform than the one on the machine, a zsh trap with
set -e, a log that found itself during a check, and a keyboard that swallowed a Back press. This brief names each of them in advance.
You can change the folder (part 0), the package name eu.papuh.pero to your own (everywhere at once) and the colour palette. I would not throw out the notice or parts 9 and 10.
How the brief did in a real build, and what I would change in it afterwards, is in part thirteen. The whole process is also in a video on YouTube, in Slovak; the voice in it is AI-generated from my own.
I prepared this text with the help of AI from my own notes and the build log.