上QQ阅读APP看书,第一时间看更新
Recording user actions
Some applications are better served when you record the user's actions. In this context, a user action refers to an in-app behavior such as clicking on/touching a button or moving a slider. In this recipe, we will create a user action log and program a button to record user actions.
How to do it...
To record user actions, perform the following steps:
- Create a new main stack for a mobile application.
- Add three buttons across the top named
Safe
,Secure
, andRestricted
. - Add a button named
Reset Log
at the bottom-center of the card. - Create a scrolling text field named
fldLog
to fill the remainder of the card. - Set the background color of the
fldLog
field to black. - Set the foreground color of the
fldLog
field to yellow. This will be the color of the text entered into the log. - Set text size of the
fldLog
field to 14. - Set the
traversalOn
property tofalse
(deselect the Focusable checkbox in the Basic Properties section of the property inspector). - When you complete steps 1 to 5, your interface should look similar to the following screenshot. Make any adjustments to your four buttons and the scrolling text field before moving on to step 7.
- Add the following code to the card that contains your interface:
global logLine on preCardOpen put 1 into logLine end preCardOpen on updateLog msg2log put msg2log into line logLine of fld "fldLog" add 1 to logLine end updateLog
- Add the following code to the Reset Log button:
on mouseUp global logLine put 1 into logLine put empty into fld "fldLog" end mouseUp
- Add the following code to the Safe, Secure, and Restricted buttons:
on mouseUp updateLog(short name of me & ": mouseUp") end mouseUp on mouseDown updateLog(short name of me & ": mouseDown") end mouseDown on mouseEnter updateLog(short name of me & ": mouseEnter") end mouseEnter on mouseLeave updateLog(short name of me & ": mouseLeave") end mouseLeave
- Test your application. It should look similar to the following screenshot:
How it works...
By creating listeners (also known as handlers), we can record user actions in our apps. Depending upon your application, you might want to create a system log for security purposes or even to provide a display (as we did in our example) for users to review.