Exercises

7.3 Fill in the blanks in each of the following statements:

a) Most Android devices have a(n) __________ that allows apps to detect movement.

b) Override Fragment method __________ to respond to the event when a Fragment is attached to a parent Activity.

c) The __________ monitors the accelerometer to detect device movement.

d) SensorManager’s __________ constant represents the acceleration due to gravity on earth.

e) You register to receive accelerometer events using SensorManager’s registerListener method, which receives three arguments: the SensorEventListener object that will respond to the events, a Sensor representing the type of sensor data the app wishes to receive and __________.

f) You pass true to Paint’s __________ method to enable anti-aliasing which smooths the edges of the lines.

g) Paint method __________ sets the stroke width to the specified number of pixels.

h) Android supports __________—that is, having multiple fingers touching the screen.

i) The Android Support Library’s class provides a GUI for selecting a printer and method __________ for printing a Bitmap.

7.4 State whether each of the following is true or false. If false, explain why.

a) In Android, sensor events are handled in the GUI thread.

b) The alpha component specifies the Color’s transparency with 0 representing completely transparent and 100 representing completely opaque.

c) For accelerometer events, the SensorEvent parameter values array contains three elements representing the acceleration (in meters/second2) in the x (left/right), y (up/down) and z (forward/backward) directions.

d) Method onProgressChanged is called once when the user drags a SeekBar’s thumb.

e) To get the finger’s unique ID that persists across MotionEvents until the user removes that finger from the screen, you use MotionEvent’s getID method, passing the finger index as an argument.

f) The system MotionEvent passed from onTouchEvent contains touch information for multiple moves on the screen if they occur at the same time.

7.5 (Enhanced Doodlz App) Make the following enhancements to the Doodlz app:

a) Allow the user to select a background color. The erase capability should use the selected background color. Clearing the entire image should return the background to the default white background.

b) Allow the user to select a background image on which to draw. Clearing the entire image should return the background to the default white background. The erase capability should use the default white background color.

c) Use pressure to determine transparency of color or thickness of line. Class MotionEvent has methods that allow you to get the pressure of the touch.

d) Add the ability to draw rectangles and ovals. Options should include whether the shape is filled or hollow. The user should be able to specify the line thickness for each shape’s border and the shape’s fill color.

e) (Advanced) When the user selects a background image on which to draw, the erase capability should reveal the original background image pixels in the erased location.

7.6 (Hangman Game App) Recreate the classic word game Hangman using the Android robot icon rather than a stick figure. (For the Android logo terms of use, visit www.android.com/branding.html). At the start of the game, display a dashed line with one dash representing each letter in the word. As a hint to the user, provide either a category for the word (e.g., sport or landmark) or the word’s definition. Ask the user to enter a letter. If the letter is in the word, place it in the location of the corresponding dash. If the letter is not part of the word, draw part of the Android robot on the screen (e.g., the robot’s head). For each incorrect answer, draw another part of the Android robot. The game ends when the user completes the word or the entire Android Robot is drawn to the screen.

7.7 (Fortune Teller App) The user “asks a question” then shakes the phone to find a fortune (e.g., “probably not,” “looks promising,” “ask me again later.” etc.

7.8 (Block Breaker Game) Display several columns of blocks in red, yellow, blue and green. Each column should have blocks of each color randomly placed. Blocks can be removed from the screen only if they are in groups of two or more. A group consists of blocks of the same color that are vertically and/or horizontally adjacent. When the user taps a group of blocks, the group disappears and the blocks above move down to fill the space. The goal is to clear all of the blocks from the screen. More points should be awarded for larger groups of blocks.

7.9 (Enhanced Block Breaker Game) Modify the Block Breaker game in Exercise 7.8 as follows:

a) Provide a timer—the user wins by clearing the blocks in the alotted time. Add more blocks to the screen the longer it takes the user to clear the screen.

b) Add multiple levels. In each level, the alotted time for clearing the screen decreases.

c) Provide a continous mode in which as the user clears blocks, a new row of blocks is added. If the space below a given block is empty, the block should drop into that space. In this mode, the game ends when the user cannot remove any more blocks.

d) Keep track of the high scores in each game mode.

7.10 (Word Search App) Create a grid of letters that fills the screen. Hidden in the grid should be at least ten words. The words may be horizontal, vertical or diagonal, and, in each case, forwards, backwards, up or down. Allow the user to highlight the words by dragging a finger across the letters on the screen or tapping each letter of the word. Include a timer. The less time it takes the user to complete the game, the higher the score. Keep track of the high scores.

7.11 (Fractal App) Research how to draw fractals and develop an app that draws them. Provide options that allow the user to control the number of levels of the fractal and its colors.

7.12 (Kaleidascope App) Create an app that simulates a kaleidascope. Allow the user to shake the device to redraw the screen.

7.13 (Labyrinth Game App: Open Source) Check out the open-source Android app, Amazed, on the Google Code site (http://apps-for-android.googlecode.com/svn/trunk/Amazed/). In this game, the user maneuvers a marble through a maze by tilting the device in various directions. Possible modifications and enhancements include: adding a timer to keep track of how fast the user completes the game, improving the graphics, adding sounds and adding more puzzles of varying difficulty.

7.14 (Game of Snake App) Research the Game of Snake online and develop an app that allows a user to play the game.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset