Documentation / LemmeKnow

Notification cards Coming soon

A notification card is a small HTML page that LemmeKnow draws over a whole notification when a notify rule's OS style is Card (Premium, with the notification styles accessibility setting on). Plugins add them, and users pick one per rule (see Notify and Silence).

A card is built like a Delivery Screen page. It runs in the same sandbox, loads files from the same kind of address, and talks to the same Lk object, with the same params, theme, palette colors, CSS variables and notification style. This page covers what is different about cards. The LemmeGetIt package is a complete example that uses every feature below.

Declaring a card

Declare cards under notificationCards in the package manifest, exactly like deliveryScreens: id, label, entry, assets, includesSound and params (see Building plugin packages). A card can also set thumbnail and bleed, described below. The rule editor shows a card's params the same way the Delivery step shows a screen's, and stores them the same way.

How a card differs from a screen

  • The page is the size of the notification row, often only around 100 to 260 pixels tall, and it moves and resizes with the row, including when the user expands or collapses the notification. Paint the whole box: anything left transparent shows the plain notification underneath. To draw beyond the row, see Drawing past the notification.
  • payload() carries title, message, rule_name, icon, volume, stream, audioTurn and shown, plus image (the notification's own picture, such as the rule image or the app's large icon) and picture (its big picture, such as a camera snapshot or a feed item's image) when it has them. theme() is the theme the rule picked, or the one picked from its playlist.
  • deliveryComplete() and deliveryDismissed() don't close anything. They tell LemmeKnow the card's audio turn is over.
  • capabilities() reports card, audioTurn, thumbnail, bleed and reserve.

Pictures

A notification can carry two pictures, and they mean different things:

  • payload.image is a small secondary picture, such as a sender's photo or the app's large icon. It suits a small spot beside the title.
  • payload.picture is the notification's content, such as a camera snapshot or a feed item's image. Android shows it as a thumbnail beside the text while the notification is collapsed, and across the notification under the text once it's expanded. Do the same: never shrink it into an icon-sized spot. Check the page's height to tell the two apart, since it grows when the user expands the notification, and show the full picture only when all of it fits, so it isn't squeezed while the notification opens or closes.

Playing the opening once

A notification's card plays its opening once. LemmeKnow can load your page again for the same notification, for example when its row scrolls back into view or the shade opens again. Then payload.shown is true and payload.audioTurn is false: draw the card at rest, as it looks once the opening is over.

if (payload.shown) document.body.classList.add('settled');
else requestAnimationFrame(() => document.body.classList.add('play'));

Thumbnails

A card can also draw a still thumbnail of its notification. Declare "thumbnail": true on the card in the manifest. Before a Card notification posts, LemmeKnow loads your page twice off screen, with payload.thumbnail true and payload.expanded false and then true, and posts the notification with those two frames as its own look. The system then shows your card's style from the very first moment, in the shade and when it pops up, and a long-press on the notification shows the thumbnail. Your live card takes its place as soon as it's ready.

  • Draw one still frame that shows the notification's content: the title and message in place, with no animation and nothing caught mid-motion. The expanded thumbnail should show the whole message, even if your live card never does.
  • The collapsed thumbnail is about 64 pixels tall. The expanded one is laid out in a box up to 256 pixels tall: lay it out from the top.
  • Call Lk.thumbnailReady(height) once the frame is drawn, after your fonts and images have loaded, with the height in pixels your expanded content needs (or Lk.thumbnailReady() to use the whole box).
  • A card that isn't ready within a second and a half, or doesn't declare a thumbnail, posts with the plain notification look instead.
const payload = JSON.parse(Lk.payload());
if (payload.thumbnail) {
  document.body.classList.add(payload.expanded ? 'still-expanded' : 'still');
  document.fonts.ready.then(() => requestAnimationFrame(() =>
    Lk.thumbnailReady(Math.ceil(document.querySelector('.content').getBoundingClientRect().bottom))));
} else {
  start();
}

Space the app draws over

A rule can show the theme's expand arrow (with a group's count) over your card, at its right edge. LemmeKnow tells your page how much of that edge it covers, in pixels from the notification's right edge, so you can keep your content clear of it. Or ignore it, and the arrow draws over whatever is underneath.

  • The --lk-reserve-right CSS variable always holds the current space, 0px when nothing is drawn over the card.
  • Lk.reserved() returns it as JSON: right, plus chevron (left, top, width, height) when the arrow shows.
  • An lkreserve event fires on window with the same object whenever it changes, for example when the notification joins a group and the arrow appears.
.content { margin-right: var(--lk-reserve-right, 0px); transition: margin-right 0.2s; }

Drawing past the notification

A card can reach past its notification, for example to have a character run in from the edge of the screen. Declare "bleed" on the card with how far it reaches on each side in pixels, up to 160: "bleed": {"left": 48, "right": 48}. Your page is then that much larger than the notification, and payload.bleed carries the same four values (left, top, right, bottom) so you can place your panel exactly over the notification.

  • Anything you leave transparent around the notification shows the real screen: the gaps in the shade, the notifications beside yours and the screen edge.
  • Your page isn't rounded to the notification's corners when it bleeds. Round your own panel with notificationStyle().cornerRadius.
  • The page is cut to the notification list, so it never draws over quick settings or the status bar. Over a pop-up, it can use the screen below the status bar.
  • Thumbnails never bleed: payload.bleed is absent there, and the page is exactly the notification.
.panel {
  position: absolute;
  left: var(--bl); top: var(--bt); right: var(--br); bottom: var(--bb);
}
const b = payload.bleed || {};
['left', 'top', 'right', 'bottom'].forEach(side =>
  document.documentElement.style.setProperty('--b' + side[0], (b[side] || 0) + 'px'));

Sound and reading aloud

Audio is off unless the user turns it on for the rule. They can have LemmeKnow read the notification aloud, and, if your card declares includesSound, let the card play its own sound. Every card on screen shares one queue, so only one speaks at a time:

  • Your card shows as soon as it has drawn, whether or not it's waiting. When payload.audioTurn is true it will also get a turn: draw it at rest until then, and hold only what goes with sound (a talking animation, text typed in time with a voice, your own sound) until the turn comes. When it's false, play everything right away. Cards with nothing timed to sound ignore turns and animate at once.
  • When the app starts reading your card aloud, the page gets window event lkaudio with detail.phase "speak".
  • When your card may play its own sound, it gets lkaudio with detail.phase "sound", detail.play true and detail.volume (0 to 1). Call Lk.deliveryComplete() when your sound ends so the next card can start. A turn ends after 60 seconds regardless.
  • A card whose notification is dismissed leaves the queue, and its page is closed. One that scrolls out of view keeps its page and its place, and shows again at rest.
const payload = JSON.parse(Lk.payload());
// The card is already drawn at rest; this starts only the parts that go with the voice.
function start() { /* talking animation, typing in time */ }
if (!payload.audioTurn) start();
window.addEventListener('lkaudio', e => {
  if (e.detail.phase === 'sound') { start(); playVoice(e.detail.volume).then(() => Lk.deliveryComplete()); }
});

Checklist

  • Declare the card in notificationCards with id, entry, every file in assets, and includesSound if it plays audio.
  • Paint the whole notification; the page starts transparent.
  • Keep clear of --lk-reserve-right, or draw underneath the arrow on purpose.
  • Show payload.picture beside the text when collapsed and across the card when there's room, never as a tiny icon.
  • Start at rest when payload.shown is true.
  • Declare thumbnail and call Lk.thumbnailReady() so the notification looks like your card from its first moment.
  • Install the package, pick the card in a rule's OS style, and press Test in the card's settings to try it.