Single Prompt License Agreement

This is something I setup for my I AM HUB app and I really wanted to share it because it’s a very important piece of code for any application that needs the user to accept a license agreement. I know what you’re thinking…this tutorial has already been done. True, it has, it’s been done very well, but it hasn’t been done like this!

When the users of my application first launch the app, they will see a splash screen, which will be followed by my EULA with the usual accept or decline. Declining closes the app, and accepting takes you to the main page of the app. What about the next time the user opens my app? Do I want my user having to click I accept every time? Sure there might be cases where you want or need this, but for most situations, you only need them to accept it once. So stick with me while I go through the blocks and explain how to set this works.

This tutorial uses one of my favorite components, the notifier. You can see various uses of the notifier in my More Notifier tutorial.

As usual, start by setting up the UI in the designer. We’ll need the following components.

  • Vertical Arrangement – Call it Page1
  • Label – Call it Page1Lbl and place it inside the vertical arrangement. Enter some text in the Text property
  • Button – Call it Page1Btn and place it inside the vertical arrangement and enter Button for the Text property
    • The above 3 elements will server as the representation of our application main page
  • CheckBox – Call it EULAcheck and place on Screen1 and uncheck Visible and Value in the properties
  • Image – Call it SpashScreen, place it on Screen1 and attach an image to it in the Picture property
  • Notifier – Call it LicenseNotifier
  • Clock – Call it SplashTimer set the TimerInterval to 5000 and uncheck TimerAlwaysFires and TimerEnabled
  • TinyDB1
Once you have that setup, uncheck Visible property for Page1 and head on over to the Blocks Editor. Instead of going through each component to drag out, I will just show you the blocks and step through them.
Start by defining a variable that will hold the value of our checkbox. I called it licenseValue and it has an empty text block. In other words, I declare the variable and initialize it with no value.
The next thing I do is setup my splash screen event. By the way, the order in which I’m showing this is not relevant. There is no reason that it needs to be done in this order, other then I chose this as the most logical way of explaining this routine. For my clock, now called SplashTimer.Timer, I setup the blocks that I want to run when the clock reaches the interval, which we set as 5000ms or 5 seconds. This includes the Notifer portion which is what pops up my license agreement and presents two options. The user can either touch “I agree” or “I decline”. I set this up using an if test, followed by another if test. Both of these check the status of my checkbox, called EULAcheck.

Now I setup the instructions to handle the choice of my notifier using LicenseNotifier.AfterChoosing.

Using two more if test blocks, I check to see which button the user clicked on the license agreement that is presented with the notifier and provide my instructions for what to do based on each option.

Finally, I setup the Screen1.Initialize block with the instructions for what I want to happen when the app starts.

Now that all the code is complete, lets step through and see what happens.
  1. The app starts and Screen1.Initialize is called, which does the following
    • Set the value of licenseValue to the value stored in the TinyDB which is either true or false. The first time the app starts it will always be true since we unchecked the Value property in the CheckBox properties window.
    • Now that we have the value in memory, we do a quick if test to make sure we have the correct value and we set the CheckBox (EULAcheck.Visible) to the value we retrieved from the DB. A true value checks it, a false value unchecks it.
    • Then it sets the splash screen to visible which displays the image we used for our splash screen
    • Set the timer to fire and
    • Enable the timer
  2. At this point the user is watching the splash screen and our timer is counting, when it reaches 5 seconds SplashTimer.Timer will fire and those events will run
    • First the splash screen will be set to false and will no longer be visible
    • TimerAlwaysFires will be set to false and
    • The timer will be disabled. This insures that this event will only fire once
    • Now we do an if test and check if the value of the EULAcheck Checkbox is false, meaning it is NOT checked
    • If the above check returns a true, it will call the notifier, which will present the user with you license agreement
    • The user will either click “I agree” or “I disagree”
    • If the check of the EULAcheck.Value was true, meaning the CheckBox was checked, the second if test will run, set Page1.Visible to true and simply let the user access the application
  3. If the notifier was called in the previous event, it will be followed by the LicenseNotifier.AfterChoosing event, which will check to see what choice the user made and execute the given set of instructions, based on that choice
    • The first if test will check if the choice made was “I agree”. If it was it will set the EULAcheck.Value to true, placing a check in the CheckBox
    • It will store the value of the CheckBox in the DB under the tag licenseAccepted. If you recall, we loaded this value on Screen1.Initialize
    • Finally, it will set Page1.Visible to true and let the user access the application
    • If the user clicked “I Decline”, when the AfterChoosing event fires and this responds true to the if test to check for the value “I Decline”, it will
    • Set the EULAcheck.Value to false and
    • Call close screen, which will exit the app

So what did we do different from all the other splash screen plus license agreement tutorials? Well, we introduced the TinyDB and a checkbox,, to establish a persistent value for the users response to our license agreement. Every time the app starts, it will check what this value is and based on that value it will either present the license agreement or just let the user access the app. This can be reset by clearing the application cache, or by re-installing the app. Now you can present your users with a license agreement and not spam them every time they open your app.

Try it out and see if any of your apps can utilize this functionality.

You may also like...

  • Phil

    Thank you for this!  It was exactly what I was looking for!

  • Christie Douglas

    Where d o I find the “EULAcheck.Value block”?