COMP 1601 2021W Tutorial 9 Solutions 1. Where in the application is the following behaviour specified? 1a. The size of the red circle activity_main.xml, lines 11 & 12 - android:layout_width and android:layout_height properties for the circle ImageView 1b. The colour of the red circle. circle.xml, line 3 - android:color property of solid 1c. No application title on the screens. theme.xml, lines 15 & 16 - windowActionBar and windowNoTitle items 1d. The application should start with showing the splash screen. AndroidManifest.xml, lines 12-18 - defines the .SplashScreen activity and says it responds to the MAIN and LAUNCHER activities 1e. The splash screen layout in splashscreen.xml is associated with the code in SplashScreen.kt SplashScreen.kt line 12, SetContentView() 1f. Clicking on continue on the splash screen should cause MainActivity to be run. splashscreen.xml line 37, the android:onClick property specifies startMain() as the function to call (as defined in SplashScreen.kt). 2. The layout of the application changes when you switch the device to dark/night mode, beyond different colors. Why? night/themes.xml does not have the items that were added to values/themes.xml (windowActionBar and windowNoTitle). If those are added we see the same layout in dark and light modes. 3. Where does the application send an explicit intent? Where does it receive an explicit intent? It sends an explicit intent using the startActivity() call on line 19 of SplashScreen.kt. It receives this same intent using the activity declaration for MainActivity in AndroidManifest.xml, lines 19 and 20. 4. Where does the application send an implicit intent? Where does it receive an implicit intent? It sends an implicit intent when it opens a web page in openPage(), specifically the call to startActivity() on line 29 of MainActivity.kt. It receives an implicit intent to start the application via the intent filter on the SplashScreen activity, lines 13-17 of AndroidManifest.xml. 5. What touch events does MainActivity respond to? What code implements the response for them? MainActivity Open Page button responds to a "click" event via the onClick handler specified in activity_main.xml for the button (line 24). This event is handled via the openPage() method of MainActivity. MainActivity's circle response to touch events via trackCircle's onTouch method, which is registered to the circle with the setOnTouchListener on line 21 of onCreate(). 6. Why are the constants added to circle.x and circle.y in TrackCircle's onTouch handler (lines 40 and 41)? How does the behavior of the app change if these constants are removed? Why? The constants (128 for both) are added so the coordinates of the touch events align with the position of the circle. Without them, the circle will always be offset from where the user touches. This offset occurs because we are using the raw coordinates from the event, which are relative to the top left corner of the screen, while we draw the circle at coordinates relative to the view it is positioned in (which excludes things like the application titlebar and the phone status bar). 7. TrackCircle's onTouch method does the same thing in response to an ACTION_MOVE and an ACTION_UP event. Are both of these needed? What happens if either is removed? We actually don't need the ACTION_UP event, as the ACTION_UP event will be basically where the last ACTION_MOVE event. ACTION_MOVE events are reported continuously as the user moves their finger while ACTION_UP is reported when they lift their finger up. Since we do nothing special when the user lifts their finger we don't need the coordinate updates there. If we got rid of the ACTION_MOVE updates, however, things would be very different as the user would get no feedback while they were moving their finger - the circle would instead only move when the finger was lifted, and then it would jump instantly to where the touch gesture ended.