Monday, December 18, 2017

Service worker and authentication in a Polymer app

In order to sign in with a Google account or to sign out, a web app running on Google App Engine needs to navigate to a URIs that start with /_ah.  If the app is configured to use a service worker, the service worker will intercept these URIs and won't allow the sign-in/sign-out flow to continue.

In order to enable sign-in/sign-out for a Polymer app, polymer.json configuration needs to specify swPrecacheConfig option, e.g.:

"builds": [
  {
    "preset": "es6-unbundled",
    "swPrecacheConfig": "sw-precache-config.js"
  }

And sw-precache-config.js file needs to specify navigateFallbackWhitelist option:

module.exports = {
    // Everything except '/_' prefixes
    navigateFallbackWhitelist: [/^(?!\/_).*/]
};

When built with these options, the generated service worker will allow a Polymer app to successfully navigate to sign-in/sign-out URIs.

See Generating a Service Worker for more information.

Sunday, December 17, 2017

Debugging an AppEngine app locally using IntelliJ Community Edition

This post puts together information that is spread across different GCP documents.

First, configure appengine.run.jvmFlags in build.gradle as described here:

appengine {
    run {
        jvmFlags = [
            '-Xdebug',
            '-Xrunjdwp:transport=dt_socket,' + 
                'server=y,suspend=y,address=5005'
        ]
    }
}

Second, configure remote debug configuration as shown here.

In order to debug the app, start the local server from the Gradle or Maven toolbox in the margin of your IDE, or run

gradle appengineRun or gradle appengineStart

from the command line.

Then choose the remote debug configuration on the top toolbar and click Debug icon.

Monday, December 4, 2017

Leap years in Android CalendarView

Use CalendarView with caution.

MonthView uses Utils.getDaysInMonth() that defines a leap year as follows:

case Calendar.FEBRUARY:
    return (year % 4 == 0) ? 29 : 28;

And this is how a leap year should be defined:

Exactly Which Years Are Leap Years?

We add a Leap Day on February 29, almost every four years. The leap day is an extra, or intercalary, day and we add it to the shortest month of the year, February.

In the Gregorian calendar three criteria must be taken into account to identify leap years:


  • The year can be evenly divided by 4;
  • If the year can be evenly divided by 100, it is NOT a leap year, unless;
  • The year is also evenly divisible by 400. Then it is a leap year.


This means that in the Gregorian calendar, the years 2000 and 2400 are leap years, while 1800, 1900, 2100, 2200, 2300 and 2500 are NOT leap years.

So, 2100 is not a leap year, but according to Android, it is:


There are more problems related to CalendarView.  For example, the control does not allow a user to select February 29, 2100, but it allows to select February 28.  Again, be cautious.