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
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.
- 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
- 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
- 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.