Android CS323 Cornez

Lab 9: Touch Gestures and Sensors



Exercise 1: Touch Gestures - Bee Finds Finger

  1. Construct the application shown in the figure below

  2. When the application is first launched, the user will see a bee element hovering just above a flower located in the upper left corner of the screen.
  3. As the user positions their finger on the screen, the bee will move toward the finger in a proportional easing motion.
  4. As the user moves their finger around the touchscreen, the bee will chase the finger.
  5. When and if the user removes their finger from the screen, the bee will return to the flower.
The application involves three drawable elements, the bee, the flower, and the background.

bee_image.xml




activity_main.xml




Bee.java.xml









Exercise 2: Track Fingers in a Multi-touch Gesture

Create a simple application to handle multiple pointers directly in a multi-touch gesture. The objective of the application is to track two finger pointers as they travel around the screen. As shown in the figure below, the primary pointer is tracked by a large black rectangle. The primary pointer represents the first pointer placed on the screen. The secondary pointer is tracked by a smaller black rectangle.

As the primary and secondary fingers are placed on the touchscreen, their pointer identifiers are accessed using their pointer data index. These identifiers provide the actual pointer number associated with the MotionEvent data, accounting for individual pointers going up and down since the start of the gesture.

Once the ACTION_MOVE MotionEvent is triggered, a pointer identifier is used to find the index of its data in the event. Each pointer is tracked by repositioning the rectangle objects at the location of their targeted pointers.

If either of the pointers is removed from the touchscreen, the fingers are no longer tracked by the rectangles. If only one finger is placed on the touchscreen, as a primary pointer, it will be tracked by the larger rectangle.







Exercise 3: Prey and Predator Game

Create a turn-based game using prey and predator rules.