Kurt CapatanMobile Dev
← All work

IceMobile · LoyaltyOne

AIR MILES logo

Air Miles Android App

Led a feature across Android and backend with no lead title.

Role
Android Developer (contract)
When
Jan 2017 – Mar 2018
Platforms
Android
Industry
Loyalty & Rewards, Retail
Release
Released on Google Play in 2017. The program is now Blue Rewards, and today's app is a later redesign I didn't work on.
  • Java
  • RxJava
  • Retrofit
  • OkHttp
  • Android ViewModel
  • Android Pay API
  • View Animations
Saving the digital Air Miles card to Google Pay from the app
Save to Android Pay, which I led. The Google Pay screens are Google's app. My collector number, the card barcodes and the pass number are blurred.

About the app

AIR MILES was one of Canada's largest loyalty programs. Members collected miles when they shopped at partner stores, then spent them on rewards. The app let members browse partners and offers, find nearby stores, check their balance and show a digital card at checkout.

What I built

  • Led Save to Android Pay across Android and backend (the deep dive below).
  • Built the animated entrance into partner details. I first built a shared-element transition that moved the partner’s logo along a curve. The designer later replaced that design, and I built the new one by hand with Android’s view animations: fades, slides and scales combined in AnimationSets with interpolators, in Java (the second deep dive below).
  • Added the nearest store on the partner details page, with a distance button that fires an implicit intent so the member opens directions in the app they already use.

Deep dive: Save to Android Pay

We planned a feature to let members save their digital Air Miles card to Android Pay, which had just launched in Canada. Nobody on the team had used the API.

I offered to build a proof of concept to answer one question early: did this need backend work? I set up the Air Miles loyalty program in LoyaltyOne’s Google merchant account — the program name, points label, tier labels and card colors — and in one week built a small app that saved a fake card to my own Android Pay account.

The proof of concept found the security constraint: saving a card needs a request signed with a private key, and that signing could not live in the APK — anyone can unpack an APK and extract the key, then create cards in the Air Miles name. So the signing had to happen on our server.

I walked the three backend developers and the other Android developer through the flow, the key and the API. The backend built the signing; I led the work across both sides. After about a month of development and testing, the feature shipped in a staged rollout.

How saving a card works
  1. In Google’s merchant account, the issuer defines the program once as a loyalty class.
  2. Each member’s card is a loyalty object belonging to that class.
  3. The backend puts the loyalty object in a JSON Web Token and signs it with the private key of a Google service account.
  4. The app asks our backend for the signed JWT and hands it to Android Pay, which shows the save screen.

Today this is Google Wallet. Its Android SDK can save a pass straight from the app with savePasses, signed with the app’s SHA-1 fingerprint, or save a server-signed JWT with savePassesJwt. I would still have the backend build and sign each member’s card, so the card data comes from the server that knows who the member is.

Deep dive: the partner details entrance

When a member opened a partner, the details page built itself in steps instead of appearing all at once. The recording in the gallery shows it. Frame by frame, it plays like this:

  1. The header and the sheet arrive together. The partner’s name fades in while sliding down into place, and the logo grows from half size to full. At the same time, the Bonus Offers sheet slides up from the bottom and covers the nearest store.
  2. A spinner shows while the offers load. The ViewModel starts fetching as soon as the page opens, without waiting for the animation. The spinner appears only after the sheet lands, and only if the offers haven’t arrived yet.
  3. When the offers load, the sheet drops a short way to uncover the nearest store.
  4. At the same time, the nearest-store card fades in and rises into place. The rise is only a few pixels, against the direction of the sheet’s drop.

Each part is a view animation — an AlphaAnimation, TranslateAnimation or ScaleAnimation — or an AnimationSet that runs several on one view together. Interpolators set the feel: the sheet speeds up and then slows down, and everything else starts fast and settles. The code below summarizes how the parts fit together. It is not the actual code, which I no longer have, and it leaves out durations and distances.

// One animation per view. true: the set's children share one interpolator.
AnimationSet partnerNameIn = new AnimationSet(true);
AnimationSet logoIn = new AnimationSet(true);
TranslateAnimation sheetUp = new TranslateAnimation(...);   // up over the store
TranslateAnimation sheetDown = new TranslateAnimation(...); // down to its place
AnimationSet storeCardIn = new AnimationSet(true);

boolean entranceDone, offersLoaded;

void setUpAnimations() {
    // Stitch: a set plays its children together on one view
    partnerNameIn.addAnimation(new AlphaAnimation(...));     // fade in
    partnerNameIn.addAnimation(new TranslateAnimation(...)); // slide down
    logoIn.addAnimation(new AlphaAnimation(...));
    logoIn.addAnimation(new ScaleAnimation(...));            // grow from center
    storeCardIn.addAnimation(new AlphaAnimation(...));
    storeCardIn.addAnimation(new TranslateAnimation(...));   // rise into place

    // Interpolators set the feel
    partnerNameIn.setInterpolator(new DecelerateInterpolator());
    logoIn.setInterpolator(new DecelerateInterpolator());
    sheetUp.setInterpolator(new AccelerateDecelerateInterpolator());
    sheetDown.setInterpolator(new DecelerateInterpolator());
    storeCardIn.setInterpolator(new DecelerateInterpolator());

    // Pause: the sheet holds over the store until the offers load
    sheetUp.setFillAfter(true);
    sheetUp.setAnimationListener(new AnimationListenerAdapter() {
        @Override public void onAnimationEnd(Animation animation) {
            entranceDone = true;
            if (offersLoaded) playLoaded();
            else progressBar.setVisibility(View.VISIBLE);
        }
    });
}

// Start: the header and the sheet together
void playEntrance() {
    partnerName.startAnimation(partnerNameIn);
    logo.startAnimation(logoIn);
    sheet.startAnimation(sheetUp);
}

// Resume: the offers observer calls this, before or after the entrance ends
void onOffersLoaded(List<Offer> offers) {
    offersAdapter.setOffers(offers);
    offersLoaded = true;
    if (entranceDone) playLoaded();
}

void playLoaded() {
    progressBar.setVisibility(View.GONE);
    sheet.startAnimation(sheetDown);
    storeCard.startAnimation(storeCardIn);
}
Technical notes
  • Why every animation ends at zero: a view animation moves only the view’s drawing, not the view. Its real position, where taps land, stays where the layout put it. So the layout places each view at its final spot, and each animation starts from an offset and ends at zero. The drawing and the real view then agree when the animation ends, and the offer buttons in the sheet are tappable exactly where they appear.
  • The one held offset: while the offers load, setFillAfter(true) keeps the sheet drawn above its real position. Nothing in it can be tapped yet except the spinner, so the mismatch is harmless, and sheetDown returns it to zero before the offers can be tapped.
  • AnimationListenerAdapter is a small helper class: an Animation.AnimationListener with empty methods, so the code overrides only onAnimationEnd.
  • Today: I would use property animations, which move the real view, or in Jetpack Compose, Animatable and animate*AsState.